Browse Source

staging:iio:ad799x use regulator for vref

Switch the ad799x driver to use the regulator framework and add binding for reference voltage.

Signed-off-by: Hartmut Knaack <knaack.h@gmx.de>
Acked-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Hartmut Knaack 12 years ago
parent
commit
2deaf23b22
2 changed files with 22 additions and 20 deletions
  1. 1 9
      drivers/staging/iio/adc/ad799x.h
  2. 21 11
      drivers/staging/iio/adc/ad799x_core.c

+ 1 - 9
drivers/staging/iio/adc/ad799x.h

@@ -95,7 +95,7 @@ struct ad799x_state {
 	struct i2c_client		*client;
 	struct i2c_client		*client;
 	const struct ad799x_chip_info	*chip_info;
 	const struct ad799x_chip_info	*chip_info;
 	struct regulator		*reg;
 	struct regulator		*reg;
-	u16				int_vref_mv;
+	struct regulator		*vref;
 	unsigned			id;
 	unsigned			id;
 	u16				config;
 	u16				config;
 
 
@@ -103,14 +103,6 @@ struct ad799x_state {
 	unsigned int			transfer_size;
 	unsigned int			transfer_size;
 };
 };
 
 
-/*
- * TODO: struct ad799x_platform_data needs to go into include/linux/iio
- */
-
-struct ad799x_platform_data {
-	u16				vref_mv;
-};
-
 #ifdef CONFIG_AD799X_RING_BUFFER
 #ifdef CONFIG_AD799X_RING_BUFFER
 int ad799x_register_ring_funcs_and_init(struct iio_dev *indio_dev);
 int ad799x_register_ring_funcs_and_init(struct iio_dev *indio_dev);
 void ad799x_ring_cleanup(struct iio_dev *indio_dev);
 void ad799x_ring_cleanup(struct iio_dev *indio_dev);

+ 21 - 11
drivers/staging/iio/adc/ad799x_core.c

@@ -179,7 +179,10 @@ static int ad799x_read_raw(struct iio_dev *indio_dev,
 			RES_MASK(chan->scan_type.realbits);
 			RES_MASK(chan->scan_type.realbits);
 		return IIO_VAL_INT;
 		return IIO_VAL_INT;
 	case IIO_CHAN_INFO_SCALE:
 	case IIO_CHAN_INFO_SCALE:
-		*val = st->int_vref_mv;
+		ret = regulator_get_voltage(st->vref);
+		if (ret < 0)
+			return ret;
+		*val = ret / 1000;
 		*val2 = chan->scan_type.realbits;
 		*val2 = chan->scan_type.realbits;
 		return IIO_VAL_FRACTIONAL_LOG2;
 		return IIO_VAL_FRACTIONAL_LOG2;
 	}
 	}
@@ -533,7 +536,6 @@ static int ad799x_probe(struct i2c_client *client,
 				   const struct i2c_device_id *id)
 				   const struct i2c_device_id *id)
 {
 {
 	int ret;
 	int ret;
-	struct ad799x_platform_data *pdata = client->dev.platform_data;
 	struct ad799x_state *st;
 	struct ad799x_state *st;
 	struct iio_dev *indio_dev;
 	struct iio_dev *indio_dev;
 
 
@@ -551,17 +553,21 @@ static int ad799x_probe(struct i2c_client *client,
 
 
 	/* TODO: Add pdata options for filtering and bit delay */
 	/* TODO: Add pdata options for filtering and bit delay */
 
 
-	if (!pdata)
-		return -EINVAL;
-
-	st->int_vref_mv = pdata->vref_mv;
-
 	st->reg = devm_regulator_get(&client->dev, "vcc");
 	st->reg = devm_regulator_get(&client->dev, "vcc");
-	if (!IS_ERR(st->reg)) {
-		ret = regulator_enable(st->reg);
-		if (ret)
-			return ret;
+	if (IS_ERR(st->reg))
+		return PTR_ERR(st->reg);
+	ret = regulator_enable(st->reg);
+	if (ret)
+		return ret;
+	st->vref = devm_regulator_get(&client->dev, "vref");
+	if (IS_ERR(st->vref)) {
+		ret = PTR_ERR(st->vref);
+		goto error_disable_reg;
 	}
 	}
+	ret = regulator_enable(st->vref);
+	if (ret)
+		goto error_disable_reg;
+
 	st->client = client;
 	st->client = client;
 
 
 	indio_dev->dev.parent = &client->dev;
 	indio_dev->dev.parent = &client->dev;
@@ -597,6 +603,8 @@ static int ad799x_probe(struct i2c_client *client,
 error_cleanup_ring:
 error_cleanup_ring:
 	ad799x_ring_cleanup(indio_dev);
 	ad799x_ring_cleanup(indio_dev);
 error_disable_reg:
 error_disable_reg:
+	if (!IS_ERR(st->vref))
+		regulator_disable(st->vref);
 	if (!IS_ERR(st->reg))
 	if (!IS_ERR(st->reg))
 		regulator_disable(st->reg);
 		regulator_disable(st->reg);
 
 
@@ -611,6 +619,8 @@ static int ad799x_remove(struct i2c_client *client)
 	iio_device_unregister(indio_dev);
 	iio_device_unregister(indio_dev);
 
 
 	ad799x_ring_cleanup(indio_dev);
 	ad799x_ring_cleanup(indio_dev);
+	if (!IS_ERR(st->vref))
+		regulator_disable(st->vref);
 	if (!IS_ERR(st->reg))
 	if (!IS_ERR(st->reg))
 		regulator_disable(st->reg);
 		regulator_disable(st->reg);
 	kfree(st->rx_buf);
 	kfree(st->rx_buf);