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