Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <Zubair.Kakakhel@imgtec.com>
Signed-off-by: Paul Burton <paul.burton@imgtec.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Zubair Lutfullah Kakakhel and committed by
David S. Miller
7994fe55 7eb35b14

+44
+4
Documentation/devicetree/bindings/net/davicom-dm9000.txt
··· 11 11 Optional properties: 12 12 - davicom,no-eeprom : Configuration EEPROM is not available 13 13 - 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 14 16 15 17 Example: 16 18 ··· 23 21 interrupts = <7 4>; 24 22 local-mac-address = [00 00 de ad be ef]; 25 23 davicom,no-eeprom; 24 + reset-gpios = <&gpf 12 GPIO_ACTIVE_LOW>; 25 + vcc-supply = <&eth0_power>; 26 26 };
+40
drivers/net/ethernet/davicom/dm9000.c
··· 36 36 #include <linux/platform_device.h> 37 37 #include <linux/irq.h> 38 38 #include <linux/slab.h> 39 + #include <linux/regulator/consumer.h> 40 + #include <linux/gpio.h> 41 + #include <linux/of_gpio.h> 39 42 40 43 #include <asm/delay.h> 41 44 #include <asm/irq.h> ··· 1429 1426 struct dm9000_plat_data *pdata = dev_get_platdata(&pdev->dev); 1430 1427 struct board_info *db; /* Point a board information structure */ 1431 1428 struct net_device *ndev; 1429 + struct device *dev = &pdev->dev; 1432 1430 const unsigned char *mac_src; 1433 1431 int ret = 0; 1434 1432 int iosize; 1435 1433 int i; 1436 1434 u32 id_val; 1435 + int reset_gpios; 1436 + enum of_gpio_flags flags; 1437 + struct regulator *power; 1438 + 1439 + power = devm_regulator_get(dev, "vcc"); 1440 + if (IS_ERR(power)) { 1441 + if (PTR_ERR(power) == -EPROBE_DEFER) 1442 + return -EPROBE_DEFER; 1443 + dev_dbg(dev, "no regulator provided\n"); 1444 + } else { 1445 + ret = regulator_enable(power); 1446 + if (ret != 0) { 1447 + dev_err(dev, 1448 + "Failed to enable power regulator: %d\n", ret); 1449 + return ret; 1450 + } 1451 + dev_dbg(dev, "regulator enabled\n"); 1452 + } 1453 + 1454 + reset_gpios = of_get_named_gpio_flags(dev->of_node, "reset-gpios", 0, 1455 + &flags); 1456 + if (gpio_is_valid(reset_gpios)) { 1457 + ret = devm_gpio_request_one(dev, reset_gpios, flags, 1458 + "dm9000_reset"); 1459 + if (ret) { 1460 + dev_err(dev, "failed to request reset gpio %d: %d\n", 1461 + reset_gpios, ret); 1462 + return -ENODEV; 1463 + } 1464 + 1465 + /* According to manual PWRST# Low Period Min 1ms */ 1466 + msleep(2); 1467 + gpio_set_value(reset_gpios, 1); 1468 + /* Needs 3ms to read eeprom when PWRST is deasserted */ 1469 + msleep(4); 1470 + } 1437 1471 1438 1472 if (!pdata) { 1439 1473 pdata = dm9000_parse_dt(&pdev->dev);