Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp1994020imm; Sun, 27 May 2018 22:42:36 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoHbqxE2rxazOmrLA8Lzu2wFc4T8qnP0gx24XYe0silRoNOSVRTNDF/3flvbv4NzEQqtAYZ X-Received: by 2002:a17:902:5409:: with SMTP id d9-v6mr12071511pli.1.1527486156132; Sun, 27 May 2018 22:42:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527486156; cv=none; d=google.com; s=arc-20160816; b=wvVTve3SeDWD44bXgH2U2dgKckKKGMX6cuFP2Q70xrStN/w1OlqPufGT6O0/Pv60TZ d4uSUVvVfnVLmNZiJRd0jBBcaFTLYhAaKZ6pUww9gcJxDQlGxxPOOW5OVcGCp9W7ImUL K/qVQJdiz8xwOpMz7YEXjaiqz6TqlN/FkfVc9syBcvGcOvwnPRrAVMtCVB0TLZjnCKas JyoSWykn1o0iqY56qzYRsO/eey6Kqfy+r1zoxZqlwoU19QTdUILBfebic04BbnvZ1LTr JtQYUyL22E6qKkWB4eDb1WGdtHzmNbYYyZOtH7JDcWoI8hByK4BnBjTmffxg6D/fRExl lokA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=g/6n9FG4/AwRmtH+suwPSqNqKqY+EGD3syhT2Lq/dvA=; b=ixd40PS79zs9oEsJFTYRPCV0XmP410LgIHLCrFlVx8ICHwuppxCJbqSbrAq4JOlVKq YuQYJ7WGsx0THp6isQDbjFD/iAM0Bx6cr/cvm+Ok1SjH3pBMw9yt/ll2JyHgNxl/+8BF 8pIgKIUxwMDEOERLZCj7toCUYfDu5oI+nJ3zS0aXYxwthELrUcR5X10EoAE5XDYm9UvK oC1wwDJn8HW2cqQESDhveHyalI43DNdJssg2caI2MKdZTQsE5gx9N9eVfm7EGk22Tjcj G4Bu43UxInZKFvNcxqQhr8AeONiqU+fo8cPFOtI+oHz+lQIE++ogf9/n9Xvgi9dgKD9/ 9L3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b=LCEhkYP3; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v4-v6si28010284pff.281.2018.05.27.22.42.21; Sun, 27 May 2018 22:42:36 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b=LCEhkYP3; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753339AbeE1FmA (ORCPT + 99 others); Mon, 28 May 2018 01:42:00 -0400 Received: from mail-qt0-f195.google.com ([209.85.216.195]:33973 "EHLO mail-qt0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753389AbeE1Fl4 (ORCPT ); Mon, 28 May 2018 01:41:56 -0400 Received: by mail-qt0-f195.google.com with SMTP id m5-v6so13667030qti.1 for ; Sun, 27 May 2018 22:41:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=g/6n9FG4/AwRmtH+suwPSqNqKqY+EGD3syhT2Lq/dvA=; b=LCEhkYP31ubFq6Tx+6g+OTM3hpinM6FBxbL4zlJGVa4DpWRH+pgETHyTL4ofleUaVw P+E14iWeZy5RGDplQ8gV+CiXjYIUUMXL3+gQb9V1ug+NHHMWiZQxbyzRnruLW2xtA63C OpErCJQHj7ZgpKChXijy7lT8kO6MWdlTIr8BM= 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=g/6n9FG4/AwRmtH+suwPSqNqKqY+EGD3syhT2Lq/dvA=; b=Q/IPkDhbly26RbAIcYN9Hywvl8Qq356Db+u0G0Cd/VAjC5DjZIByJf5tWCO4ybMjdq rond3IbWynH0t7wJmFPBYy7iVVZmw+pjwbL1pl5bLStp7Zbtye7AirXfYeE5PzHenVZ6 vwB+4O78DQihMysoS2h4jnQ60wNehyqcdNhUlVaKjnli2RHcZClr7x3rDybzPqESkbTO DQO6RPAjLFlla8sKNLNpgtnwgR/OIoaLNcHy+4gImIL0L2I4O5IP9K4CWTLH90u67AnC HDdnYlUR3AyqSAVG2tDFlhZTbVqJJA9dccp9ZHMhoYZGus0Gu67GCltVFC/UaNohBWXT 3aKQ== X-Gm-Message-State: ALKqPwcgF6sMqltQOBTj8IawckCVlLUVuzl3kC+ZJ+9oRK7lRFGBcQsg x5gTqUS1KC8e26TwHXfBoyEWQg== X-Received: by 2002:ac8:1c4b:: with SMTP id j11-v6mr11142657qtk.188.1527486115860; Sun, 27 May 2018 22:41:55 -0700 (PDT) Received: from mannams-OptiPlex-7010.dhcp.broadcom.net ([192.19.234.250]) by smtp.gmail.com with ESMTPSA id m70-v6sm2543580qkl.72.2018.05.27.22.41.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 27 May 2018 22:41:55 -0700 (PDT) From: Srinath Mannam To: Zhang Rui , Eduardo Valentin , Rob Herring , Mark Rutland Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, bcm-kernel-feedback-list@broadcom.com, Pramod Kumar , Srinath Mannam Subject: [PATCH 3/3] thermal: broadcom: Add Stingray thermal driver Date: Mon, 28 May 2018 11:11:24 +0530 Message-Id: <1527486084-4636-4-git-send-email-srinath.mannam@broadcom.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1527486084-4636-1-git-send-email-srinath.mannam@broadcom.com> References: <1527486084-4636-1-git-send-email-srinath.mannam@broadcom.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Pramod Kumar This commit adds stingray thermal driver to monitor six thermal zones temperature and trips at critical temperature. Signed-off-by: Pramod Kumar Signed-off-by: Srinath Mannam Reviewed-by: Ray Jui Reviewed-by: Scott Branden Reviewed-by: Vikram Prakash --- drivers/thermal/Kconfig | 3 +- drivers/thermal/broadcom/Kconfig | 9 ++ drivers/thermal/broadcom/Makefile | 1 + drivers/thermal/broadcom/sr-thermal.c | 151 ++++++++++++++++++++++++++++++++++ 4 files changed, 163 insertions(+), 1 deletion(-) create mode 100644 drivers/thermal/broadcom/sr-thermal.c diff --git a/drivers/thermal/Kconfig b/drivers/thermal/Kconfig index 8297988..26d39d4 100644 --- a/drivers/thermal/Kconfig +++ b/drivers/thermal/Kconfig @@ -416,7 +416,8 @@ config MTK_THERMAL controller present in Mediatek SoCs menu "Broadcom thermal drivers" -depends on ARCH_BCM || ARCH_BRCMSTB || ARCH_BCM2835 || COMPILE_TEST +depends on ARCH_BCM || ARCH_BRCMSTB || ARCH_BCM2835 || ARCH_BCM_IPROC || \ + COMPILE_TEST source "drivers/thermal/broadcom/Kconfig" endmenu diff --git a/drivers/thermal/broadcom/Kconfig b/drivers/thermal/broadcom/Kconfig index c106a15..dc9a9bd 100644 --- a/drivers/thermal/broadcom/Kconfig +++ b/drivers/thermal/broadcom/Kconfig @@ -22,3 +22,12 @@ config BCM_NS_THERMAL BCM4708, BCM4709, BCM5301x, BCM95852X, etc). It contains DMU (Device Management Unit) block with a thermal sensor that allows checking CPU temperature. + +config BCM_SR_THERMAL + tristate "Stingray thermal driver" + depends on ARCH_BCM_IPROC || COMPILE_TEST + default ARCH_BCM_IPROC + help + Support for the Stingray family of SoCs. Its different blocks like + iHost, CRMU and NITRO has thermal sensor that allows checking its + temperature. diff --git a/drivers/thermal/broadcom/Makefile b/drivers/thermal/broadcom/Makefile index fae10ec..79df69e 100644 --- a/drivers/thermal/broadcom/Makefile +++ b/drivers/thermal/broadcom/Makefile @@ -1,3 +1,4 @@ obj-$(CONFIG_BCM2835_THERMAL) += bcm2835_thermal.o obj-$(CONFIG_BRCMSTB_THERMAL) += brcmstb_thermal.o obj-$(CONFIG_BCM_NS_THERMAL) += ns-thermal.o +obj-$(CONFIG_BCM_SR_THERMAL) += sr-thermal.o diff --git a/drivers/thermal/broadcom/sr-thermal.c b/drivers/thermal/broadcom/sr-thermal.c new file mode 100644 index 0000000..5baaa6e --- /dev/null +++ b/drivers/thermal/broadcom/sr-thermal.c @@ -0,0 +1,151 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2018 Broadcom + */ + +#include +#include +#include +#include + +#define TMON_CRIT_TEMP 105000 /* temp in millidegree C */ + +struct sr_thermal { + struct thermal_zone_device *tz; + struct device *dev; + void __iomem *regs; + unsigned int crit_temp; +}; + +static int sr_get_temp(struct thermal_zone_device *tz, int *temp) +{ + struct sr_thermal *sr_thermal = tz->devdata; + + *temp = readl(sr_thermal->regs); + + return 0; +} + +static int sr_get_trip_type(struct thermal_zone_device *tz, int trip, + enum thermal_trip_type *type) +{ + struct sr_thermal *sr_thermal = tz->devdata; + + switch (trip) { + case 0: + *type = THERMAL_TRIP_CRITICAL; + break; + default: + dev_dbg(sr_thermal->dev, + "Driver does not support more than 1 trip point\n"); + return -EINVAL; + } + return 0; +} + +static int sr_get_trip_temp(struct thermal_zone_device *tz, int trip, int *temp) +{ + struct sr_thermal *sr_thermal = tz->devdata; + + switch (trip) { + case 0: + *temp = sr_thermal->crit_temp; + break; + default: + dev_dbg(sr_thermal->dev, + "Driver does not support more than 1 trip point\n"); + return -EINVAL; + } + return 0; +} + +static int sr_set_trip_temp(struct thermal_zone_device *tz, int trip, int temp) +{ + struct sr_thermal *sr_thermal = tz->devdata; + + switch (trip) { + case 0: + /* + * Allow the user to change critical temperature + * as per their requirement, could be for debug + * purpose, even if it's more than the recommended + * critical temperature. + */ + sr_thermal->crit_temp = temp; + break; + default: + return -EINVAL; + } + return 0; +} + +static struct thermal_zone_device_ops sr_thermal_ops = { + .get_temp = sr_get_temp, + .get_trip_type = sr_get_trip_type, + .get_trip_temp = sr_get_trip_temp, + .set_trip_temp = sr_set_trip_temp, +}; + +static int sr_thermal_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct sr_thermal *sr_thermal; + struct resource *res; + + sr_thermal = devm_kzalloc(dev, sizeof(*sr_thermal), GFP_KERNEL); + if (!sr_thermal) + return -ENOMEM; + sr_thermal->dev = dev; + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + sr_thermal->regs = devm_memremap(&pdev->dev, res->start, + resource_size(res), MEMREMAP_WB); + if (IS_ERR(sr_thermal->regs)) { + dev_err(dev, "failed to get io address\n"); + return PTR_ERR(sr_thermal->regs); + } + + /* initialize tmon value to 0 */ + writel(0, sr_thermal->regs); + sr_thermal->crit_temp = TMON_CRIT_TEMP; + + sr_thermal->tz = thermal_zone_device_register(dev_name(dev), 1, 1, + sr_thermal, + &sr_thermal_ops, + NULL, 1000, 1000); + if (IS_ERR(sr_thermal->tz)) + return PTR_ERR(sr_thermal->tz); + + platform_set_drvdata(pdev, sr_thermal); + + return 0; +} + +static int sr_thermal_remove(struct platform_device *pdev) +{ + struct sr_thermal *sr_thermal = platform_get_drvdata(pdev); + + thermal_zone_device_unregister(sr_thermal->tz); + + return 0; +} + +static const struct of_device_id sr_thermal_of_match[] = { + { .compatible = "brcm,sr-thermal", }, + {}, +}; +MODULE_DEVICE_TABLE(of, sr_thermal_of_match); + +static struct platform_driver sr_thermal_driver = { + .probe = sr_thermal_probe, + .remove = sr_thermal_remove, + .driver = { + .name = "sr-thermal", + .of_match_table = sr_thermal_of_match, + }, +}; +module_platform_driver(sr_thermal_driver); + +MODULE_AUTHOR("Pramod Kumar "); +MODULE_DESCRIPTION("Stingray thermal driver"); +MODULE_LICENSE("GPL v2"); -- 2.7.4