From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.3 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,UNWANTED_LANGUAGE_BODY autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BB14BC04AAF for ; Sat, 18 May 2019 10:33:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8916F20B7C for ; Sat, 18 May 2019 10:33:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1558175637; bh=lyxZ2oAa3nSh2jH4FzM6/fqpfbA1xb/Q3QFlyxQaA7Q=; h=Date:From:To:Cc:Subject:In-Reply-To:References:List-ID:From; b=nvYFdSlZeb9s36o2s5t11AWKW7Ux2WdyX2gD1zir99YOVYutpH6pm3nq5lu+mq2cc 7JvwkUMQJlN21i7tma0HnLonWj9b2KCwOonWhqhs6XTKJZ4r9fzH4tfMbqbukku5S9 WnZD4SyUWDRsflaff6hZhZcGh2xo6VcBCVGbvbJo= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728074AbfERKd4 (ORCPT ); Sat, 18 May 2019 06:33:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:43592 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726263AbfERKd4 (ORCPT ); Sat, 18 May 2019 06:33:56 -0400 Received: from archlinux (cpc91196-cmbg18-2-0-cust659.5-4.cable.virginm.net [81.96.234.148]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8317C2087E; Sat, 18 May 2019 10:33:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1558175635; bh=lyxZ2oAa3nSh2jH4FzM6/fqpfbA1xb/Q3QFlyxQaA7Q=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=JG5SW2dvsxct3gLLqXmySEq60SKoEsCtIPeqqqM81XYl23VEimz4AzbQIRAW7qU62 YPFIYlKSbHtCVVzsjk/BG7dOnd2M67zd8URJa4E7zu3Px5gtQH0PbikZAcV+EGGqFF X9LRSDcR5gN0m0F1gvPSweUB1ftGMynLqonM9UQM= Date: Sat, 18 May 2019 11:33:49 +0100 From: Jonathan Cameron To: Chun-Hung Wu Cc: Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Rob Herring , Mark Rutland , Matthias Brugger , , , , , , , , , Subject: Re: [PATCH 2/4] iio: adc: mediatek: mt6765 upstream driver Message-ID: <20190518113349.2858f5ac@archlinux> In-Reply-To: <1557994247-16739-3-git-send-email-chun-hung.wu@mediatek.com> References: <1557994247-16739-1-git-send-email-chun-hung.wu@mediatek.com> <1557994247-16739-3-git-send-email-chun-hung.wu@mediatek.com> X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org On Thu, 16 May 2019 16:10:45 +0800 Chun-Hung Wu wrote: Hi, I changed the title to just say we were adding support to the existing driver. Applied to the togreg branch of iio.git and pushed out as testing for the autobuilders to play with it. Thanks, Jonathan > 1. Add calibrated sample data support > 2. Use of_match_table to decide each platform's > feature set > > Signed-off-by: Chun-Hung Wu > --- > drivers/iio/adc/mt6577_auxadc.c | 54 +++++++++++++++++++++++++++++++---------- > 1 file changed, 41 insertions(+), 13 deletions(-) > > diff --git a/drivers/iio/adc/mt6577_auxadc.c b/drivers/iio/adc/mt6577_auxadc.c > index 95d76ab..e1bdcc0 100644 > --- a/drivers/iio/adc/mt6577_auxadc.c > +++ b/drivers/iio/adc/mt6577_auxadc.c > @@ -42,10 +42,26 @@ > #define MT6577_AUXADC_POWER_READY_MS 1 > #define MT6577_AUXADC_SAMPLE_READY_US 25 > > +struct mtk_auxadc_compatible { > + bool sample_data_cali; > + bool check_global_idle; > +}; > + > struct mt6577_auxadc_device { > void __iomem *reg_base; > struct clk *adc_clk; > struct mutex lock; > + const struct mtk_auxadc_compatible *dev_comp; > +}; > + > +static const struct mtk_auxadc_compatible mt8173_compat = { > + .sample_data_cali = false, > + .check_global_idle = true, > +}; > + > +static const struct mtk_auxadc_compatible mt6765_compat = { > + .sample_data_cali = true, > + .check_global_idle = false, > }; > > #define MT6577_AUXADC_CHANNEL(idx) { \ > @@ -74,6 +90,11 @@ struct mt6577_auxadc_device { > MT6577_AUXADC_CHANNEL(15), > }; > > +static int mt_auxadc_get_cali_data(int rawdata, bool enable_cali) > +{ > + return rawdata; > +} > + > static inline void mt6577_auxadc_mod_reg(void __iomem *reg, > u32 or_mask, u32 and_mask) > { > @@ -120,15 +141,17 @@ static int mt6577_auxadc_read(struct iio_dev *indio_dev, > /* we must delay here for hardware sample channel data */ > udelay(MT6577_AUXADC_SAMPLE_READY_US); > > - /* check MTK_AUXADC_CON2 if auxadc is idle */ > - ret = readl_poll_timeout(adc_dev->reg_base + MT6577_AUXADC_CON2, val, > - ((val & MT6577_AUXADC_STA) == 0), > - MT6577_AUXADC_SLEEP_US, > - MT6577_AUXADC_TIMEOUT_US); > - if (ret < 0) { > - dev_err(indio_dev->dev.parent, > - "wait for auxadc idle time out\n"); > - goto err_timeout; > + if (adc_dev->dev_comp->check_global_idle) { > + /* check MTK_AUXADC_CON2 if auxadc is idle */ > + ret = readl_poll_timeout(adc_dev->reg_base + MT6577_AUXADC_CON2, > + val, ((val & MT6577_AUXADC_STA) == 0), > + MT6577_AUXADC_SLEEP_US, > + MT6577_AUXADC_TIMEOUT_US); > + if (ret < 0) { > + dev_err(indio_dev->dev.parent, > + "wait for auxadc idle time out\n"); > + goto err_timeout; > + } > } > > /* read channel and make sure ready bit == 1 */ > @@ -163,6 +186,8 @@ static int mt6577_auxadc_read_raw(struct iio_dev *indio_dev, > int *val2, > long info) > { > + struct mt6577_auxadc_device *adc_dev = iio_priv(indio_dev); > + > switch (info) { > case IIO_CHAN_INFO_PROCESSED: > *val = mt6577_auxadc_read(indio_dev, chan); > @@ -172,6 +197,8 @@ static int mt6577_auxadc_read_raw(struct iio_dev *indio_dev, > chan->channel); > return *val; > } > + if (adc_dev->dev_comp->sample_data_cali) > + *val = mt_auxadc_get_cali_data(*val, true); > return IIO_VAL_INT; > > default: > @@ -304,10 +331,11 @@ static SIMPLE_DEV_PM_OPS(mt6577_auxadc_pm_ops, > mt6577_auxadc_resume); > > static const struct of_device_id mt6577_auxadc_of_match[] = { > - { .compatible = "mediatek,mt2701-auxadc", }, > - { .compatible = "mediatek,mt2712-auxadc", }, > - { .compatible = "mediatek,mt7622-auxadc", }, > - { .compatible = "mediatek,mt8173-auxadc", }, > + { .compatible = "mediatek,mt2701-auxadc", .data = &mt8173_compat}, > + { .compatible = "mediatek,mt2712-auxadc", .data = &mt8173_compat}, > + { .compatible = "mediatek,mt7622-auxadc", .data = &mt8173_compat}, > + { .compatible = "mediatek,mt8173-auxadc", .data = &mt8173_compat}, > + { .compatible = "mediatek,mt6765-auxadc", .data = &mt6765_compat}, > { } > }; > MODULE_DEVICE_TABLE(of, mt6577_auxadc_of_match);