2 * phy-bcm-kona-usb2.c - Broadcom Kona USB2 Phy Driver
4 * Copyright (C) 2013 Linaro Limited
5 * Matt Porter <mporter@linaro.org>
7 * This software is licensed under the terms of the GNU General Public
8 * License version 2, as published by the Free Software Foundation, and
9 * may be copied, distributed, and modified under those terms.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
17 #include <linux/clk.h>
18 #include <linux/delay.h>
19 #include <linux/err.h>
21 #include <linux/module.h>
23 #include <linux/phy/phy.h>
24 #include <linux/platform_device.h>
27 #define OTGCTL_OTGSTAT2 BIT(31)
28 #define OTGCTL_OTGSTAT1 BIT(30)
29 #define OTGCTL_PRST_N_SW BIT(11)
30 #define OTGCTL_HRESET_N BIT(10)
31 #define OTGCTL_UTMI_LINE_STATE1 BIT(9)
32 #define OTGCTL_UTMI_LINE_STATE0 BIT(8)
35 #define P1CTL_SOFT_RESET BIT(1)
36 #define P1CTL_NON_DRIVING BIT(0)
42 static void bcm_kona_usb_phy_power(struct bcm_kona_usb
*phy
, int on
)
46 val
= readl(phy
->regs
+ OTGCTL
);
48 /* Configure and power PHY */
49 val
&= ~(OTGCTL_OTGSTAT2
| OTGCTL_OTGSTAT1
|
50 OTGCTL_UTMI_LINE_STATE1
| OTGCTL_UTMI_LINE_STATE0
);
51 val
|= OTGCTL_PRST_N_SW
| OTGCTL_HRESET_N
;
53 val
&= ~(OTGCTL_PRST_N_SW
| OTGCTL_HRESET_N
);
55 writel(val
, phy
->regs
+ OTGCTL
);
58 static int bcm_kona_usb_phy_init(struct phy
*gphy
)
60 struct bcm_kona_usb
*phy
= phy_get_drvdata(gphy
);
64 val
= readl(phy
->regs
+ P1CTL
);
65 val
&= ~P1CTL_NON_DRIVING
;
66 val
|= P1CTL_SOFT_RESET
;
67 writel(val
, phy
->regs
+ P1CTL
);
68 writel(val
& ~P1CTL_SOFT_RESET
, phy
->regs
+ P1CTL
);
69 /* Reset needs to be asserted for 2ms */
71 writel(val
| P1CTL_SOFT_RESET
, phy
->regs
+ P1CTL
);
76 static int bcm_kona_usb_phy_power_on(struct phy
*gphy
)
78 struct bcm_kona_usb
*phy
= phy_get_drvdata(gphy
);
80 bcm_kona_usb_phy_power(phy
, 1);
85 static int bcm_kona_usb_phy_power_off(struct phy
*gphy
)
87 struct bcm_kona_usb
*phy
= phy_get_drvdata(gphy
);
89 bcm_kona_usb_phy_power(phy
, 0);
94 static struct phy_ops ops
= {
95 .init
= bcm_kona_usb_phy_init
,
96 .power_on
= bcm_kona_usb_phy_power_on
,
97 .power_off
= bcm_kona_usb_phy_power_off
,
101 static int bcm_kona_usb2_probe(struct platform_device
*pdev
)
103 struct device
*dev
= &pdev
->dev
;
104 struct bcm_kona_usb
*phy
;
105 struct resource
*res
;
107 struct phy_provider
*phy_provider
;
109 phy
= devm_kzalloc(dev
, sizeof(*phy
), GFP_KERNEL
);
113 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
114 phy
->regs
= devm_ioremap_resource(&pdev
->dev
, res
);
115 if (IS_ERR(phy
->regs
))
116 return PTR_ERR(phy
->regs
);
118 platform_set_drvdata(pdev
, phy
);
120 gphy
= devm_phy_create(dev
, &ops
, NULL
);
122 return PTR_ERR(gphy
);
124 /* The Kona PHY supports an 8-bit wide UTMI interface */
125 phy_set_bus_width(gphy
, 8);
127 phy_set_drvdata(gphy
, phy
);
129 phy_provider
= devm_of_phy_provider_register(dev
,
130 of_phy_simple_xlate
);
131 if (IS_ERR(phy_provider
))
132 return PTR_ERR(phy_provider
);
137 static const struct of_device_id bcm_kona_usb2_dt_ids
[] = {
138 { .compatible
= "brcm,kona-usb2-phy" },
142 MODULE_DEVICE_TABLE(of
, bcm_kona_usb2_dt_ids
);
144 static struct platform_driver bcm_kona_usb2_driver
= {
145 .probe
= bcm_kona_usb2_probe
,
147 .name
= "bcm-kona-usb2",
148 .owner
= THIS_MODULE
,
149 .of_match_table
= bcm_kona_usb2_dt_ids
,
153 module_platform_driver(bcm_kona_usb2_driver
);
155 MODULE_ALIAS("platform:bcm-kona-usb2");
156 MODULE_AUTHOR("Matt Porter <mporter@linaro.org>");
157 MODULE_DESCRIPTION("BCM Kona USB 2.0 PHY driver");
158 MODULE_LICENSE("GPL v2");