From: Linus Walleij <linus.walleij@linaro.org>
To: Andrew Lunn <andrew@lunn.ch>,
Florian Fainelli <f.fainelli@gmail.com>,
"David S . Miller" <davem@davemloft.net>
Cc: netdev@vger.kernel.org,
Laurent Pinchart <Laurent.pinchart@ideasonboard.com>,
Linus Walleij <linus.walleij@linaro.org>
Subject: [PATCH net-next 4/5] net: mdio-gpio: Merge platform data into state
Date: Sun, 25 Feb 2018 13:51:31 +0100 [thread overview]
Message-ID: <20180225125132.25275-5-linus.walleij@linaro.org> (raw)
In-Reply-To: <20180225125132.25275-1-linus.walleij@linaro.org>
There is no instantiation without DT data, we can now move
to a single state container and merge the DT property
retrieveal into mdio_gpio_bus_init().
We decomission the phy_mask, phy_ignore_ta_mask and
irqs array and the reset() callback that were all just
sitting unused and taking up space.
If bitbanged GPIOs need to set up reset() callbacks these
should be done in the device tree using proper bindings.
If bitbanged GPIOs need to handle IRQs, these should be
done in the device tree using the proper bindings.
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
drivers/net/phy/mdio-gpio.c | 130 ++++++++++++++++----------------------------
1 file changed, 48 insertions(+), 82 deletions(-)
diff --git a/drivers/net/phy/mdio-gpio.c b/drivers/net/phy/mdio-gpio.c
index 96c953d086c6..9146077b5278 100644
--- a/drivers/net/phy/mdio-gpio.c
+++ b/drivers/net/phy/mdio-gpio.c
@@ -30,61 +30,11 @@
#include <linux/of_gpio.h>
#include <linux/of_mdio.h>
-struct mdio_gpio_platform_data {
- /* GPIO numbers for bus pins */
- unsigned int mdc;
- unsigned int mdio;
- unsigned int mdo;
-
- bool mdc_active_low;
- bool mdio_active_low;
- bool mdo_active_low;
-
- u32 phy_mask;
- u32 phy_ignore_ta_mask;
- int irqs[PHY_MAX_ADDR];
- /* reset callback */
- int (*reset)(struct mii_bus *bus);
-};
-
struct mdio_gpio_info {
struct mdiobb_ctrl ctrl;
struct gpio_desc *mdc, *mdio, *mdo;
};
-static void *mdio_gpio_of_get_data(struct device *dev)
-{
- struct device_node *np = dev->of_node;
- struct mdio_gpio_platform_data *pdata;
- enum of_gpio_flags flags;
- int ret;
-
- pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
- if (!pdata)
- return NULL;
-
- 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_flags(np, 1, &flags);
- if (ret < 0)
- return NULL;
- pdata->mdio = ret;
- pdata->mdio_active_low = flags & OF_GPIO_ACTIVE_LOW;
-
- ret = of_get_gpio_flags(np, 2, &flags);
- if (ret > 0) {
- pdata->mdo = ret;
- pdata->mdo_active_low = flags & OF_GPIO_ACTIVE_LOW;
- }
-
- return pdata;
-}
-
static void mdio_dir(struct mdiobb_ctrl *ctrl, int dir)
{
struct mdio_gpio_info *bitbang =
@@ -142,31 +92,60 @@ static const struct mdiobb_ops mdio_gpio_ops = {
};
static struct mii_bus *mdio_gpio_bus_init(struct device *dev,
- struct mdio_gpio_info *bitbang,
- struct mdio_gpio_platform_data *pdata,
- int bus_id)
+ struct mdio_gpio_info *bitbang)
{
- struct mii_bus *new_bus;
- int i;
- int mdc, mdio, mdo;
+ unsigned long mdo_flags = GPIOF_OUT_INIT_HIGH;
unsigned long mdc_flags = GPIOF_OUT_INIT_LOW;
unsigned long mdio_flags = GPIOF_DIR_IN;
- unsigned long mdo_flags = GPIOF_OUT_INIT_HIGH;
+ struct device_node *np = dev->of_node;
+ enum of_gpio_flags flags;
+ struct mii_bus *new_bus;
+ bool mdio_active_low;
+ bool mdc_active_low;
+ bool mdo_active_low;
+ unsigned int mdio;
+ unsigned int mdc;
+ unsigned int mdo;
+ int bus_id;
+ int ret, i;
+
+ ret = of_get_gpio_flags(np, 0, &flags);
+ if (ret < 0)
+ return NULL;
+
+ mdc = ret;
+ mdc_active_low = flags & OF_GPIO_ACTIVE_LOW;
+
+ ret = of_get_gpio_flags(np, 1, &flags);
+ if (ret < 0)
+ return NULL;
+ mdio = ret;
+ mdio_active_low = flags & OF_GPIO_ACTIVE_LOW;
+
+ ret = of_get_gpio_flags(np, 2, &flags);
+ if (ret > 0) {
+ mdo = ret;
+ mdo_active_low = flags & OF_GPIO_ACTIVE_LOW;
+ } else {
+ mdo = 0;
+ }
+
+ bus_id = of_alias_get_id(np, "mdio-gpio");
+ if (bus_id < 0) {
+ dev_warn(dev, "failed to get alias id\n");
+ bus_id = 0;
+ }
bitbang->ctrl.ops = &mdio_gpio_ops;
- bitbang->ctrl.reset = pdata->reset;
- mdc = pdata->mdc;
bitbang->mdc = gpio_to_desc(mdc);
- if (pdata->mdc_active_low)
+ if (mdc_active_low)
mdc_flags = GPIOF_OUT_INIT_HIGH | GPIOF_ACTIVE_LOW;
- mdio = pdata->mdio;
bitbang->mdio = gpio_to_desc(mdio);
- if (pdata->mdio_active_low)
+ if (mdio_active_low)
mdio_flags |= GPIOF_ACTIVE_LOW;
- mdo = pdata->mdo;
if (mdo) {
bitbang->mdo = gpio_to_desc(mdo);
- if (pdata->mdo_active_low)
+ if (mdo_active_low)
mdo_flags = GPIOF_OUT_INIT_LOW | GPIOF_ACTIVE_LOW;
}
@@ -175,10 +154,6 @@ static struct mii_bus *mdio_gpio_bus_init(struct device *dev,
goto out;
new_bus->name = "GPIO Bitbanged MDIO",
-
- new_bus->phy_mask = pdata->phy_mask;
- new_bus->phy_ignore_ta_mask = pdata->phy_ignore_ta_mask;
- memcpy(new_bus->irq, pdata->irqs, sizeof(new_bus->irq));
new_bus->parent = dev;
if (new_bus->phy_mask == ~0)
@@ -229,31 +204,22 @@ static void mdio_gpio_bus_destroy(struct device *dev)
static int mdio_gpio_probe(struct platform_device *pdev)
{
- struct mdio_gpio_platform_data *pdata;
struct device *dev = &pdev->dev;
struct mdio_gpio_info *bitbang;
struct mii_bus *new_bus;
- int ret, bus_id;
+ struct device_node *np;
+ int ret;
+ np = dev->of_node;
bitbang = devm_kzalloc(dev, sizeof(*bitbang), GFP_KERNEL);
if (!bitbang)
return -ENOMEM;
- pdata = mdio_gpio_of_get_data(dev);
- bus_id = of_alias_get_id(dev->of_node, "mdio-gpio");
- if (bus_id < 0) {
- dev_warn(dev, "failed to get alias id\n");
- bus_id = 0;
- }
-
- if (!pdata)
- return -ENODEV;
-
- new_bus = mdio_gpio_bus_init(dev, bitbang, pdata, bus_id);
+ new_bus = mdio_gpio_bus_init(dev, bitbang);
if (!new_bus)
return -ENODEV;
- ret = of_mdiobus_register(new_bus, dev->of_node);
+ ret = of_mdiobus_register(new_bus, np);
if (ret)
mdio_gpio_bus_deinit(dev);
--
2.14.3
next prev parent reply other threads:[~2018-02-25 12:54 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-25 12:51 [PATCH net-next 0/5] Modernize bitbanged GPIO MDIO Linus Walleij
2018-02-25 12:51 ` [PATCH net-next 1/5] net: mdio-gpio: Localize platform data Linus Walleij
2018-02-25 12:51 ` [PATCH net-next 2/5] net: mdio-gpio: Allocate state in probe() Linus Walleij
2018-02-25 12:51 ` [PATCH net-next 3/5] net: mdio-gpio: Remove non-DT probe path Linus Walleij
2018-02-25 12:51 ` Linus Walleij [this message]
2018-02-25 12:51 ` [PATCH net-next 5/5] net: mdio-gpio: Move to gpiod API Linus Walleij
2018-02-25 19:08 ` [PATCH net-next 0/5] Modernize bitbanged GPIO MDIO Andrew Lunn
2018-02-27 8:53 ` Linus Walleij
2018-02-27 14:00 ` Florian Fainelli
2018-02-27 23:10 ` Andrew Lunn
2018-02-27 23:46 ` Florian Fainelli
2018-03-02 9:44 ` Linus Walleij
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=20180225125132.25275-5-linus.walleij@linaro.org \
--to=linus.walleij@linaro.org \
--cc=Laurent.pinchart@ideasonboard.com \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=f.fainelli@gmail.com \
--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).