From: Andrew Lunn <andrew@lunn.ch>
To: Jisheng Zhang <Jisheng.Zhang@synaptics.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>,
"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
Jose Abreu <joabreu@synopsys.com>,
Giuseppe Cavallaro <peppe.cavallaro@st.com>,
"David S. Miller" <davem@davemloft.net>,
"linux-arm-kernel@lists.infradead.org"
<linux-arm-kernel@lists.infradead.org>
Subject: Re: [PATCH v2 net-next] net: stmmac: move reset gpio parse & request to stmmac_mdio_register
Date: Thu, 6 Jun 2019 15:44:52 +0200 [thread overview]
Message-ID: <20190606134452.GD19590@lunn.ch> (raw)
In-Reply-To: <20190606182244.422e187f@xhacker.debian>
On Thu, Jun 06, 2019 at 10:31:56AM +0000, Jisheng Zhang wrote:
> Move the reset gpio dt parse and request to stmmac_mdio_register(),
> thus makes the mdio code straightforward.
>
> This patch also replace stack var mdio_bus_data with data to simplify
> the code.
Hi Jisheng
Please split this into two patches.
>
> Signed-off-by: Jisheng Zhang <Jisheng.Zhang@synaptics.com>
> ---
> Since v1:
> - rebase on the latest net-next tree
>
> .../net/ethernet/stmicro/stmmac/stmmac_mdio.c | 58 ++++++++-----------
> 1 file changed, 25 insertions(+), 33 deletions(-)
>
> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
> index 093a223fe408..7d1562ec1149 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
> @@ -250,28 +250,7 @@ int stmmac_mdio_reset(struct mii_bus *bus)
> struct stmmac_mdio_bus_data *data = priv->plat->mdio_bus_data;
>
> #ifdef CONFIG_OF
> - if (priv->device->of_node) {
> - if (data->reset_gpio < 0) {
> - struct device_node *np = priv->device->of_node;
> -
> - if (!np)
> - return 0;
> -
> - data->reset_gpio = of_get_named_gpio(np,
> - "snps,reset-gpio", 0);
> - if (data->reset_gpio < 0)
> - return 0;
> -
> - data->active_low = of_property_read_bool(np,
> - "snps,reset-active-low");
> - of_property_read_u32_array(np,
> - "snps,reset-delays-us", data->delays, 3);
> -
> - if (devm_gpio_request(priv->device, data->reset_gpio,
> - "mdio-reset"))
> - return 0;
> - }
> -
> + if (gpio_is_valid(data->reset_gpio)) {
> gpio_direction_output(data->reset_gpio,
> data->active_low ? 1 : 0);
> if (data->delays[0])
> @@ -313,24 +292,38 @@ int stmmac_mdio_register(struct net_device *ndev)
> int err = 0;
> struct mii_bus *new_bus;
> struct stmmac_priv *priv = netdev_priv(ndev);
> - struct stmmac_mdio_bus_data *mdio_bus_data = priv->plat->mdio_bus_data;
> + struct stmmac_mdio_bus_data *data = priv->plat->mdio_bus_data;
> struct device_node *mdio_node = priv->plat->mdio_node;
> struct device *dev = ndev->dev.parent;
> int addr, found, max_addr;
>
> - if (!mdio_bus_data)
> + if (!data)
> return 0;
>
> new_bus = mdiobus_alloc();
> if (!new_bus)
> return -ENOMEM;
>
> - if (mdio_bus_data->irqs)
> - memcpy(new_bus->irq, mdio_bus_data->irqs, sizeof(new_bus->irq));
> + if (data->irqs)
> + memcpy(new_bus->irq, data->irqs, sizeof(new_bus->irq));
>
> #ifdef CONFIG_OF
> - if (priv->device->of_node)
> - mdio_bus_data->reset_gpio = -1;
> + if (priv->device->of_node) {
> + struct device_node *np = priv->device->of_node;
> +
> + data->reset_gpio = of_get_named_gpio(np, "snps,reset-gpio", 0);
> + if (gpio_is_valid(data->reset_gpio)) {
> + data->active_low = of_property_read_bool(np,
> + "snps,reset-active-low");
> + of_property_read_u32_array(np,
> + "snps,reset-delays-us", data->delays, 3);
> +
> + devm_gpio_request(priv->device, data->reset_gpio,
> + "mdio-reset");
> + }
> + } else {
> + data->reset_gpio = -1;
> + }
This seems like a good candidate to be a small helper
function. Quoting the coding style:
6) Functions
------------
Functions should be short and sweet, and do just one thing. They should
fit on one or two screenfuls of text (the ISO/ANSI screen size is 80x24,
as we all know), and do one thing and do that well.
stmmac_mdio_register() is not short and sweet, and this is making it
bigger.
Andrew
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
WARNING: multiple messages have this Message-ID (diff)
From: Andrew Lunn <andrew@lunn.ch>
To: Jisheng Zhang <Jisheng.Zhang@synaptics.com>
Cc: Giuseppe Cavallaro <peppe.cavallaro@st.com>,
Alexandre Torgue <alexandre.torgue@st.com>,
Jose Abreu <joabreu@synopsys.com>,
"David S. Miller" <davem@davemloft.net>,
"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"linux-arm-kernel@lists.infradead.org"
<linux-arm-kernel@lists.infradead.org>
Subject: Re: [PATCH v2 net-next] net: stmmac: move reset gpio parse & request to stmmac_mdio_register
Date: Thu, 6 Jun 2019 15:44:52 +0200 [thread overview]
Message-ID: <20190606134452.GD19590@lunn.ch> (raw)
In-Reply-To: <20190606182244.422e187f@xhacker.debian>
On Thu, Jun 06, 2019 at 10:31:56AM +0000, Jisheng Zhang wrote:
> Move the reset gpio dt parse and request to stmmac_mdio_register(),
> thus makes the mdio code straightforward.
>
> This patch also replace stack var mdio_bus_data with data to simplify
> the code.
Hi Jisheng
Please split this into two patches.
>
> Signed-off-by: Jisheng Zhang <Jisheng.Zhang@synaptics.com>
> ---
> Since v1:
> - rebase on the latest net-next tree
>
> .../net/ethernet/stmicro/stmmac/stmmac_mdio.c | 58 ++++++++-----------
> 1 file changed, 25 insertions(+), 33 deletions(-)
>
> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
> index 093a223fe408..7d1562ec1149 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
> @@ -250,28 +250,7 @@ int stmmac_mdio_reset(struct mii_bus *bus)
> struct stmmac_mdio_bus_data *data = priv->plat->mdio_bus_data;
>
> #ifdef CONFIG_OF
> - if (priv->device->of_node) {
> - if (data->reset_gpio < 0) {
> - struct device_node *np = priv->device->of_node;
> -
> - if (!np)
> - return 0;
> -
> - data->reset_gpio = of_get_named_gpio(np,
> - "snps,reset-gpio", 0);
> - if (data->reset_gpio < 0)
> - return 0;
> -
> - data->active_low = of_property_read_bool(np,
> - "snps,reset-active-low");
> - of_property_read_u32_array(np,
> - "snps,reset-delays-us", data->delays, 3);
> -
> - if (devm_gpio_request(priv->device, data->reset_gpio,
> - "mdio-reset"))
> - return 0;
> - }
> -
> + if (gpio_is_valid(data->reset_gpio)) {
> gpio_direction_output(data->reset_gpio,
> data->active_low ? 1 : 0);
> if (data->delays[0])
> @@ -313,24 +292,38 @@ int stmmac_mdio_register(struct net_device *ndev)
> int err = 0;
> struct mii_bus *new_bus;
> struct stmmac_priv *priv = netdev_priv(ndev);
> - struct stmmac_mdio_bus_data *mdio_bus_data = priv->plat->mdio_bus_data;
> + struct stmmac_mdio_bus_data *data = priv->plat->mdio_bus_data;
> struct device_node *mdio_node = priv->plat->mdio_node;
> struct device *dev = ndev->dev.parent;
> int addr, found, max_addr;
>
> - if (!mdio_bus_data)
> + if (!data)
> return 0;
>
> new_bus = mdiobus_alloc();
> if (!new_bus)
> return -ENOMEM;
>
> - if (mdio_bus_data->irqs)
> - memcpy(new_bus->irq, mdio_bus_data->irqs, sizeof(new_bus->irq));
> + if (data->irqs)
> + memcpy(new_bus->irq, data->irqs, sizeof(new_bus->irq));
>
> #ifdef CONFIG_OF
> - if (priv->device->of_node)
> - mdio_bus_data->reset_gpio = -1;
> + if (priv->device->of_node) {
> + struct device_node *np = priv->device->of_node;
> +
> + data->reset_gpio = of_get_named_gpio(np, "snps,reset-gpio", 0);
> + if (gpio_is_valid(data->reset_gpio)) {
> + data->active_low = of_property_read_bool(np,
> + "snps,reset-active-low");
> + of_property_read_u32_array(np,
> + "snps,reset-delays-us", data->delays, 3);
> +
> + devm_gpio_request(priv->device, data->reset_gpio,
> + "mdio-reset");
> + }
> + } else {
> + data->reset_gpio = -1;
> + }
This seems like a good candidate to be a small helper
function. Quoting the coding style:
6) Functions
------------
Functions should be short and sweet, and do just one thing. They should
fit on one or two screenfuls of text (the ISO/ANSI screen size is 80x24,
as we all know), and do one thing and do that well.
stmmac_mdio_register() is not short and sweet, and this is making it
bigger.
Andrew
next prev parent reply other threads:[~2019-06-06 13:45 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-06 10:31 [PATCH v2 net-next] net: stmmac: move reset gpio parse & request to stmmac_mdio_register Jisheng Zhang
2019-06-06 10:31 ` Jisheng Zhang
2019-06-06 13:44 ` Andrew Lunn [this message]
2019-06-06 13:44 ` Andrew Lunn
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=20190606134452.GD19590@lunn.ch \
--to=andrew@lunn.ch \
--cc=Jisheng.Zhang@synaptics.com \
--cc=alexandre.torgue@st.com \
--cc=davem@davemloft.net \
--cc=joabreu@synopsys.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=peppe.cavallaro@st.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.