Skip to content

Commit

Permalink
dm9000: Add regulator and reset support to dm9000
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Zubair Lutfullah Kakakhel authored and davem330 committed Jan 15, 2015
1 parent 7eb35b1 commit 7994fe5
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Documentation/devicetree/bindings/net/davicom-dm9000.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Required properties:
Optional properties:
- davicom,no-eeprom : Configuration EEPROM is not available
- davicom,ext-phy : Use external PHY
- reset-gpios : 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:

Expand All @@ -21,4 +23,6 @@ Example:
interrupts = <7 4>;
local-mac-address = [00 00 de ad be ef];
davicom,no-eeprom;
reset-gpios = <&gpf 12 GPIO_ACTIVE_LOW>;
vcc-supply = <&eth0_power>;
};
40 changes: 40 additions & 0 deletions drivers/net/ethernet/davicom/dm9000.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -1426,11 +1429,48 @@ 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_gpios;
enum of_gpio_flags flags;
struct regulator *power;

power = devm_regulator_get(dev, "vcc");
if (IS_ERR(power)) {
if (PTR_ERR(power) == -EPROBE_DEFER)
return -EPROBE_DEFER;
dev_dbg(dev, "no regulator provided\n");
} else {
ret = regulator_enable(power);
if (ret != 0) {
dev_err(dev,
"Failed to enable power regulator: %d\n", ret);
return ret;
}
dev_dbg(dev, "regulator enabled\n");
}

reset_gpios = of_get_named_gpio_flags(dev->of_node, "reset-gpios", 0,
&flags);
if (gpio_is_valid(reset_gpios)) {
ret = devm_gpio_request_one(dev, reset_gpios, flags,
"dm9000_reset");
if (ret) {
dev_err(dev, "failed to request reset gpio %d: %d\n",
reset_gpios, ret);
return -ENODEV;
}

/* According to manual PWRST# Low Period Min 1ms */
msleep(2);
gpio_set_value(reset_gpios, 1);
/* Needs 3ms to read eeprom when PWRST is deasserted */
msleep(4);
}

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

0 comments on commit 7994fe5

Please sign in to comment.