Skip to content

Commit ebf4ad9

Browse files
nmenondavem330
authored andcommitted
net: micrel : ks8851-ml: add vdd-supply support
Few platforms use external regulator to keep the ethernet MAC supplied. So, request and enable the regulator for driver functionality. Fixes: 66fda75 (regulator: core: Replace direct ops->disable usage) Reported-by: Russell King <[email protected]> Suggested-by: Markus Pargmann <[email protected]> Signed-off-by: Nishanth Menon <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent b74d3fe commit ebf4ad9

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

Documentation/devicetree/bindings/net/micrel-ks8851.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ Required properties:
77

88
Optional properties:
99
- local-mac-address : Ethernet mac address to use
10+
- vdd-supply: supply for Ethernet mac

drivers/net/ethernet/micrel/ks8851.c

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <linux/crc32.h>
2424
#include <linux/mii.h>
2525
#include <linux/eeprom_93cx6.h>
26+
#include <linux/regulator/consumer.h>
2627

2728
#include <linux/spi/spi.h>
2829

@@ -83,6 +84,7 @@ union ks8851_tx_hdr {
8384
* @rc_rxqcr: Cached copy of KS_RXQCR.
8485
* @eeprom_size: Companion eeprom size in Bytes, 0 if no eeprom
8586
* @eeprom: 93CX6 EEPROM state for accessing on-board EEPROM.
87+
* @vdd_reg: Optional regulator supplying the chip
8688
*
8789
* The @lock ensures that the chip is protected when certain operations are
8890
* in progress. When the read or write packet transfer is in progress, most
@@ -130,6 +132,7 @@ struct ks8851_net {
130132
struct spi_transfer spi_xfer2[2];
131133

132134
struct eeprom_93cx6 eeprom;
135+
struct regulator *vdd_reg;
133136
};
134137

135138
static int msg_enable;
@@ -1414,6 +1417,21 @@ static int ks8851_probe(struct spi_device *spi)
14141417
ks->spidev = spi;
14151418
ks->tx_space = 6144;
14161419

1420+
ks->vdd_reg = regulator_get_optional(&spi->dev, "vdd");
1421+
if (IS_ERR(ks->vdd_reg)) {
1422+
ret = PTR_ERR(ks->vdd_reg);
1423+
if (ret == -EPROBE_DEFER)
1424+
goto err_reg;
1425+
} else {
1426+
ret = regulator_enable(ks->vdd_reg);
1427+
if (ret) {
1428+
dev_err(&spi->dev, "regulator enable fail: %d\n",
1429+
ret);
1430+
goto err_reg_en;
1431+
}
1432+
}
1433+
1434+
14171435
mutex_init(&ks->lock);
14181436
spin_lock_init(&ks->statelock);
14191437

@@ -1508,8 +1526,14 @@ static int ks8851_probe(struct spi_device *spi)
15081526
err_netdev:
15091527
free_irq(ndev->irq, ks);
15101528

1511-
err_id:
15121529
err_irq:
1530+
err_id:
1531+
if (!IS_ERR(ks->vdd_reg))
1532+
regulator_disable(ks->vdd_reg);
1533+
err_reg_en:
1534+
if (!IS_ERR(ks->vdd_reg))
1535+
regulator_put(ks->vdd_reg);
1536+
err_reg:
15131537
free_netdev(ndev);
15141538
return ret;
15151539
}
@@ -1523,6 +1547,10 @@ static int ks8851_remove(struct spi_device *spi)
15231547

15241548
unregister_netdev(priv->netdev);
15251549
free_irq(spi->irq, priv);
1550+
if (!IS_ERR(priv->vdd_reg)) {
1551+
regulator_disable(priv->vdd_reg);
1552+
regulator_put(priv->vdd_reg);
1553+
}
15261554
free_netdev(priv->netdev);
15271555

15281556
return 0;

0 commit comments

Comments
 (0)