Merge tag 'xfs-5.1-merge-5' of git://git.kernel.org/pub/scm/fs/xfs/xfs-linux
[sfrench/cifs-2.6.git] / arch / arm / mach-davinci / usb-da8xx.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * DA8xx USB
4  */
5 #include <linux/clk-provider.h>
6 #include <linux/delay.h>
7 #include <linux/dma-mapping.h>
8 #include <linux/init.h>
9 #include <linux/mfd/da8xx-cfgchip.h>
10 #include <linux/mfd/syscon.h>
11 #include <linux/phy/phy.h>
12 #include <linux/platform_data/clk-da8xx-cfgchip.h>
13 #include <linux/platform_data/phy-da8xx-usb.h>
14 #include <linux/platform_data/usb-davinci.h>
15 #include <linux/platform_device.h>
16 #include <linux/usb/musb.h>
17
18 #include <mach/common.h>
19 #include <mach/cputype.h>
20 #include <mach/da8xx.h>
21
22 #include "irqs.h"
23
24 #define DA8XX_USB0_BASE         0x01e00000
25 #define DA8XX_USB1_BASE         0x01e25000
26
27 #ifndef CONFIG_COMMON_CLK
28 static struct clk *usb20_clk;
29 #endif
30
31 static struct da8xx_usb_phy_platform_data da8xx_usb_phy_pdata;
32
33 static struct platform_device da8xx_usb_phy = {
34         .name           = "da8xx-usb-phy",
35         .id             = -1,
36         .dev            = {
37                 /*
38                  * Setting init_name so that clock lookup will work in
39                  * da8xx_register_usb11_phy_clk() even if this device is not
40                  * registered yet.
41                  */
42                 .init_name      = "da8xx-usb-phy",
43                 .platform_data  = &da8xx_usb_phy_pdata,
44         },
45 };
46
47 int __init da8xx_register_usb_phy(void)
48 {
49         da8xx_usb_phy_pdata.cfgchip = da8xx_get_cfgchip();
50
51         return platform_device_register(&da8xx_usb_phy);
52 }
53
54 static struct musb_hdrc_config musb_config = {
55         .multipoint     = true,
56         .num_eps        = 5,
57         .ram_bits       = 10,
58 };
59
60 static struct musb_hdrc_platform_data usb_data = {
61         /* OTG requires a Mini-AB connector */
62         .mode           = MUSB_OTG,
63         .clock          = "usb20",
64         .config         = &musb_config,
65 };
66
67 static struct resource da8xx_usb20_resources[] = {
68         {
69                 .start          = DA8XX_USB0_BASE,
70                 .end            = DA8XX_USB0_BASE + SZ_64K - 1,
71                 .flags          = IORESOURCE_MEM,
72         },
73         {
74                 .start          = DAVINCI_INTC_IRQ(IRQ_DA8XX_USB_INT),
75                 .flags          = IORESOURCE_IRQ,
76                 .name           = "mc",
77         },
78 };
79
80 static u64 usb_dmamask = DMA_BIT_MASK(32);
81
82 static struct platform_device da8xx_usb20_dev = {
83         .name           = "musb-da8xx",
84         .id             = -1,
85         .dev = {
86                 .platform_data          = &usb_data,
87                 .dma_mask               = &usb_dmamask,
88                 .coherent_dma_mask      = DMA_BIT_MASK(32),
89         },
90         .resource       = da8xx_usb20_resources,
91         .num_resources  = ARRAY_SIZE(da8xx_usb20_resources),
92 };
93
94 int __init da8xx_register_usb20(unsigned int mA, unsigned int potpgt)
95 {
96         usb_data.power  = mA > 510 ? 255 : mA / 2;
97         usb_data.potpgt = (potpgt + 1) / 2;
98
99         return platform_device_register(&da8xx_usb20_dev);
100 }
101
102 static struct resource da8xx_usb11_resources[] = {
103         [0] = {
104                 .start  = DA8XX_USB1_BASE,
105                 .end    = DA8XX_USB1_BASE + SZ_4K - 1,
106                 .flags  = IORESOURCE_MEM,
107         },
108         [1] = {
109                 .start  = DAVINCI_INTC_IRQ(IRQ_DA8XX_IRQN),
110                 .end    = DAVINCI_INTC_IRQ(IRQ_DA8XX_IRQN),
111                 .flags  = IORESOURCE_IRQ,
112         },
113 };
114
115 static u64 da8xx_usb11_dma_mask = DMA_BIT_MASK(32);
116
117 static struct platform_device da8xx_usb11_device = {
118         .name           = "ohci-da8xx",
119         .id             = -1,
120         .dev = {
121                 .dma_mask               = &da8xx_usb11_dma_mask,
122                 .coherent_dma_mask      = DMA_BIT_MASK(32),
123         },
124         .num_resources  = ARRAY_SIZE(da8xx_usb11_resources),
125         .resource       = da8xx_usb11_resources,
126 };
127
128 int __init da8xx_register_usb11(struct da8xx_ohci_root_hub *pdata)
129 {
130         da8xx_usb11_device.dev.platform_data = pdata;
131         return platform_device_register(&da8xx_usb11_device);
132 }
133
134 static struct platform_device da8xx_usb_phy_clks_device = {
135         .name           = "da830-usb-phy-clks",
136         .id             = -1,
137 };
138
139 int __init da8xx_register_usb_phy_clocks(void)
140 {
141         struct da8xx_cfgchip_clk_platform_data pdata;
142
143         pdata.cfgchip = da8xx_get_cfgchip();
144         da8xx_usb_phy_clks_device.dev.platform_data = &pdata;
145
146         return platform_device_register(&da8xx_usb_phy_clks_device);
147 }