13 #include <linux/device.h>
14 #include <linux/kernel.h>
16 #include <linux/slab.h>
18 #include <linux/list.h>
19 #include <linux/module.h>
33 static int adxrs450_spi_read_reg_16(
struct iio_dev *indio_dev,
42 st->tx[1] = reg_address << 1;
49 ret = spi_write(st->
us, st->tx, 4);
51 dev_err(&st->
us->dev,
"problem while reading 16 bit register 0x%02x\n",
55 ret = spi_read(st->
us, st->
rx, 4);
57 dev_err(&st->
us->dev,
"problem while reading 16 bit register 0x%02x\n",
76 static int adxrs450_spi_write_reg_16(
struct iio_dev *indio_dev,
85 st->tx[1] = reg_address << 1 | val >> 15;
92 ret = spi_write(st->
us, st->tx, 4);
94 dev_err(&st->
us->dev,
"problem while writing 16 bit register 0x%02x\n",
106 static int adxrs450_spi_sensor_data(
struct iio_dev *indio_dev,
s16 *val)
117 ret = spi_write(st->
us, st->tx, 4);
119 dev_err(&st->
us->dev,
"Problem while reading sensor data\n");
123 ret = spi_read(st->
us, st->
rx, 4);
125 dev_err(&st->
us->dev,
"Problem while reading sensor data\n");
160 spi_message_init(&
msg);
161 spi_message_add_tail(&xfers, &
msg);
164 dev_err(&st->
us->dev,
"Problem while reading initializing data\n");
176 static int adxrs450_initial_setup(
struct iio_dev *indio_dev)
184 ret = adxrs450_spi_initial(st, &t, 1);
188 dev_warn(&st->
us->dev,
"The initial power on response "
189 "is not correct! Restart without reset?\n");
192 ret = adxrs450_spi_initial(st, &t, 0);
197 ret = adxrs450_spi_initial(st, &t, 0);
201 dev_err(&st->
us->dev,
"The second response is not correct!\n");
205 ret = adxrs450_spi_initial(st, &t, 0);
209 dev_err(&st->
us->dev,
"The third response is not correct!\n");
217 dev_err(&st->
us->dev,
"The device is not in normal status!\n");
220 ret = adxrs450_spi_read_reg_16(indio_dev,
ADXRS450_PID1, &data);
223 dev_info(&st->
us->dev,
"The Part ID is 0x%x\n", data);
225 ret = adxrs450_spi_read_reg_16(indio_dev,
ADXRS450_SNL, &data);
229 ret = adxrs450_spi_read_reg_16(indio_dev,
ADXRS450_SNH, &data);
233 dev_info(&st->
us->dev,
"The Serial Number is 0x%x\n", t);
238 static int adxrs450_write_raw(
struct iio_dev *indio_dev,
247 ret = adxrs450_spi_write_reg_16(indio_dev,
258 static int adxrs450_read_raw(
struct iio_dev *indio_dev,
269 switch (chan->
type) {
271 ret = adxrs450_spi_sensor_data(indio_dev, &t);
278 ret = adxrs450_spi_read_reg_16(indio_dev,
282 *val = (t >> 6) + 225;
291 switch (chan->
type) {
312 ret = adxrs450_spi_read_reg_16(indio_dev,
ADXRS450_DNC1, &t);
326 static const struct iio_chan_spec adxrs450_channels[2][2] = {
362 static const struct iio_info adxrs450_info = {
364 .read_raw = &adxrs450_read_raw,
365 .write_raw = &adxrs450_write_raw,
376 if (indio_dev ==
NULL) {
380 st = iio_priv(indio_dev);
384 spi_set_drvdata(spi, indio_dev);
386 indio_dev->
dev.parent = &spi->
dev;
387 indio_dev->
info = &adxrs450_info;
392 indio_dev->
name = spi->
dev.driver->name;
399 ret = adxrs450_initial_setup(indio_dev);
432 .probe = adxrs450_probe,
434 .id_table = adxrs450_id,