From patchwork Mon Apr 17 18:28:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Blumenstingl X-Patchwork-Id: 9684033 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B840B600F6 for ; Mon, 17 Apr 2017 18:29:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AE04628174 for ; Mon, 17 Apr 2017 18:29:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A26622817F; Mon, 17 Apr 2017 18:29:40 +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=-1.9 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.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 0B05128174 for ; Mon, 17 Apr 2017 18:29:40 +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=h/6IQ2Gw205SwVIFq9YztAkMw7aPkKCTJ8z1AgxFrdU=; b=ub/LRetC2HRYBsGQFfdOry+fDx z7usvLxNf3LlkvV++IdQnhGGTwZkgL7qOY7xaSKxDPX16Qui77myiY+RLFOMDhluFx7gDQoAzYYAv luy5NfJtBMVw21W8rwP3xzDShqUCRY3dTLPA7jJ/AJaAuBWMmN2+CsDiC6ALvDjyA+gOQ5U7oSIx8 BBt5fMkqycVlVxqdtE+fRktLYYkOpck5nSq3jm2f84+g7dU6VPUEPizi+lBLt6LPITugMNdJJVVfq /sOgwrfTbM97foRo9GNVOFihzI7d0TCOHVVHSuFAXK9kkaniMwjL3pn5hlOO+Uuenlj+3gubpmqXM xlyr8sig==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1d0BP1-0006GJ-7O; Mon, 17 Apr 2017 18:29:31 +0000 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1d0BOT-0005dK-UR; Mon, 17 Apr 2017 18:29:01 +0000 Received: by mail-wm0-x244.google.com with SMTP id d79so10396409wmi.2; Mon, 17 Apr 2017 11:28:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=xkATXFJF+2P7v5WuNJMbFhdD03gDzru5/luwd6fZFmw=; b=eQUwlRr94RbPdN/Sh23vh2Pmb1K7oyQIZL7q549AUaYzpDyLSZBDzAW7myqLJ+5PPY ogWH1ErBA5u5kK6YLUTzvaBJa5EZch6BKOrXvnk3JWKMOfMqxyFop5AG6GlX3slBOjF9 hNA9wsdsJfujeAKClwJ5FjWZC190sixkBiFNTCDWKyVUKqcJWQuQ5q2ixq1iRBz0rv7C hfLmMvDQVO4X3YsjUFRxylI0HkNKjJi2/ZMn8h1ntlUfpM1pXbH6VgCTQ26txviMEb9P 3gwO2iq8UFS+wF6jGlmQUnmOdHOgoCNHjoBSMMgy+rnScxjeTfu+AypMZCTQYgszCC2X B4kQ== 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=xkATXFJF+2P7v5WuNJMbFhdD03gDzru5/luwd6fZFmw=; b=S38o0OxXlfuHZDw12c/mPr4nXUQsTOzrLHX79bwfsr+UFb9OU0BVoQu+4ilcAuIt99 hv5cJEdOTkKjjziG4+0JNeCRZAm5rZdxWV8zO/XlXwFKYxcTsBmtw5FTxNUws80jK937 dJ7fxFhdEixSwtVhOaFVr47terHrsAVS60czWyboPs7b16dAGMN3Ozwbcl7VbGPzgCuT vUoUwfMM3qTIDZF626acL1q5kScqEBftQT8Pfj3A5REcvJ7mmBjQST3r5Kz+VxD4YwsQ xq5hKqn97pFnV8y8lWEp3BWzpNBN8Z7hPkDtBThv72gS/7j9f5l6pw/BM9n8XRgtu/VA Sixw== X-Gm-Message-State: AN3rC/7Akwmvx70epV1hJkE1FJI1smn2C2GeqzQZetgXvI0qgZtJ+ncW c4zKFAIFU4fIiw== X-Received: by 10.28.140.17 with SMTP id o17mr9266510wmd.14.1492453715780; Mon, 17 Apr 2017 11:28:35 -0700 (PDT) Received: from blackbox.darklights.net (p200300DCD3CA7E045886EFA6B17A7A33.dip0.t-ipconnect.de. [2003:dc:d3ca:7e04:5886:efa6:b17a:7a33]) by smtp.googlemail.com with ESMTPSA id v14sm15354192wra.65.2017.04.17.11.28.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Apr 2017 11:28:35 -0700 (PDT) From: Martin Blumenstingl To: jic23@kernel.org, knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net, robh+dt@kernel.org, mark.rutland@arm.com, linux-iio@vger.kernel.org Subject: [PATCH 2/3] iio: adc: meson-saradc: add Meson8b SoC compatibility Date: Mon, 17 Apr 2017 20:28:19 +0200 Message-Id: <20170417182820.26670-3-martin.blumenstingl@googlemail.com> X-Mailer: git-send-email 2.12.2 In-Reply-To: <20170417182820.26670-1-martin.blumenstingl@googlemail.com> References: <20170417182820.26670-1-martin.blumenstingl@googlemail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170417_112858_253929_786E6BAD X-CRM114-Status: GOOD ( 19.75 ) 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: devicetree@vger.kernel.org, Martin Blumenstingl , khilman@baylibre.com, carlo@caione.org, linux-amlogic@lists.infradead.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 Meson GX SoCs however use some magic bits to prevent simultaneous (= conflicting, because only consumer should use the FIFO buffer with the ADC results) usage by the Linux kernel and the bootloader (the BL30 bootloader uses the SAR ADC to read the CPU temperature). This patch changes guards all BL30 functionality so it is skipped on SoCs which don't have it. Since the hardware itself doesn't know whether BL30 is available the internal meson_sar_adc_data is extended so this information can be provided per of_device_id.data inside the driver. Additionally the clocks "adc_clk" and "adc_sel" are not provided by the clock-controller itself. "adc_sel" is not available at all. "adc_clk" is provided by the SAR ADC IP block itself on Meson8b (and earlier). This is already supported by the meson_saradc driver. Finally a new of_device_id for the Meson8b SoC is added so it can be wired up in the corresponding DT. Signed-off-by: Martin Blumenstingl --- drivers/iio/adc/meson_saradc.c | 80 +++++++++++++++++++++++++++++------------- 1 file changed, 56 insertions(+), 24 deletions(-) diff --git a/drivers/iio/adc/meson_saradc.c b/drivers/iio/adc/meson_saradc.c index dd4190b50df6..cf13691009ee 100644 --- a/drivers/iio/adc/meson_saradc.c +++ b/drivers/iio/adc/meson_saradc.c @@ -220,6 +220,7 @@ enum meson_sar_adc_chan7_mux_sel { }; struct meson_sar_adc_data { + bool has_bl30_integration; unsigned int resolution; const char *name; }; @@ -437,19 +438,24 @@ static int meson_sar_adc_lock(struct iio_dev *indio_dev) mutex_lock(&indio_dev->mlock); - /* prevent BL30 from using the SAR ADC while we are using it */ - regmap_update_bits(priv->regmap, MESON_SAR_ADC_DELAY, - MESON_SAR_ADC_DELAY_KERNEL_BUSY, - MESON_SAR_ADC_DELAY_KERNEL_BUSY); - - /* wait until BL30 releases it's lock (so we can use the SAR ADC) */ - do { - udelay(1); - regmap_read(priv->regmap, MESON_SAR_ADC_DELAY, &val); - } while (val & MESON_SAR_ADC_DELAY_BL30_BUSY && timeout--); - - if (timeout < 0) - return -ETIMEDOUT; + if (priv->data->has_bl30_integration) { + /* prevent BL30 from using the SAR ADC while we are using it */ + regmap_update_bits(priv->regmap, MESON_SAR_ADC_DELAY, + MESON_SAR_ADC_DELAY_KERNEL_BUSY, + MESON_SAR_ADC_DELAY_KERNEL_BUSY); + + /* + * wait until BL30 releases it's lock (so we can use the SAR + * ADC) + */ + do { + udelay(1); + regmap_read(priv->regmap, MESON_SAR_ADC_DELAY, &val); + } while (val & MESON_SAR_ADC_DELAY_BL30_BUSY && timeout--); + + if (timeout < 0) + return -ETIMEDOUT; + } return 0; } @@ -458,9 +464,10 @@ static void meson_sar_adc_unlock(struct iio_dev *indio_dev) { struct meson_sar_adc_priv *priv = iio_priv(indio_dev); - /* allow BL30 to use the SAR ADC again */ - regmap_update_bits(priv->regmap, MESON_SAR_ADC_DELAY, - MESON_SAR_ADC_DELAY_KERNEL_BUSY, 0); + if (priv->data->has_bl30_integration) + /* allow BL30 to use the SAR ADC again */ + regmap_update_bits(priv->regmap, MESON_SAR_ADC_DELAY, + MESON_SAR_ADC_DELAY_KERNEL_BUSY, 0); mutex_unlock(&indio_dev->mlock); } @@ -614,14 +621,16 @@ static int meson_sar_adc_init(struct iio_dev *indio_dev) */ meson_sar_adc_set_chan7_mux(indio_dev, CHAN7_MUX_CH7_INPUT); - /* - * leave sampling delay and the input clocks as configured by BL30 to - * make sure BL30 gets the values it expects when reading the - * temperature sensor. - */ - regmap_read(priv->regmap, MESON_SAR_ADC_REG3, ®val); - if (regval & MESON_SAR_ADC_REG3_BL30_INITIALIZED) - return 0; + if (priv->data->has_bl30_integration) { + /* + * leave sampling delay and the input clocks as configured by + * BL30 to make sure BL30 gets the values it expects when + * reading the temperature sensor. + */ + regmap_read(priv->regmap, MESON_SAR_ADC_REG3, ®val); + if (regval & MESON_SAR_ADC_REG3_BL30_INITIALIZED) + return 0; + } meson_sar_adc_stop_sample_engine(indio_dev); @@ -834,23 +843,46 @@ static const struct iio_info meson_sar_adc_iio_info = { .driver_module = THIS_MODULE, }; +struct meson_sar_adc_data meson_sar_adc_meson8_data = { + .has_bl30_integration = false, + .resolution = 10, + .name = "meson-meson8b-saradc", +}; + +struct meson_sar_adc_data meson_sar_adc_meson8b_data = { + .has_bl30_integration = false, + .resolution = 10, + .name = "meson-meson8b-saradc", +}; + struct meson_sar_adc_data meson_sar_adc_gxbb_data = { + .has_bl30_integration = true, .resolution = 10, .name = "meson-gxbb-saradc", }; struct meson_sar_adc_data meson_sar_adc_gxl_data = { + .has_bl30_integration = true, .resolution = 12, .name = "meson-gxl-saradc", }; struct meson_sar_adc_data meson_sar_adc_gxm_data = { + .has_bl30_integration = true, .resolution = 12, .name = "meson-gxm-saradc", }; static const struct of_device_id meson_sar_adc_of_match[] = { { + .compatible = "amlogic,meson8-saradc", + .data = &meson_sar_adc_meson8_data, + }, + { + .compatible = "amlogic,meson8b-saradc", + .data = &meson_sar_adc_meson8b_data, + }, + { .compatible = "amlogic,meson-gxbb-saradc", .data = &meson_sar_adc_gxbb_data, }, {