[PATCH 2/2 v5] net/smsc911x: Add regulator support

2011-11-24 Thread Robert Marklund
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 
Cc: linux...@vger.kernel.org
Cc: Sascha Hauer 
Cc: Tony Lindgren 
Cc: linux-omap@vger.kernel.org
Cc: Mike Frysinger 
Cc: uclinux-dist-de...@blackfin.uclinux.org
Reviewed-by: Mark Brown 
Signed-off-by: Robert Marklund 
Signed-off-by: Linus Walleij 
---
ChangeLog v4->v5:
- Split the enable_disable method on Mikes request.
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 |  111 ++
 1 files changed, 100 insertions(+), 11 deletions(-)

diff --git a/drivers/net/ethernet/smsc/smsc911x.c 
b/drivers/net/ethernet/smsc/smsc911x.c
index 8843071..06d0df6 100644
--- a/drivers/net/ethernet/smsc/smsc911x.c
+++ b/drivers/net/ethernet/smsc/smsc911x.c
@@ -44,6 +44,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -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,76 @@ out:
spin_unlock_irqrestore(&pdata->dev_lock, flags);
 }
 
+/*
+ * enable resources, currently just regulators.
+ */
+static int smsc911x_enable_resources(struct platform_device *pdev)
+{
+   struct net_device *ndev = platform_get_drvdata(pdev);
+   struct smsc911x_data *pdata = netdev_priv(ndev);
+   int ret = 0;
+
+   ret = regulator_bulk_enable(ARRAY_SIZE(pdata->supplies),
+   pdata->supplies);
+   if (ret)
+   netdev_err(ndev, "failed to enable regulators %d\n",
+   ret);
+   return ret;
+}
+
+/*
+ * disable resources, currently just regulators.
+ */
+static int smsc911x_disable_resources(struct platform_device *pdev)
+{
+   struct net_device *ndev = platform_get_drvdata(pdev);
+   struct smsc911x_data *pdata = netdev_priv(ndev);
+   int ret = 0;
+
+   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 *pda

RE: [PATCH 2/2 v4] net/smsc911x: Add regulator support

2011-11-16 Thread Robert MARKLUND

> -Original Message-
> From: Mike Frysinger [mailto:vap...@gentoo.org]
> Sent: den 31 oktober 2011 19:21
> To: Robert MARKLUND
> Cc: net...@vger.kernel.org; Steve Glendinning; Mathieu Poirier; Paul Mundt; 
> linux...@vger.kernel.org;
> Sascha Hauer; Tony Lindgren; linux-omap@vger.kernel.org; 
> uclinux-dist-de...@blackfin.uclinux.org;
> Linus Walleij
> Subject: Re: [PATCH 2/2 v4] net/smsc911x: Add regulator support
> 
> 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.

> 
> > iounmap(pdata->ioaddr);
> >
> > +   (void)smsc911x_enable_disable_resources(pdev, false);
> 
> i don't think the (void) cast is necessary

I like telling the reader of the code that I ignore the return value, 
I did not just forget it.

/R

> 
> otherwise looks fine
> -mike
N�r��yb�X��ǧv�^�)޺{.n�+{��f��{ay�ʇڙ�,j��f���h���z��w���
���j:+v���w�j�mzZ+�ݢj"��!�i

[PATCH 2/2 v4] net/smsc911x: Add regulator support

2011-10-31 Thread Robert Marklund
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 
Cc: linux...@vger.kernel.org
Cc: Sascha Hauer 
Cc: Tony Lindgren 
Cc: linux-omap@vger.kernel.org
Cc: Mike Frysinger 
Cc: uclinux-dist-de...@blackfin.uclinux.org
Reviewed-by: Mark Brown 
Signed-off-by: Robert Marklund 
Signed-off-by: Linus Walleij 
---
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 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -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_ena