Skip to content
Permalink
Browse files

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.

[paul.burton@imgtec.com: s/dev_dgb/dev_dbg/]

Signed-off-by: Zubair Lutfullah Kakakhel <Zubair.Kakakhel@imgtec.com>
Signed-off-by: Paul Burton <paul.burton@imgtec.com>
  • Loading branch information...
Zubair Lutfullah Kakakhel authored and paulburton committed Sep 1, 2014
1 parent e4ad9c4 commit e2299336b2922cbbaf1036869690b6fdf953c435
Showing with 37 additions and 0 deletions.
  1. +4 −0 Documentation/devicetree/bindings/net/davicom-dm9000.txt
  2. +33 −0 drivers/net/ethernet/davicom/dm9000.c
@@ -11,6 +11,8 @@ Required properties:
Optional properties:
- davicom,no-eeprom : Configuration EEPROM is not available
- davicom,ext-phy : Use external PHY
- reset-gpio : phandle of gpio that will be used to reset chip during probe
- vcc-supply : phandle of regulator that will be used to enable power to chip

Example:

@@ -21,4 +23,6 @@ Example:
interrupts = <7 4>;
local-mac-address = [00 00 de ad be ef];
davicom,no-eeprom;
reset-gpio = <&gpf 12 GPIO_ACTIVE_LOW>;
vcc-supply = <&eth0_power>;
};
@@ -36,6 +36,9 @@
#include <linux/platform_device.h>
#include <linux/irq.h>
#include <linux/slab.h>
#include <linux/regulator/consumer.h>
#include <linux/gpio.h>
#include <linux/of_gpio.h>

#include <asm/delay.h>
#include <asm/irq.h>
@@ -1424,11 +1427,41 @@ dm9000_probe(struct platform_device *pdev)
struct dm9000_plat_data *pdata = dev_get_platdata(&pdev->dev);
struct board_info *db; /* Point a board information structure */
struct net_device *ndev;
struct device *dev = &pdev->dev;
const unsigned char *mac_src;
int ret = 0;
int iosize;
int i;
u32 id_val;
int reset_gpio;
enum of_gpio_flags flags;
struct regulator *power;

power = devm_regulator_get(dev, "vcc");
if (IS_ERR(power)) {
dev_dbg(dev, "no regulator provided\n");
} else if (!regulator_is_enabled(power)) {
ret = regulator_enable(power);
dev_dbg(dev, "regulator enabled\n");
}

reset_gpio = of_get_named_gpio_flags(dev->of_node, "reset-gpio", 0,
&flags);
if (gpio_is_valid(reset_gpio)) {
ret = devm_gpio_request_one(dev, reset_gpio, flags,
"dm9000_reset");
if (ret) {
dev_err(dev, "failed to request reset gpio %d: %d\n",
reset_gpio, ret);
} else {
gpio_direction_output(reset_gpio, 0);
/* According to manual PWRST# Low Period Min 1ms */
msleep(2);
gpio_direction_output(reset_gpio, 1);
/* Needs 3ms to read eeprom when PWRST is deasserted */
msleep(4);
}
}

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

0 comments on commit e229933

Please sign in to comment.
You can’t perform that action at this time.