Release 4.7 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/gpio.h>
#include <linux/platform_data/mdio-gpio.h>
#include <linux/of_gpio.h>
#include <linux/of_mdio.h>
struct mdio_gpio_info {
struct mdiobb_ctrl ctrl;
int mdc, mdio, mdo;
int mdc_active_low, mdio_active_low, mdo_active_low;
};
static void *mdio_gpio_of_get_data(struct platform_device *pdev)
{
struct device_node *np = pdev->dev.of_node;
struct mdio_gpio_platform_data *pdata;
enum of_gpio_flags flags;
int ret;
pdata = devm_kzalloc(&pdev->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;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
srinivas kandagatla | srinivas kandagatla | 106 | 63.10% | 1 | 33.33% |
guenter roeck | guenter roeck | 62 | 36.90% | 2 | 66.67% |
| Total | 168 | 100.00% | 3 | 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.
*/
gpio_set_value_cansleep(bitbang->mdo,
1 ^ bitbang->mdo_active_low);
return;
}
if (dir)
gpio_direction_output(bitbang->mdio,
1 ^ bitbang->mdio_active_low);
else
gpio_direction_input(bitbang->mdio);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
laurent pinchart | laurent pinchart | 50 | 64.94% | 1 | 25.00% |
guenter roeck | guenter roeck | 26 | 33.77% | 2 | 50.00% |
vivien didelot | vivien didelot | 1 | 1.30% | 1 | 25.00% |
| Total | 77 | 100.00% | 4 | 100.00% |
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;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
laurent pinchart | laurent pinchart | 32 | 84.21% | 1 | 25.00% |
guenter roeck | guenter roeck | 4 | 10.53% | 1 | 25.00% |
vivien didelot | vivien didelot | 1 | 2.63% | 1 | 25.00% |
paulius zaleckas | paulius zaleckas | 1 | 2.63% | 1 | 25.00% |
| Total | 38 | 100.00% | 4 | 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)
gpio_set_value_cansleep(bitbang->mdo,
what ^ bitbang->mdo_active_low);
else
gpio_set_value_cansleep(bitbang->mdio,
what ^ bitbang->mdio_active_low);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
laurent pinchart | laurent pinchart | 36 | 58.06% | 1 | 20.00% |
guenter roeck | guenter roeck | 23 | 37.10% | 2 | 40.00% |
vivien didelot | vivien didelot | 2 | 3.23% | 1 | 20.00% |
paulius zaleckas | paulius zaleckas | 1 | 1.61% | 1 | 20.00% |
| Total | 62 | 100.00% | 5 | 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);
gpio_set_value_cansleep(bitbang->mdc, what ^ bitbang->mdc_active_low);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
laurent pinchart | laurent pinchart | 36 | 85.71% | 1 | 25.00% |
guenter roeck | guenter roeck | 4 | 9.52% | 1 | 25.00% |
vivien didelot | vivien didelot | 1 | 2.38% | 1 | 25.00% |
paulius zaleckas | paulius zaleckas | 1 | 2.38% | 1 | 25.00% |
| Total | 42 | 100.00% | 4 | 100.00% |
static 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_platform_data *pdata,
int bus_id)
{
struct mii_bus *new_bus;
struct mdio_gpio_info *bitbang;
int i;
bitbang = devm_kzalloc(dev, sizeof(*bitbang), GFP_KERNEL);
if (!bitbang)
goto out;
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;
new_bus = alloc_mdio_bitbang(&bitbang->ctrl);
if (!new_bus)
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)
goto out_free_bus;
for (i = 0; i < PHY_MAX_ADDR; i++)
if (!new_bus->irq[i])
new_bus->irq[i] = PHY_POLL;
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);
if (devm_gpio_request(dev, bitbang->mdc, "mdc"))
goto out_free_bus;
if (devm_gpio_request(dev, bitbang->mdio, "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);
dev_set_drvdata(dev, new_bus);
return new_bus;
out_free_bus:
free_mdio_bitbang(new_bus);
out:
return NULL;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
paulius zaleckas | paulius zaleckas | 122 | 33.24% | 2 | 16.67% |
laurent pinchart | laurent pinchart | 108 | 29.43% | 1 | 8.33% |
guenter roeck | guenter roeck | 83 | 22.62% | 3 | 25.00% |
bert vermeulen | bert vermeulen | 27 | 7.36% | 2 | 16.67% |
andrew lunn | andrew lunn | 11 | 3.00% | 1 | 8.33% |
srinivas kandagatla | srinivas kandagatla | 10 | 2.72% | 1 | 8.33% |
mark ware | mark ware | 5 | 1.36% | 1 | 8.33% |
florian fainelli | florian fainelli | 1 | 0.27% | 1 | 8.33% |
| Total | 367 | 100.00% | 12 | 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 | paulius zaleckas | 22 | 84.62% | 1 | 50.00% |
mark ware | 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 | 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_platform_data *pdata;
struct mii_bus *new_bus;
int ret, bus_id;
if (pdev->dev.of_node) {
pdata = mdio_gpio_of_get_data(pdev);
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 {
pdata = dev_get_platdata(&pdev->dev);
bus_id = pdev->id;
}
if (!pdata)
return -ENODEV;
new_bus = mdio_gpio_bus_init(&pdev->dev, pdata, bus_id);
if (!new_bus)
return -ENODEV;
if (pdev->dev.of_node)
ret = of_mdiobus_register(new_bus, pdev->dev.of_node);
else
ret = mdiobus_register(new_bus);
if (ret)
mdio_gpio_bus_deinit(&pdev->dev);
return ret;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
srinivas kandagatla | srinivas kandagatla | 55 | 31.79% | 2 | 22.22% |
paulius zaleckas | paulius zaleckas | 41 | 23.70% | 1 | 11.11% |
mark ware | mark ware | 34 | 19.65% | 1 | 11.11% |
johan hovold | johan hovold | 22 | 12.72% | 1 | 11.11% |
laurent pinchart | laurent pinchart | 10 | 5.78% | 1 | 11.11% |
grant likely | grant likely | 5 | 2.89% | 1 | 11.11% |
jingoo han | jingoo han | 4 | 2.31% | 1 | 11.11% |
roel kluin | roel kluin | 2 | 1.16% | 1 | 11.11% |
| Total | 173 | 100.00% | 9 | 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 | laurent pinchart | 17 | 77.27% | 1 | 25.00% |
srinivas kandagatla | srinivas kandagatla | 3 | 13.64% | 1 | 25.00% |
grant likely | grant likely | 1 | 4.55% | 1 | 25.00% |
paulius zaleckas | paulius zaleckas | 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 | laurent pinchart | 365 | 31.20% | 1 | 4.17% |
paulius zaleckas | paulius zaleckas | 251 | 21.45% | 2 | 8.33% |
guenter roeck | guenter roeck | 211 | 18.03% | 3 | 12.50% |
srinivas kandagatla | srinivas kandagatla | 180 | 15.38% | 3 | 12.50% |
mark ware | mark ware | 75 | 6.41% | 1 | 4.17% |
bert vermeulen | bert vermeulen | 27 | 2.31% | 2 | 8.33% |
johan hovold | johan hovold | 22 | 1.88% | 1 | 4.17% |
andrew lunn | andrew lunn | 11 | 0.94% | 1 | 4.17% |
luis de bethencourt | luis de bethencourt | 7 | 0.60% | 1 | 4.17% |
vivien didelot | vivien didelot | 6 | 0.51% | 2 | 8.33% |
grant likely | grant likely | 6 | 0.51% | 2 | 8.33% |
jingoo han | jingoo han | 4 | 0.34% | 1 | 4.17% |
roel kluin | roel kluin | 2 | 0.17% | 1 | 4.17% |
fabian frederick | fabian frederick | 1 | 0.09% | 1 | 4.17% |
sachin kamat | sachin kamat | 1 | 0.09% | 1 | 4.17% |
florian fainelli | florian fainelli | 1 | 0.09% | 1 | 4.17% |
| Total | 1170 | 100.00% | 24 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.