From patchwork Sat Mar 25 16:29:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Blumenstingl X-Patchwork-Id: 9644699 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 8A89B60327 for ; Sat, 25 Mar 2017 16:30:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8D8B02621D for ; Sat, 25 Mar 2017 16:30:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8298827FB0; Sat, 25 Mar 2017 16:30: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=-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 1A80D2621D for ; Sat, 25 Mar 2017 16:30: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=gIVouoou462uI7mN1PkNap1ZZ/iDv6MRKvhkHm8ISdU=; b=A7V45eZaii23haU3/Q0nCzEL9J J7eexPBMtVcBsmK4q25Ivg95B6/6x38xcdOhtplO3cHdfl5c32wmIv8VzUzHXSOo0bvum4ZjI1m4H HAs3bfklvzb+pPK3Hs0mO0UjprhMMEgVePW1Vpa1GNFMCxbiJlHG0ZlnBiRpUoE5wRsuBQOZX8Sbt NfYnwjOaG3b4XNhQUwYXtDOZStFKYfs+qUIIM5sFEOIcl/w3xtoMO6KztqNZbB7Y79kwO4QXcuWl/ sPZcNTAa+TSDFrsqWy7fxjpF4t9811ao5CcJZaTHpx5JJAYeI4sTG0SZ7Jg+T8rOERL17He8Qtr4Q HINs31uA==; 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 1croaO-0008KK-0g; Sat, 25 Mar 2017 16:30:40 +0000 Received: from mail-wr0-x242.google.com ([2a00:1450:400c:c0c::242]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1croZy-0006RF-Am; Sat, 25 Mar 2017 16:30:17 +0000 Received: by mail-wr0-x242.google.com with SMTP id y90so2572640wrb.1; Sat, 25 Mar 2017 09:29:56 -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=m35MvKvbDxQjKXBilSKKTyHfaCFCfh2L4yJBuqfpSrY=; b=gqCVuzrPTyhdhD5dPmQm0oj7B6xd3U6yBjQrLSzTtFOebcCU4OfVCPul02Bfqz9bUI Sw5hT7ihu99N4lrScSGpHo8mIOO0p3cGcCJ1JT4mDgwYfSU5xwYZh0jquVWatxudyiMW xLnowtAAJG1sjRH3lqF9AbiprSgtUSb61mF/6gw3Z4R3vuBdHdtIooD6p0C7NFlW0Fgs SeFoKxC8PF1cn2c1zgaUXlD7qiVBaLKyLxu+tjY3mkkreG9tKP9Sg0tr5KQ2E4JVqDdq Uh5/Rh/Q4/SMLk2aV+F/NwbAfyF73VUsB2NtK9IDL0dfGTekd5VBuQf+ao4WhznjywYl sYWA== 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=m35MvKvbDxQjKXBilSKKTyHfaCFCfh2L4yJBuqfpSrY=; b=guqV36W7cUaOXIj3I/89uWonxnK0HAh5BftUCEkKm9GbyPeL3T2FsmNobi7nNvTdqS twwAA+aGbrL9xIBsj5EyUJzxhJCvCo0uh8mwNVdnjECuw/i/qe+NhBhO8J9aA+rZyPWa f/kVlebjT113wLTJZ0/E0TGjvn2Nq1ny9zGqWOsj9Lgi90LyGASvOi889wc50436tTt6 VV8DIwCdsSgu7U0gYC9KNxHdrO8cSniUJ8aq8MVGMYRBhQGCEOTzn/uQEk4I1RbntIYu Z8pQlsrvH/A5xs4zLUBlIPUgzVZxzPQQZd6H60i1RQhAbzzHhGQ0gyImR5QMUOLmHtH0 F3iA== X-Gm-Message-State: AFeK/H2ATqLUERTgMyzl/36PIcpO7RDkQXJor+xSOOPbVXO3pG/Cv2Z4LMbdXk+HGgTyuQ== X-Received: by 10.223.166.46 with SMTP id k43mr870341wrc.64.1490459395224; Sat, 25 Mar 2017 09:29:55 -0700 (PDT) Received: from blackbox.darklights.net (p5DE38642.dip0.t-ipconnect.de. [93.227.134.66]) by smtp.googlemail.com with ESMTPSA id b199sm7121955wmb.13.2017.03.25.09.29.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 25 Mar 2017 09:29:54 -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/2] iio: adc: meson-saradc: add Meson8b SoC compatibility Date: Sat, 25 Mar 2017 17:29:38 +0100 Message-Id: <20170325162938.28659-3-martin.blumenstingl@googlemail.com> X-Mailer: git-send-email 2.12.1 In-Reply-To: <20170325162938.28659-1-martin.blumenstingl@googlemail.com> References: <20170325162938.28659-1-martin.blumenstingl@googlemail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170325_093014_569187_74D4FE35 X-CRM114-Status: GOOD ( 19.92 ) 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 | 70 +++++++++++++++++++++++++++--------------- 1 file changed, 46 insertions(+), 24 deletions(-) diff --git a/drivers/iio/adc/meson_saradc.c b/drivers/iio/adc/meson_saradc.c index dd4190b50df6..f78fe66e0ec8 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 { + char 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,36 @@ static const struct iio_info meson_sar_adc_iio_info = { .driver_module = THIS_MODULE, }; +struct meson_sar_adc_data meson_sar_adc_meson8b_data = { + .has_bl30_integration = 0, + .resolution = 10, + .name = "meson-meson8b-saradc", +}; + struct meson_sar_adc_data meson_sar_adc_gxbb_data = { + .has_bl30_integration = 1, .resolution = 10, .name = "meson-gxbb-saradc", }; struct meson_sar_adc_data meson_sar_adc_gxl_data = { + .has_bl30_integration = 1, .resolution = 12, .name = "meson-gxl-saradc", }; struct meson_sar_adc_data meson_sar_adc_gxm_data = { + .has_bl30_integration = 1, .resolution = 12, .name = "meson-gxm-saradc", }; static const struct of_device_id meson_sar_adc_of_match[] = { { + .compatible = "amlogic,meson8b-saradc", + .data = &meson_sar_adc_meson8b_data, + }, + { .compatible = "amlogic,meson-gxbb-saradc", .data = &meson_sar_adc_gxbb_data, }, {