Skip to content

Commit 7994fe5

Browse files
Zubair Lutfullah Kakakheldavem330
authored andcommitted
dm9000: Add regulator and reset support to dm9000
In boards, the dm9000 chip's power and reset can be controlled by gpio. It makes sense to add them to the dm9000 driver and let dt be used to enable power and reset the phy. Signed-off-by: Zubair Lutfullah Kakakhel <[email protected]> Signed-off-by: Paul Burton <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 7eb35b1 commit 7994fe5

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

Documentation/devicetree/bindings/net/davicom-dm9000.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ Required properties:
1111
Optional properties:
1212
- davicom,no-eeprom : Configuration EEPROM is not available
1313
- davicom,ext-phy : Use external PHY
14+
- reset-gpios : phandle of gpio that will be used to reset chip during probe
15+
- vcc-supply : phandle of regulator that will be used to enable power to chip
1416

1517
Example:
1618

@@ -21,4 +23,6 @@ Example:
2123
interrupts = <7 4>;
2224
local-mac-address = [00 00 de ad be ef];
2325
davicom,no-eeprom;
26+
reset-gpios = <&gpf 12 GPIO_ACTIVE_LOW>;
27+
vcc-supply = <&eth0_power>;
2428
};

drivers/net/ethernet/davicom/dm9000.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
#include <linux/platform_device.h>
3737
#include <linux/irq.h>
3838
#include <linux/slab.h>
39+
#include <linux/regulator/consumer.h>
40+
#include <linux/gpio.h>
41+
#include <linux/of_gpio.h>
3942

4043
#include <asm/delay.h>
4144
#include <asm/irq.h>
@@ -1426,11 +1429,48 @@ dm9000_probe(struct platform_device *pdev)
14261429
struct dm9000_plat_data *pdata = dev_get_platdata(&pdev->dev);
14271430
struct board_info *db; /* Point a board information structure */
14281431
struct net_device *ndev;
1432+
struct device *dev = &pdev->dev;
14291433
const unsigned char *mac_src;
14301434
int ret = 0;
14311435
int iosize;
14321436
int i;
14331437
u32 id_val;
1438+
int reset_gpios;
1439+
enum of_gpio_flags flags;
1440+
struct regulator *power;
1441+
1442+
power = devm_regulator_get(dev, "vcc");
1443+
if (IS_ERR(power)) {
1444+
if (PTR_ERR(power) == -EPROBE_DEFER)
1445+
return -EPROBE_DEFER;
1446+
dev_dbg(dev, "no regulator provided\n");
1447+
} else {
1448+
ret = regulator_enable(power);
1449+
if (ret != 0) {
1450+
dev_err(dev,
1451+
"Failed to enable power regulator: %d\n", ret);
1452+
return ret;
1453+
}
1454+
dev_dbg(dev, "regulator enabled\n");
1455+
}
1456+
1457+
reset_gpios = of_get_named_gpio_flags(dev->of_node, "reset-gpios", 0,
1458+
&flags);
1459+
if (gpio_is_valid(reset_gpios)) {
1460+
ret = devm_gpio_request_one(dev, reset_gpios, flags,
1461+
"dm9000_reset");
1462+
if (ret) {
1463+
dev_err(dev, "failed to request reset gpio %d: %d\n",
1464+
reset_gpios, ret);
1465+
return -ENODEV;
1466+
}
1467+
1468+
/* According to manual PWRST# Low Period Min 1ms */
1469+
msleep(2);
1470+
gpio_set_value(reset_gpios, 1);
1471+
/* Needs 3ms to read eeprom when PWRST is deasserted */
1472+
msleep(4);
1473+
}
14341474

14351475
if (!pdata) {
14361476
pdata = dm9000_parse_dt(&pdev->dev);

0 commit comments

Comments
 (0)