aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/ethernet/micrel/ks8851.c
diff options
context:
space:
mode:
authorStephen Boyd <sboyd@codeaurora.org>2014-05-23 15:57:19 -0400
committerDavid S. Miller <davem@davemloft.net>2014-05-24 14:03:21 -0400
commit73fdeb82e963a0e0f7f2781560b43655ab0b40d5 (patch)
treeea4728e5079e513e830ef655247e47bfa8a54974 /drivers/net/ethernet/micrel/ks8851.c
parentc78dbad8c441af4815cd660587470b78552ecfd8 (diff)
net: ks8851: Add optional vdd_io regulator and reset gpio
Allow the ks8851 driver to enable an optional 1.8V vdd_io regulator and assert the reset pin to the phy if a reset gpio is present in device tree. Cc: Nishanth Menon <nm@ti.com> Signed-off-by: Stephen Boyd <sboyd@codeaurora.org> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/ethernet/micrel/ks8851.c')
-rw-r--r--drivers/net/ethernet/micrel/ks8851.c54
1 files changed, 53 insertions, 1 deletions
diff --git a/drivers/net/ethernet/micrel/ks8851.c b/drivers/net/ethernet/micrel/ks8851.c
index f2bfc708880c..3a322daba5ff 100644
--- a/drivers/net/ethernet/micrel/ks8851.c
+++ b/drivers/net/ethernet/micrel/ks8851.c
@@ -26,6 +26,8 @@
26#include <linux/regulator/consumer.h> 26#include <linux/regulator/consumer.h>
27 27
28#include <linux/spi/spi.h> 28#include <linux/spi/spi.h>
29#include <linux/gpio.h>
30#include <linux/of_gpio.h>
29 31
30#include "ks8851.h" 32#include "ks8851.h"
31 33
@@ -85,6 +87,8 @@ union ks8851_tx_hdr {
85 * @eeprom_size: Companion eeprom size in Bytes, 0 if no eeprom 87 * @eeprom_size: Companion eeprom size in Bytes, 0 if no eeprom
86 * @eeprom: 93CX6 EEPROM state for accessing on-board EEPROM. 88 * @eeprom: 93CX6 EEPROM state for accessing on-board EEPROM.
87 * @vdd_reg: Optional regulator supplying the chip 89 * @vdd_reg: Optional regulator supplying the chip
90 * @vdd_io: Optional digital power supply for IO
91 * @gpio: Optional reset_n gpio
88 * 92 *
89 * The @lock ensures that the chip is protected when certain operations are 93 * The @lock ensures that the chip is protected when certain operations are
90 * in progress. When the read or write packet transfer is in progress, most 94 * in progress. When the read or write packet transfer is in progress, most
@@ -133,6 +137,8 @@ struct ks8851_net {
133 137
134 struct eeprom_93cx6 eeprom; 138 struct eeprom_93cx6 eeprom;
135 struct regulator *vdd_reg; 139 struct regulator *vdd_reg;
140 struct regulator *vdd_io;
141 int gpio;
136}; 142};
137 143
138static int msg_enable; 144static int msg_enable;
@@ -1404,6 +1410,7 @@ static int ks8851_probe(struct spi_device *spi)
1404 struct ks8851_net *ks; 1410 struct ks8851_net *ks;
1405 int ret; 1411 int ret;
1406 unsigned cider; 1412 unsigned cider;
1413 int gpio;
1407 1414
1408 ndev = alloc_etherdev(sizeof(struct ks8851_net)); 1415 ndev = alloc_etherdev(sizeof(struct ks8851_net));
1409 if (!ndev) 1416 if (!ndev)
@@ -1417,6 +1424,37 @@ static int ks8851_probe(struct spi_device *spi)
1417 ks->spidev = spi; 1424 ks->spidev = spi;
1418 ks->tx_space = 6144; 1425 ks->tx_space = 6144;
1419 1426
1427 gpio = of_get_named_gpio_flags(spi->dev.of_node, "reset-gpios",
1428 0, NULL);
1429 if (gpio == -EPROBE_DEFER) {
1430 ret = gpio;
1431 goto err_gpio;
1432 }
1433
1434 ks->gpio = gpio;
1435 if (gpio_is_valid(gpio)) {
1436 ret = devm_gpio_request_one(&spi->dev, gpio,
1437 GPIOF_OUT_INIT_LOW, "ks8851_rst_n");
1438 if (ret) {
1439 dev_err(&spi->dev, "reset gpio request failed\n");
1440 goto err_gpio;
1441 }
1442 }
1443
1444 ks->vdd_io = devm_regulator_get_optional(&spi->dev, "vdd-io");
1445 if (IS_ERR(ks->vdd_io)) {
1446 ret = PTR_ERR(ks->vdd_io);
1447 if (ret == -EPROBE_DEFER)
1448 goto err_reg_io;
1449 } else {
1450 ret = regulator_enable(ks->vdd_io);
1451 if (ret) {
1452 dev_err(&spi->dev, "regulator vdd_io enable fail: %d\n",
1453 ret);
1454 goto err_reg_io;
1455 }
1456 }
1457
1420 ks->vdd_reg = devm_regulator_get_optional(&spi->dev, "vdd"); 1458 ks->vdd_reg = devm_regulator_get_optional(&spi->dev, "vdd");
1421 if (IS_ERR(ks->vdd_reg)) { 1459 if (IS_ERR(ks->vdd_reg)) {
1422 ret = PTR_ERR(ks->vdd_reg); 1460 ret = PTR_ERR(ks->vdd_reg);
@@ -1425,12 +1463,16 @@ static int ks8851_probe(struct spi_device *spi)
1425 } else { 1463 } else {
1426 ret = regulator_enable(ks->vdd_reg); 1464 ret = regulator_enable(ks->vdd_reg);
1427 if (ret) { 1465 if (ret) {
1428 dev_err(&spi->dev, "regulator enable fail: %d\n", 1466 dev_err(&spi->dev, "regulator vdd enable fail: %d\n",
1429 ret); 1467 ret);
1430 goto err_reg; 1468 goto err_reg;
1431 } 1469 }
1432 } 1470 }
1433 1471
1472 if (gpio_is_valid(gpio)) {
1473 usleep_range(10000, 11000);
1474 gpio_set_value(gpio, 1);
1475 }
1434 1476
1435 mutex_init(&ks->lock); 1477 mutex_init(&ks->lock);
1436 spin_lock_init(&ks->statelock); 1478 spin_lock_init(&ks->statelock);
@@ -1527,10 +1569,16 @@ err_netdev:
1527 free_irq(ndev->irq, ks); 1569 free_irq(ndev->irq, ks);
1528 1570
1529err_irq: 1571err_irq:
1572 if (gpio_is_valid(gpio))
1573 gpio_set_value(gpio, 0);
1530err_id: 1574err_id:
1531 if (!IS_ERR(ks->vdd_reg)) 1575 if (!IS_ERR(ks->vdd_reg))
1532 regulator_disable(ks->vdd_reg); 1576 regulator_disable(ks->vdd_reg);
1533err_reg: 1577err_reg:
1578 if (!IS_ERR(ks->vdd_io))
1579 regulator_disable(ks->vdd_io);
1580err_reg_io:
1581err_gpio:
1534 free_netdev(ndev); 1582 free_netdev(ndev);
1535 return ret; 1583 return ret;
1536} 1584}
@@ -1544,8 +1592,12 @@ static int ks8851_remove(struct spi_device *spi)
1544 1592
1545 unregister_netdev(priv->netdev); 1593 unregister_netdev(priv->netdev);
1546 free_irq(spi->irq, priv); 1594 free_irq(spi->irq, priv);
1595 if (gpio_is_valid(priv->gpio))
1596 gpio_set_value(priv->gpio, 0);
1547 if (!IS_ERR(priv->vdd_reg)) 1597 if (!IS_ERR(priv->vdd_reg))
1548 regulator_disable(priv->vdd_reg); 1598 regulator_disable(priv->vdd_reg);
1599 if (!IS_ERR(priv->vdd_io))
1600 regulator_disable(priv->vdd_io);
1549 free_netdev(priv->netdev); 1601 free_netdev(priv->netdev);
1550 1602
1551 return 0; 1603 return 0;