Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp3675771imm; Mon, 18 Jun 2018 02:04:25 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKrGyPzwRdu8RFOX7nfEEagrWfmRnEovTK2l2eRRZjdCkDPwewBxUtOXfLi0DGYDhek2HyQ X-Received: by 2002:a62:ba13:: with SMTP id k19-v6mr12554298pff.245.1529312665786; Mon, 18 Jun 2018 02:04:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529312665; cv=none; d=google.com; s=arc-20160816; b=pUAc2hvNAZWekGmA1GElz45mgOXQi8Y8b6BRBZsQMDPxPKDlr2Gb2jhsu/R4f8kuYk xI9Ao8AT5W5GKbVu1S7m+djIywHxM5s4CnJhIkzYw9ERjqHFLgINJm0xkr9uwl6e3l3m pIodNgFWilDuKxNopTQ7kWpCm8afJ3+AUnrXZmx1oMMYCHLk/g7KiHQP3l2kAPIOtVYI x3x9BD8vKZ7mOmlzkPlKrtmvHPX90os36+ocKnk/uFyNgINQBGffT5uvMf5Sm9UUKP2k ejZlK/BfrWa8+P4Y69GqQXpuALsxGWoFqisFmhzJRwKiR2mo6B1Q4ePNdRiS476Y61Qe D75A== 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=Xig+YgGUpoeKt6709Z5HEXuCGHUYfFQZJkHXzhcEUvY=; b=QU6peqqh4y8a7xbM4CpPUdC2OjkYiimIy3jdTDgzV1B6Xj8mM+KojX8whvq4hSfMNC rbygyfrfHhSHOTlVg2LroNqdD2HQilM7Ac2Z88tvECU0iFVapreuC43xw6IqIMlFzfKe gveEXh5lTlAZAD0HcF6QcYQoczL3p0Z/OK9fc4TobLw7326bxzOkxOQP887Pk48DEhu7 nUBzNfeiFIUGk3NjurnKfCyp0/M6K77WShNPBBVfS9+I4W6jzMMljt91VRQBO85BicF3 ZmyxK1EbZ6bmlfcBHHc9l5eLAVp1UUSIaBeALeES60raIuQ/QdJyVdIiDVIIejkNKgEJ KMAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b=Es2+e2vq; 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 s4-v6si11858373pgf.169.2018.06.18.02.04.12; Mon, 18 Jun 2018 02:04:25 -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=Es2+e2vq; 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 S967433AbeFRJDh (ORCPT + 99 others); Mon, 18 Jun 2018 05:03:37 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:35174 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966954AbeFRIcX (ORCPT ); Mon, 18 Jun 2018 04:32:23 -0400 Received: by mail-wm0-f68.google.com with SMTP id j15-v6so13903863wme.0 for ; Mon, 18 Jun 2018 01:32:22 -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=Xig+YgGUpoeKt6709Z5HEXuCGHUYfFQZJkHXzhcEUvY=; b=Es2+e2vqTZ0/YnhT+QFK5w/P9XzJDOukOuKqB0KOzW0tgLFB1i79spw6ryBPktunV3 xwLeza5eK/vjuPGHLSNUT5NkEQp7BD4a+09z7wYsB8FSqpIADZyjsqmjVS5+O9O/qAl0 jga0J2dlnXh2yNKPycLwYzP76r1/ypd3LO5hk= 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=Xig+YgGUpoeKt6709Z5HEXuCGHUYfFQZJkHXzhcEUvY=; b=lIJo4jDBN7EJKOzVMxYm23/araxOqlayhxmB6RCBovOFi92dTeUEuX6FRTIyIkusrC pAnJXW0ZjpSQcMAwtu8GZZk67oEqBpRTauo2qx+ONKIXvU03EVEUa67E/1J//VH066DI 4KByNHI2LIvsfOgGGEC9WJT9xXOba/BcvqYztqUIHb4D73Kn3Uw/Xv2saEUs3GiU6503 8W3eOg++M0Qqm1p31qKn44RY/kLCABlWx3cq2r/4zo7+amOCNjMg+j/iX5do/2ol55pr 1JiPeDQoprpb69GXzlSxtyFEdAcHsX30FjX7/4+pb2HbEfhSP0gaOLJxCTrrgz1dTr1U 6Q3w== X-Gm-Message-State: APt69E2TjwGFgGGO9uxGE6YxbiGzs7zSqLD60WFnZooI1pqAeaYCDMJp 7BAwoONIcNcSyaE8M6JWuwbs0A== X-Received: by 2002:a50:a624:: with SMTP id d33-v6mr10342895edc.8.1529310741693; Mon, 18 Jun 2018 01:32:21 -0700 (PDT) Received: from mannams-OptiPlex-7010.dhcp.broadcom.net ([192.19.234.250]) by smtp.gmail.com with ESMTPSA id r10-v6sm6261992edo.77.2018.06.18.01.32.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 18 Jun 2018 01:32:21 -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 v2 3/3] thermal: broadcom: Add Stingray thermal driver Date: Mon, 18 Jun 2018 14:01:19 +0530 Message-Id: <1529310679-13482-4-git-send-email-srinath.mannam@broadcom.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1529310679-13482-1-git-send-email-srinath.mannam@broadcom.com> References: <1529310679-13482-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 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..362dcda --- /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 = (void __iomem *)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