From patchwork Sat Nov 3 23:10:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Blumenstingl X-Patchwork-Id: 10666795 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 11ECA17DF for ; Sat, 3 Nov 2018 23:10:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D7F5929D2C for ; Sat, 3 Nov 2018 23:10:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C5DF729D2E; Sat, 3 Nov 2018 23:10:34 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 4A9D629D2C for ; Sat, 3 Nov 2018 23:10:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728728AbeKDIXQ (ORCPT ); Sun, 4 Nov 2018 03:23:16 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:34014 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726703AbeKDIXQ (ORCPT ); Sun, 4 Nov 2018 03:23:16 -0500 Received: by mail-wr1-f67.google.com with SMTP id j26-v6so5538201wre.1; Sat, 03 Nov 2018 16:10:32 -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:mime-version :content-transfer-encoding; bh=a4LiP7YFQuFtt+Db1nEnP/ZvzBfZ0jwyQ05C7HAHUdQ=; b=lz9H5Zij+UkJ9iNV/Zn6/B0tBkXVjOJew7i8Qb9ngtVZP24e0LViu1ilRJoXNWDFu+ rurorfV7+H/J7sZcf3Pa43eAYuEtBzQOaH5JT6Vi2Y0CMdtWgKxitwszV6a4pZUZB28H eLzXgQGbyb326EySzcvj3oPzy2HUj7uaIuuGG61GcBOeHKzGWi2PmnzTGQvBxv+4rlR8 eFIL2sftw4ZoTBJN9dH/bzKQka4YqJSAAldPscZm7hgUWpDoTNZHt0mMnTyide0/xnek kmlwB4EfE3Z7EyHwcoHVNQnT0DZe3T/cOOxtgixBuQ7G4E54Xnohw7U9o7fErna/g8FE /kgA== 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:mime-version :content-transfer-encoding; bh=a4LiP7YFQuFtt+Db1nEnP/ZvzBfZ0jwyQ05C7HAHUdQ=; b=uaVCLAwwxN75XqfiIuEp1znXQWCOvTxMhjz2riGK+7mihr+wyJ851M/8wD45E5PCbb Iyd/LrcjbN3ev4hDfm8KUsbVLLigICcXuq6vNkyNXPnQTGOiMg6m+TvPmAfRQW57Fb0g fvfHloOpm+1TSMJydqTVp79U5oaONKZMjEVIrkUgtqoqU5LW7xNgLBDukXzRslQboB/z BaFpBmkCH4tG24yz6J2Tr5iJ46Hch6GgHNMnYKzBr3QknMeocezDv2uk10V/udE4mdjZ IrUww02UxM/DH3XC+MdCy10qRkHg3x6lk1sJ3Cfh5T9F0SSXiJDpuS7d/yR/wazgS1FN BxhQ== X-Gm-Message-State: AGRZ1gJlXpNFugmnF9nPAssoEYIFFiRsLro8/QHQAtldZf6gAtRuStdA +8Wbn9M6hIgcxgRHR/6f4nMLUp6cRGo= X-Google-Smtp-Source: AJdET5eOEO+WQQ3Q76p7I49BRgSsYGaAkqWR9rq2nVk0XZR8MLtsJegNouR9v7BNJxLOjCCPt43Qug== X-Received: by 2002:adf:c5c4:: with SMTP id v4-v6mr14730972wrg.30.1541286631080; Sat, 03 Nov 2018 16:10:31 -0700 (PDT) Received: from blackbox.darklights.net (p200300DCD732B10011F5E51309F23E8D.dip0.t-ipconnect.de. [2003:dc:d732:b100:11f5:e513:9f2:3e8d]) by smtp.googlemail.com with ESMTPSA id 21-v6sm22673935wmv.5.2018.11.03.16.10.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 03 Nov 2018 16:10:30 -0700 (PDT) From: Martin Blumenstingl To: linux-amlogic@lists.infradead.org, devicetree@vger.kernel.org, linux-iio@vger.kernel.org, robh+dt@kernel.org, pmeerw@pmeerw.net, lars@metafoo.de, knaack.h@gmx.de, jic23@kernel.org Cc: Martin Blumenstingl Subject: [PATCH v2 0/2] meson-saradc: add chip temperature support Date: Sun, 4 Nov 2018 00:10:22 +0100 Message-Id: <20181103231024.659-1-martin.blumenstingl@googlemail.com> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 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 The meson-saradc allows switching the input of channel #6 between an actual ADC pad and the SoC's internal temperature sensor. On the 64-bit SoCs the SCPI firmware reads the chip temperature using the SAR ADC. Thus the 64-bit SoCs simply expose the temperature through the "arm,scpi-sensors" interface (and so Linux doesn't have to program the SAR ADC for temperature readings). The 32-bit SoCs however don't have any SCPI firmware. Thus we need to configure the SAR ADC in Linux to get the chip temperature. To make it work we need two changes to the existing dt-bindings: - we have to get the TSC (temperature sensor calibration coefficient) from the eFuse (where it has been programmed to the correct value in the manufacturing process). the SAR ADC needs the TSC value, otherwise it returns only garbage readings - we need to get a phandle to the new HHI syscon region because on Meson8b and Meson8m2 the TSC is five bits wide (on Meson8 it's only four bits wide) but only four bits are stored inside the SAR ADC's memory region. The upper most bit (not all five bits, only one out of five) is stored at a seemingly random register HHI_DPLL_TOP_0) in the HHI register area. This also requires changes to the clock controller where we don't have a solution where everyone's happy with the dt-bindings (see the discussion in [0]) - so this will be added in a future series. changes since v1 at [1]: - (many thanks to Peter Meerwald-Stadler and Jonathan Cameron for taking the time to review my patches) - use "MESON_SAR_ADC_" as naming schema for two new #defines - remove .indexed = 0 (because it's already the default) from MESON_SAR_ADC_TEMP_CHAN - simplify setting MESON_SAR_ADC_DELTA_10_TEMP_SEL in meson_sar_adc_enable_channel - remove IIO_CHAN_INFO_ENABLE (abuse) from MESON_SAR_ADC_TEMP_CHAN - register the channel set depending on whether the temperature sensor can be used or not (instead of exposing the info whether it can be used through the "ENABLE" element) - shorten check for MESON_SAR_ADC_EFUSE_BYTE3_IS_CALIBRATED - dropped Meson8b and Meson8m2 support for now (see the HHI register discussion mentioned above). I still plan to add support for these SoCs, but I don't want to add any code to the SAR ADC driver before we have a decision on the dt-bindings of the clock driver (where we need to write one bit from the SAR ADC driver for the temperature sensor calibration coefficient). - dropped the .dts changes for now since the useful part was adding iio-hwmon on Meson8b and Meson8m2 boards. now that support for these two SoCs is postponed we can wait with the .dts changes as well. [0] https://patchwork.kernel.org/cover/10658527/ [1] https://patchwork.kernel.org/cover/10658551/ Martin Blumenstingl (2): dt-bindings: iio: adc: meson-saradc: add temperature sensor support iio: adc: meson-saradc: add support for the chip's temperature sensor .../bindings/iio/adc/amlogic,meson-saradc.txt | 6 + drivers/iio/adc/meson_saradc.c | 229 ++++++++++++++++-- 2 files changed, 209 insertions(+), 26 deletions(-)