Skip to content

Commit 32e4377

Browse files
committed
Merge branch 'Modernize-mdio-gpio'
Andrew Lunn says: ==================== Modernize mdio-gpio This patchset is inspired by a previous version by Linus Walleij It reworks the mdio-gpio code to make use of gpio descriptors instead of gpio numbers. However compared to the previous version, it retains support for platform devices. It does however remove the platform_data header file. The needed GPIOs are now passed by making use of a gpiod lookup table. e.g: static struct gpiod_lookup_table zii_scu_mdio_gpiod_table = { .dev_id = "mdio-gpio.0", .table = { GPIO_LOOKUP_IDX("gpio_ich", 17, NULL, MDIO_GPIO_MDC, GPIO_ACTIVE_HIGH), GPIO_LOOKUP_IDX("gpio_ich", 2, NULL, MDIO_GPIO_MDIO, GPIO_ACTIVE_HIGH), GPIO_LOOKUP_IDX("gpio_ich", 21, NULL, MDIO_GPIO_MDO, GPIO_ACTIVE_LOW), }, }; ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents 3f4fe75 + 0207dd1 commit 32e4377

File tree

6 files changed

+40
-136
lines changed

6 files changed

+40
-136
lines changed

MAINTAINERS

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5321,7 +5321,6 @@ F: include/linux/*mdio*.h
53215321
F: include/linux/of_net.h
53225322
F: include/linux/phy.h
53235323
F: include/linux/phy_fixed.h
5324-
F: include/linux/platform_data/mdio-gpio.h
53255324
F: include/linux/platform_data/mdio-bcm-unimac.h
53265325
F: include/trace/events/mdio.h
53275326
F: include/uapi/linux/mdio.h

drivers/net/phy/mdio-bitbang.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -205,14 +205,6 @@ static int mdiobb_write(struct mii_bus *bus, int phy, int reg, u16 val)
205205
return 0;
206206
}
207207

208-
static int mdiobb_reset(struct mii_bus *bus)
209-
{
210-
struct mdiobb_ctrl *ctrl = bus->priv;
211-
if (ctrl->reset)
212-
ctrl->reset(bus);
213-
return 0;
214-
}
215-
216208
struct mii_bus *alloc_mdio_bitbang(struct mdiobb_ctrl *ctrl)
217209
{
218210
struct mii_bus *bus;
@@ -225,7 +217,6 @@ struct mii_bus *alloc_mdio_bitbang(struct mdiobb_ctrl *ctrl)
225217

226218
bus->read = mdiobb_read;
227219
bus->write = mdiobb_write;
228-
bus->reset = mdiobb_reset;
229220
bus->priv = ctrl;
230221

231222
return bus;

drivers/net/phy/mdio-gpio.c

Lines changed: 31 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@
2424
#include <linux/slab.h>
2525
#include <linux/interrupt.h>
2626
#include <linux/platform_device.h>
27+
#include <linux/mdio-bitbang.h>
28+
#include <linux/mdio-gpio.h>
2729
#include <linux/gpio.h>
28-
#include <linux/platform_data/mdio-gpio.h>
30+
#include <linux/gpio/consumer.h>
2931

3032
#include <linux/of_gpio.h>
3133
#include <linux/of_mdio.h>
@@ -35,37 +37,22 @@ struct mdio_gpio_info {
3537
struct gpio_desc *mdc, *mdio, *mdo;
3638
};
3739

38-
static void *mdio_gpio_of_get_data(struct platform_device *pdev)
40+
static int mdio_gpio_get_data(struct device *dev,
41+
struct mdio_gpio_info *bitbang)
3942
{
40-
struct device_node *np = pdev->dev.of_node;
41-
struct mdio_gpio_platform_data *pdata;
42-
enum of_gpio_flags flags;
43-
int ret;
44-
45-
pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
46-
if (!pdata)
47-
return NULL;
48-
49-
ret = of_get_gpio_flags(np, 0, &flags);
50-
if (ret < 0)
51-
return NULL;
52-
53-
pdata->mdc = ret;
54-
pdata->mdc_active_low = flags & OF_GPIO_ACTIVE_LOW;
55-
56-
ret = of_get_gpio_flags(np, 1, &flags);
57-
if (ret < 0)
58-
return NULL;
59-
pdata->mdio = ret;
60-
pdata->mdio_active_low = flags & OF_GPIO_ACTIVE_LOW;
61-
62-
ret = of_get_gpio_flags(np, 2, &flags);
63-
if (ret > 0) {
64-
pdata->mdo = ret;
65-
pdata->mdo_active_low = flags & OF_GPIO_ACTIVE_LOW;
66-
}
67-
68-
return pdata;
43+
bitbang->mdc = devm_gpiod_get_index(dev, NULL, MDIO_GPIO_MDC,
44+
GPIOD_OUT_LOW);
45+
if (IS_ERR(bitbang->mdc))
46+
return PTR_ERR(bitbang->mdc);
47+
48+
bitbang->mdio = devm_gpiod_get_index(dev, NULL, MDIO_GPIO_MDIO,
49+
GPIOD_IN);
50+
if (IS_ERR(bitbang->mdio))
51+
return PTR_ERR(bitbang->mdio);
52+
53+
bitbang->mdo = devm_gpiod_get_index_optional(dev, NULL, MDIO_GPIO_MDO,
54+
GPIOD_OUT_LOW);
55+
return PTR_ERR_OR_ZERO(bitbang->mdo);
6956
}
7057

7158
static void mdio_dir(struct mdiobb_ctrl *ctrl, int dir)
@@ -125,78 +112,28 @@ static const struct mdiobb_ops mdio_gpio_ops = {
125112
};
126113

127114
static struct mii_bus *mdio_gpio_bus_init(struct device *dev,
128-
struct mdio_gpio_platform_data *pdata,
115+
struct mdio_gpio_info *bitbang,
129116
int bus_id)
130117
{
131118
struct mii_bus *new_bus;
132-
struct mdio_gpio_info *bitbang;
133-
int i;
134-
int mdc, mdio, mdo;
135-
unsigned long mdc_flags = GPIOF_OUT_INIT_LOW;
136-
unsigned long mdio_flags = GPIOF_DIR_IN;
137-
unsigned long mdo_flags = GPIOF_OUT_INIT_HIGH;
138-
139-
bitbang = devm_kzalloc(dev, sizeof(*bitbang), GFP_KERNEL);
140-
if (!bitbang)
141-
goto out;
142119

143120
bitbang->ctrl.ops = &mdio_gpio_ops;
144-
bitbang->ctrl.reset = pdata->reset;
145-
mdc = pdata->mdc;
146-
bitbang->mdc = gpio_to_desc(mdc);
147-
if (pdata->mdc_active_low)
148-
mdc_flags = GPIOF_OUT_INIT_HIGH | GPIOF_ACTIVE_LOW;
149-
mdio = pdata->mdio;
150-
bitbang->mdio = gpio_to_desc(mdio);
151-
if (pdata->mdio_active_low)
152-
mdio_flags |= GPIOF_ACTIVE_LOW;
153-
mdo = pdata->mdo;
154-
if (mdo) {
155-
bitbang->mdo = gpio_to_desc(mdo);
156-
if (pdata->mdo_active_low)
157-
mdo_flags = GPIOF_OUT_INIT_LOW | GPIOF_ACTIVE_LOW;
158-
}
159121

160122
new_bus = alloc_mdio_bitbang(&bitbang->ctrl);
161123
if (!new_bus)
162-
goto out;
163-
164-
new_bus->name = "GPIO Bitbanged MDIO",
124+
return NULL;
165125

166-
new_bus->phy_mask = pdata->phy_mask;
167-
new_bus->phy_ignore_ta_mask = pdata->phy_ignore_ta_mask;
168-
memcpy(new_bus->irq, pdata->irqs, sizeof(new_bus->irq));
126+
new_bus->name = "GPIO Bitbanged MDIO";
169127
new_bus->parent = dev;
170128

171-
if (new_bus->phy_mask == ~0)
172-
goto out_free_bus;
173-
174-
for (i = 0; i < PHY_MAX_ADDR; i++)
175-
if (!new_bus->irq[i])
176-
new_bus->irq[i] = PHY_POLL;
177-
178129
if (bus_id != -1)
179130
snprintf(new_bus->id, MII_BUS_ID_SIZE, "gpio-%x", bus_id);
180131
else
181132
strncpy(new_bus->id, "gpio", MII_BUS_ID_SIZE);
182133

183-
if (devm_gpio_request_one(dev, mdc, mdc_flags, "mdc"))
184-
goto out_free_bus;
185-
186-
if (devm_gpio_request_one(dev, mdio, mdio_flags, "mdio"))
187-
goto out_free_bus;
188-
189-
if (mdo && devm_gpio_request_one(dev, mdo, mdo_flags, "mdo"))
190-
goto out_free_bus;
191-
192134
dev_set_drvdata(dev, new_bus);
193135

194136
return new_bus;
195-
196-
out_free_bus:
197-
free_mdio_bitbang(new_bus);
198-
out:
199-
return NULL;
200137
}
201138

202139
static void mdio_gpio_bus_deinit(struct device *dev)
@@ -216,26 +153,29 @@ static void mdio_gpio_bus_destroy(struct device *dev)
216153

217154
static int mdio_gpio_probe(struct platform_device *pdev)
218155
{
219-
struct mdio_gpio_platform_data *pdata;
156+
struct mdio_gpio_info *bitbang;
220157
struct mii_bus *new_bus;
221158
int ret, bus_id;
222159

160+
bitbang = devm_kzalloc(&pdev->dev, sizeof(*bitbang), GFP_KERNEL);
161+
if (!bitbang)
162+
return -ENOMEM;
163+
164+
ret = mdio_gpio_get_data(&pdev->dev, bitbang);
165+
if (ret)
166+
return ret;
167+
223168
if (pdev->dev.of_node) {
224-
pdata = mdio_gpio_of_get_data(pdev);
225169
bus_id = of_alias_get_id(pdev->dev.of_node, "mdio-gpio");
226170
if (bus_id < 0) {
227171
dev_warn(&pdev->dev, "failed to get alias id\n");
228172
bus_id = 0;
229173
}
230174
} else {
231-
pdata = dev_get_platdata(&pdev->dev);
232175
bus_id = pdev->id;
233176
}
234177

235-
if (!pdata)
236-
return -ENODEV;
237-
238-
new_bus = mdio_gpio_bus_init(&pdev->dev, pdata, bus_id);
178+
new_bus = mdio_gpio_bus_init(&pdev->dev, bitbang, bus_id);
239179
if (!new_bus)
240180
return -ENODEV;
241181

include/linux/mdio-bitbang.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ struct mdiobb_ops {
3333

3434
struct mdiobb_ctrl {
3535
const struct mdiobb_ops *ops;
36-
/* reset callback */
37-
int (*reset)(struct mii_bus *bus);
3836
};
3937

4038
/* The returned bus is not yet registered with the phy layer. */

include/linux/mdio-gpio.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
#ifndef __LINUX_MDIO_GPIO_H
3+
#define __LINUX_MDIO_GPIO_H
4+
5+
#define MDIO_GPIO_MDC 0
6+
#define MDIO_GPIO_MDIO 1
7+
#define MDIO_GPIO_MDO 2
8+
9+
#endif

include/linux/platform_data/mdio-gpio.h

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)