From patchwork Sat Mar 18 00:06:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= X-Patchwork-Id: 9631759 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 A378160245 for ; Sat, 18 Mar 2017 00:06:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8C203284FA for ; Sat, 18 Mar 2017 00:06:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8027228543; Sat, 18 Mar 2017 00:06:29 +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=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, 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 9375B284FA for ; Sat, 18 Mar 2017 00:06:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751101AbdCRAGZ (ORCPT ); Fri, 17 Mar 2017 20:06:25 -0400 Received: from mail-lf0-f65.google.com ([209.85.215.65]:34572 "EHLO mail-lf0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751132AbdCRAGW (ORCPT ); Fri, 17 Mar 2017 20:06:22 -0400 Received: by mail-lf0-f65.google.com with SMTP id y193so6449281lfd.1; Fri, 17 Mar 2017 17:06:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9h1iVoDMaqsFcV+IeYHh71FSfpI81i+6yCa7HM55HeQ=; b=bF8fqxSZGQSXeY9p3TWbYw+Az12NS2Sk0P071aBJ2UQXrGSWS8yhxe76CjoMryHpG5 QN8aQY09He5dVczxIv7Jg0RgWlh8OdS1Qnycr50CwqPoI/H1qe6XWd84Boo0JuTVmbUf p0X0Aha/3uHMeKmsEo4LpEOyDb42KDCJlYgOqjKl3QoDy3RKTRyKirFu4VFraeqC/Iis FbVEfNo9nOq37MVgmNGWPUvfLiudJKiciYRpBzfWZjwci5CdoNVDbVRpEDhXyZyPHbfA wbeT4+fH70XTszWC/v7RmIc7A6jwcEol5SampcCkF539luTolgjIXVGexHJ3cJKKfmGe 1eCQ== 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:mime-version:content-transfer-encoding; bh=9h1iVoDMaqsFcV+IeYHh71FSfpI81i+6yCa7HM55HeQ=; b=OGvDx7Gy7WXYPdso69tqd27Hfbb4sw+e5nbUz0HWLjbrnt0dKWjEguQnQlZjYaUTCh Jv9J43I2N5mVui2EcfGgtjcig4fPZhGxOSSH4tdCkbDne4WWPUsaqRHzCUGMCQ3H5itA xnjJgYOjhqvRak5QHOUC+OCXATuJzw/7N0ndRslAV4AxA44WGCaK5EDw/61kQsJj6P0/ 5ssnmfQtiqy+f9zVPopNLOv3X2Rkud4wKMLQnanZFcJtml9jeZ7sLjgYHdHu6yhm59yp oRFogLx0SHEHLqUuKlqR44MmaJwQUqXe9N7EzmzG4ff8ecoJ46wT48dbWOZSCmpOz29C 1qpg== X-Gm-Message-State: AFeK/H2dq1ty98JcjdX40AI4zJ9sQS+EDJxFPGT9syuwEAgDy22OW+g51Le2IjsuYB+RcA== X-Received: by 10.46.80.21 with SMTP id e21mr5774872ljb.29.1489795571305; Fri, 17 Mar 2017 17:06:11 -0700 (PDT) Received: from linux-samsung.lan (ip-194-187-74-233.konfederacka.maverick.com.pl. [194.187.74.233]) by smtp.gmail.com with ESMTPSA id 2sm1670864ljh.57.2017.03.17.17.06.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 17 Mar 2017 17:06:10 -0700 (PDT) From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= To: Zhang Rui , Eduardo Valentin Cc: Rob Herring , Mark Rutland , Stephen Warren , Lee Jones , Eric Anholt , Florian Fainelli , Ray Jui , Scott Branden , bcm-kernel-feedback-list@broadcom.com, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-rpi-kernel@lists.infradead.org, linux-arm-kernel@lists.infradead.org, =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= Subject: [PATCH V2 2/2] thermal: broadcom: add Raspberry Pi thermal driver Date: Sat, 18 Mar 2017 01:06:03 +0100 Message-Id: <20170318000603.10158-2-zajec5@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170318000603.10158-1-zajec5@gmail.com> References: <20170318000132.9212-1-zajec5@gmail.com> <20170318000603.10158-1-zajec5@gmail.com> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Rafał Miłecki Raspberry Pi devices use BCM283[567] SoCs with a thermal device inside. Querying it is possible using Raspberry specific firmware interface. This simple driver allows reading SoC temperature. Signed-off-by: Rafał Miłecki --- V2: Update Kconfig help message. I forgot to locally rebase & fixup before sending, sorry. --- drivers/thermal/Kconfig | 5 ++ drivers/thermal/Makefile | 1 + drivers/thermal/broadcom/Kconfig | 7 +++ drivers/thermal/broadcom/Makefile | 1 + drivers/thermal/broadcom/raspberrypi-thermal.c | 85 ++++++++++++++++++++++++++ 5 files changed, 99 insertions(+) create mode 100644 drivers/thermal/broadcom/Kconfig create mode 100644 drivers/thermal/broadcom/Makefile create mode 100644 drivers/thermal/broadcom/raspberrypi-thermal.c diff --git a/drivers/thermal/Kconfig b/drivers/thermal/Kconfig index 776b34396144..008e173ec825 100644 --- a/drivers/thermal/Kconfig +++ b/drivers/thermal/Kconfig @@ -392,6 +392,11 @@ config MTK_THERMAL Enable this option if you want to have support for thermal management controller present in Mediatek SoCs +menu "Broadcom thermal drivers" +depends on ARCH_BCM || COMPILE_TEST +source "drivers/thermal/broadcom/Kconfig" +endmenu + menu "Texas Instruments thermal drivers" depends on ARCH_HAS_BANDGAP || COMPILE_TEST depends on HAS_IOMEM diff --git a/drivers/thermal/Makefile b/drivers/thermal/Makefile index 7adae2029355..549d81b6363c 100644 --- a/drivers/thermal/Makefile +++ b/drivers/thermal/Makefile @@ -27,6 +27,7 @@ thermal_sys-$(CONFIG_CLOCK_THERMAL) += clock_cooling.o thermal_sys-$(CONFIG_DEVFREQ_THERMAL) += devfreq_cooling.o # platform thermal drivers +obj-y += broadcom/ obj-$(CONFIG_QCOM_SPMI_TEMP_ALARM) += qcom-spmi-temp-alarm.o obj-$(CONFIG_SPEAR_THERMAL) += spear_thermal.o obj-$(CONFIG_ROCKCHIP_THERMAL) += rockchip_thermal.o diff --git a/drivers/thermal/broadcom/Kconfig b/drivers/thermal/broadcom/Kconfig new file mode 100644 index 000000000000..2524b2ff16f6 --- /dev/null +++ b/drivers/thermal/broadcom/Kconfig @@ -0,0 +1,7 @@ +config RASPBERRYPI_THERMAL + tristate "Raspberry Pi thermal driver" + depends on ARCH_BCM2835 || COMPILE_TEST + depends on RASPBERRYPI_FIRMWARE=y + help + This enables support for the RPi thermal that is part of BCM2835 SoC + and can be accessed using firmware interface. diff --git a/drivers/thermal/broadcom/Makefile b/drivers/thermal/broadcom/Makefile new file mode 100644 index 000000000000..5ea7f8819b7d --- /dev/null +++ b/drivers/thermal/broadcom/Makefile @@ -0,0 +1 @@ +obj-$(CONFIG_RASPBERRYPI_THERMAL) += raspberrypi-thermal.o diff --git a/drivers/thermal/broadcom/raspberrypi-thermal.c b/drivers/thermal/broadcom/raspberrypi-thermal.c new file mode 100644 index 000000000000..d9c1db06f806 --- /dev/null +++ b/drivers/thermal/broadcom/raspberrypi-thermal.c @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2017 Rafał Miłecki + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#include +#include +#include + +#include + +struct rpi_thermal { + struct rpi_firmware *fw; +}; + +static int rpi_thermal_get_temp(void *data, int *temp) +{ + struct rpi_thermal *rpi_thermal = data; + struct { + u32 id; + u32 temp; + } tag_data = {}; + int err; + + err = rpi_firmware_property(rpi_thermal->fw, + RPI_FIRMWARE_GET_TEMPERATURE, + &tag_data, sizeof(tag_data)); + if (!err) + *temp = tag_data.temp; + + return err; +} + +const struct thermal_zone_of_device_ops rpi_thermal_ops = { + .get_temp = rpi_thermal_get_temp, +}; + +static int rpi_thermal_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct rpi_thermal *rpi_thermal; + struct device_node *fw_np; + struct thermal_zone_device *tzd; + + rpi_thermal = devm_kzalloc(dev, sizeof(*rpi_thermal), GFP_KERNEL); + if (!rpi_thermal) + return -ENOMEM; + + fw_np = of_parse_phandle(dev->of_node, "firmware", 0); + if (!fw_np) { + dev_err(dev, "Failed to get firmware phandle\n"); + return -ENOENT; + } + + rpi_thermal->fw = rpi_firmware_get(fw_np); + of_node_put(fw_np); + if (!rpi_thermal->fw) + return -ENODEV; + + tzd = devm_thermal_zone_of_sensor_register(dev, 0, rpi_thermal, + &rpi_thermal_ops); + + return PTR_ERR_OR_ZERO(tzd); +} + +static const struct of_device_id rpi_thermal_of_match[] = { + { .compatible = "raspberrypi,bcm2835-thermal", }, + {}, +}; +MODULE_DEVICE_TABLE(of, rpi_thermal_of_match); + +static struct platform_driver rpi_thermal_driver = { + .probe = rpi_thermal_probe, + .driver = { + .name = "raspberrypi-thermal", + .of_match_table = rpi_thermal_of_match, + }, +}; +module_platform_driver(rpi_thermal_driver); + +MODULE_DESCRIPTION("Raspberry Pi thermal driver"); +MODULE_LICENSE("GPL v2");