18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (C) 2011 Marvell International Ltd. All rights reserved. 48c2ecf20Sopenharmony_ci * Copyright (C) 2018 Lubomir Rintel <lkundrak@v3.sk> 58c2ecf20Sopenharmony_ci */ 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci#include <dt-bindings/phy/phy.h> 88c2ecf20Sopenharmony_ci#include <linux/clk.h> 98c2ecf20Sopenharmony_ci#include <linux/delay.h> 108c2ecf20Sopenharmony_ci#include <linux/io.h> 118c2ecf20Sopenharmony_ci#include <linux/module.h> 128c2ecf20Sopenharmony_ci#include <linux/of_address.h> 138c2ecf20Sopenharmony_ci#include <linux/phy/phy.h> 148c2ecf20Sopenharmony_ci#include <linux/platform_device.h> 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_ci/* phy regs */ 178c2ecf20Sopenharmony_ci#define UTMI_REVISION 0x0 188c2ecf20Sopenharmony_ci#define UTMI_CTRL 0x4 198c2ecf20Sopenharmony_ci#define UTMI_PLL 0x8 208c2ecf20Sopenharmony_ci#define UTMI_TX 0xc 218c2ecf20Sopenharmony_ci#define UTMI_RX 0x10 228c2ecf20Sopenharmony_ci#define UTMI_IVREF 0x14 238c2ecf20Sopenharmony_ci#define UTMI_T0 0x18 248c2ecf20Sopenharmony_ci#define UTMI_T1 0x1c 258c2ecf20Sopenharmony_ci#define UTMI_T2 0x20 268c2ecf20Sopenharmony_ci#define UTMI_T3 0x24 278c2ecf20Sopenharmony_ci#define UTMI_T4 0x28 288c2ecf20Sopenharmony_ci#define UTMI_T5 0x2c 298c2ecf20Sopenharmony_ci#define UTMI_RESERVE 0x30 308c2ecf20Sopenharmony_ci#define UTMI_USB_INT 0x34 318c2ecf20Sopenharmony_ci#define UTMI_DBG_CTL 0x38 328c2ecf20Sopenharmony_ci#define UTMI_OTG_ADDON 0x3c 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ci/* For UTMICTRL Register */ 358c2ecf20Sopenharmony_ci#define UTMI_CTRL_USB_CLK_EN (1 << 31) 368c2ecf20Sopenharmony_ci/* pxa168 */ 378c2ecf20Sopenharmony_ci#define UTMI_CTRL_SUSPEND_SET1 (1 << 30) 388c2ecf20Sopenharmony_ci#define UTMI_CTRL_SUSPEND_SET2 (1 << 29) 398c2ecf20Sopenharmony_ci#define UTMI_CTRL_RXBUF_PDWN (1 << 24) 408c2ecf20Sopenharmony_ci#define UTMI_CTRL_TXBUF_PDWN (1 << 11) 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci#define UTMI_CTRL_INPKT_DELAY_SHIFT 30 438c2ecf20Sopenharmony_ci#define UTMI_CTRL_INPKT_DELAY_SOF_SHIFT 28 448c2ecf20Sopenharmony_ci#define UTMI_CTRL_PU_REF_SHIFT 20 458c2ecf20Sopenharmony_ci#define UTMI_CTRL_ARC_PULLDN_SHIFT 12 468c2ecf20Sopenharmony_ci#define UTMI_CTRL_PLL_PWR_UP_SHIFT 1 478c2ecf20Sopenharmony_ci#define UTMI_CTRL_PWR_UP_SHIFT 0 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_ci/* For UTMI_PLL Register */ 508c2ecf20Sopenharmony_ci#define UTMI_PLL_PLLCALI12_SHIFT 29 518c2ecf20Sopenharmony_ci#define UTMI_PLL_PLLCALI12_MASK (0x3 << 29) 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_ci#define UTMI_PLL_PLLVDD18_SHIFT 27 548c2ecf20Sopenharmony_ci#define UTMI_PLL_PLLVDD18_MASK (0x3 << 27) 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ci#define UTMI_PLL_PLLVDD12_SHIFT 25 578c2ecf20Sopenharmony_ci#define UTMI_PLL_PLLVDD12_MASK (0x3 << 25) 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ci#define UTMI_PLL_CLK_BLK_EN_SHIFT 24 608c2ecf20Sopenharmony_ci#define CLK_BLK_EN (0x1 << 24) 618c2ecf20Sopenharmony_ci#define PLL_READY (0x1 << 23) 628c2ecf20Sopenharmony_ci#define KVCO_EXT (0x1 << 22) 638c2ecf20Sopenharmony_ci#define VCOCAL_START (0x1 << 21) 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_ci#define UTMI_PLL_KVCO_SHIFT 15 668c2ecf20Sopenharmony_ci#define UTMI_PLL_KVCO_MASK (0x7 << 15) 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_ci#define UTMI_PLL_ICP_SHIFT 12 698c2ecf20Sopenharmony_ci#define UTMI_PLL_ICP_MASK (0x7 << 12) 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_ci#define UTMI_PLL_FBDIV_SHIFT 4 728c2ecf20Sopenharmony_ci#define UTMI_PLL_FBDIV_MASK (0xFF << 4) 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_ci#define UTMI_PLL_REFDIV_SHIFT 0 758c2ecf20Sopenharmony_ci#define UTMI_PLL_REFDIV_MASK (0xF << 0) 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_ci/* For UTMI_TX Register */ 788c2ecf20Sopenharmony_ci#define UTMI_TX_REG_EXT_FS_RCAL_SHIFT 27 798c2ecf20Sopenharmony_ci#define UTMI_TX_REG_EXT_FS_RCAL_MASK (0xf << 27) 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_ci#define UTMI_TX_REG_EXT_FS_RCAL_EN_SHIFT 26 828c2ecf20Sopenharmony_ci#define UTMI_TX_REG_EXT_FS_RCAL_EN_MASK (0x1 << 26) 838c2ecf20Sopenharmony_ci 848c2ecf20Sopenharmony_ci#define UTMI_TX_TXVDD12_SHIFT 22 858c2ecf20Sopenharmony_ci#define UTMI_TX_TXVDD12_MASK (0x3 << 22) 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_ci#define UTMI_TX_CK60_PHSEL_SHIFT 17 888c2ecf20Sopenharmony_ci#define UTMI_TX_CK60_PHSEL_MASK (0xf << 17) 898c2ecf20Sopenharmony_ci 908c2ecf20Sopenharmony_ci#define UTMI_TX_IMPCAL_VTH_SHIFT 14 918c2ecf20Sopenharmony_ci#define UTMI_TX_IMPCAL_VTH_MASK (0x7 << 14) 928c2ecf20Sopenharmony_ci 938c2ecf20Sopenharmony_ci#define REG_RCAL_START (0x1 << 12) 948c2ecf20Sopenharmony_ci 958c2ecf20Sopenharmony_ci#define UTMI_TX_LOW_VDD_EN_SHIFT 11 968c2ecf20Sopenharmony_ci 978c2ecf20Sopenharmony_ci#define UTMI_TX_AMP_SHIFT 0 988c2ecf20Sopenharmony_ci#define UTMI_TX_AMP_MASK (0x7 << 0) 998c2ecf20Sopenharmony_ci 1008c2ecf20Sopenharmony_ci/* For UTMI_RX Register */ 1018c2ecf20Sopenharmony_ci#define UTMI_REG_SQ_LENGTH_SHIFT 15 1028c2ecf20Sopenharmony_ci#define UTMI_REG_SQ_LENGTH_MASK (0x3 << 15) 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_ci#define UTMI_RX_SQ_THRESH_SHIFT 4 1058c2ecf20Sopenharmony_ci#define UTMI_RX_SQ_THRESH_MASK (0xf << 4) 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_ci#define UTMI_OTG_ADDON_OTG_ON (1 << 0) 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_cienum pxa_usb_phy_version { 1108c2ecf20Sopenharmony_ci PXA_USB_PHY_MMP2, 1118c2ecf20Sopenharmony_ci PXA_USB_PHY_PXA910, 1128c2ecf20Sopenharmony_ci PXA_USB_PHY_PXA168, 1138c2ecf20Sopenharmony_ci}; 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_cistruct pxa_usb_phy { 1168c2ecf20Sopenharmony_ci struct phy *phy; 1178c2ecf20Sopenharmony_ci void __iomem *base; 1188c2ecf20Sopenharmony_ci enum pxa_usb_phy_version version; 1198c2ecf20Sopenharmony_ci}; 1208c2ecf20Sopenharmony_ci 1218c2ecf20Sopenharmony_ci/***************************************************************************** 1228c2ecf20Sopenharmony_ci * The registers read/write routines 1238c2ecf20Sopenharmony_ci *****************************************************************************/ 1248c2ecf20Sopenharmony_ci 1258c2ecf20Sopenharmony_cistatic unsigned int u2o_get(void __iomem *base, unsigned int offset) 1268c2ecf20Sopenharmony_ci{ 1278c2ecf20Sopenharmony_ci return readl_relaxed(base + offset); 1288c2ecf20Sopenharmony_ci} 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_cistatic void u2o_set(void __iomem *base, unsigned int offset, 1318c2ecf20Sopenharmony_ci unsigned int value) 1328c2ecf20Sopenharmony_ci{ 1338c2ecf20Sopenharmony_ci u32 reg; 1348c2ecf20Sopenharmony_ci 1358c2ecf20Sopenharmony_ci reg = readl_relaxed(base + offset); 1368c2ecf20Sopenharmony_ci reg |= value; 1378c2ecf20Sopenharmony_ci writel_relaxed(reg, base + offset); 1388c2ecf20Sopenharmony_ci readl_relaxed(base + offset); 1398c2ecf20Sopenharmony_ci} 1408c2ecf20Sopenharmony_ci 1418c2ecf20Sopenharmony_cistatic void u2o_clear(void __iomem *base, unsigned int offset, 1428c2ecf20Sopenharmony_ci unsigned int value) 1438c2ecf20Sopenharmony_ci{ 1448c2ecf20Sopenharmony_ci u32 reg; 1458c2ecf20Sopenharmony_ci 1468c2ecf20Sopenharmony_ci reg = readl_relaxed(base + offset); 1478c2ecf20Sopenharmony_ci reg &= ~value; 1488c2ecf20Sopenharmony_ci writel_relaxed(reg, base + offset); 1498c2ecf20Sopenharmony_ci readl_relaxed(base + offset); 1508c2ecf20Sopenharmony_ci} 1518c2ecf20Sopenharmony_ci 1528c2ecf20Sopenharmony_cistatic void u2o_write(void __iomem *base, unsigned int offset, 1538c2ecf20Sopenharmony_ci unsigned int value) 1548c2ecf20Sopenharmony_ci{ 1558c2ecf20Sopenharmony_ci writel_relaxed(value, base + offset); 1568c2ecf20Sopenharmony_ci readl_relaxed(base + offset); 1578c2ecf20Sopenharmony_ci} 1588c2ecf20Sopenharmony_ci 1598c2ecf20Sopenharmony_cistatic int pxa_usb_phy_init(struct phy *phy) 1608c2ecf20Sopenharmony_ci{ 1618c2ecf20Sopenharmony_ci struct pxa_usb_phy *pxa_usb_phy = phy_get_drvdata(phy); 1628c2ecf20Sopenharmony_ci void __iomem *base = pxa_usb_phy->base; 1638c2ecf20Sopenharmony_ci int loops; 1648c2ecf20Sopenharmony_ci 1658c2ecf20Sopenharmony_ci dev_info(&phy->dev, "initializing Marvell PXA USB PHY"); 1668c2ecf20Sopenharmony_ci 1678c2ecf20Sopenharmony_ci /* Initialize the USB PHY power */ 1688c2ecf20Sopenharmony_ci if (pxa_usb_phy->version == PXA_USB_PHY_PXA910) { 1698c2ecf20Sopenharmony_ci u2o_set(base, UTMI_CTRL, (1<<UTMI_CTRL_INPKT_DELAY_SOF_SHIFT) 1708c2ecf20Sopenharmony_ci | (1<<UTMI_CTRL_PU_REF_SHIFT)); 1718c2ecf20Sopenharmony_ci } 1728c2ecf20Sopenharmony_ci 1738c2ecf20Sopenharmony_ci u2o_set(base, UTMI_CTRL, 1<<UTMI_CTRL_PLL_PWR_UP_SHIFT); 1748c2ecf20Sopenharmony_ci u2o_set(base, UTMI_CTRL, 1<<UTMI_CTRL_PWR_UP_SHIFT); 1758c2ecf20Sopenharmony_ci 1768c2ecf20Sopenharmony_ci /* UTMI_PLL settings */ 1778c2ecf20Sopenharmony_ci u2o_clear(base, UTMI_PLL, UTMI_PLL_PLLVDD18_MASK 1788c2ecf20Sopenharmony_ci | UTMI_PLL_PLLVDD12_MASK | UTMI_PLL_PLLCALI12_MASK 1798c2ecf20Sopenharmony_ci | UTMI_PLL_FBDIV_MASK | UTMI_PLL_REFDIV_MASK 1808c2ecf20Sopenharmony_ci | UTMI_PLL_ICP_MASK | UTMI_PLL_KVCO_MASK); 1818c2ecf20Sopenharmony_ci 1828c2ecf20Sopenharmony_ci u2o_set(base, UTMI_PLL, 0xee<<UTMI_PLL_FBDIV_SHIFT 1838c2ecf20Sopenharmony_ci | 0xb<<UTMI_PLL_REFDIV_SHIFT | 3<<UTMI_PLL_PLLVDD18_SHIFT 1848c2ecf20Sopenharmony_ci | 3<<UTMI_PLL_PLLVDD12_SHIFT | 3<<UTMI_PLL_PLLCALI12_SHIFT 1858c2ecf20Sopenharmony_ci | 1<<UTMI_PLL_ICP_SHIFT | 3<<UTMI_PLL_KVCO_SHIFT); 1868c2ecf20Sopenharmony_ci 1878c2ecf20Sopenharmony_ci /* UTMI_TX */ 1888c2ecf20Sopenharmony_ci u2o_clear(base, UTMI_TX, UTMI_TX_REG_EXT_FS_RCAL_EN_MASK 1898c2ecf20Sopenharmony_ci | UTMI_TX_TXVDD12_MASK | UTMI_TX_CK60_PHSEL_MASK 1908c2ecf20Sopenharmony_ci | UTMI_TX_IMPCAL_VTH_MASK | UTMI_TX_REG_EXT_FS_RCAL_MASK 1918c2ecf20Sopenharmony_ci | UTMI_TX_AMP_MASK); 1928c2ecf20Sopenharmony_ci u2o_set(base, UTMI_TX, 3<<UTMI_TX_TXVDD12_SHIFT 1938c2ecf20Sopenharmony_ci | 4<<UTMI_TX_CK60_PHSEL_SHIFT | 4<<UTMI_TX_IMPCAL_VTH_SHIFT 1948c2ecf20Sopenharmony_ci | 8<<UTMI_TX_REG_EXT_FS_RCAL_SHIFT | 3<<UTMI_TX_AMP_SHIFT); 1958c2ecf20Sopenharmony_ci 1968c2ecf20Sopenharmony_ci /* UTMI_RX */ 1978c2ecf20Sopenharmony_ci u2o_clear(base, UTMI_RX, UTMI_RX_SQ_THRESH_MASK 1988c2ecf20Sopenharmony_ci | UTMI_REG_SQ_LENGTH_MASK); 1998c2ecf20Sopenharmony_ci u2o_set(base, UTMI_RX, 7<<UTMI_RX_SQ_THRESH_SHIFT 2008c2ecf20Sopenharmony_ci | 2<<UTMI_REG_SQ_LENGTH_SHIFT); 2018c2ecf20Sopenharmony_ci 2028c2ecf20Sopenharmony_ci /* UTMI_IVREF */ 2038c2ecf20Sopenharmony_ci if (pxa_usb_phy->version == PXA_USB_PHY_PXA168) { 2048c2ecf20Sopenharmony_ci /* 2058c2ecf20Sopenharmony_ci * fixing Microsoft Altair board interface with NEC hub issue - 2068c2ecf20Sopenharmony_ci * Set UTMI_IVREF from 0x4a3 to 0x4bf 2078c2ecf20Sopenharmony_ci */ 2088c2ecf20Sopenharmony_ci u2o_write(base, UTMI_IVREF, 0x4bf); 2098c2ecf20Sopenharmony_ci } 2108c2ecf20Sopenharmony_ci 2118c2ecf20Sopenharmony_ci /* toggle VCOCAL_START bit of UTMI_PLL */ 2128c2ecf20Sopenharmony_ci udelay(200); 2138c2ecf20Sopenharmony_ci u2o_set(base, UTMI_PLL, VCOCAL_START); 2148c2ecf20Sopenharmony_ci udelay(40); 2158c2ecf20Sopenharmony_ci u2o_clear(base, UTMI_PLL, VCOCAL_START); 2168c2ecf20Sopenharmony_ci 2178c2ecf20Sopenharmony_ci /* toggle REG_RCAL_START bit of UTMI_TX */ 2188c2ecf20Sopenharmony_ci udelay(400); 2198c2ecf20Sopenharmony_ci u2o_set(base, UTMI_TX, REG_RCAL_START); 2208c2ecf20Sopenharmony_ci udelay(40); 2218c2ecf20Sopenharmony_ci u2o_clear(base, UTMI_TX, REG_RCAL_START); 2228c2ecf20Sopenharmony_ci udelay(400); 2238c2ecf20Sopenharmony_ci 2248c2ecf20Sopenharmony_ci /* Make sure PHY PLL is ready */ 2258c2ecf20Sopenharmony_ci loops = 0; 2268c2ecf20Sopenharmony_ci while ((u2o_get(base, UTMI_PLL) & PLL_READY) == 0) { 2278c2ecf20Sopenharmony_ci mdelay(1); 2288c2ecf20Sopenharmony_ci loops++; 2298c2ecf20Sopenharmony_ci if (loops > 100) { 2308c2ecf20Sopenharmony_ci dev_warn(&phy->dev, "calibrate timeout, UTMI_PLL %x\n", 2318c2ecf20Sopenharmony_ci u2o_get(base, UTMI_PLL)); 2328c2ecf20Sopenharmony_ci break; 2338c2ecf20Sopenharmony_ci } 2348c2ecf20Sopenharmony_ci } 2358c2ecf20Sopenharmony_ci 2368c2ecf20Sopenharmony_ci if (pxa_usb_phy->version == PXA_USB_PHY_PXA168) { 2378c2ecf20Sopenharmony_ci u2o_set(base, UTMI_RESERVE, 1 << 5); 2388c2ecf20Sopenharmony_ci /* Turn on UTMI PHY OTG extension */ 2398c2ecf20Sopenharmony_ci u2o_write(base, UTMI_OTG_ADDON, 1); 2408c2ecf20Sopenharmony_ci } 2418c2ecf20Sopenharmony_ci 2428c2ecf20Sopenharmony_ci return 0; 2438c2ecf20Sopenharmony_ci 2448c2ecf20Sopenharmony_ci} 2458c2ecf20Sopenharmony_ci 2468c2ecf20Sopenharmony_cistatic int pxa_usb_phy_exit(struct phy *phy) 2478c2ecf20Sopenharmony_ci{ 2488c2ecf20Sopenharmony_ci struct pxa_usb_phy *pxa_usb_phy = phy_get_drvdata(phy); 2498c2ecf20Sopenharmony_ci void __iomem *base = pxa_usb_phy->base; 2508c2ecf20Sopenharmony_ci 2518c2ecf20Sopenharmony_ci dev_info(&phy->dev, "deinitializing Marvell PXA USB PHY"); 2528c2ecf20Sopenharmony_ci 2538c2ecf20Sopenharmony_ci if (pxa_usb_phy->version == PXA_USB_PHY_PXA168) 2548c2ecf20Sopenharmony_ci u2o_clear(base, UTMI_OTG_ADDON, UTMI_OTG_ADDON_OTG_ON); 2558c2ecf20Sopenharmony_ci 2568c2ecf20Sopenharmony_ci u2o_clear(base, UTMI_CTRL, UTMI_CTRL_RXBUF_PDWN); 2578c2ecf20Sopenharmony_ci u2o_clear(base, UTMI_CTRL, UTMI_CTRL_TXBUF_PDWN); 2588c2ecf20Sopenharmony_ci u2o_clear(base, UTMI_CTRL, UTMI_CTRL_USB_CLK_EN); 2598c2ecf20Sopenharmony_ci u2o_clear(base, UTMI_CTRL, 1<<UTMI_CTRL_PWR_UP_SHIFT); 2608c2ecf20Sopenharmony_ci u2o_clear(base, UTMI_CTRL, 1<<UTMI_CTRL_PLL_PWR_UP_SHIFT); 2618c2ecf20Sopenharmony_ci 2628c2ecf20Sopenharmony_ci return 0; 2638c2ecf20Sopenharmony_ci} 2648c2ecf20Sopenharmony_ci 2658c2ecf20Sopenharmony_cistatic const struct phy_ops pxa_usb_phy_ops = { 2668c2ecf20Sopenharmony_ci .init = pxa_usb_phy_init, 2678c2ecf20Sopenharmony_ci .exit = pxa_usb_phy_exit, 2688c2ecf20Sopenharmony_ci .owner = THIS_MODULE, 2698c2ecf20Sopenharmony_ci}; 2708c2ecf20Sopenharmony_ci 2718c2ecf20Sopenharmony_cistatic const struct of_device_id pxa_usb_phy_of_match[] = { 2728c2ecf20Sopenharmony_ci { 2738c2ecf20Sopenharmony_ci .compatible = "marvell,mmp2-usb-phy", 2748c2ecf20Sopenharmony_ci .data = (void *)PXA_USB_PHY_MMP2, 2758c2ecf20Sopenharmony_ci }, { 2768c2ecf20Sopenharmony_ci .compatible = "marvell,pxa910-usb-phy", 2778c2ecf20Sopenharmony_ci .data = (void *)PXA_USB_PHY_PXA910, 2788c2ecf20Sopenharmony_ci }, { 2798c2ecf20Sopenharmony_ci .compatible = "marvell,pxa168-usb-phy", 2808c2ecf20Sopenharmony_ci .data = (void *)PXA_USB_PHY_PXA168, 2818c2ecf20Sopenharmony_ci }, 2828c2ecf20Sopenharmony_ci { }, 2838c2ecf20Sopenharmony_ci}; 2848c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(of, pxa_usb_phy_of_match); 2858c2ecf20Sopenharmony_ci 2868c2ecf20Sopenharmony_cistatic int pxa_usb_phy_probe(struct platform_device *pdev) 2878c2ecf20Sopenharmony_ci{ 2888c2ecf20Sopenharmony_ci struct device *dev = &pdev->dev; 2898c2ecf20Sopenharmony_ci struct resource *resource; 2908c2ecf20Sopenharmony_ci struct pxa_usb_phy *pxa_usb_phy; 2918c2ecf20Sopenharmony_ci struct phy_provider *provider; 2928c2ecf20Sopenharmony_ci const struct of_device_id *of_id; 2938c2ecf20Sopenharmony_ci 2948c2ecf20Sopenharmony_ci pxa_usb_phy = devm_kzalloc(dev, sizeof(struct pxa_usb_phy), GFP_KERNEL); 2958c2ecf20Sopenharmony_ci if (!pxa_usb_phy) 2968c2ecf20Sopenharmony_ci return -ENOMEM; 2978c2ecf20Sopenharmony_ci 2988c2ecf20Sopenharmony_ci of_id = of_match_node(pxa_usb_phy_of_match, dev->of_node); 2998c2ecf20Sopenharmony_ci if (of_id) 3008c2ecf20Sopenharmony_ci pxa_usb_phy->version = (enum pxa_usb_phy_version)of_id->data; 3018c2ecf20Sopenharmony_ci else 3028c2ecf20Sopenharmony_ci pxa_usb_phy->version = PXA_USB_PHY_MMP2; 3038c2ecf20Sopenharmony_ci 3048c2ecf20Sopenharmony_ci resource = platform_get_resource(pdev, IORESOURCE_MEM, 0); 3058c2ecf20Sopenharmony_ci pxa_usb_phy->base = devm_ioremap_resource(dev, resource); 3068c2ecf20Sopenharmony_ci if (IS_ERR(pxa_usb_phy->base)) { 3078c2ecf20Sopenharmony_ci dev_err(dev, "failed to remap PHY regs\n"); 3088c2ecf20Sopenharmony_ci return PTR_ERR(pxa_usb_phy->base); 3098c2ecf20Sopenharmony_ci } 3108c2ecf20Sopenharmony_ci 3118c2ecf20Sopenharmony_ci pxa_usb_phy->phy = devm_phy_create(dev, NULL, &pxa_usb_phy_ops); 3128c2ecf20Sopenharmony_ci if (IS_ERR(pxa_usb_phy->phy)) { 3138c2ecf20Sopenharmony_ci dev_err(dev, "failed to create PHY\n"); 3148c2ecf20Sopenharmony_ci return PTR_ERR(pxa_usb_phy->phy); 3158c2ecf20Sopenharmony_ci } 3168c2ecf20Sopenharmony_ci 3178c2ecf20Sopenharmony_ci phy_set_drvdata(pxa_usb_phy->phy, pxa_usb_phy); 3188c2ecf20Sopenharmony_ci provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate); 3198c2ecf20Sopenharmony_ci if (IS_ERR(provider)) { 3208c2ecf20Sopenharmony_ci dev_err(dev, "failed to register PHY provider\n"); 3218c2ecf20Sopenharmony_ci return PTR_ERR(provider); 3228c2ecf20Sopenharmony_ci } 3238c2ecf20Sopenharmony_ci 3248c2ecf20Sopenharmony_ci if (!dev->of_node) { 3258c2ecf20Sopenharmony_ci phy_create_lookup(pxa_usb_phy->phy, "usb", "mv-udc"); 3268c2ecf20Sopenharmony_ci phy_create_lookup(pxa_usb_phy->phy, "usb", "pxa-u2oehci"); 3278c2ecf20Sopenharmony_ci phy_create_lookup(pxa_usb_phy->phy, "usb", "mv-otg"); 3288c2ecf20Sopenharmony_ci } 3298c2ecf20Sopenharmony_ci 3308c2ecf20Sopenharmony_ci dev_info(dev, "Marvell PXA USB PHY"); 3318c2ecf20Sopenharmony_ci return 0; 3328c2ecf20Sopenharmony_ci} 3338c2ecf20Sopenharmony_ci 3348c2ecf20Sopenharmony_cistatic struct platform_driver pxa_usb_phy_driver = { 3358c2ecf20Sopenharmony_ci .probe = pxa_usb_phy_probe, 3368c2ecf20Sopenharmony_ci .driver = { 3378c2ecf20Sopenharmony_ci .name = "pxa-usb-phy", 3388c2ecf20Sopenharmony_ci .of_match_table = pxa_usb_phy_of_match, 3398c2ecf20Sopenharmony_ci }, 3408c2ecf20Sopenharmony_ci}; 3418c2ecf20Sopenharmony_cimodule_platform_driver(pxa_usb_phy_driver); 3428c2ecf20Sopenharmony_ci 3438c2ecf20Sopenharmony_ciMODULE_AUTHOR("Lubomir Rintel <lkundrak@v3.sk>"); 3448c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("Marvell PXA USB PHY Driver"); 3458c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL v2"); 346