From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.5 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 934B5C433E0 for ; Wed, 24 Jun 2020 21:12:43 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4F6F120768 for ; Wed, 24 Jun 2020 21:12:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="PnlH5gOU"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Xvwuxmj2" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4F6F120768 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=roeck-us.net Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=0mfz6a4ez29gtCpF74lDWqbZzwqwfn25e5FiM3doIs0=; b=PnlH5gOUr9T+qnltJJE7mo+Sa AxPg3Gl4qsKjDL+DzpW7zHtmcTRfcKJ0uZcR/hI54mZxPKfXWCUwBjxsw4VefATPq3ub0tigO8GuB Mb3Plnej3abjRzmQ3v+dFgzShiN2+pouCsps/u0+zhCoQSxsI17eBCD6F/hiR5GDyBBQXJ2/B4ctN t4Ls9JnEVe6isrmOQo7c1etlyoLw+9NacaxJbce5GMthaV4DYLjEUFR98Xyf7Hh6Ih0F25/2aAO0m GGDEBtycC53G2uaqmkCl4gu4rFQddG59gCMHuBWIik6J+Fcn2fGdN3tAdJaoH1nKjizFE0kIpPWGC vCprfo+TQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1joCfQ-0000hk-UU; Wed, 24 Jun 2020 21:10:49 +0000 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1joCfL-0000eD-KC for linux-arm-kernel@lists.infradead.org; Wed, 24 Jun 2020 21:10:45 +0000 Received: by mail-pl1-x644.google.com with SMTP id x8so735302plm.10 for ; Wed, 24 Jun 2020 14:10:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=/eiwI1eGlw5Yv/W0V/S+2e3gbq80QMsr1vAJ9YkSwVk=; b=Xvwuxmj2iQDNUKKjDTIqIAu6fZ+stY6McugP2B54qu1N7oEoLEOCueH1Gsp801kIiD q6nsT96rBUvSj6fOUVDUU6nkt0JacEuQMAeQBWRfoT3DZK9KvAghar2F0u/FBZxhufvX 2qiMPClEd6PGrpi+I2Imry5467U+ehY+z88sjuPbXavayx2Q7f58vjd+9hW6wRMLCvC1 /duw0dNh7fqVh9b80es9Yk6noeCaD9GHLHsQBWYIDWtbEBGKSRG93+WvcQqckY3pNRyo jQkSLtXcu0TaJj6unTdwEMe/HziJ2RAShMb+5J+KXsUHbssx6KExaa+J1T7tBPtKXB40 S7Vw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=/eiwI1eGlw5Yv/W0V/S+2e3gbq80QMsr1vAJ9YkSwVk=; b=dHiN4dzwdfAqiOcVYBhE0Wr8YZ2TK+y0z5vbNOMrAFs+qk5JInuDpGYGgcfu2X8HtU 77h50aWqREGttlIEYuH0oDgqV1eLMSz0eearqmPC0D0+aMcIqfV0KZcc//cjYW0VRVCp KGn1/Hxl3yrkBljohwp3tI7OeKWAPeIHgat99LCY4MAbp2JEHtsqMYmeQLE3trwU9iVE DE/4tRsPMKqMavz7KbAzd5IQ+M9o7Fi63BV6YXouSZ2FccYKGn5TiJWuvowdKJXiQrR/ c+HGcjpvFlvtJ3Awafm2TgBxbNJ+WeEp6MBrSZk9PwXi98SqI+LkmIzQLfYK9ylYGhBX yGzw== X-Gm-Message-State: AOAM533rU7vsF5266E14xSripa8xcNbXQTUp9NH5UkSes+5ocNNLE0eD iGqbLXJt8+HQTE+nmuHzVcnJPsdB X-Google-Smtp-Source: ABdhPJybmXXFlZ8AhuIjBfTS+0JjnixQMHnBIuXtWZkkRNHD0uqvco3gh2AjNP+Xw9uTmHbVcCIRHw== X-Received: by 2002:a17:902:bcc1:: with SMTP id o1mr26623226pls.246.1593033040342; Wed, 24 Jun 2020 14:10:40 -0700 (PDT) Received: from localhost ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id b14sm2987858pfb.186.2020.06.24.14.10.38 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 24 Jun 2020 14:10:39 -0700 (PDT) Date: Wed, 24 Jun 2020 14:10:38 -0700 From: Guenter Roeck To: Lars Povlsen Subject: Re: [PATCH v4 3/3] hwmon: sparx5: Add Sparx5 SoC temperature driver Message-ID: <20200624211038.GA72859@roeck-us.net> References: <20200618135951.25441-1-lars.povlsen@microchip.com> <20200618135951.25441-4-lars.povlsen@microchip.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20200618135951.25441-4-lars.povlsen@microchip.com> User-Agent: Mutt/1.9.4 (2018-02-28) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org, Alexandre Belloni , Jean Delvare , linux-kernel@vger.kernel.org, Microchip Linux Driver Support , linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, Jun 18, 2020 at 03:59:51PM +0200, Lars Povlsen wrote: > This patch adds a temperature sensor driver to the Sparx5 SoC. > = > Signed-off-by: Lars Povlsen Sorry for the long delay. We'll still need approval from DT for DT properties. > --- > Documentation/hwmon/sparx5-temp.rst | 33 ++++++ Nitpick: The new file needs to be added to index.rst. Other than that, for my reference: Reviewed-by: Guenter Roeck > drivers/hwmon/Kconfig | 10 ++ > drivers/hwmon/Makefile | 1 + > drivers/hwmon/sparx5-temp.c | 168 ++++++++++++++++++++++++++++ > 4 files changed, 212 insertions(+) > create mode 100644 Documentation/hwmon/sparx5-temp.rst > create mode 100644 drivers/hwmon/sparx5-temp.c > = > diff --git a/Documentation/hwmon/sparx5-temp.rst b/Documentation/hwmon/sp= arx5-temp.rst > new file mode 100644 > index 0000000000000..0140809089542 > --- /dev/null > +++ b/Documentation/hwmon/sparx5-temp.rst > @@ -0,0 +1,33 @@ > +.. SPDX-License-Identifier: GPL-2.0-only > + > +Microchip SparX-5 SoC > +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > + > +Supported chips: > + > + * VSC7546, VSC7549, VSC755, VSC7556, and VSC7558 (Sparx5 series) > + > + Prefix: 'sparx5-temp' > + > + Addresses scanned: - > + > + Datasheet: Provided by Microchip upon request and under NDA > + > +Author: Lars Povlsen > + > +Description > +----------- > + > +The Sparx5 SoC contains a temperature sensor based on the MR74060 > +Moortec IP. > + > +The sensor has a range of -40=B0C to +125=B0C and an accuracy of +/-5=B0= C. > + > +Sysfs entries > +------------- > + > +The following attributes are supported. > + > +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D > +temp1_input Die temperature (in millidegree Celsius.) > +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D > diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig > index 288ae9f63588c..7fb5e0c6c6306 100644 > --- a/drivers/hwmon/Kconfig > +++ b/drivers/hwmon/Kconfig > @@ -515,6 +515,16 @@ config SENSORS_I5K_AMB > This driver can also be built as a module. If so, the module > will be called i5k_amb. > = > +config SENSORS_SPARX5 > + tristate "Sparx5 SoC temperature sensor" > + depends on ARCH_SPARX5 || COMPILE_TEST > + help > + If you say yes here you get support for temperature monitoring > + with the Microchip Sparx5 SoC. > + > + This driver can also be built as a module. If so, the module > + will be called sparx5-temp. > + > config SENSORS_F71805F > tristate "Fintek F71805F/FG, F71806F/FG and F71872F/FG" > depends on !PPC > diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile > index 3e32c21f5efe3..857293f650412 100644 > --- a/drivers/hwmon/Makefile > +++ b/drivers/hwmon/Makefile > @@ -167,6 +167,7 @@ obj-$(CONFIG_SENSORS_SMM665) +=3D smm665.o > obj-$(CONFIG_SENSORS_SMSC47B397)+=3D smsc47b397.o > obj-$(CONFIG_SENSORS_SMSC47M1) +=3D smsc47m1.o > obj-$(CONFIG_SENSORS_SMSC47M192)+=3D smsc47m192.o > +obj-$(CONFIG_SENSORS_SPARX5) +=3D sparx5-temp.o > obj-$(CONFIG_SENSORS_STTS751) +=3D stts751.o > obj-$(CONFIG_SENSORS_AMC6821) +=3D amc6821.o > obj-$(CONFIG_SENSORS_TC74) +=3D tc74.o > diff --git a/drivers/hwmon/sparx5-temp.c b/drivers/hwmon/sparx5-temp.c > new file mode 100644 > index 0000000000000..7d7a060259a80 > --- /dev/null > +++ b/drivers/hwmon/sparx5-temp.c > @@ -0,0 +1,168 @@ > +// SPDX-License-Identifier: GPL-2.0-or-later > +/* Sparx5 SoC temperature sensor driver > + * > + * Copyright (C) 2020 Lars Povlsen > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#define TEMP_CTRL 0 > +#define TEMP_CFG 4 > +#define TEMP_CFG_CYCLES GENMASK(24, 15) > +#define TEMP_CFG_ENA BIT(0) > +#define TEMP_STAT 8 > +#define TEMP_STAT_VALID BIT(12) > +#define TEMP_STAT_TEMP GENMASK(11, 0) > + > +struct s5_hwmon { > + void __iomem *base; > + struct clk *clk; > +}; > + > +static void s5_temp_clk_disable(void *data) > +{ > + struct clk *clk =3D data; > + > + clk_disable_unprepare(clk); > +} > + > +static void s5_temp_enable(struct s5_hwmon *hwmon) > +{ > + u32 val =3D readl(hwmon->base + TEMP_CFG); > + u32 clk =3D clk_get_rate(hwmon->clk) / USEC_PER_SEC; > + > + val &=3D ~TEMP_CFG_CYCLES; > + val |=3D FIELD_PREP(TEMP_CFG_CYCLES, clk); > + val |=3D TEMP_CFG_ENA; > + > + writel(val, hwmon->base + TEMP_CFG); > +} > + > +static int s5_read(struct device *dev, enum hwmon_sensor_types type, > + u32 attr, int channel, long *temp) > +{ > + struct s5_hwmon *hwmon =3D dev_get_drvdata(dev); > + int rc =3D 0, value; > + u32 stat; > + > + switch (attr) { > + case hwmon_temp_input: > + stat =3D readl_relaxed(hwmon->base + TEMP_STAT); > + if (!(stat & TEMP_STAT_VALID)) > + return -EIO; > + value =3D stat & TEMP_STAT_TEMP; > + /* > + * From register documentation: > + * Temp(C) =3D TEMP_SENSOR_STAT.TEMP / 4096 * 352.2 - 109.4 > + */ > + value =3D DIV_ROUND_CLOSEST(value * 3522, 4096) - 1094; > + /* > + * Scale down by 10 from above and multiply by 1000 to > + * have millidegrees as specified by the hwmon sysfs > + * interface. > + */ > + value *=3D 100; > + *temp =3D value; > + break; > + default: > + rc =3D -EOPNOTSUPP; > + break; > + } > + > + return rc; > +} > + > +static umode_t s5_is_visible(const void *_data, enum hwmon_sensor_types = type, > + u32 attr, int channel) > +{ > + if (type !=3D hwmon_temp) > + return 0; > + > + switch (attr) { > + case hwmon_temp_input: > + return 0444; > + default: > + return 0; > + } > +} > + > +static const struct hwmon_channel_info *s5_info[] =3D { > + HWMON_CHANNEL_INFO(chip, HWMON_C_REGISTER_TZ), > + HWMON_CHANNEL_INFO(temp, HWMON_T_INPUT), > + NULL > +}; > + > +static const struct hwmon_ops s5_hwmon_ops =3D { > + .is_visible =3D s5_is_visible, > + .read =3D s5_read, > +}; > + > +static const struct hwmon_chip_info s5_chip_info =3D { > + .ops =3D &s5_hwmon_ops, > + .info =3D s5_info, > +}; > + > +static int s5_temp_probe(struct platform_device *pdev) > +{ > + struct device *hwmon_dev; > + struct s5_hwmon *hwmon; > + int ret; > + > + hwmon =3D devm_kzalloc(&pdev->dev, sizeof(*hwmon), GFP_KERNEL); > + if (!hwmon) > + return -ENOMEM; > + > + hwmon->base =3D devm_platform_ioremap_resource(pdev, 0); > + if (IS_ERR(hwmon->base)) > + return PTR_ERR(hwmon->base); > + > + hwmon->clk =3D devm_clk_get(&pdev->dev, NULL); > + if (IS_ERR(hwmon->clk)) > + return PTR_ERR(hwmon->clk); > + > + ret =3D clk_prepare_enable(hwmon->clk); > + if (ret) > + return ret; > + > + ret =3D devm_add_action_or_reset(&pdev->dev, s5_temp_clk_disable, > + hwmon->clk); > + if (ret) > + return ret; > + > + s5_temp_enable(hwmon); > + > + hwmon_dev =3D devm_hwmon_device_register_with_info(&pdev->dev, > + "s5_temp", > + hwmon, > + &s5_chip_info, > + NULL); > + > + return PTR_ERR_OR_ZERO(hwmon_dev); > +} > + > +const struct of_device_id s5_temp_match[] =3D { > + { .compatible =3D "microchip,sparx5-temp" }, > + {}, > +}; > +MODULE_DEVICE_TABLE(of, s5_temp_match); > + > +static struct platform_driver s5_temp_driver =3D { > + .probe =3D s5_temp_probe, > + .driver =3D { > + .name =3D "sparx5-temp", > + .of_match_table =3D s5_temp_match, > + }, > +}; > + > +module_platform_driver(s5_temp_driver); > + > +MODULE_AUTHOR("Lars Povlsen "); > +MODULE_DESCRIPTION("Sparx5 SoC temperature sensor driver"); > +MODULE_LICENSE("GPL"); _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel