From: Guenter Roeck <linux@roeck-us.net>
To: Florian Fainelli <f.fainelli@gmail.com>
Cc: Chris Healy <chealy@imsco-us.com>,
linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
Guenter Roeck <linux@roeck-us.net>
Subject: [PATCH 2/3] net: mdio-gpio: Add support for active low gpio pins
Date: Tue, 15 Apr 2014 19:16:41 -0700 [thread overview]
Message-ID: <1397614602-29694-3-git-send-email-linux@roeck-us.net> (raw)
In-Reply-To: <1397614602-29694-1-git-send-email-linux@roeck-us.net>
Some systems using mdio-gpio may use active-low gpio pins
(eg with inverters or FETs connected to all or some of the
gpio pins).
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
drivers/net/phy/mdio-gpio.c | 19 +++++++++++++------
include/linux/mdio-gpio.h | 3 +++
2 files changed, 16 insertions(+), 6 deletions(-)
diff --git a/drivers/net/phy/mdio-gpio.c b/drivers/net/phy/mdio-gpio.c
index e853066..fac211a 100644
--- a/drivers/net/phy/mdio-gpio.c
+++ b/drivers/net/phy/mdio-gpio.c
@@ -33,28 +33,32 @@
struct mdio_gpio_info {
struct mdiobb_ctrl ctrl;
int mdc, mdio;
+ int mdc_active_low, mdio_active_low;
};
static void *mdio_gpio_of_get_data(struct platform_device *pdev)
{
struct device_node *np = pdev->dev.of_node;
struct mdio_gpio_platform_data *pdata;
+ enum of_gpio_flags flags;
int ret;
pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
if (!pdata)
return NULL;
- ret = of_get_gpio(np, 0);
+ ret = of_get_gpio_flags(np, 0, &flags);
if (ret < 0)
return NULL;
pdata->mdc = ret;
+ pdata->mdc_active_low = flags & OF_GPIO_ACTIVE_LOW;
- ret = of_get_gpio(np, 1);
+ ret = of_get_gpio_flags(np, 1, &flags);
if (ret < 0)
return NULL;
pdata->mdio = ret;
+ pdata->mdio_active_low = flags & OF_GPIO_ACTIVE_LOW;
return pdata;
}
@@ -65,7 +69,8 @@ static void mdio_dir(struct mdiobb_ctrl *ctrl, int dir)
container_of(ctrl, struct mdio_gpio_info, ctrl);
if (dir)
- gpio_direction_output(bitbang->mdio, 1);
+ gpio_direction_output(bitbang->mdio,
+ 1 ^ bitbang->mdio_active_low);
else
gpio_direction_input(bitbang->mdio);
}
@@ -75,7 +80,7 @@ static int mdio_get(struct mdiobb_ctrl *ctrl)
struct mdio_gpio_info *bitbang =
container_of(ctrl, struct mdio_gpio_info, ctrl);
- return gpio_get_value(bitbang->mdio);
+ return gpio_get_value(bitbang->mdio) ^ bitbang->mdio_active_low;
}
static void mdio_set(struct mdiobb_ctrl *ctrl, int what)
@@ -83,7 +88,7 @@ static void mdio_set(struct mdiobb_ctrl *ctrl, int what)
struct mdio_gpio_info *bitbang =
container_of(ctrl, struct mdio_gpio_info, ctrl);
- gpio_set_value(bitbang->mdio, what);
+ gpio_set_value(bitbang->mdio, what ^ bitbang->mdio_active_low);
}
static void mdc_set(struct mdiobb_ctrl *ctrl, int what)
@@ -91,7 +96,7 @@ static void mdc_set(struct mdiobb_ctrl *ctrl, int what)
struct mdio_gpio_info *bitbang =
container_of(ctrl, struct mdio_gpio_info, ctrl);
- gpio_set_value(bitbang->mdc, what);
+ gpio_set_value(bitbang->mdc, what ^ bitbang->mdc_active_low);
}
static struct mdiobb_ops mdio_gpio_ops = {
@@ -117,7 +122,9 @@ static struct mii_bus *mdio_gpio_bus_init(struct device *dev,
bitbang->ctrl.ops = &mdio_gpio_ops;
bitbang->ctrl.reset = pdata->reset;
bitbang->mdc = pdata->mdc;
+ bitbang->mdc_active_low = pdata->mdc_active_low;
bitbang->mdio = pdata->mdio;
+ bitbang->mdio_active_low = pdata->mdio_active_low;
new_bus = alloc_mdio_bitbang(&bitbang->ctrl);
if (!new_bus)
diff --git a/include/linux/mdio-gpio.h b/include/linux/mdio-gpio.h
index 7c9fe3c..57e57fe 100644
--- a/include/linux/mdio-gpio.h
+++ b/include/linux/mdio-gpio.h
@@ -18,6 +18,9 @@ struct mdio_gpio_platform_data {
unsigned int mdc;
unsigned int mdio;
+ bool mdc_active_low;
+ bool mdio_active_low;
+
unsigned int phy_mask;
int irqs[PHY_MAX_ADDR];
/* reset callback */
--
1.7.9.7
next prev parent reply other threads:[~2014-04-16 2:16 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-16 2:16 [PATCH 0/3] net: mdio-gpio enhancements Guenter Roeck
2014-04-16 2:16 ` [PATCH 1/3] net: mdio-gpio: Use devm_ functions where possible Guenter Roeck
2014-04-16 2:50 ` Chris Healy
2014-04-16 3:17 ` David Miller
2014-04-16 18:48 ` Chris Healy
2014-04-16 18:50 ` Chris Healy
2014-04-16 20:22 ` Guenter Roeck
2014-04-18 19:19 ` Sergei Shtylyov
2014-04-16 2:16 ` Guenter Roeck [this message]
2014-04-16 2:44 ` [PATCH 2/3] net: mdio-gpio: Add support for active low gpio pins Chris Healy
2014-04-16 2:16 ` [PATCH 3/3] net: mdio-gpio: Add support for separate MDI and MDO " Guenter Roeck
2014-04-16 2:45 ` Chris Healy
2014-04-16 19:10 ` [PATCH 0/3] net: mdio-gpio enhancements David Miller
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=1397614602-29694-3-git-send-email-linux@roeck-us.net \
--to=linux@roeck-us.net \
--cc=chealy@imsco-us.com \
--cc=f.fainelli@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).