1 // SPDX-License-Identifier: GPL-2.0+
3 * phy-keystone - USB PHY, talking to dwc3 controller in Keystone.
5 * Copyright (C) 2013 Texas Instruments Incorporated - https://www.ti.com
7 * Author: WingMan Kwok <w-kwok2@ti.com>
10 #include <linux/module.h>
11 #include <linux/platform_device.h>
12 #include <linux/usb/usb_phy_generic.h>
16 #include "phy-generic.h"
18 /* USB PHY control register offsets */
19 #define USB_PHY_CTL_UTMI 0x0000
20 #define USB_PHY_CTL_PIPE 0x0004
21 #define USB_PHY_CTL_PARAM_1 0x0008
22 #define USB_PHY_CTL_PARAM_2 0x000c
23 #define USB_PHY_CTL_CLOCK 0x0010
24 #define USB_PHY_CTL_PLL 0x0014
26 #define PHY_REF_SSP_EN BIT(29)
28 struct keystone_usbphy
{
29 struct usb_phy_generic usb_phy_gen
;
30 void __iomem
*phy_ctrl
;
33 static inline u32
keystone_usbphy_readl(void __iomem
*base
, u32 offset
)
35 return readl(base
+ offset
);
38 static inline void keystone_usbphy_writel(void __iomem
*base
,
39 u32 offset
, u32 value
)
41 writel(value
, base
+ offset
);
44 static int keystone_usbphy_init(struct usb_phy
*phy
)
46 struct keystone_usbphy
*k_phy
= dev_get_drvdata(phy
->dev
);
49 val
= keystone_usbphy_readl(k_phy
->phy_ctrl
, USB_PHY_CTL_CLOCK
);
50 keystone_usbphy_writel(k_phy
->phy_ctrl
, USB_PHY_CTL_CLOCK
,
51 val
| PHY_REF_SSP_EN
);
55 static void keystone_usbphy_shutdown(struct usb_phy
*phy
)
57 struct keystone_usbphy
*k_phy
= dev_get_drvdata(phy
->dev
);
60 val
= keystone_usbphy_readl(k_phy
->phy_ctrl
, USB_PHY_CTL_CLOCK
);
61 keystone_usbphy_writel(k_phy
->phy_ctrl
, USB_PHY_CTL_CLOCK
,
62 val
&= ~PHY_REF_SSP_EN
);
65 static int keystone_usbphy_probe(struct platform_device
*pdev
)
67 struct device
*dev
= &pdev
->dev
;
68 struct keystone_usbphy
*k_phy
;
71 k_phy
= devm_kzalloc(dev
, sizeof(*k_phy
), GFP_KERNEL
);
75 k_phy
->phy_ctrl
= devm_platform_ioremap_resource(pdev
, 0);
76 if (IS_ERR(k_phy
->phy_ctrl
))
77 return PTR_ERR(k_phy
->phy_ctrl
);
79 ret
= usb_phy_gen_create_phy(dev
, &k_phy
->usb_phy_gen
);
83 k_phy
->usb_phy_gen
.phy
.init
= keystone_usbphy_init
;
84 k_phy
->usb_phy_gen
.phy
.shutdown
= keystone_usbphy_shutdown
;
86 platform_set_drvdata(pdev
, k_phy
);
88 return usb_add_phy_dev(&k_phy
->usb_phy_gen
.phy
);
91 static int keystone_usbphy_remove(struct platform_device
*pdev
)
93 struct keystone_usbphy
*k_phy
= platform_get_drvdata(pdev
);
95 usb_remove_phy(&k_phy
->usb_phy_gen
.phy
);
100 static const struct of_device_id keystone_usbphy_ids
[] = {
101 { .compatible
= "ti,keystone-usbphy" },
104 MODULE_DEVICE_TABLE(of
, keystone_usbphy_ids
);
106 static struct platform_driver keystone_usbphy_driver
= {
107 .probe
= keystone_usbphy_probe
,
108 .remove
= keystone_usbphy_remove
,
110 .name
= "keystone-usbphy",
111 .of_match_table
= keystone_usbphy_ids
,
115 module_platform_driver(keystone_usbphy_driver
);
117 MODULE_ALIAS("platform:keystone-usbphy");
118 MODULE_AUTHOR("Texas Instruments Inc.");
119 MODULE_DESCRIPTION("Keystone USB phy driver");
120 MODULE_LICENSE("GPL v2");