summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/machine/pci-usb.cpp
blob: c750c4d107e4c92c2af411627f53d4b34da57adf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
// license:BSD-3-Clause
// copyright-holders:Olivier Galibert, Angelo Salese
#include "emu.h"
#include "pci-usb.h"

#define VERBOSE (LOG_GENERAL)
//#define LOG_OUTPUT_FUNC osd_printf_info

#include "logmacro.h"


DEFINE_DEVICE_TYPE(USB_OHCI, usb_ohci_device, "usb_ohci", "USB 1.1 OHCI interface")
DEFINE_DEVICE_TYPE(USB_UHCI, usb_uhci_device, "usb_uhci", "USB 1.1 UHCI interface")
DEFINE_DEVICE_TYPE(USB_EHCI, usb_ehci_device, "usb_ehci", "USB 2.0 EHCI interface")

/*
 *
 * National/Compaq/Microsoft OHCI
 *
 */

usb_ohci_device::usb_ohci_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
	: pci_device(mconfig, USB_OHCI, tag, owner, clock)
{
}

void usb_ohci_device::device_start()
{
	pci_device::device_start();
	add_map(4096, M_MEM, FUNC(usb_ohci_device::map));
}

void usb_ohci_device::device_reset()
{
	pci_device::device_reset();
}

void usb_ohci_device::map(address_map &map)
{
}

/*
 *
 * Intel/VIA UHCI
 *
 */

usb_uhci_device::usb_uhci_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock)
	: pci_device(mconfig, type, tag, owner, clock)
{
}


usb_uhci_device::usb_uhci_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
	: usb_uhci_device(mconfig, USB_UHCI, tag, owner, clock)
{
}

void usb_uhci_device::device_start()
{
	pci_device::device_start();

	skip_map_regs(4);
	add_map(32, M_IO, FUNC(usb_uhci_device::map));

	save_item(NAME(m_usbcmd));
	save_item(NAME(m_usbsts));
	save_item(NAME(m_usbintr));
	save_item(NAME(m_frnum));
	save_item(NAME(m_flbaseadd));
	save_item(NAME(m_sofmod));
	save_item(NAME(m_portsc));
}

void usb_uhci_device::device_reset()
{
	pci_device::device_reset();

	m_usbcmd = 0;
	m_usbsts = 0;
	m_usbintr = 0;
	m_frnum = 0;
	// flbaseadd is "undefined"
	m_sofmod = 0x40;
	m_portsc[0] = m_portsc[1] = 0x80;
}

void usb_uhci_device::map(address_map &map)
{
	map(0x00, 0x01).lrw16(
		NAME([this] () { return m_usbcmd; }),
		NAME([this] (offs_t offset, u16 data, u16 mem_mask) {
			COMBINE_DATA(&m_usbcmd);
			LOG("USBCMD %04x & %04x\n", data, mem_mask);
			LOG("MAXP %d CF %d SWDBG %d FGR %d EGSM %d GRESET %d HCRESET %d RS %d\n"
				, BIT(data, 7)
				, BIT(data, 6)
				, BIT(data, 5)
				, BIT(data, 4)
				, BIT(data, 3)
				, BIT(data, 2)
				, BIT(data, 1)
				, BIT(data, 0)
			);
			// set HCHalted if Run/Stop bit is clear
			if (!BIT(data, 0))
				m_usbsts |= (1 << 5);
			if (mem_mask != 0xffff)
				LOG("\tnon-word access!\n");
		})
	);
	// --x- ---- HCHalted
	// ---x ---- Host Controller Process Error
	// ---- x--- Host System Error
	// ---- -x-- Resume Detect
	// ---- --x- USB Error Interrupt
	// ---- ---x USB Interrupt (USBINT)
	map(0x02, 0x03).lrw16(
		NAME([this] () { return m_usbsts; }),
		NAME([this] (offs_t offset, u16 data, u16 mem_mask) {
			if (ACCESSING_BITS_0_7)
				m_usbsts &= ~(data & 0x3f);
		})
	);
	// USB Interrupt Enable
	// x--- Short Packet Interrupt Enable
	// -x-- Interrupt On Complete (IOC)
	// --x- Resume Interrupt Enable
	// ---x Time-out/CRC Interrupt Enable
	map(0x04, 0x05).lrw16(
		NAME([this] () { return m_usbintr; }),
		NAME([this] (offs_t offset, u16 data, u16 mem_mask) {
			COMBINE_DATA(&m_usbintr);
			LOG("USBINTR %04x & %04x\n", data, mem_mask);
		})
	);
	// Frame Number
	map(0x06, 0x07).lrw16(
		NAME([this] () { return m_frnum; }),
		NAME([this] (offs_t offset, u16 data, u16 mem_mask) {
			COMBINE_DATA(&m_frnum);
			LOG("FRNUM %04x & %04x\n", data, mem_mask);
			if (mem_mask != 0xffff)
				LOG("\tnon-word access!\n");
		})
	);
	// Frame List Base Address
	// bits 11-0 are <reserved>
	map(0x08, 0x0b).lrw32(
		NAME([this] () { return m_flbaseadd; }),
		NAME([this] (offs_t offset, u32 data, u32 mem_mask) {
			COMBINE_DATA(&m_flbaseadd);
			LOG("FLBASEADD %04x & %04x\n", data, mem_mask);
		})
	);
	// Start of Frame Modify
	map(0x0c, 0x0c).lrw8(
		NAME([this] () { return m_sofmod; }),
		NAME([this] (offs_t offset, u8 data) {
			m_sofmod = data;
			LOG("SOFMOD %02x\n", data);
		})
	);
	// ---x ---- ---- ---- Suspend
	// ---- x--- ---- ---- Over-current Indicator Change
	// ---- -x-- ---- ---- Over-current Indicator (r/o)
	// ---- --x- ---- ---- Port Reset
	// ---- ---x ---- ---- Low Speed Device Attached (r/o)
	// ---- ---- 1--- ---- <reserved>, reads high
	// ---- ---- -x-- ---- Resume Detect
	// ---- ---- --xx ---- Line Status (r/o) D+/D-
	// ---- ---- ---- x--- Port Enable/Disable Change
	// ---- ---- ---- -x-- Port Enabled/Disabled
	// ---- ---- ---- --x- Connect Status Change
	// ---- ---- ---- ---x Current Connect Status (r/o)
	map(0x10, 0x13).lrw16(
		NAME([this] (offs_t offset) { return m_portsc[offset] | 0x80; }),
		NAME([this] (offs_t offset, u16 data, u16 mem_mask) {
			if (ACCESSING_BITS_8_15)
			{
				m_portsc[offset] &= ~(0x1200);
				m_portsc[offset] |= (BIT(data, 12) << 12);
				m_portsc[offset] |= (BIT(data, 9) << 9);
				if (BIT(data, 11))
					m_portsc[offset] &= ~(1 << 11);
			}
			if (ACCESSING_BITS_0_7)
			{
				m_portsc[offset] &= ~(0x44);
				m_portsc[offset] |= (BIT(data, 6) << 6);
				m_portsc[offset] |= (BIT(data, 2) << 2);
				if (BIT(data, 3))
					m_portsc[offset] &= ~(1 << 3);
				if (BIT(data, 1))
					m_portsc[offset] &= ~(1 << 1);
			}
			LOG("PORTSC%d %04x & %04x -> %04x\n", offset, data, mem_mask, m_portsc[offset]);
			if (mem_mask != 0xffff)
				LOG("\tnon-word access!\n");
		})
	);

}

/*
 *
 * EHCI
 *
 */

usb_ehci_device::usb_ehci_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
	: pci_device(mconfig, USB_EHCI, tag, owner, clock)
{
}

void usb_ehci_device::device_start()
{
	pci_device::device_start();
	add_map(1024, M_MEM, FUNC(usb_ehci_device::map));
}

void usb_ehci_device::device_reset()
{
	pci_device::device_reset();
}

void usb_ehci_device::map(address_map &map)
{
}