Commit | Line | Data |
---|---|---|
5fd54ace | 1 | // SPDX-License-Identifier: GPL-2.0+ |
25acdd08 WK |
2 | /* |
3 | * phy-keystone - USB PHY, talking to dwc3 controller in Keystone. | |
4 | * | |
5 | * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com | |
25acdd08 WK |
6 | * |
7 | * Author: WingMan Kwok <w-kwok2@ti.com> | |
25acdd08 WK |
8 | */ |
9 | ||
10 | #include <linux/module.h> | |
11 | #include <linux/platform_device.h> | |
d7078df6 | 12 | #include <linux/usb/usb_phy_generic.h> |
25acdd08 WK |
13 | #include <linux/io.h> |
14 | #include <linux/of.h> | |
15 | ||
16 | #include "phy-generic.h" | |
17 | ||
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 | |
25 | ||
26 | #define PHY_REF_SSP_EN BIT(29) | |
27 | ||
28 | struct keystone_usbphy { | |
4525beeb | 29 | struct usb_phy_generic usb_phy_gen; |
25acdd08 WK |
30 | void __iomem *phy_ctrl; |
31 | }; | |
32 | ||
33 | static inline u32 keystone_usbphy_readl(void __iomem *base, u32 offset) | |
34 | { | |
35 | return readl(base + offset); | |
36 | } | |
37 | ||
38 | static inline void keystone_usbphy_writel(void __iomem *base, | |
39 | u32 offset, u32 value) | |
40 | { | |
41 | writel(value, base + offset); | |
42 | } | |
43 | ||
44 | static int keystone_usbphy_init(struct usb_phy *phy) | |
45 | { | |
46 | struct keystone_usbphy *k_phy = dev_get_drvdata(phy->dev); | |
47 | u32 val; | |
48 | ||
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); | |
52 | return 0; | |
53 | } | |
54 | ||
55 | static void keystone_usbphy_shutdown(struct usb_phy *phy) | |
56 | { | |
57 | struct keystone_usbphy *k_phy = dev_get_drvdata(phy->dev); | |
58 | u32 val; | |
59 | ||
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); | |
63 | } | |
64 | ||
65 | static int keystone_usbphy_probe(struct platform_device *pdev) | |
66 | { | |
67 | struct device *dev = &pdev->dev; | |
68 | struct keystone_usbphy *k_phy; | |
69 | struct resource *res; | |
70 | int ret; | |
71 | ||
72 | k_phy = devm_kzalloc(dev, sizeof(*k_phy), GFP_KERNEL); | |
73 | if (!k_phy) | |
74 | return -ENOMEM; | |
75 | ||
76 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | |
25acdd08 WK |
77 | k_phy->phy_ctrl = devm_ioremap_resource(dev, res); |
78 | if (IS_ERR(k_phy->phy_ctrl)) | |
79 | return PTR_ERR(k_phy->phy_ctrl); | |
80 | ||
c139e142 | 81 | ret = usb_phy_gen_create_phy(dev, &k_phy->usb_phy_gen, NULL); |
25acdd08 WK |
82 | if (ret) |
83 | return ret; | |
84 | ||
85 | k_phy->usb_phy_gen.phy.init = keystone_usbphy_init; | |
86 | k_phy->usb_phy_gen.phy.shutdown = keystone_usbphy_shutdown; | |
87 | ||
88 | platform_set_drvdata(pdev, k_phy); | |
89 | ||
a9c5d8fe | 90 | return usb_add_phy_dev(&k_phy->usb_phy_gen.phy); |
25acdd08 WK |
91 | } |
92 | ||
93 | static int keystone_usbphy_remove(struct platform_device *pdev) | |
94 | { | |
95 | struct keystone_usbphy *k_phy = platform_get_drvdata(pdev); | |
96 | ||
97 | usb_remove_phy(&k_phy->usb_phy_gen.phy); | |
98 | ||
99 | return 0; | |
100 | } | |
101 | ||
102 | static const struct of_device_id keystone_usbphy_ids[] = { | |
103 | { .compatible = "ti,keystone-usbphy" }, | |
104 | { } | |
105 | }; | |
106 | MODULE_DEVICE_TABLE(of, keystone_usbphy_ids); | |
107 | ||
108 | static struct platform_driver keystone_usbphy_driver = { | |
109 | .probe = keystone_usbphy_probe, | |
110 | .remove = keystone_usbphy_remove, | |
111 | .driver = { | |
112 | .name = "keystone-usbphy", | |
ed40082d | 113 | .of_match_table = keystone_usbphy_ids, |
25acdd08 WK |
114 | }, |
115 | }; | |
116 | ||
117 | module_platform_driver(keystone_usbphy_driver); | |
118 | ||
119 | MODULE_ALIAS("platform:keystone-usbphy"); | |
120 | MODULE_AUTHOR("Texas Instruments Inc."); | |
121 | MODULE_DESCRIPTION("Keystone USB phy driver"); | |
122 | MODULE_LICENSE("GPL v2"); |