From patchwork Wed Jun 5 16:24:45 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 2671281 Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 70F7940077 for ; Wed, 5 Jun 2013 16:27:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755911Ab3FEQ1T (ORCPT ); Wed, 5 Jun 2013 12:27:19 -0400 Received: from www.linutronix.de ([62.245.132.108]:35266 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754553Ab3FEQ1T (ORCPT ); Wed, 5 Jun 2013 12:27:19 -0400 Received: from localhost ([127.0.0.1] helo=localhost.localdomain) by Galois.linutronix.de with esmtp (Exim 4.72) (envelope-from ) id 1UkGWS-0005Yp-E7; Wed, 05 Jun 2013 18:25:16 +0200 From: Sebastian Andrzej Siewior To: Samuel Ortiz Cc: Felipe Balbi , linux-iio@vger.kernel.org, linux-input@vger.kernel.org, Dmitry Torokhov , Jonathan Cameron , Pantelis Antoniou , Sebastian Andrzej Siewior Subject: [PATCH 12/22] iio/ti_tscadc: Update with IIO map interface Date: Wed, 5 Jun 2013 18:24:45 +0200 Message-Id: <1370449495-29981-13-git-send-email-bigeasy@linutronix.de> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1370449495-29981-1-git-send-email-bigeasy@linutronix.de> References: <1370449495-29981-1-git-send-email-bigeasy@linutronix.de> X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1, SHORTCIRCUIT=-0.0001 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: Pantelis Antoniou Add an IIO map interface that consumers can use. Signed-off-by: Pantelis Antoniou Signed-off-by: Felipe Balbi [bigeasy: use static AIN[0-8] names, plugged a mem leak, use kcalloc()] Signed-off-by: Sebastian Andrzej Siewior Acked-by: Jonathan Cameron --- drivers/iio/adc/ti_am335x_adc.c | 57 ++++++++++++++++++++++++++++++++++----- 1 file changed, 51 insertions(+), 6 deletions(-) diff --git a/drivers/iio/adc/ti_am335x_adc.c b/drivers/iio/adc/ti_am335x_adc.c index 502e929..c6695a8 100644 --- a/drivers/iio/adc/ti_am335x_adc.c +++ b/drivers/iio/adc/ti_am335x_adc.c @@ -24,12 +24,15 @@ #include #include #include +#include +#include #include struct tiadc_device { struct ti_tscadc_dev *mfd_tscadc; int channels; + struct iio_map *map; }; static unsigned int tiadc_readl(struct tiadc_device *adc, unsigned int reg) @@ -84,34 +87,76 @@ static void tiadc_step_config(struct tiadc_device *adc_dev) am335x_tsc_se_set(adc_dev->mfd_tscadc, step_en); } +static const char * const chan_name_ain[] = { + "AIN0", + "AIN1", + "AIN2", + "AIN3", + "AIN4", + "AIN5", + "AIN6", + "AIN7", +}; + static int tiadc_channel_init(struct iio_dev *indio_dev, int channels) { + struct tiadc_device *adc_dev = iio_priv(indio_dev); struct iio_chan_spec *chan_array; - int i; + struct iio_chan_spec *chan; + int i, ret; indio_dev->num_channels = channels; - chan_array = kcalloc(indio_dev->num_channels, + chan_array = kcalloc(channels, sizeof(struct iio_chan_spec), GFP_KERNEL); - if (chan_array == NULL) return -ENOMEM; - for (i = 0; i < (indio_dev->num_channels); i++) { - struct iio_chan_spec *chan = chan_array + i; + chan = chan_array; + for (i = 0; i < channels; i++, chan++) { + chan->type = IIO_VOLTAGE; chan->indexed = 1; chan->channel = i; chan->info_mask_separate = BIT(IIO_CHAN_INFO_RAW); + chan->datasheet_name = chan_name_ain[i]; + chan->scan_type.sign = 'u'; + chan->scan_type.realbits = 12; + chan->scan_type.storagebits = 32; + chan->scan_type.shift = 0; } indio_dev->channels = chan_array; - return indio_dev->num_channels; + adc_dev->map = kcalloc(channels + 1, sizeof(struct iio_map), + GFP_KERNEL); + if (adc_dev->map == NULL) + goto err_free_chan; + + for (i = 0; i < channels; i++) { + adc_dev->map[i].adc_channel_label = + chan_array[i].datasheet_name; + adc_dev->map[i].consumer_dev_name = "any"; + adc_dev->map[i].consumer_channel = chan_array[i].datasheet_name; + } + + ret = iio_map_array_register(indio_dev, adc_dev->map); + if (ret) + goto err_map; + + return 0; +err_map: + kfree(adc_dev->map); +err_free_chan: + kfree(chan_array); + return -ENOMEM; } static void tiadc_channels_remove(struct iio_dev *indio_dev) { + struct tiadc_device *adc_dev = iio_priv(indio_dev); + kfree(indio_dev->channels); + kfree(adc_dev->map); } static int tiadc_read_raw(struct iio_dev *indio_dev,