From patchwork Fri May 3 07:28:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yangtao Li X-Patchwork-Id: 10927975 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2A49892A for ; Fri, 3 May 2019 07:28:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 11D8D281C3 for ; Fri, 3 May 2019 07:28:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 056D92821F; Fri, 3 May 2019 07:28:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6273E281C3 for ; Fri, 3 May 2019 07:28:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=T3LRWVPr+WljDJwvNMLhpJTJPEHM0iFpClrLqvgM5z8=; b=o6Ra42IKDphOhXYqIn85w9Ww/e O3tX+6hK/fijmaNgVxvVX/fSDQR40mQCj+F3+HVJBrZUhA04G1nVh5VEPmrqpkBZZIMla7yQv4g+/ q8F7Vhi59j+0mR4GoGujyAJEr+xGdfGRcHA+etfPVzp0eCeAWFaf4df3oNEL/hQ1uGyj6bhnqTZSk 5BIo3wUnl1+WNp/hmbsDYwyt2FkCGSQw/LCf/vbqQfomdfvvbvBD523999dGs3OV/hEcnSa5P5X0b KQIzewGg+rwiZc/O8bGPE5jde2dFxQo4B+3g6vbad6SmDcpJp84GtrmFcTgsdD2W3EVRDI3eqbBJw y1714NVA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hMScT-0006Vl-5E; Fri, 03 May 2019 07:28:33 +0000 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hMScK-0006K7-FH for linux-arm-kernel@lists.infradead.org; Fri, 03 May 2019 07:28:28 +0000 Received: by mail-pf1-x444.google.com with SMTP id e67so2456597pfe.10 for ; Fri, 03 May 2019 00:28:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=MZcLgpBFS1mDxQXfnvuoOT7jBbjyb0ev7EJmb+a0GhM=; b=qOJxzs0FueS2kZGSNM2GwrCS66Ob0TEAel0B5aEN6LIFT7Ir19RGGtAZ6XWNgdh6Sf ZTK+6x3tgKx6+7rSp3PiJMVqSqb3BFn7FAkmR+8P6+PKSL9hTbG3/IdoQMEMCfwbm5MM GXE95t37e7iSKOCyMs5hNPl6CzjjxzcjfsJzoqqTPrjgwhDz1eKYwN4rjCQ28D4woA5V UrCmw6uRS9AQgu8fsflVsxmef3d2ErIoz/QDhCfG/p7iHuZryMM8ETjTxk71gkV+K/u8 Mb9sNLtf3UYMSK4B1Mx11a/5yMxxg9JNSyxKm+H1ABdTWXM7oqBNRfGbhswIJc7Ugss4 ejow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=MZcLgpBFS1mDxQXfnvuoOT7jBbjyb0ev7EJmb+a0GhM=; b=olrKoGmR6OES3P/OpMbqI3/78gHKAApygz6rb+ihEfRIGv0f/oKoQ/BJMEL1TSOke+ nXKEYRMzZDEr8pp/XgFTOlFcXMWlOFvgz82W9XayzY3t+ZTziFiFWljvt0MbW3M8g58m /O/iHq4Q4RoDi+DRB8+fcNcdcVnRMJd7LtSzyY3BiFh0yybE/0HWMUMvo+nDU9Cz6P0z c8pHYic+Fl6EG3zzBAOK6Bri0lelttOXXKi+5sSi783Uwkz8EPRSQTruJ3ySnI3ruA5Q EoPR4OFvuoZMPgU4HBhsgXReCHut8N5+Mirg/LduVgKlvmGw0b0c9dakidRAJMJVxxq+ Az7g== X-Gm-Message-State: APjAAAVQzW26iSykc/5xAD9PB2ycKCfZ/V8lHUovbSeF0SF5ZkyCtauf fPaMvSsoXXv+3JRCW2SQ2rM= X-Google-Smtp-Source: APXvYqwRGaDlZn07Q8U0dkPFx/r+GfTEeeOijOpzquwx/Wv2EfpOr9gfNga47ezAd/vEqmkBc2cIPw== X-Received: by 2002:a63:5d3:: with SMTP id 202mr8244591pgf.363.1556868503680; Fri, 03 May 2019 00:28:23 -0700 (PDT) Received: from localhost (68.168.130.77.16clouds.com. [68.168.130.77]) by smtp.gmail.com with ESMTPSA id y68sm1672883pfy.28.2019.05.03.00.28.22 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 03 May 2019 00:28:23 -0700 (PDT) From: Yangtao Li To: lee.jones@linaro.org, robh+dt@kernel.org, mark.rutland@arm.com, maxime.ripard@bootlin.com, wens@csie.org, jic23@kernel.org, knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net Subject: [PATCH 1/7] iio: adc: sun4i-gpadc: rework for support multiple thermal sensor Date: Fri, 3 May 2019 03:28:07 -0400 Message-Id: <20190503072813.2719-2-tiny.windzz@gmail.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190503072813.2719-1-tiny.windzz@gmail.com> References: <20190503072813.2719-1-tiny.windzz@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190503_002824_563023_2814B530 X-CRM114-Status: GOOD ( 18.18 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-iio@vger.kernel.org, devicetree@vger.kernel.org, Yangtao Li , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP For some SOCs, there are more than one thermal sensor, and there are currently four sensors on the A80. So we need to do some work in order to support multiple thermal sensors: 1) add sensor_count in gpadc_data. 2) introduce sun4i_sensor_tzd in sun4i_gpadc_iio, to support multiple thermal_zone_device and distinguish between different sensors. 3) modify read temperature and initialization function. Signed-off-by: Yangtao Li --- drivers/iio/adc/sun4i-gpadc-iio.c | 61 +++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 16 deletions(-) diff --git a/drivers/iio/adc/sun4i-gpadc-iio.c b/drivers/iio/adc/sun4i-gpadc-iio.c index 04d7147e0110..844fd52bd22f 100644 --- a/drivers/iio/adc/sun4i-gpadc-iio.c +++ b/drivers/iio/adc/sun4i-gpadc-iio.c @@ -56,6 +56,7 @@ struct gpadc_data { unsigned int tp_adc_select; unsigned int (*adc_chan_select)(unsigned int chan); unsigned int adc_chan_mask; + unsigned int sensor_count; }; static const struct gpadc_data sun4i_gpadc_data = { @@ -65,6 +66,7 @@ static const struct gpadc_data sun4i_gpadc_data = { .tp_adc_select = SUN4I_GPADC_CTRL1_TP_ADC_SELECT, .adc_chan_select = &sun4i_gpadc_chan_select, .adc_chan_mask = SUN4I_GPADC_CTRL1_ADC_CHAN_MASK, + .sensor_count = 1, }; static const struct gpadc_data sun5i_gpadc_data = { @@ -74,6 +76,7 @@ static const struct gpadc_data sun5i_gpadc_data = { .tp_adc_select = SUN4I_GPADC_CTRL1_TP_ADC_SELECT, .adc_chan_select = &sun4i_gpadc_chan_select, .adc_chan_mask = SUN4I_GPADC_CTRL1_ADC_CHAN_MASK, + .sensor_count = 1, }; static const struct gpadc_data sun6i_gpadc_data = { @@ -83,14 +86,24 @@ static const struct gpadc_data sun6i_gpadc_data = { .tp_adc_select = SUN6I_GPADC_CTRL1_TP_ADC_SELECT, .adc_chan_select = &sun6i_gpadc_chan_select, .adc_chan_mask = SUN6I_GPADC_CTRL1_ADC_CHAN_MASK, + .sensor_count = 1, }; static const struct gpadc_data sun8i_a33_gpadc_data = { .temp_offset = -1662, .temp_scale = 162, .tp_mode_en = SUN8I_GPADC_CTRL1_CHOP_TEMP_EN, + .sensor_count = 1, }; +struct sun4i_sensor_tzd { + struct sun4i_gpadc_iio *info; + struct thermal_zone_device *tzd; + unsigned int sensor_id; +}; + +#define MAX_SENSOR_COUNT 4 + struct sun4i_gpadc_iio { struct iio_dev *indio_dev; struct completion completion; @@ -105,7 +118,7 @@ struct sun4i_gpadc_iio { bool no_irq; /* prevents concurrent reads of temperature and ADC */ struct mutex mutex; - struct thermal_zone_device *tzd; + struct sun4i_sensor_tzd tzds[MAX_SENSOR_COUNT]; struct device *sensor_device; }; @@ -270,7 +283,8 @@ static int sun4i_gpadc_adc_read(struct iio_dev *indio_dev, int channel, return sun4i_gpadc_read(indio_dev, channel, val, info->fifo_data_irq); } -static int sun4i_gpadc_temp_read(struct iio_dev *indio_dev, int *val) +static int sun4i_gpadc_temp_read(struct iio_dev *indio_dev, int *val, + unsigned int sensor) { struct sun4i_gpadc_iio *info = iio_priv(indio_dev); @@ -324,7 +338,7 @@ static int sun4i_gpadc_read_raw(struct iio_dev *indio_dev, ret = sun4i_gpadc_adc_read(indio_dev, chan->channel, val); else - ret = sun4i_gpadc_temp_read(indio_dev, val); + ret = sun4i_gpadc_temp_read(indio_dev, val, 0); if (ret) return ret; @@ -417,10 +431,11 @@ static int sun4i_gpadc_runtime_resume(struct device *dev) static int sun4i_gpadc_get_temp(void *data, int *temp) { - struct sun4i_gpadc_iio *info = data; + struct sun4i_sensor_tzd *tzd = data; + struct sun4i_gpadc_iio *info = tzd->info; int val, scale, offset; - if (sun4i_gpadc_temp_read(info->indio_dev, &val)) + if (sun4i_gpadc_temp_read(info->indio_dev, &val, tzd->sensor_id)) return -ETIMEDOUT; sun4i_gpadc_temp_scale(info->indio_dev, &scale); @@ -609,6 +624,28 @@ static int sun4i_gpadc_probe_mfd(struct platform_device *pdev, return 0; } +static int sun4i_sensor_init(struct sun4i_gpadc_iio *info) +{ + int i = 0; + + for (; i < info->data->sensor_count; i++) { + info->tzds[i].info = info; + info->tzds[i].sensor_id = i; + info->tzds[i].tzd = devm_thermal_zone_of_sensor_register( + info->sensor_device, i, &info->tzds[i], + &sun4i_ts_tz_ops); + + if (IS_ERR(info->tzds[i].tzd)) { + dev_err(info->sensor_device, + "could not register thermal sensor: %ld\n", + PTR_ERR(info->tzds[i].tzd)); + return PTR_ERR(info->tzds[i].tzd); + } + } + + return 0; +} + static int sun4i_gpadc_probe(struct platform_device *pdev) { struct sun4i_gpadc_iio *info; @@ -646,19 +683,13 @@ static int sun4i_gpadc_probe(struct platform_device *pdev) pm_runtime_enable(&pdev->dev); if (IS_ENABLED(CONFIG_THERMAL_OF)) { - info->tzd = thermal_zone_of_sensor_register(info->sensor_device, - 0, info, - &sun4i_ts_tz_ops); + ret = sun4i_sensor_init(info); /* * Do not fail driver probing when failing to register in * thermal because no thermal DT node is found. */ - if (IS_ERR(info->tzd) && PTR_ERR(info->tzd) != -ENODEV) { - dev_err(&pdev->dev, - "could not register thermal sensor: %ld\n", - PTR_ERR(info->tzd)); - return PTR_ERR(info->tzd); - } + if (ret && ret != -ENODEV) + return ret; } ret = devm_iio_device_register(&pdev->dev, indio_dev); @@ -690,8 +721,6 @@ static int sun4i_gpadc_remove(struct platform_device *pdev) if (!IS_ENABLED(CONFIG_THERMAL_OF)) return 0; - thermal_zone_of_sensor_unregister(info->sensor_device, info->tzd); - if (!info->no_irq) iio_map_array_unregister(indio_dev); From patchwork Fri May 3 07:28:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yangtao Li X-Patchwork-Id: 10927979 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9984A1515 for ; Fri, 3 May 2019 07:28:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 81240281DB for ; Fri, 3 May 2019 07:28:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 726EB2818E; Fri, 3 May 2019 07:28:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 101CC281DB for ; Fri, 3 May 2019 07:28:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=iOZjlpo6EljsUO9Hy67djF/xams+c9F88No2ULazdTE=; b=JbrtA3mBKFgdCyPHOIwwAmF5Zq 1EWVNOVtlE6elJyGbiicwaUGvdvRwoTpDcqYbon2Sqp0EFT00hUsZBWLGm9FtTvhVSbFqquydk5wF ecbXQCxRE4RzGmgiJWL4QLMwUElfmOAat+Qb9DpVMWMjD+rPIQK5ktaFPbyxriKEZExyUY5usGJ9B tjEnmrpGZDP66NNeSB606pcvcPXP/SilPVEIg51BjHNy1QUG7aB1rNImJwHBYwVD4DTNb5zMzpXJQ i98fGmK6ogRAVqPFc0ZrX/nt/WNfgO9Gso5cy65T9wdx59TDHor6/hu/RNXuuXLmqW23qE9UmZY6t 7ewWtYZw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hMScg-0006ny-Jt; Fri, 03 May 2019 07:28:46 +0000 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hMScM-0006MN-Tm for linux-arm-kernel@lists.infradead.org; Fri, 03 May 2019 07:28:29 +0000 Received: by mail-pf1-x442.google.com with SMTP id e67so2456668pfe.10 for ; Fri, 03 May 2019 00:28:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=QLNyKddzGBEfp0X3sV4+rgzmKK42NUUFMJfNDuQuMZg=; b=HUBwzSUDq0jDdXV/2VzXw7i6CoA6g+3k9UoxZE+/peYTUL5RV/MWJwWTUZLI+JHg5a 5Kl3MkEyY6LOhvGBMsibYXdsnzwZG6Dg87r5DB4jPKH9mpV8RZbqt1Phi+nw2ZFDsvyZ Vh8TJfGFzonSqQmdBHy7e2hPmG4Sv8ZhIpF6MjWAdm3oKKsAg+hnqi1orjTYhUK8UDv7 oImpuPBod/YgpaKNor5Pl9V+mLc4dEkdyw1kiYsj706wTXLU+2DDbV+6vK13kVpiNomy CtPo/Tfi8ySWD6unN/7oqY98b1K0D6n8IHOCkat6tccm/9NoT/1dwjDh7ttlBtppF06z bsCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=QLNyKddzGBEfp0X3sV4+rgzmKK42NUUFMJfNDuQuMZg=; b=GaBi8kp5OTsaGT6OjTU/dlhXGzvINll/W4ZxVfXNuTI+ZJWxex0GanfPiZHZvDUfax Dc2QdZ8zH1CtaJt7LB0Qkwn/TqnYLcusfYY9nHBx0zG31M9JpKHWakR5IabVVamKJZEC YKP+1f1Qcxzm06LAW58dB1Mb96I0Jj3uBkce6PJKuM46JVy90KVY7nx1YjFO84NGDcmv YKoNdU+n5Iwa7qtP6e9qyQSgW03v/iTY3rVIU9EaQwhTb2kHgZZsdtswY+n/vznqTn8J Y45IAamEJ7Ohf7CVVrW4xoC0NGGewfOsWn37GHawnZ8/FTgi873S4e+r03hDsJn/dXnD Aqsw== X-Gm-Message-State: APjAAAW0bd4QSo+/svnV4IRPTsf5dOKdsr70EmV+SDYTXkA751hAKHrG F25xRjG3mk/1iy4nO/GqxZ0= X-Google-Smtp-Source: APXvYqxstsfZoFavy9Cx50OVX7G6q9TfajFvKAS3Md5IR7ON1JQDSSu/k8UeT2nXNlUFGWl9cPi9qg== X-Received: by 2002:a65:6295:: with SMTP id f21mr8626731pgv.129.1556868506538; Fri, 03 May 2019 00:28:26 -0700 (PDT) Received: from localhost (68.168.130.77.16clouds.com. [68.168.130.77]) by smtp.gmail.com with ESMTPSA id i3sm1594564pgl.57.2019.05.03.00.28.25 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 03 May 2019 00:28:25 -0700 (PDT) From: Yangtao Li To: lee.jones@linaro.org, robh+dt@kernel.org, mark.rutland@arm.com, maxime.ripard@bootlin.com, wens@csie.org, jic23@kernel.org, knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net Subject: [PATCH 2/7] iio: adc: sun4i-gpadc: introduce temp_data in gpadc_data Date: Fri, 3 May 2019 03:28:08 -0400 Message-Id: <20190503072813.2719-3-tiny.windzz@gmail.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190503072813.2719-1-tiny.windzz@gmail.com> References: <20190503072813.2719-1-tiny.windzz@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190503_002827_143254_F76183E2 X-CRM114-Status: GOOD ( 13.12 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-iio@vger.kernel.org, devicetree@vger.kernel.org, Yangtao Li , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP For some SOCs, the temperature data register start address may be different, so introduce temp_data in gpadc_data. Also modify read temperature to support multiple sensor. Signed-off-by: Yangtao Li --- drivers/iio/adc/sun4i-gpadc-iio.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/iio/adc/sun4i-gpadc-iio.c b/drivers/iio/adc/sun4i-gpadc-iio.c index 844fd52bd22f..b41ec0d5964d 100644 --- a/drivers/iio/adc/sun4i-gpadc-iio.c +++ b/drivers/iio/adc/sun4i-gpadc-iio.c @@ -57,6 +57,7 @@ struct gpadc_data { unsigned int (*adc_chan_select)(unsigned int chan); unsigned int adc_chan_mask; unsigned int sensor_count; + unsigned int temp_data_base; }; static const struct gpadc_data sun4i_gpadc_data = { @@ -67,6 +68,7 @@ static const struct gpadc_data sun4i_gpadc_data = { .adc_chan_select = &sun4i_gpadc_chan_select, .adc_chan_mask = SUN4I_GPADC_CTRL1_ADC_CHAN_MASK, .sensor_count = 1, + .temp_data_base = SUN4I_GPADC_TEMP_DATA, }; static const struct gpadc_data sun5i_gpadc_data = { @@ -77,6 +79,7 @@ static const struct gpadc_data sun5i_gpadc_data = { .adc_chan_select = &sun4i_gpadc_chan_select, .adc_chan_mask = SUN4I_GPADC_CTRL1_ADC_CHAN_MASK, .sensor_count = 1, + .temp_data_base = SUN4I_GPADC_TEMP_DATA, }; static const struct gpadc_data sun6i_gpadc_data = { @@ -87,6 +90,7 @@ static const struct gpadc_data sun6i_gpadc_data = { .adc_chan_select = &sun6i_gpadc_chan_select, .adc_chan_mask = SUN6I_GPADC_CTRL1_ADC_CHAN_MASK, .sensor_count = 1, + .temp_data_base = SUN4I_GPADC_TEMP_DATA, }; static const struct gpadc_data sun8i_a33_gpadc_data = { @@ -94,6 +98,7 @@ static const struct gpadc_data sun8i_a33_gpadc_data = { .temp_scale = 162, .tp_mode_en = SUN8I_GPADC_CTRL1_CHOP_TEMP_EN, .sensor_count = 1, + .temp_data_base = SUN4I_GPADC_TEMP_DATA, }; struct sun4i_sensor_tzd { @@ -291,7 +296,8 @@ static int sun4i_gpadc_temp_read(struct iio_dev *indio_dev, int *val, if (info->no_irq) { pm_runtime_get_sync(indio_dev->dev.parent); - regmap_read(info->regmap, SUN4I_GPADC_TEMP_DATA, val); + regmap_read(info->regmap, info->data->temp_data_base + + 0x4 * sensor, val); pm_runtime_mark_last_busy(indio_dev->dev.parent); pm_runtime_put_autosuspend(indio_dev->dev.parent); From patchwork Fri May 3 07:28:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yangtao Li X-Patchwork-Id: 10927987 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B038714DB for ; Fri, 3 May 2019 07:29:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9948A2818E for ; Fri, 3 May 2019 07:29:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8DF44281DB; Fri, 3 May 2019 07:29:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 31D112818E for ; Fri, 3 May 2019 07:29:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=IpkUOLz8b/zBn6apXkyyFwjWGhx4ao3V//x7QYKlNCM=; b=CQ6qhuRYg2tg0V+D6qgHRy2kaJ KbqV4IhrqYmGbm98PmjVoMcPG98NCQZW3H4RGCj5sQAE9YLesB7S2zXQd1kWZo+k1ayFlC51udK3J Cx6L1GZ792sxcqyPCuke9P4hRJEClrX0gP3Ri/nLi99B0cdV0h6FfdBKZwe8Ph8KVWzHmBMXhHB3e Vn7XmrP4Ba1BQ/+q+Ag60INNpF2wvV95cDadaiu3XGQhXaNwwdVsiliXbqGX9HYoTQn7eDEvycnye tBt/IS3OfIy5mZZxHKUVR/WOVXJQXA1TQjMLxUcRQUNk3MwExUkJfHnXIYIw5T1Ay6kEiolo+wT/m qbFt77nQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hMScp-000733-82; Fri, 03 May 2019 07:28:55 +0000 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hMScP-0006QN-T6 for linux-arm-kernel@lists.infradead.org; Fri, 03 May 2019 07:28:33 +0000 Received: by mail-pf1-x442.google.com with SMTP id t87so1888352pfa.2 for ; Fri, 03 May 2019 00:28:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=whcenm+FX4qRQPz4bN0k/i1kY0g1Fng8zixTNhvTcc0=; b=uqQ8gcq1579BJNvE9790OgzNmqf4HWV9M7gwyiq9lHH1omarfHr1jDi+g+jksPJRTH H8p1NT3fu+z+GbSYqr+hhhDa1/f3ihBIoxKPQTk//no9j9Ulm/aQsZUfhFq5eG8DvAJB i1Ye2+kQTkhgj5DWYza7dP8/XEyVbAVhnAtmtNIZOK5NG4ql9cyjrvjbiTFjE8sUPnGj 0L6QityL0jphNFqbOwjXQKeRwz3Zl+48b2qAaWnskTorLGa8//i4A6Jbq2L3Nhfaopbc XEzgDjcLWPEoZKsHy7Ef0az4f53exQ5zIRIDpsZ3tVIPHDq/YNH+GOnPS0UGSJYb2T9H SYtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=whcenm+FX4qRQPz4bN0k/i1kY0g1Fng8zixTNhvTcc0=; b=Pe/WmF8jpXPuUjJLYRvQ7HQXTZe176uTkJ1HuLjvNBDVzLzIYxgMaKGIhHnCnR8t9n dJnl3rkom+fl22p5hemiVX+jHOWVU0m2BBdB9z7GawNTEnsNE9dkfBNEbsCjxIW8P0mp Kj/xwIs2ReIwrp/Bz9pp3GG77BugTeHNNpOX5TG2h1+HmE50Dtb/Ryh362k/Oujs5BbU nynrg+QnUGlgj7/J7rH034Dg6DFRLETVlWGaEdoxe6XiBMtzKXs20OUj5dYiMb26K6jR Gp/AWrr5zCF4sV1zR9sibrc38Rn8OewKhDHt5xdipBfi+kzeM+GgQBPOLJXyQnyHCBUC SSag== X-Gm-Message-State: APjAAAXANwvbOTJwE+pD9eWIuluxS10Iq2yfTOXpBYliATfkVv0Nff7I NkhCLVi7MCq/G64nxewEQbo= X-Google-Smtp-Source: APXvYqxWSnuIybJbjilvsuTpxUl/E3mOx1lW2LrSkVylcN9LtF+lbeVXh1tDcp13jE2vVkAUHnpftQ== X-Received: by 2002:a63:5443:: with SMTP id e3mr8411067pgm.265.1556868509325; Fri, 03 May 2019 00:28:29 -0700 (PDT) Received: from localhost (68.168.130.77.16clouds.com. [68.168.130.77]) by smtp.gmail.com with ESMTPSA id k65sm1744995pfj.141.2019.05.03.00.28.28 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 03 May 2019 00:28:28 -0700 (PDT) From: Yangtao Li To: lee.jones@linaro.org, robh+dt@kernel.org, mark.rutland@arm.com, maxime.ripard@bootlin.com, wens@csie.org, jic23@kernel.org, knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net Subject: [PATCH 3/7] iio: adc: sun4i-gpadc: introduce gpadc_enable and gpadc_disable in gpadc_data Date: Fri, 3 May 2019 03:28:09 -0400 Message-Id: <20190503072813.2719-4-tiny.windzz@gmail.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190503072813.2719-1-tiny.windzz@gmail.com> References: <20190503072813.2719-1-tiny.windzz@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190503_002830_234208_3E3C78B7 X-CRM114-Status: GOOD ( 14.59 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-iio@vger.kernel.org, devicetree@vger.kernel.org, Yangtao Li , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Different sensors may have different enable and disable functions, so introduce enable and disable in gpadc_data to support soc specific function. Signed-off-by: Yangtao Li --- drivers/iio/adc/sun4i-gpadc-iio.c | 37 ++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/drivers/iio/adc/sun4i-gpadc-iio.c b/drivers/iio/adc/sun4i-gpadc-iio.c index b41ec0d5964d..de6b8556a549 100644 --- a/drivers/iio/adc/sun4i-gpadc-iio.c +++ b/drivers/iio/adc/sun4i-gpadc-iio.c @@ -49,6 +49,8 @@ static unsigned int sun6i_gpadc_chan_select(unsigned int chan) return SUN6I_GPADC_CTRL1_ADC_CHAN_SELECT(chan); } +struct sun4i_gpadc_iio; + struct gpadc_data { int temp_offset; int temp_scale; @@ -56,10 +58,15 @@ struct gpadc_data { unsigned int tp_adc_select; unsigned int (*adc_chan_select)(unsigned int chan); unsigned int adc_chan_mask; + int (*gpadc_enable)(struct sun4i_gpadc_iio *info); + int (*gpadc_disable)(struct sun4i_gpadc_iio *info); unsigned int sensor_count; unsigned int temp_data_base; }; +static int sun4i_gpadc_disable(struct sun4i_gpadc_iio *info); +static int sun4i_gpadc_enable(struct sun4i_gpadc_iio *info); + static const struct gpadc_data sun4i_gpadc_data = { .temp_offset = -1932, .temp_scale = 133, @@ -67,6 +74,8 @@ static const struct gpadc_data sun4i_gpadc_data = { .tp_adc_select = SUN4I_GPADC_CTRL1_TP_ADC_SELECT, .adc_chan_select = &sun4i_gpadc_chan_select, .adc_chan_mask = SUN4I_GPADC_CTRL1_ADC_CHAN_MASK, + .gpadc_enable = sun4i_gpadc_enable, + .gpadc_disable = sun4i_gpadc_disable, .sensor_count = 1, .temp_data_base = SUN4I_GPADC_TEMP_DATA, }; @@ -78,6 +87,8 @@ static const struct gpadc_data sun5i_gpadc_data = { .tp_adc_select = SUN4I_GPADC_CTRL1_TP_ADC_SELECT, .adc_chan_select = &sun4i_gpadc_chan_select, .adc_chan_mask = SUN4I_GPADC_CTRL1_ADC_CHAN_MASK, + .gpadc_enable = sun4i_gpadc_enable, + .gpadc_disable = sun4i_gpadc_disable, .sensor_count = 1, .temp_data_base = SUN4I_GPADC_TEMP_DATA, }; @@ -89,6 +100,8 @@ static const struct gpadc_data sun6i_gpadc_data = { .tp_adc_select = SUN6I_GPADC_CTRL1_TP_ADC_SELECT, .adc_chan_select = &sun6i_gpadc_chan_select, .adc_chan_mask = SUN6I_GPADC_CTRL1_ADC_CHAN_MASK, + .gpadc_enable = sun4i_gpadc_enable, + .gpadc_disable = sun4i_gpadc_disable, .sensor_count = 1, .temp_data_base = SUN4I_GPADC_TEMP_DATA, }; @@ -97,6 +110,8 @@ static const struct gpadc_data sun8i_a33_gpadc_data = { .temp_offset = -1662, .temp_scale = 162, .tp_mode_en = SUN8I_GPADC_CTRL1_CHOP_TEMP_EN, + .gpadc_enable = sun4i_gpadc_enable, + .gpadc_disable = sun4i_gpadc_disable, .sensor_count = 1, .temp_data_base = SUN4I_GPADC_TEMP_DATA, }; @@ -402,10 +417,8 @@ static irqreturn_t sun4i_gpadc_fifo_data_irq_handler(int irq, void *dev_id) return IRQ_HANDLED; } -static int sun4i_gpadc_runtime_suspend(struct device *dev) +static int sun4i_gpadc_disable(struct sun4i_gpadc_iio *info) { - struct sun4i_gpadc_iio *info = iio_priv(dev_get_drvdata(dev)); - /* Disable the ADC on IP */ regmap_write(info->regmap, SUN4I_GPADC_CTRL1, 0); /* Disable temperature sensor on IP */ @@ -414,10 +427,8 @@ static int sun4i_gpadc_runtime_suspend(struct device *dev) return 0; } -static int sun4i_gpadc_runtime_resume(struct device *dev) +static int sun4i_gpadc_enable(struct sun4i_gpadc_iio *info) { - struct sun4i_gpadc_iio *info = iio_priv(dev_get_drvdata(dev)); - /* clkin = 6MHz */ regmap_write(info->regmap, SUN4I_GPADC_CTRL0, SUN4I_GPADC_CTRL0_ADC_CLK_DIVIDER(2) | @@ -435,6 +446,20 @@ static int sun4i_gpadc_runtime_resume(struct device *dev) return 0; } +static int sun4i_gpadc_runtime_suspend(struct device *dev) +{ + struct sun4i_gpadc_iio *info = iio_priv(dev_get_drvdata(dev)); + + return info->data->gpadc_disable(info); +} + +static int sun4i_gpadc_runtime_resume(struct device *dev) +{ + struct sun4i_gpadc_iio *info = iio_priv(dev_get_drvdata(dev)); + + return info->data->gpadc_enable(info); +} + static int sun4i_gpadc_get_temp(void *data, int *temp) { struct sun4i_sensor_tzd *tzd = data; From patchwork Fri May 3 07:28:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yangtao Li X-Patchwork-Id: 10927993 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A680A14DB for ; Fri, 3 May 2019 07:29:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8ED10281C3 for ; Fri, 3 May 2019 07:29:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 821E52821F; Fri, 3 May 2019 07:29:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 25C6C281C3 for ; Fri, 3 May 2019 07:29:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=MEnzZv2ExBivGNtKQN0zP86F1IGYM4x/0mffUb/CiHg=; b=Nqbtl8pY+IzmwZLVGX8IBkEk4b +X4yakojAlf6YtSwtYpOwwJXPU5bw/7EVFb5blWSV/Z89RsHwxGEZtmfHUjWOM67v6FXPteFKBLsu psioZJPpOHvM4t6XJZpsVttgl/CeB2g8WGWC+YFSVyXX82mkWKGQutrPd/V7XJ79GLJcjMZhkmgMT O0aoS7V9MERZ2hxhz5LFLY+ZfvsBWmDWe/ZPmJ5nDGfzP+NT/5NKNvm/p06hAf8sNHBTjB7e5tqXq RPKe2GRbsY9ijVYW9YVoCFInue3/u1/maBZnN7rDFeaQg+97S2fZByqv51vswgg2KrgEogXEp4VRt ncmswd7w==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hMScz-0007IA-Fr; Fri, 03 May 2019 07:29:05 +0000 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hMScS-0006UV-Hm for linux-arm-kernel@lists.infradead.org; Fri, 03 May 2019 07:28:35 +0000 Received: by mail-pf1-x441.google.com with SMTP id b3so2475335pfd.1 for ; Fri, 03 May 2019 00:28:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=gVZ2hqRXWtLcmOTx5ox6LNbjK3xqtyJ5f5GpEMyudKg=; b=g73z3cy3M5ok9jIYuhXWrFWMx1XV6tg1I96a9U9izJ/ZS0IWD229f2w8WplFIuQ1QR z2sE3omVPJOieDsXIilbDHaJGWfHRJXc7IXO6oqkUVAkyliKINFiJ/EDxuIMwRj+fDzP vQyy6nPLc18A4IlRduGPKz7ckOUAyTMyzTgf7nhGwuxYzDcoOsPD4gtVuTTyt9sK5Up+ BCExGq0YQSE3V1KBUnH/EPE6w0kk6n14uhBps4LblIH6UJOfo8KaN6/poYqlHUhKi3ut 7xtfpZt4Zf6rClEiUyDiAU2bs8MVV5G6/85BgWR7fUoaPIcLvWZdOAucVHkkC5AWFquy Tc9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=gVZ2hqRXWtLcmOTx5ox6LNbjK3xqtyJ5f5GpEMyudKg=; b=fbVWN+LP9JWn258hwVG9ztLT4SPvqp63zVpofUrT63q0/NQZt98gfjCxzBCX1v36oY oiRE1DB1DZjyS6d2fMVu0jTBWsqSJ497eN24VEwnAfVM06xXorSNJIobb14ZWMHDKflH JS6F36N0NkLYAa6DgtTlqjYnu9amW5hzOrsrLyqf9COgbwx14viwtr/YJndH8tBiwqXU y7Ra+SHfjYT4wiwAj7HBXege42Eq0dqzvw01xgFytpy1a2C1QB5n15ViQKUweOaRs60v HeVCiPzdtH81fa+AbzhM9ocPJb3EKQ7vRmCLCQ/V1Gb0QXiM2GY73TkS6kSkn+4/SeJ1 xkTg== X-Gm-Message-State: APjAAAVh8xB3GO3AXGLGDtYKUimQ+ACEI76M0zwBg0v7FvSYYN78Ldg7 eV/Vv+DL+3hEZh8LMcbufl8IWcbOyh0= X-Google-Smtp-Source: APXvYqxYc5VWDFUgbHShXTIGD8SRCAC8A5n0VEfy+lTVDjkOMeSveLaECAOjNbh8qqWfEAyLHZWVdQ== X-Received: by 2002:a62:4602:: with SMTP id t2mr8912629pfa.26.1556868511886; Fri, 03 May 2019 00:28:31 -0700 (PDT) Received: from localhost (68.168.130.77.16clouds.com. [68.168.130.77]) by smtp.gmail.com with ESMTPSA id q5sm1877338pfb.51.2019.05.03.00.28.31 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 03 May 2019 00:28:31 -0700 (PDT) From: Yangtao Li To: lee.jones@linaro.org, robh+dt@kernel.org, mark.rutland@arm.com, maxime.ripard@bootlin.com, wens@csie.org, jic23@kernel.org, knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net Subject: [PATCH 4/7] iio: adc: sun4i-gpadc-iio: support clocks and reset Date: Fri, 3 May 2019 03:28:10 -0400 Message-Id: <20190503072813.2719-5-tiny.windzz@gmail.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190503072813.2719-1-tiny.windzz@gmail.com> References: <20190503072813.2719-1-tiny.windzz@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190503_002832_663836_62B5F843 X-CRM114-Status: GOOD ( 13.99 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-iio@vger.kernel.org, devicetree@vger.kernel.org, Yangtao Li , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP H6 has bus clock and a reset, so introduce something in gpadc_data/sun4i_gpadc_iio and adds the process of the clocks and resets. This is pre-work for supprt it. Signed-off-by: Yangtao Li --- drivers/iio/adc/sun4i-gpadc-iio.c | 32 +++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/drivers/iio/adc/sun4i-gpadc-iio.c b/drivers/iio/adc/sun4i-gpadc-iio.c index de6b8556a549..f24eb76d65c0 100644 --- a/drivers/iio/adc/sun4i-gpadc-iio.c +++ b/drivers/iio/adc/sun4i-gpadc-iio.c @@ -22,6 +22,7 @@ * shutdown for not being used. */ +#include #include #include #include @@ -31,6 +32,7 @@ #include #include #include +#include #include #include @@ -52,6 +54,8 @@ static unsigned int sun6i_gpadc_chan_select(unsigned int chan) struct sun4i_gpadc_iio; struct gpadc_data { + bool has_bus_clk; + bool has_bus_rst; int temp_offset; int temp_scale; unsigned int tp_mode_en; @@ -140,6 +144,8 @@ struct sun4i_gpadc_iio { struct mutex mutex; struct sun4i_sensor_tzd tzds[MAX_SENSOR_COUNT]; struct device *sensor_device; + struct clk *bus_clk; + struct reset_control *reset; }; #define SUN4I_GPADC_ADC_CHANNEL(_channel, _name) { \ @@ -564,14 +570,36 @@ static int sun4i_gpadc_probe_dt(struct platform_device *pdev, if (IS_ERR(base)) return PTR_ERR(base); - info->regmap = devm_regmap_init_mmio(&pdev->dev, base, - &sun4i_gpadc_regmap_config); + if (info->data->has_bus_clk) + info->regmap = devm_regmap_init_mmio_clk(&pdev->dev, "bus", + base, + &sun4i_gpadc_regmap_config); + else + info->regmap = devm_regmap_init_mmio(&pdev->dev, base, + &sun4i_gpadc_regmap_config); + if (IS_ERR(info->regmap)) { ret = PTR_ERR(info->regmap); dev_err(&pdev->dev, "failed to init regmap: %d\n", ret); return ret; } + if (info->data->has_bus_rst) { + info->reset = devm_reset_control_get(&pdev->dev, "bus"); + if (IS_ERR(info->reset)) { + ret = PTR_ERR(info->reset); + return ret; + } + } + + if (info->data->has_bus_clk) { + info->bus_clk = devm_clk_get(&pdev->dev, "bus"); + if (IS_ERR(info->bus_clk)) { + ret = PTR_ERR(info->bus_clk); + return ret; + } + } + if (IS_ENABLED(CONFIG_THERMAL_OF)) info->sensor_device = &pdev->dev; From patchwork Fri May 3 07:28:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yangtao Li X-Patchwork-Id: 10927995 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C615314DB for ; Fri, 3 May 2019 07:29:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AD517281C3 for ; Fri, 3 May 2019 07:29:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A1A5F2821F; Fri, 3 May 2019 07:29:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 56E54281C3 for ; Fri, 3 May 2019 07:29:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=irfgGuzHiq4borfztOr1bO6YPFTQ1LPfuIcNFEsybjI=; b=KlHFobH88hZKohsILuj6g6BRK4 BVyRXTxrW4m8S/sDVM06YfyuzREweRNn95rirMohfVkOGyRL+CPsY/APkV/GxcICbjEqeOy6dE2WC NNm7fgzt7sujHkyaZDhiUZ7F63GLHoszo/OZ4M5Nv0h5rJiMKayC8Tj7hAOhjb0hT/Cou58zIhHml +1UTbn/V2k0LtZ37duzDk5FrbfwZyQXj4ed1qJPiPThtb/BFxXjCYlnuM/VKD2RN6CVlOD4/qS1UD FuiZAYfBvgW8UH+nxVF62UWra1z+/fqKjVNIn0ScEOjHl+0VNCYCxwxLQZe03I0Xz5IT5clnz8Dv0 CnrjbR3g==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hMSdB-0007VB-UK; Fri, 03 May 2019 07:29:17 +0000 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hMScV-0006ZO-Db for linux-arm-kernel@lists.infradead.org; Fri, 03 May 2019 07:28:41 +0000 Received: by mail-pg1-x544.google.com with SMTP id c13so2324912pgt.1 for ; Fri, 03 May 2019 00:28:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=BG5vJhn6fxD2HS6uv5WOnrZXuoNwm2WEGnxC4AxOH3M=; b=jUoDZV+DCWUU3EUgYBvFKoREV8sJ6B/1Q75rQ5H9tc3KxBOWSt8/3gr1dnh4TFhdfQ ga2rbPD5nLju7YKiMQBEfRtUhF/oTwweozr78id4TLzAgpq+ngGV2y7R0vohC0bP7bCj zPR9I82nRFHCHKWtgxWam4lgKNnAoao2Tz1rdB0PD2MLrbzgara2d4o7nEcDumCc37AU dydBTDKK+loQH0eBRU7X4Iwz9vuolfYjqjDBzfJzTg1TJf11O5mSODS3OvZiYt8KHzpk DkK5NN+OTuuCunHlSWR7t4dha6OgAa9lDxf4OGTU6iGZjgN3ywf0L7p9YVaNpOmu982K xQJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=BG5vJhn6fxD2HS6uv5WOnrZXuoNwm2WEGnxC4AxOH3M=; b=YiQBp7UKBnnRk1z3S1hOG4lPBv2hoDEHMU4OsJbI980v4xRxIw/OY2mMA5Nri7ZtJG 9b+1HmG5h5kU4ziOuMYph1x2z1D2lVzc4nXCO+Kq6Fe44RWPRPgKgVjXqsop49plMl4s 4G52J7EXDfKE6UKAwehHzGPkZCOeHnu4H04ELlOUZRrNa+GfleuN01vEDmJO6204r+VC nc2wiP1vT8Yf3LvNyzKHLZQBLtRsGmbw40BqEtQUiCTVlodrMQq8IuxxW5fSLmD3zcGE XrnEOoCgkq+5NXjJsIxKbyQ7U5sNCJNc8J9Q9iLYN8kXd9AvbThnXrYYV8AA4bAVeQYH qZQA== X-Gm-Message-State: APjAAAWDUAR/IO0hgrVlPld4ByaVt/e/LRqwpkSNranqYblAiS8ACF5g tVUMoxIVEcEC8ngLszLydqo= X-Google-Smtp-Source: APXvYqyu8pnDxJZ7NAaHywwAUuyZaCgE1lEL2nntTbOQXneI+4QAq5jkWw32noMF6A8h1uKl77+3Bw== X-Received: by 2002:a62:5a42:: with SMTP id o63mr9308857pfb.170.1556868514630; Fri, 03 May 2019 00:28:34 -0700 (PDT) Received: from localhost (68.168.130.77.16clouds.com. [68.168.130.77]) by smtp.gmail.com with ESMTPSA id x128sm1892707pfx.103.2019.05.03.00.28.33 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 03 May 2019 00:28:34 -0700 (PDT) From: Yangtao Li To: lee.jones@linaro.org, robh+dt@kernel.org, mark.rutland@arm.com, maxime.ripard@bootlin.com, wens@csie.org, jic23@kernel.org, knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net Subject: [PATCH 5/7] dt-bindings: mfd: Add H6 GPADC binding Date: Fri, 3 May 2019 03:28:11 -0400 Message-Id: <20190503072813.2719-6-tiny.windzz@gmail.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190503072813.2719-1-tiny.windzz@gmail.com> References: <20190503072813.2719-1-tiny.windzz@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190503_002836_190793_6A81D944 X-CRM114-Status: GOOD ( 13.01 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-iio@vger.kernel.org, devicetree@vger.kernel.org, Yangtao Li , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This patch adds documentation for the H6 GPADC binding. Signed-off-by: Yangtao Li --- .../devicetree/bindings/mfd/sun4i-gpadc.txt | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/Documentation/devicetree/bindings/mfd/sun4i-gpadc.txt b/Documentation/devicetree/bindings/mfd/sun4i-gpadc.txt index 86dd8191b04c..eeaf27eb8abd 100644 --- a/Documentation/devicetree/bindings/mfd/sun4i-gpadc.txt +++ b/Documentation/devicetree/bindings/mfd/sun4i-gpadc.txt @@ -5,11 +5,22 @@ and sometimes as a touchscreen controller. Required properties: - compatible: "allwinner,sun8i-a33-ths", + "allwinner,sun50i-h6-ths", - reg: mmio address range of the chip, - - #thermal-sensor-cells: shall be 0, + - #thermal-sensor-cells: shall be 0 for sun8i-a33-ths, + shall be 1 for sun50i-h6-ths, - #io-channel-cells: shall be 0, -Example: +Optional properties: + - clocks: Must contain an entry for each entry in clock-names. + See common clock-bindings.txt for details. + - clock-names: A list of clock names. For sun50i-h6-ths, it must contain + "bus". + - resets: Must contain an entry for each entry in reset-names. + See ../reset/reset.txt for details. + - reset-names: For sun50i-h6-ths, it must contain "bus". + +Example1: ths: ths@1c25000 { compatible = "allwinner,sun8i-a33-ths"; reg = <0x01c25000 0x100>; @@ -17,6 +28,18 @@ Example: #io-channel-cells = <0>; }; +Example2: + ths: ths@1c25000 { + compatible = "allwinner,sun50i-h6-ths"; + reg = <0x05070400 0x100>; + clocks = <&ccu CLK_BUS_THS>; + clock-names = "bus"; + resets = <&ccu RST_BUS_THS>; + reset-names = "bus"; + #thermal-sensor-cells = <1>; + #io-channel-cells = <0>; + }; + sun4i, sun5i and sun6i SoCs are also supported via the older binding: sun4i resistive touchscreen controller From patchwork Fri May 3 07:28:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yangtao Li X-Patchwork-Id: 10927997 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A90E092A for ; Fri, 3 May 2019 07:29:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 91BE9281C3 for ; Fri, 3 May 2019 07:29:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 856AE2821F; Fri, 3 May 2019 07:29:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2C70C281C3 for ; Fri, 3 May 2019 07:29:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=p4tVJTt30YeI7pMxbnMnPMVfLbU4phakkMypGfxP/yU=; b=btCwmqbmNmsvDZo4k67bwp9ICN 6eKxarGp/ziEzHzfjxv9hBhUoPi/b2iIGHL4si/FLtAY7ZijnjVewxg3hAwA5V6waYSd4TmMFbqmr e7LuNtIksSv692ucZyfnjAAdY8d4kBCweAE7VBKiGiXp+K9sWgoGFkC25vciz+s//+dFeXBogYQvk lEjntyKbBW7n70mKRi+NGzxwE3nTVpC9trktxOxTmVyoQERgyMEmOLmKqhiOzLxt4j+K9usSdamRB OzPguoMMHK4hg9hoT1D4yTw/dcYvWUe+Fry+mHN6ioJj/D/RMAKwkPIjbMWZk884KY+jmiZSUTRGo /zxW/eDA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hMSdK-0007hl-6B; Fri, 03 May 2019 07:29:26 +0000 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hMScZ-0006fa-DB for linux-arm-kernel@lists.infradead.org; Fri, 03 May 2019 07:28:48 +0000 Received: by mail-pf1-x444.google.com with SMTP id z28so2479831pfk.0 for ; Fri, 03 May 2019 00:28:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=e+8X3jpzX2axqpodG5rv/zXjSeBjdMvSndQlz4t6nbo=; b=duUSP7MUL4/J85YW5hqaSOb87iG/NFCOT5u5XorwFhbcE5qeGEjVOQvHS/c/DNU3dQ RBSJCP5KHneS8mkIfw7ovpg3oosItY0y98eEWWqpbAXVYnE65MqFKxJ3ORABwrpS93mf Dn5h7SkIJJCcY0TRftWU+cW6oPHfc87XqK5XylRnZScjIrJ46AQJ+gNVX9uZOYiczz8G PHphuyQ5szjLzXk+yg/SZJ8by6vafhgZx9bIOM1oMbx52nj/Kz31FkOdSkpLwxzqnUH7 7Ee5HmDGNW6d2bzrEsgV3/QFKNXi6+C5Nxzp5qXjsavSmDGRPidD+KVLyfx9hhJDAY5l wbLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=e+8X3jpzX2axqpodG5rv/zXjSeBjdMvSndQlz4t6nbo=; b=T/+G83/G+3bVO8MGQu5SU/LCnxMO0fCdv/PEUQBtbcl0eQOCW30KtYu4OAh8NzitNJ bTcDJB2FTE2VQ1+gIBNcx0UvDsMMNa+OnN+4xFhQI6ZBJUik5syMlB2Ejf3x4LMdnZB+ XcL7/AtPNddCplePdxTx0TXF0Eiz/uPgZhvFsN2XKae1Fb1JOPKwX6xHg2phF7hNh8+B xbTrJ3Q1MfQm2x1wbMVqFifnlaYxslFmG1fviAtW2sLoguS5Ie4i/2schxyIFymlM/p7 bHjfpfxpTQAXQRbfX+6+T4Cp6VoLSGD0D0LmSLhtLoIQvaJbZ1ehPUN4IariSx+zNFWR 9lfA== X-Gm-Message-State: APjAAAWbeS5bZO6Iv+/tXfKrQyDKoXavGpgVucC3je06FnewtBxUgItV 5XSgAks90kXt6obs5RbAjihI1hc3WW0= X-Google-Smtp-Source: APXvYqyo+FeWJtf/DfiX1DWQ9UwQWJKvX9mL2ppHGlZ846WHvAKvURFV+G/AL8NV+i2yfCxzm5pepQ== X-Received: by 2002:a62:5542:: with SMTP id j63mr8768993pfb.34.1556868518500; Fri, 03 May 2019 00:28:38 -0700 (PDT) Received: from localhost (68.168.130.77.16clouds.com. [68.168.130.77]) by smtp.gmail.com with ESMTPSA id k26sm1663560pfi.136.2019.05.03.00.28.37 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 03 May 2019 00:28:37 -0700 (PDT) From: Yangtao Li To: lee.jones@linaro.org, robh+dt@kernel.org, mark.rutland@arm.com, maxime.ripard@bootlin.com, wens@csie.org, jic23@kernel.org, knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net Subject: [PATCH 6/7] iio: adc: sun4i-gpadc-iio: add support for H6 thermal sensor Date: Fri, 3 May 2019 03:28:12 -0400 Message-Id: <20190503072813.2719-7-tiny.windzz@gmail.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190503072813.2719-1-tiny.windzz@gmail.com> References: <20190503072813.2719-1-tiny.windzz@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190503_002840_102750_B6ADA042 X-CRM114-Status: GOOD ( 17.37 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-iio@vger.kernel.org, devicetree@vger.kernel.org, Yangtao Li , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This patch adds support for the H6 ths sensor. TODO: calibrate thermal sensor by using information from sid. Signed-off-by: Yangtao Li --- drivers/iio/adc/sun4i-gpadc-iio.c | 65 +++++++++++++++++++++++++++++++ include/linux/mfd/sun4i-gpadc.h | 9 +++++ 2 files changed, 74 insertions(+) diff --git a/drivers/iio/adc/sun4i-gpadc-iio.c b/drivers/iio/adc/sun4i-gpadc-iio.c index f24eb76d65c0..9b6fc592f54c 100644 --- a/drivers/iio/adc/sun4i-gpadc-iio.c +++ b/drivers/iio/adc/sun4i-gpadc-iio.c @@ -120,6 +120,20 @@ static const struct gpadc_data sun8i_a33_gpadc_data = { .temp_data_base = SUN4I_GPADC_TEMP_DATA, }; +static int sun50i_gpadc_disable(struct sun4i_gpadc_iio *info); +static int sun50i_gpadc_enable(struct sun4i_gpadc_iio *info); + +static const struct gpadc_data sun50i_h6_gpadc_data = { + .temp_offset = -2809, + .temp_scale = -67, + .has_bus_clk = true, + .has_bus_rst = true, + .gpadc_enable = sun50i_gpadc_enable, + .gpadc_disable = sun50i_gpadc_disable, + .sensor_count = 2, + .temp_data_base = SUN50I_H6_GPADC_TEMP_DATA, +}; + struct sun4i_sensor_tzd { struct sun4i_gpadc_iio *info; struct thermal_zone_device *tzd; @@ -452,6 +466,53 @@ static int sun4i_gpadc_enable(struct sun4i_gpadc_iio *info) return 0; } +static int sun50i_gpadc_enable(struct sun4i_gpadc_iio *info) +{ + int ret, val; + + ret = reset_control_deassert(info->reset); + if (ret) + return ret; + + ret = clk_prepare_enable(info->bus_clk); + if (ret) + goto assert_reset; + + /* + * clkin = 24MHz + * T acquire = clkin / (SUN50I_GPADC_CTRL0_T_ACQ + 1) + * = 20us + */ + regmap_write(info->regmap, SUN4I_GPADC_CTRL0, + SUN50I_GPADC_CTRL0_T_ACQ(479)); + /* average over 4 samples */ + regmap_write(info->regmap, SUN50I_H6_GPADC_CTRL3, + SUN4I_GPADC_CTRL3_FILTER_EN | + SUN4I_GPADC_CTRL3_FILTER_TYPE(1)); + /* period = (SUN50I_GPADC_TPR_TEMP_PERIOD + 1) * 4096 / clkin; ~10ms */ + regmap_write(info->regmap, SUN50I_GPADC_TPR, + SUN50I_GPADC_TPR_TEMP_PERIOD(58)); + /* TODO: calibrate ths */ + /* enable sensor */ + val = GENMASK(info->data->sensor_count - 1, 0); + regmap_write(info->regmap, SUN4I_GPADC_CTRL1, val); + + return 0; + +assert_reset: + reset_control_assert(info->reset); + + return ret; +} + +static int sun50i_gpadc_disable(struct sun4i_gpadc_iio *info) +{ + clk_disable_unprepare(info->bus_clk); + reset_control_assert(info->reset); + + return 0; +} + static int sun4i_gpadc_runtime_suspend(struct device *dev) { struct sun4i_gpadc_iio *info = iio_priv(dev_get_drvdata(dev)); @@ -546,6 +607,10 @@ static const struct of_device_id sun4i_gpadc_of_id[] = { .compatible = "allwinner,sun8i-a33-ths", .data = &sun8i_a33_gpadc_data, }, + { + .compatible = "allwinner,sun50i-h6-ths", + .data = &sun50i_h6_gpadc_data, + }, { /* sentinel */ } }; diff --git a/include/linux/mfd/sun4i-gpadc.h b/include/linux/mfd/sun4i-gpadc.h index 139872c2e0fe..f505013e9c0d 100644 --- a/include/linux/mfd/sun4i-gpadc.h +++ b/include/linux/mfd/sun4i-gpadc.h @@ -19,6 +19,9 @@ #define SUN4I_GPADC_CTRL0_FS_DIV(x) ((GENMASK(3, 0) & (x)) << 16) #define SUN4I_GPADC_CTRL0_T_ACQ(x) (GENMASK(15, 0) & (x)) +/* TP_CTRL0 bits for sun50i SOCs */ +#define SUN50I_GPADC_CTRL0_T_ACQ(x) ((GENMASK(15, 0) & (x)) << 16) + #define SUN4I_GPADC_CTRL1 0x04 #define SUN4I_GPADC_CTRL1_STYLUS_UP_DEBOUNCE(x) ((GENMASK(7, 0) & (x)) << 12) @@ -49,6 +52,9 @@ #define SUN4I_GPADC_CTRL2_PRE_MEA_EN BIT(24) #define SUN4I_GPADC_CTRL2_PRE_MEA_THRE_CNT(x) (GENMASK(23, 0) & (x)) +#define SUN50I_GPADC_TPR 0x08 +#define SUN50I_GPADC_TPR_TEMP_PERIOD(x) ((GENMASK(19, 0) & (x)) << 12) + #define SUN4I_GPADC_CTRL3 0x0c #define SUN4I_GPADC_CTRL3_FILTER_EN BIT(2) @@ -84,6 +90,9 @@ #define SUN4I_GPADC_TEMP_DATA 0x20 #define SUN4I_GPADC_DATA 0x24 +#define SUN50I_H6_GPADC_CTRL3 0x30 +#define SUN50I_H6_GPADC_TEMP_DATA 0xc0 + #define SUN4I_GPADC_IRQ_FIFO_DATA 0 #define SUN4I_GPADC_IRQ_TEMP_DATA 1 From patchwork Fri May 3 07:28:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yangtao Li X-Patchwork-Id: 10927999 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1694B92A for ; Fri, 3 May 2019 07:29:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EF364281C3 for ; Fri, 3 May 2019 07:29:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E105F2821F; Fri, 3 May 2019 07:29:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 97AF8281C3 for ; Fri, 3 May 2019 07:29:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=j1agit8eR0KtIjgR0tnsp4S20oYOLYU16x7b2xGl9IE=; b=DGSVyu6fePidWY8uk6EiLpl52J 5mgbBfrDGSclIgMtetMP1JIQ47jEZ7kG6jbHFjQrXd05wMkoJ0mONnU8ZT9rH3NCXsKJ1iQj10Ywa jtO4fNslV7GceJ0Y0Zdk/yHZzTujF42b6G7vuN3KbGSiaf9YicIM/jNVygaoocmW4PqA0kfYN7CI1 0k7ShuWdKa3Z7wHYw5hBJ1DleRtG/a0oxalmFr+lSOaNWnGWOJml+Jz2BSsZ+Ld9NnNZUtWy2KAfk FeuG4oaKCoAt5zPQMwU3D/dHSozem0caIYTC7skzukgs4QoJkBFQFfxA4mtqzlLVEinZrN4wMt6z6 eTVKUxpg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hMSdZ-00080v-UM; Fri, 03 May 2019 07:29:41 +0000 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hMScb-0006j0-I9 for linux-arm-kernel@lists.infradead.org; Fri, 03 May 2019 07:28:56 +0000 Received: by mail-pg1-x544.google.com with SMTP id f6so2304496pgs.8 for ; Fri, 03 May 2019 00:28:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=iV91r0hSgx47A83AU5LfJSSAdebNF8xkPCOvty2B81w=; b=f0kMsjpx0hReZbqS9A/IXDD04OeHrLmjwND+PaKZnv0lNFwIvz1+8f/D0fcaBpcjIr 3THia+s7KlQAPC75y6kfAM5tFbhKhcK34VvYtG4SXXajH/prr3rBdObYEUimYeMrLHAM W9stvHHEUJWhi/4TWXlJBqWsT9hZSZP2hS/A+mhwG5KMLY0Nh0oFW2fr+lFayywX4In0 iEQuIFu8AXL/SFXCBXSjZJiu/68s0Vcvab2mgf6lLgypQd+wNuiqu6e7aGeAz40vry7K 0QXiQC5eQDPBGYe90V+j2Vs6Ek4/nQiUNNjl0nkv+uApUE6juP602HM41dGAu2IDWZsd 3cWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=iV91r0hSgx47A83AU5LfJSSAdebNF8xkPCOvty2B81w=; b=afm8qIKadxtLE0vPHZ0vdp60FQw8VEAS2J/pv/ert9DlvrB3mJvNUih2xcWyZIM4Kc DE56bZ1iJMH5Z+j4TwZy5UzCXHcd65dUiuGdRHB8w19UoIfDjvQ2SRs/8B6AEzAuidGU w3l6TDgyvtDbKiondTpxRmJw/W4HQbxPRotapX1aO62u2HCT430HzJNCcfKHLSR8bGKJ c8CT2s1LIMtJ1MaSwhOQb5tT+rBswXABKqEd9H/eFGf8W3IerKHw7Qn1s32eZDXB+SR8 jXMI5NtbGQRKaPt20pFLgbbEkXdx7ThtM4LJGTyp81REKlTMLEsHcw8SoOYP8WU4uFWq w90Q== X-Gm-Message-State: APjAAAXClqWTeIdJz2EudXAR9qcP+GiDJnz3qqteC7twxs1HecPUcvMT I/UTQI7BsHrz+FmFVua0Krc= X-Google-Smtp-Source: APXvYqx3mHSYhYaU9e7dYSrcNlJV0QAsUNqmUsZfT1vnGpilYcYIfUsnBG2kbbtSGDGI8szlCy5aNg== X-Received: by 2002:a63:534f:: with SMTP id t15mr8595106pgl.445.1556868521022; Fri, 03 May 2019 00:28:41 -0700 (PDT) Received: from localhost (68.168.130.77.16clouds.com. [68.168.130.77]) by smtp.gmail.com with ESMTPSA id c18sm2318243pfc.0.2019.05.03.00.28.40 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 03 May 2019 00:28:40 -0700 (PDT) From: Yangtao Li To: lee.jones@linaro.org, robh+dt@kernel.org, mark.rutland@arm.com, maxime.ripard@bootlin.com, wens@csie.org, jic23@kernel.org, knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net Subject: [PATCH 7/7] iio: adc: sun4i-gpadc-iio convert to SPDX license tags Date: Fri, 3 May 2019 03:28:13 -0400 Message-Id: <20190503072813.2719-8-tiny.windzz@gmail.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190503072813.2719-1-tiny.windzz@gmail.com> References: <20190503072813.2719-1-tiny.windzz@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190503_002842_352503_D8083B34 X-CRM114-Status: GOOD ( 11.52 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-iio@vger.kernel.org, devicetree@vger.kernel.org, Yangtao Li , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Updates license to use SPDX-License-Identifier. Signed-off-by: Yangtao Li --- drivers/iio/adc/sun4i-gpadc-iio.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/drivers/iio/adc/sun4i-gpadc-iio.c b/drivers/iio/adc/sun4i-gpadc-iio.c index 9b6fc592f54c..cf2bf3ab3342 100644 --- a/drivers/iio/adc/sun4i-gpadc-iio.c +++ b/drivers/iio/adc/sun4i-gpadc-iio.c @@ -1,11 +1,8 @@ +// SPDX-License-Identifier: GPL-2.0+ /* ADC driver for sunxi platforms' (A10, A13 and A31) GPADC * * Copyright (c) 2016 Quentin Schulz * - * This program is free software; you can redistribute it and/or modify it under - * the terms of the GNU General Public License version 2 as published by the - * Free Software Foundation. - * * The Allwinner SoCs all have an ADC that can also act as a touchscreen * controller and a thermal sensor. * The thermal sensor works only when the ADC acts as a touchscreen controller