root / hw / tusb6010.c @ 94a943ef
History | View | Annotate | Download (23.3 kB)
1 | 942ac052 | balrog | /*
|
---|---|---|---|
2 | 942ac052 | balrog | * Texas Instruments TUSB6010 emulation.
|
3 | 942ac052 | balrog | * Based on reverse-engineering of a linux driver.
|
4 | 942ac052 | balrog | *
|
5 | 942ac052 | balrog | * Copyright (C) 2008 Nokia Corporation
|
6 | 942ac052 | balrog | * Written by Andrzej Zaborowski <andrew@openedhand.com>
|
7 | 942ac052 | balrog | *
|
8 | 942ac052 | balrog | * This program is free software; you can redistribute it and/or
|
9 | 942ac052 | balrog | * modify it under the terms of the GNU General Public License as
|
10 | 942ac052 | balrog | * published by the Free Software Foundation; either version 2 or
|
11 | 942ac052 | balrog | * (at your option) version 3 of the License.
|
12 | 942ac052 | balrog | *
|
13 | 942ac052 | balrog | * This program is distributed in the hope that it will be useful,
|
14 | 942ac052 | balrog | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15 | 942ac052 | balrog | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16 | 942ac052 | balrog | * GNU General Public License for more details.
|
17 | 942ac052 | balrog | *
|
18 | fad6cb1a | aurel32 | * You should have received a copy of the GNU General Public License along
|
19 | 8167ee88 | Blue Swirl | * with this program; if not, see <http://www.gnu.org/licenses/>.
|
20 | 942ac052 | balrog | */
|
21 | 942ac052 | balrog | #include "qemu-common.h" |
22 | 942ac052 | balrog | #include "qemu-timer.h" |
23 | 942ac052 | balrog | #include "usb.h" |
24 | 942ac052 | balrog | #include "omap.h" |
25 | 942ac052 | balrog | #include "irq.h" |
26 | b1d8e52e | blueswir1 | #include "devices.h" |
27 | 942ac052 | balrog | |
28 | bc24a225 | Paul Brook | struct TUSBState {
|
29 | 942ac052 | balrog | int iomemtype[2]; |
30 | 942ac052 | balrog | qemu_irq irq; |
31 | bc24a225 | Paul Brook | MUSBState *musb; |
32 | 942ac052 | balrog | QEMUTimer *otg_timer; |
33 | 942ac052 | balrog | QEMUTimer *pwr_timer; |
34 | 942ac052 | balrog | |
35 | 942ac052 | balrog | int power;
|
36 | 942ac052 | balrog | uint32_t scratch; |
37 | 942ac052 | balrog | uint16_t test_reset; |
38 | 942ac052 | balrog | uint32_t prcm_config; |
39 | 942ac052 | balrog | uint32_t prcm_mngmt; |
40 | 942ac052 | balrog | uint16_t otg_status; |
41 | 942ac052 | balrog | uint32_t dev_config; |
42 | 942ac052 | balrog | int host_mode;
|
43 | 942ac052 | balrog | uint32_t intr; |
44 | 942ac052 | balrog | uint32_t intr_ok; |
45 | 942ac052 | balrog | uint32_t mask; |
46 | 942ac052 | balrog | uint32_t usbip_intr; |
47 | 942ac052 | balrog | uint32_t usbip_mask; |
48 | 942ac052 | balrog | uint32_t gpio_intr; |
49 | 942ac052 | balrog | uint32_t gpio_mask; |
50 | 942ac052 | balrog | uint32_t gpio_config; |
51 | 942ac052 | balrog | uint32_t dma_intr; |
52 | 942ac052 | balrog | uint32_t dma_mask; |
53 | 942ac052 | balrog | uint32_t dma_map; |
54 | 942ac052 | balrog | uint32_t dma_config; |
55 | 942ac052 | balrog | uint32_t ep0_config; |
56 | 942ac052 | balrog | uint32_t rx_config[15];
|
57 | 942ac052 | balrog | uint32_t tx_config[15];
|
58 | 942ac052 | balrog | uint32_t wkup_mask; |
59 | 942ac052 | balrog | uint32_t pullup[2];
|
60 | 942ac052 | balrog | uint32_t control_config; |
61 | 942ac052 | balrog | uint32_t otg_timer_val; |
62 | 942ac052 | balrog | }; |
63 | 942ac052 | balrog | |
64 | 942ac052 | balrog | #define TUSB_DEVCLOCK 60000000 /* 60 MHz */ |
65 | 942ac052 | balrog | |
66 | 942ac052 | balrog | #define TUSB_VLYNQ_CTRL 0x004 |
67 | 942ac052 | balrog | |
68 | 942ac052 | balrog | /* Mentor Graphics OTG core registers. */
|
69 | 942ac052 | balrog | #define TUSB_BASE_OFFSET 0x400 |
70 | 942ac052 | balrog | |
71 | 942ac052 | balrog | /* FIFO registers, 32-bit. */
|
72 | 942ac052 | balrog | #define TUSB_FIFO_BASE 0x600 |
73 | 942ac052 | balrog | |
74 | 942ac052 | balrog | /* Device System & Control registers, 32-bit. */
|
75 | 942ac052 | balrog | #define TUSB_SYS_REG_BASE 0x800 |
76 | 942ac052 | balrog | |
77 | 942ac052 | balrog | #define TUSB_DEV_CONF (TUSB_SYS_REG_BASE + 0x000) |
78 | 942ac052 | balrog | #define TUSB_DEV_CONF_USB_HOST_MODE (1 << 16) |
79 | 942ac052 | balrog | #define TUSB_DEV_CONF_PROD_TEST_MODE (1 << 15) |
80 | 942ac052 | balrog | #define TUSB_DEV_CONF_SOFT_ID (1 << 1) |
81 | 942ac052 | balrog | #define TUSB_DEV_CONF_ID_SEL (1 << 0) |
82 | 942ac052 | balrog | |
83 | 942ac052 | balrog | #define TUSB_PHY_OTG_CTRL_ENABLE (TUSB_SYS_REG_BASE + 0x004) |
84 | 942ac052 | balrog | #define TUSB_PHY_OTG_CTRL (TUSB_SYS_REG_BASE + 0x008) |
85 | 942ac052 | balrog | #define TUSB_PHY_OTG_CTRL_WRPROTECT (0xa5 << 24) |
86 | 942ac052 | balrog | #define TUSB_PHY_OTG_CTRL_O_ID_PULLUP (1 << 23) |
87 | 942ac052 | balrog | #define TUSB_PHY_OTG_CTRL_O_VBUS_DET_EN (1 << 19) |
88 | 942ac052 | balrog | #define TUSB_PHY_OTG_CTRL_O_SESS_END_EN (1 << 18) |
89 | 942ac052 | balrog | #define TUSB_PHY_OTG_CTRL_TESTM2 (1 << 17) |
90 | 942ac052 | balrog | #define TUSB_PHY_OTG_CTRL_TESTM1 (1 << 16) |
91 | 942ac052 | balrog | #define TUSB_PHY_OTG_CTRL_TESTM0 (1 << 15) |
92 | 942ac052 | balrog | #define TUSB_PHY_OTG_CTRL_TX_DATA2 (1 << 14) |
93 | 942ac052 | balrog | #define TUSB_PHY_OTG_CTRL_TX_GZ2 (1 << 13) |
94 | 942ac052 | balrog | #define TUSB_PHY_OTG_CTRL_TX_ENABLE2 (1 << 12) |
95 | 942ac052 | balrog | #define TUSB_PHY_OTG_CTRL_DM_PULLDOWN (1 << 11) |
96 | 942ac052 | balrog | #define TUSB_PHY_OTG_CTRL_DP_PULLDOWN (1 << 10) |
97 | 942ac052 | balrog | #define TUSB_PHY_OTG_CTRL_OSC_EN (1 << 9) |
98 | 942ac052 | balrog | #define TUSB_PHY_OTG_CTRL_PHYREF_CLK(v) (((v) & 3) << 7) |
99 | 942ac052 | balrog | #define TUSB_PHY_OTG_CTRL_PD (1 << 6) |
100 | 942ac052 | balrog | #define TUSB_PHY_OTG_CTRL_PLL_ON (1 << 5) |
101 | 942ac052 | balrog | #define TUSB_PHY_OTG_CTRL_EXT_RPU (1 << 4) |
102 | 942ac052 | balrog | #define TUSB_PHY_OTG_CTRL_PWR_GOOD (1 << 3) |
103 | 942ac052 | balrog | #define TUSB_PHY_OTG_CTRL_RESET (1 << 2) |
104 | 942ac052 | balrog | #define TUSB_PHY_OTG_CTRL_SUSPENDM (1 << 1) |
105 | 942ac052 | balrog | #define TUSB_PHY_OTG_CTRL_CLK_MODE (1 << 0) |
106 | 942ac052 | balrog | |
107 | 942ac052 | balrog | /* OTG status register */
|
108 | 942ac052 | balrog | #define TUSB_DEV_OTG_STAT (TUSB_SYS_REG_BASE + 0x00c) |
109 | 942ac052 | balrog | #define TUSB_DEV_OTG_STAT_PWR_CLK_GOOD (1 << 8) |
110 | 942ac052 | balrog | #define TUSB_DEV_OTG_STAT_SESS_END (1 << 7) |
111 | 942ac052 | balrog | #define TUSB_DEV_OTG_STAT_SESS_VALID (1 << 6) |
112 | 942ac052 | balrog | #define TUSB_DEV_OTG_STAT_VBUS_VALID (1 << 5) |
113 | 942ac052 | balrog | #define TUSB_DEV_OTG_STAT_VBUS_SENSE (1 << 4) |
114 | 942ac052 | balrog | #define TUSB_DEV_OTG_STAT_ID_STATUS (1 << 3) |
115 | 942ac052 | balrog | #define TUSB_DEV_OTG_STAT_HOST_DISCON (1 << 2) |
116 | 942ac052 | balrog | #define TUSB_DEV_OTG_STAT_LINE_STATE (3 << 0) |
117 | 942ac052 | balrog | #define TUSB_DEV_OTG_STAT_DP_ENABLE (1 << 1) |
118 | 942ac052 | balrog | #define TUSB_DEV_OTG_STAT_DM_ENABLE (1 << 0) |
119 | 942ac052 | balrog | |
120 | 942ac052 | balrog | #define TUSB_DEV_OTG_TIMER (TUSB_SYS_REG_BASE + 0x010) |
121 | 942ac052 | balrog | #define TUSB_DEV_OTG_TIMER_ENABLE (1 << 31) |
122 | 942ac052 | balrog | #define TUSB_DEV_OTG_TIMER_VAL(v) ((v) & 0x07ffffff) |
123 | 942ac052 | balrog | #define TUSB_PRCM_REV (TUSB_SYS_REG_BASE + 0x014) |
124 | 942ac052 | balrog | |
125 | 942ac052 | balrog | /* PRCM configuration register */
|
126 | 942ac052 | balrog | #define TUSB_PRCM_CONF (TUSB_SYS_REG_BASE + 0x018) |
127 | 942ac052 | balrog | #define TUSB_PRCM_CONF_SFW_CPEN (1 << 24) |
128 | 942ac052 | balrog | #define TUSB_PRCM_CONF_SYS_CLKSEL(v) (((v) & 3) << 16) |
129 | 942ac052 | balrog | |
130 | 942ac052 | balrog | /* PRCM management register */
|
131 | 942ac052 | balrog | #define TUSB_PRCM_MNGMT (TUSB_SYS_REG_BASE + 0x01c) |
132 | 942ac052 | balrog | #define TUSB_PRCM_MNGMT_SRP_FIX_TMR(v) (((v) & 0xf) << 25) |
133 | 942ac052 | balrog | #define TUSB_PRCM_MNGMT_SRP_FIX_EN (1 << 24) |
134 | 942ac052 | balrog | #define TUSB_PRCM_MNGMT_VBUS_VAL_TMR(v) (((v) & 0xf) << 20) |
135 | 942ac052 | balrog | #define TUSB_PRCM_MNGMT_VBUS_VAL_FLT_EN (1 << 19) |
136 | 942ac052 | balrog | #define TUSB_PRCM_MNGMT_DFT_CLK_DIS (1 << 18) |
137 | 942ac052 | balrog | #define TUSB_PRCM_MNGMT_VLYNQ_CLK_DIS (1 << 17) |
138 | 942ac052 | balrog | #define TUSB_PRCM_MNGMT_OTG_SESS_END_EN (1 << 10) |
139 | 942ac052 | balrog | #define TUSB_PRCM_MNGMT_OTG_VBUS_DET_EN (1 << 9) |
140 | 942ac052 | balrog | #define TUSB_PRCM_MNGMT_OTG_ID_PULLUP (1 << 8) |
141 | 942ac052 | balrog | #define TUSB_PRCM_MNGMT_15_SW_EN (1 << 4) |
142 | 942ac052 | balrog | #define TUSB_PRCM_MNGMT_33_SW_EN (1 << 3) |
143 | 942ac052 | balrog | #define TUSB_PRCM_MNGMT_5V_CPEN (1 << 2) |
144 | 942ac052 | balrog | #define TUSB_PRCM_MNGMT_PM_IDLE (1 << 1) |
145 | 942ac052 | balrog | #define TUSB_PRCM_MNGMT_DEV_IDLE (1 << 0) |
146 | 942ac052 | balrog | |
147 | 942ac052 | balrog | /* Wake-up source clear and mask registers */
|
148 | 942ac052 | balrog | #define TUSB_PRCM_WAKEUP_SOURCE (TUSB_SYS_REG_BASE + 0x020) |
149 | 942ac052 | balrog | #define TUSB_PRCM_WAKEUP_CLEAR (TUSB_SYS_REG_BASE + 0x028) |
150 | 942ac052 | balrog | #define TUSB_PRCM_WAKEUP_MASK (TUSB_SYS_REG_BASE + 0x02c) |
151 | 942ac052 | balrog | #define TUSB_PRCM_WAKEUP_RESERVED_BITS (0xffffe << 13) |
152 | 942ac052 | balrog | #define TUSB_PRCM_WGPIO_7 (1 << 12) |
153 | 942ac052 | balrog | #define TUSB_PRCM_WGPIO_6 (1 << 11) |
154 | 942ac052 | balrog | #define TUSB_PRCM_WGPIO_5 (1 << 10) |
155 | 942ac052 | balrog | #define TUSB_PRCM_WGPIO_4 (1 << 9) |
156 | 942ac052 | balrog | #define TUSB_PRCM_WGPIO_3 (1 << 8) |
157 | 942ac052 | balrog | #define TUSB_PRCM_WGPIO_2 (1 << 7) |
158 | 942ac052 | balrog | #define TUSB_PRCM_WGPIO_1 (1 << 6) |
159 | 942ac052 | balrog | #define TUSB_PRCM_WGPIO_0 (1 << 5) |
160 | 942ac052 | balrog | #define TUSB_PRCM_WHOSTDISCON (1 << 4) /* Host disconnect */ |
161 | 942ac052 | balrog | #define TUSB_PRCM_WBUS (1 << 3) /* USB bus resume */ |
162 | 942ac052 | balrog | #define TUSB_PRCM_WNORCS (1 << 2) /* NOR chip select */ |
163 | 942ac052 | balrog | #define TUSB_PRCM_WVBUS (1 << 1) /* OTG PHY VBUS */ |
164 | 942ac052 | balrog | #define TUSB_PRCM_WID (1 << 0) /* OTG PHY ID detect */ |
165 | 942ac052 | balrog | |
166 | 942ac052 | balrog | #define TUSB_PULLUP_1_CTRL (TUSB_SYS_REG_BASE + 0x030) |
167 | 942ac052 | balrog | #define TUSB_PULLUP_2_CTRL (TUSB_SYS_REG_BASE + 0x034) |
168 | 942ac052 | balrog | #define TUSB_INT_CTRL_REV (TUSB_SYS_REG_BASE + 0x038) |
169 | 942ac052 | balrog | #define TUSB_INT_CTRL_CONF (TUSB_SYS_REG_BASE + 0x03c) |
170 | 942ac052 | balrog | #define TUSB_USBIP_INT_SRC (TUSB_SYS_REG_BASE + 0x040) |
171 | 942ac052 | balrog | #define TUSB_USBIP_INT_SET (TUSB_SYS_REG_BASE + 0x044) |
172 | 942ac052 | balrog | #define TUSB_USBIP_INT_CLEAR (TUSB_SYS_REG_BASE + 0x048) |
173 | 942ac052 | balrog | #define TUSB_USBIP_INT_MASK (TUSB_SYS_REG_BASE + 0x04c) |
174 | 942ac052 | balrog | #define TUSB_DMA_INT_SRC (TUSB_SYS_REG_BASE + 0x050) |
175 | 942ac052 | balrog | #define TUSB_DMA_INT_SET (TUSB_SYS_REG_BASE + 0x054) |
176 | 942ac052 | balrog | #define TUSB_DMA_INT_CLEAR (TUSB_SYS_REG_BASE + 0x058) |
177 | 942ac052 | balrog | #define TUSB_DMA_INT_MASK (TUSB_SYS_REG_BASE + 0x05c) |
178 | 942ac052 | balrog | #define TUSB_GPIO_INT_SRC (TUSB_SYS_REG_BASE + 0x060) |
179 | 942ac052 | balrog | #define TUSB_GPIO_INT_SET (TUSB_SYS_REG_BASE + 0x064) |
180 | 942ac052 | balrog | #define TUSB_GPIO_INT_CLEAR (TUSB_SYS_REG_BASE + 0x068) |
181 | 942ac052 | balrog | #define TUSB_GPIO_INT_MASK (TUSB_SYS_REG_BASE + 0x06c) |
182 | 942ac052 | balrog | |
183 | 942ac052 | balrog | /* NOR flash interrupt source registers */
|
184 | 942ac052 | balrog | #define TUSB_INT_SRC (TUSB_SYS_REG_BASE + 0x070) |
185 | 942ac052 | balrog | #define TUSB_INT_SRC_SET (TUSB_SYS_REG_BASE + 0x074) |
186 | 942ac052 | balrog | #define TUSB_INT_SRC_CLEAR (TUSB_SYS_REG_BASE + 0x078) |
187 | 942ac052 | balrog | #define TUSB_INT_MASK (TUSB_SYS_REG_BASE + 0x07c) |
188 | 942ac052 | balrog | #define TUSB_INT_SRC_TXRX_DMA_DONE (1 << 24) |
189 | 942ac052 | balrog | #define TUSB_INT_SRC_USB_IP_CORE (1 << 17) |
190 | 942ac052 | balrog | #define TUSB_INT_SRC_OTG_TIMEOUT (1 << 16) |
191 | 942ac052 | balrog | #define TUSB_INT_SRC_VBUS_SENSE_CHNG (1 << 15) |
192 | 942ac052 | balrog | #define TUSB_INT_SRC_ID_STATUS_CHNG (1 << 14) |
193 | 942ac052 | balrog | #define TUSB_INT_SRC_DEV_WAKEUP (1 << 13) |
194 | 942ac052 | balrog | #define TUSB_INT_SRC_DEV_READY (1 << 12) |
195 | 942ac052 | balrog | #define TUSB_INT_SRC_USB_IP_TX (1 << 9) |
196 | 942ac052 | balrog | #define TUSB_INT_SRC_USB_IP_RX (1 << 8) |
197 | 942ac052 | balrog | #define TUSB_INT_SRC_USB_IP_VBUS_ERR (1 << 7) |
198 | 942ac052 | balrog | #define TUSB_INT_SRC_USB_IP_VBUS_REQ (1 << 6) |
199 | 942ac052 | balrog | #define TUSB_INT_SRC_USB_IP_DISCON (1 << 5) |
200 | 942ac052 | balrog | #define TUSB_INT_SRC_USB_IP_CONN (1 << 4) |
201 | 942ac052 | balrog | #define TUSB_INT_SRC_USB_IP_SOF (1 << 3) |
202 | 942ac052 | balrog | #define TUSB_INT_SRC_USB_IP_RST_BABBLE (1 << 2) |
203 | 942ac052 | balrog | #define TUSB_INT_SRC_USB_IP_RESUME (1 << 1) |
204 | 942ac052 | balrog | #define TUSB_INT_SRC_USB_IP_SUSPEND (1 << 0) |
205 | 942ac052 | balrog | |
206 | 942ac052 | balrog | #define TUSB_GPIO_REV (TUSB_SYS_REG_BASE + 0x080) |
207 | 942ac052 | balrog | #define TUSB_GPIO_CONF (TUSB_SYS_REG_BASE + 0x084) |
208 | 942ac052 | balrog | #define TUSB_DMA_CTRL_REV (TUSB_SYS_REG_BASE + 0x100) |
209 | 942ac052 | balrog | #define TUSB_DMA_REQ_CONF (TUSB_SYS_REG_BASE + 0x104) |
210 | 942ac052 | balrog | #define TUSB_EP0_CONF (TUSB_SYS_REG_BASE + 0x108) |
211 | 942ac052 | balrog | #define TUSB_EP_IN_SIZE (TUSB_SYS_REG_BASE + 0x10c) |
212 | 942ac052 | balrog | #define TUSB_DMA_EP_MAP (TUSB_SYS_REG_BASE + 0x148) |
213 | 942ac052 | balrog | #define TUSB_EP_OUT_SIZE (TUSB_SYS_REG_BASE + 0x14c) |
214 | 942ac052 | balrog | #define TUSB_EP_MAX_PACKET_SIZE_OFFSET (TUSB_SYS_REG_BASE + 0x188) |
215 | 942ac052 | balrog | #define TUSB_SCRATCH_PAD (TUSB_SYS_REG_BASE + 0x1c4) |
216 | 942ac052 | balrog | #define TUSB_WAIT_COUNT (TUSB_SYS_REG_BASE + 0x1c8) |
217 | 942ac052 | balrog | #define TUSB_PROD_TEST_RESET (TUSB_SYS_REG_BASE + 0x1d8) |
218 | 942ac052 | balrog | |
219 | 942ac052 | balrog | #define TUSB_DIDR1_LO (TUSB_SYS_REG_BASE + 0x1f8) |
220 | 942ac052 | balrog | #define TUSB_DIDR1_HI (TUSB_SYS_REG_BASE + 0x1fc) |
221 | 942ac052 | balrog | |
222 | 942ac052 | balrog | /* Device System & Control register bitfields */
|
223 | 942ac052 | balrog | #define TUSB_INT_CTRL_CONF_INT_RLCYC(v) (((v) & 0x7) << 18) |
224 | 942ac052 | balrog | #define TUSB_INT_CTRL_CONF_INT_POLARITY (1 << 17) |
225 | 942ac052 | balrog | #define TUSB_INT_CTRL_CONF_INT_MODE (1 << 16) |
226 | 942ac052 | balrog | #define TUSB_GPIO_CONF_DMAREQ(v) (((v) & 0x3f) << 24) |
227 | 942ac052 | balrog | #define TUSB_DMA_REQ_CONF_BURST_SIZE(v) (((v) & 3) << 26) |
228 | 942ac052 | balrog | #define TUSB_DMA_REQ_CONF_DMA_RQ_EN(v) (((v) & 0x3f) << 20) |
229 | 942ac052 | balrog | #define TUSB_DMA_REQ_CONF_DMA_RQ_ASR(v) (((v) & 0xf) << 16) |
230 | 942ac052 | balrog | #define TUSB_EP0_CONFIG_SW_EN (1 << 8) |
231 | 942ac052 | balrog | #define TUSB_EP0_CONFIG_DIR_TX (1 << 7) |
232 | 942ac052 | balrog | #define TUSB_EP0_CONFIG_XFR_SIZE(v) ((v) & 0x7f) |
233 | 942ac052 | balrog | #define TUSB_EP_CONFIG_SW_EN (1 << 31) |
234 | 942ac052 | balrog | #define TUSB_EP_CONFIG_XFR_SIZE(v) ((v) & 0x7fffffff) |
235 | 942ac052 | balrog | #define TUSB_PROD_TEST_RESET_VAL 0xa596 |
236 | 942ac052 | balrog | |
237 | bc24a225 | Paul Brook | int tusb6010_sync_io(TUSBState *s)
|
238 | 942ac052 | balrog | { |
239 | 942ac052 | balrog | return s->iomemtype[0]; |
240 | 942ac052 | balrog | } |
241 | 942ac052 | balrog | |
242 | bc24a225 | Paul Brook | int tusb6010_async_io(TUSBState *s)
|
243 | 942ac052 | balrog | { |
244 | 942ac052 | balrog | return s->iomemtype[1]; |
245 | 942ac052 | balrog | } |
246 | 942ac052 | balrog | |
247 | bc24a225 | Paul Brook | static void tusb_intr_update(TUSBState *s) |
248 | 942ac052 | balrog | { |
249 | 942ac052 | balrog | if (s->control_config & TUSB_INT_CTRL_CONF_INT_POLARITY)
|
250 | 942ac052 | balrog | qemu_set_irq(s->irq, s->intr & ~s->mask & s->intr_ok); |
251 | 942ac052 | balrog | else
|
252 | 942ac052 | balrog | qemu_set_irq(s->irq, (!(s->intr & ~s->mask)) & s->intr_ok); |
253 | 942ac052 | balrog | } |
254 | 942ac052 | balrog | |
255 | bc24a225 | Paul Brook | static void tusb_usbip_intr_update(TUSBState *s) |
256 | 942ac052 | balrog | { |
257 | 942ac052 | balrog | /* TX interrupt in the MUSB */
|
258 | 942ac052 | balrog | if (s->usbip_intr & 0x0000ffff & ~s->usbip_mask) |
259 | 942ac052 | balrog | s->intr |= TUSB_INT_SRC_USB_IP_TX; |
260 | 942ac052 | balrog | else
|
261 | 942ac052 | balrog | s->intr &= ~TUSB_INT_SRC_USB_IP_TX; |
262 | 942ac052 | balrog | |
263 | 942ac052 | balrog | /* RX interrupt in the MUSB */
|
264 | 942ac052 | balrog | if (s->usbip_intr & 0xffff0000 & ~s->usbip_mask) |
265 | 942ac052 | balrog | s->intr |= TUSB_INT_SRC_USB_IP_RX; |
266 | 942ac052 | balrog | else
|
267 | 942ac052 | balrog | s->intr &= ~TUSB_INT_SRC_USB_IP_RX; |
268 | 942ac052 | balrog | |
269 | 942ac052 | balrog | /* XXX: What about TUSB_INT_SRC_USB_IP_CORE? */
|
270 | 942ac052 | balrog | |
271 | 942ac052 | balrog | tusb_intr_update(s); |
272 | 942ac052 | balrog | } |
273 | 942ac052 | balrog | |
274 | bc24a225 | Paul Brook | static void tusb_dma_intr_update(TUSBState *s) |
275 | 942ac052 | balrog | { |
276 | 942ac052 | balrog | if (s->dma_intr & ~s->dma_mask)
|
277 | 942ac052 | balrog | s->intr |= TUSB_INT_SRC_TXRX_DMA_DONE; |
278 | 942ac052 | balrog | else
|
279 | 942ac052 | balrog | s->intr &= ~TUSB_INT_SRC_TXRX_DMA_DONE; |
280 | 942ac052 | balrog | |
281 | 942ac052 | balrog | tusb_intr_update(s); |
282 | 942ac052 | balrog | } |
283 | 942ac052 | balrog | |
284 | bc24a225 | Paul Brook | static void tusb_gpio_intr_update(TUSBState *s) |
285 | 942ac052 | balrog | { |
286 | 942ac052 | balrog | /* TODO: How is this signalled? */
|
287 | 942ac052 | balrog | } |
288 | 942ac052 | balrog | |
289 | d60efc6b | Blue Swirl | extern CPUReadMemoryFunc * const musb_read[]; |
290 | d60efc6b | Blue Swirl | extern CPUWriteMemoryFunc * const musb_write[]; |
291 | 942ac052 | balrog | |
292 | 942ac052 | balrog | static uint32_t tusb_async_readb(void *opaque, target_phys_addr_t addr) |
293 | 942ac052 | balrog | { |
294 | bc24a225 | Paul Brook | TUSBState *s = (TUSBState *) opaque; |
295 | 942ac052 | balrog | |
296 | 942ac052 | balrog | switch (addr & 0xfff) { |
297 | 942ac052 | balrog | case TUSB_BASE_OFFSET ... (TUSB_BASE_OFFSET | 0x1ff): |
298 | 942ac052 | balrog | return musb_read[0](s->musb, addr & 0x1ff); |
299 | 942ac052 | balrog | |
300 | 942ac052 | balrog | case TUSB_FIFO_BASE ... (TUSB_FIFO_BASE | 0x1ff): |
301 | 942ac052 | balrog | return musb_read[0](s->musb, 0x20 + ((addr >> 3) & 0x3c)); |
302 | 942ac052 | balrog | } |
303 | 942ac052 | balrog | |
304 | 942ac052 | balrog | printf("%s: unknown register at %03x\n",
|
305 | 942ac052 | balrog | __FUNCTION__, (int) (addr & 0xfff)); |
306 | 942ac052 | balrog | return 0; |
307 | 942ac052 | balrog | } |
308 | 942ac052 | balrog | |
309 | 942ac052 | balrog | static uint32_t tusb_async_readh(void *opaque, target_phys_addr_t addr) |
310 | 942ac052 | balrog | { |
311 | bc24a225 | Paul Brook | TUSBState *s = (TUSBState *) opaque; |
312 | 942ac052 | balrog | |
313 | 942ac052 | balrog | switch (addr & 0xfff) { |
314 | 942ac052 | balrog | case TUSB_BASE_OFFSET ... (TUSB_BASE_OFFSET | 0x1ff): |
315 | 942ac052 | balrog | return musb_read[1](s->musb, addr & 0x1ff); |
316 | 942ac052 | balrog | |
317 | 942ac052 | balrog | case TUSB_FIFO_BASE ... (TUSB_FIFO_BASE | 0x1ff): |
318 | 942ac052 | balrog | return musb_read[1](s->musb, 0x20 + ((addr >> 3) & 0x3c)); |
319 | 942ac052 | balrog | } |
320 | 942ac052 | balrog | |
321 | 942ac052 | balrog | printf("%s: unknown register at %03x\n",
|
322 | 942ac052 | balrog | __FUNCTION__, (int) (addr & 0xfff)); |
323 | 942ac052 | balrog | return 0; |
324 | 942ac052 | balrog | } |
325 | 942ac052 | balrog | |
326 | 942ac052 | balrog | static uint32_t tusb_async_readw(void *opaque, target_phys_addr_t addr) |
327 | 942ac052 | balrog | { |
328 | bc24a225 | Paul Brook | TUSBState *s = (TUSBState *) opaque; |
329 | 942ac052 | balrog | int offset = addr & 0xfff; |
330 | 942ac052 | balrog | int epnum;
|
331 | 942ac052 | balrog | uint32_t ret; |
332 | 942ac052 | balrog | |
333 | 942ac052 | balrog | switch (offset) {
|
334 | 942ac052 | balrog | case TUSB_DEV_CONF:
|
335 | 942ac052 | balrog | return s->dev_config;
|
336 | 942ac052 | balrog | |
337 | 942ac052 | balrog | case TUSB_BASE_OFFSET ... (TUSB_BASE_OFFSET | 0x1ff): |
338 | 942ac052 | balrog | return musb_read[2](s->musb, offset & 0x1ff); |
339 | 942ac052 | balrog | |
340 | 942ac052 | balrog | case TUSB_FIFO_BASE ... (TUSB_FIFO_BASE | 0x1ff): |
341 | 942ac052 | balrog | return musb_read[2](s->musb, 0x20 + ((addr >> 3) & 0x3c)); |
342 | 942ac052 | balrog | |
343 | 942ac052 | balrog | case TUSB_PHY_OTG_CTRL_ENABLE:
|
344 | 942ac052 | balrog | case TUSB_PHY_OTG_CTRL:
|
345 | 942ac052 | balrog | return 0x00; /* TODO */ |
346 | 942ac052 | balrog | |
347 | 942ac052 | balrog | case TUSB_DEV_OTG_STAT:
|
348 | 942ac052 | balrog | ret = s->otg_status; |
349 | 942ac052 | balrog | #if 0
|
350 | 942ac052 | balrog | if (!(s->prcm_mngmt & TUSB_PRCM_MNGMT_OTG_VBUS_DET_EN))
|
351 | 942ac052 | balrog | ret &= ~TUSB_DEV_OTG_STAT_VBUS_VALID;
|
352 | 942ac052 | balrog | #endif
|
353 | 942ac052 | balrog | return ret;
|
354 | 942ac052 | balrog | case TUSB_DEV_OTG_TIMER:
|
355 | 942ac052 | balrog | return s->otg_timer_val;
|
356 | 942ac052 | balrog | |
357 | 942ac052 | balrog | case TUSB_PRCM_REV:
|
358 | 942ac052 | balrog | return 0x20; |
359 | 942ac052 | balrog | case TUSB_PRCM_CONF:
|
360 | 942ac052 | balrog | return s->prcm_config;
|
361 | 942ac052 | balrog | case TUSB_PRCM_MNGMT:
|
362 | 942ac052 | balrog | return s->prcm_mngmt;
|
363 | 942ac052 | balrog | case TUSB_PRCM_WAKEUP_SOURCE:
|
364 | 942ac052 | balrog | case TUSB_PRCM_WAKEUP_CLEAR: /* TODO: What does this one return? */ |
365 | 942ac052 | balrog | return 0x00000000; |
366 | 942ac052 | balrog | case TUSB_PRCM_WAKEUP_MASK:
|
367 | 942ac052 | balrog | return s->wkup_mask;
|
368 | 942ac052 | balrog | |
369 | 942ac052 | balrog | case TUSB_PULLUP_1_CTRL:
|
370 | 942ac052 | balrog | return s->pullup[0]; |
371 | 942ac052 | balrog | case TUSB_PULLUP_2_CTRL:
|
372 | 942ac052 | balrog | return s->pullup[1]; |
373 | 942ac052 | balrog | |
374 | 942ac052 | balrog | case TUSB_INT_CTRL_REV:
|
375 | 942ac052 | balrog | return 0x20; |
376 | 942ac052 | balrog | case TUSB_INT_CTRL_CONF:
|
377 | 942ac052 | balrog | return s->control_config;
|
378 | 942ac052 | balrog | |
379 | 942ac052 | balrog | case TUSB_USBIP_INT_SRC:
|
380 | 942ac052 | balrog | case TUSB_USBIP_INT_SET: /* TODO: What do these two return? */ |
381 | 942ac052 | balrog | case TUSB_USBIP_INT_CLEAR:
|
382 | 942ac052 | balrog | return s->usbip_intr;
|
383 | 942ac052 | balrog | case TUSB_USBIP_INT_MASK:
|
384 | 942ac052 | balrog | return s->usbip_mask;
|
385 | 942ac052 | balrog | |
386 | 942ac052 | balrog | case TUSB_DMA_INT_SRC:
|
387 | 942ac052 | balrog | case TUSB_DMA_INT_SET: /* TODO: What do these two return? */ |
388 | 942ac052 | balrog | case TUSB_DMA_INT_CLEAR:
|
389 | 942ac052 | balrog | return s->dma_intr;
|
390 | 942ac052 | balrog | case TUSB_DMA_INT_MASK:
|
391 | 942ac052 | balrog | return s->dma_mask;
|
392 | 942ac052 | balrog | |
393 | 942ac052 | balrog | case TUSB_GPIO_INT_SRC: /* TODO: What do these two return? */ |
394 | 942ac052 | balrog | case TUSB_GPIO_INT_SET:
|
395 | 942ac052 | balrog | case TUSB_GPIO_INT_CLEAR:
|
396 | 942ac052 | balrog | return s->gpio_intr;
|
397 | 942ac052 | balrog | case TUSB_GPIO_INT_MASK:
|
398 | 942ac052 | balrog | return s->gpio_mask;
|
399 | 942ac052 | balrog | |
400 | 942ac052 | balrog | case TUSB_INT_SRC:
|
401 | 942ac052 | balrog | case TUSB_INT_SRC_SET: /* TODO: What do these two return? */ |
402 | 942ac052 | balrog | case TUSB_INT_SRC_CLEAR:
|
403 | 942ac052 | balrog | return s->intr;
|
404 | 942ac052 | balrog | case TUSB_INT_MASK:
|
405 | 942ac052 | balrog | return s->mask;
|
406 | 942ac052 | balrog | |
407 | 942ac052 | balrog | case TUSB_GPIO_REV:
|
408 | 942ac052 | balrog | return 0x30; |
409 | 942ac052 | balrog | case TUSB_GPIO_CONF:
|
410 | 942ac052 | balrog | return s->gpio_config;
|
411 | 942ac052 | balrog | |
412 | 942ac052 | balrog | case TUSB_DMA_CTRL_REV:
|
413 | 942ac052 | balrog | return 0x30; |
414 | 942ac052 | balrog | case TUSB_DMA_REQ_CONF:
|
415 | 942ac052 | balrog | return s->dma_config;
|
416 | 942ac052 | balrog | case TUSB_EP0_CONF:
|
417 | 942ac052 | balrog | return s->ep0_config;
|
418 | 942ac052 | balrog | case TUSB_EP_IN_SIZE ... (TUSB_EP_IN_SIZE + 0x3b): |
419 | 942ac052 | balrog | epnum = (offset - TUSB_EP_IN_SIZE) >> 2;
|
420 | 942ac052 | balrog | return s->tx_config[epnum];
|
421 | 942ac052 | balrog | case TUSB_DMA_EP_MAP:
|
422 | 942ac052 | balrog | return s->dma_map;
|
423 | 942ac052 | balrog | case TUSB_EP_OUT_SIZE ... (TUSB_EP_OUT_SIZE + 0x3b): |
424 | 942ac052 | balrog | epnum = (offset - TUSB_EP_OUT_SIZE) >> 2;
|
425 | 942ac052 | balrog | return s->rx_config[epnum];
|
426 | 942ac052 | balrog | case TUSB_EP_MAX_PACKET_SIZE_OFFSET ...
|
427 | 942ac052 | balrog | (TUSB_EP_MAX_PACKET_SIZE_OFFSET + 0x3b):
|
428 | 942ac052 | balrog | epnum = (offset - TUSB_EP_MAX_PACKET_SIZE_OFFSET) >> 2;
|
429 | 942ac052 | balrog | return 0x00000000; /* TODO */ |
430 | 942ac052 | balrog | case TUSB_WAIT_COUNT:
|
431 | 942ac052 | balrog | return 0x00; /* TODO */ |
432 | 942ac052 | balrog | |
433 | 942ac052 | balrog | case TUSB_SCRATCH_PAD:
|
434 | 942ac052 | balrog | return s->scratch;
|
435 | 942ac052 | balrog | |
436 | 942ac052 | balrog | case TUSB_PROD_TEST_RESET:
|
437 | 942ac052 | balrog | return s->test_reset;
|
438 | 942ac052 | balrog | |
439 | 942ac052 | balrog | /* DIE IDs */
|
440 | 942ac052 | balrog | case TUSB_DIDR1_LO:
|
441 | 942ac052 | balrog | return 0xa9453c59; |
442 | 942ac052 | balrog | case TUSB_DIDR1_HI:
|
443 | 942ac052 | balrog | return 0x54059adf; |
444 | 942ac052 | balrog | } |
445 | 942ac052 | balrog | |
446 | 942ac052 | balrog | printf("%s: unknown register at %03x\n", __FUNCTION__, offset);
|
447 | 942ac052 | balrog | return 0; |
448 | 942ac052 | balrog | } |
449 | 942ac052 | balrog | |
450 | 942ac052 | balrog | static void tusb_async_writeb(void *opaque, target_phys_addr_t addr, |
451 | 942ac052 | balrog | uint32_t value) |
452 | 942ac052 | balrog | { |
453 | bc24a225 | Paul Brook | TUSBState *s = (TUSBState *) opaque; |
454 | 942ac052 | balrog | |
455 | 942ac052 | balrog | switch (addr & 0xfff) { |
456 | 942ac052 | balrog | case TUSB_BASE_OFFSET ... (TUSB_BASE_OFFSET | 0x1ff): |
457 | 942ac052 | balrog | musb_write[0](s->musb, addr & 0x1ff, value); |
458 | 942ac052 | balrog | break;
|
459 | 942ac052 | balrog | |
460 | 942ac052 | balrog | case TUSB_FIFO_BASE ... (TUSB_FIFO_BASE | 0x1ff): |
461 | 942ac052 | balrog | musb_write[0](s->musb, 0x20 + ((addr >> 3) & 0x3c), value); |
462 | 942ac052 | balrog | break;
|
463 | 942ac052 | balrog | |
464 | 942ac052 | balrog | default:
|
465 | 942ac052 | balrog | printf("%s: unknown register at %03x\n",
|
466 | 942ac052 | balrog | __FUNCTION__, (int) (addr & 0xfff)); |
467 | 942ac052 | balrog | return;
|
468 | 942ac052 | balrog | } |
469 | 942ac052 | balrog | } |
470 | 942ac052 | balrog | |
471 | 942ac052 | balrog | static void tusb_async_writeh(void *opaque, target_phys_addr_t addr, |
472 | 942ac052 | balrog | uint32_t value) |
473 | 942ac052 | balrog | { |
474 | bc24a225 | Paul Brook | TUSBState *s = (TUSBState *) opaque; |
475 | 942ac052 | balrog | |
476 | 942ac052 | balrog | switch (addr & 0xfff) { |
477 | 942ac052 | balrog | case TUSB_BASE_OFFSET ... (TUSB_BASE_OFFSET | 0x1ff): |
478 | 942ac052 | balrog | musb_write[1](s->musb, addr & 0x1ff, value); |
479 | 942ac052 | balrog | break;
|
480 | 942ac052 | balrog | |
481 | 942ac052 | balrog | case TUSB_FIFO_BASE ... (TUSB_FIFO_BASE | 0x1ff): |
482 | 942ac052 | balrog | musb_write[1](s->musb, 0x20 + ((addr >> 3) & 0x3c), value); |
483 | 942ac052 | balrog | break;
|
484 | 942ac052 | balrog | |
485 | 942ac052 | balrog | default:
|
486 | 942ac052 | balrog | printf("%s: unknown register at %03x\n",
|
487 | 942ac052 | balrog | __FUNCTION__, (int) (addr & 0xfff)); |
488 | 942ac052 | balrog | return;
|
489 | 942ac052 | balrog | } |
490 | 942ac052 | balrog | } |
491 | 942ac052 | balrog | |
492 | 942ac052 | balrog | static void tusb_async_writew(void *opaque, target_phys_addr_t addr, |
493 | 942ac052 | balrog | uint32_t value) |
494 | 942ac052 | balrog | { |
495 | bc24a225 | Paul Brook | TUSBState *s = (TUSBState *) opaque; |
496 | 942ac052 | balrog | int offset = addr & 0xfff; |
497 | 942ac052 | balrog | int epnum;
|
498 | 942ac052 | balrog | |
499 | 942ac052 | balrog | switch (offset) {
|
500 | 942ac052 | balrog | case TUSB_VLYNQ_CTRL:
|
501 | 942ac052 | balrog | break;
|
502 | 942ac052 | balrog | |
503 | 942ac052 | balrog | case TUSB_BASE_OFFSET ... (TUSB_BASE_OFFSET | 0x1ff): |
504 | 942ac052 | balrog | musb_write[2](s->musb, offset & 0x1ff, value); |
505 | 942ac052 | balrog | break;
|
506 | 942ac052 | balrog | |
507 | 942ac052 | balrog | case TUSB_FIFO_BASE ... (TUSB_FIFO_BASE | 0x1ff): |
508 | 942ac052 | balrog | musb_write[2](s->musb, 0x20 + ((addr >> 3) & 0x3c), value); |
509 | 942ac052 | balrog | break;
|
510 | 942ac052 | balrog | |
511 | 942ac052 | balrog | case TUSB_DEV_CONF:
|
512 | 942ac052 | balrog | s->dev_config = value; |
513 | 942ac052 | balrog | s->host_mode = (value & TUSB_DEV_CONF_USB_HOST_MODE); |
514 | 942ac052 | balrog | if (value & TUSB_DEV_CONF_PROD_TEST_MODE)
|
515 | 2ac71179 | Paul Brook | hw_error("%s: Product Test mode not allowed\n", __FUNCTION__);
|
516 | 942ac052 | balrog | break;
|
517 | 942ac052 | balrog | |
518 | 942ac052 | balrog | case TUSB_PHY_OTG_CTRL_ENABLE:
|
519 | 942ac052 | balrog | case TUSB_PHY_OTG_CTRL:
|
520 | 942ac052 | balrog | return; /* TODO */ |
521 | 942ac052 | balrog | case TUSB_DEV_OTG_TIMER:
|
522 | 942ac052 | balrog | s->otg_timer_val = value; |
523 | 942ac052 | balrog | if (value & TUSB_DEV_OTG_TIMER_ENABLE)
|
524 | 942ac052 | balrog | qemu_mod_timer(s->otg_timer, qemu_get_clock(vm_clock) + |
525 | 942ac052 | balrog | muldiv64(TUSB_DEV_OTG_TIMER_VAL(value), |
526 | 942ac052 | balrog | ticks_per_sec, TUSB_DEVCLOCK)); |
527 | 942ac052 | balrog | else
|
528 | 942ac052 | balrog | qemu_del_timer(s->otg_timer); |
529 | 942ac052 | balrog | break;
|
530 | 942ac052 | balrog | |
531 | 942ac052 | balrog | case TUSB_PRCM_CONF:
|
532 | 942ac052 | balrog | s->prcm_config = value; |
533 | 942ac052 | balrog | break;
|
534 | 942ac052 | balrog | case TUSB_PRCM_MNGMT:
|
535 | 942ac052 | balrog | s->prcm_mngmt = value; |
536 | 942ac052 | balrog | break;
|
537 | 942ac052 | balrog | case TUSB_PRCM_WAKEUP_CLEAR:
|
538 | 942ac052 | balrog | break;
|
539 | 942ac052 | balrog | case TUSB_PRCM_WAKEUP_MASK:
|
540 | 942ac052 | balrog | s->wkup_mask = value; |
541 | 942ac052 | balrog | break;
|
542 | 942ac052 | balrog | |
543 | 942ac052 | balrog | case TUSB_PULLUP_1_CTRL:
|
544 | 942ac052 | balrog | s->pullup[0] = value;
|
545 | 942ac052 | balrog | break;
|
546 | 942ac052 | balrog | case TUSB_PULLUP_2_CTRL:
|
547 | 942ac052 | balrog | s->pullup[1] = value;
|
548 | 942ac052 | balrog | break;
|
549 | 942ac052 | balrog | case TUSB_INT_CTRL_CONF:
|
550 | 942ac052 | balrog | s->control_config = value; |
551 | 942ac052 | balrog | tusb_intr_update(s); |
552 | 942ac052 | balrog | break;
|
553 | 942ac052 | balrog | |
554 | 942ac052 | balrog | case TUSB_USBIP_INT_SET:
|
555 | 942ac052 | balrog | s->usbip_intr |= value; |
556 | 942ac052 | balrog | tusb_usbip_intr_update(s); |
557 | 942ac052 | balrog | break;
|
558 | 942ac052 | balrog | case TUSB_USBIP_INT_CLEAR:
|
559 | 942ac052 | balrog | s->usbip_intr &= ~value; |
560 | 942ac052 | balrog | tusb_usbip_intr_update(s); |
561 | 942ac052 | balrog | musb_core_intr_clear(s->musb, ~value); |
562 | 942ac052 | balrog | break;
|
563 | 942ac052 | balrog | case TUSB_USBIP_INT_MASK:
|
564 | 942ac052 | balrog | s->usbip_mask = value; |
565 | 942ac052 | balrog | tusb_usbip_intr_update(s); |
566 | 942ac052 | balrog | break;
|
567 | 942ac052 | balrog | |
568 | 942ac052 | balrog | case TUSB_DMA_INT_SET:
|
569 | 942ac052 | balrog | s->dma_intr |= value; |
570 | 942ac052 | balrog | tusb_dma_intr_update(s); |
571 | 942ac052 | balrog | break;
|
572 | 942ac052 | balrog | case TUSB_DMA_INT_CLEAR:
|
573 | 942ac052 | balrog | s->dma_intr &= ~value; |
574 | 942ac052 | balrog | tusb_dma_intr_update(s); |
575 | 942ac052 | balrog | break;
|
576 | 942ac052 | balrog | case TUSB_DMA_INT_MASK:
|
577 | 942ac052 | balrog | s->dma_mask = value; |
578 | 942ac052 | balrog | tusb_dma_intr_update(s); |
579 | 942ac052 | balrog | break;
|
580 | 942ac052 | balrog | |
581 | 942ac052 | balrog | case TUSB_GPIO_INT_SET:
|
582 | 942ac052 | balrog | s->gpio_intr |= value; |
583 | 942ac052 | balrog | tusb_gpio_intr_update(s); |
584 | 942ac052 | balrog | break;
|
585 | 942ac052 | balrog | case TUSB_GPIO_INT_CLEAR:
|
586 | 942ac052 | balrog | s->gpio_intr &= ~value; |
587 | 942ac052 | balrog | tusb_gpio_intr_update(s); |
588 | 942ac052 | balrog | break;
|
589 | 942ac052 | balrog | case TUSB_GPIO_INT_MASK:
|
590 | 942ac052 | balrog | s->gpio_mask = value; |
591 | 942ac052 | balrog | tusb_gpio_intr_update(s); |
592 | 942ac052 | balrog | break;
|
593 | 942ac052 | balrog | |
594 | 942ac052 | balrog | case TUSB_INT_SRC_SET:
|
595 | 942ac052 | balrog | s->intr |= value; |
596 | 942ac052 | balrog | tusb_intr_update(s); |
597 | 942ac052 | balrog | break;
|
598 | 942ac052 | balrog | case TUSB_INT_SRC_CLEAR:
|
599 | 942ac052 | balrog | s->intr &= ~value; |
600 | 942ac052 | balrog | tusb_intr_update(s); |
601 | 942ac052 | balrog | break;
|
602 | 942ac052 | balrog | case TUSB_INT_MASK:
|
603 | 942ac052 | balrog | s->mask = value; |
604 | 942ac052 | balrog | tusb_intr_update(s); |
605 | 942ac052 | balrog | break;
|
606 | 942ac052 | balrog | |
607 | 942ac052 | balrog | case TUSB_GPIO_CONF:
|
608 | 942ac052 | balrog | s->gpio_config = value; |
609 | 942ac052 | balrog | break;
|
610 | 942ac052 | balrog | case TUSB_DMA_REQ_CONF:
|
611 | 942ac052 | balrog | s->dma_config = value; |
612 | 942ac052 | balrog | break;
|
613 | 942ac052 | balrog | case TUSB_EP0_CONF:
|
614 | 942ac052 | balrog | s->ep0_config = value & 0x1ff;
|
615 | 942ac052 | balrog | musb_set_size(s->musb, 0, TUSB_EP0_CONFIG_XFR_SIZE(value),
|
616 | 942ac052 | balrog | value & TUSB_EP0_CONFIG_DIR_TX); |
617 | 942ac052 | balrog | break;
|
618 | 942ac052 | balrog | case TUSB_EP_IN_SIZE ... (TUSB_EP_IN_SIZE + 0x3b): |
619 | 942ac052 | balrog | epnum = (offset - TUSB_EP_IN_SIZE) >> 2;
|
620 | 942ac052 | balrog | s->tx_config[epnum] = value; |
621 | 942ac052 | balrog | musb_set_size(s->musb, epnum + 1, TUSB_EP_CONFIG_XFR_SIZE(value), 1); |
622 | 942ac052 | balrog | break;
|
623 | 942ac052 | balrog | case TUSB_DMA_EP_MAP:
|
624 | 942ac052 | balrog | s->dma_map = value; |
625 | 942ac052 | balrog | break;
|
626 | 942ac052 | balrog | case TUSB_EP_OUT_SIZE ... (TUSB_EP_OUT_SIZE + 0x3b): |
627 | 942ac052 | balrog | epnum = (offset - TUSB_EP_OUT_SIZE) >> 2;
|
628 | 942ac052 | balrog | s->rx_config[epnum] = value; |
629 | 942ac052 | balrog | musb_set_size(s->musb, epnum + 1, TUSB_EP_CONFIG_XFR_SIZE(value), 0); |
630 | 942ac052 | balrog | break;
|
631 | 942ac052 | balrog | case TUSB_EP_MAX_PACKET_SIZE_OFFSET ...
|
632 | 942ac052 | balrog | (TUSB_EP_MAX_PACKET_SIZE_OFFSET + 0x3b):
|
633 | 942ac052 | balrog | epnum = (offset - TUSB_EP_MAX_PACKET_SIZE_OFFSET) >> 2;
|
634 | 942ac052 | balrog | return; /* TODO */ |
635 | 942ac052 | balrog | case TUSB_WAIT_COUNT:
|
636 | 942ac052 | balrog | return; /* TODO */ |
637 | 942ac052 | balrog | |
638 | 942ac052 | balrog | case TUSB_SCRATCH_PAD:
|
639 | 942ac052 | balrog | s->scratch = value; |
640 | 942ac052 | balrog | break;
|
641 | 942ac052 | balrog | |
642 | 942ac052 | balrog | case TUSB_PROD_TEST_RESET:
|
643 | 942ac052 | balrog | s->test_reset = value; |
644 | 942ac052 | balrog | break;
|
645 | 942ac052 | balrog | |
646 | 942ac052 | balrog | default:
|
647 | 942ac052 | balrog | printf("%s: unknown register at %03x\n", __FUNCTION__, offset);
|
648 | 942ac052 | balrog | return;
|
649 | 942ac052 | balrog | } |
650 | 942ac052 | balrog | } |
651 | 942ac052 | balrog | |
652 | d60efc6b | Blue Swirl | static CPUReadMemoryFunc * const tusb_async_readfn[] = { |
653 | 942ac052 | balrog | tusb_async_readb, |
654 | 942ac052 | balrog | tusb_async_readh, |
655 | 942ac052 | balrog | tusb_async_readw, |
656 | 942ac052 | balrog | }; |
657 | 942ac052 | balrog | |
658 | d60efc6b | Blue Swirl | static CPUWriteMemoryFunc * const tusb_async_writefn[] = { |
659 | 942ac052 | balrog | tusb_async_writeb, |
660 | 942ac052 | balrog | tusb_async_writeh, |
661 | 942ac052 | balrog | tusb_async_writew, |
662 | 942ac052 | balrog | }; |
663 | 942ac052 | balrog | |
664 | 942ac052 | balrog | static void tusb_otg_tick(void *opaque) |
665 | 942ac052 | balrog | { |
666 | bc24a225 | Paul Brook | TUSBState *s = (TUSBState *) opaque; |
667 | 942ac052 | balrog | |
668 | 942ac052 | balrog | s->otg_timer_val = 0;
|
669 | 942ac052 | balrog | s->intr |= TUSB_INT_SRC_OTG_TIMEOUT; |
670 | 942ac052 | balrog | tusb_intr_update(s); |
671 | 942ac052 | balrog | } |
672 | 942ac052 | balrog | |
673 | 942ac052 | balrog | static void tusb_power_tick(void *opaque) |
674 | 942ac052 | balrog | { |
675 | bc24a225 | Paul Brook | TUSBState *s = (TUSBState *) opaque; |
676 | 942ac052 | balrog | |
677 | 942ac052 | balrog | if (s->power) {
|
678 | 942ac052 | balrog | s->intr_ok = ~0;
|
679 | 942ac052 | balrog | tusb_intr_update(s); |
680 | 942ac052 | balrog | } |
681 | 942ac052 | balrog | } |
682 | 942ac052 | balrog | |
683 | 942ac052 | balrog | static void tusb_musb_core_intr(void *opaque, int source, int level) |
684 | 942ac052 | balrog | { |
685 | bc24a225 | Paul Brook | TUSBState *s = (TUSBState *) opaque; |
686 | 942ac052 | balrog | uint16_t otg_status = s->otg_status; |
687 | 942ac052 | balrog | |
688 | 942ac052 | balrog | switch (source) {
|
689 | 942ac052 | balrog | case musb_set_vbus:
|
690 | 942ac052 | balrog | if (level)
|
691 | 942ac052 | balrog | otg_status |= TUSB_DEV_OTG_STAT_VBUS_VALID; |
692 | 942ac052 | balrog | else
|
693 | 942ac052 | balrog | otg_status &= ~TUSB_DEV_OTG_STAT_VBUS_VALID; |
694 | 942ac052 | balrog | |
695 | 942ac052 | balrog | /* XXX: only if TUSB_PHY_OTG_CTRL_OTG_VBUS_DET_EN set? */
|
696 | 942ac052 | balrog | /* XXX: only if TUSB_PRCM_MNGMT_OTG_VBUS_DET_EN set? */
|
697 | 942ac052 | balrog | if (s->otg_status != otg_status) {
|
698 | 942ac052 | balrog | s->otg_status = otg_status; |
699 | 942ac052 | balrog | s->intr |= TUSB_INT_SRC_VBUS_SENSE_CHNG; |
700 | 942ac052 | balrog | tusb_intr_update(s); |
701 | 942ac052 | balrog | } |
702 | 942ac052 | balrog | break;
|
703 | 942ac052 | balrog | |
704 | 942ac052 | balrog | case musb_set_session:
|
705 | 942ac052 | balrog | /* XXX: only if TUSB_PHY_OTG_CTRL_OTG_SESS_END_EN set? */
|
706 | 942ac052 | balrog | /* XXX: only if TUSB_PRCM_MNGMT_OTG_SESS_END_EN set? */
|
707 | 942ac052 | balrog | if (level) {
|
708 | 942ac052 | balrog | s->otg_status |= TUSB_DEV_OTG_STAT_SESS_VALID; |
709 | 942ac052 | balrog | s->otg_status &= ~TUSB_DEV_OTG_STAT_SESS_END; |
710 | 942ac052 | balrog | } else {
|
711 | 942ac052 | balrog | s->otg_status &= ~TUSB_DEV_OTG_STAT_SESS_VALID; |
712 | 942ac052 | balrog | s->otg_status |= TUSB_DEV_OTG_STAT_SESS_END; |
713 | 942ac052 | balrog | } |
714 | 942ac052 | balrog | |
715 | 942ac052 | balrog | /* XXX: some IRQ or anything? */
|
716 | 942ac052 | balrog | break;
|
717 | 942ac052 | balrog | |
718 | 942ac052 | balrog | case musb_irq_tx:
|
719 | 942ac052 | balrog | case musb_irq_rx:
|
720 | 942ac052 | balrog | s->usbip_intr = musb_core_intr_get(s->musb); |
721 | 942ac052 | balrog | /* Fall through. */
|
722 | 942ac052 | balrog | default:
|
723 | 942ac052 | balrog | if (level)
|
724 | 942ac052 | balrog | s->intr |= 1 << source;
|
725 | 942ac052 | balrog | else
|
726 | 942ac052 | balrog | s->intr &= ~(1 << source);
|
727 | 942ac052 | balrog | tusb_intr_update(s); |
728 | 942ac052 | balrog | break;
|
729 | 942ac052 | balrog | } |
730 | 942ac052 | balrog | } |
731 | 942ac052 | balrog | |
732 | bc24a225 | Paul Brook | TUSBState *tusb6010_init(qemu_irq intr) |
733 | 942ac052 | balrog | { |
734 | bc24a225 | Paul Brook | TUSBState *s = qemu_mallocz(sizeof(*s));
|
735 | 942ac052 | balrog | |
736 | 942ac052 | balrog | s->test_reset = TUSB_PROD_TEST_RESET_VAL; |
737 | 942ac052 | balrog | s->host_mode = 0;
|
738 | 942ac052 | balrog | s->dev_config = 0;
|
739 | 942ac052 | balrog | s->otg_status = 0; /* !TUSB_DEV_OTG_STAT_ID_STATUS means host mode */ |
740 | 942ac052 | balrog | s->power = 0;
|
741 | 942ac052 | balrog | s->mask = 0xffffffff;
|
742 | 942ac052 | balrog | s->intr = 0x00000000;
|
743 | 942ac052 | balrog | s->otg_timer_val = 0;
|
744 | 1eed09cb | Avi Kivity | s->iomemtype[1] = cpu_register_io_memory(tusb_async_readfn,
|
745 | 942ac052 | balrog | tusb_async_writefn, s); |
746 | 942ac052 | balrog | s->irq = intr; |
747 | 942ac052 | balrog | s->otg_timer = qemu_new_timer(vm_clock, tusb_otg_tick, s); |
748 | 942ac052 | balrog | s->pwr_timer = qemu_new_timer(vm_clock, tusb_power_tick, s); |
749 | 942ac052 | balrog | s->musb = musb_init(qemu_allocate_irqs(tusb_musb_core_intr, s, |
750 | 942ac052 | balrog | __musb_irq_max)); |
751 | 942ac052 | balrog | |
752 | 942ac052 | balrog | return s;
|
753 | 942ac052 | balrog | } |
754 | 942ac052 | balrog | |
755 | bc24a225 | Paul Brook | void tusb6010_power(TUSBState *s, int on) |
756 | 942ac052 | balrog | { |
757 | 942ac052 | balrog | if (!on)
|
758 | 942ac052 | balrog | s->power = 0;
|
759 | 942ac052 | balrog | else if (!s->power && on) { |
760 | 942ac052 | balrog | s->power = 1;
|
761 | 942ac052 | balrog | |
762 | 942ac052 | balrog | /* Pull the interrupt down after TUSB6010 comes up. */
|
763 | 942ac052 | balrog | s->intr_ok = 0;
|
764 | 942ac052 | balrog | tusb_intr_update(s); |
765 | 942ac052 | balrog | qemu_mod_timer(s->pwr_timer, |
766 | 942ac052 | balrog | qemu_get_clock(vm_clock) + ticks_per_sec / 2);
|
767 | 942ac052 | balrog | } |
768 | 942ac052 | balrog | } |