[PATCH 05/21] net: ksz8864: Use dev_add_param_bool for enable parameter

Sascha Hauer s.hauer at pengutronix.de
Sun Apr 7 10:00:39 EDT 2013


Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/net/ksz8864rmn.c | 30 +++++++++++-------------------
 1 file changed, 11 insertions(+), 19 deletions(-)

diff --git a/drivers/net/ksz8864rmn.c b/drivers/net/ksz8864rmn.c
index af3c124..ec3e9f7 100644
--- a/drivers/net/ksz8864rmn.c
+++ b/drivers/net/ksz8864rmn.c
@@ -49,6 +49,7 @@
 struct micrel_switch_priv {
 	struct cdev             cdev;
 	struct spi_device       *spi;
+	unsigned int		p_enable;
 };
 
 static int micrel_switch_read_reg(struct spi_device *spi, uint8_t reg)
@@ -78,27 +79,15 @@ static void micrel_switch_write_reg(struct spi_device *spi, uint8_t reg, uint8_t
 	spi_write_then_read(spi, tx, 3, NULL, 0);
 }
 
-static int micrel_switch_enable_set(struct device_d *dev, struct param_d *param,
-		const char *val)
+static int micrel_switch_enable_set(struct param_d *param, void *_priv)
 {
-	struct spi_device *spi = (struct spi_device *)dev->type_data;
-	int enable;
-	char *new;
+	struct micrel_switch_priv *priv = _priv;
+	struct spi_device *spi = priv->spi;
 
-	if (!val)
-		return dev_param_set_generic(dev, param, NULL);
-
-	enable = simple_strtoul(val, NULL, 0);
-
-	if (enable) {
+	if (priv->p_enable)
 		micrel_switch_write_reg(spi, REG_ID1, 1);
-		new = "1";
-	} else {
+	else
 		micrel_switch_write_reg(spi, REG_ID1, 0);
-		new = "0";
-	}
-
-	dev_param_set_generic(dev, param, new);
 
 	return 0;
 }
@@ -172,8 +161,11 @@ static int micrel_switch_probe(struct device_d *dev)
 	priv->cdev.dev = dev;
 	devfs_create(&priv->cdev);
 
-	dev_add_param(dev, "enable", micrel_switch_enable_set, NULL, 0);
-	dev_set_param(dev, "enable", "1");
+	dev_add_param_bool(dev, "enable", micrel_switch_enable_set,
+			NULL, &priv->p_enable, priv);
+
+	priv->p_enable = 1;
+	micrel_switch_write_reg(priv->spi, REG_ID1, 1);
 
 	return 0;
 }
-- 
1.8.2.rc2




More information about the barebox mailing list