From patchwork Tue Jun 4 14:47:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guillaume LA ROQUE X-Patchwork-Id: 10975481 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 A066F2D49 for ; Tue, 4 Jun 2019 15:03:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9067828A95 for ; Tue, 4 Jun 2019 15:03:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 84E2528A22; Tue, 4 Jun 2019 15:03:23 +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_SIGNED, DKIM_VALID,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 298532886C for ; Tue, 4 Jun 2019 15:03:23 +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=JA0+D3DCS0+YwWm6z2dqFK3I6WCk6HQBLzwfpQXieRg=; b=oQy6HwYViabt05uTB5TlpqK026 PDEDNLG6EWzBfP6jrXEl5U8fG5+3i7yoy7cVWeeWumVTHhGDkKYLk675LlZEjHW62LSE5oCSdSCr+ teoPh6jy2wfFgZzG7m6tTAJppF6YahutOx8iOQzviIMC6ATqx5vQtKXeCzRBKUY9fRDKOtIABvGHe VVf7lEj1pf+9nAG7a9nnFrI4NRHiax176zfiqYwJrqP1skRXUDopIrkSZxLWWh7MKX93IwHyvHvJ4 f/gjQ2jKU6WNsZpT3uW2kbJ1XwkoPZyFOXBHfqRAPdjgY6Wa15EgAVv7xR9u6VomJFjmwmgo6Eaws WGYwfoZg==; 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 1hYAy9-0002il-At; Tue, 04 Jun 2019 15:03:21 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hYAy1-0002TH-EN for linux-arm-kernel@bombadil.infradead.org; Tue, 04 Jun 2019 15:03:13 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=SnjvT/D0cW1JiliaxzQrnOjeQzlchEAI6VR+JZ5y+Qk=; b=QF5SWB5EIg/Ab4LbJztF1bks0 ogkK7mWL/XDaYIqlWuRzqV1VQdqRyE16jYMdOKLrEbGfH+mYGReXGSJpevkYsDXbqOHRXh8evXYHg gw9qPMR7XxIhNxE453Ri6mMAjWgjilTJAJDR+Xwhy7WO/nCf4YM6hs4D35HMyykZak0/98KYshTju kPgwq0vwxjfIHupHnK5j/yoPlZMC/MgxKC6I3pxxErb6zKgDjl2V8vVsi4POAGOdAxvZLlPvLdOI9 zKXnbZOLX7+lPB5WkvEZKAxHJc3teKs+QF8VqdK65eXW6oQKnWRmy/bsX1y35/mFOrueLYJyeNn1s nCougYk0A==; Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]) by casper.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hYAic-0008P7-NA for linux-arm-kernel@lists.infradead.org; Tue, 04 Jun 2019 14:47:22 +0000 Received: by mail-wr1-x441.google.com with SMTP id p11so11301372wre.7 for ; Tue, 04 Jun 2019 07:47:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=SnjvT/D0cW1JiliaxzQrnOjeQzlchEAI6VR+JZ5y+Qk=; b=b1GKNOnN95jk6p9sY+UTKLGXWVTPtbcumXKRhyS/7BVQ0GSsVUG3onM+bQfdjl6yoc ukbAzcipgmBZWkOSbAkttBYNgCq6tDvGfhzOFjJAodCqZKHhLdCtnFSdGB+EhpvJVWVv Ao5yFwm+UVLgGbs0siLkS87AK9ePzyhi+lbK6avLEqyfxa2tcWEtIsf8/g+PA8vxqy0a XzPgCwVb972Ddl9WFCD+0q8Qg0S6z4D/KffGpWfog+syujg7OJWZPxJemwHT44InwjGo +8Z8xPxWQpIyOay3xiAVFFEa5JWwSWFNWlvuDSWLPeUWykVajK4/5dpKHsoeVERZzb2i hWIA== 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=SnjvT/D0cW1JiliaxzQrnOjeQzlchEAI6VR+JZ5y+Qk=; b=C8HKiLe0KRDvBp53fUN6Eed4G/zfbtaFtfR/8e1XraW3X18X8JyQcM0lH2vxYjsxqN 98vq/ryhsLEHfKbnNgUl57W4At8eL5v6oKhaCbBRR55gVP7ep2LeTAte4ktuEUVxT7M9 Gffc8eVKOOdKK9O5cc25ux4ma9BCYdIxiz4UaMKNCiM7RltPkjAd/j9sgb11LktRb4h0 hvONSnHlYP2MkSM8xR1TmDJgDP6RDaLcAIh5oU2p8NmKlzO9aTh3SIIqgfeIYPq7U5uR UdpaQ/RrVRsiIRXDeMt5tKnRozA0FLFyAAziXj6wpGwhj5Q0dZcp1LOXYjm3vo7BZATg hJag== X-Gm-Message-State: APjAAAXFsT45IAJzqTLtYZGxjPw2RUIHqcSdDvEHrX+N7s3OpRGmhbqC L+cQhGAoeyH5Ak2Ylh8pFnSe/A== X-Google-Smtp-Source: APXvYqyRQhjdyMK6YK07C+dlJF+QvuSSvZcEwhbdHS+SKqZ1uaK2nDj1a6UiJjyrdfuKgXxc/NmwfQ== X-Received: by 2002:adf:e54b:: with SMTP id z11mr6859295wrm.198.1559659637766; Tue, 04 Jun 2019 07:47:17 -0700 (PDT) Received: from glaroque-ThinkPad-T480.baylibre.local (lmontsouris-657-1-212-31.w90-63.abo.wanadoo.fr. [90.63.244.31]) by smtp.gmail.com with ESMTPSA id v184sm3649639wme.10.2019.06.04.07.47.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Jun 2019 07:47:17 -0700 (PDT) From: Guillaume La Roque To: jic23@kernel.org, khilman@baylibre.com Subject: [PATCH 1/3] Documentation: dt-bindings: add the Amlogic Meson Temperature Sensor Date: Tue, 4 Jun 2019 16:47:12 +0200 Message-Id: <20190604144714.2009-2-glaroque@baylibre.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190604144714.2009-1-glaroque@baylibre.com> References: <20190604144714.2009-1-glaroque@baylibre.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190604_154718_860644_245B409B X-CRM114-Status: GOOD ( 15.95 ) 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, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-amlogic@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 adds the devicetree binding documentation for the Temperature Sensor found in the Amlogic Meson G12 SoCs. Currently only the G12A SoCs are supported. Signed-off-by: Guillaume La Roque --- .../iio/temperature/amlogic,meson-tsensor.txt | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/temperature/amlogic,meson-tsensor.txt diff --git a/Documentation/devicetree/bindings/iio/temperature/amlogic,meson-tsensor.txt b/Documentation/devicetree/bindings/iio/temperature/amlogic,meson-tsensor.txt new file mode 100644 index 000000000000..d064db0e9cac --- /dev/null +++ b/Documentation/devicetree/bindings/iio/temperature/amlogic,meson-tsensor.txt @@ -0,0 +1,31 @@ +* Amlogic Meson Temperature Sensor + +Required properties: +- compatible: depending on the SoC and the position of the sensor, + this should be one of: + - "amlogic,meson-g12a-cpu-tsensor" for the CPU G12A SoC sensor + - "amlogic,meson-g12a-ddr-tsensor" for the DDR G12A SoC sensor + followed by the common : + - "amlogic,meson-g12a-tsensor" for G12A SoC family +- reg: the physical base address and length of the registers +- interrupts: the interrupt indicating end of sampling +- clocks: phandle identifier for the reference clock of temperature sensor +- #io-channel-cells: must be 1, see ../iio-bindings.txt +- amlogic,ao-secure: phandle to the ao-secure syscon + +Optional properties: +- amlogic,critical-temperature: temperature value in milli degrees Celsius + to set automatic reboot on too high temperature + +Example: + cpu_temp: temperature-sensor@ff634800 { + compatible = "amlogic,meson-g12a-cpu-tsensor", + "amlogic,meson-g12a-tsensor"; + reg = <0x0 0xff634800 0x0 0x50>; + interrupts = ; + clocks = <&clkc CLKID_TS>; + status = "okay"; + #io-channel-cells = <1>; + amlogic,meson-ao-secure = <&sec_AO>; + amlogic,critical-temperature = <115000>; + }; From patchwork Tue Jun 4 14:47:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guillaume LA ROQUE X-Patchwork-Id: 10975397 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 CEC5176 for ; Tue, 4 Jun 2019 14:47:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BC75A1FFD8 for ; Tue, 4 Jun 2019 14:47:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B058B289A5; Tue, 4 Jun 2019 14:47:53 +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_SIGNED, DKIM_VALID,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 51834289A7 for ; Tue, 4 Jun 2019 14:47:53 +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=dWD5RSfMug4I2OBzuMftVTHaknQfGaIf4MZXsa5Kmnk=; b=OOhvqQguhnyrjId/DbNbxtuHWd 8f1U/llRlHqJCIXk9q6vq5HvUT4FKesz2ocdvglSSTXQn771mEiXNdWvEVfH3qNQm9oR1Yc/QrbzJ 7LC9xCUjgarnO4n1o6DAuIyZQ/PwqO/p8qCr2eFJh7iTZnZZknFbKFQMg3edRZ9XHiXnSzzFVr8hw LYprGF1l02vo8JJU9seQC2M0utbZKgP+aX+0wf0AxdslPqko98KNyrUXQV4Yl2hWQBBRV9R7GvqY2 Dfoup74FVG7wR+aXaw3Jja0idT7V5twQS+MNmE9QqwWA009kWrCfL7gbzmig5hRSaduOsrG0cX0ss eogPLqMA==; 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 1hYAj4-0000CZ-33; Tue, 04 Jun 2019 14:47:46 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hYAiq-0008G6-FD for linux-arm-kernel@bombadil.infradead.org; Tue, 04 Jun 2019 14:47:32 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=bLDsai7BCDJ9/WAFUmOmDJ4D/4W6/bXgG+qdhNwcZhk=; b=2HKuP+tn7HjMdYlqVQ1z89Uly uXmJALO95SDlwpKzDJVneC2TLSqaRL/+vyu/xphr6ERQWmeATlX6JwNrTm35thvMHh6g1cxHbH4pC hGJeFoGQdWqjhBHyjGDLCqtdyTtR5PE4mzppUNCUVwCRCGfE1JP910H0IfhMHVCpzmpJ7T5+Ftb4R IEe0px4ZkdZdVDXz5cPw6ci6wWRvyvelE/6p4rGBQQDPL3jLPUNNkvpiF9acIFmiOtQSEsS35UxKL CeCcYldBVX1tquMeBL04GcNn+lqJ8HSjtuBDFk0DRB/PqKAaOKbjS1Ub+zVfqRVCRHJHoERIzCo+V f2Lf7q2og==; Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]) by merlin.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hYAii-0006Ty-LO for linux-arm-kernel@lists.infradead.org; Tue, 04 Jun 2019 14:47:28 +0000 Received: by mail-wr1-x442.google.com with SMTP id c2so16146589wrm.8 for ; Tue, 04 Jun 2019 07:47:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=bLDsai7BCDJ9/WAFUmOmDJ4D/4W6/bXgG+qdhNwcZhk=; b=iNBvPjb5Qy21/12AvtkoRo4IHAm41Wg4Vk0nBhVKAQXzW/FfWktrlAJB1cx60YTjZN pYT8vqd6X/6JxxL9Q2aDSrZhJTO8FGCMZjYSJ5YlrT0gcbOLrUoxbTCpOJhoo0WVj4uS qaihsQHl5/DKak5ZC4VFsTKtIgy1bcly73SbJxXYkhpOuPjvu72uV4TFbFhLE4u3db1x XBPLS2/aV/kZr/v/fqELn48ZEdCAlNPLQJ879P7p7ggyomOArRwgIWvmJZa1MtjT8tc2 kZ2WrTjGxBjbXU7Ioqw6JIRq/dfUL+mD1M9xuYkST96HZDAcr4mgLkbPuWKE5Xr5iIM5 KumQ== 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=bLDsai7BCDJ9/WAFUmOmDJ4D/4W6/bXgG+qdhNwcZhk=; b=fopm61pYp1vMF9/qAlFyA36KJ3SZXM1cTfYEPEuWWyV34b4CjkX0R5rKjhkNuZvOwd O0XaMwH5PSVlbqXkE/CGikOBrSDZXMEzHwgJVzgFnKq4nbMfzSiNtKMQ4AiUyEBoMwXf 4ZdBs6MohWxuUmw9Ix/d3cTERVw9NOdub1BeA0mDOvg7wVx6mEoafsG4823ScX79fubv drhhgclyxhc8l6NJteOsfm8ocGwNRNT7+yNEj4Dvy6wpQk/1JGOM96HLu3z+g5e3ofau qoHAkWzEfUJZnSyjVpyUBsGdXzZm1T0jHtr690kFdfxHJGY333uZO/OwYIC+zQkzY3OM ELRQ== X-Gm-Message-State: APjAAAXZeZFVG0HGSDkAQgL7ry4Wvihx7ijOfgmzbMqKEUBi1UOngJsA 696ysm2t/nd5jJ2bBlHS7JEmGg== X-Google-Smtp-Source: APXvYqw4x2gWBkZ94JwAp/u/xenQcH6trywYc6ypCThQKgduCn+6apBhkSU1BFXr5dezDKoFoQcCDw== X-Received: by 2002:a5d:62c9:: with SMTP id o9mr19704199wrv.186.1559659638823; Tue, 04 Jun 2019 07:47:18 -0700 (PDT) Received: from glaroque-ThinkPad-T480.baylibre.local (lmontsouris-657-1-212-31.w90-63.abo.wanadoo.fr. [90.63.244.31]) by smtp.gmail.com with ESMTPSA id v184sm3649639wme.10.2019.06.04.07.47.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Jun 2019 07:47:18 -0700 (PDT) From: Guillaume La Roque To: jic23@kernel.org, khilman@baylibre.com Subject: [PATCH 2/3] arm64: dts: meson: g12a: add temperature sensor node Date: Tue, 4 Jun 2019 16:47:13 +0200 Message-Id: <20190604144714.2009-3-glaroque@baylibre.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190604144714.2009-1-glaroque@baylibre.com> References: <20190604144714.2009-1-glaroque@baylibre.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190604_104724_803291_3B7E3479 X-CRM114-Status: GOOD ( 11.69 ) 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, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-amlogic@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 Add two temperature sensor the first near CPU and GPU, second near DDR Signed-off-by: Guillaume La Roque --- arch/arm64/boot/dts/amlogic/meson-g12a.dtsi | 22 +++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/arch/arm64/boot/dts/amlogic/meson-g12a.dtsi b/arch/arm64/boot/dts/amlogic/meson-g12a.dtsi index 840dab606110..37f17087bdb1 100644 --- a/arch/arm64/boot/dts/amlogic/meson-g12a.dtsi +++ b/arch/arm64/boot/dts/amlogic/meson-g12a.dtsi @@ -1360,6 +1360,28 @@ }; }; + cpu_temp: temperature-sensor@34800 { + compatible = "amlogic,meson-g12a-cpu-tsensor", + "amlogic,meson-g12a-tsensor"; + reg = <0x0 0x34800 0x0 0x50>; + interrupts = ; + clocks = <&clkc CLKID_TS>; + status = "okay"; + #io-channel-cells = <1>; + amlogic,ao-secure = <&sec_AO>; + }; + + ddr_temp: temperature-sensor@34c00 { + compatible = "amlogic,meson-g12a-ddr-tsensor", + "amlogic,meson-g12a-tsensor"; + reg = <0x0 0x34c00 0x0 0x50>; + interrupts = ; + clocks = <&clkc CLKID_TS>; + status = "okay"; + #io-channel-cells = <1>; + amlogic,ao-secure = <&sec_AO>; + }; + usb2_phy0: phy@36000 { compatible = "amlogic,g12a-usb2-phy"; reg = <0x0 0x36000 0x0 0x2000>; From patchwork Tue Jun 4 14:47:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guillaume LA ROQUE X-Patchwork-Id: 10975479 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 34A982D49 for ; Tue, 4 Jun 2019 15:03:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2230328718 for ; Tue, 4 Jun 2019 15:03:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1695828A8C; Tue, 4 Jun 2019 15:03:21 +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_SIGNED, DKIM_VALID,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 F3E0A28A3F for ; Tue, 4 Jun 2019 15:03:19 +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=CKRuiXyhoupOYXXQGpwd6XB2f2WJXOr1ytJnO5WmXEA=; b=ZSJJpGA4agZbb7mn/pQ7m/e0Ps u+5gRc4963iXBIhmdVs0UuuJpue5jTuk9CGq/gOKExr0vfUBQ4hZi2utodDUwFrdkp5VdYrEMx5iz XI1e1fCMK0ZN8aiLzZDiZfDsyuXfd76Q77rvgqXTibTIKJE7JkegStUe4iNDEsEsIMn+SPNuf3UT2 Gont6erUtHtT5WwTeqELDBFs/duZq4Kpk++rp1DUKdxY6d+X/3Ws8iWM4n35TphB9fNesQxFnPgo7 soq47LCneFkzZqftk2RdYpmJTo7QaEFfi2LZL3K+Ynt/bHfU67IgXVVG882XWFs3ypRRTPZXwDv8l qASot2GA==; 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 1hYAy3-0002br-4P; Tue, 04 Jun 2019 15:03:15 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hYAy0-00025e-OR for linux-arm-kernel@bombadil.infradead.org; Tue, 04 Jun 2019 15:03:13 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=KFNX0x0uDiVEnACY7GX/xfcM9Z1YE5k1Hro/dmSU21U=; b=VecRhQv+SzOJAKZpf6duCA8/6 bBH6jPYz/w31jo96e/sNQZQ623n1zVWI0uiC+SNe2vEe/GeM4Tl+qzXGogv+Qr0d+IbaZppGGkCqZ 4l4oMzCnWmqYg6OHLwoewx8u1fonTz94Gv6ojr+xlwWg7+blO+zxdV3vs7YauhmRBp1VizSeH+l0O HYEOB07tSj4QtKDxHkPEOjN9uqanFJRc/iz2aPd8L4tLPa8A5r3y8Xr/z9lDblor+4GAKHx6VB3mp 4k9IvHKDP9brr567txVH8SWf20FtMRdL8fyDDwz9jaArJNVUxjdirYsHhInFfeDzAom4MOjPrLHbG KFpuEf87w==; Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]) by casper.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hYAie-0008PX-VB for linux-arm-kernel@lists.infradead.org; Tue, 04 Jun 2019 14:47:23 +0000 Received: by mail-wr1-x444.google.com with SMTP id w13so16105436wru.11 for ; Tue, 04 Jun 2019 07:47:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=KFNX0x0uDiVEnACY7GX/xfcM9Z1YE5k1Hro/dmSU21U=; b=tL9ZDb1HmSqQuR6YGGVWJKZZVio2W9Srq8Iq3w8+YQVB79OgI97cvGgjtA5qqIvLEq xpBtXIY+Bq+QVM+Hg3xmsa1Fw1ZvfJQ+iuTJ7AFEzdXWgdfXl4drvbHrOuWAEc1YrEuu q//R9SUG3TQjJelcxzvSjRZZ1xR3Mr7PCmLsJZfiTaa3MXJFQfLr8uN8gTgGNAyf9BFn Yn2ACvOu5w2DfO2rvRguXVXpSqKKThj+TxKbAdOySWiFds79a9M/ICZRWfl4uc8tfTOh wd+OW21degsYpfNBHJ7DEWDoh9UJqOlt/C4RFxD8wRYpCxFE4+l8TZj3NgLVLr7sw31o a9EA== 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=KFNX0x0uDiVEnACY7GX/xfcM9Z1YE5k1Hro/dmSU21U=; b=pTIodPnRk5tKlh+nSY9vjPTRCaeQNQirBmiPbGPUacOeISpLcnoN2vGfCCvctjYVCx X8yO/YhwtKJEJT2V4TIv/Dmb7SMYF2a2GbWAczng6AlpPaFgqHoFUa8F2EeqJICsap5x pZL99S1HCjfDQcGUn0OFuNp59OXqKdq1pg4k3/Xg5OOlAo1PSiSF0YyyyyzwGVLvMt1K QbgC0+FqRxRpTQ8LgY9Rdkfad5UsI2blKbJPCE/9S1MVOyxGq/IkjpOejQUCyhhk5HIm 92wIztfq2gFZF54XKzRrZfISBKKZW6bdhcRCrfPfWVXPf7QM7EWY0QKCgiSrN+tilySR nNbA== X-Gm-Message-State: APjAAAVC4ZRpuKvs+PClapzUemBw2ULpVyMxk098L34oen22GIPzKCwb pWP6TnCAFSGI3TwKzHwy5QlBzA== X-Google-Smtp-Source: APXvYqwnQlYmXdRjEl9h3Z01LMzU9Jkhig/p/oYJ+TOwizec2QZYooOw7KZ0UbRELLEhOW4YxXOzpw== X-Received: by 2002:a5d:518c:: with SMTP id k12mr21042838wrv.322.1559659639754; Tue, 04 Jun 2019 07:47:19 -0700 (PDT) Received: from glaroque-ThinkPad-T480.baylibre.local (lmontsouris-657-1-212-31.w90-63.abo.wanadoo.fr. [90.63.244.31]) by smtp.gmail.com with ESMTPSA id v184sm3649639wme.10.2019.06.04.07.47.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Jun 2019 07:47:19 -0700 (PDT) From: Guillaume La Roque To: jic23@kernel.org, khilman@baylibre.com Subject: [PATCH 3/3] iio: temperature: add a driver for the temperature sensor found in Amlogic Meson G12 SoCs Date: Tue, 4 Jun 2019 16:47:14 +0200 Message-Id: <20190604144714.2009-4-glaroque@baylibre.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190604144714.2009-1-glaroque@baylibre.com> References: <20190604144714.2009-1-glaroque@baylibre.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190604_154721_200788_D4DAC092 X-CRM114-Status: GOOD ( 29.68 ) 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, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-amlogic@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 The code is based on Amlogic source code. No public datasheet for this. Currently the G12A SoCs are supported. Supported features: - possibility to set an automatic reboot temperature Signed-off-by: Guillaume La Roque --- drivers/iio/temperature/Kconfig | 11 + drivers/iio/temperature/Makefile | 1 + drivers/iio/temperature/meson_tsensor.c | 416 ++++++++++++++++++++++++ 3 files changed, 428 insertions(+) create mode 100644 drivers/iio/temperature/meson_tsensor.c diff --git a/drivers/iio/temperature/Kconfig b/drivers/iio/temperature/Kconfig index 737faa0901fe..712a0062790d 100644 --- a/drivers/iio/temperature/Kconfig +++ b/drivers/iio/temperature/Kconfig @@ -34,6 +34,17 @@ config HID_SENSOR_TEMP To compile this driver as a module, choose M here: the module will be called hid-sensor-temperature. +config MESON_TSENSOR + tristate "Amlogic Meson temperature sensor Support" + default ARCH_MESON + depends on OF && ARCH_MESON + help + If you say yess here you get support for Meson Temperature sensor + for G12 SoC Family. + + This driver can also be built as a module. If so, the module will + be called meson_tsensor. + config MLX90614 tristate "MLX90614 contact-less infrared sensor" depends on I2C diff --git a/drivers/iio/temperature/Makefile b/drivers/iio/temperature/Makefile index baca4776ca0d..466d8c1c91d6 100644 --- a/drivers/iio/temperature/Makefile +++ b/drivers/iio/temperature/Makefile @@ -6,6 +6,7 @@ obj-$(CONFIG_HID_SENSOR_TEMP) += hid-sensor-temperature.o obj-$(CONFIG_MAXIM_THERMOCOUPLE) += maxim_thermocouple.o obj-$(CONFIG_MAX31856) += max31856.o +obj-$(CONFIG_MESON_TSENSOR) += meson_tsensor.o obj-$(CONFIG_MLX90614) += mlx90614.o obj-$(CONFIG_MLX90632) += mlx90632.o obj-$(CONFIG_TMP006) += tmp006.o diff --git a/drivers/iio/temperature/meson_tsensor.c b/drivers/iio/temperature/meson_tsensor.c new file mode 100644 index 000000000000..be0a8d073ba3 --- /dev/null +++ b/drivers/iio/temperature/meson_tsensor.c @@ -0,0 +1,416 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Amlogic Meson Temperature Sensor + * + * Copyright (C) 2017 Huan Biao + * Copyright (C) 2019 Guillaume La Roque + * + * Register value to celsius temperature formulas: + * Read_Val m * U + * U = ---------, Uptat = --------- + * 2^16 1 + n * U + * + * Temperature = A * ( Uptat + u_efuse / 2^16 )- B + * + * A B m n : calibration parameters + * u_efuse : fused calibration value, it's a signed 16 bits value + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define TSENSOR_CFG_REG1 0x4 + #define TSENSOR_CFG_REG1_RSET_VBG BIT(12) + #define TSENSOR_CFG_REG1_RSET_ADC BIT(11) + #define TSENSOR_CFG_REG1_VCM_EN BIT(10) + #define TSENSOR_CFG_REG1_VBG_EN BIT(9) + #define TSENSOR_CFG_REG1_OUT_CTL BIT(6) + #define TSENSOR_CFG_REG1_FILTER_EN BIT(5) + #define TSENSOR_CFG_REG1_DEM_EN BIT(3) + #define TSENSOR_CFG_REG1_CH_SEL GENMASK(1, 0) + #define TSENSOR_CFG_REG1_ENABLE \ + (TSENSOR_CFG_REG1_FILTER_EN | \ + TSENSOR_CFG_REG1_VCM_EN | \ + TSENSOR_CFG_REG1_VBG_EN | \ + TSENSOR_CFG_REG1_DEM_EN | \ + TSENSOR_CFG_REG1_CH_SEL) + +#define TSENSOR_CFG_REG2 0x8 + #define TSENSOR_CFG_REG2_HITEMP_EN BIT(31) + #define TSENSOR_CFG_REG2_REBOOT_ALL_EN BIT(30) + #define TSENSOR_CFG_REG2_REBOOT_TIME GENMASK(25, 16) + #define TSENSOR_CFG_REG2_HITEMP_REBOOT_ENABLE \ + (TSENSOR_CFG_REG2_HITEMP_EN | \ + TSENSOR_CFG_REG2_REBOOT_ALL_EN | \ + TSENSOR_CFG_REG2_REBOOT_TIME) + #define TSENSOR_CFG_REG2_HITEMP_REBOOT_ENABLE_MASK \ + (GENMASK(31, 30) | GENMASK(25, 4)) + #define TSENSOR_CFG_REG2_HITEMP_REBOOT_REG_MASK \ + GENMASK(15, 4) + #define TSENSOR_CFG_REG2_HITEMP_REG_VAL(_reg_val) \ + (FIELD_PREP(TSENSOR_CFG_REG2_HITEMP_REBOOT_REG_MASK, \ + _reg_val) | \ + TSENSOR_CFG_REG2_HITEMP_REBOOT_ENABLE) + +#define TSENSOR_CFG_REG3 0xC +#define TSENSOR_CFG_REG4 0x10 +#define TSENSOR_CFG_REG5 0x14 +#define TSENSOR_CFG_REG6 0x18 +#define TSENSOR_CFG_REG7 0x1C +#define TSENSOR_CFG_REG8 0x20 + +#define TSENSOR_STAT0 0x40 + +#define TSENSOR_STAT9 0x64 + +#define TSENSOR_READ_TEMP_MASK GENMASK(15, 0) +#define TSENSOR_TEMP_MASK GENMASK(11, 0) + +#define TSENSOR_TRIM_SIGN_MASK BIT(15) +#define TSENSOR_TRIM_TEMP_MASK GENMASK(14, 0) +#define TSENSOR_TRIM_VERSION_MASK GENMASK(31, 24) + +#define TSENSOR_TRIM_VERSION(_version) \ + FIELD_GET(TSENSOR_TRIM_VERSION_MASK, _version) + +#define TSENSOR_TRIM_CALIB_VALID_MASK (GENMASK(3, 2) | BIT(7)) + +#define TSENSOR_CALIB_OFFSET 1 +#define TSENSOR_CALIB_SHIFT 4 + +static const struct iio_chan_spec temperature_channel[] = { + { + .type = IIO_TEMP, + .channel = 0, + .address = 0, + .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED), + }, +}; + +/** + * struct meson_tsensor_soc_data + * @A, B, m, n: calibration parameters + * This structure is required for configuration of meson tsensor driver. + */ +struct meson_tsensor_soc_data { + int A; + int B; + int m; + int n; +}; + +/** + * struct meson_tsensor_data + * @u_efuse_off: register offset to read fused calibration value + * @soc: calibration parameters structure pointer + * @regmap_config: regmap config for the device + * This structure is required for configuration of meson tsensor driver. + */ +struct meson_tsensor_data { + int u_efuse_off; + const struct meson_tsensor_soc_data *soc; + const struct regmap_config *regmap_config; +}; + +struct meson_tsensor { + int id; + const struct meson_tsensor_data *data; + struct regmap *regmap; + struct regmap *sec_ao_map; + struct clk *clk; + u32 trim_info; + void __iomem *base; + int reboot_temp; +}; + +/* + * tsensor treats temperature as a mapped temperature code. + * The temperature is converted differently depending on the calibration type. + */ +static u32 temp_to_code(struct meson_tsensor *priv, int temp) +{ + const struct meson_tsensor_soc_data *param = priv->data->soc; + s64 divisor, factor, uefuse; + u32 reg_code; + + uefuse = priv->trim_info & TSENSOR_TRIM_SIGN_MASK ? + ~(priv->trim_info & TSENSOR_TRIM_TEMP_MASK) + 1 : + (priv->trim_info & TSENSOR_TRIM_TEMP_MASK); + + factor = BIT(16) * (temp * 10 + param->B); + factor = div_s64(factor, param->A); + factor = factor + uefuse; + + factor = factor * 100; + + divisor = param->n * factor; + divisor = div_s64(divisor, BIT(16)); + divisor = param->m - divisor; + + reg_code = div_s64(factor, divisor); + reg_code = ((reg_code >> TSENSOR_CALIB_SHIFT) & TSENSOR_TEMP_MASK) + + TSENSOR_CALIB_OFFSET; + + return reg_code; +} + +/* + * Calculate a temperature value from a temperature code. + * The unit of the temperature is degree Celsius. + */ +static int code_to_temp(struct meson_tsensor *priv, int temp_code) +{ + const struct meson_tsensor_soc_data *param = priv->data->soc; + int temp; + s64 factor, Uptat, uefuse; + + uefuse = priv->trim_info & TSENSOR_TRIM_SIGN_MASK ? + ~(priv->trim_info & TSENSOR_TRIM_TEMP_MASK) + 1 : + (priv->trim_info & TSENSOR_TRIM_TEMP_MASK); + + factor = param->n * temp_code; + factor = div_s64(factor, 100); + + Uptat = temp_code * param->m; + Uptat = div_s64(Uptat, 100); + Uptat = Uptat * BIT(16); + Uptat = div_s64(Uptat, BIT(16) + factor); + + temp = (Uptat + uefuse) * param->A; + temp = div_s64(temp, BIT(16)); + temp = (temp - param->B) * 100; + + return temp; +} + +static int meson_tsensor_initialize(struct iio_dev *indio_dev) +{ + struct meson_tsensor *priv = iio_priv(indio_dev); + u32 reg_val; + int ret = 0; + int ver; + + regmap_read(priv->sec_ao_map, priv->data->u_efuse_off, + &priv->trim_info); + + ver = TSENSOR_TRIM_VERSION(priv->trim_info); + + if ((ver & TSENSOR_TRIM_CALIB_VALID_MASK) == 0) { + ret = -EINVAL; + dev_err(&indio_dev->dev, + "tsensor thermal calibration not supported: 0x%x!\n", + ver); + goto out; + } + + /* init the ts reboot soc function */ + if (priv->reboot_temp) { + /* register need value in celsius */ + reg_val = temp_to_code(priv, priv->reboot_temp / 1000); + regmap_update_bits(priv->regmap, TSENSOR_CFG_REG2, + TSENSOR_CFG_REG2_HITEMP_REBOOT_ENABLE_MASK, + TSENSOR_CFG_REG2_HITEMP_REG_VAL(reg_val)); + } + +out: + return ret; +} + +static int meson_tsensor_enable(struct iio_dev *indio_dev) +{ + struct meson_tsensor *priv = iio_priv(indio_dev); + + clk_prepare_enable(priv->clk); + regmap_update_bits(priv->regmap, TSENSOR_CFG_REG1, + TSENSOR_CFG_REG1_ENABLE, TSENSOR_CFG_REG1_ENABLE); + + return 0; +} + +static int meson_tsensor_disable(struct iio_dev *indio_dev) +{ + struct meson_tsensor *priv = iio_priv(indio_dev); + + regmap_update_bits(priv->regmap, TSENSOR_CFG_REG1, + TSENSOR_CFG_REG1_ENABLE, 0); + clk_disable(priv->clk); + + return 0; +} + +static int meson_tsensor_read(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, int *val, + int *val2, long mask) +{ + unsigned int tvalue; + struct meson_tsensor *priv = iio_priv(indio_dev); + + switch (mask) { + case IIO_CHAN_INFO_PROCESSED: + regmap_read(priv->regmap, TSENSOR_STAT0, &tvalue); + *val = code_to_temp(priv, + tvalue & TSENSOR_READ_TEMP_MASK); + + return IIO_VAL_INT; + default: + return -EINVAL; + } +} + +static const struct iio_info meson_tsensor_iio_info = { + .read_raw = &meson_tsensor_read, +}; + +static const struct regmap_config meson_tsensor_regmap_config_g12a = { + .reg_bits = 8, + .val_bits = 32, + .reg_stride = 4, + .max_register = TSENSOR_STAT9, +}; + +static const struct meson_tsensor_soc_data meson_tsensor_g12a = { + .A = 9411, + .B = 3159, + .m = 424, + .n = 324, +}; + +static const struct meson_tsensor_data meson_tsensor_g12a_cpu_param = { + .u_efuse_off = 0x128, + .soc = &meson_tsensor_g12a, + .regmap_config = &meson_tsensor_regmap_config_g12a, +}; + +static const struct meson_tsensor_data meson_tsensor_g12a_ddr_param = { + .u_efuse_off = 0xF0, + .soc = &meson_tsensor_g12a, + .regmap_config = &meson_tsensor_regmap_config_g12a, +}; + +static const struct of_device_id meson_tsensor_of_match[] = { + { + .compatible = "amlogic,meson-g12a-ddr-tsensor", + .data = &meson_tsensor_g12a_ddr_param, + }, + { + .compatible = "amlogic,meson-g12a-cpu-tsensor", + .data = &meson_tsensor_g12a_cpu_param, + }, + {}, +}; +MODULE_DEVICE_TABLE(of, meson_tsensor_of_match); + +static int meson_tsensor_probe(struct platform_device *pdev) +{ + struct meson_tsensor *priv; + struct iio_dev *indio_dev; + struct resource *res; + + int ret; + + indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*priv)); + if (!indio_dev) { + dev_err(&pdev->dev, "failed allocating iio device\n"); + return -ENOMEM; + } + + priv = iio_priv(indio_dev); + priv->data = of_device_get_match_data(&pdev->dev); + if (!priv->data) { + dev_err(&pdev->dev, "failed to get match data\n"); + return -ENODEV; + } + + indio_dev->channels = temperature_channel; + indio_dev->num_channels = ARRAY_SIZE(temperature_channel); + indio_dev->name = dev_name(&pdev->dev); + indio_dev->dev.parent = &pdev->dev; + indio_dev->dev.of_node = pdev->dev.of_node; + indio_dev->modes = INDIO_DIRECT_MODE; + indio_dev->info = &meson_tsensor_iio_info; + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + priv->base = devm_ioremap_resource(&pdev->dev, res); + if (IS_ERR(priv->base)) + return PTR_ERR(priv->base); + + priv->regmap = devm_regmap_init_mmio(&pdev->dev, priv->base, + priv->data->regmap_config); + if (IS_ERR(priv->regmap)) + return PTR_ERR(priv->regmap); + + priv->clk = devm_clk_get(&pdev->dev, NULL); + if (IS_ERR(priv->clk)) { + if (PTR_ERR(priv->clk) != -EPROBE_DEFER) + dev_err(&pdev->dev, "failed to get clock\n"); + return PTR_ERR(priv->clk); + } + + if (of_property_read_u32(pdev->dev.of_node, + "amlogic,critical-temperature", + &priv->reboot_temp)) { + priv->reboot_temp = 0; + } + + priv->sec_ao_map = syscon_regmap_lookup_by_phandle + (pdev->dev.of_node, "amlogic,ao-secure"); + if (IS_ERR(priv->sec_ao_map)) { + dev_err(&pdev->dev, "syscon regmap lookup failed.\n"); + return PTR_ERR(priv->sec_ao_map); + } + + ret = meson_tsensor_initialize(indio_dev); + if (ret) + return ret; + + ret = meson_tsensor_enable(indio_dev); + if (ret) + goto err; + + platform_set_drvdata(pdev, indio_dev); + ret = iio_device_register(indio_dev); + if (ret) + goto err_hw; + + return 0; + +err_hw: + meson_tsensor_disable(indio_dev); +err: + clk_unprepare(priv->clk); + + return ret; +} + +static int meson_tsensor_remove(struct platform_device *pdev) +{ + struct iio_dev *indio_dev = platform_get_drvdata(pdev); + + iio_device_unregister(indio_dev); + + return meson_tsensor_disable(indio_dev); +} + +static struct platform_driver meson_tsensor_driver = { + .probe = meson_tsensor_probe, + .remove = meson_tsensor_remove, + .driver = { + .name = "meson-tsensor", + .of_match_table = meson_tsensor_of_match, + }, +}; + +module_platform_driver(meson_tsensor_driver); + +MODULE_AUTHOR("Guillaume La Roque "); +MODULE_DESCRIPTION("Amlogic Meson Temperature Sensor Driver"); +MODULE_LICENSE("GPL v2");