kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
From: Himanshu Jha <himanshujha199640@gmail.com>
To: Bharath Vedartham <linux.bhar@gmail.com>
Cc: kernelnewbies@kernelnewbies.org
Subject: Re: drivers: iio: dummy: Unable to add channels to simple_dummy_channel
Date: Thu, 24 Jan 2019 16:35:16 +0530	[thread overview]
Message-ID: <20190124110516.GB13680@himanshu-Vostro-3559> (raw)
In-Reply-To: <20190123175556.GA1039@bhar.linux>

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

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

      parent reply	other threads:[~2019-01-24 11:06 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-23 17:55 drivers: iio: dummy: Unable to add channels to simple_dummy_channel Bharath Vedartham
2019-01-23 18:57 ` valdis.kletnieks
2019-01-24 11:05 ` Himanshu Jha [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190124110516.GB13680@himanshu-Vostro-3559 \
    --to=himanshujha199640@gmail.com \
    --cc=kernelnewbies@kernelnewbies.org \
    --cc=linux.bhar@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).