Commit 0e0a22ae authored by Marcelo Schmitt's avatar Marcelo Schmitt Committed by Jonathan Cameron

staging: iio: ad5933: use clock framework for clock reference

Add the option to specify the external clock (MCLK) using the clock
framework.
Also remove the old platform data structure.
Signed-off-by: default avatarMarcelo Schmitt <marcelo.schmitt1@gmail.com>
Signed-off-by: default avatarGabriel Capella <gabriel@capella.pro>
Co-developed-by: default avatarGabriel Capella <gabriel@capella.pro>
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent c9d07120
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include <linux/err.h> #include <linux/err.h>
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/clk.h>
#include <linux/iio/iio.h> #include <linux/iio/iio.h>
#include <linux/iio/sysfs.h> #include <linux/iio/sysfs.h>
...@@ -82,20 +83,10 @@ ...@@ -82,20 +83,10 @@
#define AD5933_POLL_TIME_ms 10 #define AD5933_POLL_TIME_ms 10
#define AD5933_INIT_EXCITATION_TIME_ms 100 #define AD5933_INIT_EXCITATION_TIME_ms 100
/**
* struct ad5933_platform_data - platform specific data
* @ext_clk_hz: the external clock frequency in Hz, if not set
* the driver uses the internal clock (16.776 MHz)
* @vref_mv: the external reference voltage in millivolt
*/
struct ad5933_platform_data {
unsigned long ext_clk_hz;
};
struct ad5933_state { struct ad5933_state {
struct i2c_client *client; struct i2c_client *client;
struct regulator *reg; struct regulator *reg;
struct clk *mclk;
struct delayed_work work; struct delayed_work work;
struct mutex lock; /* Protect sensor state */ struct mutex lock; /* Protect sensor state */
unsigned long mclk_hz; unsigned long mclk_hz;
...@@ -111,9 +102,6 @@ struct ad5933_state { ...@@ -111,9 +102,6 @@ struct ad5933_state {
unsigned int poll_time_jiffies; unsigned int poll_time_jiffies;
}; };
static struct ad5933_platform_data ad5933_default_pdata = {
};
#define AD5933_CHANNEL(_type, _extend_name, _info_mask_separate, _address, \ #define AD5933_CHANNEL(_type, _extend_name, _info_mask_separate, _address, \
_scan_index, _realbits) { \ _scan_index, _realbits) { \
.type = (_type), \ .type = (_type), \
...@@ -690,9 +678,9 @@ static int ad5933_probe(struct i2c_client *client, ...@@ -690,9 +678,9 @@ static int ad5933_probe(struct i2c_client *client,
const struct i2c_device_id *id) const struct i2c_device_id *id)
{ {
int ret; int ret;
struct ad5933_platform_data *pdata = dev_get_platdata(&client->dev);
struct ad5933_state *st; struct ad5933_state *st;
struct iio_dev *indio_dev; struct iio_dev *indio_dev;
unsigned long ext_clk_hz = 0;
indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*st)); indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*st));
if (!indio_dev) if (!indio_dev)
...@@ -704,9 +692,6 @@ static int ad5933_probe(struct i2c_client *client, ...@@ -704,9 +692,6 @@ static int ad5933_probe(struct i2c_client *client,
mutex_init(&st->lock); mutex_init(&st->lock);
if (!pdata)
pdata = &ad5933_default_pdata;
st->reg = devm_regulator_get(&client->dev, "vdd"); st->reg = devm_regulator_get(&client->dev, "vdd");
if (IS_ERR(st->reg)) if (IS_ERR(st->reg))
return PTR_ERR(st->reg); return PTR_ERR(st->reg);
...@@ -723,8 +708,21 @@ static int ad5933_probe(struct i2c_client *client, ...@@ -723,8 +708,21 @@ static int ad5933_probe(struct i2c_client *client,
st->vref_mv = ret / 1000; st->vref_mv = ret / 1000;
if (pdata->ext_clk_hz) { st->mclk = devm_clk_get(&client->dev, "mclk");
st->mclk_hz = pdata->ext_clk_hz; if (IS_ERR(st->mclk) && PTR_ERR(st->mclk) != -ENOENT) {
ret = PTR_ERR(st->mclk);
goto error_disable_reg;
}
if (!IS_ERR(st->mclk)) {
ret = clk_prepare_enable(st->mclk);
if (ret < 0)
goto error_disable_reg;
ext_clk_hz = clk_get_rate(st->mclk);
}
if (ext_clk_hz) {
st->mclk_hz = ext_clk_hz;
st->ctrl_lb = AD5933_CTRL_EXT_SYSCLK; st->ctrl_lb = AD5933_CTRL_EXT_SYSCLK;
} else { } else {
st->mclk_hz = AD5933_INT_OSC_FREQ_Hz; st->mclk_hz = AD5933_INT_OSC_FREQ_Hz;
...@@ -744,7 +742,7 @@ static int ad5933_probe(struct i2c_client *client, ...@@ -744,7 +742,7 @@ static int ad5933_probe(struct i2c_client *client,
ret = ad5933_register_ring_funcs_and_init(indio_dev); ret = ad5933_register_ring_funcs_and_init(indio_dev);
if (ret) if (ret)
goto error_disable_reg; goto error_disable_mclk;
ret = ad5933_setup(st); ret = ad5933_setup(st);
if (ret) if (ret)
...@@ -758,6 +756,8 @@ static int ad5933_probe(struct i2c_client *client, ...@@ -758,6 +756,8 @@ static int ad5933_probe(struct i2c_client *client,
error_unreg_ring: error_unreg_ring:
iio_kfifo_free(indio_dev->buffer); iio_kfifo_free(indio_dev->buffer);
error_disable_mclk:
clk_disable_unprepare(st->mclk);
error_disable_reg: error_disable_reg:
regulator_disable(st->reg); regulator_disable(st->reg);
...@@ -772,6 +772,7 @@ static int ad5933_remove(struct i2c_client *client) ...@@ -772,6 +772,7 @@ static int ad5933_remove(struct i2c_client *client)
iio_device_unregister(indio_dev); iio_device_unregister(indio_dev);
iio_kfifo_free(indio_dev->buffer); iio_kfifo_free(indio_dev->buffer);
regulator_disable(st->reg); regulator_disable(st->reg);
clk_disable_unprepare(st->mclk);
return 0; return 0;
} }
......
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