drivers: iio: dummy: Unable to add channels to simple_dummy_channel
Himanshu Jha
himanshujha199640 at gmail.com
Thu Jan 24 06:05:16 EST 2019
On Wed, Jan 23, 2019 at 11:25:59PM +0530, Bharath Vedartham wrote:
> I am trying to add the 3-axis compass data channels to the
> simple_dummy_channel. I have mounted configfs and am able to load the
> modules correctly. Is this the right approach? printk is not printing
> anything to syslogs.
>
> This is part of the iio_tasks in (I have finished the first 2 tasks):
>
> https://kernelnewbies.org/IIO_tasks
>
> output of lsmod | grep dummy:
>
> iio_dummy 20480 2
> iio_dummy_evgen 16384 1 iio_dummy
>
> output of ls /sys/bus/iio/devices/iio:device0/:
>
> buffer in_sampling_frequency
> in_voltage-voltage_scale
> current_timestamp_clock in_steps_calibheight name
> dev in_steps_en out_voltage0_raw
> events in_steps_input power
> in_accel_x_calibbias in_voltage0_offset scan_elements
> in_accel_x_calibscale in_voltage0_raw subsystem
> in_accel_x_raw in_voltage0_scale trigger
> in_activity_running_input in_voltage1-voltage2_raw uevent
> in_activity_walking_input in_voltage3-voltage4_raw
>
> I have also put the diff.Added channel to iio_dummy_channels and added
> element to enum simple_dummy_scan_elements.
>
> Thank you,
> Bharath
>
> ---
> drivers/iio/dummy/iio_simple_dummy.c | 43 ++++++++++++++++++++++++++++++++++++
> drivers/iio/dummy/iio_simple_dummy.h | 3 +++
> 2 files changed, 46 insertions(+)
>
> diff --git a/drivers/iio/dummy/iio_simple_dummy.c b/drivers/iio/dummy/iio_simple_dummy.c
> index 6205247..306e0cd 100644
> --- a/drivers/iio/dummy/iio_simple_dummy.c
> +++ b/drivers/iio/dummy/iio_simple_dummy.c
> @@ -268,6 +268,48 @@ static const struct iio_chan_spec iio_dummy_channels[] = {
> .num_event_specs = 1,
> #endif /* CONFIG_IIO_SIMPLE_DUMMY_EVENTS */
> },
> + {
> + .type = IIO_MAGN,
> + .modified = 1,
> + .channel2 = IIO_MOD_X,
> + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
> + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
> + .scan_index = DUMMY_INDEX_MAGNX,
> + .scan_type = {
> + .sign = 'u',
> + .realbits = 16,
> + .storagebits = 16,
> + .shift = 0,
> + },
> + },
> + {
> + .type = IIO_MAGN,
> + .modified = 1,
> + .channel2 = IIO_MOD_Y,
> + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
> + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
> + .scan_index = DUMMY_INDEX_MAGNY,
> + .scan_type = {
> + .sign = 'u',
> + .realbits= 16,
> + .storagebits = 16,
> + .shift = 0,
> + },
> + },
> + {
> + .type = IIO_MAGN,
> + .modified = 1,
> + .channel2 = IIO_MOD_Z,
> + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
> + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
> + .scan_index = DUMMY_INDEX_MAGNZ,
> + .scan_type = {
> + .sign = 'u',
> + .realbits = 16,
> + .storagebits = 16,
> + .shift = 0,
> + },
> + },
> };
>
> /**
> @@ -621,6 +663,7 @@ static struct iio_sw_device *iio_dummy_probe(const char *name)
> /* Provide description of available channels */
> indio_dev->channels = iio_dummy_channels;
> indio_dev->num_channels = ARRAY_SIZE(iio_dummy_channels);
> + printk(KERN_DEBUG "No of channels are %d\n",indio_dev -> num_channels);
>
> /*
> * Provide device type specific interface functions and
> diff --git a/drivers/iio/dummy/iio_simple_dummy.h b/drivers/iio/dummy/iio_simple_dummy.h
> index f7005c3..be6eff0 100644
> --- a/drivers/iio/dummy/iio_simple_dummy.h
> +++ b/drivers/iio/dummy/iio_simple_dummy.h
> @@ -110,6 +110,9 @@ enum iio_simple_dummy_scan_elements {
> DUMMY_INDEX_DIFFVOLTAGE_1M2,
> DUMMY_INDEX_DIFFVOLTAGE_3M4,
> DUMMY_INDEX_ACCELX,
> + DUMMY_INDEX_MAGNX,
> + DUMMY_INDEX_MAGNY,
> + DUMMY_INDEX_MAGNZ,
> };
This looks good.
But think about what would happen if you read one of those attributes ?
Like if you do:
# cat in_accel_x_raw
34
(Looking at hardcoded value in the dummy source)
st->accel_val = 34;
--
Himanshu Jha
Undergraduate Student
Department of Electronics & Communication
Guru Tegh Bahadur Institute of Technology
More information about the Kernelnewbies
mailing list