* [PATCH 2/2 v4] net/smsc911x: Add regulator support
@ 2011-10-31 12:38 Robert Marklund
2011-10-31 18:21 ` Mike Frysinger
0 siblings, 1 reply; 4+ messages in thread
From: Robert Marklund @ 2011-10-31 12:38 UTC (permalink / raw)
To: netdev, Steve Glendinning
Cc: Mathieu Poirier, Robert Marklund, Paul Mundt, linux-sh,
Sascha Hauer, Tony Lindgren, linux-omap, Mike Frysinger,
uclinux-dist-devel, Linus Walleij
Add some basic regulator support for the power pins, as needed
by the ST-Ericsson Snowball platform that powers up the SMSC911
chip using an external regulator.
Platforms that use regulators and the smsc911x and have no defined
regulator for the smsc911x and claim complete regulator
constraints with no dummy regulators will need to provide it, for
example using a fixed voltage regulator. It appears that this may
affect (apart from Ux500 Snowball) possibly these archs/machines
that from some grep:s appear to define both CONFIG_SMSC911X and
CONFIG_REGULATOR:
- ARM Freescale mx3 and OMAP 2 plus, Raumfeld machines
- Blackfin
- Super-H
Cc: Paul Mundt <lethal@linux-sh.org>
Cc: linux-sh@vger.kernel.org
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Tony Lindgren <tony@atomide.com>
Cc: linux-omap@vger.kernel.org
Cc: Mike Frysinger <vapier@gentoo.org>
Cc: uclinux-dist-devel@blackfin.uclinux.org
Reviewed-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Signed-off-by: Robert Marklund <robert.marklund@stericsson.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
ChangeLog v3->v4:
- Remove dual prints and old comment on Mike's request.
- Split the request_free fucntion on Mike and Sascha request.
ChangeLog v2->v3:
- Use bulk regulators on Mark's request.
- Add Cc-fileds to some possibly affected platforms.
ChangeLog v1->v2:
- Don't check for NULL regulators and error out properly if the
regulators can't be found. All platforms using the smsc911x
and the regulator framework simultaneously need to provide some
kind of regulator for it.
---
drivers/net/ethernet/smsc/smsc911x.c | 103 ++++++++++++++++++++++++++++++----
1 files changed, 92 insertions(+), 11 deletions(-)
diff --git a/drivers/net/ethernet/smsc/smsc911x.c b/drivers/net/ethernet/smsc/smsc911x.c
index 8843071..9a2e792 100644
--- a/drivers/net/ethernet/smsc/smsc911x.c
+++ b/drivers/net/ethernet/smsc/smsc911x.c
@@ -44,6 +44,7 @@
#include <linux/module.h>
#include <linux/netdevice.h>
#include <linux/platform_device.h>
+#include <linux/regulator/consumer.h>
#include <linux/sched.h>
#include <linux/timer.h>
#include <linux/bug.h>
@@ -88,6 +89,8 @@ struct smsc911x_ops {
unsigned int *buf, unsigned int wordcount);
};
+#define SMSC911X_NUM_SUPPLIES 2
+
struct smsc911x_data {
void __iomem *ioaddr;
@@ -138,6 +141,9 @@ struct smsc911x_data {
/* register access functions */
const struct smsc911x_ops *ops;
+
+ /* regulators */
+ struct regulator_bulk_data supplies[SMSC911X_NUM_SUPPLIES];
};
/* Easy access to information */
@@ -362,6 +368,68 @@ out:
spin_unlock_irqrestore(&pdata->dev_lock, flags);
}
+/*
+ * Enable or disable resources, currently just regulators.
+ */
+static int smsc911x_enable_disable_resources(struct platform_device *pdev,
+ bool enable)
+{
+ struct net_device *ndev = platform_get_drvdata(pdev);
+ struct smsc911x_data *pdata = netdev_priv(ndev);
+ int ret = 0;
+
+ /* enable/disable regulators */
+ if (enable) {
+ ret = regulator_bulk_enable(ARRAY_SIZE(pdata->supplies),
+ pdata->supplies);
+ if (ret)
+ netdev_err(ndev, "failed to enable regulators %d\n",
+ ret);
+ } else
+ ret = regulator_bulk_disable(ARRAY_SIZE(pdata->supplies),
+ pdata->supplies);
+ return ret;
+}
+
+/*
+ * Request resources, currently just regulators.
+ *
+ * The SMSC911x has two power pins: vddvario and vdd33a, in designs where
+ * these are not always-on we need to request regulators to be turned on
+ * before we can try to access the device registers.
+ */
+static int smsc911x_request_resources(struct platform_device *pdev)
+{
+ struct net_device *ndev = platform_get_drvdata(pdev);
+ struct smsc911x_data *pdata = netdev_priv(ndev);
+ int ret = 0;
+
+ /* Request regulators */
+ pdata->supplies[0].supply = "vdd33a";
+ pdata->supplies[1].supply = "vddvario";
+ ret = regulator_bulk_get(&pdev->dev,
+ ARRAY_SIZE(pdata->supplies),
+ pdata->supplies);
+ if (ret)
+ netdev_err(ndev, "couldn't get regulators %d\n",
+ ret);
+ return ret;
+}
+
+/*
+ * Free resources, currently just regulators.
+ *
+ */
+static void smsc911x_free_resources(struct platform_device *pdev)
+{
+ struct net_device *ndev = platform_get_drvdata(pdev);
+ struct smsc911x_data *pdata = netdev_priv(ndev);
+
+ /* Free regulators */
+ regulator_bulk_free(ARRAY_SIZE(pdata->supplies),
+ pdata->supplies);
+}
+
/* waits for MAC not busy, with timeout. Only called by smsc911x_mac_read
* and smsc911x_mac_write, so assumes mac_lock is held */
static int smsc911x_mac_complete(struct smsc911x_data *pdata)
@@ -2092,6 +2160,9 @@ static int __devexit smsc911x_drv_remove(struct platform_device *pdev)
iounmap(pdata->ioaddr);
+ (void)smsc911x_enable_disable_resources(pdev, false);
+ smsc911x_free_resources(pdev);
+
free_netdev(dev);
return 0;
@@ -2218,10 +2289,20 @@ static int __devinit smsc911x_drv_probe(struct platform_device *pdev)
pdata->dev = dev;
pdata->msg_enable = ((1 << debug) - 1);
+ platform_set_drvdata(pdev, dev);
+
+ retval = smsc911x_request_resources(pdev);
+ if (retval)
+ goto out_return_resources;
+
+ retval = smsc911x_enable_disable_resources(pdev, true);
+ if (retval)
+ goto out_disable_resources;
+
if (pdata->ioaddr = NULL) {
SMSC_WARN(pdata, probe, "Error smsc911x base address invalid");
retval = -ENOMEM;
- goto out_free_netdev_2;
+ goto out_disable_resources;
}
retval = smsc911x_probe_config_dt(&pdata->config, np);
@@ -2233,7 +2314,7 @@ static int __devinit smsc911x_drv_probe(struct platform_device *pdev)
if (retval) {
SMSC_WARN(pdata, probe, "Error smsc911x config not found");
- goto out_unmap_io_3;
+ goto out_disable_resources;
}
/* assume standard, non-shifted, access to HW registers */
@@ -2244,7 +2325,7 @@ static int __devinit smsc911x_drv_probe(struct platform_device *pdev)
retval = smsc911x_init(dev);
if (retval < 0)
- goto out_unmap_io_3;
+ goto out_disable_resources;
/* configure irq polarity and type before connecting isr */
if (pdata->config.irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_HIGH)
@@ -2264,15 +2345,13 @@ static int __devinit smsc911x_drv_probe(struct platform_device *pdev)
if (retval) {
SMSC_WARN(pdata, probe,
"Unable to claim requested irq: %d", dev->irq);
- goto out_unmap_io_3;
+ goto out_free_irq;
}
- platform_set_drvdata(pdev, dev);
-
retval = register_netdev(dev);
if (retval) {
SMSC_WARN(pdata, probe, "Error %i registering device", retval);
- goto out_unset_drvdata_4;
+ goto out_free_irq;
} else {
SMSC_TRACE(pdata, probe,
"Network interface: \"%s\"", dev->name);
@@ -2321,12 +2400,14 @@ static int __devinit smsc911x_drv_probe(struct platform_device *pdev)
out_unregister_netdev_5:
unregister_netdev(dev);
-out_unset_drvdata_4:
- platform_set_drvdata(pdev, NULL);
+out_free_irq:
free_irq(dev->irq, dev);
-out_unmap_io_3:
+out_disable_resources:
+ (void)smsc911x_enable_disable_resources(pdev, false);
+out_return_resources:
+ smsc911x_free_resources(pdev);
+ platform_set_drvdata(pdev, NULL);
iounmap(pdata->ioaddr);
-out_free_netdev_2:
free_netdev(dev);
out_release_io_1:
release_mem_region(res->start, resource_size(res));
--
1.7.1
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH 2/2 v4] net/smsc911x: Add regulator support
2011-10-31 12:38 [PATCH 2/2 v4] net/smsc911x: Add regulator support Robert Marklund
@ 2011-10-31 18:21 ` Mike Frysinger
2011-11-16 12:59 ` Robert MARKLUND
0 siblings, 1 reply; 4+ messages in thread
From: Mike Frysinger @ 2011-10-31 18:21 UTC (permalink / raw)
To: Robert Marklund
Cc: netdev, Steve Glendinning, Mathieu Poirier, Paul Mundt, linux-sh,
Sascha Hauer, Tony Lindgren, linux-omap, uclinux-dist-devel,
Linus Walleij
[-- Attachment #1: Type: Text/Plain, Size: 437 bytes --]
On Monday 31 October 2011 08:38:39 Robert Marklund wrote:
> ChangeLog v3->v4:
> - Remove dual prints and old comment on Mike's request.
> - Split the request_free fucntion on Mike and Sascha request.
would be nice if the enable/disable were split as well ...
> iounmap(pdata->ioaddr);
>
> + (void)smsc911x_enable_disable_resources(pdev, false);
i don't think the (void) cast is necessary
otherwise looks fine
-mike
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* RE: [PATCH 2/2 v4] net/smsc911x: Add regulator support
2011-10-31 18:21 ` Mike Frysinger
@ 2011-11-16 12:59 ` Robert MARKLUND
2011-11-17 5:07 ` Mike Frysinger
0 siblings, 1 reply; 4+ messages in thread
From: Robert MARKLUND @ 2011-11-16 12:59 UTC (permalink / raw)
To: Mike Frysinger
Cc: netdev@vger.kernel.org, Steve Glendinning, Mathieu Poirier,
Paul Mundt, linux-sh@vger.kernel.org, Sascha Hauer, Tony Lindgren,
linux-omap@vger.kernel.org,
uclinux-dist-devel@blackfin.uclinux.org, Linus Walleij
DQo+IC0tLS0tT3JpZ2luYWwgTWVzc2FnZS0tLS0tDQo+IEZyb206IE1pa2UgRnJ5c2luZ2VyIFtt
YWlsdG86dmFwaWVyQGdlbnRvby5vcmddDQo+IFNlbnQ6IGRlbiAzMSBva3RvYmVyIDIwMTEgMTk6
MjENCj4gVG86IFJvYmVydCBNQVJLTFVORA0KPiBDYzogbmV0ZGV2QHZnZXIua2VybmVsLm9yZzsg
U3RldmUgR2xlbmRpbm5pbmc7IE1hdGhpZXUgUG9pcmllcjsgUGF1bCBNdW5kdDsgbGludXgtc2hA
dmdlci5rZXJuZWwub3JnOw0KPiBTYXNjaGEgSGF1ZXI7IFRvbnkgTGluZGdyZW47IGxpbnV4LW9t
YXBAdmdlci5rZXJuZWwub3JnOyB1Y2xpbnV4LWRpc3QtZGV2ZWxAYmxhY2tmaW4udWNsaW51eC5v
cmc7DQo+IExpbnVzIFdhbGxlaWoNCj4gU3ViamVjdDogUmU6IFtQQVRD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-11-17 5:07 ` Mike Frysinger
0 siblings, 0 replies; 4+ messages in thread
From: Mike Frysinger @ 2011-11-17 5:07 UTC (permalink / raw)
To: Robert MARKLUND
Cc: netdev@vger.kernel.org, Steve Glendinning, Mathieu Poirier,
Paul Mundt, linux-sh@vger.kernel.org, Sascha Hauer, Tony Lindgren,
linux-omap@vger.kernel.org,
uclinux-dist-devel@blackfin.uclinux.org, Linus Walleij
[-- Attachment #1: Type: Text/Plain, Size: 521 bytes --]
On Wednesday 16 November 2011 07:59:41 Robert MARKLUND wrote:
> From: Mike Frysinger [mailto:vapier@gentoo.org]
> > On Monday 31 October 2011 08:38:39 Robert Marklund wrote:
> > > ChangeLog v3->v4:
> > > - Remove dual prints and old comment on Mike's request.
> > > - Split the request_free fucntion on Mike and Sascha request.
> >
> > would be nice if the enable/disable were split as well ...
>
> I interpret this as "nice if", if it's a "must be" then ill change it.
i would prefer it were split
-mike
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2011-11-17 5:07 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-10-31 12:38 [PATCH 2/2 v4] net/smsc911x: Add regulator support Robert Marklund
2011-10-31 18:21 ` Mike Frysinger
2011-11-16 12:59 ` Robert MARKLUND
2011-11-17 5:07 ` Mike Frysinger
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox