提交 72d13c15 编写于 作者: D David S. Miller

Merge branch 'mdio-gpio-next'

Florian Fainelli says:

====================
net: mdio-gpio: Use modern GPIO helpers

This patch series modernizes the mdio-gpio and makes it switch to the
latest and greatest API for manipulating GPIO lines, thus allowing
some simplifications in the driver.
====================
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
......@@ -32,8 +32,7 @@
struct mdio_gpio_info {
struct mdiobb_ctrl ctrl;
int mdc, mdio, mdo;
int mdc_active_low, mdio_active_low, mdo_active_low;
struct gpio_desc *mdc, *mdio, *mdo;
};
static void *mdio_gpio_of_get_data(struct platform_device *pdev)
......@@ -80,16 +79,14 @@ static void mdio_dir(struct mdiobb_ctrl *ctrl, int dir)
* assume the pin serves as pull-up. If direction is
* output, the default value is high.
*/
gpio_set_value_cansleep(bitbang->mdo,
1 ^ bitbang->mdo_active_low);
gpiod_set_value(bitbang->mdo, 1);
return;
}
if (dir)
gpio_direction_output(bitbang->mdio,
1 ^ bitbang->mdio_active_low);
gpiod_direction_output(bitbang->mdio, 1);
else
gpio_direction_input(bitbang->mdio);
gpiod_direction_input(bitbang->mdio);
}
static int mdio_get(struct mdiobb_ctrl *ctrl)
......@@ -97,8 +94,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_cansleep(bitbang->mdio) ^
bitbang->mdio_active_low;
return gpiod_get_value(bitbang->mdio);
}
static void mdio_set(struct mdiobb_ctrl *ctrl, int what)
......@@ -107,11 +103,9 @@ static void mdio_set(struct mdiobb_ctrl *ctrl, int what)
container_of(ctrl, struct mdio_gpio_info, ctrl);
if (bitbang->mdo)
gpio_set_value_cansleep(bitbang->mdo,
what ^ bitbang->mdo_active_low);
gpiod_set_value(bitbang->mdo, what);
else
gpio_set_value_cansleep(bitbang->mdio,
what ^ bitbang->mdio_active_low);
gpiod_set_value(bitbang->mdio, what);
}
static void mdc_set(struct mdiobb_ctrl *ctrl, int what)
......@@ -119,7 +113,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_cansleep(bitbang->mdc, what ^ bitbang->mdc_active_low);
gpiod_set_value(bitbang->mdc, what);
}
static struct mdiobb_ops mdio_gpio_ops = {
......@@ -137,6 +131,10 @@ static struct mii_bus *mdio_gpio_bus_init(struct device *dev,
struct mii_bus *new_bus;
struct mdio_gpio_info *bitbang;
int i;
int mdc, mdio, mdo;
unsigned long mdc_flags = GPIOF_OUT_INIT_LOW;
unsigned long mdio_flags = GPIOF_DIR_IN;
unsigned long mdo_flags = GPIOF_OUT_INIT_HIGH;
bitbang = devm_kzalloc(dev, sizeof(*bitbang), GFP_KERNEL);
if (!bitbang)
......@@ -144,12 +142,20 @@ 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;
bitbang->mdo = pdata->mdo;
bitbang->mdo_active_low = pdata->mdo_active_low;
mdc = pdata->mdc;
bitbang->mdc = gpio_to_desc(mdc);
if (pdata->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)
mdio_flags |= GPIOF_ACTIVE_LOW;
mdo = pdata->mdo;
if (mdo) {
bitbang->mdo = gpio_to_desc(mdo);
if (pdata->mdo_active_low)
mdo_flags = GPIOF_OUT_INIT_LOW | GPIOF_ACTIVE_LOW;
}
new_bus = alloc_mdio_bitbang(&bitbang->ctrl);
if (!new_bus)
......@@ -174,20 +180,14 @@ static struct mii_bus *mdio_gpio_bus_init(struct device *dev,
else
strncpy(new_bus->id, "gpio", MII_BUS_ID_SIZE);
if (devm_gpio_request(dev, bitbang->mdc, "mdc"))
if (devm_gpio_request_one(dev, mdc, mdc_flags, "mdc"))
goto out_free_bus;
if (devm_gpio_request(dev, bitbang->mdio, "mdio"))
if (devm_gpio_request_one(dev, mdio, mdio_flags, "mdio"))
goto out_free_bus;
if (bitbang->mdo) {
if (devm_gpio_request(dev, bitbang->mdo, "mdo"))
goto out_free_bus;
gpio_direction_output(bitbang->mdo, 1);
gpio_direction_input(bitbang->mdio);
}
gpio_direction_output(bitbang->mdc, 0);
if (mdo && devm_gpio_request_one(dev, mdo, mdo_flags, "mdo"))
goto out_free_bus;
dev_set_drvdata(dev, new_bus);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册