2 * arch/nios2nommu/kernel/usb.c -- platform level USB initialization
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include <linux/module.h>
22 #include <linux/kernel.h>
23 #include <linux/types.h>
24 #include <linux/errno.h>
25 #include <linux/init.h>
26 #include <linux/platform_device.h>
27 #include <linux/delay.h>
31 #include <asm/system.h>
34 #if defined(CONFIG_USB_SL811_HCD) || defined (CONFIG_USB_SL811_HCD_MODULE)
35 #if defined(CONFIG_MICROTRONIX_STRATIX) || defined (CONFIG_MICROTRONIX_CYCLONE)
37 #include <linux/usb_sl811.h>
38 #define SL811_ADDR ((unsigned int)na_usb)
39 #define SL811_IRQ na_usb_irq
41 static void sl811_port_power(struct device
*dev
, int is_on
)
45 static void sl811_port_reset(struct device
*dev
)
47 writeb(0xA, (SL811_ADDR
+8));
49 writeb(4, (SL811_ADDR
+8));
52 static struct resource sl811hs_resources
[] = {
54 .start
= (SL811_ADDR
),
55 .end
= (SL811_ADDR
+ 3),
56 .flags
= IORESOURCE_MEM
,
59 .start
= (SL811_ADDR
+ 4),
60 .end
= (SL811_ADDR
+ 7),
61 .flags
= IORESOURCE_MEM
,
65 .flags
= IORESOURCE_IRQ
,
69 static struct sl811_platform_data sl811_data
= {
73 .port_power
= sl811_port_power
,
74 .reset
= sl811_port_reset
,
77 static struct platform_device sl811hs_device
= {
81 //.release = usb_release,
82 //.dma_mask = &ohci_dmamask,
83 .coherent_dma_mask
= 0x0fffffff,
84 .platform_data
= &sl811_data
,
86 .num_resources
= ARRAY_SIZE(sl811hs_resources
),
87 .resource
= sl811hs_resources
,
91 static int __init
mtx_kit_usb_init(void)
95 status
= platform_device_register(&sl811hs_device
);
97 pr_debug("can't register sl811hs device, %d\n", status
);
101 writeb(4, (SL811_ADDR
+8));
105 subsys_initcall(mtx_kit_usb_init
);
106 #endif /* (CONFIG_MICROTRONIX_STRATIX) || (CONFIG_MICROTRONIX_CYCLONE)*/
107 #endif /*(CONFIG_USB_SL811_HCD) ||(CONFIG_USB_SL811_HCD_MODULE) */
109 #if defined(CONFIG_USB_ISP116X_HCD) || defined (CONFIG_USB_ISP116X_HCD_MODULE)
111 #include <linux/usb_isp116x.h>
113 #define ISP116X_HCD_ADDR ((unsigned int)na_usb)
114 #define ISP116X_HCD_IRQ na_usb_irq
116 static void isp116x_delay(struct device
*dev
, int delay
)
121 static struct resource isp116x_hcd_resources
[] = {
123 .start
= (ISP116X_HCD_ADDR
),
124 .end
= (ISP116X_HCD_ADDR
+ 3),
125 .flags
= IORESOURCE_MEM
,
128 .start
= (ISP116X_HCD_ADDR
+ 4),
129 .end
= (ISP116X_HCD_ADDR
+ 7),
130 .flags
= IORESOURCE_MEM
,
133 .start
= ISP116X_HCD_IRQ
,
134 .flags
= IORESOURCE_IRQ
,
138 static struct isp116x_platform_data isp116x_data
= {
139 // Enable internal resistors on downstream ports
141 // Clock cannot be stopped
143 // On-chip overcurrent protection
145 // INT output polarity
147 // INT edge or level triggered
148 .int_edge_triggered
= 0,
149 // End-of-transfer input polarity
151 // DREQ output polarity
153 // WAKEUP pin connected
154 .remote_wakeup_connected
= 0,
155 // Wakeup by devices on usb bus enabled
156 .remote_wakeup_enable
= 0,
157 // Switch or not to switch (keep always powered)
158 .no_power_switching
= 1,
159 // Ganged port power switching (0) or individual port power switching (1)
160 .power_switching_mode
= 0,
161 .reset
= NULL
/* isp116x_reset */,
162 .delay
= isp116x_delay
,
165 static struct platform_device isp116x_hcd
= {
166 .name
= "isp116x-hcd",
169 //.release = usb_release,
170 //.dma_mask = &ohci_dmamask,
171 .coherent_dma_mask
= 0x0fffffff,
172 .platform_data
= &isp116x_data
,
174 .num_resources
= ARRAY_SIZE(isp116x_hcd_resources
),
175 .resource
= isp116x_hcd_resources
,
178 static int __init
usb_hcd_init(void)
182 status
= platform_device_register(&isp116x_hcd
);
184 pr_debug("can't register isp116x host controller, %d\n", status
);
190 subsys_initcall(usb_hcd_init
);
191 #endif /*(CONFIG_USB_ISP116X_HCD) ||(CONFIG_USB_ISP116X_HCD_MODULE) */
193 #if defined(CONFIG_USB_ISP1161X) || defined(CONFIG_USB_ISP1161X_MODULE)
194 #include <linux/usb_isp116x_dc.h>
196 #define ISP116X_UDC_ADDR ((unsigned int)na_usb+8)
197 #define ISP116X_UDC_IRQ na_int2_usb_irq
199 static struct resource isp116x_udc_resources
[] = {
201 .start
= (ISP116X_UDC_ADDR
),
202 .end
= (ISP116X_UDC_ADDR
+ 3),
203 .flags
= IORESOURCE_MEM
,
206 .start
= (ISP116X_UDC_ADDR
+ 4),
207 .end
= (ISP116X_UDC_ADDR
+ 7),
208 .flags
= IORESOURCE_MEM
,
211 .start
= ISP116X_UDC_IRQ
,
212 .flags
= IORESOURCE_IRQ
,
215 static void isp116x_udc_delay()
217 __asm__
__volatile__(
219 " beq %0,zero,2f\n\t"
220 " addi %0, %0, -1\n\t"
224 : "r" (nasys_clock_freq_1000
* 180 / 2000000)
228 struct isp116x_dc_platform_data isp116x_udc_data
= {
229 .ext_pullup_enable
=0,
232 .remote_wakeup_enable
=1,
233 .power_off_enable
=1,
234 .int_edge_triggered
=0,
237 .delay
= isp116x_udc_delay
240 static struct platform_device isp116x_udc
= {
241 .name
= "isp1161a_udc",
244 //.release = usb_release,
245 //.dma_mask = &ohci_dmamask,
246 .coherent_dma_mask
= 0x0fffffff,
247 .platform_data
= &isp116x_udc_data
,
249 .num_resources
= ARRAY_SIZE(isp116x_udc_resources
),
250 .resource
= isp116x_udc_resources
,
253 static int __init
usb_udc_init(void)
258 status
= platform_device_register(&isp116x_udc
);
260 pr_debug("can't register isp116x device controller, %d\n", status
);
264 /* enable interrupts */
265 pio
= (np_pio
*)na_int2_usb
;
266 //outw(0, &pio->np_piodata);
267 //outw(0, &pio->np_pioedgecapture);
268 outw(1, &pio
->np_piointerruptmask
);
272 subsys_initcall(usb_udc_init
);
275 #if defined(na_ISP1362_avalonS) // for DE2 dev board, FIX ME otehrwise
276 #define na_usb na_ISP1362_avalonS
277 #define na_usb_irq na_ISP1362_avalonS_irq
280 #if defined(na_ISP1362_avalon_slave_0) // for DE2 dev board, FIX ME otehrwise
281 #define na_usb na_ISP1362_avalon_slave_0
282 #define na_usb_irq na_ISP1362_avalon_slave_0_irq
285 #if defined(CONFIG_USB_ISP1362_HCD) && defined(na_usb)
287 #include <linux/usb_isp1362.h>
288 #define ISP1362_HCD_ADDR ((unsigned int)na_usb)
289 #define ISP1362_HCD_IRQ na_usb_irq
291 static struct resource isp1362_hcd_resources
[] = {
293 .start
= (ISP1362_HCD_ADDR
),
294 .end
= (ISP1362_HCD_ADDR
+ 3),
295 .flags
= IORESOURCE_MEM
,
298 .start
= (ISP1362_HCD_ADDR
+ 4),
299 .end
= (ISP1362_HCD_ADDR
+ 7),
300 .flags
= IORESOURCE_MEM
,
303 .start
= ISP1362_HCD_IRQ
,
304 .flags
= IORESOURCE_IRQ
,
308 static struct isp1362_platform_data isp1362_data
= {
309 // Enable internal resistors on downstream ports
311 // Clock cannot be stopped
313 // On-chip overcurrent protection
315 // INT output polarity
317 // INT edge or level triggered
318 .int_edge_triggered
= 0,
319 // WAKEUP pin connected
320 .remote_wakeup_connected
= 0,
321 // Switch or not to switch (keep always powered)
322 .no_power_switching
= 1,
323 // Ganged port power switching (0) or individual port power switching (1)
324 .power_switching_mode
= 0,
327 static struct platform_device isp1362_hcd
= {
328 .name
= "isp1362-hcd",
331 //.release = usb_release,
332 //.dma_mask = &ohci_dmamask,
333 .coherent_dma_mask
= 0x0fffffff,
334 .platform_data
= &isp1362_data
,
336 .num_resources
= ARRAY_SIZE(isp1362_hcd_resources
),
337 .resource
= isp1362_hcd_resources
,
340 static int __init
usb_hcd_init(void)
344 status
= platform_device_register(&isp1362_hcd
);
346 pr_debug("can't register isp1362 host controller, %d\n", status
);
352 subsys_initcall(usb_hcd_init
);