Commit 8cfa26a7 authored by Andy Shevchenko's avatar Andy Shevchenko Committed by Jonathan Cameron

iio: adc: ti-ads7950: Allow to use on ACPI platforms

ACPI enabled platforms do not have a mean of regulators. Instead we use
hard coded voltage value for reference pin. When value is 0 (default) we
fall back to request a regulator.
Signed-off-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 0a60340f
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
* GNU General Public License for more details. * GNU General Public License for more details.
*/ */
#include <linux/acpi.h>
#include <linux/bitops.h> #include <linux/bitops.h>
#include <linux/device.h> #include <linux/device.h>
#include <linux/err.h> #include <linux/err.h>
...@@ -37,6 +38,12 @@ ...@@ -37,6 +38,12 @@
#include <linux/iio/trigger_consumer.h> #include <linux/iio/trigger_consumer.h>
#include <linux/iio/triggered_buffer.h> #include <linux/iio/triggered_buffer.h>
/*
* In case of ACPI, we use the 5000 mV as default for the reference pin.
* Device tree users encode that via the vref-supply regulator.
*/
#define TI_ADS7950_VA_MV_ACPI_DEFAULT 5000
#define TI_ADS7950_CR_MANUAL BIT(12) #define TI_ADS7950_CR_MANUAL BIT(12)
#define TI_ADS7950_CR_WRITE BIT(11) #define TI_ADS7950_CR_WRITE BIT(11)
#define TI_ADS7950_CR_CHAN(ch) ((ch) << 7) #define TI_ADS7950_CR_CHAN(ch) ((ch) << 7)
...@@ -58,6 +65,7 @@ struct ti_ads7950_state { ...@@ -58,6 +65,7 @@ struct ti_ads7950_state {
struct spi_message scan_single_msg; struct spi_message scan_single_msg;
struct regulator *reg; struct regulator *reg;
unsigned int vref_mv;
unsigned int settings; unsigned int settings;
...@@ -305,11 +313,15 @@ static int ti_ads7950_get_range(struct ti_ads7950_state *st) ...@@ -305,11 +313,15 @@ static int ti_ads7950_get_range(struct ti_ads7950_state *st)
{ {
int vref; int vref;
if (st->vref_mv) {
vref = st->vref_mv;
} else {
vref = regulator_get_voltage(st->reg); vref = regulator_get_voltage(st->reg);
if (vref < 0) if (vref < 0)
return vref; return vref;
vref /= 1000; vref /= 1000;
}
if (st->settings & TI_ADS7950_CR_RANGE_5V) if (st->settings & TI_ADS7950_CR_RANGE_5V)
vref *= 2; vref *= 2;
...@@ -411,6 +423,10 @@ static int ti_ads7950_probe(struct spi_device *spi) ...@@ -411,6 +423,10 @@ static int ti_ads7950_probe(struct spi_device *spi)
spi_message_init_with_transfers(&st->scan_single_msg, spi_message_init_with_transfers(&st->scan_single_msg,
st->scan_single_xfer, 3); st->scan_single_xfer, 3);
/* Use hard coded value for reference voltage in ACPI case */
if (ACPI_COMPANION(&spi->dev))
st->vref_mv = TI_ADS7950_VA_MV_ACPI_DEFAULT;
st->reg = devm_regulator_get(&spi->dev, "vref"); st->reg = devm_regulator_get(&spi->dev, "vref");
if (IS_ERR(st->reg)) { if (IS_ERR(st->reg)) {
dev_err(&spi->dev, "Failed get get regulator \"vref\"\n"); dev_err(&spi->dev, "Failed get get regulator \"vref\"\n");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment