Laurent Pinchart | a5edecc | 2008-05-26 11:53:21 +0200 | [diff] [blame] | 1 | /* |
Paulius Zaleckas | f004f3e | 2008-11-14 00:24:34 +0000 | [diff] [blame] | 2 | * GPIO based MDIO bitbang driver. |
| 3 | * Supports OpenFirmware. |
Laurent Pinchart | a5edecc | 2008-05-26 11:53:21 +0200 | [diff] [blame] | 4 | * |
| 5 | * Copyright (c) 2008 CSE Semaphore Belgium. |
| 6 | * by Laurent Pinchart <laurentp@cse-semaphore.com> |
| 7 | * |
Paulius Zaleckas | f004f3e | 2008-11-14 00:24:34 +0000 | [diff] [blame] | 8 | * Copyright (C) 2008, Paulius Zaleckas <paulius.zaleckas@teltonika.lt> |
| 9 | * |
Laurent Pinchart | a5edecc | 2008-05-26 11:53:21 +0200 | [diff] [blame] | 10 | * Based on earlier work by |
| 11 | * |
| 12 | * Copyright (c) 2003 Intracom S.A. |
| 13 | * by Pantelis Antoniou <panto@intracom.gr> |
| 14 | * |
| 15 | * 2005 (c) MontaVista Software, Inc. |
| 16 | * Vitaly Bordug <vbordug@ru.mvista.com> |
| 17 | * |
| 18 | * This file is licensed under the terms of the GNU General Public License |
| 19 | * version 2. This program is licensed "as is" without any warranty of any |
| 20 | * kind, whether express or implied. |
| 21 | */ |
| 22 | |
| 23 | #include <linux/module.h> |
| 24 | #include <linux/slab.h> |
Laurent Pinchart | a5edecc | 2008-05-26 11:53:21 +0200 | [diff] [blame] | 25 | #include <linux/interrupt.h> |
Paulius Zaleckas | f004f3e | 2008-11-14 00:24:34 +0000 | [diff] [blame] | 26 | #include <linux/platform_device.h> |
| 27 | #include <linux/gpio.h> |
Vivien Didelot | e2aacd9 | 2015-10-20 10:08:59 -0400 | [diff] [blame] | 28 | #include <linux/platform_data/mdio-gpio.h> |
Paulius Zaleckas | f004f3e | 2008-11-14 00:24:34 +0000 | [diff] [blame] | 29 | |
Laurent Pinchart | a5edecc | 2008-05-26 11:53:21 +0200 | [diff] [blame] | 30 | #include <linux/of_gpio.h> |
Mark Ware | dacac4d | 2009-07-23 10:56:48 -0700 | [diff] [blame] | 31 | #include <linux/of_mdio.h> |
Laurent Pinchart | a5edecc | 2008-05-26 11:53:21 +0200 | [diff] [blame] | 32 | |
| 33 | struct mdio_gpio_info { |
| 34 | struct mdiobb_ctrl ctrl; |
Guenter Roeck | 7e5fbd1 | 2017-01-11 12:59:50 -0800 | [diff] [blame] | 35 | struct gpio_desc *mdc, *mdio, *mdo; |
Laurent Pinchart | a5edecc | 2008-05-26 11:53:21 +0200 | [diff] [blame] | 36 | }; |
| 37 | |
Srinivas Kandagatla | e92bdf4b | 2012-08-24 01:59:17 +0000 | [diff] [blame] | 38 | static void *mdio_gpio_of_get_data(struct platform_device *pdev) |
| 39 | { |
| 40 | struct device_node *np = pdev->dev.of_node; |
| 41 | struct mdio_gpio_platform_data *pdata; |
Guenter Roeck | 1d25148 | 2014-04-15 19:16:41 -0700 | [diff] [blame] | 42 | enum of_gpio_flags flags; |
Srinivas Kandagatla | e92bdf4b | 2012-08-24 01:59:17 +0000 | [diff] [blame] | 43 | int ret; |
| 44 | |
| 45 | pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); |
| 46 | if (!pdata) |
| 47 | return NULL; |
| 48 | |
Guenter Roeck | 1d25148 | 2014-04-15 19:16:41 -0700 | [diff] [blame] | 49 | ret = of_get_gpio_flags(np, 0, &flags); |
Srinivas Kandagatla | e92bdf4b | 2012-08-24 01:59:17 +0000 | [diff] [blame] | 50 | if (ret < 0) |
| 51 | return NULL; |
| 52 | |
| 53 | pdata->mdc = ret; |
Guenter Roeck | 1d25148 | 2014-04-15 19:16:41 -0700 | [diff] [blame] | 54 | pdata->mdc_active_low = flags & OF_GPIO_ACTIVE_LOW; |
Srinivas Kandagatla | e92bdf4b | 2012-08-24 01:59:17 +0000 | [diff] [blame] | 55 | |
Guenter Roeck | 1d25148 | 2014-04-15 19:16:41 -0700 | [diff] [blame] | 56 | ret = of_get_gpio_flags(np, 1, &flags); |
Srinivas Kandagatla | e92bdf4b | 2012-08-24 01:59:17 +0000 | [diff] [blame] | 57 | if (ret < 0) |
| 58 | return NULL; |
| 59 | pdata->mdio = ret; |
Guenter Roeck | 1d25148 | 2014-04-15 19:16:41 -0700 | [diff] [blame] | 60 | pdata->mdio_active_low = flags & OF_GPIO_ACTIVE_LOW; |
Srinivas Kandagatla | e92bdf4b | 2012-08-24 01:59:17 +0000 | [diff] [blame] | 61 | |
Guenter Roeck | f1d54c4 | 2014-04-15 19:16:42 -0700 | [diff] [blame] | 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 | |
Srinivas Kandagatla | e92bdf4b | 2012-08-24 01:59:17 +0000 | [diff] [blame] | 68 | return pdata; |
| 69 | } |
| 70 | |
Laurent Pinchart | a5edecc | 2008-05-26 11:53:21 +0200 | [diff] [blame] | 71 | static void mdio_dir(struct mdiobb_ctrl *ctrl, int dir) |
| 72 | { |
| 73 | struct mdio_gpio_info *bitbang = |
| 74 | container_of(ctrl, struct mdio_gpio_info, ctrl); |
| 75 | |
Guenter Roeck | f1d54c4 | 2014-04-15 19:16:42 -0700 | [diff] [blame] | 76 | if (bitbang->mdo) { |
| 77 | /* Separate output pin. Always set its value to high |
| 78 | * when changing direction. If direction is input, |
| 79 | * assume the pin serves as pull-up. If direction is |
| 80 | * output, the default value is high. |
| 81 | */ |
Guenter Roeck | 52aab18 | 2017-01-11 12:59:51 -0800 | [diff] [blame] | 82 | gpiod_set_value(bitbang->mdo, 1); |
Guenter Roeck | f1d54c4 | 2014-04-15 19:16:42 -0700 | [diff] [blame] | 83 | return; |
| 84 | } |
| 85 | |
Laurent Pinchart | a5edecc | 2008-05-26 11:53:21 +0200 | [diff] [blame] | 86 | if (dir) |
Guenter Roeck | 52aab18 | 2017-01-11 12:59:51 -0800 | [diff] [blame] | 87 | gpiod_direction_output(bitbang->mdio, 1); |
Laurent Pinchart | a5edecc | 2008-05-26 11:53:21 +0200 | [diff] [blame] | 88 | else |
Guenter Roeck | 7e5fbd1 | 2017-01-11 12:59:50 -0800 | [diff] [blame] | 89 | gpiod_direction_input(bitbang->mdio); |
Laurent Pinchart | a5edecc | 2008-05-26 11:53:21 +0200 | [diff] [blame] | 90 | } |
| 91 | |
Paulius Zaleckas | f004f3e | 2008-11-14 00:24:34 +0000 | [diff] [blame] | 92 | static int mdio_get(struct mdiobb_ctrl *ctrl) |
Laurent Pinchart | a5edecc | 2008-05-26 11:53:21 +0200 | [diff] [blame] | 93 | { |
| 94 | struct mdio_gpio_info *bitbang = |
| 95 | container_of(ctrl, struct mdio_gpio_info, ctrl); |
| 96 | |
Guenter Roeck | 52aab18 | 2017-01-11 12:59:51 -0800 | [diff] [blame] | 97 | return gpiod_get_value(bitbang->mdio); |
Laurent Pinchart | a5edecc | 2008-05-26 11:53:21 +0200 | [diff] [blame] | 98 | } |
| 99 | |
Paulius Zaleckas | f004f3e | 2008-11-14 00:24:34 +0000 | [diff] [blame] | 100 | static void mdio_set(struct mdiobb_ctrl *ctrl, int what) |
Laurent Pinchart | a5edecc | 2008-05-26 11:53:21 +0200 | [diff] [blame] | 101 | { |
| 102 | struct mdio_gpio_info *bitbang = |
| 103 | container_of(ctrl, struct mdio_gpio_info, ctrl); |
| 104 | |
Guenter Roeck | f1d54c4 | 2014-04-15 19:16:42 -0700 | [diff] [blame] | 105 | if (bitbang->mdo) |
Guenter Roeck | 52aab18 | 2017-01-11 12:59:51 -0800 | [diff] [blame] | 106 | gpiod_set_value(bitbang->mdo, what); |
Guenter Roeck | f1d54c4 | 2014-04-15 19:16:42 -0700 | [diff] [blame] | 107 | else |
Guenter Roeck | 52aab18 | 2017-01-11 12:59:51 -0800 | [diff] [blame] | 108 | gpiod_set_value(bitbang->mdio, what); |
Laurent Pinchart | a5edecc | 2008-05-26 11:53:21 +0200 | [diff] [blame] | 109 | } |
| 110 | |
Paulius Zaleckas | f004f3e | 2008-11-14 00:24:34 +0000 | [diff] [blame] | 111 | static void mdc_set(struct mdiobb_ctrl *ctrl, int what) |
Laurent Pinchart | a5edecc | 2008-05-26 11:53:21 +0200 | [diff] [blame] | 112 | { |
| 113 | struct mdio_gpio_info *bitbang = |
| 114 | container_of(ctrl, struct mdio_gpio_info, ctrl); |
| 115 | |
Guenter Roeck | 52aab18 | 2017-01-11 12:59:51 -0800 | [diff] [blame] | 116 | gpiod_set_value(bitbang->mdc, what); |
Laurent Pinchart | a5edecc | 2008-05-26 11:53:21 +0200 | [diff] [blame] | 117 | } |
| 118 | |
Bhumika Goyal | 41a130f | 2017-08-22 13:43:29 +0530 | [diff] [blame] | 119 | static const struct mdiobb_ops mdio_gpio_ops = { |
Laurent Pinchart | a5edecc | 2008-05-26 11:53:21 +0200 | [diff] [blame] | 120 | .owner = THIS_MODULE, |
Paulius Zaleckas | f004f3e | 2008-11-14 00:24:34 +0000 | [diff] [blame] | 121 | .set_mdc = mdc_set, |
Laurent Pinchart | a5edecc | 2008-05-26 11:53:21 +0200 | [diff] [blame] | 122 | .set_mdio_dir = mdio_dir, |
Paulius Zaleckas | f004f3e | 2008-11-14 00:24:34 +0000 | [diff] [blame] | 123 | .set_mdio_data = mdio_set, |
| 124 | .get_mdio_data = mdio_get, |
Laurent Pinchart | a5edecc | 2008-05-26 11:53:21 +0200 | [diff] [blame] | 125 | }; |
| 126 | |
Bill Pemberton | 633d159 | 2012-12-03 09:24:14 -0500 | [diff] [blame] | 127 | static struct mii_bus *mdio_gpio_bus_init(struct device *dev, |
Greg Kroah-Hartman | 1dd06ae | 2012-12-06 14:30:56 +0000 | [diff] [blame] | 128 | struct mdio_gpio_platform_data *pdata, |
| 129 | int bus_id) |
Laurent Pinchart | a5edecc | 2008-05-26 11:53:21 +0200 | [diff] [blame] | 130 | { |
Paulius Zaleckas | f004f3e | 2008-11-14 00:24:34 +0000 | [diff] [blame] | 131 | struct mii_bus *new_bus; |
| 132 | struct mdio_gpio_info *bitbang; |
Paulius Zaleckas | f004f3e | 2008-11-14 00:24:34 +0000 | [diff] [blame] | 133 | int i; |
Guenter Roeck | 7e5fbd1 | 2017-01-11 12:59:50 -0800 | [diff] [blame] | 134 | int mdc, mdio, mdo; |
Guenter Roeck | 08d9665 | 2017-01-11 12:59:49 -0800 | [diff] [blame] | 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; |
Paulius Zaleckas | f004f3e | 2008-11-14 00:24:34 +0000 | [diff] [blame] | 138 | |
Guenter Roeck | 78cdb07 | 2014-04-15 19:16:40 -0700 | [diff] [blame] | 139 | bitbang = devm_kzalloc(dev, sizeof(*bitbang), GFP_KERNEL); |
Paulius Zaleckas | f004f3e | 2008-11-14 00:24:34 +0000 | [diff] [blame] | 140 | if (!bitbang) |
| 141 | goto out; |
| 142 | |
| 143 | bitbang->ctrl.ops = &mdio_gpio_ops; |
Srinivas Kandagatla | 6488270 | 2011-11-15 11:54:15 +0000 | [diff] [blame] | 144 | bitbang->ctrl.reset = pdata->reset; |
Guenter Roeck | 7e5fbd1 | 2017-01-11 12:59:50 -0800 | [diff] [blame] | 145 | mdc = pdata->mdc; |
| 146 | bitbang->mdc = gpio_to_desc(mdc); |
Guenter Roeck | 52aab18 | 2017-01-11 12:59:51 -0800 | [diff] [blame] | 147 | if (pdata->mdc_active_low) |
| 148 | mdc_flags = GPIOF_OUT_INIT_HIGH | GPIOF_ACTIVE_LOW; |
Guenter Roeck | 7e5fbd1 | 2017-01-11 12:59:50 -0800 | [diff] [blame] | 149 | mdio = pdata->mdio; |
| 150 | bitbang->mdio = gpio_to_desc(mdio); |
Guenter Roeck | 52aab18 | 2017-01-11 12:59:51 -0800 | [diff] [blame] | 151 | if (pdata->mdio_active_low) |
| 152 | mdio_flags |= GPIOF_ACTIVE_LOW; |
Guenter Roeck | 7e5fbd1 | 2017-01-11 12:59:50 -0800 | [diff] [blame] | 153 | mdo = pdata->mdo; |
Guenter Roeck | 52aab18 | 2017-01-11 12:59:51 -0800 | [diff] [blame] | 154 | if (mdo) { |
Guenter Roeck | 7e5fbd1 | 2017-01-11 12:59:50 -0800 | [diff] [blame] | 155 | bitbang->mdo = gpio_to_desc(mdo); |
Guenter Roeck | 52aab18 | 2017-01-11 12:59:51 -0800 | [diff] [blame] | 156 | if (pdata->mdo_active_low) |
| 157 | mdo_flags = GPIOF_OUT_INIT_LOW | GPIOF_ACTIVE_LOW; |
| 158 | } |
Paulius Zaleckas | f004f3e | 2008-11-14 00:24:34 +0000 | [diff] [blame] | 159 | |
| 160 | new_bus = alloc_mdio_bitbang(&bitbang->ctrl); |
| 161 | if (!new_bus) |
Guenter Roeck | 78cdb07 | 2014-04-15 19:16:40 -0700 | [diff] [blame] | 162 | goto out; |
Paulius Zaleckas | f004f3e | 2008-11-14 00:24:34 +0000 | [diff] [blame] | 163 | |
| 164 | new_bus->name = "GPIO Bitbanged MDIO", |
| 165 | |
Paulius Zaleckas | f004f3e | 2008-11-14 00:24:34 +0000 | [diff] [blame] | 166 | new_bus->phy_mask = pdata->phy_mask; |
Bert Vermeulen | ef7f3a5 | 2015-05-13 13:35:39 +0200 | [diff] [blame] | 167 | new_bus->phy_ignore_ta_mask = pdata->phy_ignore_ta_mask; |
Andrew Lunn | e7f4dc3 | 2016-01-06 20:11:15 +0100 | [diff] [blame] | 168 | memcpy(new_bus->irq, pdata->irqs, sizeof(new_bus->irq)); |
Paulius Zaleckas | f004f3e | 2008-11-14 00:24:34 +0000 | [diff] [blame] | 169 | new_bus->parent = dev; |
| 170 | |
| 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 | |
Bert Vermeulen | 7c0c826 | 2015-05-08 16:18:49 +0200 | [diff] [blame] | 178 | if (bus_id != -1) |
| 179 | snprintf(new_bus->id, MII_BUS_ID_SIZE, "gpio-%x", bus_id); |
| 180 | else |
| 181 | strncpy(new_bus->id, "gpio", MII_BUS_ID_SIZE); |
Paulius Zaleckas | f004f3e | 2008-11-14 00:24:34 +0000 | [diff] [blame] | 182 | |
Guenter Roeck | 7e5fbd1 | 2017-01-11 12:59:50 -0800 | [diff] [blame] | 183 | if (devm_gpio_request_one(dev, mdc, mdc_flags, "mdc")) |
Paulius Zaleckas | f004f3e | 2008-11-14 00:24:34 +0000 | [diff] [blame] | 184 | goto out_free_bus; |
| 185 | |
Guenter Roeck | 7e5fbd1 | 2017-01-11 12:59:50 -0800 | [diff] [blame] | 186 | if (devm_gpio_request_one(dev, mdio, mdio_flags, "mdio")) |
Guenter Roeck | 78cdb07 | 2014-04-15 19:16:40 -0700 | [diff] [blame] | 187 | goto out_free_bus; |
Paulius Zaleckas | f004f3e | 2008-11-14 00:24:34 +0000 | [diff] [blame] | 188 | |
Guenter Roeck | 7e5fbd1 | 2017-01-11 12:59:50 -0800 | [diff] [blame] | 189 | if (mdo && devm_gpio_request_one(dev, mdo, mdo_flags, "mdo")) |
| 190 | goto out_free_bus; |
Guenter Roeck | f1d54c4 | 2014-04-15 19:16:42 -0700 | [diff] [blame] | 191 | |
Paulius Zaleckas | f004f3e | 2008-11-14 00:24:34 +0000 | [diff] [blame] | 192 | dev_set_drvdata(dev, new_bus); |
| 193 | |
Mark Ware | dacac4d | 2009-07-23 10:56:48 -0700 | [diff] [blame] | 194 | return new_bus; |
Paulius Zaleckas | f004f3e | 2008-11-14 00:24:34 +0000 | [diff] [blame] | 195 | |
Paulius Zaleckas | f004f3e | 2008-11-14 00:24:34 +0000 | [diff] [blame] | 196 | out_free_bus: |
| 197 | free_mdio_bitbang(new_bus); |
Paulius Zaleckas | f004f3e | 2008-11-14 00:24:34 +0000 | [diff] [blame] | 198 | out: |
Mark Ware | dacac4d | 2009-07-23 10:56:48 -0700 | [diff] [blame] | 199 | return NULL; |
| 200 | } |
| 201 | |
Stephen Rothwell | f99b4a0 | 2009-11-16 22:47:33 +0000 | [diff] [blame] | 202 | static void mdio_gpio_bus_deinit(struct device *dev) |
Mark Ware | dacac4d | 2009-07-23 10:56:48 -0700 | [diff] [blame] | 203 | { |
| 204 | struct mii_bus *bus = dev_get_drvdata(dev); |
Mark Ware | dacac4d | 2009-07-23 10:56:48 -0700 | [diff] [blame] | 205 | |
Mark Ware | dacac4d | 2009-07-23 10:56:48 -0700 | [diff] [blame] | 206 | free_mdio_bitbang(bus); |
Paulius Zaleckas | f004f3e | 2008-11-14 00:24:34 +0000 | [diff] [blame] | 207 | } |
| 208 | |
Bill Pemberton | 633d159 | 2012-12-03 09:24:14 -0500 | [diff] [blame] | 209 | static void mdio_gpio_bus_destroy(struct device *dev) |
Paulius Zaleckas | f004f3e | 2008-11-14 00:24:34 +0000 | [diff] [blame] | 210 | { |
| 211 | struct mii_bus *bus = dev_get_drvdata(dev); |
Laurent Pinchart | a5edecc | 2008-05-26 11:53:21 +0200 | [diff] [blame] | 212 | |
Paulius Zaleckas | f004f3e | 2008-11-14 00:24:34 +0000 | [diff] [blame] | 213 | mdiobus_unregister(bus); |
Mark Ware | dacac4d | 2009-07-23 10:56:48 -0700 | [diff] [blame] | 214 | mdio_gpio_bus_deinit(dev); |
Paulius Zaleckas | f004f3e | 2008-11-14 00:24:34 +0000 | [diff] [blame] | 215 | } |
Laurent Pinchart | a5edecc | 2008-05-26 11:53:21 +0200 | [diff] [blame] | 216 | |
Bill Pemberton | 633d159 | 2012-12-03 09:24:14 -0500 | [diff] [blame] | 217 | static int mdio_gpio_probe(struct platform_device *pdev) |
Paulius Zaleckas | f004f3e | 2008-11-14 00:24:34 +0000 | [diff] [blame] | 218 | { |
Srinivas Kandagatla | e92bdf4b | 2012-08-24 01:59:17 +0000 | [diff] [blame] | 219 | struct mdio_gpio_platform_data *pdata; |
Mark Ware | dacac4d | 2009-07-23 10:56:48 -0700 | [diff] [blame] | 220 | struct mii_bus *new_bus; |
Srinivas Kandagatla | 3272dd9 | 2012-11-16 00:33:59 +0000 | [diff] [blame] | 221 | int ret, bus_id; |
Paulius Zaleckas | f004f3e | 2008-11-14 00:24:34 +0000 | [diff] [blame] | 222 | |
Srinivas Kandagatla | 3272dd9 | 2012-11-16 00:33:59 +0000 | [diff] [blame] | 223 | if (pdev->dev.of_node) { |
Srinivas Kandagatla | e92bdf4b | 2012-08-24 01:59:17 +0000 | [diff] [blame] | 224 | pdata = mdio_gpio_of_get_data(pdev); |
Srinivas Kandagatla | 3272dd9 | 2012-11-16 00:33:59 +0000 | [diff] [blame] | 225 | bus_id = of_alias_get_id(pdev->dev.of_node, "mdio-gpio"); |
Johan Hovold | 7f52da5 | 2014-05-08 10:09:21 +0200 | [diff] [blame] | 226 | if (bus_id < 0) { |
| 227 | dev_warn(&pdev->dev, "failed to get alias id\n"); |
| 228 | bus_id = 0; |
| 229 | } |
Srinivas Kandagatla | 3272dd9 | 2012-11-16 00:33:59 +0000 | [diff] [blame] | 230 | } else { |
Jingoo Han | 9bc7b1c | 2013-08-30 14:08:55 +0900 | [diff] [blame] | 231 | pdata = dev_get_platdata(&pdev->dev); |
Srinivas Kandagatla | 3272dd9 | 2012-11-16 00:33:59 +0000 | [diff] [blame] | 232 | bus_id = pdev->id; |
| 233 | } |
Srinivas Kandagatla | e92bdf4b | 2012-08-24 01:59:17 +0000 | [diff] [blame] | 234 | |
Paulius Zaleckas | f004f3e | 2008-11-14 00:24:34 +0000 | [diff] [blame] | 235 | if (!pdata) |
Laurent Pinchart | a5edecc | 2008-05-26 11:53:21 +0200 | [diff] [blame] | 236 | return -ENODEV; |
| 237 | |
Srinivas Kandagatla | 3272dd9 | 2012-11-16 00:33:59 +0000 | [diff] [blame] | 238 | new_bus = mdio_gpio_bus_init(&pdev->dev, pdata, bus_id); |
Mark Ware | dacac4d | 2009-07-23 10:56:48 -0700 | [diff] [blame] | 239 | if (!new_bus) |
| 240 | return -ENODEV; |
| 241 | |
Srinivas Kandagatla | e92bdf4b | 2012-08-24 01:59:17 +0000 | [diff] [blame] | 242 | if (pdev->dev.of_node) |
| 243 | ret = of_mdiobus_register(new_bus, pdev->dev.of_node); |
| 244 | else |
| 245 | ret = mdiobus_register(new_bus); |
| 246 | |
Mark Ware | dacac4d | 2009-07-23 10:56:48 -0700 | [diff] [blame] | 247 | if (ret) |
| 248 | mdio_gpio_bus_deinit(&pdev->dev); |
| 249 | |
| 250 | return ret; |
Paulius Zaleckas | f004f3e | 2008-11-14 00:24:34 +0000 | [diff] [blame] | 251 | } |
| 252 | |
Bill Pemberton | 633d159 | 2012-12-03 09:24:14 -0500 | [diff] [blame] | 253 | static int mdio_gpio_remove(struct platform_device *pdev) |
Paulius Zaleckas | f004f3e | 2008-11-14 00:24:34 +0000 | [diff] [blame] | 254 | { |
| 255 | mdio_gpio_bus_destroy(&pdev->dev); |
| 256 | |
Laurent Pinchart | a5edecc | 2008-05-26 11:53:21 +0200 | [diff] [blame] | 257 | return 0; |
| 258 | } |
| 259 | |
Fabian Frederick | d8a7dad | 2015-03-17 19:40:23 +0100 | [diff] [blame] | 260 | static const struct of_device_id mdio_gpio_of_match[] = { |
Srinivas Kandagatla | e92bdf4b | 2012-08-24 01:59:17 +0000 | [diff] [blame] | 261 | { .compatible = "virtual,mdio-gpio", }, |
| 262 | { /* sentinel */ } |
Laurent Pinchart | a5edecc | 2008-05-26 11:53:21 +0200 | [diff] [blame] | 263 | }; |
Luis de Bethencourt | 1ccb141 | 2015-09-18 18:16:29 +0200 | [diff] [blame] | 264 | MODULE_DEVICE_TABLE(of, mdio_gpio_of_match); |
Laurent Pinchart | a5edecc | 2008-05-26 11:53:21 +0200 | [diff] [blame] | 265 | |
Paulius Zaleckas | f004f3e | 2008-11-14 00:24:34 +0000 | [diff] [blame] | 266 | static struct platform_driver mdio_gpio_driver = { |
| 267 | .probe = mdio_gpio_probe, |
Bill Pemberton | 633d159 | 2012-12-03 09:24:14 -0500 | [diff] [blame] | 268 | .remove = mdio_gpio_remove, |
Paulius Zaleckas | f004f3e | 2008-11-14 00:24:34 +0000 | [diff] [blame] | 269 | .driver = { |
| 270 | .name = "mdio-gpio", |
Srinivas Kandagatla | e92bdf4b | 2012-08-24 01:59:17 +0000 | [diff] [blame] | 271 | .of_match_table = mdio_gpio_of_match, |
Paulius Zaleckas | f004f3e | 2008-11-14 00:24:34 +0000 | [diff] [blame] | 272 | }, |
| 273 | }; |
| 274 | |
Sachin Kamat | f8e5fc8 | 2013-03-20 01:41:31 +0000 | [diff] [blame] | 275 | module_platform_driver(mdio_gpio_driver); |
Paulius Zaleckas | f004f3e | 2008-11-14 00:24:34 +0000 | [diff] [blame] | 276 | |
| 277 | MODULE_ALIAS("platform:mdio-gpio"); |
| 278 | MODULE_AUTHOR("Laurent Pinchart, Paulius Zaleckas"); |
| 279 | MODULE_LICENSE("GPL"); |
| 280 | MODULE_DESCRIPTION("Generic driver for MDIO bus emulation using GPIO"); |