Release 4.18 drivers/net/phy/mdio-gpio.c
/*
* GPIO based MDIO bitbang driver.
* Supports OpenFirmware.
*
* Copyright (c) 2008 CSE Semaphore Belgium.
* by Laurent Pinchart <laurentp@cse-semaphore.com>
*
* Copyright (C) 2008, Paulius Zaleckas <paulius.zaleckas@teltonika.lt>
*
* Based on earlier work by
*
* Copyright (c) 2003 Intracom S.A.
* by Pantelis Antoniou <panto@intracom.gr>
*
* 2005 (c) MontaVista Software, Inc.
* Vitaly Bordug <vbordug@ru.mvista.com>
*
* This file is licensed under the terms of the GNU General Public License
* version 2. This program is licensed "as is" without any warranty of any
* kind, whether express or implied.
*/
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/interrupt.h>
#include <linux/platform_device.h>
#include <linux/mdio-bitbang.h>
#include <linux/mdio-gpio.h>
#include <linux/gpio/consumer.h>
#include <linux/of_mdio.h>
struct mdio_gpio_info {
struct mdiobb_ctrl ctrl;
struct gpio_desc *mdc, *mdio, *mdo;
};
static int mdio_gpio_get_data(struct device *dev,
struct mdio_gpio_info *bitbang)
{
bitbang->mdc = devm_gpiod_get_index(dev, NULL, MDIO_GPIO_MDC,
GPIOD_OUT_LOW);
if (IS_ERR(bitbang->mdc))
return PTR_ERR(bitbang->mdc);
bitbang->mdio = devm_gpiod_get_index(dev, NULL, MDIO_GPIO_MDIO,
GPIOD_IN);
if (IS_ERR(bitbang->mdio))
return PTR_ERR(bitbang->mdio);
bitbang->mdo = devm_gpiod_get_index_optional(dev, NULL, MDIO_GPIO_MDO,
GPIOD_OUT_LOW);
return PTR_ERR_OR_ZERO(bitbang->mdo);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Andrew Lunn | 63 | 61.17% | 3 | 50.00% |
Srinivas Kandagatla | 29 | 28.16% | 1 | 16.67% |
Guenter Roeck | 11 | 10.68% | 2 | 33.33% |
Total | 103 | 100.00% | 6 | 100.00% |
static void mdio_dir(struct mdiobb_ctrl *ctrl, int dir)
{
struct mdio_gpio_info *bitbang =
container_of(ctrl, struct mdio_gpio_info, ctrl);
if (bitbang->mdo) {
/* Separate output pin. Always set its value to high
* when changing direction. If direction is input,
* assume the pin serves as pull-up. If direction is
* output, the default value is high.
*/
gpiod_set_value(bitbang->mdo, 1);
return;
}
if (dir)
gpiod_direction_output(bitbang->mdio, 1);
else
gpiod_direction_input(bitbang->mdio);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Laurent Pinchart | 48 | 69.57% | 1 | 33.33% |
Guenter Roeck | 21 | 30.43% | 2 | 66.67% |
Total | 69 | 100.00% | 3 | 100.00% |
static int mdio_get(struct mdiobb_ctrl *ctrl)
{
struct mdio_gpio_info *bitbang =
container_of(ctrl, struct mdio_gpio_info, ctrl);
return gpiod_get_value(bitbang->mdio);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Laurent Pinchart | 32 | 94.12% | 1 | 33.33% |
Paulius Zaleckas | 1 | 2.94% | 1 | 33.33% |
Guenter Roeck | 1 | 2.94% | 1 | 33.33% |
Total | 34 | 100.00% | 3 | 100.00% |
static void mdio_set(struct mdiobb_ctrl *ctrl, int what)
{
struct mdio_gpio_info *bitbang =
container_of(ctrl, struct mdio_gpio_info, ctrl);
if (bitbang->mdo)
gpiod_set_value(bitbang->mdo, what);
else
gpiod_set_value(bitbang->mdio, what);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Laurent Pinchart | 36 | 66.67% | 1 | 25.00% |
Guenter Roeck | 17 | 31.48% | 2 | 50.00% |
Paulius Zaleckas | 1 | 1.85% | 1 | 25.00% |
Total | 54 | 100.00% | 4 | 100.00% |
static void mdc_set(struct mdiobb_ctrl *ctrl, int what)
{
struct mdio_gpio_info *bitbang =
container_of(ctrl, struct mdio_gpio_info, ctrl);
gpiod_set_value(bitbang->mdc, what);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Laurent Pinchart | 36 | 94.74% | 1 | 33.33% |
Guenter Roeck | 1 | 2.63% | 1 | 33.33% |
Paulius Zaleckas | 1 | 2.63% | 1 | 33.33% |
Total | 38 | 100.00% | 3 | 100.00% |
static const struct mdiobb_ops mdio_gpio_ops = {
.owner = THIS_MODULE,
.set_mdc = mdc_set,
.set_mdio_dir = mdio_dir,
.set_mdio_data = mdio_set,
.get_mdio_data = mdio_get,
};
static struct mii_bus *mdio_gpio_bus_init(struct device *dev,
struct mdio_gpio_info *bitbang,
int bus_id)
{
struct mii_bus *new_bus;
bitbang->ctrl.ops = &mdio_gpio_ops;
new_bus = alloc_mdio_bitbang(&bitbang->ctrl);
if (!new_bus)
return NULL;
new_bus->name = "GPIO Bitbanged MDIO";
new_bus->parent = dev;
if (bus_id != -1)
snprintf(new_bus->id, MII_BUS_ID_SIZE, "gpio-%x", bus_id);
else
strncpy(new_bus->id, "gpio", MII_BUS_ID_SIZE);
dev_set_drvdata(dev, new_bus);
return new_bus;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Laurent Pinchart | 43 | 40.19% | 1 | 12.50% |
Paulius Zaleckas | 32 | 29.91% | 1 | 12.50% |
Bert Vermeulen | 19 | 17.76% | 1 | 12.50% |
Andrew Lunn | 8 | 7.48% | 3 | 37.50% |
Mark Ware | 4 | 3.74% | 1 | 12.50% |
Florian Fainelli | 1 | 0.93% | 1 | 12.50% |
Total | 107 | 100.00% | 8 | 100.00% |
static void mdio_gpio_bus_deinit(struct device *dev)
{
struct mii_bus *bus = dev_get_drvdata(dev);
free_mdio_bitbang(bus);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Paulius Zaleckas | 22 | 84.62% | 1 | 50.00% |
Mark Ware | 4 | 15.38% | 1 | 50.00% |
Total | 26 | 100.00% | 2 | 100.00% |
static void mdio_gpio_bus_destroy(struct device *dev)
{
struct mii_bus *bus = dev_get_drvdata(dev);
mdiobus_unregister(bus);
mdio_gpio_bus_deinit(dev);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Mark Ware | 31 | 100.00% | 1 | 100.00% |
Total | 31 | 100.00% | 1 | 100.00% |
static int mdio_gpio_probe(struct platform_device *pdev)
{
struct mdio_gpio_info *bitbang;
struct mii_bus *new_bus;
int ret, bus_id;
bitbang = devm_kzalloc(&pdev->dev, sizeof(*bitbang), GFP_KERNEL);
if (!bitbang)
return -ENOMEM;
ret = mdio_gpio_get_data(&pdev->dev, bitbang);
if (ret)
return ret;
if (pdev->dev.of_node) {
bus_id = of_alias_get_id(pdev->dev.of_node, "mdio-gpio");
if (bus_id < 0) {
dev_warn(&pdev->dev, "failed to get alias id\n");
bus_id = 0;
}
} else {
bus_id = pdev->id;
}
new_bus = mdio_gpio_bus_init(&pdev->dev, bitbang, bus_id);
if (!new_bus)
return -ENODEV;
ret = of_mdiobus_register(new_bus, pdev->dev.of_node);
if (ret)
mdio_gpio_bus_deinit(&pdev->dev);
return ret;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Andrew Lunn | 53 | 29.94% | 2 | 20.00% |
Srinivas Kandagatla | 38 | 21.47% | 2 | 20.00% |
Mark Ware | 28 | 15.82% | 1 | 10.00% |
Paulius Zaleckas | 25 | 14.12% | 1 | 10.00% |
Johan Hovold | 22 | 12.43% | 1 | 10.00% |
Laurent Pinchart | 7 | 3.95% | 1 | 10.00% |
Grant C. Likely | 3 | 1.69% | 1 | 10.00% |
Roel Kluin | 1 | 0.56% | 1 | 10.00% |
Total | 177 | 100.00% | 10 | 100.00% |
static int mdio_gpio_remove(struct platform_device *pdev)
{
mdio_gpio_bus_destroy(&pdev->dev);
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Laurent Pinchart | 17 | 77.27% | 1 | 25.00% |
Srinivas Kandagatla | 3 | 13.64% | 1 | 25.00% |
Paulius Zaleckas | 1 | 4.55% | 1 | 25.00% |
Grant C. Likely | 1 | 4.55% | 1 | 25.00% |
Total | 22 | 100.00% | 4 | 100.00% |
static const struct of_device_id mdio_gpio_of_match[] = {
{ .compatible = "virtual,mdio-gpio", },
{ /* sentinel */ }
};
MODULE_DEVICE_TABLE(of, mdio_gpio_of_match);
static struct platform_driver mdio_gpio_driver = {
.probe = mdio_gpio_probe,
.remove = mdio_gpio_remove,
.driver = {
.name = "mdio-gpio",
.of_match_table = mdio_gpio_of_match,
},
};
module_platform_driver(mdio_gpio_driver);
MODULE_ALIAS("platform:mdio-gpio");
MODULE_AUTHOR("Laurent Pinchart, Paulius Zaleckas");
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("Generic driver for MDIO bus emulation using GPIO");
Overall Contributors
Person | Tokens | Prop | Commits | CommitProp |
Laurent Pinchart | 292 | 35.48% | 1 | 4.17% |
Paulius Zaleckas | 141 | 17.13% | 1 | 4.17% |
Andrew Lunn | 131 | 15.92% | 6 | 25.00% |
Srinivas Kandagatla | 76 | 9.23% | 2 | 8.33% |
Mark Ware | 68 | 8.26% | 1 | 4.17% |
Guenter Roeck | 58 | 7.05% | 3 | 12.50% |
Johan Hovold | 22 | 2.67% | 1 | 4.17% |
Bert Vermeulen | 19 | 2.31% | 1 | 4.17% |
Luis de Bethencourt | 7 | 0.85% | 1 | 4.17% |
Grant C. Likely | 4 | 0.49% | 2 | 8.33% |
Roel Kluin | 1 | 0.12% | 1 | 4.17% |
Florian Fainelli | 1 | 0.12% | 1 | 4.17% |
Sachin Kamat | 1 | 0.12% | 1 | 4.17% |
Fabian Frederick | 1 | 0.12% | 1 | 4.17% |
Bhumika Goyal | 1 | 0.12% | 1 | 4.17% |
Total | 823 | 100.00% | 24 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.