From patchwork Fri Oct 7 15:22:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pantelis Antoniou X-Patchwork-Id: 9366361 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 50F486075E for ; Fri, 7 Oct 2016 15:31:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 415B0296F7 for ; Fri, 7 Oct 2016 15:31:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3617B296FA; Fri, 7 Oct 2016 15:31:08 +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=-6.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=unavailable 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 9F802296F7 for ; Fri, 7 Oct 2016 15:31:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934919AbcJGPaM (ORCPT ); Fri, 7 Oct 2016 11:30:12 -0400 Received: from mail-wm0-f46.google.com ([74.125.82.46]:34848 "EHLO mail-wm0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757149AbcJGPYd (ORCPT ); Fri, 7 Oct 2016 11:24:33 -0400 Received: by mail-wm0-f46.google.com with SMTP id f193so39153102wmg.0 for ; Fri, 07 Oct 2016 08:24:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=konsulko.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=nk7a+3jyVE6r90czByk90dIcupmeKqRhxZ7v1TEX+i0=; b=btc2TV/GjlIC9hU/1X9lE4VR/3etpTYZ8MDTv+wcN9L3v40KakOP/z+7oVeooLTYaq qVPGtZB6w23uVOxU2kkf3IgcZuc0aMo6nfrKkfTg4BRlG6YvFLIIXKPPI24wrJRuEOzr EHKQHCmE3TrqM7oRUvXv0Jg6eRm9f11a0uOWo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=nk7a+3jyVE6r90czByk90dIcupmeKqRhxZ7v1TEX+i0=; b=BsU7Wut/R4j8/hKOJ2yEH+ZOWJIuJ19dV46ReHME1HymKS039zN3lPWC+NNBQiiHmK Sa2DA6hQxKMjSoevI/usevsKgRiCjXDeezn8/mwp23AuRm1C1gEeU+GOm31HZa9DCIGR gWeYvZcsnXJcGg39E4u+4+gCDCTmEMv5wT1yZyCj5hmEwdLva/gjT/54TDCP24KJTRhO mcYJNRfJj+MFFLkS9hk09DAEErSAYOydXDYNA5pt7wm9ZCTMfjCJjBakxz7Gd5BFY4vs 8LXkceMhwkVfjHACDJXToE162Lh77vaYmfbLeSUk1z9Ubt4p7cEBWbb+2EwbFSyMAd6n wX5g== X-Gm-Message-State: AA6/9RmdOZCxQahLc5GzFach/KJ5iaOj2Mi1Yh9lXL6seHzYzdCKVO/rzHPfFZz2PuyUPg== X-Received: by 10.28.95.87 with SMTP id t84mr18826678wmb.51.1475853871983; Fri, 07 Oct 2016 08:24:31 -0700 (PDT) Received: from localhost.localdomain ([195.97.110.117]) by smtp.gmail.com with ESMTPSA id f2sm3491056wjr.2.2016.10.07.08.24.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 07 Oct 2016 08:24:31 -0700 (PDT) From: Pantelis Antoniou To: Lee Jones Cc: Rob Herring , Mark Rutland , Frank Rowand , David Woodhouse , Brian Norris , Wim Van Sebroeck , Jean Delvare , Georgi Vlaev , Guenter Roeck , JawaharBalaji Thirumalaisamy , Pantelis Antoniou , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org, linux-watchdog@vger.kernel.org, linux-hwmon@vger.kernel.org Subject: [PATCH 7/7] hwmon: ptx1kbf: Add PTX1K I2CS BootFPGA sensor driver Date: Fri, 7 Oct 2016 18:22:04 +0300 Message-Id: <1475853724-22557-8-git-send-email-pantelis.antoniou@konsulko.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1475853724-22557-1-git-send-email-pantelis.antoniou@konsulko.com> References: <1475853724-22557-1-git-send-email-pantelis.antoniou@konsulko.com> Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Georgi Vlaev The drivers allows reading CPU, PCH and DIMM modules teperatures from the I2CS FPGA via the SMLink1 to the PCH. Signed-off-by: Georgi Vlaev Signed-off-by: Guenter Roeck [Ported from Juniper kernel] Signed-off-by: Pantelis Antoniou --- drivers/hwmon/Kconfig | 17 ++++++ drivers/hwmon/Makefile | 1 + drivers/hwmon/jnx_ptx1kbf_hwmon.c | 123 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 141 insertions(+) create mode 100644 drivers/hwmon/jnx_ptx1kbf_hwmon.c diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig index b9348d2..5b66c7b 100644 --- a/drivers/hwmon/Kconfig +++ b/drivers/hwmon/Kconfig @@ -674,6 +674,23 @@ config SENSORS_JNX_FAN This driver can also be built as a module. If so, the module will be called jnx-fan. +config SENSORS_JNX_PTX1KBF + tristate "Juniper Networks PTX1000 I2CS BootFPGA thermal sensors" + depends on MFD_JUNIPER_PTX1KBF + help + If you say yes here you get support for the hardware + monitoring features of the Juniper Networks PTX1000 I2CS BootFPGA + on the LPC bus. The CPU's digital thermal sensor can be read over + the PECI interface. PECI is connected to the PCH and the PCH's + Management Engine (ME) can be configured to poll CPU and DIMM + temperatures over the PECI interface. Then, it is possible for an + external I2C master (in the I2CS FPGA) to read CPU, DIMM and PCH + temperatures from the PCH over SMLink1 (which is connected to the board + I2C tree). + + This driver can also be built as a module. If so, the module + will be called jnx_ptx1kbf_hwmon. + config SENSORS_POWR1220 tristate "Lattice POWR1220 Power Monitoring" depends on I2C diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile index eea631e..a3dedef 100644 --- a/drivers/hwmon/Makefile +++ b/drivers/hwmon/Makefile @@ -82,6 +82,7 @@ obj-$(CONFIG_SENSORS_INA3221) += ina3221.o obj-$(CONFIG_SENSORS_IT87) += it87.o obj-$(CONFIG_SENSORS_JC42) += jc42.o obj-$(CONFIG_SENSORS_JNX_FAN) += jnx-fan.o +obj-$(CONFIG_SENSORS_JNX_PTX1KBF) += jnx_ptx1kbf_hwmon.o obj-$(CONFIG_SENSORS_JZ4740) += jz4740-hwmon.o obj-$(CONFIG_SENSORS_K8TEMP) += k8temp.o obj-$(CONFIG_SENSORS_K10TEMP) += k10temp.o diff --git a/drivers/hwmon/jnx_ptx1kbf_hwmon.c b/drivers/hwmon/jnx_ptx1kbf_hwmon.c new file mode 100644 index 0000000..a9d6562 --- /dev/null +++ b/drivers/hwmon/jnx_ptx1kbf_hwmon.c @@ -0,0 +1,123 @@ +/* + * Juniper Networks PTX1K RCB I2CS Boot FPGA hwmon driver + * + * Copyright (C) 2014 Juniper Networks. All rights reserved. + * Author: Georgi Vlaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#define DRVNAME "jnx-ptx1kbf-hwmon" + +struct bf_hwmon { + void __iomem *base; +}; + +static const char *const bf_temp_label[] = { + "CPU", "PCH", "DIMM1", "DIMM2" +}; + +static ssize_t bf_show_temp(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct bf_hwmon *hwmon = dev_get_drvdata(dev); + int channel = to_sensor_dev_attr(attr)->index; + + return sprintf(buf, "%d\n", be16_to_cpu(ioread16(hwmon->base + + BOOT_FPGA_CPU_TEMP_MSB + (channel * 2)))); +} + +static ssize_t bf_show_label(struct device *dev, + struct device_attribute *attr, char *buf) +{ + int channel = to_sensor_dev_attr(attr)->index; + + return sprintf(buf, "%s\n", bf_temp_label[channel]); +} + +/* CPU Temp */ +static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, bf_show_temp, NULL, 0); +static SENSOR_DEVICE_ATTR(temp1_label, S_IRUGO, bf_show_label, NULL, 0); +/* PCH Temp */ +static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, bf_show_temp, NULL, 1); +static SENSOR_DEVICE_ATTR(temp2_label, S_IRUGO, bf_show_label, NULL, 1); +/* DIMM1 Temp */ +static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, bf_show_temp, NULL, 2); +static SENSOR_DEVICE_ATTR(temp3_label, S_IRUGO, bf_show_label, NULL, 2); +/* DIMM2 Temp */ +static SENSOR_DEVICE_ATTR(temp4_input, S_IRUGO, bf_show_temp, NULL, 3); +static SENSOR_DEVICE_ATTR(temp4_label, S_IRUGO, bf_show_label, NULL, 3); + +static struct attribute *bf_attrs[] = { + &sensor_dev_attr_temp1_input.dev_attr.attr, + &sensor_dev_attr_temp1_label.dev_attr.attr, + &sensor_dev_attr_temp2_input.dev_attr.attr, + &sensor_dev_attr_temp2_label.dev_attr.attr, + &sensor_dev_attr_temp3_input.dev_attr.attr, + &sensor_dev_attr_temp3_label.dev_attr.attr, + &sensor_dev_attr_temp4_input.dev_attr.attr, + &sensor_dev_attr_temp4_label.dev_attr.attr, + NULL +}; + +ATTRIBUTE_GROUPS(bf); + +static int bf_hwmon_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct device *hwmon_dev; + struct bf_hwmon *hwmon; + struct resource *mem; + + hwmon = devm_kzalloc(dev, sizeof(*hwmon), GFP_KERNEL); + if (!hwmon) + return -ENOMEM; + + mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (!mem) { + dev_err(&pdev->dev, "Failed to get platform mmio resource\n"); + return -ENOENT; + } + + hwmon->base = devm_ioremap_nocache(dev, mem->start, resource_size(mem)); + if (IS_ERR(hwmon->base)) { + dev_err(dev, "Failed to ioremap mmio memory\n"); + return PTR_ERR(hwmon->base); + } + + hwmon_dev = devm_hwmon_device_register_with_groups(dev, "jnx_ptx1kbf", + hwmon, bf_groups); + return PTR_ERR_OR_ZERO(hwmon_dev); +} + +static struct platform_driver bf_hwmon_driver = { + .probe = bf_hwmon_probe, + .driver = { + .name = DRVNAME, + .owner = THIS_MODULE, + }, +}; + +module_platform_driver(bf_hwmon_driver); + +MODULE_DESCRIPTION("Juniper Networks PTX1K RCB I2CS Boot FPGA hwmon driver"); +MODULE_AUTHOR("Georgi Vlaev "); +MODULE_LICENSE("GPL"); +MODULE_ALIAS("platform:" DRVNAME);