Skip to contentSkip to conversation

USB: PHY: Re-organize Tegra USB PHY driver

PATCH Superseded Venu Byravarasu 3 participants 8 messages Sep 21, 2012 – Sep 25, 2012

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 USB: PHY: Re-organize Tegra USB PHY driver

NVIDIA produces several Tegra SoCs viz Tegra20, Tegra30 etc. In order to support USB PHY drivers on these SoCs, existing PHY driver is split into SoC agnostic common USB PHY driver and Tegra20-specific USB phy driver. This will facilitate easy addition and deletion of phy drivers for Tegra SoCs.

---
delta from v2:

Added an if condition to check for device_node to be not NULL, before dereferencing it.

 drivers/usb/host/ehci-tegra.c                      |   26 +-
 drivers/usb/phy/Makefile                           |    1 +
 .../usb/phy/{tegra_usb_phy.c => tegra2_usb_phy.c}  |  421 +++----------
 drivers/usb/phy/tegra2_usb_phy.h                   |  140 ++++
 drivers/usb/phy/tegra_usb_phy.c                    |  688 +-------------------
 include/linux/usb/tegra_usb_phy.h                  |   34 +-
 6 files changed, 298 insertions(+), 1012 deletions(-)
 copy drivers/usb/phy/{tegra_usb_phy.c => tegra2_usb_phy.c} (53%)
 create mode 100644 drivers/usb/phy/tegra2_usb_phy.h
drivers/usb/host/ehci-tegra.c +22 -4
index 6223d17..8199a6e 100644
@@ -618,6 +618,9 @@ static int tegra_ehci_probe(struct platform_device *pdev)
 	int err = 0;
 	int irq;
 	int instance = pdev->id;
+	struct device_node *np = pdev->dev.of_node;
+	struct phy_params params;
+	int phy_type;
 
 	pdata = pdev->dev.platform_data;
 	if (!pdata) {
@@ -701,14 +704,29 @@ static int tegra_ehci_probe(struct platform_device *pdev)
 			break;
 		default:
 			err = -ENODEV;
-			dev_err(&pdev->dev, "unknown usb instance\n");
+			dev_err(&pdev->dev, "unknown usb inst:%d\n", instance);
 			goto fail_io;
 		}
 	}
 
+	if (np) {
+		phy_type = of_property_match_string(np, "phy_type", "utmi");
+		if (phy_type >= 0)
+			params.type = TEGRA_USB_PHY_TYPE_UTMI;
+		else {
+			phy_type = of_property_match_string(np, "phy_type", "ulpi");
+			if (phy_type >= 0)
+				params.type = TEGRA_USB_PHY_TYPE_ULPI;
+			else
+				params.type = TEGRA_USB_PHY_TYPE_INVALID;
+		}
+	}
+
+	params.mode = TEGRA_USB_PHY_MODE_HOST;
+	params.config = pdata->phy_config;
+
 	tegra->phy = tegra_usb_phy_open(&pdev->dev, instance, hcd->regs,
-					pdata->phy_config,
-					TEGRA_USB_PHY_MODE_HOST);
+		&params);
 	if (IS_ERR(tegra->phy)) {
 		dev_err(&pdev->dev, "Failed to open USB phy\n");
 		err = -ENXIO;
@@ -744,7 +762,7 @@ static int tegra_ehci_probe(struct platform_device *pdev)
 
 	err = usb_add_hcd(hcd, irq, IRQF_SHARED);
 	if (err) {
-		dev_err(&pdev->dev, "Failed to add USB HCD\n");
+		dev_err(&pdev->dev, "usb_add_hcd failed with err 0x%x\n", err);
 		goto fail;
 	}
 
drivers/usb/phy/Makefile +1 -0
index b069f29..21872e1 100644
@@ -8,3 +8,4 @@ obj-$(CONFIG_OMAP_USB2)			+= omap-usb2.o
 obj-$(CONFIG_USB_ISP1301)		+= isp1301.o
 obj-$(CONFIG_MV_U3D_PHY)		+= mv_u3d_phy.o
 obj-$(CONFIG_USB_EHCI_TEGRA)	+= tegra_usb_phy.o
+obj-$(CONFIG_USB_EHCI_TEGRA)	+= tegra2_usb_phy.o
drivers/usb/phy/tegra2_usb_phy.c renamed from drivers/usb/phy/tegra_usb_phy.c +74 -347

576 lines not on this page · raw message

drivers/usb/phy/tegra2_usb_phy.h new file +140 -0

140 lines not on this page · raw message

drivers/usb/phy/tegra_usb_phy.c +32 -656

771 lines not on this page · raw message

include/linux/usb/tegra_usb_phy.h +29 -5
index 176b1ca..8e1a34a 100644
@@ -44,8 +44,34 @@ enum tegra_usb_phy_mode {
 	TEGRA_USB_PHY_MODE_HOST,
 };
 
+enum tegra_usb_phy_type {
+	TEGRA_USB_PHY_TYPE_UTMI = 0,
+	TEGRA_USB_PHY_TYPE_ULPI,
+	TEGRA_USB_PHY_TYPE_INVALID,
+};
+
+struct tegra_usb_phy;
+
+struct tegra_usb_phy_ops {
+	int (*open)(struct tegra_usb_phy *phy);
+	void (*close)(struct tegra_usb_phy *phy);
+	int (*power_on)(struct tegra_usb_phy *phy);
+	int (*power_off)(struct tegra_usb_phy *phy);
+	void (*preresume)(struct tegra_usb_phy *phy);
+	void (*postresume)(struct tegra_usb_phy *phy);
+	void (*restore_start)(struct tegra_usb_phy *phy,
+				   enum tegra_usb_phy_port_speed port_speed);
+	void (*restore_end)(struct tegra_usb_phy *phy);
+};
+
 struct tegra_xtal_freq;
 
+struct phy_params {
+	void *config;
+	enum tegra_usb_phy_mode mode;
+	enum tegra_usb_phy_type type;
+};
+
 struct tegra_usb_phy {
 	int instance;
 	const struct tegra_xtal_freq *freq;
@@ -58,15 +84,13 @@ struct tegra_usb_phy {
 	void *config;
 	struct usb_phy *ulpi;
 	struct usb_phy u_phy;
+	struct tegra_usb_phy_ops ops;
+	enum tegra_usb_phy_type type;
 	struct device *dev;
 };
 
 struct tegra_usb_phy *tegra_usb_phy_open(struct device *dev, int instance,
-	void __iomem *regs, void *config, enum tegra_usb_phy_mode phy_mode);
-
-void tegra_usb_phy_clk_disable(struct tegra_usb_phy *phy);
-
-void tegra_usb_phy_clk_enable(struct tegra_usb_phy *phy);
+	void __iomem *regs, struct phy_params *params);
 
 void tegra_usb_phy_preresume(struct tegra_usb_phy *phy);
 
Signature · 1 line
1.7.1.1
#1 lore raw

Hi,

Quoted 52 lines · Venu Byravarasu

NVIDIA produces several Tegra SoCs viz Tegra20, Tegra30 etc. In order to support USB PHY drivers on these SoCs, existing PHY driver is split into SoC agnostic common USB PHY driver and Tegra20-specific USB phy driver. This will facilitate easy addition and deletion of phy drivers for Tegra SoCs.

---
delta from v2:

Added an if condition to check for device_node to be not NULL, before dereferencing it.

 drivers/usb/host/ehci-tegra.c                      |   26 +-
 drivers/usb/phy/Makefile                           |    1 +
 .../usb/phy/{tegra_usb_phy.c => tegra2_usb_phy.c}  |  421 +++----------
 drivers/usb/phy/tegra2_usb_phy.h                   |  140 ++++
 drivers/usb/phy/tegra_usb_phy.c                    |  688 +-------------------
 include/linux/usb/tegra_usb_phy.h                  |   34 +-
 6 files changed, 298 insertions(+), 1012 deletions(-)
 copy drivers/usb/phy/{tegra_usb_phy.c => tegra2_usb_phy.c} (53%)
 create mode 100644 drivers/usb/phy/tegra2_usb_phy.h
drivers/usb/host/ehci-tegra.c +9 -1
index 6223d17..8199a6e 100644
@@ -618,6 +618,9 @@ static int tegra_ehci_probe(struct platform_device *pdev)
        int err = 0;
        int irq;
        int instance = pdev->id;
+       struct device_node *np = pdev->dev.of_node;
+       struct phy_params params;
+       int phy_type;
 
        pdata = pdev->dev.platform_data;
        if (!pdata) {
@@ -701,14 +704,29 @@ static int tegra_ehci_probe(struct platform_device *pdev)
                        break;
                default:
                        err = -ENODEV;
-                       dev_err(&pdev->dev, "unknown usb instance\n");
+                       dev_err(&pdev->dev, "unknown usb inst:%d\n", instance);
                        goto fail_io;
                }
        }
 
+       if (np) {
+               phy_type = of_property_match_string(np, "phy_type", "utmi");
+               if (phy_type >= 0)
+                       params.type = TEGRA_USB_PHY_TYPE_UTMI;
+               else {

drivers/usb/host/ehci-tegra.c static int tegra_ehci_probe(struct platform_device *pdev) · line 726

Quoted 10 lines
drivers/usb/host/ehci-tegra.c +10 -0
+                       phy_type = of_property_match_string(np, "phy_type", "ulpi");
+                       if (phy_type >= 0)
+                               params.type = TEGRA_USB_PHY_TYPE_ULPI;
+                       else
+                               params.type = TEGRA_USB_PHY_TYPE_INVALID;
+               }
+       }
+
+       params.mode = TEGRA_USB_PHY_MODE_HOST;
+       params.config = pdata->phy_config;

I fail to understand how pdata is not NULL in dt boot. I know i've already given this comment and you replied that you dint see any crash. But I'd like to know where and how pdata gets populated.

Thanks
Kishon

#2 lore raw
Quoted 10 lines · KISHON VIJAY

Hi,

Quoted 7 lines · Venu Byravarasu

NVIDIA produces several Tegra SoCs viz Tegra20, Tegra30 etc. In order to support USB PHY drivers on these SoCs, existing PHY driver is split into SoC agnostic common USB PHY driver and Tegra20-specific USB phy driver. This will facilitate easy addition and deletion of phy drivers for Tegra SoCs.

(quoted diff) +0 -0
@@ -618,6 +618,9 @@ static int tegra_ehci_probe(struct platform_device *pdev)

...

Quoted 2 lines
Quoted 2 lines
        pdata = pdev->dev.platform_data;
        if (!pdata) {

Some missing lines of context are:

                dev_err(&pdev->dev, "Platform data missing\n");
                return -EINVAL;
        }

...

Quoted 6 lines

drivers/usb/host/ehci-tegra.c static int tegra_ehci_probe(struct platform_device *pdev) · line 726

Quoted 2 lines
drivers/usb/host/ehci-tegra.c +2 -0
+       params.mode = TEGRA_USB_PHY_MODE_HOST;
+       params.config = pdata->phy_config;

I fail to understand how pdata is not NULL in dt boot. I know i've already given this comment and you replied that you dint see any crash. But I'd like to know where and how pdata gets populated.

In practice, the platform uses AUXDATA to provide platform data to the driver even when it's instantiated using device tree; see arch/arm/mach-tegra/board-dt-tegra20.c variables tegra_ehci*_pdata and tegra20_auxdata_lookup[].

In the slightly (very very slightly, hopefully) longer term, I would like to completely remove the AUXDATA setup from board-dt-tegra20.c; tegra_ehci_probe() should do something like:

pdata = pdev->dev.platform_data
if (!pdata)

    pdata = parse_pdata_from_dt();
/* user didn't specify any in DT either */
if (!pdata)
    pdata = default_pdata_for_port();

... where perhaps the use of defaults could be folded into parse_pdata_from_dt().

#3 lore raw
Quoted 50 lines

-----Original Message-----
From: Stephen Warren [mailto:[email protected]]
Sent: Friday, September 21, 2012 9:45 PM
To: ABRAHAM, KISHON VIJAY
Cc: Venu Byravarasu; [email protected]; [email protected]; linux- [email protected]; [email protected]
Subject: Re: [PATCH v3] USB: PHY: Re-organize Tegra USB PHY driver

Quoted 3 lines · KISHON VIJAY

Hi,

On Fri, Sep 21, 2012 at 5:50 PM, Venu Byravarasu

Quoted 7 lines · <[email protected]> wrote:

Review static int tegra_ehci_probe(struct platform_device

Quoted 7 lines

NVIDIA produces several Tegra SoCs viz Tegra20, Tegra30 etc. In order to support USB PHY drivers on these SoCs, existing PHY driver is split into SoC agnostic common USB PHY driver and Tegra20-specific USB phy driver. This will facilitate easy addition and deletion of phy drivers for Tegra SoCs.

(quoted diff) +0 -0
@@ -618,6 +618,9 @@ static int tegra_ehci_probe(struct platform_device

*pdev)
...

Quoted 2 lines

drivers/usb/host/ehci-tegra.c static int tegra_ehci_probe(struct platform_device *pdev) · line 626

Quoted 2 lines
drivers/usb/host/ehci-tegra.c +0 -0
        pdata = pdev->dev.platform_data;
        if (!pdata) {

Some missing lines of context are:

                dev_err(&pdev->dev, "Platform data missing\n");
                return -EINVAL;
        }

...

Quoted 6 lines

drivers/usb/host/ehci-tegra.c static int tegra_ehci_probe(struct platform_device *pdev) · line 726

Quoted 2 lines
drivers/usb/host/ehci-tegra.c +2 -0
+       params.mode = TEGRA_USB_PHY_MODE_HOST;
+       params.config = pdata->phy_config;

I fail to understand how pdata is not NULL in dt boot. I know i've already given this comment and you replied that you dint see any crash. But I'd like to know where and how pdata gets populated.

In practice, the platform uses AUXDATA to provide platform data to the driver even when it's instantiated using device tree; see arch/arm/mach-tegra/board-dt-tegra20.c variables tegra_ehci*_pdata and tegra20_auxdata_lookup[].

In the slightly (very very slightly, hopefully) longer term, I would like to completely remove the AUXDATA setup from board-dt-tegra20.c; tegra_ehci_probe() should do something like:

pdata = pdev->dev.platform_data
if (!pdata)

Quoted 7 lines
    pdata = parse_pdata_from_dt();
/* user didn't specify any in DT either */
if (!pdata)
    pdata = default_pdata_for_port();

... where perhaps the use of defaults could be folded into parse_pdata_from_dt().

Thanks Stephen for the detailed explanation.

Kishon / Felipe,
Do you have any more questions in this related, before patch can be applied?

#4 lore raw

Hi,

Quoted 55 lines · Venu Byravarasu
Quoted 55 lines

-----Original Message-----
From: Stephen Warren [mailto:[email protected]]
Sent: Friday, September 21, 2012 9:45 PM
To: ABRAHAM, KISHON VIJAY
Cc: Venu Byravarasu; [email protected]; [email protected]; linux- [email protected]; [email protected]
Subject: Re: [PATCH v3] USB: PHY: Re-organize Tegra USB PHY driver

Quoted 3 lines · KISHON VIJAY

Hi,

On Fri, Sep 21, 2012 at 5:50 PM, Venu Byravarasu

Quoted 7 lines · <[email protected]> wrote:

Review static int tegra_ehci_probe(struct platform_device

Quoted 7 lines

NVIDIA produces several Tegra SoCs viz Tegra20, Tegra30 etc. In order to support USB PHY drivers on these SoCs, existing PHY driver is split into SoC agnostic common USB PHY driver and Tegra20-specific USB phy driver. This will facilitate easy addition and deletion of phy drivers for Tegra SoCs.

(quoted diff) +0 -0
@@ -618,6 +618,9 @@ static int tegra_ehci_probe(struct platform_device

*pdev)
...

Quoted 2 lines

drivers/usb/host/ehci-tegra.c static int tegra_ehci_probe(struct platform_device *pdev) · line 626

Quoted 2 lines
drivers/usb/host/ehci-tegra.c +0 -0
        pdata = pdev->dev.platform_data;
        if (!pdata) {

Some missing lines of context are:

                dev_err(&pdev->dev, "Platform data missing\n");
                return -EINVAL;
        }

...

Quoted 6 lines

drivers/usb/host/ehci-tegra.c static int tegra_ehci_probe(struct platform_device *pdev) · line 726

Quoted 2 lines
drivers/usb/host/ehci-tegra.c +2 -0
+       params.mode = TEGRA_USB_PHY_MODE_HOST;
+       params.config = pdata->phy_config;

I fail to understand how pdata is not NULL in dt boot. I know i've already given this comment and you replied that you dint see any crash. But I'd like to know where and how pdata gets populated.

In practice, the platform uses AUXDATA to provide platform data to the driver even when it's instantiated using device tree; see arch/arm/mach-tegra/board-dt-tegra20.c variables tegra_ehci*_pdata and tegra20_auxdata_lookup[].

In the slightly (very very slightly, hopefully) longer term, I would like to completely remove the AUXDATA setup from board-dt-tegra20.c; tegra_ehci_probe() should do something like:

pdata = pdev->dev.platform_data
if (!pdata)

    pdata = parse_pdata_from_dt();
/* user didn't specify any in DT either */
if (!pdata)
    pdata = default_pdata_for_port();
Quoted 8 lines
Quoted 2 lines

... where perhaps the use of defaults could be folded into parse_pdata_from_dt().

Thanks Stephen for the detailed explanation.

Kishon / Felipe,
Do you have any more questions in this related, before patch can be applied?

I don't have any further comments.

Thanks
Kishon

#5 lore raw
Quoted 73 lines

-----Original Message-----
From: ABRAHAM, KISHON VIJAY [mailto:[email protected]]
Sent: Monday, September 24, 2012 11:48 AM
To: Venu Byravarasu
Cc: Stephen Warren; [email protected]; [email protected]; linux- [email protected]; [email protected]
Subject: Re: [PATCH v3] USB: PHY: Re-organize Tegra USB PHY driver

Hi,

Quoted 12 lines · Venu Byravarasu
Quoted 12 lines

-----Original Message-----
From: Stephen Warren [mailto:[email protected]]
Sent: Friday, September 21, 2012 9:45 PM
To: ABRAHAM, KISHON VIJAY
Cc: Venu Byravarasu; [email protected]; [email protected]; linux- [email protected]; [email protected]
Subject: Re: [PATCH v3] USB: PHY: Re-organize Tegra USB PHY driver

Quoted 3 lines · KISHON VIJAY

Hi,

On Fri, Sep 21, 2012 at 5:50 PM, Venu Byravarasu

Quoted 8 lines
Quoted 8 lines
Quoted 7 lines · <[email protected]> wrote:

Review static int tegra_ehci_probe(struct

Quoted 7 lines

NVIDIA produces several Tegra SoCs viz Tegra20, Tegra30 etc. In order to support USB PHY drivers on these SoCs, existing PHY driver is split into SoC agnostic common USB PHY driver and Tegra20-specific USB phy driver. This will facilitate easy addition and deletion of phy drivers for Tegra SoCs.

(quoted diff) +0 -0
@@ -618,6 +618,9 @@ static int tegra_ehci_probe(struct

platform_device

Quoted 15 lines
Quoted 15 lines

*pdev)
...

Quoted 2 lines

drivers/usb/host/ehci-tegra.c static int tegra_ehci_probe(struct platform_device *pdev) · line 626

Quoted 2 lines
drivers/usb/host/ehci-tegra.c +0 -0
        pdata = pdev->dev.platform_data;
        if (!pdata) {

Some missing lines of context are:

                dev_err(&pdev->dev, "Platform data missing\n");
                return -EINVAL;
        }

...

Quoted 3 lines
Quoted 2 lines
drivers/usb/host/ehci-tegra.c +2 -0
+       params.mode = TEGRA_USB_PHY_MODE_HOST;
+       params.config = pdata->phy_config;
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines

I fail to understand how pdata is not NULL in dt boot. I know i've already given this comment and you replied that you dint see any crash. But I'd like to know where and how pdata gets populated.

In practice, the platform uses AUXDATA to provide platform data to the driver even when it's instantiated using device tree; see arch/arm/mach-tegra/board-dt-tegra20.c variables tegra_ehci*_pdata

and

Quoted 17 lines
Quoted 15 lines

tegra20_auxdata_lookup[].

In the slightly (very very slightly, hopefully) longer term, I would like to completely remove the AUXDATA setup from board-dt-tegra20.c; tegra_ehci_probe() should do something like:

pdata = pdev->dev.platform_data
if (!pdata)

    pdata = parse_pdata_from_dt();
/* user didn't specify any in DT either */
if (!pdata)
    pdata = default_pdata_for_port();

... where perhaps the use of defaults could be folded into parse_pdata_from_dt().

Quoted 8 lines
Quoted 4 lines

Thanks Stephen for the detailed explanation.

Kishon / Felipe,
Do you have any more questions in this related, before patch can be

applied?

I don't have any further comments.

Thanks Kishon for your quick response.

Quoted 2 lines

Thanks
Kishon

#6 lore raw
In reply to ABRAHAM, KISHON VIJAY
Quoted 23 lines

-----Original Message-----
From: ABRAHAM, KISHON VIJAY [mailto:[email protected]]
Sent: Monday, September 24, 2012 11:48 AM
To: Venu Byravarasu
Cc: Stephen Warren; [email protected]; [email protected]; linux- [email protected]; [email protected]
Subject: Re: [PATCH v3] USB: PHY: Re-organize Tegra USB PHY driver

Hi,

Quoted 11 lines · Venu Byravarasu
Quoted 11 lines

-----Original Message-----
From: Stephen Warren [mailto:[email protected]]
Sent: Friday, September 21, 2012 9:45 PM
To: ABRAHAM, KISHON VIJAY
Cc: Venu Byravarasu; [email protected]; [email protected]; linux- [email protected]; [email protected]
Subject: Re: [PATCH v3] USB: PHY: Re-organize Tegra USB PHY driver

Quoted 2 lines · KISHON VIJAY

Hi,

...

Quoted 7 lines
Quoted 7 lines
Quoted 3 lines

... where perhaps the use of defaults could be folded into parse_pdata_from_dt().

Thanks Stephen for the detailed explanation.

Quoted 8 lines
Quoted 2 lines

Kishon / Felipe,
Do you have any more questions in this related, before patch can be

applied?

I don't have any further comments.

Thanks
Kishon

Felipe,

Can you plz merge this patch, if you don't have any objections?

Thanks,
Venu

Tested-by on v3 1/1
#7 lore raw
In reply to Venu Byravarasu
Quoted 7 lines · Venu Byravarasu

NVIDIA produces several Tegra SoCs viz Tegra20, Tegra30 etc. In order to support USB PHY drivers on these SoCs, existing PHY driver is split into SoC agnostic common USB PHY driver and Tegra20-specific USB phy driver. This will facilitate easy addition and deletion of phy drivers for Tegra SoCs.

Quoted 5 lines

---
delta from v2:

Added an if condition to check for device_node to be not NULL, before dereferencing it.

I suppose that doesn't hurt, but it's not strictly needed; this code will only ever run on systems that boot using device tree now.