staging:iio:accel rework driver and move out of staging.
Subsystems (3)
Jonathan Cameron
maintainerv2 cover staging:iio:accel rework driver and move out of staging.
Changes since V1:
- Fix the patch that breaks the makefile due to a := when it should be += It didn't make it to the end of the set, but broke building of other drivers in the middle (thanks Lars-Peter Clausen)
- Drop the unwanted buffer setup after the move to the hybrid hardware / software buffer (Lars-Peter Clausen)
- Use chan->address rather than the modifier to index the address array. (Lars-Peter Clausen)
- Typo and gibberish fixups (Peter Meerwald-Stadhler)
V1 Message
This was around about the 4th IIO driver dating back to the days when I was sticking these on sprinters and seeing if we could learn anything useful about how they ran.
It was a device way ahead of it's time. Back then this was pretty much the only relatively high G / low cost sensor and it had a hardware fifo.
Anyhow, it has languished in staging primarily because of the complexity around working out how we handle hardware buffers. However, that trail has long since been blaized by the likes of the am335x driver and now lots of of newer devices are coming with fifos to smooth the flow of data between these realtime chips and non realtime operating sytems, so it just became a question of getting around to sorting it out. I suspect there are very few of these still out there, but I have an sca3000-e05 so that's no excuse
Anyhow, please review the whole series, but in particular the final move patch (i.e. the resulting code). The only odd corner I know of now is the interaction of the watermark with the software controlled watermarks. That may take some thought, but in the meantime I don't think that is sufficient reason to keep it in staging.
Some wacky corners in this hardware (like the crazy number representations for the motion detection thresholds). It's a good datasheet but you do have to wonder what the designers were thinking at times
Jonathan
p.s. The best bit about this series is now I can moan at everyone else about not cleaning up their staging drivers as this is the last one of mine.
Jonathan Cameron (18):
staging:iio:accel:sca3000 Fix a use before setting of the
indio_dev->buffer pointer.
staging:iio:accel:sca3000 merge files into one. staging:iio:accel:sca3000 drop sca3000_register_ring_funcs staging:iio:accel:sca3000 Fix clearing of flag + setting of size of
scan.
staging:iio:accel:sca3000 Drop custom ABI for watersheds. staging:iio:accel:sca3000 move to hybrid hard / soft buffer design. staging:iio:accel:sca3000 drop some unused variables. staging:iio:accel:sca3000 use a 'fake' channel to handle freefall
event registration.
staging:iio:accel:sca3000 Clean up register defines. staging:iio:accel:sca3000 add readback of the 3db low pass filter
frequency
staging:iio:accel:sca3000: Fix off by one error in axis due to
IIO_NO_MOD
staging:iio:accel:sca3000 Add write support to the low pass filter
control
staging:iio:accel:sca3000 Drop custom measurement mode attributes staging:iio:accel:sca3000 replace non standard revision attr with
dev_info on probe
staging:iio:accel:sca3000 Tidy up probe order to avoid a race. staging:iio:accel:sca3000 small checkpatch fixes (alignment etc) staging:iio:accel:sca3000 kernel docify comments that were nearly
kernel doc.
staging:iio:accel:sca3000 Move out of staging.
drivers/iio/accel/Kconfig | 12 + drivers/iio/accel/Makefile | 2 + drivers/iio/accel/sca3000.c | 1575 ++++++++++++++++++++++++++++++ drivers/staging/iio/accel/Kconfig | 10 - drivers/staging/iio/accel/Makefile | 3 - drivers/staging/iio/accel/sca3000.h | 279 ------ drivers/staging/iio/accel/sca3000_core.c | 1210 ----------------------- drivers/staging/iio/accel/sca3000_ring.c | 350 ------- drivers/staging/iio/ring_hw.h | 27 - 9 files changed, 1589 insertions(+), 1879 deletions(-) create mode 100644 drivers/iio/accel/sca3000.c delete mode 100644 drivers/staging/iio/accel/sca3000.h delete mode 100644 drivers/staging/iio/accel/sca3000_core.c delete mode 100644 drivers/staging/iio/accel/sca3000_ring.c delete mode 100644 drivers/staging/iio/ring_hw.h
Signature · 1 line
2.10.0
Jonathan Cameron
maintainerPATCH v2 1/18 staging:iio:accel:sca3000 Fix a use before setting of the indio_dev->buffer pointer.
--- drivers/staging/iio/accel/sca3000_ring.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/iio/accel/sca3000_ring.c +1 -1
@@ -270,8 +270,8 @@ int sca3000_configure_ring(struct iio_dev *indio_dev)return -ENOMEM ; indio_dev->modes |=INDIO_BUFFER_HARDWARE ; - indio_dev->buffer->access = &sca3000_ring_access_funcs; + buffer->access = &sca3000_ring_access_funcs;iio_device_attach_buffer (indio_dev, buffer);return 0 ;
Signature · 1 line
2.10.0
Jonathan Cameron
maintainerRe: [PATCH 01/18] staging:iio:accel:sca3000 Fix a use before setting of the indio_dev->buffer pointer.
Quoted 1 line · Jonathan Cameron
Signed-off-by Jonathan Cameron <[email protected]>
Applied to the togreg branch of iio.git and pushed out as testing for the autobuilders to play with it.
Jonathan
Quoted 19 lines
--- drivers/staging/iio/accel/sca3000_ring.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/staging/iio/accel/sca3000_ring.c +1
-1@@ -270,8 +270,8 @@ int sca3000_configure_ring(struct iio_dev *indio_dev)return -ENOMEM ; indio_dev->modes |=INDIO_BUFFER_HARDWARE ; - indio_dev->buffer->access = &sca3000_ring_access_funcs; + buffer->access = &sca3000_ring_access_funcs;iio_device_attach_buffer (indio_dev, buffer);return 0 ;
Jonathan Cameron
maintainerPATCH v2 2/18 staging:iio:accel:sca3000 merge files into one.
In reply to Jonathan CameronIn the early days of IIO we were much more inclined to keep the impact of the core IIO elements to the minimum. As time has moved on it has become clear that hardly any builds are done without buffer support and that it adds considerable complexity to the drivers.
Hence merge down the buffer and non buffer elements of the sca3000 driver also allowing us to drop the header file used for the interfaces between the two.
---
drivers/staging/iio/accel/Makefile | 1 -
.../iio/accel/{sca3000_core.c => sca3000.c} | 498 ++++++++++++++++++++-
drivers/staging/iio/accel/sca3000.h | 279 ------------
drivers/staging/iio/accel/sca3000_ring.c | 350 ---------------
4 files changed, 495 insertions(+), 633 deletions(-)drivers/staging/iio/accel/Makefile +0 -1
@@ -14,5 +14,4 @@ obj-$(CONFIG_ADIS16209) += adis16209.o adis16240-y := adis16240_core.o obj-$(CONFIG_ADIS16240) += adis16240.o -sca3000-y := sca3000_core.o sca3000_ring.o obj-$(CONFIG_SCA3000) += sca3000.o
drivers/staging/iio/accel/sca3000.c renamed from drivers/staging/iio/accel/sca3000_core.c +495 -3
533 lines not on this page · raw message
drivers/staging/iio/accel/sca3000.h deleted +0 -279
279 lines not on this page · raw message
drivers/staging/iio/accel/sca3000_ring.c deleted +0 -350
350 lines not on this page · raw message
Signature · 1 line
2.10.0
Jonathan Cameron
maintainerPATCH v2 3/18 staging:iio:accel:sca3000 drop sca3000_register_ring_funcs
In reply to Jonathan CameronThis was needed when the buffer support was optional. Pointless wrapper now so drop it.
--- drivers/staging/iio/accel/sca3000.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
drivers/staging/iio/accel/sca3000.c +1 -6
@@ -1504,11 +1504,6 @@ static const struct iio_buffer_setup_ops sca3000_ring_setup_ops = { .postdisable = &sca3000_hw_ring_postdisable, }; -static void sca3000_register_ring_funcs (struct iio_dev *indio_dev) -{ - indio_dev->setup_ops = &sca3000_ring_setup_ops; -} -/** * sca3000_clean_setup() get the device into a predictable state *
@@ -1631,7 +1626,7 @@ static int sca3000_probe(struct spi_device *spi)if (ret) goto error_unregister_dev; } -sca3000_register_ring_funcs (indio_dev); + indio_dev->setup_ops = &sca3000_ring_setup_ops; ret =sca3000_clean_setup (st);if (ret) goto error_free_irq;
Signature · 1 line
2.10.0
Jonathan Cameron
maintainerPATCH v2 4/18 staging:iio:accel:sca3000 Fix clearing of flag + setting of size of scan.
In reply to Jonathan CameronNot clearing the stuff_to_read flag can lead to a false flag being set on restarting the buffer if the data was not all read the previous time.
The size of the scan is needed to ensure the function iio_buffer_read_first_n_outer actually tries to read the data.
This stuff has been broken for some time so not stable material.
--- drivers/staging/iio/accel/sca3000.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
drivers/staging/iio/accel/sca3000.c +13 -0
@@ -1491,6 +1491,19 @@ error_ret:**/ static int sca3000_hw_ring_preenable (struct iio_dev *indio_dev) { +/* +* Set stuff to read to indicate no data present. +* Need for cases where the interrupt had fired at the +* end of a cycle, but the data was never read. +*/ + indio_dev->buffer->stufftoread =0 ; +/* +* Needed to ensure the core will actually read data +* from the device rather than assuming no channels +* are enabled. +*/ + indio_dev->buffer->bytes_per_datum =6 ; +return __sca3000_hw_ring_state_set (indio_dev,1 ); }
Signature · 1 line
2.10.0
Jonathan Cameron
maintainerPATCH v2 5/18 staging:iio:accel:sca3000 Drop custom ABI for watersheds.
In reply to Jonathan CameronFor now we support only the 50% watershed interrupt and start and stop it as part of the buffer bring up. The 75% case may come back in future.
--- drivers/staging/iio/accel/sca3000.c | 111 +++++++++++++----------------------- 1 file changed, 41 insertions(+), 70 deletions(-)
drivers/staging/iio/accel/sca3000.c +41 -70
@@ -1309,73 +1309,6 @@ static size_t sca3000_ring_buf_data_available(struct iio_buffer *r)return r->stufftoread ? r->watermark :0 ; } -/** -* sca3000_query_ring_int() is the hardware ring status interrupt enabled -**/ -static ssize_t sca3000_query_ring_int (struct device *dev, -struct device_attribute *attr, -char *buf) -{ -struct iio_dev_attr *this_attr =to_iio_dev_attr (attr); -int ret, val; -struct iio_dev *indio_dev =dev_to_iio_dev (dev); -struct sca3000_state *st =iio_priv (indio_dev); - -mutex_lock (&st->lock); - ret =sca3000_read_data_short (st,SCA3000_REG_ADDR_INT_MASK ,1 ); - val = st->rx[0 ]; -mutex_unlock (&st->lock); -if (ret) -return ret; - -return sprintf (buf,"%d\n" , !!(val & this_attr->address)); -} - -/** -* sca3000_set_ring_int() set state of ring status interrupt -**/ -static ssize_t sca3000_set_ring_int (struct device *dev, -struct device_attribute *attr, -const char *buf, -size_t len) -{ -struct iio_dev *indio_dev =dev_to_iio_dev (dev); -struct sca3000_state *st =iio_priv (indio_dev); -struct iio_dev_attr *this_attr =to_iio_dev_attr (attr); -u8 val; -int ret; - -mutex_lock (&st->lock); - ret =kstrtou8 (buf,10 , &val); -if (ret) - goto error_ret; - ret =sca3000_read_data_short (st,SCA3000_REG_ADDR_INT_MASK ,1 ); -if (ret) - goto error_ret; -if (val) - ret =sca3000_write_reg (st, -SCA3000_REG_ADDR_INT_MASK , - st->rx[0 ] | this_attr->address); -else - ret =sca3000_write_reg (st, -SCA3000_REG_ADDR_INT_MASK , - st->rx[0 ] & ~this_attr->address); -error_ret: -mutex_unlock (&st->lock); - -return ret ? ret : len; -} - -static IIO_DEVICE_ATTR(50_percent, S_IRUGO | S_IWUSR, - sca3000_query_ring_int, - sca3000_set_ring_int, - SCA3000_INT_MASK_RING_HALF); - -static IIO_DEVICE_ATTR(75_percent, S_IRUGO | S_IWUSR, - sca3000_query_ring_int, - sca3000_set_ring_int, - SCA3000_INT_MASK_RING_THREE_QUARTER); -static ssize_t sca3000_show_buffer_scale (struct device *dev,struct device_attribute *attr,char *buf)
@@ -1399,8 +1332,6 @@ static IIO_DEVICE_ATTR(in_accel_scale,* is available via direct reading from registers. */ static const struct attribute *sca3000_ring_attributes[] = { - &iio_dev_attr_50_percent.dev_attr.attr, - &iio_dev_attr_75_percent.dev_attr.attr, &iio_dev_attr_in_accel_scale.dev_attr.attr,NULL , };
@@ -1491,6 +1422,9 @@ error_ret:**/ static int sca3000_hw_ring_preenable (struct iio_dev *indio_dev) { +int ret; +struct sca3000_state *st =iio_priv (indio_dev); +/* * Set stuff to read to indicate no data present. * Need for cases where the interrupt had fired at the
@@ -1504,12 +1438,49 @@ static int sca3000_hw_ring_preenable(struct iio_dev *indio_dev)*/ indio_dev->buffer->bytes_per_datum =6 ; +mutex_lock (&st->lock); + +/* Enable the 50% full interrupt */ + ret =sca3000_read_data_short (st,SCA3000_REG_ADDR_INT_MASK ,1 ); +if (ret) + goto error_unlock; + ret =sca3000_write_reg (st, +SCA3000_REG_ADDR_INT_MASK , + st->rx[0 ] |SCA3000_INT_MASK_RING_HALF ); +if (ret) + goto error_unlock; + +mutex_unlock (&st->lock); +return __sca3000_hw_ring_state_set (indio_dev,1 ); + +error_unlock: +mutex_unlock (&st->lock); + +return ret; }static int sca3000_hw_ring_postdisable (struct iio_dev *indio_dev) { -return __sca3000_hw_ring_state_set (indio_dev,0 ); +int ret; +struct sca3000_state *st =iio_priv (indio_dev); + + ret =__sca3000_hw_ring_state_set (indio_dev,0 ); +if (ret) +return ret; + +/* Disable the 50% full interrupt */ +mutex_lock (&st->lock); + + ret =sca3000_read_data_short (st,SCA3000_REG_ADDR_INT_MASK ,1 ); +if (ret) + goto unlock; + ret =sca3000_write_reg (st, +SCA3000_REG_ADDR_INT_MASK , + st->rx[0 ] & ~SCA3000_INT_MASK_RING_HALF ); +unlock: +mutex_unlock (&st->lock); +return ret; }static const struct iio_buffer_setup_ops sca3000_ring_setup_ops = {
Signature · 1 line
2.10.0
Jonathan Cameron
maintainerPATCH v2 6/18 staging:iio:accel:sca3000 move to hybrid hard / soft buffer design.
In reply to Jonathan CameronIn a similar fashion to other newer drivers (e.g. ti_am335x), instead of using the hardware buffer support in IIO to directly access the hardware fifo, insert a software fifo and feed that from the hardware one when interrupts occur. This gives a simpler structure to the data flows and allows more flexibility over how often data is shipped to userspace etc.
This was also the only direct user of the simplistic generalization found in ring_hw.h so that header is removed.
--- drivers/staging/iio/accel/Kconfig | 3 +- drivers/staging/iio/accel/sca3000.c | 256 ++++++++++-------------------------- drivers/staging/iio/ring_hw.h | 27 ---- 3 files changed, 72 insertions(+), 214 deletions(-)
drivers/staging/iio/accel/Kconfig +2 -1
@@ -52,7 +52,8 @@ config ADIS16240 called adis16240. config SCA3000 - depends on IIO_BUFFER + select IIO_BUFFER + select IIO_KFIFO_BUF depends on SPI tristate "VTI SCA3000 series accelerometers" help
drivers/staging/iio/accel/sca3000.c +70 -186
327 lines not on this page · raw message
drivers/staging/iio/ring_hw.h deleted +0 -27
@@ -1,27 +0,0 @@ -/* -* ring_hw.h - common functionality for iio hardware ring buffers -* -* This program is free software; you can redistribute it and/or modify it -* under the terms of the GNU General Public License version 2 as published by -* the Free Software Foundation. -* -* Copyright (c) 2009 Jonathan Cameron <[email protected]> -* -*/ - -#ifndef _RING_HW_H_ -#define _RING_HW_H_ - -/** -* struct iio_hw_ring_buffer- hardware ring buffer -* @buf: generic ring buffer elements -* @private: device specific data -*/ -struct iio_hw_buffer { -struct iio_buffer buf; -void *private; -}; - -#define iio_to_hw_buf (r) container_of(r, struct iio_hw_buffer, buf) - -#endif /* _RING_HW_H_ */
Signature · 1 line
2.10.0
Jonathan Cameron
maintainerPATCH v2 7/18 staging:iio:accel:sca3000 drop some unused variables.
In reply to Jonathan Cameron--- drivers/staging/iio/accel/sca3000.c | 5 ----- 1 file changed, 5 deletions(-)
drivers/staging/iio/accel/sca3000.c +0 -5
@@ -155,23 +155,19 @@* struct sca3000_state - device instance state information * @us: the associated spi device * @info: chip variant information -* @interrupt_handler_ws: event interrupt handler for all events * @last_timestamp: the timestamp of the last event * @mo_det_use_count: reference counter for the motion detection unit * @lock: lock used to protect elements of sca3000_state * and the underlying device state. -* @bpse: number of bits per scan element * @tx: dma-able transmit buffer * @rx: dma-able receive buffer **/ struct sca3000_state {struct spi_device *us;const struct sca3000_chip_info *info; -struct work_struct interrupt_handler_ws;s64 last_timestamp;int mo_det_use_count;struct mutex lock; -int bpse;/* Can these share a cacheline ? */ u8 rx[384 ]____cacheline_aligned ;u8 tx[6 ]____cacheline_aligned ;
@@ -1430,7 +1426,6 @@ static int sca3000_clean_setup(struct sca3000_state *st) goto error_ret; ret =sca3000_write_reg (st,SCA3000_REG_ADDR_MODE , (st->rx[0 ] &SCA3000_MODE_PROT_MASK )); - st->bpse =11 ; error_ret:mutex_unlock (&st->lock);
Signature · 1 line
2.10.0
Jonathan Cameron
maintainerPATCH v2 8/18 staging:iio:accel:sca3000 use a 'fake' channel to handle freefall event registration.
In reply to Jonathan CameronThis is an approach used in some newer drivers as it exposes the compound channel events to the core rather than hiding their control in sysfs attributes entirely via the driver.
--- drivers/staging/iio/accel/sca3000.c | 302 ++++++++++++++++++------------------ 1 file changed, 154 insertions(+), 148 deletions(-)
drivers/staging/iio/accel/sca3000.c +154 -148
@@ -593,10 +593,25 @@ static const struct iio_event_spec sca3000_event = { .num_event_specs = 1, \ } +static const struct iio_event_spec sca3000_freefall_event_spec = { + .type =IIO_EV_TYPE_MAG , + .dir =IIO_EV_DIR_FALLING , + .mask_separate =BIT (IIO_EV_INFO_ENABLE ) | +BIT (IIO_EV_INFO_PERIOD ), +}; +static const struct iio_chan_spec sca3000_channels[] = {SCA3000_CHAN (0 ,IIO_MOD_X ),SCA3000_CHAN (1 ,IIO_MOD_Y ),SCA3000_CHAN (2 ,IIO_MOD_Z ), + { + .type =IIO_ACCEL , + .modified =1 , + .channel2 =IIO_MOD_X_AND_Y_AND_Z , + .scan_index =-1 ,/* Fake channel */ + .event_spec = &sca3000_freefall_event_spec, + .num_event_specs =1 , + }, };static const struct iio_chan_spec sca3000_channels_with_temp[] = {
@@ -611,6 +626,14 @@ static const struct iio_chan_spec sca3000_channels_with_temp[] = {/* No buffer support */ .scan_index = -1, }, + { + .type = IIO_ACCEL, + .modified = 1, + .channel2 = IIO_MOD_X_AND_Y_AND_Z, + .scan_index = -1, /* Fake channel */ + .event_spec = &sca3000_freefall_event_spec, + .num_event_specs = 1, + }, };static u8 sca3000_addresses[3 ][3 ] = {
@@ -854,46 +877,54 @@ error_ret:static IIO_DEV_ATTR_SAMP_FREQ_AVAIL (sca3000_read_av_freq);/** -* sca3000_read_thresh() - query of a threshold +* sca3000_read_event_value() - query of a threshold or period **/ -static int sca3000_read_thresh (struct iio_dev *indio_dev, -const struct iio_chan_spec *chan, -enum iio_event_type type, -enum iio_event_direction dir, -enum iio_event_info info, -int *val,int *val2) +static int sca3000_read_event_value (struct iio_dev *indio_dev, +const struct iio_chan_spec *chan, +enum iio_event_type type, +enum iio_event_direction dir, +enum iio_event_info info, +int *val,int *val2) {int ret, i;struct sca3000_state *st =iio_priv (indio_dev);int num = chan->channel2; +switch (info) { +case IIO_EV_INFO_VALUE : +mutex_lock (&st->lock); + ret =sca3000_read_ctrl_reg (st, sca3000_addresses[num][1 ]); +mutex_unlock (&st->lock); +if (ret <0 ) +return ret; + *val =0 ; +if (num ==1 ) +for_each_set_bit (i, (unsigned long *)&ret, +ARRAY_SIZE (st->info->mot_det_mult_y)) + *val += st->info->mot_det_mult_y[i]; +else +for_each_set_bit (i, (unsigned long *)&ret, +ARRAY_SIZE (st->info->mot_det_mult_xz)) + *val += st->info->mot_det_mult_xz[i]; -mutex_lock (&st->lock); - ret =sca3000_read_ctrl_reg (st, sca3000_addresses[num][1 ]); -mutex_unlock (&st->lock); -if (ret <0 ) -return ret; - *val =0 ; -if (num ==1 ) -for_each_set_bit (i, (unsigned long *)&ret, -ARRAY_SIZE (st->info->mot_det_mult_y)) - *val += st->info->mot_det_mult_y[i]; -else -for_each_set_bit (i, (unsigned long *)&ret, -ARRAY_SIZE (st->info->mot_det_mult_xz)) - *val += st->info->mot_det_mult_xz[i]; - -return IIO_VAL_INT ; +return IIO_VAL_INT ; +case IIO_EV_INFO_PERIOD : + *val =0 ; + *val2 =226000 ; +return IIO_VAL_INT_PLUS_MICRO ; +default : +return -EINVAL ; + } }/** -* sca3000_write_thresh() control of threshold +* sca3000_write_value() control of threshold and period **/ -static int sca3000_write_thresh (struct iio_dev *indio_dev, -const struct iio_chan_spec *chan, -enum iio_event_type type, -enum iio_event_direction dir, -enum iio_event_info info, -int val,int val2) +static int sca3000_write_event_value (struct iio_dev *indio_dev, +const struct iio_chan_spec *chan, +enum iio_event_type type, +enum iio_event_direction dir, +enum iio_event_info info, +int val,int val2) {struct sca3000_state *st =iio_priv (indio_dev);int num = chan->channel2;
@@ -901,7 +932,7 @@ static int sca3000_write_thresh(struct iio_dev *indio_dev,int i;u8 nonlinear =0 ; -if (num ==1 ) { +if (num ==IIO_MOD_Y ) { i =ARRAY_SIZE (st->info->mot_det_mult_y);while (i >0 )if (val >= st->info->mot_det_mult_y[--i]) {
@@ -1088,180 +1119,156 @@ static int sca3000_read_event_config(struct iio_dev *indio_dev,/* read current value of mode register */ mutex_lock (&st->lock); + ret =sca3000_read_data_short (st,SCA3000_REG_ADDR_MODE ,1 );if (ret) goto error_ret; -if ((st->rx[0 ] & protect_mask) !=SCA3000_MEAS_MODE_MOT_DET ) { - ret =0 ; - }else { - ret =sca3000_read_ctrl_reg (st,SCA3000_REG_CTRL_SEL_MD_CTRL ); -if (ret <0 ) - goto error_ret; -/* only supporting logical or's for now */ - ret = !!(ret & sca3000_addresses[num][2 ]); +switch (chan->channel2) { +case IIO_MOD_X_AND_Y_AND_Z : + ret = !!(st->rx[0 ] &SCA3000_FREE_FALL_DETECT ); +break ; +case IIO_MOD_X : +case IIO_MOD_Y : +case IIO_MOD_Z : +/* +* Motion detection mode cannot run at the same time as +* acceleration data being read. +*/ +if ((st->rx[0 ] & protect_mask) !=SCA3000_MEAS_MODE_MOT_DET ) { + ret =0 ; + }else { + ret =sca3000_read_ctrl_reg (st, +SCA3000_REG_CTRL_SEL_MD_CTRL ); +if (ret <0 ) + goto error_ret; +/* only supporting logical or's for now */ + ret = !!(ret & sca3000_addresses[num][2 ]); + } +break ; +default : + ret = -EINVAL ; } + error_ret:mutex_unlock (&st->lock);return ret; } -/** -* sca3000_query_free_fall_mode() is free fall mode enabled -**/ -static ssize_t sca3000_query_free_fall_mode (struct device *dev, -struct device_attribute *attr, -char *buf) +static int sca3000_freefall_set_state (struct iio_dev *indio_dev,int state) { -int ret; -struct iio_dev *indio_dev =dev_to_iio_dev (dev);struct sca3000_state *st =iio_priv (indio_dev); -int val; - -mutex_lock (&st->lock); - ret =sca3000_read_data_short (st,SCA3000_REG_ADDR_MODE ,1 ); - val = st->rx[0 ]; -mutex_unlock (&st->lock); -if (ret <0 ) -return ret; -return sprintf (buf,"%d\n" , !!(val &SCA3000_FREE_FALL_DETECT )); -} - -/** -* sca3000_set_free_fall_mode() simple on off control for free fall int -* -* In these chips the free fall detector should send an interrupt if -* the device falls more than 25cm. This has not been tested due -* to fragile wiring. -**/ -static ssize_t sca3000_set_free_fall_mode (struct device *dev, -struct device_attribute *attr, -const char *buf, -size_t len) -{ -struct iio_dev *indio_dev =dev_to_iio_dev (dev); -struct sca3000_state *st =iio_priv (indio_dev); -u8 val;int ret; -u8 protect_mask =SCA3000_FREE_FALL_DETECT ; - -mutex_lock (&st->lock); - ret =kstrtou8 (buf,10 , &val); -if (ret) - goto error_ret;/* read current value of mode register */ ret =sca3000_read_data_short (st,SCA3000_REG_ADDR_MODE ,1 );if (ret) - goto error_ret; +return ret;/* if off and should be on */ -if (val && !(st->rx[0 ] & protect_mask)) - ret =sca3000_write_reg (st,SCA3000_REG_ADDR_MODE , - (st->rx[0 ] |SCA3000_FREE_FALL_DETECT )); +if (state && !(st->rx[0 ] &SCA3000_FREE_FALL_DETECT )) +return sca3000_write_reg (st,SCA3000_REG_ADDR_MODE , + st->rx[0 ] |SCA3000_FREE_FALL_DETECT );/* if on and should be off */ -else if (!val && (st->rx[0 ] & protect_mask)) - ret =sca3000_write_reg (st,SCA3000_REG_ADDR_MODE , - (st->rx[0 ] & ~protect_mask)); -error_ret: -mutex_unlock (&st->lock); - -return ret ? ret : len; +else if (!state && (st->rx[0 ] &SCA3000_FREE_FALL_DETECT )) +return sca3000_write_reg (st,SCA3000_REG_ADDR_MODE , + st->rx[0 ] & ~SCA3000_FREE_FALL_DETECT ); +else +return 0 ; } -/** -* sca3000_write_event_config() simple on off control for motion detector -* -* This is a per axis control, but enabling any will result in the -* motion detector unit being enabled. -* N.B. enabling motion detector stops normal data acquisition. -* There is a complexity in knowing which mode to return to when -* this mode is disabled. Currently normal mode is assumed. -**/ -static int sca3000_write_event_config (struct iio_dev *indio_dev, -const struct iio_chan_spec *chan, -enum iio_event_type type, -enum iio_event_direction dir, -int state) +static int sca3000_motion_detect_set_state (struct iio_dev *indio_dev,int axis, +int state) {struct sca3000_state *st =iio_priv (indio_dev);int ret, ctrlval; -u8 protect_mask =0x03 ; -int num = chan->channel2; -mutex_lock (&st->lock);/* * First read the motion detector config to find out if * this axis is on */ ret =sca3000_read_ctrl_reg (st,SCA3000_REG_CTRL_SEL_MD_CTRL );if (ret <0 ) - goto exit_point; +return ret; ctrlval = ret;/* if off and should be on */ -if (state && !(ctrlval & sca3000_addresses[num][2 ])) { +if (state && !(ctrlval & sca3000_addresses[axis][2 ])) { ret =sca3000_write_ctrl_reg (st,SCA3000_REG_CTRL_SEL_MD_CTRL , ctrlval | - sca3000_addresses[num][2 ]); + sca3000_addresses[axis][2 ]);if (ret) - goto exit_point; +return ret; st->mo_det_use_count++; - }else if (!state && (ctrlval & sca3000_addresses[num][2 ])) { + }else if (!state && (ctrlval & sca3000_addresses[axis][2 ])) { ret =sca3000_write_ctrl_reg (st,SCA3000_REG_CTRL_SEL_MD_CTRL , ctrlval & - ~(sca3000_addresses[num][2 ])); + ~(sca3000_addresses[axis][2 ]));if (ret) - goto exit_point; +return ret; st->mo_det_use_count--; }/* read current value of mode register */ ret =sca3000_read_data_short (st,SCA3000_REG_ADDR_MODE ,1 );if (ret) - goto exit_point; +return ret;/* if off and should be on */ if ((st->mo_det_use_count) && - ((st->rx[0 ] & protect_mask) !=SCA3000_MEAS_MODE_MOT_DET )) - ret =sca3000_write_reg (st,SCA3000_REG_ADDR_MODE , - (st->rx[0 ] & ~protect_mask) + ((st->rx[0 ] &SCA3000_MODE_MASK ) !=SCA3000_MEAS_MODE_MOT_DET )) +return sca3000_write_reg (st,SCA3000_REG_ADDR_MODE , + (st->rx[0 ] & ~SCA3000_MODE_MASK ) |SCA3000_MEAS_MODE_MOT_DET );/* if on and should be off */ else if (!(st->mo_det_use_count) && - ((st->rx[0 ] & protect_mask) ==SCA3000_MEAS_MODE_MOT_DET )) - ret =sca3000_write_reg (st,SCA3000_REG_ADDR_MODE , - (st->rx[0 ] & ~protect_mask)); -exit_point: + ((st->rx[0 ] &SCA3000_MODE_MASK ) ==SCA3000_MEAS_MODE_MOT_DET )) +return sca3000_write_reg (st,SCA3000_REG_ADDR_MODE , + st->rx[0 ] &SCA3000_MODE_MASK ); +else +return 0 ; +} + +/** +* sca3000_write_event_config() simple on off control for motion detector +* +* This is a per axis control, but enabling any will result in the +* motion detector unit being enabled. +* N.B. enabling motion detector stops normal data acquisition. +* There is a complexity in knowing which mode to return to when +* this mode is disabled. Currently normal mode is assumed. +**/ +static int sca3000_write_event_config (struct iio_dev *indio_dev, +const struct iio_chan_spec *chan, +enum iio_event_type type, +enum iio_event_direction dir, +int state) +{ +struct sca3000_state *st =iio_priv (indio_dev); +int ret; + +mutex_lock (&st->lock); +switch (chan->channel2) { +case IIO_MOD_X_AND_Y_AND_Z : + ret =sca3000_freefall_set_state (indio_dev, state); +break ; + +case IIO_MOD_X : +case IIO_MOD_Y : +case IIO_MOD_Z : + ret =sca3000_motion_detect_set_state (indio_dev, chan->channel2, + state); +break ; +default : + ret = -EINVAL ; +break ; + }mutex_unlock (&st->lock);return ret; } -/* Free fall detector related event attribute */ -static IIO_DEVICE_ATTR_NAMED(accel_xayaz_mag_falling_en, - in_accel_x & y & z_mag_falling_en, -S_IRUGO |S_IWUSR , - sca3000_query_free_fall_mode, - sca3000_set_free_fall_mode, - 0); - -static IIO_CONST_ATTR_NAMED(accel_xayaz_mag_falling_period, - in_accel_x & y & z_mag_falling_period, - "0.226"); - -static struct attribute *sca3000_event_attributes[] = { - &iio_dev_attr_accel_xayaz_mag_falling_en.dev_attr.attr, - &iio_const_attr_accel_xayaz_mag_falling_period.dev_attr.attr, -NULL , -}; - -static struct attribute_group sca3000_event_attribute_group = { - .attrs = sca3000_event_attributes, - .name ="events" , -}; -static int sca3000_configure_ring (struct iio_dev *indio_dev) {struct iio_buffer *buffer;
@@ -1436,9 +1443,8 @@ static const struct iio_info sca3000_info = { .attrs = &sca3000_attribute_group, .read_raw = &sca3000_read_raw, .write_raw = &sca3000_write_raw, - .event_attrs = &sca3000_event_attribute_group, - .read_event_value = &sca3000_read_thresh, - .write_event_value = &sca3000_write_thresh, + .read_event_value = &sca3000_read_event_value, + .write_event_value = &sca3000_write_event_value, .read_event_config = &sca3000_read_event_config, .write_event_config = &sca3000_write_event_config, .driver_module = THIS_MODULE,
Signature · 1 line
2.10.0
Jonathan Cameron
maintainerRe: [PATCH 08/18] staging:iio:accel:sca3000 use a 'fake' channel to handle freefall event registration.
Quoted 5 lines · Jonathan Cameron
This is an approach used in some newer drivers as it exposes the compound channel events to the core rather than hiding their control in sysfs attributes entirely via the driver.
Signed-off-by Jonathan Cameron <[email protected]>
oops. the sca3000_mode_mask (which gets replaced in the next patch). doesn't actually exist.
I've added it during the apply and will take it out when applying the next patch so that bisection works fine across this one.
Applied with that tweak.
Jonathan
Quoted 427 lines
--- drivers/staging/iio/accel/sca3000.c | 302 ++++++++++++++++++------------------ 1 file changed, 154 insertions(+), 148 deletions(-)drivers/staging/iio/accel/sca3000.c +154
-148@@ -593,10 +593,25 @@ static const struct iio_event_spec sca3000_event = { .num_event_specs = 1, \ } +static const struct iio_event_spec sca3000_freefall_event_spec = { + .type =IIO_EV_TYPE_MAG , + .dir =IIO_EV_DIR_FALLING , + .mask_separate =BIT (IIO_EV_INFO_ENABLE ) | +BIT (IIO_EV_INFO_PERIOD ), +}; +static const struct iio_chan_spec sca3000_channels[] = {SCA3000_CHAN (0 ,IIO_MOD_X ),SCA3000_CHAN (1 ,IIO_MOD_Y ),SCA3000_CHAN (2 ,IIO_MOD_Z ), + { + .type =IIO_ACCEL , + .modified =1 , + .channel2 =IIO_MOD_X_AND_Y_AND_Z , + .scan_index =-1 ,/* Fake channel */ + .event_spec = &sca3000_freefall_event_spec, + .num_event_specs =1 , + }, };static const struct iio_chan_spec sca3000_channels_with_temp[] = {@@ -611,6 +626,14 @@ static const struct iio_chan_spec sca3000_channels_with_temp[] = {/* No buffer support */ .scan_index = -1, }, + { + .type = IIO_ACCEL, + .modified = 1, + .channel2 = IIO_MOD_X_AND_Y_AND_Z, + .scan_index = -1, /* Fake channel */ + .event_spec = &sca3000_freefall_event_spec, + .num_event_specs = 1, + }, };static u8 sca3000_addresses[3 ][3 ] = {@@ -854,46 +877,54 @@ error_ret:static IIO_DEV_ATTR_SAMP_FREQ_AVAIL (sca3000_read_av_freq);/** -* sca3000_read_thresh() - query of a threshold +* sca3000_read_event_value() - query of a threshold or period **/ -static int sca3000_read_thresh (struct iio_dev *indio_dev, -const struct iio_chan_spec *chan, -enum iio_event_type type, -enum iio_event_direction dir, -enum iio_event_info info, -int *val,int *val2) +static int sca3000_read_event_value (struct iio_dev *indio_dev, +const struct iio_chan_spec *chan, +enum iio_event_type type, +enum iio_event_direction dir, +enum iio_event_info info, +int *val,int *val2) {int ret, i;struct sca3000_state *st =iio_priv (indio_dev);int num = chan->channel2; +switch (info) { +case IIO_EV_INFO_VALUE : +mutex_lock (&st->lock); + ret =sca3000_read_ctrl_reg (st, sca3000_addresses[num][1 ]); +mutex_unlock (&st->lock); +if (ret <0 ) +return ret; + *val =0 ; +if (num ==1 ) +for_each_set_bit (i, (unsigned long *)&ret, +ARRAY_SIZE (st->info->mot_det_mult_y)) + *val += st->info->mot_det_mult_y[i]; +else +for_each_set_bit (i, (unsigned long *)&ret, +ARRAY_SIZE (st->info->mot_det_mult_xz)) + *val += st->info->mot_det_mult_xz[i]; -mutex_lock (&st->lock); - ret =sca3000_read_ctrl_reg (st, sca3000_addresses[num][1 ]); -mutex_unlock (&st->lock); -if (ret <0 ) -return ret; - *val =0 ; -if (num ==1 ) -for_each_set_bit (i, (unsigned long *)&ret, -ARRAY_SIZE (st->info->mot_det_mult_y)) - *val += st->info->mot_det_mult_y[i]; -else -for_each_set_bit (i, (unsigned long *)&ret, -ARRAY_SIZE (st->info->mot_det_mult_xz)) - *val += st->info->mot_det_mult_xz[i]; - -return IIO_VAL_INT ; +return IIO_VAL_INT ; +case IIO_EV_INFO_PERIOD : + *val =0 ; + *val2 =226000 ; +return IIO_VAL_INT_PLUS_MICRO ; +default : +return -EINVAL ; + } }/** -* sca3000_write_thresh() control of threshold +* sca3000_write_value() control of threshold and period **/ -static int sca3000_write_thresh (struct iio_dev *indio_dev, -const struct iio_chan_spec *chan, -enum iio_event_type type, -enum iio_event_direction dir, -enum iio_event_info info, -int val,int val2) +static int sca3000_write_event_value (struct iio_dev *indio_dev, +const struct iio_chan_spec *chan, +enum iio_event_type type, +enum iio_event_direction dir, +enum iio_event_info info, +int val,int val2) {struct sca3000_state *st =iio_priv (indio_dev);int num = chan->channel2;@@ -901,7 +932,7 @@ static int sca3000_write_thresh(struct iio_dev *indio_dev,int i;u8 nonlinear =0 ; -if (num ==1 ) { +if (num ==IIO_MOD_Y ) { i =ARRAY_SIZE (st->info->mot_det_mult_y);while (i >0 )if (val >= st->info->mot_det_mult_y[--i]) {@@ -1088,180 +1119,156 @@ static int sca3000_read_event_config(struct iio_dev *indio_dev,/* read current value of mode register */ mutex_lock (&st->lock); + ret =sca3000_read_data_short (st,SCA3000_REG_ADDR_MODE ,1 );if (ret) goto error_ret; -if ((st->rx[0 ] & protect_mask) !=SCA3000_MEAS_MODE_MOT_DET ) { - ret =0 ; - }else { - ret =sca3000_read_ctrl_reg (st,SCA3000_REG_CTRL_SEL_MD_CTRL ); -if (ret <0 ) - goto error_ret; -/* only supporting logical or's for now */ - ret = !!(ret & sca3000_addresses[num][2 ]); +switch (chan->channel2) { +case IIO_MOD_X_AND_Y_AND_Z : + ret = !!(st->rx[0 ] &SCA3000_FREE_FALL_DETECT ); +break ; +case IIO_MOD_X : +case IIO_MOD_Y : +case IIO_MOD_Z : +/* +* Motion detection mode cannot run at the same time as +* acceleration data being read. +*/ +if ((st->rx[0 ] & protect_mask) !=SCA3000_MEAS_MODE_MOT_DET ) { + ret =0 ; + }else { + ret =sca3000_read_ctrl_reg (st, +SCA3000_REG_CTRL_SEL_MD_CTRL ); +if (ret <0 ) + goto error_ret; +/* only supporting logical or's for now */ + ret = !!(ret & sca3000_addresses[num][2 ]); + } +break ; +default : + ret = -EINVAL ; } + error_ret:mutex_unlock (&st->lock);return ret; } -/** -* sca3000_query_free_fall_mode() is free fall mode enabled -**/ -static ssize_t sca3000_query_free_fall_mode (struct device *dev, -struct device_attribute *attr, -char *buf) +static int sca3000_freefall_set_state (struct iio_dev *indio_dev,int state) { -int ret; -struct iio_dev *indio_dev =dev_to_iio_dev (dev);struct sca3000_state *st =iio_priv (indio_dev); -int val; - -mutex_lock (&st->lock); - ret =sca3000_read_data_short (st,SCA3000_REG_ADDR_MODE ,1 ); - val = st->rx[0 ]; -mutex_unlock (&st->lock); -if (ret <0 ) -return ret; -return sprintf (buf,"%d\n" , !!(val &SCA3000_FREE_FALL_DETECT )); -} - -/** -* sca3000_set_free_fall_mode() simple on off control for free fall int -* -* In these chips the free fall detector should send an interrupt if -* the device falls more than 25cm. This has not been tested due -* to fragile wiring. -**/ -static ssize_t sca3000_set_free_fall_mode (struct device *dev, -struct device_attribute *attr, -const char *buf, -size_t len) -{ -struct iio_dev *indio_dev =dev_to_iio_dev (dev); -struct sca3000_state *st =iio_priv (indio_dev); -u8 val;int ret; -u8 protect_mask =SCA3000_FREE_FALL_DETECT ; - -mutex_lock (&st->lock); - ret =kstrtou8 (buf,10 , &val); -if (ret) - goto error_ret;/* read current value of mode register */ ret =sca3000_read_data_short (st,SCA3000_REG_ADDR_MODE ,1 );if (ret) - goto error_ret; +return ret;/* if off and should be on */ -if (val && !(st->rx[0 ] & protect_mask)) - ret =sca3000_write_reg (st,SCA3000_REG_ADDR_MODE , - (st->rx[0 ] |SCA3000_FREE_FALL_DETECT )); +if (state && !(st->rx[0 ] &SCA3000_FREE_FALL_DETECT )) +return sca3000_write_reg (st,SCA3000_REG_ADDR_MODE , + st->rx[0 ] |SCA3000_FREE_FALL_DETECT );/* if on and should be off */ -else if (!val && (st->rx[0 ] & protect_mask)) - ret =sca3000_write_reg (st,SCA3000_REG_ADDR_MODE , - (st->rx[0 ] & ~protect_mask)); -error_ret: -mutex_unlock (&st->lock); - -return ret ? ret : len; +else if (!state && (st->rx[0 ] &SCA3000_FREE_FALL_DETECT )) +return sca3000_write_reg (st,SCA3000_REG_ADDR_MODE , + st->rx[0 ] & ~SCA3000_FREE_FALL_DETECT ); +else +return 0 ; } -/** -* sca3000_write_event_config() simple on off control for motion detector -* -* This is a per axis control, but enabling any will result in the -* motion detector unit being enabled. -* N.B. enabling motion detector stops normal data acquisition. -* There is a complexity in knowing which mode to return to when -* this mode is disabled. Currently normal mode is assumed. -**/ -static int sca3000_write_event_config (struct iio_dev *indio_dev, -const struct iio_chan_spec *chan, -enum iio_event_type type, -enum iio_event_direction dir, -int state) +static int sca3000_motion_detect_set_state (struct iio_dev *indio_dev,int axis, +int state) {struct sca3000_state *st =iio_priv (indio_dev);int ret, ctrlval; -u8 protect_mask =0x03 ; -int num = chan->channel2; -mutex_lock (&st->lock);/* * First read the motion detector config to find out if * this axis is on */ ret =sca3000_read_ctrl_reg (st,SCA3000_REG_CTRL_SEL_MD_CTRL );if (ret <0 ) - goto exit_point; +return ret; ctrlval = ret;/* if off and should be on */ -if (state && !(ctrlval & sca3000_addresses[num][2 ])) { +if (state && !(ctrlval & sca3000_addresses[axis][2 ])) { ret =sca3000_write_ctrl_reg (st,SCA3000_REG_CTRL_SEL_MD_CTRL , ctrlval | - sca3000_addresses[num][2 ]); + sca3000_addresses[axis][2 ]);if (ret) - goto exit_point; +return ret; st->mo_det_use_count++; - }else if (!state && (ctrlval & sca3000_addresses[num][2 ])) { + }else if (!state && (ctrlval & sca3000_addresses[axis][2 ])) { ret =sca3000_write_ctrl_reg (st,SCA3000_REG_CTRL_SEL_MD_CTRL , ctrlval & - ~(sca3000_addresses[num][2 ])); + ~(sca3000_addresses[axis][2 ]));if (ret) - goto exit_point; +return ret; st->mo_det_use_count--; }/* read current value of mode register */ ret =sca3000_read_data_short (st,SCA3000_REG_ADDR_MODE ,1 );if (ret) - goto exit_point; +return ret;/* if off and should be on */ if ((st->mo_det_use_count) && - ((st->rx[0 ] & protect_mask) !=SCA3000_MEAS_MODE_MOT_DET )) - ret =sca3000_write_reg (st,SCA3000_REG_ADDR_MODE , - (st->rx[0 ] & ~protect_mask) + ((st->rx[0 ] &SCA3000_MODE_MASK ) !=SCA3000_MEAS_MODE_MOT_DET )) +return sca3000_write_reg (st,SCA3000_REG_ADDR_MODE , + (st->rx[0 ] & ~SCA3000_MODE_MASK ) |SCA3000_MEAS_MODE_MOT_DET );/* if on and should be off */ else if (!(st->mo_det_use_count) && - ((st->rx[0 ] & protect_mask) ==SCA3000_MEAS_MODE_MOT_DET )) - ret =sca3000_write_reg (st,SCA3000_REG_ADDR_MODE , - (st->rx[0 ] & ~protect_mask)); -exit_point: + ((st->rx[0 ] &SCA3000_MODE_MASK ) ==SCA3000_MEAS_MODE_MOT_DET )) +return sca3000_write_reg (st,SCA3000_REG_ADDR_MODE , + st->rx[0 ] &SCA3000_MODE_MASK ); +else +return 0 ; +} + +/** +* sca3000_write_event_config() simple on off control for motion detector +* +* This is a per axis control, but enabling any will result in the +* motion detector unit being enabled. +* N.B. enabling motion detector stops normal data acquisition. +* There is a complexity in knowing which mode to return to when +* this mode is disabled. Currently normal mode is assumed. +**/ +static int sca3000_write_event_config (struct iio_dev *indio_dev, +const struct iio_chan_spec *chan, +enum iio_event_type type, +enum iio_event_direction dir, +int state) +{ +struct sca3000_state *st =iio_priv (indio_dev); +int ret; + +mutex_lock (&st->lock); +switch (chan->channel2) { +case IIO_MOD_X_AND_Y_AND_Z : + ret =sca3000_freefall_set_state (indio_dev, state); +break ; + +case IIO_MOD_X : +case IIO_MOD_Y : +case IIO_MOD_Z : + ret =sca3000_motion_detect_set_state (indio_dev, chan->channel2, + state); +break ; +default : + ret = -EINVAL ; +break ; + }mutex_unlock (&st->lock);return ret; } -/* Free fall detector related event attribute */ -static IIO_DEVICE_ATTR_NAMED(accel_xayaz_mag_falling_en, - in_accel_x & y & z_mag_falling_en, -S_IRUGO |S_IWUSR , - sca3000_query_free_fall_mode, - sca3000_set_free_fall_mode, - 0); - -static IIO_CONST_ATTR_NAMED(accel_xayaz_mag_falling_period, - in_accel_x & y & z_mag_falling_period, - "0.226"); - -static struct attribute *sca3000_event_attributes[] = { - &iio_dev_attr_accel_xayaz_mag_falling_en.dev_attr.attr, - &iio_const_attr_accel_xayaz_mag_falling_period.dev_attr.attr, -NULL , -}; - -static struct attribute_group sca3000_event_attribute_group = { - .attrs = sca3000_event_attributes, - .name ="events" , -}; -static int sca3000_configure_ring (struct iio_dev *indio_dev) {struct iio_buffer *buffer;@@ -1436,9 +1443,8 @@ static const struct iio_info sca3000_info = { .attrs = &sca3000_attribute_group, .read_raw = &sca3000_read_raw, .write_raw = &sca3000_write_raw, - .event_attrs = &sca3000_event_attribute_group, - .read_event_value = &sca3000_read_thresh, - .write_event_value = &sca3000_write_thresh, + .read_event_value = &sca3000_read_event_value, + .write_event_value = &sca3000_write_event_value, .read_event_config = &sca3000_read_event_config, .write_event_config = &sca3000_write_event_config, .driver_module = THIS_MODULE,
Jonathan Cameron
maintainerPATCH v2 9/18 staging:iio:accel:sca3000 Clean up register defines.
In reply to Jonathan CameronIntroduce some more masks and generally drive towards consistent naming. Note the small indents used to indicate parts of registers + parts of multiplexed registers.
--- drivers/staging/iio/accel/sca3000.c | 318 ++++++++++++++++++------------------ 1 file changed, 160 insertions(+), 158 deletions(-)
drivers/staging/iio/accel/sca3000.c +160 -158
@@ -28,110 +28,110 @@#define SCA3000_WRITE_REG (a) (((a) << 2) | 0x02)#define SCA3000_READ_REG (a) ((a) << 2) -#define SCA3000_REG_ADDR_REVID 0x00 -#define SCA3000_REVID_MAJOR_MASK 0xf0 -#define SCA3000_REVID_MINOR_MASK 0x0f +#define SCA3000_REG_REVID_ADDR 0x00 +#define SCA3000_REG_REVID_MAJOR_MASK GENMASK(8, 4) +#define SCA3000_REG_REVID_MINOR_MASK GENMASK(3, 0) -#define SCA3000_REG_ADDR_STATUS 0x02 -#define SCA3000_LOCKED 0x20 -#define SCA3000_EEPROM_CS_ERROR 0x02 -#define SCA3000_SPI_FRAME_ERROR 0x01 +#define SCA3000_REG_STATUS_ADDR 0x02 +#define SCA3000_LOCKED BIT(5) +#define SCA3000_EEPROM_CS_ERROR BIT(1) +#define SCA3000_SPI_FRAME_ERROR BIT(0)/* All reads done using register decrement so no need to directly access LSBs */ -#define SCA3000_REG_ADDR_X_MSB 0x05 -#define SCA3000_REG_ADDR_Y_MSB 0x07 -#define SCA3000_REG_ADDR_Z_MSB 0x09 +#define SCA3000_REG_X_MSB_ADDR 0x05 +#define SCA3000_REG_Y_MSB_ADDR 0x07 +#define SCA3000_REG_Z_MSB_ADDR 0x09 -#define SCA3000_REG_ADDR_RING_OUT 0x0f +#define SCA3000_REG_RING_OUT_ADDR 0x0f/* Temp read untested - the e05 doesn't have the sensor */ -#define SCA3000_REG_ADDR_TEMP_MSB 0x13 +#define SCA3000_REG_TEMP_MSB_ADDR 0x13 -#define SCA3000_REG_ADDR_MODE 0x14 -#define SCA3000_MODE_PROT_MASK 0x28 - -#define SCA3000_RING_BUF_ENABLE 0x80 -#define SCA3000_RING_BUF_8BIT 0x40 +#define SCA3000_REG_MODE_ADDR 0x14 +#define SCA3000_MODE_PROT_MASK 0x28 +#define SCA3000_REG_MODE_RING_BUF_ENABLE BIT(7) +#define SCA3000_REG_MODE_RING_BUF_8BIT BIT(6)/* * Free fall detection triggers an interrupt if the acceleration * is below a threshold for equivalent of 25cm drop */ -#define SCA3000_FREE_FALL_DETECT 0x10 -#define SCA3000_MEAS_MODE_NORMAL 0x00 -#define SCA3000_MEAS_MODE_OP_1 0x01 -#define SCA3000_MEAS_MODE_OP_2 0x02 +#define SCA3000_REG_MODE_FREE_FALL_DETECT BIT(4) +#define SCA3000_REG_MODE_MEAS_MODE_NORMAL 0x00 +#define SCA3000_REG_MODE_MEAS_MODE_OP_1 0x01 +#define SCA3000_REG_MODE_MEAS_MODE_OP_2 0x02/* * In motion detection mode the accelerations are band pass filtered * (approx 1 - 25Hz) and then a programmable threshold used to trigger * and interrupt. */ -#define SCA3000_MEAS_MODE_MOT_DET 0x03 - -#define SCA3000_REG_ADDR_BUF_COUNT 0x15 +#define SCA3000_REG_MODE_MEAS_MODE_MOT_DET 0x03 +#define SCA3000_REG_MODE_MODE_MASK 0x03 -#define SCA3000_REG_ADDR_INT_STATUS 0x16 +#define SCA3000_REG_BUF_COUNT_ADDR 0x15 -#define SCA3000_INT_STATUS_THREE_QUARTERS 0x80 -#define SCA3000_INT_STATUS_HALF 0x40 +#define SCA3000_REG_INT_STATUS_ADDR 0x16 +#define SCA3000_REG_INT_STATUS_THREE_QUARTERS BIT(7) +#define SCA3000_REG_INT_STATUS_HALF BIT(6) -#define SCA3000_INT_STATUS_FREE_FALL 0x08 -#define SCA3000_INT_STATUS_Y_TRIGGER 0x04 -#define SCA3000_INT_STATUS_X_TRIGGER 0x02 -#define SCA3000_INT_STATUS_Z_TRIGGER 0x01 +#define SCA3000_INT_STATUS_FREE_FALL BIT(3) +#define SCA3000_INT_STATUS_Y_TRIGGER BIT(2) +#define SCA3000_INT_STATUS_X_TRIGGER BIT(1) +#define SCA3000_INT_STATUS_Z_TRIGGER BIT(0)/* Used to allow access to multiplexed registers */ -#define SCA3000_REG_ADDR_CTRL_SEL 0x18 +#define SCA3000_REG_CTRL_SEL_ADDR 0x18/* Only available for SCA3000-D03 and SCA3000-D01 */ -#define SCA3000_REG_CTRL_SEL_I2C_DISABLE 0x01 -#define SCA3000_REG_CTRL_SEL_MD_CTRL 0x02 -#define SCA3000_REG_CTRL_SEL_MD_Y_TH 0x03 -#define SCA3000_REG_CTRL_SEL_MD_X_TH 0x04 -#define SCA3000_REG_CTRL_SEL_MD_Z_TH 0x05 +#define SCA3000_REG_CTRL_SEL_I2C_DISABLE 0x01 +#define SCA3000_REG_CTRL_SEL_MD_CTRL 0x02 +#define SCA3000_REG_CTRL_SEL_MD_Y_TH 0x03 +#define SCA3000_REG_CTRL_SEL_MD_X_TH 0x04 +#define SCA3000_REG_CTRL_SEL_MD_Z_TH 0x05/* * BE VERY CAREFUL WITH THIS, IF 3 BITS ARE NOT SET the device * will not function */ -#define SCA3000_REG_CTRL_SEL_OUT_CTRL 0x0B -#define SCA3000_OUT_CTRL_PROT_MASK 0xE0 -#define SCA3000_OUT_CTRL_BUF_X_EN 0x10 -#define SCA3000_OUT_CTRL_BUF_Y_EN 0x08 -#define SCA3000_OUT_CTRL_BUF_Z_EN 0x04 -#define SCA3000_OUT_CTRL_BUF_DIV_MASK 0x03 -#define SCA3000_OUT_CTRL_BUF_DIV_4 0x02 -#define SCA3000_OUT_CTRL_BUF_DIV_2 0x01 +#define SCA3000_REG_CTRL_SEL_OUT_CTRL 0x0B + +#define SCA3000_REG_OUT_CTRL_PROT_MASK 0xE0 +#define SCA3000_REG_OUT_CTRL_BUF_X_EN 0x10 +#define SCA3000_REG_OUT_CTRL_BUF_Y_EN 0x08 +#define SCA3000_REG_OUT_CTRL_BUF_Z_EN 0x04 +#define SCA3000_REG_OUT_CTRL_BUF_DIV_MASK 0x03 +#define SCA3000_REG_OUT_CTRL_BUF_DIV_4 0x02 +#define SCA3000_REG_OUT_CTRL_BUF_DIV_2 0x01/* * Control which motion detector interrupts are on. * For now only OR combinations are supported. */ -#define SCA3000_MD_CTRL_PROT_MASK 0xC0 -#define SCA3000_MD_CTRL_OR_Y 0x01 -#define SCA3000_MD_CTRL_OR_X 0x02 -#define SCA3000_MD_CTRL_OR_Z 0x04 +#define SCA3000_MD_CTRL_PROT_MASK 0xC0 +#define SCA3000_MD_CTRL_OR_Y BIT(0) +#define SCA3000_MD_CTRL_OR_X BIT(1) +#define SCA3000_MD_CTRL_OR_Z BIT(2)/* Currently unsupported */ -#define SCA3000_MD_CTRL_AND_Y 0x08 -#define SCA3000_MD_CTRL_AND_X 0x10 -#define SAC3000_MD_CTRL_AND_Z 0x20 +#define SCA3000_MD_CTRL_AND_Y BIT(3) +#define SCA3000_MD_CTRL_AND_X BIT(4) +#define SAC3000_MD_CTRL_AND_Z BIT(5)/* * Some control registers of complex access methods requiring this register to * be used to remove a lock. */ -#define SCA3000_REG_ADDR_UNLOCK 0x1e +#define SCA3000_REG_UNLOCK_ADDR 0x1e -#define SCA3000_REG_ADDR_INT_MASK 0x21 -#define SCA3000_INT_MASK_PROT_MASK 0x1C +#define SCA3000_REG_INT_MASK_ADDR 0x21 +#define SCA3000_REG_INT_MASK_PROT_MASK 0x1C -#define SCA3000_INT_MASK_RING_THREE_QUARTER 0x80 -#define SCA3000_INT_MASK_RING_HALF 0x40 +#define SCA3000_REG_INT_MASK_RING_THREE_QUARTER BIT(7) +#define SCA3000_REG_INT_MASK_RING_HALF BIT(6) -#define SCA3000_INT_MASK_ALL_INTS 0x02 -#define SCA3000_INT_MASK_ACTIVE_HIGH 0x01 -#define SCA3000_INT_MASK_ACTIVE_LOW 0x00 +#define SCA3000_REG_INT_MASK_ALL_INTS 0x02 +#define SCA3000_REG_INT_MASK_ACTIVE_HIGH 0x01 +#define SCA3000_REG_INT_MASK_ACTIVE_LOW 0x00/* Values of multiplexed registers (write to ctrl_data after select) */ -#define SCA3000_REG_ADDR_CTRL_DATA 0x22 +#define SCA3000_REG_CTRL_DATA_ADDR 0x22/* * Measurement modes available on some sca3000 series chips. Code assumes others
@@ -145,9 +145,9 @@* * Wide - Widen low-pass filtering of signal channel to increase bandwidth */ -#define SCA3000_OP_MODE_BYPASS 0x01 -#define SCA3000_OP_MODE_NARROW 0x02 -#define SCA3000_OP_MODE_WIDE 0x04 +#define SCA3000_OP_MODE_BYPASS 0x01 +#define SCA3000_OP_MODE_NARROW 0x02 +#define SCA3000_OP_MODE_WIDE 0x04#define SCA3000_MAX_TX 6#define SCA3000_MAX_RX 2
@@ -287,7 +287,7 @@ static int sca3000_reg_lock_on(struct sca3000_state *st) {int ret; - ret =sca3000_read_data_short (st,SCA3000_REG_ADDR_STATUS ,1 ); + ret =sca3000_read_data_short (st,SCA3000_REG_STATUS_ADDR ,1 );if (ret <0 )return ret;
@@ -317,11 +317,11 @@ static int __sca3000_unlock_reg_lock(struct sca3000_state *st) .tx_buf = st->tx + 4, }, }; - st->tx[0 ] =SCA3000_WRITE_REG (SCA3000_REG_ADDR_UNLOCK ); + st->tx[0 ] =SCA3000_WRITE_REG (SCA3000_REG_UNLOCK_ADDR ); st->tx[1 ] =0x00 ; - st->tx[2 ] =SCA3000_WRITE_REG (SCA3000_REG_ADDR_UNLOCK ); + st->tx[2 ] =SCA3000_WRITE_REG (SCA3000_REG_UNLOCK_ADDR ); st->tx[3 ] =0x50 ; - st->tx[4 ] =SCA3000_WRITE_REG (SCA3000_REG_ADDR_UNLOCK ); + st->tx[4 ] =SCA3000_WRITE_REG (SCA3000_REG_UNLOCK_ADDR ); st->tx[5 ] =0xA0 ;return spi_sync_transfer (st->us, xfer,ARRAY_SIZE (xfer));
@@ -353,12 +353,12 @@ static int sca3000_write_ctrl_reg(struct sca3000_state *st, }/* Set the control select register */ - ret =sca3000_write_reg (st,SCA3000_REG_ADDR_CTRL_SEL , sel); + ret =sca3000_write_reg (st,SCA3000_REG_CTRL_SEL_ADDR , sel);if (ret) goto error_ret;/* Write the actual value into the register */ - ret =sca3000_write_reg (st,SCA3000_REG_ADDR_CTRL_DATA , val); + ret =sca3000_write_reg (st,SCA3000_REG_CTRL_DATA_ADDR , val); error_ret:return ret;
@@ -383,10 +383,10 @@ static int sca3000_read_ctrl_reg(struct sca3000_state *st, goto error_ret; }/* Set the control select register */ - ret =sca3000_write_reg (st,SCA3000_REG_ADDR_CTRL_SEL , ctrl_reg); + ret =sca3000_write_reg (st,SCA3000_REG_CTRL_SEL_ADDR , ctrl_reg);if (ret) goto error_ret; - ret =sca3000_read_data_short (st,SCA3000_REG_ADDR_CTRL_DATA ,1 ); + ret =sca3000_read_data_short (st,SCA3000_REG_CTRL_DATA_ADDR ,1 );if (ret) goto error_ret;return st->rx[0 ];
@@ -406,13 +406,13 @@ static ssize_t sca3000_show_rev(struct device *dev,struct sca3000_state *st =iio_priv (indio_dev);mutex_lock (&st->lock); - ret =sca3000_read_data_short (st,SCA3000_REG_ADDR_REVID ,1 ); + ret =sca3000_read_data_short (st,SCA3000_REG_REVID_ADDR ,1 );if (ret <0 ) goto error_ret; len +=sprintf (buf + len, -"major=%d, minor=%d\n" , - st->rx[0 ] &SCA3000_REVID_MAJOR_MASK , - st->rx[0 ] &SCA3000_REVID_MINOR_MASK ); +"major=%lu, minor=%lu\n" , + st->rx[0 ] &SCA3000_REG_REVID_MAJOR_MASK , + st->rx[0 ] &SCA3000_REG_REVID_MINOR_MASK ); error_ret:mutex_unlock (&st->lock);
@@ -467,19 +467,19 @@ sca3000_show_measurement_mode(struct device *dev,int len =0 , ret;mutex_lock (&st->lock); - ret =sca3000_read_data_short (st,SCA3000_REG_ADDR_MODE ,1 ); + ret =sca3000_read_data_short (st,SCA3000_REG_MODE_ADDR ,1 );if (ret) goto error_ret;/* mask bottom 2 bits - only ones that are relevant */ - st->rx[0 ] &=0x03 ; + st->rx[0 ] &=SCA3000_REG_MODE_MODE_MASK ;switch (st->rx[0 ]) { -case SCA3000_MEAS_MODE_NORMAL : +case SCA3000_REG_MODE_MEAS_MODE_NORMAL : len +=sprintf (buf + len,"0 - normal mode\n" );break ; -case SCA3000_MEAS_MODE_MOT_DET : +case SCA3000_REG_MODE_MEAS_MODE_MOT_DET : len +=sprintf (buf + len,"3 - motion detection\n" );break ; -case SCA3000_MEAS_MODE_OP_1 : +case SCA3000_REG_MODE_MEAS_MODE_OP_1 :switch (st->info->option_mode_1) {case SCA3000_OP_MODE_NARROW : len +=sprintf (buf + len,"1 - narrow mode\n" );
@@ -489,7 +489,7 @@ sca3000_show_measurement_mode(struct device *dev,break ; }break ; -case SCA3000_MEAS_MODE_OP_2 : +case SCA3000_REG_MODE_MEAS_MODE_OP_2 :switch (st->info->option_mode_2) {case SCA3000_OP_MODE_WIDE : len +=sprintf (buf + len,"2 - wide mode\n" );
@@ -516,7 +516,6 @@ sca3000_store_measurement_mode(struct device *dev,struct iio_dev *indio_dev =dev_to_iio_dev (dev);struct sca3000_state *st =iio_priv (indio_dev);int ret; -u8 mask =0x03 ;u8 val;mutex_lock (&st->lock);
@@ -527,12 +526,12 @@ sca3000_store_measurement_mode(struct device *dev, ret = -EINVAL ; goto error_ret; } - ret =sca3000_read_data_short (st,SCA3000_REG_ADDR_MODE ,1 ); + ret =sca3000_read_data_short (st,SCA3000_REG_MODE_ADDR ,1 );if (ret) goto error_ret; - st->rx[0 ] &= ~mask; - st->rx[0 ] |= (val & mask); - ret =sca3000_write_reg (st,SCA3000_REG_ADDR_MODE , st->rx[0 ]); + st->rx[0 ] &= ~SCA3000_REG_MODE_MODE_MASK ; + st->rx[0 ] |= (val &SCA3000_REG_MODE_MODE_MASK ); + ret =sca3000_write_reg (st,SCA3000_REG_MODE_ADDR , st->rx[0 ]);if (ret) goto error_ret;mutex_unlock (&st->lock);
@@ -637,11 +636,11 @@ static const struct iio_chan_spec sca3000_channels_with_temp[] = { };static u8 sca3000_addresses[3 ][3 ] = { - [0 ] = {SCA3000_REG_ADDR_X_MSB ,SCA3000_REG_CTRL_SEL_MD_X_TH , + [0 ] = {SCA3000_REG_X_MSB_ADDR ,SCA3000_REG_CTRL_SEL_MD_X_TH ,SCA3000_MD_CTRL_OR_X }, - [1 ] = {SCA3000_REG_ADDR_Y_MSB ,SCA3000_REG_CTRL_SEL_MD_Y_TH , + [1 ] = {SCA3000_REG_Y_MSB_ADDR ,SCA3000_REG_CTRL_SEL_MD_Y_TH ,SCA3000_MD_CTRL_OR_Y }, - [2 ] = {SCA3000_REG_ADDR_Z_MSB ,SCA3000_REG_CTRL_SEL_MD_Z_TH , + [2 ] = {SCA3000_REG_Z_MSB_ADDR ,SCA3000_REG_CTRL_SEL_MD_Z_TH ,SCA3000_MD_CTRL_OR_Z }, };
@@ -656,17 +655,17 @@ static inline int __sca3000_get_base_freq(struct sca3000_state *st, {int ret; - ret =sca3000_read_data_short (st,SCA3000_REG_ADDR_MODE ,1 ); + ret =sca3000_read_data_short (st,SCA3000_REG_MODE_ADDR ,1 );if (ret) goto error_ret; -switch (0x03 & st->rx[0 ]) { -case SCA3000_MEAS_MODE_NORMAL : +switch (SCA3000_REG_MODE_MODE_MASK & st->rx[0 ]) { +case SCA3000_REG_MODE_MEAS_MODE_NORMAL : *base_freq = info->measurement_mode_freq;break ; -case SCA3000_MEAS_MODE_OP_1 : +case SCA3000_REG_MODE_MEAS_MODE_OP_1 : *base_freq = info->option_mode_1_freq;break ; -case SCA3000_MEAS_MODE_OP_2 : +case SCA3000_REG_MODE_MEAS_MODE_OP_2 : *base_freq = info->option_mode_2_freq;break ;default :
@@ -694,12 +693,12 @@ static int read_raw_samp_freq(struct sca3000_state *st, int *val)return ret;if (*val >0 ) { - ret &=SCA3000_OUT_CTRL_BUF_DIV_MASK ; + ret &=SCA3000_REG_OUT_CTRL_BUF_DIV_MASK ;switch (ret) { -case SCA3000_OUT_CTRL_BUF_DIV_2 : +case SCA3000_REG_OUT_CTRL_BUF_DIV_2 : *val /=2 ;break ; -case SCA3000_OUT_CTRL_BUF_DIV_4 : +case SCA3000_REG_OUT_CTRL_BUF_DIV_4 : *val /=4 ;break ; }
@@ -725,12 +724,12 @@ static int write_raw_samp_freq(struct sca3000_state *st, int val)if (ret <0 )return ret; - ctrlval = ret & ~SCA3000_OUT_CTRL_BUF_DIV_MASK ; + ctrlval = ret & ~SCA3000_REG_OUT_CTRL_BUF_DIV_MASK ;if (val == base_freq /2 ) - ctrlval |=SCA3000_OUT_CTRL_BUF_DIV_2 ; + ctrlval |=SCA3000_REG_OUT_CTRL_BUF_DIV_2 ;if (val == base_freq /4 ) - ctrlval |=SCA3000_OUT_CTRL_BUF_DIV_4 ; + ctrlval |=SCA3000_REG_OUT_CTRL_BUF_DIV_4 ;else if (val != base_freq)return -EINVAL ;
@@ -768,7 +767,7 @@ static int sca3000_read_raw(struct iio_dev *indio_dev, }else {/* get the temperature when available */ ret =sca3000_read_data_short (st, -SCA3000_REG_ADDR_TEMP_MSB , +SCA3000_REG_TEMP_MSB_ADDR ,2 );if (ret <0 ) {mutex_unlock (&st->lock);
@@ -839,26 +838,26 @@ static ssize_t sca3000_read_av_freq(struct device *dev,int len =0 , ret, val;mutex_lock (&st->lock); - ret =sca3000_read_data_short (st,SCA3000_REG_ADDR_MODE ,1 ); + ret =sca3000_read_data_short (st,SCA3000_REG_MODE_ADDR ,1 ); val = st->rx[0 ];mutex_unlock (&st->lock);if (ret) goto error_ret; -switch (val &0x03 ) { -case SCA3000_MEAS_MODE_NORMAL : +switch (val &SCA3000_REG_MODE_MODE_MASK ) { +case SCA3000_REG_MODE_MEAS_MODE_NORMAL : len +=sprintf (buf + len,"%d %d %d\n" , st->info->measurement_mode_freq, st->info->measurement_mode_freq /2 , st->info->measurement_mode_freq /4 );break ; -case SCA3000_MEAS_MODE_OP_1 : +case SCA3000_REG_MODE_MEAS_MODE_OP_1 : len +=sprintf (buf + len,"%d %d %d\n" , st->info->option_mode_1_freq, st->info->option_mode_1_freq /2 , st->info->option_mode_1_freq /4 );break ; -case SCA3000_MEAS_MODE_OP_2 : +case SCA3000_REG_MODE_MEAS_MODE_OP_2 : len += sprintf(buf + len, "%d %d %d\n", st->info->option_mode_2_freq, st->info->option_mode_2_freq / 2,
@@ -1005,8 +1004,9 @@ static void sca3000_ring_int_process(u8 val, struct iio_dev *indio_dev)int ret, i, num_available;mutex_lock (&st->lock); -if (val &SCA3000_INT_STATUS_HALF ) { - ret =sca3000_read_data_short (st,SCA3000_REG_ADDR_BUF_COUNT , + +if (val &SCA3000_REG_INT_STATUS_HALF ) { + ret =sca3000_read_data_short (st,SCA3000_REG_BUF_COUNT_ADDR ,1 );if (ret) goto error_ret;
@@ -1015,7 +1015,7 @@ static void sca3000_ring_int_process(u8 val, struct iio_dev *indio_dev)* num_available is the total number of samples available * i.e. number of time points * number of channels. */ - ret =sca3000_read_data (st,SCA3000_REG_ADDR_RING_OUT , st->rx, + ret =sca3000_read_data (st,SCA3000_REG_RING_OUT_ADDR , st->rx, num_available *2 );if (ret) goto error_ret;
@@ -1056,7 +1056,7 @@ static irqreturn_t sca3000_event_handler(int irq, void *private)* but ensures no interrupt is missed. */ mutex_lock (&st->lock); - ret =sca3000_read_data_short (st,SCA3000_REG_ADDR_INT_STATUS ,1 ); + ret =sca3000_read_data_short (st,SCA3000_REG_INT_STATUS_ADDR ,1 ); val = st->rx[0 ];mutex_unlock (&st->lock);if (ret)
@@ -1114,19 +1114,18 @@ static int sca3000_read_event_config(struct iio_dev *indio_dev, {struct sca3000_state *st =iio_priv (indio_dev);int ret; -u8 protect_mask =0x03 ;int num = chan->channel2;/* read current value of mode register */ mutex_lock (&st->lock); - ret =sca3000_read_data_short (st,SCA3000_REG_ADDR_MODE ,1 ); + ret =sca3000_read_data_short (st,SCA3000_REG_MODE_ADDR ,1 );if (ret) goto error_ret;switch (chan->channel2) {case IIO_MOD_X_AND_Y_AND_Z : - ret = !!(st->rx[0 ] &SCA3000_FREE_FALL_DETECT ); + ret = !!(st->rx[0 ] &SCA3000_REG_MODE_FREE_FALL_DETECT );break ;case IIO_MOD_X :case IIO_MOD_Y :
@@ -1135,7 +1134,8 @@ static int sca3000_read_event_config(struct iio_dev *indio_dev,* Motion detection mode cannot run at the same time as * acceleration data being read. */ -if ((st->rx[0 ] & protect_mask) !=SCA3000_MEAS_MODE_MOT_DET ) { +if ((st->rx[0 ] &SCA3000_REG_MODE_MODE_MASK ) + !=SCA3000_REG_MODE_MEAS_MODE_MOT_DET ) { ret =0 ; }else { ret = sca3000_read_ctrl_reg(st,
@@ -1162,18 +1162,18 @@ static int sca3000_freefall_set_state(struct iio_dev *indio_dev, int state)int ret;/* read current value of mode register */ - ret =sca3000_read_data_short (st,SCA3000_REG_ADDR_MODE ,1 ); + ret =sca3000_read_data_short (st,SCA3000_REG_MODE_ADDR ,1 );if (ret)return ret;/* if off and should be on */ -if (state && !(st->rx[0 ] &SCA3000_FREE_FALL_DETECT )) -return sca3000_write_reg (st,SCA3000_REG_ADDR_MODE , - st->rx[0 ] |SCA3000_FREE_FALL_DETECT ); +if (state && !(st->rx[0 ] &SCA3000_REG_MODE_FREE_FALL_DETECT )) +return sca3000_write_reg (st,SCA3000_REG_MODE_ADDR , + st->rx[0 ] |SCA3000_REG_MODE_FREE_FALL_DETECT );/* if on and should be off */ -else if (!state && (st->rx[0 ] &SCA3000_FREE_FALL_DETECT )) -return sca3000_write_reg (st,SCA3000_REG_ADDR_MODE , - st->rx[0 ] & ~SCA3000_FREE_FALL_DETECT ); +else if (!state && (st->rx[0 ] &SCA3000_REG_MODE_FREE_FALL_DETECT )) +return sca3000_write_reg (st,SCA3000_REG_MODE_ADDR , + st->rx[0 ] & ~SCA3000_REG_MODE_FREE_FALL_DETECT );else return 0 ; }
@@ -1212,20 +1212,22 @@ static int sca3000_motion_detect_set_state(struct iio_dev *indio_dev, int axis, }/* read current value of mode register */ - ret =sca3000_read_data_short (st,SCA3000_REG_ADDR_MODE ,1 ); + ret =sca3000_read_data_short (st,SCA3000_REG_MODE_ADDR ,1 );if (ret)return ret;/* if off and should be on */ if ((st->mo_det_use_count) && - ((st->rx[0 ] &SCA3000_MODE_MASK ) !=SCA3000_MEAS_MODE_MOT_DET )) -return sca3000_write_reg (st,SCA3000_REG_ADDR_MODE , - (st->rx[0 ] & ~SCA3000_MODE_MASK ) - |SCA3000_MEAS_MODE_MOT_DET ); + ((st->rx[0 ] &SCA3000_REG_MODE_MODE_MASK ) + !=SCA3000_REG_MODE_MEAS_MODE_MOT_DET )) +return sca3000_write_reg (st,SCA3000_REG_MODE_ADDR , + (st->rx[0 ] & ~SCA3000_REG_MODE_MODE_MASK ) + |SCA3000_REG_MODE_MEAS_MODE_MOT_DET );/* if on and should be off */ else if (!(st->mo_det_use_count) && - ((st->rx[0 ] &SCA3000_MODE_MASK ) ==SCA3000_MEAS_MODE_MOT_DET )) -return sca3000_write_reg (st,SCA3000_REG_ADDR_MODE , - st->rx[0 ] &SCA3000_MODE_MASK ); + ((st->rx[0 ] &SCA3000_REG_MODE_MODE_MASK ) + ==SCA3000_REG_MODE_MEAS_MODE_MOT_DET )) +return sca3000_write_reg (st,SCA3000_REG_MODE_ADDR , + st->rx[0 ] &SCA3000_REG_MODE_MODE_MASK );else return 0 ; }
@@ -1295,18 +1297,18 @@ int __sca3000_hw_ring_state_set(struct iio_dev *indio_dev, bool state)int ret;mutex_lock (&st->lock); - ret =sca3000_read_data_short (st,SCA3000_REG_ADDR_MODE ,1 ); + ret =sca3000_read_data_short (st,SCA3000_REG_MODE_ADDR ,1 );if (ret) goto error_ret;if (state) {dev_info (&indio_dev->dev,"supposedly enabling ring buffer\n" ); ret =sca3000_write_reg (st, -SCA3000_REG_ADDR_MODE , - (st->rx[0 ] |SCA3000_RING_BUF_ENABLE )); +SCA3000_REG_MODE_ADDR , + (st->rx[0 ] |SCA3000_REG_MODE_RING_BUF_ENABLE )); }else ret =sca3000_write_reg (st, -SCA3000_REG_ADDR_MODE , - (st->rx[0 ] & ~SCA3000_RING_BUF_ENABLE )); +SCA3000_REG_MODE_ADDR , + (st->rx[0 ] & ~SCA3000_REG_MODE_RING_BUF_ENABLE )); error_ret:mutex_unlock (&st->lock);
@@ -1328,12 +1330,12 @@ static int sca3000_hw_ring_preenable(struct iio_dev *indio_dev)mutex_lock (&st->lock);/* Enable the 50% full interrupt */ - ret =sca3000_read_data_short (st,SCA3000_REG_ADDR_INT_MASK ,1 ); + ret =sca3000_read_data_short (st,SCA3000_REG_INT_MASK_ADDR ,1 );if (ret) goto error_unlock; ret =sca3000_write_reg (st, -SCA3000_REG_ADDR_INT_MASK , - st->rx[0 ] |SCA3000_INT_MASK_RING_HALF ); +SCA3000_REG_INT_MASK_ADDR , + st->rx[0 ] |SCA3000_REG_INT_MASK_RING_HALF );if (ret) goto error_unlock;
@@ -1359,12 +1361,12 @@ static int sca3000_hw_ring_postdisable(struct iio_dev *indio_dev)/* Disable the 50% full interrupt */ mutex_lock (&st->lock); - ret =sca3000_read_data_short (st,SCA3000_REG_ADDR_INT_MASK ,1 ); + ret =sca3000_read_data_short (st,SCA3000_REG_INT_MASK_ADDR ,1 );if (ret) goto unlock; ret =sca3000_write_reg (st, -SCA3000_REG_ADDR_INT_MASK , - st->rx[0 ] & ~SCA3000_INT_MASK_RING_HALF ); +SCA3000_REG_INT_MASK_ADDR , + st->rx[0 ] & ~SCA3000_REG_INT_MASK_RING_HALF ); unlock:mutex_unlock (&st->lock);return ret;
@@ -1388,7 +1390,7 @@ static int sca3000_clean_setup(struct sca3000_state *st)mutex_lock (&st->lock);/* Ensure all interrupts have been acknowledged */ - ret =sca3000_read_data_short (st,SCA3000_REG_ADDR_INT_STATUS ,1 ); + ret =sca3000_read_data_short (st,SCA3000_REG_INT_STATUS_ADDR ,1 );if (ret) goto error_ret;
@@ -1406,21 +1408,21 @@ static int sca3000_clean_setup(struct sca3000_state *st)if (ret <0 ) goto error_ret; ret =sca3000_write_ctrl_reg (st,SCA3000_REG_CTRL_SEL_OUT_CTRL , - (ret &SCA3000_OUT_CTRL_PROT_MASK ) - |SCA3000_OUT_CTRL_BUF_X_EN - |SCA3000_OUT_CTRL_BUF_Y_EN - |SCA3000_OUT_CTRL_BUF_Z_EN - |SCA3000_OUT_CTRL_BUF_DIV_4 ); + (ret &SCA3000_REG_OUT_CTRL_PROT_MASK ) + |SCA3000_REG_OUT_CTRL_BUF_X_EN + |SCA3000_REG_OUT_CTRL_BUF_Y_EN + |SCA3000_REG_OUT_CTRL_BUF_Z_EN + |SCA3000_REG_OUT_CTRL_BUF_DIV_4 );if (ret) goto error_ret;/* Enable interrupts, relevant to mode and set up as active low */ - ret =sca3000_read_data_short (st,SCA3000_REG_ADDR_INT_MASK ,1 ); + ret =sca3000_read_data_short (st,SCA3000_REG_INT_MASK_ADDR ,1 );if (ret) goto error_ret; ret =sca3000_write_reg (st, -SCA3000_REG_ADDR_INT_MASK , - (ret &SCA3000_INT_MASK_PROT_MASK ) - |SCA3000_INT_MASK_ACTIVE_LOW ); +SCA3000_REG_INT_MASK_ADDR , + (ret &SCA3000_REG_INT_MASK_PROT_MASK ) + |SCA3000_REG_INT_MASK_ACTIVE_LOW );if (ret) goto error_ret;/*
@@ -1428,10 +1430,10 @@ static int sca3000_clean_setup(struct sca3000_state *st)* Ring in 12 bit mode - it is fine to overwrite reserved bits 3,5 * as that occurs in one of the example on the datasheet */ - ret =sca3000_read_data_short (st,SCA3000_REG_ADDR_MODE ,1 ); + ret =sca3000_read_data_short (st,SCA3000_REG_MODE_ADDR ,1 );if (ret) goto error_ret; - ret =sca3000_write_reg (st,SCA3000_REG_ADDR_MODE , + ret =sca3000_write_reg (st,SCA3000_REG_MODE_ADDR , (st->rx[0 ] &SCA3000_MODE_PROT_MASK )); error_ret:
@@ -1514,14 +1516,14 @@ static int sca3000_stop_all_interrupts(struct sca3000_state *st)int ret;mutex_lock (&st->lock); - ret =sca3000_read_data_short (st,SCA3000_REG_ADDR_INT_MASK ,1 ); + ret =sca3000_read_data_short (st,SCA3000_REG_INT_MASK_ADDR ,1 );if (ret) goto error_ret; - ret =sca3000_write_reg (st,SCA3000_REG_ADDR_INT_MASK , + ret =sca3000_write_reg (st,SCA3000_REG_INT_MASK_ADDR , (st->rx[0 ] & - ~(SCA3000_INT_MASK_RING_THREE_QUARTER | -SCA3000_INT_MASK_RING_HALF | -SCA3000_INT_MASK_ALL_INTS ))); + ~(SCA3000_REG_INT_MASK_RING_THREE_QUARTER | +SCA3000_REG_INT_MASK_RING_HALF | +SCA3000_REG_INT_MASK_ALL_INTS ))); error_ret:mutex_unlock (&st->lock);return ret;
Signature · 1 line
2.10.0
Jonathan Cameron
maintainerPATCH v2 10/18 staging:iio:accel:sca3000 add readback of the 3db low pass filter frequency
In reply to Jonathan CameronDriving towards getting rid of the non standard mode control interface.
--- drivers/staging/iio/accel/sca3000.c | 48 ++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-)
drivers/staging/iio/accel/sca3000.c +47 -1
@@ -190,10 +190,13 @@ struct sca3000_chip_info {unsigned int scale;bool temp_output;int measurement_mode_freq; +int measurement_mode_3db_freq;int option_mode_1;int option_mode_1_freq; +int option_mode_1_3db_freq;int option_mode_2;int option_mode_2_freq; +int option_mode_2_3db_freq;int mot_det_mult_xz[6 ];int mot_det_mult_y[7 ]; };
@@ -218,36 +221,46 @@ static const struct sca3000_chip_info sca3000_spi_chip_info_tbl[] = { .scale = 7357, .temp_output = true, .measurement_mode_freq = 250, + .measurement_mode_3db_freq = 45, .option_mode_1 = SCA3000_OP_MODE_BYPASS, .option_mode_1_freq = 250, + .option_mode_1_3db_freq = 70, .mot_det_mult_xz = {50, 100, 200, 350, 650, 1300}, .mot_det_mult_y = {50, 100, 150, 250, 450, 850, 1750}, }, [e02] = { .scale =9810 , .measurement_mode_freq = 125, + .measurement_mode_3db_freq = 40, .option_mode_1 = SCA3000_OP_MODE_NARROW, .option_mode_1_freq = 63, + .option_mode_1_3db_freq = 11, .mot_det_mult_xz = {100, 150, 300, 550, 1050, 2050}, .mot_det_mult_y = {50, 100, 200, 350, 700, 1350, 2700}, }, [e04] = { .scale =19620 , .measurement_mode_freq = 100, + .measurement_mode_3db_freq = 38, .option_mode_1 = SCA3000_OP_MODE_NARROW, .option_mode_1_freq = 50, + .option_mode_1_3db_freq = 9, .option_mode_2 = SCA3000_OP_MODE_WIDE, .option_mode_2_freq = 400, + .option_mode_2_3db_freq = 70, .mot_det_mult_xz = {200, 300, 600, 1100, 2100, 4100}, .mot_det_mult_y = {100, 200, 400, 7000, 1400, 2700, 54000}, }, [e05] = { .scale =61313 , .measurement_mode_freq = 200, + .measurement_mode_3db_freq = 60, .option_mode_1 = SCA3000_OP_MODE_NARROW, .option_mode_1_freq = 50, + .option_mode_1_3db_freq = 9, .option_mode_2 = SCA3000_OP_MODE_WIDE, .option_mode_2_freq = 400, + .option_mode_2_3db_freq = 75, .mot_det_mult_xz = {600, 900, 1700, 3200, 6100, 11900}, .mot_det_mult_y = {300, 600, 1200, 2000, 4100, 7800, 15600}, },
@@ -577,7 +590,8 @@ static const struct iio_event_spec sca3000_event = { .modified = 1, \ .channel2 = mod, \ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ - .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),\ + .info_mask_shared_by_type =BIT (IIO_CHAN_INFO_SCALE ) |\ + BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY),\ .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ),\ .address = index, \ .scan_index = index, \
@@ -737,6 +751,33 @@ static int write_raw_samp_freq(struct sca3000_state *st, int val) ctrlval); } +static int sca3000_read_3db_freq (struct sca3000_state *st,int *val) +{ +int ret; + + ret =sca3000_read_data_short (st,SCA3000_REG_MODE_ADDR ,1 ); +if (ret) +return ret; + +/* mask bottom 2 bits - only ones that are relevant */ + st->rx[0 ] &=SCA3000_REG_MODE_MODE_MASK ; +switch (st->rx[0 ]) { +case SCA3000_REG_MODE_MEAS_MODE_NORMAL : + *val = st->info->measurement_mode_3db_freq; +return IIO_VAL_INT ; +case SCA3000_REG_MODE_MEAS_MODE_MOT_DET : +return -EBUSY ; +case SCA3000_REG_MODE_MEAS_MODE_OP_1 : + *val = st->info->option_mode_1_3db_freq; +return IIO_VAL_INT ; +case SCA3000_REG_MODE_MEAS_MODE_OP_2 : + *val = st->info->option_mode_2_3db_freq; +return IIO_VAL_INT ; +default : +return -EINVAL ; + } +} + static int sca3000_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val,
@@ -794,6 +835,11 @@ static int sca3000_read_raw(struct iio_dev *indio_dev, ret =read_raw_samp_freq (st, val);mutex_unlock (&st->lock);return ret ? ret :IIO_VAL_INT ; +case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY : +mutex_lock (&st->lock); + ret =sca3000_read_3db_freq (st, val); +mutex_unlock (&st->lock); +return ret;default :return -EINVAL ; }
Signature · 1 line
2.10.0
Jonathan Cameron
maintainerPATCH v2 11/18 staging:iio:accel:sca3000: Fix off by one error in axis due to IIO_NO_MOD
In reply to Jonathan CameronGiven the introduction of IIO_NO_MOD was prior to the first submission prior to IIO entering staging this has been broken for a while.
--- drivers/staging/iio/accel/sca3000.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-)
drivers/staging/iio/accel/sca3000.c +11 -10
@@ -933,16 +933,17 @@ static int sca3000_read_event_value(struct iio_dev *indio_dev, {int ret, i;struct sca3000_state *st =iio_priv (indio_dev); -int num = chan->channel2; +switch (info) {case IIO_EV_INFO_VALUE :mutex_lock (&st->lock); - ret =sca3000_read_ctrl_reg (st, sca3000_addresses[num][1 ]); + ret =sca3000_read_ctrl_reg (st, + sca3000_addresses[chan->address][1 ]);mutex_unlock (&st->lock);if (ret <0 )return ret; *val =0 ; -if (num ==1 ) +if (chan->channel2 ==IIO_MOD_Y )for_each_set_bit (i, (unsigned long *)&ret,ARRAY_SIZE (st->info->mot_det_mult_y)) *val += st->info->mot_det_mult_y[i];
@@ -972,12 +973,11 @@ static int sca3000_write_event_value(struct iio_dev *indio_dev, int val, int val2) {struct sca3000_state *st =iio_priv (indio_dev); -int num = chan->channel2;int ret;int i;u8 nonlinear =0 ; -if (num ==IIO_MOD_Y ) { +if (chan->channel2 ==IIO_MOD_Y ) { i =ARRAY_SIZE (st->info->mot_det_mult_y);while (i >0 )if (val >= st->info->mot_det_mult_y[--i]) {
@@ -994,7 +994,9 @@ static int sca3000_write_event_value(struct iio_dev *indio_dev, }mutex_lock (&st->lock); - ret =sca3000_write_ctrl_reg (st, sca3000_addresses[num][1 ], nonlinear); + ret =sca3000_write_ctrl_reg (st, + sca3000_addresses[chan->address][1 ], + nonlinear);mutex_unlock (&st->lock);return ret;
@@ -1160,8 +1162,6 @@ static int sca3000_read_event_config(struct iio_dev *indio_dev, {struct sca3000_state *st =iio_priv (indio_dev);int ret; -int num = chan->channel2; -/* read current value of mode register */ mutex_lock (&st->lock);
@@ -1189,7 +1189,7 @@ static int sca3000_read_event_config(struct iio_dev *indio_dev,if (ret <0 ) goto error_ret;/* only supporting logical or's for now */ - ret = !!(ret & sca3000_addresses[num][2 ]); + ret = !!(ret & sca3000_addresses[chan->address][2 ]); }break ;default :
@@ -1305,7 +1305,8 @@ static int sca3000_write_event_config(struct iio_dev *indio_dev,case IIO_MOD_X :case IIO_MOD_Y :case IIO_MOD_Z : - ret =sca3000_motion_detect_set_state (indio_dev, chan->channel2, + ret =sca3000_motion_detect_set_state (indio_dev, + chan->address, state);break ;default :
Signature · 1 line
2.10.0
Jonathan Cameron
maintainerPATCH v2 12/18 staging:iio:accel:sca3000 Add write support to the low pass filter control
In reply to Jonathan CameronAlso includes an available attribute. The ordering of values appears a bit random, but as the ABI doesn't specify this and we already have both rising and falling lists I think this is fine.
--- drivers/staging/iio/accel/sca3000.c | 55 +++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+)
drivers/staging/iio/accel/sca3000.c +55 -0
@@ -432,6 +432,26 @@ error_ret:return ret ? ret : len; } +static ssize_t +sca3000_show_available_3db_freqs (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct iio_dev *indio_dev =dev_to_iio_dev (dev); +struct sca3000_state *st =iio_priv (indio_dev); +int len; + + len =sprintf (buf,"%d" , st->info->measurement_mode_3db_freq); +if (st->info->option_mode_1) + len +=sprintf (buf + len," %d" , + st->info->option_mode_1_3db_freq); +if (st->info->option_mode_2) + len +=sprintf (buf + len," %d" , + st->info->option_mode_2_3db_freq); + len +=sprintf (buf + len,"\n" ); + +return len; +}/** * sca3000_show_available_measurement_modes() display available modes *
@@ -570,6 +590,9 @@ static IIO_DEVICE_ATTR(measurement_mode, S_IRUGO | S_IWUSR, sca3000_store_measurement_mode, 0); +static IIO_DEVICE_ATTR(in_accel_filter_low_pass_3db_frequency_available, + S_IRUGO, sca3000_show_available_3db_freqs, + NULL, 0);/* More standard attributes */ static IIO_DEVICE_ATTR(revision, S_IRUGO, sca3000_show_rev, NULL, 0);
@@ -778,6 +801,31 @@ static int sca3000_read_3db_freq(struct sca3000_state *st, int *val) } } +static int sca3000_write_3db_freq (struct sca3000_state *st,int val) +{ +int ret; +int mode; + +if (val == st->info->measurement_mode_3db_freq) + mode =SCA3000_REG_MODE_MEAS_MODE_NORMAL ; +else if (st->info->option_mode_1 && + (val == st->info->option_mode_1_3db_freq)) + mode =SCA3000_REG_MODE_MEAS_MODE_OP_1 ; +else if (st->info->option_mode_2 && + (val == st->info->option_mode_2_3db_freq)) + mode =SCA3000_REG_MODE_MEAS_MODE_OP_2 ; +else +return -EINVAL ; + ret =sca3000_read_data_short (st,SCA3000_REG_MODE_ADDR ,1 ); +if (ret) +return ret; + + st->rx[0 ] &= ~SCA3000_REG_MODE_MODE_MASK ; + st->rx[0 ] |= (mode &SCA3000_REG_MODE_MODE_MASK ); + +return sca3000_write_reg (st,SCA3000_REG_MODE_ADDR , st->rx[0 ]); +} + static int sca3000_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val,
@@ -860,6 +908,12 @@ static int sca3000_write_raw(struct iio_dev *indio_dev, ret =write_raw_samp_freq (st, val);mutex_unlock (&st->lock);return ret; +case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY : +if (val2) +return -EINVAL ; +mutex_lock (&st->lock); + ret =sca3000_write_3db_freq (st, val); +mutex_unlock (&st->lock);default :return -EINVAL ; }
@@ -1006,6 +1060,7 @@ static struct attribute *sca3000_attributes[] = { &iio_dev_attr_revision.dev_attr.attr, &iio_dev_attr_measurement_mode_available.dev_attr.attr, &iio_dev_attr_measurement_mode.dev_attr.attr, + &iio_dev_attr_in_accel_filter_low_pass_3db_frequency_available.dev_attr.attr, &iio_dev_attr_sampling_frequency_available.dev_attr.attr, NULL, };
Signature · 1 line
2.10.0
Jonathan Cameron
maintainerPATCH v2 13/18 staging:iio:accel:sca3000 Drop custom measurement mode attributes
In reply to Jonathan CameronThis is now represented by the standard 3db filter frequency controls. Things get complex wrt to the sampling frequency as these modes change but that is fine under the IIO ABI where any value is allowed to effect any other.
--- drivers/staging/iio/accel/sca3000.c | 139 ------------------------------------ 1 file changed, 139 deletions(-)
drivers/staging/iio/accel/sca3000.c +0 -139
@@ -452,143 +452,6 @@ sca3000_show_available_3db_freqs(struct device *dev,return len; } -/** -* sca3000_show_available_measurement_modes() display available modes -* -* This is all read from chip specific data in the driver. Not all -* of the sca3000 series support modes other than normal. -**/ -static ssize_t -sca3000_show_available_measurement_modes (struct device *dev, -struct device_attribute *attr, -char *buf) -{ -struct iio_dev *indio_dev =dev_to_iio_dev (dev); -struct sca3000_state *st =iio_priv (indio_dev); -int len =0 ; - - len +=sprintf (buf + len,"0 - normal mode" ); -switch (st->info->option_mode_1) { -case SCA3000_OP_MODE_NARROW : - len +=sprintf (buf + len,", 1 - narrow mode" ); -break ; -case SCA3000_OP_MODE_BYPASS : - len +=sprintf (buf + len,", 1 - bypass mode" ); -break ; - } -switch (st->info->option_mode_2) { -case SCA3000_OP_MODE_WIDE : - len +=sprintf (buf + len,", 2 - wide mode" ); -break ; - } -/* always supported */ - len +=sprintf (buf + len," 3 - motion detection\n" ); - -return len; -} - -/** -* sca3000_show_measurement_mode() sysfs read of current mode -**/ -static ssize_t -sca3000_show_measurement_mode (struct device *dev, -struct device_attribute *attr, -char *buf) -{ -struct iio_dev *indio_dev =dev_to_iio_dev (dev); -struct sca3000_state *st =iio_priv (indio_dev); -int len =0 , ret; - -mutex_lock (&st->lock); - ret =sca3000_read_data_short (st,SCA3000_REG_MODE_ADDR ,1 ); -if (ret) - goto error_ret; -/* mask bottom 2 bits - only ones that are relevant */ - st->rx[0 ] &=SCA3000_REG_MODE_MODE_MASK ; -switch (st->rx[0 ]) { -case SCA3000_REG_MODE_MEAS_MODE_NORMAL : - len +=sprintf (buf + len,"0 - normal mode\n" ); -break ; -case SCA3000_REG_MODE_MEAS_MODE_MOT_DET : - len +=sprintf (buf + len,"3 - motion detection\n" ); -break ; -case SCA3000_REG_MODE_MEAS_MODE_OP_1 : -switch (st->info->option_mode_1) { -case SCA3000_OP_MODE_NARROW : - len +=sprintf (buf + len,"1 - narrow mode\n" ); -break ; -case SCA3000_OP_MODE_BYPASS : - len +=sprintf (buf + len,"1 - bypass mode\n" ); -break ; - } -break ; -case SCA3000_REG_MODE_MEAS_MODE_OP_2 : -switch (st->info->option_mode_2) { -case SCA3000_OP_MODE_WIDE : - len +=sprintf (buf + len,"2 - wide mode\n" ); -break ; - } -break ; - } - -error_ret: -mutex_unlock (&st->lock); - -return ret ? ret : len; -} - -/** -* sca3000_store_measurement_mode() set the current mode -**/ -static ssize_t -sca3000_store_measurement_mode (struct device *dev, -struct device_attribute *attr, -const char *buf, -size_t len) -{ -struct iio_dev *indio_dev =dev_to_iio_dev (dev); -struct sca3000_state *st =iio_priv (indio_dev); -int ret; -u8 val; - -mutex_lock (&st->lock); - ret =kstrtou8 (buf,10 , &val); -if (ret) - goto error_ret; -if (val >3 ) { - ret = -EINVAL ; - goto error_ret; - } - ret =sca3000_read_data_short (st,SCA3000_REG_MODE_ADDR ,1 ); -if (ret) - goto error_ret; - st->rx[0 ] &= ~SCA3000_REG_MODE_MODE_MASK ; - st->rx[0 ] |= (val &SCA3000_REG_MODE_MODE_MASK ); - ret =sca3000_write_reg (st,SCA3000_REG_MODE_ADDR , st->rx[0 ]); -if (ret) - goto error_ret; -mutex_unlock (&st->lock); - -return len; - -error_ret: -mutex_unlock (&st->lock); - -return ret; -} - -/* -* Not even vaguely standard attributes so defined here rather than -* in the relevant IIO core headers -*/ -static IIO_DEVICE_ATTR(measurement_mode_available, S_IRUGO, - sca3000_show_available_measurement_modes, - NULL, 0); - -static IIO_DEVICE_ATTR(measurement_mode, S_IRUGO | S_IWUSR, - sca3000_show_measurement_mode, - sca3000_store_measurement_mode, - 0); static IIO_DEVICE_ATTR(in_accel_filter_low_pass_3db_frequency_available, S_IRUGO, sca3000_show_available_3db_freqs,
@@ -1058,8 +921,6 @@ static int sca3000_write_event_value(struct iio_dev *indio_dev,static struct attribute *sca3000_attributes[] = { &iio_dev_attr_revision.dev_attr.attr, - &iio_dev_attr_measurement_mode_available.dev_attr.attr, - &iio_dev_attr_measurement_mode.dev_attr.attr, &iio_dev_attr_in_accel_filter_low_pass_3db_frequency_available.dev_attr.attr, &iio_dev_attr_sampling_frequency_available.dev_attr.attr,NULL ,
Signature · 1 line
2.10.0
Jonathan Cameron
maintainerPATCH v2 14/18 staging:iio:accel:sca3000 replace non standard revision attr with dev_info on probe
In reply to Jonathan CameronThere seems little point in being able to query the part revision number via sysfs. Hence just put it in the kernel logs during probe incase anyone ever wants to know.
--- drivers/staging/iio/accel/sca3000.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-)
drivers/staging/iio/accel/sca3000.c +12 -14
@@ -410,26 +410,23 @@ error_ret:/** * sca3000_show_rev() - sysfs interface to read the chip revision number **/ -static ssize_t sca3000_show_rev (struct device *dev, -struct device_attribute *attr, -char *buf) +static int sca3000_print_rev (struct iio_dev *indio_dev) { -int len =0 , ret; -struct iio_dev *indio_dev =dev_to_iio_dev (dev); +int ret;struct sca3000_state *st =iio_priv (indio_dev);mutex_lock (&st->lock); ret =sca3000_read_data_short (st,SCA3000_REG_REVID_ADDR ,1 );if (ret <0 ) goto error_ret; - len +=sprintf (buf + len, -"major=%lu, minor=%lu\n" , - st->rx[0 ] &SCA3000_REG_REVID_MAJOR_MASK , - st->rx[0 ] &SCA3000_REG_REVID_MINOR_MASK ); +dev_info (&indio_dev->dev, +"sca3000 revision major=%lu, minor=%lu\n" , + st->rx[0 ] &SCA3000_REG_REVID_MAJOR_MASK , + st->rx[0 ] &SCA3000_REG_REVID_MINOR_MASK ); error_ret:mutex_unlock (&st->lock); -return ret ? ret : len; +return ret; } static ssize_t
@@ -456,9 +453,6 @@ sca3000_show_available_3db_freqs(struct device *dev, static IIO_DEVICE_ATTR(in_accel_filter_low_pass_3db_frequency_available, S_IRUGO, sca3000_show_available_3db_freqs, NULL, 0); -/* More standard attributes */ - -static IIO_DEVICE_ATTR(revision, S_IRUGO, sca3000_show_rev, NULL, 0);static const struct iio_event_spec sca3000_event = { .type =IIO_EV_TYPE_MAG ,
@@ -920,7 +914,6 @@ static int sca3000_write_event_value(struct iio_dev *indio_dev, }static struct attribute *sca3000_attributes[] = { - &iio_dev_attr_revision.dev_attr.attr, &iio_dev_attr_in_accel_filter_low_pass_3db_frequency_available.dev_attr.attr, &iio_dev_attr_sampling_frequency_available.dev_attr.attr,NULL ,
@@ -1464,6 +1457,11 @@ static int sca3000_probe(struct spi_device *spi) ret =sca3000_clean_setup (st);if (ret) goto error_free_irq; + + ret =sca3000_print_rev (indio_dev); +if (ret) + goto error_free_irq; +return 0 ; error_free_irq:
Signature · 1 line
2.10.0
Jonathan Cameron
maintainerPATCH v2 15/18 staging:iio:accel:sca3000 Tidy up probe order to avoid a race.
In reply to Jonathan CameronPreviously the device was exposed to userspace and in kernel consumers before the interrupts had been configured. As nothing stopped them being enabled in the interval this could cause unhandled interrupts.
--- drivers/staging/iio/accel/sca3000.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
drivers/staging/iio/accel/sca3000.c +6 -8
@@ -1439,9 +1439,6 @@ static int sca3000_probe(struct spi_device *spi) indio_dev->modes =INDIO_DIRECT_MODE ;sca3000_configure_ring (indio_dev); - ret =iio_device_register (indio_dev); -if (ret <0 ) -return ret;if (spi->irq) { ret = request_threaded_irq(spi->irq,
@@ -1451,7 +1448,7 @@ static int sca3000_probe(struct spi_device *spi)"sca3000" , indio_dev);if (ret) - goto error_unregister_dev; +return ret; } indio_dev->setup_ops = &sca3000_ring_setup_ops; ret =sca3000_clean_setup (st);
@@ -1462,13 +1459,12 @@ static int sca3000_probe(struct spi_device *spi)if (ret) goto error_free_irq; -return 0 ; +return iio_device_register (indio_dev); error_free_irq:if (spi->irq)free_irq (spi->irq, indio_dev); -error_unregister_dev: -iio_device_unregister (indio_dev); +return ret; }
@@ -1495,11 +1491,13 @@ static int sca3000_remove(struct spi_device *spi)struct iio_dev *indio_dev =spi_get_drvdata (spi);struct sca3000_state *st =iio_priv (indio_dev); +iio_device_unregister (indio_dev); +/* Must ensure no interrupts can be generated after this! */ sca3000_stop_all_interrupts (st);if (spi->irq)free_irq (spi->irq, indio_dev); -iio_device_unregister (indio_dev); +sca3000_unconfigure_ring (indio_dev);return 0 ;
Signature · 1 line
2.10.0
Jonathan Cameron
maintainerPATCH v2 16/18 staging:iio:accel:sca3000 small checkpatch fixes (alignment etc)
In reply to Jonathan CameronTidied up where checkpatch warning suppressions doesn't effect the readability of the code.
--- drivers/staging/iio/accel/sca3000.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/iio/accel/sca3000.c +2 -2
@@ -274,8 +274,8 @@ static int sca3000_write_reg(struct sca3000_state *st, u8 address, u8 val) }static int sca3000_read_data_short (struct sca3000_state *st, -u8 reg_address_high, -int len) +u8 reg_address_high, +int len) {struct spi_transfer xfer[2 ] = { {
Signature · 1 line
2.10.0
Jonathan Cameron
maintainerPATCH v2 17/18 staging:iio:accel:sca3000 kernel docify comments that were nearly kernel doc.
In reply to Jonathan CameronBasic tidy up of comments to bring them into a standard style.
--- drivers/staging/iio/accel/sca3000.c | 106 ++++++++++++++++++++++++++---------- 1 file changed, 77 insertions(+), 29 deletions(-)
drivers/staging/iio/accel/sca3000.c +77 -29
@@ -178,10 +178,20 @@ struct sca3000_state {* @scale: scale * 10^-6 * @temp_output: some devices have temperature sensors. * @measurement_mode_freq: normal mode sampling frequency +* @measurement_mode_3db_freq: 3db cutoff frequency of the low pass filter for +* the normal measurement mode. * @option_mode_1: first optional mode. Not all models have one * @option_mode_1_freq: option mode 1 sampling frequency +* @option_mode_1_3db_freq: 3db cutoff frequency of the low pass filter for +* the first option mode. * @option_mode_2: second optional mode. Not all chips have one * @option_mode_2_freq: option mode 2 sampling frequency +* @option_mode_2_3db_freq: 3db cutoff frequency of the low pass filter for +* the second option mode. +* @mod_det_mult_xz: Bit wise multipliers to calculate the threshold +* for motion detection in the x and z axis. +* @mod_det_mult_y: Bit wise multipliers to calculate the threshold +* for motion detection in the y axis. * * This structure is used to hold information about the functionality of a given * sca3000 variant.
@@ -292,7 +302,8 @@ static int sca3000_read_data_short(struct sca3000_state *st, }/** -* sca3000_reg_lock_on() test if the ctrl register lock is on +* sca3000_reg_lock_on() - test if the ctrl register lock is on +* @st: Driver specific device instance data. * * Lock must be held. **/
@@ -308,12 +319,13 @@ static int sca3000_reg_lock_on(struct sca3000_state *st) }/** -* __sca3000_unlock_reg_lock() unlock the control registers +* __sca3000_unlock_reg_lock() - unlock the control registers +* @st: Driver specific device instance data. * * Note the device does not appear to support doing this in a single transfer. * This should only ever be used as part of ctrl reg read. * Lock must be held before calling this -**/ +*/ static int __sca3000_unlock_reg_lock (struct sca3000_state *st) {struct spi_transfer xfer[3 ] = {
@@ -342,6 +354,7 @@ static int __sca3000_unlock_reg_lock(struct sca3000_state *st)/** * sca3000_write_ctrl_reg() write to a lock protect ctrl register +* @st: Driver specific device instance data. * @sel: selects which registers we wish to write to * @val: the value to be written *
@@ -349,7 +362,7 @@ static int __sca3000_unlock_reg_lock(struct sca3000_state *st)* register and use a shared write address. This function allows writing of * these registers. * Lock must be held. -**/ +*/ static int sca3000_write_ctrl_reg (struct sca3000_state *st,u8 sel,uint8_t val)
@@ -379,9 +392,11 @@ error_ret:/** * sca3000_read_ctrl_reg() read from lock protected control register. +* @st: Driver specific device instance data. +* @ctrl_reg: Which ctrl register do we want to read. * * Lock must be held. -**/ +*/ static int sca3000_read_ctrl_reg (struct sca3000_state *st,u8 ctrl_reg) {
@@ -409,7 +424,10 @@ error_ret:/** * sca3000_show_rev() - sysfs interface to read the chip revision number -**/ +* @indio_dev: Device instance specific generic IIO data. +* Driver specific device instance data can be obtained via +* via iio_priv(indio_dev) +*/ static int sca3000_print_rev (struct iio_dev *indio_dev) {int ret;
@@ -539,10 +557,13 @@ static u8 sca3000_addresses[3][3] = { };/** -* __sca3000_get_base_freq() obtain mode specific base frequency +* __sca3000_get_base_freq() - obtain mode specific base frequency +* @st: Private driver specific device instance specific state. +* @info: chip type specific information. +* @base_freq: Base frequency for the current measurement mode. * * lock must be held -**/ +*/ static inline int __sca3000_get_base_freq (struct sca3000_state *st,const struct sca3000_chip_info *info,int *base_freq)
@@ -570,11 +591,13 @@ error_ret: }/** -* read_raw handler for IIO_CHAN_INFO_SAMP_FREQ +* sca3000_read_raw_samp_freq() - read_raw handler for IIO_CHAN_INFO_SAMP_FREQ +* @st: Private driver specific device instance specific state. +* @val: The frequency read back. * * lock must be held **/ -static int read_raw_samp_freq (struct sca3000_state *st,int *val) +static int sca3000_read_raw_samp_freq (struct sca3000_state *st,int *val) {int ret;
@@ -602,11 +625,13 @@ static int read_raw_samp_freq(struct sca3000_state *st, int *val) }/** -* write_raw handler for IIO_CHAN_INFO_SAMP_FREQ +* sca3000_write_raw_samp_freq() - write_raw handler for IIO_CHAN_INFO_SAMP_FREQ +* @st: Private driver specific device instance specific state. +* @val: The frequency desired. * * lock must be held -**/ -static int write_raw_samp_freq (struct sca3000_state *st,int val) +*/ +static int sca3000_write_raw_samp_freq (struct sca3000_state *st,int val) {int ret, base_freq, ctrlval;
@@ -737,7 +762,7 @@ static int sca3000_read_raw(struct iio_dev *indio_dev,return IIO_VAL_INT_PLUS_MICRO ;case IIO_CHAN_INFO_SAMP_FREQ :mutex_lock (&st->lock); - ret =read_raw_samp_freq (st, val); + ret =sca3000_read_raw_samp_freq (st, val);mutex_unlock (&st->lock);return ret ? ret :IIO_VAL_INT ;case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY :
@@ -762,7 +787,7 @@ static int sca3000_write_raw(struct iio_dev *indio_dev,if (val2)return -EINVAL ;mutex_lock (&st->lock); - ret =write_raw_samp_freq (st, val); + ret =sca3000_write_raw_samp_freq (st, val);mutex_unlock (&st->lock);return ret;case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY :
@@ -779,7 +804,10 @@ static int sca3000_write_raw(struct iio_dev *indio_dev, }/** -* sca3000_read_av_freq() sysfs function to get available frequencies +* sca3000_read_av_freq() - sysfs function to get available frequencies +* @dev: Device structure for this device. +* @attr: Description of the attribute. +* @buf: Incoming string * * The later modes are only relevant to the ring buffer - and depend on current * mode. Note that data sheet gives rather wide tolerances for these so integer
@@ -874,8 +902,18 @@ static int sca3000_read_event_value(struct iio_dev *indio_dev, }/** -* sca3000_write_value() control of threshold and period -**/ +* sca3000_write_value() - control of threshold and period +* @indio_dev: Device instance specific IIO information. +* @chan: Description of the channel for which the event is being +* configured. +* @type: The type of event being configured, here magnitude rising +* as everything else is read only. +* @dir: Direction of the event (here rising) +* @info: What information about the event are we configuring. +* Here the threshold only. +* @val: Integer part of the value being written.. +* @val2: Non integer part of the value being written. Here always 0. +*/ static int sca3000_write_event_value(struct iio_dev *indio_dev, const struct iio_chan_spec *chan, enum iio_event_type type,
@@ -950,11 +988,10 @@ static int sca3000_read_data(struct sca3000_state *st, }/** -* sca3000_ring_int_process() ring specific interrupt handling. -* -* This is only split from the main interrupt handler so as to -* reduce the amount of code if the ring buffer is not enabled. -**/ +* sca3000_ring_int_process() - ring specific interrupt handling. +* @val: Value of the interrupt status register. +* @indio_dev: Device instance specific IIO device structure. +*/ static void sca3000_ring_int_process (u8 val,struct iio_dev *indio_dev) {struct sca3000_state *st =iio_priv (indio_dev);
@@ -993,6 +1030,8 @@ error_ret:/** * sca3000_event_handler() - handling ring and non ring events +* @irq: The irq being handled. +* @private: struct iio_device pointer for the device. * * Ring related interrupt handler. Depending on event, push to * the ring buffer event chrdev or the event one.
@@ -1000,7 +1039,7 @@ error_ret:* This function is complicated by the fact that the devices can signify ring * and non ring events via the same interrupt line and they can only * be distinguished via a read of the relevant status register. -**/ +*/ static irqreturn_t sca3000_event_handler (int irq,void *private) {struct iio_dev *indio_dev = private;
@@ -1188,7 +1227,13 @@ static int sca3000_motion_detect_set_state(struct iio_dev *indio_dev, int axis, }/** -* sca3000_write_event_config() simple on off control for motion detector +* sca3000_write_event_config() - simple on off control for motion detector +* @indio_dev: IIO device instance specific structure. Data specific to this +* particular driver may be accessed via iio_priv(indio_dev). +* @chan: Description of the channel whose event we are configuring. +* @type: The type of event. +* @dir: The direction of the event. +* @state: Desired state of event being configured. * * This is a per axis control, but enabling any will result in the * motion detector unit being enabled.
@@ -1272,12 +1317,14 @@ error_ret: }/** -* sca3000_hw_ring_preenable() hw ring buffer preenable function +* sca3000_hw_ring_preenable() - hw ring buffer preenable function +* @indio_dev: structure representing the IIO device. Device instance +* specific state can be accessed via iio_priv(indio_dev). * * Very simple enable function as the chip will allows normal reads * during ring buffer operation so as long as it is indeed running * before we notify the core, the precise ordering does not matter. -**/ +*/ static int sca3000_hw_ring_preenable (struct iio_dev *indio_dev) {int ret;
@@ -1334,12 +1381,13 @@ static const struct iio_buffer_setup_ops sca3000_ring_setup_ops = { };/** -* sca3000_clean_setup() get the device into a predictable state +* sca3000_clean_setup() - get the device into a predictable state +* @st: Device instance specific private data structure * * Devices use flash memory to store many of the register values * and hence can come up in somewhat unpredictable states. * Hence reset everything on driver load. -**/ +*/ static int sca3000_clean_setup (struct sca3000_state *st) {int ret;
Signature · 1 line
2.10.0
Jonathan Cameron
maintainerPATCH v2 18/18 staging:iio:accel:sca3000 Move out of staging.
In reply to Jonathan CameronNow the driver is in a reasonable state, lets get it (finally) out of staging.
---
drivers/iio/accel/Kconfig | 12 ++++++++++++
drivers/iio/accel/Makefile | 2 ++
drivers/{staging => }/iio/accel/sca3000.c | 0
drivers/staging/iio/accel/Kconfig | 11 -----------
drivers/staging/iio/accel/Makefile | 2 --
5 files changed, 14 insertions(+), 13 deletions(-)drivers/iio/accel/Kconfig +12 -0
@@ -283,6 +283,18 @@ config MXC6255 To compile this driver as a module, choose M here: the module will be called mxc6255. +config SCA3000 + select IIO_BUFFER + select IIO_KFIFO_BUF + depends on SPI + tristate "VTI SCA3000 series accelerometers" + help + Say Y here to build support for the VTI SCA3000 series of SPI + accelerometers. These devices use a hardware ring buffer. + + To compile this driver as a module, say M here: the module will be + called sca3000. + config STK8312 tristate "Sensortek STK8312 3-Axis Accelerometer Driver" depends on I2C
drivers/iio/accel/Makefile +2 -0
@@ -33,6 +33,8 @@ obj-$(CONFIG_MMA9553) += mma9553.o obj-$(CONFIG_MXC4005) += mxc4005.o obj-$(CONFIG_MXC6255) += mxc6255.o +obj-$(CONFIG_SCA3000) += sca3000.o + obj-$(CONFIG_STK8312) += stk8312.o obj-$(CONFIG_STK8BA50) += stk8ba50.o
drivers/iio/accel/sca3000.c renamed from drivers/staging/iio/accel/sca3000.c +0 -0
drivers/staging/iio/accel/Kconfig +0 -11
@@ -51,15 +51,4 @@ config ADIS16240 To compile this driver as a module, say M here: the module will be called adis16240. -config SCA3000 - select IIO_BUFFER - select IIO_KFIFO_BUF - depends on SPI - tristate "VTI SCA3000 series accelerometers" - help - Say Y here to build support for the VTI SCA3000 series of SPI - accelerometers. These devices use a hardware ring buffer. - - To compile this driver as a module, say M here: the module will be - called sca3000. endmenu
drivers/staging/iio/accel/Makefile +0 -2
@@ -13,5 +13,3 @@ obj-$(CONFIG_ADIS16209) += adis16209.o adis16240-y := adis16240_core.o obj-$(CONFIG_ADIS16240) += adis16240.o - -obj-$(CONFIG_SCA3000) += sca3000.o
Signature · 1 line
2.10.0
Jonathan Cameron
maintainer*Smiles sweetly at the list*
Go on, someone give me a review on these.
Thanks,
Jonathan
Quoted 87 lines · Jonathan Cameron
Changes since V1:
- Fix the patch that breaks the makefile due to a := when it should be += It didn't make it to the end of the set, but broke building of other drivers in the middle (thanks Lars-Peter Clausen)
- Drop the unwanted buffer setup after the move to the hybrid hardware / software buffer (Lars-Peter Clausen)
- Usechan->addressrather than the modifier to index the address array. (Lars-Peter Clausen)
- Typo and gibberish fixups (Peter Meerwald-Stadhler)V1 Message
This was around about the 4th IIO driver dating back to the days when I was sticking these on sprinters and seeing if we could learn anything useful about how they ran.
It was a device way ahead of it's time. Back then this was pretty much the only relatively high G / low cost sensor and it had a hardware fifo.
Anyhow, it has languished in staging primarily because of the complexity around working out how we handle hardware buffers. However, that trail has long since been blaized by the likes of the am335x driver and now lots of of newer devices are coming with fifos to smooth the flow of data between these realtime chips and non realtime operating sytems, so it just became a question of getting around to sorting it out. I suspect there are very few of these still out there, but I have an sca3000-e05 so that's no excuse
Anyhow, please review the whole series, but in particular the final move patch (i.e. the resulting code). The only odd corner I know of now is the interaction of the watermark with the software controlled watermarks. That may take some thought, but in the meantime I don't think that is sufficient reason to keep it in staging.
Some wacky corners in this hardware (like the crazy number representations for the motion detection thresholds). It's a good datasheet but you do have to wonder what the designers were thinking at times
Jonathan
p.s. The best bit about this series is now I can moan at everyone else about not cleaning up their staging drivers as this is the last one of mine.
Jonathan Cameron (18):
staging:iio:accel:sca3000 Fix a use before setting of theindio_dev->buffer pointer.staging:iio:accel:sca3000 merge files into one. staging:iio:accel:sca3000 drop
sca3000_register_ring_funcsstaging:iio:accel:sca3000 Fix clearing of flag + setting of size of
scan.
staging:iio:accel:sca3000 Drop custom ABI for watersheds. staging:iio:accel:sca3000 move to hybrid hard / soft buffer design. staging:iio:accel:sca3000 drop some unused variables. staging:iio:accel:sca3000 use a 'fake' channel to handle freefall
event registration.
staging:iio:accel:sca3000 Clean up register defines. staging:iio:accel:sca3000 add readback of the 3db low pass filter
frequency
staging:iio:accel:sca3000: Fix off by one error in axis due to
IIO_NO_MOD
staging:iio:accel:sca3000 Add write support to the low pass filter
control
staging:iio:accel:sca3000 Drop custom measurement mode attributes staging:iio:accel:sca3000 replace non standard revision attr with
dev_infoon probe
staging:iio:accel:sca3000 Tidy up probe order to avoid a race. staging:iio:accel:sca3000 small checkpatch fixes (alignment etc) staging:iio:accel:sca3000 kernel docify comments that were nearly
kernel doc.
staging:iio:accel:sca3000 Move out of staging.drivers/iio/accel/Kconfig | 12 + drivers/iio/accel/Makefile | 2 + drivers/iio/accel/sca3000.c | 1575 ++++++++++++++++++++++++++++++ drivers/staging/iio/accel/Kconfig | 10 - drivers/staging/iio/accel/Makefile | 3 - drivers/staging/iio/accel/sca3000.h | 279 ------ drivers/staging/iio/accel/sca3000_core.c | 1210 ----------------------- drivers/staging/iio/accel/sca3000_ring.c | 350 ------- drivers/staging/iio/ring_hw.h | 27 - 9 files changed, 1589 insertions(+), 1879 deletions(-) create mode 100644 drivers/iio/accel/sca3000.c delete mode 100644 drivers/staging/iio/accel/sca3000.h delete mode 100644 drivers/staging/iio/accel/sca3000_core.c delete mode 100644 drivers/staging/iio/accel/sca3000_ring.c delete mode 100644 drivers/staging/iio/ring_hw.h
Lars-Peter Clausen
Reviewed-byQuoted 3 lines · Jonathan Cameron
*Smiles sweetly at the list*
Go on, someone give me a review on these.
Looks good, otherwise I'd complained ;)
Quoted 94 lines
Thanks,
Jonathan
Quoted 87 lines · Jonathan Cameron
Changes since V1:
- Fix the patch that breaks the makefile due to a := when it should be += It didn't make it to the end of the set, but broke building of other drivers in the middle (thanks Lars-Peter Clausen)
- Drop the unwanted buffer setup after the move to the hybrid hardware / software buffer (Lars-Peter Clausen)
- Usechan->addressrather than the modifier to index the address array. (Lars-Peter Clausen)
- Typo and gibberish fixups (Peter Meerwald-Stadhler)V1 Message
This was around about the 4th IIO driver dating back to the days when I was sticking these on sprinters and seeing if we could learn anything useful about how they ran.
It was a device way ahead of it's time. Back then this was pretty much the only relatively high G / low cost sensor and it had a hardware fifo.
Anyhow, it has languished in staging primarily because of the complexity around working out how we handle hardware buffers. However, that trail has long since been blaized by the likes of the am335x driver and now lots of of newer devices are coming with fifos to smooth the flow of data between these realtime chips and non realtime operating sytems, so it just became a question of getting around to sorting it out. I suspect there are very few of these still out there, but I have an sca3000-e05 so that's no excuse
Anyhow, please review the whole series, but in particular the final move patch (i.e. the resulting code). The only odd corner I know of now is the interaction of the watermark with the software controlled watermarks. That may take some thought, but in the meantime I don't think that is sufficient reason to keep it in staging.
Some wacky corners in this hardware (like the crazy number representations for the motion detection thresholds). It's a good datasheet but you do have to wonder what the designers were thinking at times
Jonathan
p.s. The best bit about this series is now I can moan at everyone else about not cleaning up their staging drivers as this is the last one of mine.
Jonathan Cameron (18):
staging:iio:accel:sca3000 Fix a use before setting of theindio_dev->buffer pointer.staging:iio:accel:sca3000 merge files into one. staging:iio:accel:sca3000 drop
sca3000_register_ring_funcsstaging:iio:accel:sca3000 Fix clearing of flag + setting of size of
scan.
staging:iio:accel:sca3000 Drop custom ABI for watersheds. staging:iio:accel:sca3000 move to hybrid hard / soft buffer design. staging:iio:accel:sca3000 drop some unused variables. staging:iio:accel:sca3000 use a 'fake' channel to handle freefall
event registration.
staging:iio:accel:sca3000 Clean up register defines. staging:iio:accel:sca3000 add readback of the 3db low pass filter
frequency
staging:iio:accel:sca3000: Fix off by one error in axis due to
IIO_NO_MOD
staging:iio:accel:sca3000 Add write support to the low pass filter
control
staging:iio:accel:sca3000 Drop custom measurement mode attributes staging:iio:accel:sca3000 replace non standard revision attr with
dev_infoon probe
staging:iio:accel:sca3000 Tidy up probe order to avoid a race. staging:iio:accel:sca3000 small checkpatch fixes (alignment etc) staging:iio:accel:sca3000 kernel docify comments that were nearly
kernel doc.
staging:iio:accel:sca3000 Move out of staging.drivers/iio/accel/Kconfig | 12 + drivers/iio/accel/Makefile | 2 + drivers/iio/accel/sca3000.c | 1575 ++++++++++++++++++++++++++++++ drivers/staging/iio/accel/Kconfig | 10 - drivers/staging/iio/accel/Makefile | 3 - drivers/staging/iio/accel/sca3000.h | 279 ------ drivers/staging/iio/accel/sca3000_core.c | 1210 ----------------------- drivers/staging/iio/accel/sca3000_ring.c | 350 ------- drivers/staging/iio/ring_hw.h | 27 - 9 files changed, 1589 insertions(+), 1879 deletions(-) create mode 100644 drivers/iio/accel/sca3000.c delete mode 100644 drivers/staging/iio/accel/sca3000.h delete mode 100644 drivers/staging/iio/accel/sca3000_core.c delete mode 100644 drivers/staging/iio/accel/sca3000_ring.c delete mode 100644 drivers/staging/iio/ring_hw.h
Jonathan Cameron
maintainerQuoted 8 lines · Lars-Peter Clausen
Quoted 3 lines · Jonathan Cameron
*Smiles sweetly at the list*
Go on, someone give me a review on these.
Looks good, otherwise I'd complained ;)
Reviewed-by Lars-Peter Clausen <[email protected]>
Cool. Don't want to add to those stats of applied with no sign offs or reviews other than the author ;)
Jonathan
Quoted 96 lines
Quoted 95 lines
Thanks,
Jonathan
Quoted 87 lines · Jonathan Cameron
Changes since V1:
- Fix the patch that breaks the makefile due to a := when it should be += It didn't make it to the end of the set, but broke building of other drivers in the middle (thanks Lars-Peter Clausen)
- Drop the unwanted buffer setup after the move to the hybrid hardware / software buffer (Lars-Peter Clausen)
- Usechan->addressrather than the modifier to index the address array. (Lars-Peter Clausen)
- Typo and gibberish fixups (Peter Meerwald-Stadhler)V1 Message
This was around about the 4th IIO driver dating back to the days when I was sticking these on sprinters and seeing if we could learn anything useful about how they ran.
It was a device way ahead of it's time. Back then this was pretty much the only relatively high G / low cost sensor and it had a hardware fifo.
Anyhow, it has languished in staging primarily because of the complexity around working out how we handle hardware buffers. However, that trail has long since been blaized by the likes of the am335x driver and now lots of of newer devices are coming with fifos to smooth the flow of data between these realtime chips and non realtime operating sytems, so it just became a question of getting around to sorting it out. I suspect there are very few of these still out there, but I have an sca3000-e05 so that's no excuse
Anyhow, please review the whole series, but in particular the final move patch (i.e. the resulting code). The only odd corner I know of now is the interaction of the watermark with the software controlled watermarks. That may take some thought, but in the meantime I don't think that is sufficient reason to keep it in staging.
Some wacky corners in this hardware (like the crazy number representations for the motion detection thresholds). It's a good datasheet but you do have to wonder what the designers were thinking at times
Jonathan
p.s. The best bit about this series is now I can moan at everyone else about not cleaning up their staging drivers as this is the last one of mine.
Jonathan Cameron (18):
staging:iio:accel:sca3000 Fix a use before setting of theindio_dev->buffer pointer.staging:iio:accel:sca3000 merge files into one. staging:iio:accel:sca3000 drop
sca3000_register_ring_funcsstaging:iio:accel:sca3000 Fix clearing of flag + setting of size of
scan.
staging:iio:accel:sca3000 Drop custom ABI for watersheds. staging:iio:accel:sca3000 move to hybrid hard / soft buffer design. staging:iio:accel:sca3000 drop some unused variables. staging:iio:accel:sca3000 use a 'fake' channel to handle freefall
event registration.
staging:iio:accel:sca3000 Clean up register defines. staging:iio:accel:sca3000 add readback of the 3db low pass filter
frequency
staging:iio:accel:sca3000: Fix off by one error in axis due to
IIO_NO_MOD
staging:iio:accel:sca3000 Add write support to the low pass filter
control
staging:iio:accel:sca3000 Drop custom measurement mode attributes staging:iio:accel:sca3000 replace non standard revision attr with
dev_infoon probe
staging:iio:accel:sca3000 Tidy up probe order to avoid a race. staging:iio:accel:sca3000 small checkpatch fixes (alignment etc) staging:iio:accel:sca3000 kernel docify comments that were nearly
kernel doc.
staging:iio:accel:sca3000 Move out of staging.drivers/iio/accel/Kconfig | 12 + drivers/iio/accel/Makefile | 2 + drivers/iio/accel/sca3000.c | 1575 ++++++++++++++++++++++++++++++ drivers/staging/iio/accel/Kconfig | 10 - drivers/staging/iio/accel/Makefile | 3 - drivers/staging/iio/accel/sca3000.h | 279 ------ drivers/staging/iio/accel/sca3000_core.c | 1210 ----------------------- drivers/staging/iio/accel/sca3000_ring.c | 350 ------- drivers/staging/iio/ring_hw.h | 27 - 9 files changed, 1589 insertions(+), 1879 deletions(-) create mode 100644 drivers/iio/accel/sca3000.c delete mode 100644 drivers/staging/iio/accel/sca3000.h delete mode 100644 drivers/staging/iio/accel/sca3000_core.c delete mode 100644 drivers/staging/iio/accel/sca3000_ring.c delete mode 100644 drivers/staging/iio/ring_hw.h
Jonathan Cameron
maintainerQuoted 11 lines · Jonathan Cameron
Quoted 8 lines · Lars-Peter Clausen
Quoted 3 lines · Jonathan Cameron
*Smiles sweetly at the list*
Go on, someone give me a review on these.
Looks good, otherwise I'd complained ;)
Reviewed-by Lars-Peter Clausen <[email protected]>Cool. Don't want to add to those stats of applied with no sign offs or reviews other than the author ;)
All applied and pushed out as testing to see what I missed.
Thanks,
Jonathan
Quoted 104 lines
Jonathan
Quoted 87 lines
Quoted 87 lines
Thanks,
Jonathan
Quoted 80 lines · Jonathan Cameron
Changes since V1:
- Fix the patch that breaks the makefile due to a := when it should be += It didn't make it to the end of the set, but broke building of other drivers in the middle (thanks Lars-Peter Clausen)
- Drop the unwanted buffer setup after the move to the hybrid hardware / software buffer (Lars-Peter Clausen)
- Usechan->addressrather than the modifier to index the address array. (Lars-Peter Clausen)
- Typo and gibberish fixups (Peter Meerwald-Stadhler)V1 Message
This was around about the 4th IIO driver dating back to the days when I was sticking these on sprinters and seeing if we could learn anything useful about how they ran.
It was a device way ahead of it's time. Back then this was pretty much the only relatively high G / low cost sensor and it had a hardware fifo.
Anyhow, it has languished in staging primarily because of the complexity around working out how we handle hardware buffers. However, that trail has long since been blaized by the likes of the am335x driver and now lots of of newer devices are coming with fifos to smooth the flow of data between these realtime chips and non realtime operating sytems, so it just became a question of getting around to sorting it out. I suspect there are very few of these still out there, but I have an sca3000-e05 so that's no excuse
Anyhow, please review the whole series, but in particular the final move patch (i.e. the resulting code). The only odd corner I know of now is the interaction of the watermark with the software controlled watermarks. That may take some thought, but in the meantime I don't think that is sufficient reason to keep it in staging.
Some wacky corners in this hardware (like the crazy number representations for the motion detection thresholds). It's a good datasheet but you do have to wonder what the designers were thinking at times
Jonathan
p.s. The best bit about this series is now I can moan at everyone else about not cleaning up their staging drivers as this is the last one of mine.
Jonathan Cameron (18):
staging:iio:accel:sca3000 Fix a use before setting of theindio_dev->buffer pointer.staging:iio:accel:sca3000 merge files into one. staging:iio:accel:sca3000 drop
sca3000_register_ring_funcsstaging:iio:accel:sca3000 Fix clearing of flag + setting of size of
scan.
staging:iio:accel:sca3000 Drop custom ABI for watersheds. staging:iio:accel:sca3000 move to hybrid hard / soft buffer design. staging:iio:accel:sca3000 drop some unused variables. staging:iio:accel:sca3000 use a 'fake' channel to handle freefall
event registration.
staging:iio:accel:sca3000 Clean up register defines. staging:iio:accel:sca3000 add readback of the 3db low pass filter
frequency
staging:iio:accel:sca3000: Fix off by one error in axis due to
IIO_NO_MOD
staging:iio:accel:sca3000 Add write support to the low pass filter
control
staging:iio:accel:sca3000 Drop custom measurement mode attributes staging:iio:accel:sca3000 replace non standard revision attr with
dev_infoon probe
staging:iio:accel:sca3000 Tidy up probe order to avoid a race. staging:iio:accel:sca3000 small checkpatch fixes (alignment etc) staging:iio:accel:sca3000 kernel docify comments that were nearly
kernel doc.
staging:iio:accel:sca3000 Move out of staging.drivers/iio/accel/Kconfig | 12 + drivers/iio/accel/Makefile | 2 + drivers/iio/accel/sca3000.c | 1575 ++++++++++++++++++++++++++++++ drivers/staging/iio/accel/Kconfig | 10 - drivers/staging/iio/accel/Makefile | 3 - drivers/staging/iio/accel/sca3000.h | 279 ------ drivers/staging/iio/accel/sca3000_core.c | 1210 ----------------------- drivers/staging/iio/accel/sca3000_ring.c | 350 ------- drivers/staging/iio/ring_hw.h | 27 -Quoted 9 lines
Quoted 8 lines
Quoted 7 lines
9 files changed, 1589 insertions(+), 1879 deletions(-) create mode 100644 drivers/iio/accel/sca3000.c delete mode 100644 drivers/staging/iio/accel/sca3000.h delete mode 100644 drivers/staging/iio/accel/sca3000_core.c delete mode 100644 drivers/staging/iio/accel/sca3000_ring.c delete mode 100644 drivers/staging/iio/ring_hw.h--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html