From patchwork Tue Oct 31 20:01:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Blumenstingl X-Patchwork-Id: 10035335 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 5A3DC602B9 for ; Tue, 31 Oct 2017 20:02:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4DAE728A7C for ; Tue, 31 Oct 2017 20:02:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 429CE28AA1; Tue, 31 Oct 2017 20:02:32 +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=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DBB5528A7C for ; Tue, 31 Oct 2017 20:02:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753876AbdJaUCb (ORCPT ); Tue, 31 Oct 2017 16:02:31 -0400 Received: from mail-wr0-f195.google.com ([209.85.128.195]:56823 "EHLO mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753874AbdJaUCa (ORCPT ); Tue, 31 Oct 2017 16:02:30 -0400 Received: by mail-wr0-f195.google.com with SMTP id r79so119323wrb.13 for ; Tue, 31 Oct 2017 13:02:30 -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=jTWoV+CqxUlPk0vtDpQXolC0IenludliBlK/RezdcDQ=; b=QSln9bCW0bk5M5ygl/63cvYrZqDRAUl+6jTj+JrxbmLwBdeOxq5zPM24Jk4HyytJCG hoWVREQ7dYcKZD+0qA27KMso49C/E5iwAUncJaRSkWute5QHJ/Sevk18ykjCkPg/SNg2 yLEWQywwk4XwLpiCs60S/mxdks8+GM3SMsGMicwZlL9R3VNKNWC2Y5r9xjNoQvZN76A/ TzF8u3/gTJP7shqT3Yol/lJBhBhcdzpdg6Tnjj5IYVCdES8BmxqqEESl0oWqnxDNsmoa xvKlswLGaN8RH9hgBjjL3F/derlAn6CIjSk2ArCHxKAos6eA3QXn3K+9HVe/Ws05FJ/F /RtQ== 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=jTWoV+CqxUlPk0vtDpQXolC0IenludliBlK/RezdcDQ=; b=nt6zg21P7BjWxc+mOj6AtO5MvpTE/2ISam7KaYylGjPZIktYm/fNE/MKg2lvOm8vaD /YaxEfvg6YZF99ZnR6rFCCqm/c4TuS+R0voGC3GECbd/GZTe46Lt97WD/guUD+Zk+FFO A2HuGZDBwHaxf4Bx5cbf0Kp9kaM8XNVZXRDNmVGGXrJEhVnZvZy0UxRa/FdEFy7tOhl1 dZYOMbjr5lpx57BoerowV+ZiMudt5OA31KNLxM8mD54O4TreCFvN3txT29iXsubEwlAS TbqJzClz0SgxE2155B/ma/DpUp9u5rhYSh0DKMnTjnePwAb7BBuYOukLExXjZj11q4BU /AOA== X-Gm-Message-State: AMCzsaWQZ4Ba1ZGRUtFZY++5WV0OVkGUY8Z0x4d6T9rG0RH6/xHWHiBJ j6e4egh1F/DGiDQI5/viXveCGNxL X-Google-Smtp-Source: ABhQp+Tuzt/ApYM65ZI0sfYVU4+1fd4SVwoSPy5mzrQSeFRtwNiH1FnGKt+/diwgzPKZqoyrX3a9xQ== X-Received: by 10.223.154.74 with SMTP id z68mr2786886wrb.36.1509480149109; Tue, 31 Oct 2017 13:02:29 -0700 (PDT) Received: from blackbox.darklights.net (p5DE3887A.dip0.t-ipconnect.de. [93.227.136.122]) by smtp.googlemail.com with ESMTPSA id c17sm3420261wrg.26.2017.10.31.13.02.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 31 Oct 2017 13:02:28 -0700 (PDT) From: Martin Blumenstingl To: linux-iio@vger.kernel.org, jic23@kernel.org, knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net Cc: linux-amlogic@lists.infradead.org, Martin Blumenstingl Subject: [PATCH 5/5] iio: adc: meson-saradc: program the channel muxes during initialization Date: Tue, 31 Oct 2017 21:01:47 +0100 Message-Id: <20171031200147.14660-6-martin.blumenstingl@googlemail.com> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20171031200147.14660-1-martin.blumenstingl@googlemail.com> References: <20171031200147.14660-1-martin.blumenstingl@googlemail.com> Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On some Meson8 devices the channel muxes are not programmed. This results in garbage values when trying to read channels that are not set up. Fix this by initializing the channel 0 and 1 muxes in MESON_SAR_ADC_CHAN_10_SW as well as the muxes for all other channels in MESON_SAR_ADC_AUX_SW based on what the vendor driver does (which is simply a 1:1 mapping of channel number and channel mux). This only showed up on Meson8 devices, because for GXBB and newer BL30 is taking care of initializing the channel muxes. This additionally fixes a typo in the MESON_SAR_ADC_AUX_SW_MUX_SEL_CHAN_MASK macro because the old definition assumed that the register fields were 2 bit wide, while they are actually 3 bit wide. Signed-off-by: Martin Blumenstingl --- drivers/iio/adc/meson_saradc.c | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/drivers/iio/adc/meson_saradc.c b/drivers/iio/adc/meson_saradc.c index fa3c1378c2c9..48fb1b642a5e 100644 --- a/drivers/iio/adc/meson_saradc.c +++ b/drivers/iio/adc/meson_saradc.c @@ -96,8 +96,8 @@ #define MESON_SAR_ADC_FIFO_RD_SAMPLE_VALUE_MASK GENMASK(11, 0) #define MESON_SAR_ADC_AUX_SW 0x1c - #define MESON_SAR_ADC_AUX_SW_MUX_SEL_CHAN_MASK(_chan) \ - (GENMASK(10, 8) << (((_chan) - 2) * 2)) + #define MESON_SAR_ADC_AUX_SW_MUX_SEL_CHAN_SHIFT(_chan) \ + (8 + (((_chan) - 2) * 3)) #define MESON_SAR_ADC_AUX_SW_VREF_P_MUX BIT(6) #define MESON_SAR_ADC_AUX_SW_VREF_N_MUX BIT(5) #define MESON_SAR_ADC_AUX_SW_MODE_SEL BIT(4) @@ -623,7 +623,7 @@ static int meson_sar_adc_clk_init(struct iio_dev *indio_dev, static int meson_sar_adc_init(struct iio_dev *indio_dev) { struct meson_sar_adc_priv *priv = iio_priv(indio_dev); - int regval, ret; + int regval, i, ret; /* * make sure we start at CH7 input since the other muxes are only used @@ -678,6 +678,32 @@ static int meson_sar_adc_init(struct iio_dev *indio_dev) FIELD_PREP(MESON_SAR_ADC_DELAY_INPUT_DLY_SEL_MASK, 1)); + /* + * set up the input channel muxes in MESON_SAR_ADC_CHAN_10_SW + * (0 = SAR_ADC_CH0, 1 = SAR_ADC_CH1) + */ + regval = FIELD_PREP(MESON_SAR_ADC_CHAN_10_SW_CHAN0_MUX_SEL_MASK, 0); + regmap_update_bits(priv->regmap, MESON_SAR_ADC_CHAN_10_SW, + MESON_SAR_ADC_CHAN_10_SW_CHAN0_MUX_SEL_MASK, + regval); + regval = FIELD_PREP(MESON_SAR_ADC_CHAN_10_SW_CHAN1_MUX_SEL_MASK, 1); + regmap_update_bits(priv->regmap, MESON_SAR_ADC_CHAN_10_SW, + MESON_SAR_ADC_CHAN_10_SW_CHAN1_MUX_SEL_MASK, + regval); + + /* + * set up the input channel muxes in MESON_SAR_ADC_AUX_SW + * (2 = SAR_ADC_CH2, 3 = SAR_ADC_CH3, ...) and enable + * MESON_SAR_ADC_AUX_SW_YP_DRIVE_SW and + * MESON_SAR_ADC_AUX_SW_XP_DRIVE_SW like the vendor driver. + */ + regval = 0; + for (i = 2; i <= 7; i++) + regval |= i << MESON_SAR_ADC_AUX_SW_MUX_SEL_CHAN_SHIFT(i); + regval |= MESON_SAR_ADC_AUX_SW_YP_DRIVE_SW; + regval |= MESON_SAR_ADC_AUX_SW_XP_DRIVE_SW; + regmap_write(priv->regmap, MESON_SAR_ADC_AUX_SW, regval); + ret = clk_set_parent(priv->adc_sel_clk, priv->clkin); if (ret) { dev_err(indio_dev->dev.parent,