Commit 64335c4a authored by Andy Shevchenko's avatar Andy Shevchenko Committed by Jonathan Cameron

iio: adc: ti-ads1015: Make use of device property API

Make use of device property API in this driver so that both OF based
system and ACPI based system can use this driver.
Signed-off-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 0cd9ff15
...@@ -12,10 +12,10 @@ ...@@ -12,10 +12,10 @@
*/ */
#include <linux/module.h> #include <linux/module.h>
#include <linux/of_device.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/irq.h> #include <linux/irq.h>
#include <linux/i2c.h> #include <linux/i2c.h>
#include <linux/property.h>
#include <linux/regmap.h> #include <linux/regmap.h>
#include <linux/pm_runtime.h> #include <linux/pm_runtime.h>
#include <linux/mutex.h> #include <linux/mutex.h>
...@@ -77,6 +77,7 @@ ...@@ -77,6 +77,7 @@
#define ADS1015_DEFAULT_CHAN 0 #define ADS1015_DEFAULT_CHAN 0
enum chip_ids { enum chip_ids {
ADSXXXX = 0,
ADS1015, ADS1015,
ADS1115, ADS1115,
}; };
...@@ -843,65 +844,58 @@ static const struct iio_info ads1115_info = { ...@@ -843,65 +844,58 @@ static const struct iio_info ads1115_info = {
.attrs = &ads1115_attribute_group, .attrs = &ads1115_attribute_group,
}; };
#ifdef CONFIG_OF static int ads1015_client_get_channels_config(struct i2c_client *client)
static int ads1015_get_channels_config_of(struct i2c_client *client)
{ {
struct iio_dev *indio_dev = i2c_get_clientdata(client); struct iio_dev *indio_dev = i2c_get_clientdata(client);
struct ads1015_data *data = iio_priv(indio_dev); struct ads1015_data *data = iio_priv(indio_dev);
struct device_node *node; struct device *dev = &client->dev;
struct fwnode_handle *node;
int i = -1;
if (!client->dev.of_node || device_for_each_child_node(dev, node) {
!of_get_next_child(client->dev.of_node, NULL))
return -EINVAL;
for_each_child_of_node(client->dev.of_node, node) {
u32 pval; u32 pval;
unsigned int channel; unsigned int channel;
unsigned int pga = ADS1015_DEFAULT_PGA; unsigned int pga = ADS1015_DEFAULT_PGA;
unsigned int data_rate = ADS1015_DEFAULT_DATA_RATE; unsigned int data_rate = ADS1015_DEFAULT_DATA_RATE;
if (of_property_read_u32(node, "reg", &pval)) { if (fwnode_property_read_u32(node, "reg", &pval)) {
dev_err(&client->dev, "invalid reg on %pOF\n", dev_err(dev, "invalid reg on %pfw\n", node);
node);
continue; continue;
} }
channel = pval; channel = pval;
if (channel >= ADS1015_CHANNELS) { if (channel >= ADS1015_CHANNELS) {
dev_err(&client->dev, dev_err(dev, "invalid channel index %d on %pfw\n",
"invalid channel index %d on %pOF\n",
channel, node); channel, node);
continue; continue;
} }
if (!of_property_read_u32(node, "ti,gain", &pval)) { if (!fwnode_property_read_u32(node, "ti,gain", &pval)) {
pga = pval; pga = pval;
if (pga > 6) { if (pga > 6) {
dev_err(&client->dev, "invalid gain on %pOF\n", dev_err(dev, "invalid gain on %pfw\n", node);
node); fwnode_handle_put(node);
of_node_put(node);
return -EINVAL; return -EINVAL;
} }
} }
if (!of_property_read_u32(node, "ti,datarate", &pval)) { if (!fwnode_property_read_u32(node, "ti,datarate", &pval)) {
data_rate = pval; data_rate = pval;
if (data_rate > 7) { if (data_rate > 7) {
dev_err(&client->dev, dev_err(dev, "invalid data_rate on %pfw\n", node);
"invalid data_rate on %pOF\n", fwnode_handle_put(node);
node);
of_node_put(node);
return -EINVAL; return -EINVAL;
} }
} }
data->channel_data[channel].pga = pga; data->channel_data[channel].pga = pga;
data->channel_data[channel].data_rate = data_rate; data->channel_data[channel].data_rate = data_rate;
i++;
} }
return 0; return i < 0 ? -EINVAL : 0;
} }
#endif
static void ads1015_get_channels_config(struct i2c_client *client) static void ads1015_get_channels_config(struct i2c_client *client)
{ {
...@@ -910,10 +904,9 @@ static void ads1015_get_channels_config(struct i2c_client *client) ...@@ -910,10 +904,9 @@ static void ads1015_get_channels_config(struct i2c_client *client)
struct iio_dev *indio_dev = i2c_get_clientdata(client); struct iio_dev *indio_dev = i2c_get_clientdata(client);
struct ads1015_data *data = iio_priv(indio_dev); struct ads1015_data *data = iio_priv(indio_dev);
#ifdef CONFIG_OF if (!ads1015_client_get_channels_config(client))
if (!ads1015_get_channels_config_of(client))
return; return;
#endif
/* fallback on default configuration */ /* fallback on default configuration */
for (k = 0; k < ADS1015_CHANNELS; ++k) { for (k = 0; k < ADS1015_CHANNELS; ++k) {
data->channel_data[k].pga = ADS1015_DEFAULT_PGA; data->channel_data[k].pga = ADS1015_DEFAULT_PGA;
...@@ -951,9 +944,8 @@ static int ads1015_probe(struct i2c_client *client, ...@@ -951,9 +944,8 @@ static int ads1015_probe(struct i2c_client *client,
indio_dev->name = ADS1015_DRV_NAME; indio_dev->name = ADS1015_DRV_NAME;
indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->modes = INDIO_DIRECT_MODE;
if (client->dev.of_node) chip = (enum chip_ids)device_get_match_data(&client->dev);
chip = (enum chip_ids)of_device_get_match_data(&client->dev); if (chip == ADSXXXX)
else
chip = id->driver_data; chip = id->driver_data;
switch (chip) { switch (chip) {
case ADS1015: case ADS1015:
...@@ -968,6 +960,9 @@ static int ads1015_probe(struct i2c_client *client, ...@@ -968,6 +960,9 @@ static int ads1015_probe(struct i2c_client *client,
indio_dev->info = &ads1115_info; indio_dev->info = &ads1115_info;
data->data_rate = (unsigned int *) &ads1115_data_rate; data->data_rate = (unsigned int *) &ads1115_data_rate;
break; break;
default:
dev_err(&client->dev, "Unknown chip %d\n", chip);
return -EINVAL;
} }
data->event_channel = ADS1015_CHANNELS; data->event_channel = ADS1015_CHANNELS;
......
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