From: ahaslam@baylibre.com
To: gregkh@linuxfoundation.org, johan@kernel.org, robh+dt@kernel.org,
nsekhar@ti.com, stern@rowland.harvard.edu, khilman@baylibre.com,
sshtylyov@ru.mvista.com, david@lechnology.com,
manjunath.goudar@linaro.org, broonie@kernel.org,
abailon@baylibre.com
Cc: linux-usb@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
Axel Haslam <ahaslam@baylibre.com>
Subject: [PATCH/RFT v2 13/17] USB: da8xx: use ohci priv data instead of globals
Date: Mon, 24 Oct 2016 18:46:30 +0200 [thread overview]
Message-ID: <20161024164634.4330-14-ahaslam@baylibre.com> (raw)
In-Reply-To: <20161024164634.4330-1-ahaslam@baylibre.com>
From: Axel Haslam <ahaslam@baylibre.com>
Instead of global variables, use the extra_priv_size of the ohci driver
to add a reference to driver private data.
Signed-off-by: Axel Haslam <ahaslam@baylibre.com>
---
drivers/usb/host/ohci-da8xx.c | 135 ++++++++++++++++++++++++------------------
1 file changed, 79 insertions(+), 56 deletions(-)
diff --git a/drivers/usb/host/ohci-da8xx.c b/drivers/usb/host/ohci-da8xx.c
index f4bda4d..bebc3f0 100644
--- a/drivers/usb/host/ohci-da8xx.c
+++ b/drivers/usb/host/ohci-da8xx.c
@@ -37,60 +37,66 @@ static int (*orig_ohci_hub_control)(struct usb_hcd *hcd, u16 typeReq,
u16 wValue, u16 wIndex, char *buf, u16 wLength);
static int (*orig_ohci_hub_status_data)(struct usb_hcd *hcd, char *buf);
-static struct clk *usb11_clk;
-static struct phy *usb11_phy;
-static struct regulator *vbus_reg;
-struct notifier_block nb;
-
-/* Over-current indicator change flag */
-static int ocic_flag;
+struct da8xx_ohci_hcd {
+ struct usb_hcd *hcd;
+ struct clk *usb11_clk;
+ struct phy *usb11_phy;
+ struct regulator *vbus_reg;
+ struct notifier_block nb;
+ int ocic_flag;
+};
+#define to_da8xx_ohci(hcd) (struct da8xx_ohci_hcd *)(hcd_to_ohci(hcd)->priv)
-static int ohci_da8xx_enable(void)
+static int ohci_da8xx_enable(struct usb_hcd *hcd)
{
+ struct da8xx_ohci_hcd *da8xx_ohci = to_da8xx_ohci(hcd);
int ret;
- ret = clk_prepare_enable(usb11_clk);
+ ret = clk_prepare_enable(da8xx_ohci->usb11_clk);
if (ret)
return ret;
- ret = phy_init(usb11_phy);
+ ret = phy_init(da8xx_ohci->usb11_phy);
if (ret)
goto err_phy_init;
- ret = phy_power_on(usb11_phy);
+ ret = phy_power_on(da8xx_ohci->usb11_phy);
if (ret)
goto err_phy_power_on;
return 0;
err_phy_power_on:
- phy_exit(usb11_phy);
+ phy_exit(da8xx_ohci->usb11_phy);
err_phy_init:
- clk_disable_unprepare(usb11_clk);
+ clk_disable_unprepare(da8xx_ohci->usb11_clk);
return ret;
}
-static void ohci_da8xx_disable(void)
+static void ohci_da8xx_disable(struct usb_hcd *hcd)
{
- phy_power_off(usb11_phy);
- phy_exit(usb11_phy);
- clk_disable_unprepare(usb11_clk);
+ struct da8xx_ohci_hcd *da8xx_ohci = to_da8xx_ohci(hcd);
+
+ phy_power_off(da8xx_ohci->usb11_phy);
+ phy_exit(da8xx_ohci->usb11_phy);
+ clk_disable_unprepare(da8xx_ohci->usb11_clk);
}
-static int ohci_da8xx_set_power(int on)
+static int ohci_da8xx_set_power(struct usb_hcd *hcd, int on)
{
+ struct da8xx_ohci_hcd *da8xx_ohci = to_da8xx_ohci(hcd);
int ret = 0;
- if (!vbus_reg)
+ if (!da8xx_ohci->vbus_reg)
return 0;
if (on) {
- ret = regulator_enable(vbus_reg);
+ ret = regulator_enable(da8xx_ohci->vbus_reg);
if (ret)
pr_err("fail to enable regulator: %d\n", ret);
} else {
- ret = regulator_disable(vbus_reg);
+ ret = regulator_disable(da8xx_ohci->vbus_reg);
if (ret)
pr_err("fail to disable regulator: %d\n", ret);
}
@@ -98,17 +104,22 @@ static int ohci_da8xx_set_power(int on)
return ret;
}
-static int ohci_da8xx_get_power(void)
+static int ohci_da8xx_get_power(struct usb_hcd *hcd)
{
- if (!vbus_reg)
+ struct da8xx_ohci_hcd *da8xx_ohci = to_da8xx_ohci(hcd);
+
+ if (!da8xx_ohci->vbus_reg)
return 1;
- return regulator_is_enabled(vbus_reg);
+ return regulator_is_enabled(da8xx_ohci->vbus_reg);
}
-static int ohci_da8xx_get_oci(void)
+static int ohci_da8xx_get_oci(struct usb_hcd *hcd)
{
- if (regulator_get_mode(vbus_reg) == REGULATOR_MODE_OVERCURRENT)
+ struct da8xx_ohci_hcd *da8xx_ohci = to_da8xx_ohci(hcd);
+
+ if (regulator_get_mode(da8xx_ohci->vbus_reg) ==
+ REGULATOR_MODE_OVERCURRENT)
return 1;
return 0;
@@ -117,10 +128,13 @@ static int ohci_da8xx_get_oci(void)
static int ohci_da8xx_regulator_event(struct notifier_block *nb,
unsigned long event, void *data)
{
+ struct da8xx_ohci_hcd *da8xx_ohci =
+ container_of(nb, struct da8xx_ohci_hcd, nb);
+
if (event & REGULATOR_EVENT_OVER_CURRENT) {
- ocic_flag = 1;
- if (ohci_da8xx_get_oci())
- ohci_da8xx_set_power(0);
+ da8xx_ohci->ocic_flag = 1;
+ if (ohci_da8xx_get_oci(da8xx_ohci->hcd))
+ ohci_da8xx_set_power(da8xx_ohci->hcd, 0);
}
return 0;
@@ -130,12 +144,13 @@ static int ohci_da8xx_reset(struct usb_hcd *hcd)
{
struct device *dev = hcd->self.controller;
struct ohci_hcd *ohci = hcd_to_ohci(hcd);
+ struct da8xx_ohci_hcd *da8xx_ohci = to_da8xx_ohci(hcd);
int result;
u32 rh_a;
dev_dbg(dev, "starting USB controller\n");
- result = ohci_da8xx_enable();
+ result = ohci_da8xx_enable(hcd);
if (result < 0)
return result;
@@ -147,7 +162,7 @@ static int ohci_da8xx_reset(struct usb_hcd *hcd)
result = ohci_setup(hcd);
if (result < 0) {
- ohci_da8xx_disable();
+ ohci_da8xx_disable(hcd);
return result;
}
@@ -159,7 +174,7 @@ static int ohci_da8xx_reset(struct usb_hcd *hcd)
*/
rh_a = ohci_readl(ohci, &ohci->regs->roothub.a);
- if (vbus_reg) {
+ if (da8xx_ohci->vbus_reg) {
rh_a &= ~RH_A_NPS;
rh_a |= RH_A_PSM;
rh_a &= ~RH_A_NOCP;
@@ -176,10 +191,11 @@ static int ohci_da8xx_reset(struct usb_hcd *hcd)
*/
static int ohci_da8xx_hub_status_data(struct usb_hcd *hcd, char *buf)
{
+ struct da8xx_ohci_hcd *da8xx_ohci = to_da8xx_ohci(hcd);
int length = orig_ohci_hub_status_data(hcd, buf);
/* See if we have OCIC flag set */
- if (ocic_flag) {
+ if (da8xx_ohci->ocic_flag) {
dev_dbg(hcd->self.controller, "over-current indicator change "
"on port 1\n");
@@ -197,6 +213,7 @@ static int ohci_da8xx_hub_status_data(struct usb_hcd *hcd, char *buf)
static int ohci_da8xx_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
u16 wIndex, char *buf, u16 wLength)
{
+ struct da8xx_ohci_hcd *da8xx_ohci = to_da8xx_ohci(hcd);
struct device *dev = hcd->self.controller;
int temp;
@@ -211,15 +228,15 @@ static int ohci_da8xx_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
temp = roothub_portstatus(hcd_to_ohci(hcd), wIndex - 1);
/* The port power status (PPS) bit defaults to 1 */
- if (ohci_da8xx_get_power() == 0)
+ if (ohci_da8xx_get_power(hcd) == 0)
temp &= ~RH_PS_PPS;
/* The port over-current indicator (POCI) bit is always 0 */
- if (ohci_da8xx_get_oci() > 0)
+ if (ohci_da8xx_get_oci(hcd) > 0)
temp |= RH_PS_POCI;
/* The over-current indicator change (OCIC) bit is 0 too */
- if (ocic_flag)
+ if (da8xx_ohci->ocic_flag)
temp |= RH_PS_OCIC;
put_unaligned(cpu_to_le32(temp), (__le32 *)buf);
@@ -240,13 +257,13 @@ static int ohci_da8xx_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
dev_dbg(dev, "%sPortFeature(%u): %s\n",
temp ? "Set" : "Clear", wIndex, "POWER");
- return ohci_da8xx_set_power(temp) ? -EPIPE : 0;
+ return ohci_da8xx_set_power(hcd, temp) ? -EPIPE : 0;
case USB_PORT_FEAT_C_OVER_CURRENT:
dev_dbg(dev, "%sPortFeature(%u): %s\n",
temp ? "Set" : "Clear", wIndex,
"C_OVER_CURRENT");
- ocic_flag = temp;
+ da8xx_ohci->ocic_flag = temp;
return 0;
}
}
@@ -259,6 +276,7 @@ static int ohci_da8xx_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
static int ohci_da8xx_probe(struct platform_device *pdev)
{
+ struct da8xx_ohci_hcd *da8xx_ohci;
struct usb_hcd *hcd;
struct resource *mem;
int error, irq;
@@ -268,30 +286,34 @@ static int ohci_da8xx_probe(struct platform_device *pdev)
if (!hcd)
return -ENOMEM;
- usb11_clk = devm_clk_get(&pdev->dev, "usb11");
- if (IS_ERR(usb11_clk)) {
- if (PTR_ERR(usb11_clk) != -EPROBE_DEFER)
+ da8xx_ohci = to_da8xx_ohci(hcd);
+ da8xx_ohci->hcd = hcd;
+
+ da8xx_ohci->usb11_clk = devm_clk_get(&pdev->dev, "usb11");
+ if (IS_ERR(da8xx_ohci->usb11_clk)) {
+ if (PTR_ERR(da8xx_ohci->usb11_clk) != -EPROBE_DEFER)
dev_err(&pdev->dev, "Failed to get clock.\n");
- return PTR_ERR(usb11_clk);
+ return PTR_ERR(da8xx_ohci->usb11_clk);
}
- usb11_phy = devm_phy_get(&pdev->dev, "usb-phy");
- if (IS_ERR(usb11_phy)) {
- if (PTR_ERR(usb11_phy) != -EPROBE_DEFER)
+ da8xx_ohci->usb11_phy = devm_phy_get(&pdev->dev, "usb-phy");
+ if (IS_ERR(da8xx_ohci->usb11_phy)) {
+ if (PTR_ERR(da8xx_ohci->usb11_phy) != -EPROBE_DEFER)
dev_err(&pdev->dev, "Failed to get phy.\n");
- return PTR_ERR(usb11_phy);
+ return PTR_ERR(da8xx_ohci->usb11_phy);
}
- vbus_reg = devm_regulator_get(&pdev->dev, "vbus");
- if (IS_ERR(vbus_reg)) {
- if (PTR_ERR(vbus_reg) != -EPROBE_DEFER)
+ da8xx_ohci->vbus_reg = devm_regulator_get(&pdev->dev, "vbus");
+ if (IS_ERR(da8xx_ohci->vbus_reg)) {
+ if (PTR_ERR(da8xx_ohci->vbus_reg) != -EPROBE_DEFER)
dev_err(&pdev->dev, "Failed to get regulator.\n");
- return PTR_ERR(vbus_reg);
+ return PTR_ERR(da8xx_ohci->vbus_reg);
}
- if (vbus_reg) {
- nb.notifier_call = ohci_da8xx_regulator_event;
- error = devm_regulator_register_notifier(vbus_reg, &nb);
+ if (da8xx_ohci->vbus_reg) {
+ da8xx_ohci->nb.notifier_call = ohci_da8xx_regulator_event;
+ error = devm_regulator_register_notifier(da8xx_ohci->vbus_reg,
+ &da8xx_ohci->nb);
if (error) {
dev_err(&pdev->dev,
"Could not register regulator notifier\n");
@@ -354,7 +376,7 @@ static int ohci_da8xx_suspend(struct platform_device *pdev,
if (ret)
return ret;
- ohci_da8xx_disable();
+ ohci_da8xx_disable(hcd);
hcd->state = HC_STATE_SUSPENDED;
return ret;
@@ -370,7 +392,7 @@ static int ohci_da8xx_resume(struct platform_device *dev)
msleep(5);
ohci->next_statechange = jiffies;
- ret = ohci_da8xx_enable();
+ ret = ohci_da8xx_enable(hcd);
if (ret)
return ret;
@@ -382,7 +404,8 @@ static int ohci_da8xx_resume(struct platform_device *dev)
#endif
static const struct ohci_driver_overrides da8xx_overrides __initconst = {
- .reset = ohci_da8xx_reset
+ .reset = ohci_da8xx_reset,
+ .extra_priv_size = sizeof(struct da8xx_ohci_hcd),
};
/*
--
1.9.1
next prev parent reply other threads:[~2016-10-24 16:48 UTC|newest]
Thread overview: 64+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-24 16:46 [PATCH/RFT v2 00/17] Add DT support for ohci-da8xx ahaslam
2016-10-24 16:46 ` [PATCH/RFT v2 01/17] ARM: davinci: da8xx: add usb phy clocks ahaslam
2016-10-24 16:46 ` [PATCH/RFT v2 02/17] ARM: davinci: da8xx: Add CFGCHIP syscon platform declaration ahaslam
2016-10-25 8:10 ` Sekhar Nori
2016-10-25 9:37 ` Axel Haslam
2016-10-25 10:17 ` Sekhar Nori
2016-10-25 15:53 ` David Lechner
2016-10-26 8:56 ` Sekhar Nori
2016-10-24 16:46 ` [PATCH/RFT v2 03/17] ARM: davinci: da8xx: Add USB PHY " ahaslam
2016-10-25 9:18 ` Sekhar Nori
2016-10-25 9:37 ` Axel Haslam
2016-10-24 16:46 ` [PATCH/RFT v2 04/17] ARM: DTS: da850: Add cfgchip syscon node ahaslam
2016-10-24 16:46 ` [PATCH/RFT v2 05/17] ARM: DTS: da850: Add usb phy node ahaslam
2016-10-24 16:46 ` [PATCH/RFT v2 06/17] ARM: davinci: da8xx: Fix some redefined symbol warnings ahaslam
2016-10-25 10:03 ` Sekhar Nori
2016-10-25 12:14 ` Alexandre Bailon
2016-10-24 16:46 ` [PATCH/RFT v2 07/17] ARM: davinci: da8xx: Enable the usb20 "per" clk on phy_clk_enable ahaslam
2016-10-25 2:53 ` David Lechner
2016-10-25 10:01 ` Axel Haslam
2016-10-25 10:12 ` Sekhar Nori
2016-10-25 16:05 ` David Lechner
2016-10-26 9:30 ` Sekhar Nori
2016-10-24 16:46 ` [PATCH/RFT v2 08/17] ARM: davinci: hawk: add full constraints for ohci plat boot ahaslam
2016-10-25 10:28 ` Sekhar Nori
2016-10-25 10:31 ` Axel Haslam
2016-10-24 16:46 ` [PATCH/RFT v2 09/17] regulator: fixed: Add over current event ahaslam
2016-10-24 17:43 ` Mark Brown
2016-10-24 17:53 ` Axel Haslam
2016-10-24 17:53 ` Mark Brown
2016-10-24 18:11 ` Axel Haslam
2016-10-24 18:19 ` Mark Brown
2016-10-25 12:55 ` Axel Haslam
2016-10-25 14:33 ` Mark Brown
2016-10-25 14:57 ` Axel Haslam
2016-10-25 15:07 ` Axel Haslam
2016-10-30 20:42 ` Rob Herring
2016-10-24 16:46 ` [PATCH/RFT v2 10/17] USB: da8xx: use flag instead of bitmask for over current change ahaslam
2016-10-24 16:46 ` [PATCH/RFT v2 11/17] USB: OHCI: make ohci-da8xx a separate driver ahaslam
2016-10-25 0:38 ` David Lechner
2016-10-25 7:39 ` Axel Haslam
2016-10-25 16:12 ` David Lechner
2016-10-25 16:21 ` Axel Haslam
2016-10-25 16:24 ` David Lechner
2016-10-24 16:46 ` [PATCH/RFT v2 12/17] USB: ochi-da8xx: Use a regulator for vbus/overcurrent ahaslam
2016-10-25 1:39 ` David Lechner
2016-10-25 8:24 ` Axel Haslam
2016-10-25 16:53 ` David Lechner
2016-10-25 17:32 ` Axel Haslam
2016-10-25 10:43 ` Sekhar Nori
2016-10-25 10:52 ` Axel Haslam
2016-10-24 16:46 ` ahaslam [this message]
2016-10-25 1:12 ` [PATCH/RFT v2 13/17] USB: da8xx: use ohci priv data instead of globals David Lechner
2016-10-25 9:56 ` Axel Haslam
2016-10-24 16:46 ` [PATCH/RFT v2 14/17] ARM: davinci: register the usb20_phy clock on the DT file ahaslam
2016-10-24 16:46 ` [PATCH/RFT v2 15/17] usb: host: ohci-da8xx: Add devicetree bindings documentation ahaslam
2016-10-25 1:02 ` David Lechner
2016-10-25 9:56 ` Axel Haslam
2016-10-24 16:46 ` [PATCH/RFT v2 16/17] USB: ohci-da8xx: Allow probing from DT ahaslam
2016-10-25 0:53 ` David Lechner
2016-10-25 8:10 ` Axel Haslam
2016-10-24 16:46 ` [PATCH/RFT v2 17/17] ARM: dts: da850: add usb device node ahaslam
2016-10-25 0:48 ` David Lechner
2016-10-25 8:03 ` Axel Haslam
2016-10-25 10:55 ` [PATCH/RFT v2 00/17] Add DT support for ohci-da8xx Sekhar Nori
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20161024164634.4330-14-ahaslam@baylibre.com \
--to=ahaslam@baylibre.com \
--cc=abailon@baylibre.com \
--cc=broonie@kernel.org \
--cc=david@lechnology.com \
--cc=devicetree@vger.kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=johan@kernel.org \
--cc=khilman@baylibre.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=manjunath.goudar@linaro.org \
--cc=nsekhar@ti.com \
--cc=robh+dt@kernel.org \
--cc=sshtylyov@ru.mvista.com \
--cc=stern@rowland.harvard.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome