David Brownell | cece6e5 | 2008-09-07 23:41:57 -0700 | [diff] [blame] | 1 | /* |
| 2 | * USB |
| 3 | */ |
David Brownell | cece6e5 | 2008-09-07 23:41:57 -0700 | [diff] [blame] | 4 | #include <linux/init.h> |
| 5 | #include <linux/platform_device.h> |
| 6 | #include <linux/dma-mapping.h> |
| 7 | |
| 8 | #include <linux/usb/musb.h> |
David Brownell | cece6e5 | 2008-09-07 23:41:57 -0700 | [diff] [blame] | 9 | |
| 10 | #include <mach/common.h> |
David Brownell | d0e58ae | 2009-01-18 17:29:10 +0100 | [diff] [blame] | 11 | #include <mach/irqs.h> |
Sergei Shtylyov | efd9118 | 2009-07-16 19:58:53 +0400 | [diff] [blame] | 12 | #include <mach/cputype.h> |
Sergei Shtylyov | e5d3d25 | 2009-09-25 23:14:02 +0400 | [diff] [blame] | 13 | #include <mach/usb.h> |
David Brownell | cece6e5 | 2008-09-07 23:41:57 -0700 | [diff] [blame] | 14 | |
Sergei Shtylyov | e5d3d25 | 2009-09-25 23:14:02 +0400 | [diff] [blame] | 15 | #define DAVINCI_USB_OTG_BASE 0x01c64000 |
Sergei Shtylyov | b0ea26e | 2009-10-30 23:49:44 +0400 | [diff] [blame] | 16 | |
| 17 | #define DA8XX_USB0_BASE 0x01e00000 |
Sergei Shtylyov | e5d3d25 | 2009-09-25 23:14:02 +0400 | [diff] [blame] | 18 | #define DA8XX_USB1_BASE 0x01e25000 |
Kevin Hilman | f5c122d | 2009-04-14 07:04:16 -0500 | [diff] [blame] | 19 | |
David Brownell | cece6e5 | 2008-09-07 23:41:57 -0700 | [diff] [blame] | 20 | #if defined(CONFIG_USB_MUSB_HDRC) || defined(CONFIG_USB_MUSB_HDRC_MODULE) |
| 21 | static struct musb_hdrc_eps_bits musb_eps[] = { |
| 22 | { "ep1_tx", 8, }, |
| 23 | { "ep1_rx", 8, }, |
| 24 | { "ep2_tx", 8, }, |
| 25 | { "ep2_rx", 8, }, |
| 26 | { "ep3_tx", 5, }, |
| 27 | { "ep3_rx", 5, }, |
| 28 | { "ep4_tx", 5, }, |
| 29 | { "ep4_rx", 5, }, |
| 30 | }; |
| 31 | |
| 32 | static struct musb_hdrc_config musb_config = { |
| 33 | .multipoint = true, |
| 34 | .dyn_fifo = true, |
| 35 | .soft_con = true, |
| 36 | .dma = true, |
| 37 | |
| 38 | .num_eps = 5, |
| 39 | .dma_channels = 8, |
| 40 | .ram_bits = 10, |
| 41 | .eps_bits = musb_eps, |
| 42 | }; |
| 43 | |
| 44 | static struct musb_hdrc_platform_data usb_data = { |
| 45 | #if defined(CONFIG_USB_MUSB_OTG) |
| 46 | /* OTG requires a Mini-AB connector */ |
| 47 | .mode = MUSB_OTG, |
| 48 | #elif defined(CONFIG_USB_MUSB_PERIPHERAL) |
| 49 | .mode = MUSB_PERIPHERAL, |
| 50 | #elif defined(CONFIG_USB_MUSB_HOST) |
| 51 | .mode = MUSB_HOST, |
| 52 | #endif |
David Brownell | 34f32c9 | 2009-02-20 13:45:17 -0800 | [diff] [blame] | 53 | .clock = "usb", |
David Brownell | cece6e5 | 2008-09-07 23:41:57 -0700 | [diff] [blame] | 54 | .config = &musb_config, |
| 55 | }; |
| 56 | |
| 57 | static struct resource usb_resources[] = { |
| 58 | { |
| 59 | /* physical address */ |
| 60 | .start = DAVINCI_USB_OTG_BASE, |
| 61 | .end = DAVINCI_USB_OTG_BASE + 0x5ff, |
| 62 | .flags = IORESOURCE_MEM, |
| 63 | }, |
| 64 | { |
| 65 | .start = IRQ_USBINT, |
| 66 | .flags = IORESOURCE_IRQ, |
| 67 | }, |
Sergei Shtylyov | efd9118 | 2009-07-16 19:58:53 +0400 | [diff] [blame] | 68 | { |
| 69 | /* placeholder for the dedicated CPPI IRQ */ |
| 70 | .flags = IORESOURCE_IRQ, |
| 71 | }, |
David Brownell | cece6e5 | 2008-09-07 23:41:57 -0700 | [diff] [blame] | 72 | }; |
| 73 | |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 74 | static u64 usb_dmamask = DMA_BIT_MASK(32); |
David Brownell | cece6e5 | 2008-09-07 23:41:57 -0700 | [diff] [blame] | 75 | |
| 76 | static struct platform_device usb_dev = { |
| 77 | .name = "musb_hdrc", |
| 78 | .id = -1, |
| 79 | .dev = { |
| 80 | .platform_data = &usb_data, |
| 81 | .dma_mask = &usb_dmamask, |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 82 | .coherent_dma_mask = DMA_BIT_MASK(32), |
David Brownell | cece6e5 | 2008-09-07 23:41:57 -0700 | [diff] [blame] | 83 | }, |
| 84 | .resource = usb_resources, |
| 85 | .num_resources = ARRAY_SIZE(usb_resources), |
| 86 | }; |
| 87 | |
Sergei Shtylyov | 355fb4e | 2009-10-30 23:46:14 +0400 | [diff] [blame] | 88 | void __init davinci_setup_usb(unsigned mA, unsigned potpgt_ms) |
David Brownell | cece6e5 | 2008-09-07 23:41:57 -0700 | [diff] [blame] | 89 | { |
Sergei Shtylyov | 355fb4e | 2009-10-30 23:46:14 +0400 | [diff] [blame] | 90 | usb_data.power = mA > 510 ? 255 : mA / 2; |
| 91 | usb_data.potpgt = (potpgt_ms + 1) / 2; |
Sergei Shtylyov | efd9118 | 2009-07-16 19:58:53 +0400 | [diff] [blame] | 92 | |
| 93 | if (cpu_is_davinci_dm646x()) { |
| 94 | /* Override the defaults as DM6467 uses different IRQs. */ |
| 95 | usb_dev.resource[1].start = IRQ_DM646X_USBINT; |
| 96 | usb_dev.resource[2].start = IRQ_DM646X_USBDMAINT; |
| 97 | } else /* other devices don't have dedicated CPPI IRQ */ |
| 98 | usb_dev.num_resources = 2; |
| 99 | |
David Brownell | cece6e5 | 2008-09-07 23:41:57 -0700 | [diff] [blame] | 100 | platform_device_register(&usb_dev); |
| 101 | } |
| 102 | |
Sergei Shtylyov | b0ea26e | 2009-10-30 23:49:44 +0400 | [diff] [blame] | 103 | #ifdef CONFIG_ARCH_DAVINCI_DA8XX |
| 104 | static struct resource da8xx_usb20_resources[] = { |
| 105 | { |
| 106 | .start = DA8XX_USB0_BASE, |
| 107 | .end = DA8XX_USB0_BASE + SZ_64K - 1, |
| 108 | .flags = IORESOURCE_MEM, |
| 109 | }, |
| 110 | { |
| 111 | .start = IRQ_DA8XX_USB_INT, |
| 112 | .flags = IORESOURCE_IRQ, |
| 113 | }, |
| 114 | }; |
| 115 | |
| 116 | int __init da8xx_register_usb20(unsigned mA, unsigned potpgt) |
| 117 | { |
| 118 | usb_data.clock = "usb20"; |
| 119 | usb_data.power = mA > 510 ? 255 : mA / 2; |
| 120 | usb_data.potpgt = (potpgt + 1) / 2; |
| 121 | |
| 122 | usb_dev.resource = da8xx_usb20_resources; |
| 123 | usb_dev.num_resources = ARRAY_SIZE(da8xx_usb20_resources); |
| 124 | |
| 125 | return platform_device_register(&usb_dev); |
| 126 | } |
| 127 | #endif /* CONFIG_DAVINCI_DA8XX */ |
| 128 | |
David Brownell | cece6e5 | 2008-09-07 23:41:57 -0700 | [diff] [blame] | 129 | #else |
| 130 | |
Sergei Shtylyov | 355fb4e | 2009-10-30 23:46:14 +0400 | [diff] [blame] | 131 | void __init davinci_setup_usb(unsigned mA, unsigned potpgt_ms) |
David Brownell | cece6e5 | 2008-09-07 23:41:57 -0700 | [diff] [blame] | 132 | { |
| 133 | } |
| 134 | |
Sergei Shtylyov | b0ea26e | 2009-10-30 23:49:44 +0400 | [diff] [blame] | 135 | #ifdef CONFIG_ARCH_DAVINCI_DA8XX |
| 136 | int __init da8xx_register_usb20(unsigned mA, unsigned potpgt) |
| 137 | { |
| 138 | return 0; |
| 139 | } |
| 140 | #endif |
| 141 | |
David Brownell | cece6e5 | 2008-09-07 23:41:57 -0700 | [diff] [blame] | 142 | #endif /* CONFIG_USB_MUSB_HDRC */ |
| 143 | |
Sergei Shtylyov | e5d3d25 | 2009-09-25 23:14:02 +0400 | [diff] [blame] | 144 | #ifdef CONFIG_ARCH_DAVINCI_DA8XX |
| 145 | static struct resource da8xx_usb11_resources[] = { |
| 146 | [0] = { |
| 147 | .start = DA8XX_USB1_BASE, |
| 148 | .end = DA8XX_USB1_BASE + SZ_4K - 1, |
| 149 | .flags = IORESOURCE_MEM, |
| 150 | }, |
| 151 | [1] = { |
| 152 | .start = IRQ_DA8XX_IRQN, |
| 153 | .end = IRQ_DA8XX_IRQN, |
| 154 | .flags = IORESOURCE_IRQ, |
| 155 | }, |
| 156 | }; |
| 157 | |
| 158 | static u64 da8xx_usb11_dma_mask = DMA_BIT_MASK(32); |
| 159 | |
| 160 | static struct platform_device da8xx_usb11_device = { |
| 161 | .name = "ohci", |
| 162 | .id = 0, |
| 163 | .dev = { |
| 164 | .dma_mask = &da8xx_usb11_dma_mask, |
| 165 | .coherent_dma_mask = DMA_BIT_MASK(32), |
| 166 | }, |
| 167 | .num_resources = ARRAY_SIZE(da8xx_usb11_resources), |
| 168 | .resource = da8xx_usb11_resources, |
| 169 | }; |
| 170 | |
| 171 | int __init da8xx_register_usb11(struct da8xx_ohci_root_hub *pdata) |
| 172 | { |
| 173 | da8xx_usb11_device.dev.platform_data = pdata; |
| 174 | return platform_device_register(&da8xx_usb11_device); |
| 175 | } |
| 176 | #endif /* CONFIG_DAVINCI_DA8XX */ |