public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Lars-Peter Clausen <lars@metafoo.de>
To: anish kumar <anish198519851985@gmail.com>
Cc: Jonathan Cameron <jic23@kernel.org>,
	linux-iio@vger.kernel.org, cbou@mail.ru, dwmw2@infradead.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] [RFC]power: battery: Generic battery driver using IIO
Date: Sun, 09 Sep 2012 11:46:05 +0200	[thread overview]
Message-ID: <504C655D.70901@metafoo.de> (raw)
In-Reply-To: <1347183129.5051.174.camel@anish-Inspiron-N5050>

On 09/09/2012 11:32 AM, anish kumar wrote:
>>>>> +	channels = iio_channel_get_all(dev_name(&pdev->dev));
>>>> I would give these explicit names and get the two individual channels by 
>>>> name. I think it will give you cleaner code.
>>> Yes, now it will be based on pdata->voltage_channel,
>>> pdata->current_channel and so on.We will use this to get the channel.
>> Maybe better to just do this via the iio_map structures in the platform data
>> and standard naming for each channel.
>>
>> "voltage", "current", "power" would do nicely. Note we'll have to add the
>> relevant naming for the other side to more IIO device drivers via the
>> 'datasheet_name' element of iio_chan_spec.   A quick grep shows this
>> is only done in drivers/staging/iio/max1363_core.c so far (bet you can't
>> guess what is soldered to my test board :)
> Sorry I couldn't understand this but this is what I came up with.Hope it
> doesn't disappoint.
> It has the advantage of getting extended easily.
> 
> enum chan_type{
>         VOLTAGE,
>         CURRENT,
>         POWER,
>         MAX_TYPE
> };
> 
> struct channel_map {
>         struct iio_map channel;
>         enum chan_type type;
> };
> 
> struct iio_battery_platform_data {
>         struct power_supply_info battery_info;
>         struct channel_map *map;
>         int     num_map;
>         char    battery_name[BAT_MAX_NAME];
>         int     (*cal_charge)(long);
>         int     gpio_charge_finished;
>         int     gpio_inverted;
>         int     bat_poll_interval;
>         int     jitter_delay;
> };
> 
> here goes the assignment:
> for(i = 0; i < pdata->num_map; i++) {
>         switch(pdata->map[i].type)
>         case VOLTAGE:
>                 adc_bat->channel[VOLTAGE] = 
>                  iio_channel_get(
>                         pdata->map[i].channel.consumer_dev_name,
>                         pdata->map[i].channel.adc_channel_label);
>                 adc_bat->chan_index = 1 << VOLTAGE;
>                 break;  
>         case CURRENT:
>                 adc_bat->channel[CURRENT] =
>                 iio_channel_get(
>                         pdata->map->channel->consumer_dev_name,
>                         pdata->map[i].channel.adc_channel_label);
>                 adc_bat->chan_index = 1 << CURRENT;
>                 break;  
>         case POWER:
>                 adc_bat->channel[POWER] =
>                 iio_channel_get(
>                         pdata->map[i].channel.consumer_dev_name,
>                         pdata->map[i].channel.adc_channel_label);
>                 adc_bat->chan_index = 1 << POWER;
>                 break;  
>         default:
>                 pr_info("add any other channels here in the case\n");
> }
> 
> With the chan_index we can know which property is set or every time we
> need to run through pdata->map[i].type to know the property set.

Hi,

I think what Jonathon meant is something like this.

adc_bat->channel[VOLTAGE] = iio_channel_get(dev_name(&pdev->dev), "voltage");
...
adc_bat->channel[CURRENT] = iio_channel_get(dev_name(&pdev->dev), "current");
...
adc_bat->channel[POWER] = iio_channel_get(dev_name(&pdev->dev), "power");

That's the beauty of the channel iio_map you can map an arbitrary channel of
your ADC to a virtual identifier.

E.g. an example map could look like.

static struct iio_map map[] = {
	{ "AIN1", "iio-battery.1", "voltage" },
};

With this when the battery driver calls iio_channel_get(... "voltage") it will
get the "AIN1" channel of the device.

- Lars

  reply	other threads:[~2012-09-09  9:46 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-02 15:39 [PATCH] [RFC]power: battery: Generic battery driver using IIO anish kumar
2012-09-02 16:14 ` Sannu K
2012-09-02 21:34   ` Anton Vorontsov
2012-09-04 15:05     ` anish kumar
2012-09-07  7:52 ` Jonathan Cameron
2012-09-08  7:10   ` anish kumar
2012-09-08  8:34     ` Anton Vorontsov
2012-09-08 10:09     ` Jonathan Cameron
2012-09-09  9:32       ` anish kumar
2012-09-09  9:46         ` Lars-Peter Clausen [this message]
2012-09-09  9:59           ` Jonathan Cameron
2012-09-07  8:49 ` Lars-Peter Clausen
2012-09-08  7:30   ` anish kumar
2012-09-08 10:10     ` Jonathan Cameron
  -- strict thread matches above, loose matches on Subject: below --
2012-09-10 15:40 anish kumar
2012-09-11  9:59 ` Lars-Peter Clausen
2012-09-12  8:30   ` anish singh
2012-09-13 12:26     ` Jonathan Cameron
2012-09-13 12:33       ` anish singh

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=504C655D.70901@metafoo.de \
    --to=lars@metafoo.de \
    --cc=anish198519851985@gmail.com \
    --cc=cbou@mail.ru \
    --cc=dwmw2@infradead.org \
    --cc=jic23@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /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