Skip to content

Commit 6747caa

Browse files
kishongregkh
authored andcommitted
usb: phy: twl4030: use the new generic PHY framework
Used the generic PHY framework API to create the PHY. For powering on and powering off the PHY, power_on and power_off ops are used. Once the MUSB OMAP glue is adapted to the new framework, the suspend and resume ops of usb phy library will be removed. Also twl4030-usb driver is moved to drivers/phy/. However using the old usb phy library cannot be completely removed because otg is intertwined with phy and moving to the new framework completely will break otg. Once we have a separate otg state machine, we can get rid of the usb phy library. Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com> Acked-by: Felipe Balbi <balbi@ti.com> Reviewed-by: Sylwester Nawrocki <s.nawrocki@samsung.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 5d93d1e commit 6747caa

6 files changed

Lines changed: 67 additions & 14 deletions

File tree

‎drivers/phy/Kconfig‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,15 @@ config OMAP_USB2
2727
The USB OTG controller communicates with the comparator using this
2828
driver.
2929

30+
config TWL4030_USB
31+
tristate "TWL4030 USB Transceiver Driver"
32+
depends on TWL4030_CORE && REGULATOR_TWL4030 && USB_MUSB_OMAP2PLUS
33+
select GENERIC_PHY
34+
select USB_PHY
35+
help
36+
Enable this to support the USB OTG transceiver on TWL4030
37+
family chips (including the TWL5030 and TPS659x0 devices).
38+
This transceiver supports high and full speed devices plus,
39+
in host mode, low speed.
40+
3041
endmenu

‎drivers/phy/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44

55
obj-$(CONFIG_GENERIC_PHY) += phy-core.o
66
obj-$(CONFIG_OMAP_USB2) += phy-omap-usb2.o
7+
obj-$(CONFIG_TWL4030_USB) += phy-twl4030-usb.o
Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <linux/io.h>
3434
#include <linux/delay.h>
3535
#include <linux/usb/otg.h>
36+
#include <linux/phy/phy.h>
3637
#include <linux/usb/musb-omap.h>
3738
#include <linux/usb/ulpi.h>
3839
#include <linux/i2c/twl.h>
@@ -431,6 +432,14 @@ static void twl4030_phy_suspend(struct twl4030_usb *twl, int controller_off)
431432
dev_dbg(twl->dev, "%s\n", __func__);
432433
}
433434

435+
static int twl4030_phy_power_off(struct phy *phy)
436+
{
437+
struct twl4030_usb *twl = phy_get_drvdata(phy);
438+
439+
twl4030_phy_suspend(twl, 0);
440+
return 0;
441+
}
442+
434443
static void __twl4030_phy_resume(struct twl4030_usb *twl)
435444
{
436445
twl4030_phy_power(twl, 1);
@@ -459,6 +468,14 @@ static void twl4030_phy_resume(struct twl4030_usb *twl)
459468
}
460469
}
461470

471+
static int twl4030_phy_power_on(struct phy *phy)
472+
{
473+
struct twl4030_usb *twl = phy_get_drvdata(phy);
474+
475+
twl4030_phy_resume(twl);
476+
return 0;
477+
}
478+
462479
static int twl4030_usb_ldo_init(struct twl4030_usb *twl)
463480
{
464481
/* Enable writing to power configuration registers */
@@ -602,13 +619,22 @@ static int twl4030_usb_phy_init(struct usb_phy *phy)
602619
status = twl4030_usb_linkstat(twl);
603620
twl->linkstat = status;
604621

605-
if (status == OMAP_MUSB_ID_GROUND || status == OMAP_MUSB_VBUS_VALID)
622+
if (status == OMAP_MUSB_ID_GROUND || status == OMAP_MUSB_VBUS_VALID) {
606623
omap_musb_mailbox(twl->linkstat);
624+
twl4030_phy_resume(twl);
625+
}
607626

608627
sysfs_notify(&twl->dev->kobj, NULL, "vbus");
609628
return 0;
610629
}
611630

631+
static int twl4030_phy_init(struct phy *phy)
632+
{
633+
struct twl4030_usb *twl = phy_get_drvdata(phy);
634+
635+
return twl4030_usb_phy_init(&twl->phy);
636+
}
637+
612638
static int twl4030_set_suspend(struct usb_phy *x, int suspend)
613639
{
614640
struct twl4030_usb *twl = phy_to_twl(x);
@@ -646,13 +672,23 @@ static int twl4030_set_host(struct usb_otg *otg, struct usb_bus *host)
646672
return 0;
647673
}
648674

675+
static const struct phy_ops ops = {
676+
.init = twl4030_phy_init,
677+
.power_on = twl4030_phy_power_on,
678+
.power_off = twl4030_phy_power_off,
679+
.owner = THIS_MODULE,
680+
};
681+
649682
static int twl4030_usb_probe(struct platform_device *pdev)
650683
{
651684
struct twl4030_usb_data *pdata = dev_get_platdata(&pdev->dev);
652685
struct twl4030_usb *twl;
686+
struct phy *phy;
653687
int status, err;
654688
struct usb_otg *otg;
655689
struct device_node *np = pdev->dev.of_node;
690+
struct phy_provider *phy_provider;
691+
struct phy_init_data *init_data = NULL;
656692

657693
twl = devm_kzalloc(&pdev->dev, sizeof *twl, GFP_KERNEL);
658694
if (!twl)
@@ -661,9 +697,10 @@ static int twl4030_usb_probe(struct platform_device *pdev)
661697
if (np)
662698
of_property_read_u32(np, "usb_mode",
663699
(enum twl4030_usb_mode *)&twl->usb_mode);
664-
else if (pdata)
700+
else if (pdata) {
665701
twl->usb_mode = pdata->usb_mode;
666-
else {
702+
init_data = pdata->init_data;
703+
} else {
667704
dev_err(&pdev->dev, "twl4030 initialized without pdata\n");
668705
return -EINVAL;
669706
}
@@ -689,6 +726,19 @@ static int twl4030_usb_probe(struct platform_device *pdev)
689726
otg->set_host = twl4030_set_host;
690727
otg->set_peripheral = twl4030_set_peripheral;
691728

729+
phy_provider = devm_of_phy_provider_register(twl->dev,
730+
of_phy_simple_xlate);
731+
if (IS_ERR(phy_provider))
732+
return PTR_ERR(phy_provider);
733+
734+
phy = devm_phy_create(twl->dev, &ops, init_data);
735+
if (IS_ERR(phy)) {
736+
dev_dbg(&pdev->dev, "Failed to create PHY\n");
737+
return PTR_ERR(phy);
738+
}
739+
740+
phy_set_drvdata(phy, twl);
741+
692742
/* init spinlock for workqueue */
693743
spin_lock_init(&twl->lock);
694744

‎drivers/usb/phy/Kconfig‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,6 @@ config SAMSUNG_USB3PHY
113113
Enable this to support Samsung USB 3.0 (Super Speed) phy controller
114114
for samsung SoCs.
115115

116-
config TWL4030_USB
117-
tristate "TWL4030 USB Transceiver Driver"
118-
depends on TWL4030_CORE && REGULATOR_TWL4030 && USB_MUSB_OMAP2PLUS
119-
select USB_PHY
120-
help
121-
Enable this to support the USB OTG transceiver on TWL4030
122-
family chips (including the TWL5030 and TPS659x0 devices).
123-
This transceiver supports high and full speed devices plus,
124-
in host mode, low speed.
125-
126116
config TWL6030_USB
127117
tristate "TWL6030 USB Transceiver Driver"
128118
depends on TWL4030_CORE && OMAP_USB2 && USB_MUSB_OMAP2PLUS

‎drivers/usb/phy/Makefile‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ obj-$(CONFIG_OMAP_USB3) += phy-omap-usb3.o
1919
obj-$(CONFIG_SAMSUNG_USBPHY) += phy-samsung-usb.o
2020
obj-$(CONFIG_SAMSUNG_USB2PHY) += phy-samsung-usb2.o
2121
obj-$(CONFIG_SAMSUNG_USB3PHY) += phy-samsung-usb3.o
22-
obj-$(CONFIG_TWL4030_USB) += phy-twl4030-usb.o
2322
obj-$(CONFIG_TWL6030_USB) += phy-twl6030-usb.o
2423
obj-$(CONFIG_USB_EHCI_TEGRA) += phy-tegra-usb.o
2524
obj-$(CONFIG_USB_GPIO_VBUS) += phy-gpio-vbus-usb.o

‎include/linux/i2c/twl.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#define __TWL_H_
2727

2828
#include <linux/types.h>
29+
#include <linux/phy/phy.h>
2930
#include <linux/input/matrix_keypad.h>
3031

3132
/*
@@ -615,6 +616,7 @@ enum twl4030_usb_mode {
615616
struct twl4030_usb_data {
616617
enum twl4030_usb_mode usb_mode;
617618
unsigned long features;
619+
struct phy_init_data *init_data;
618620

619621
int (*phy_init)(struct device *dev);
620622
int (*phy_exit)(struct device *dev);

0 commit comments

Comments
 (0)