From patchwork Fri Apr 30 12:35:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Marko X-Patchwork-Id: 12233261 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=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 1CE76C433B4 for ; Fri, 30 Apr 2021 12:35:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E4A8D6142A for ; Fri, 30 Apr 2021 12:35:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231856AbhD3MgN (ORCPT ); Fri, 30 Apr 2021 08:36:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230020AbhD3MgM (ORCPT ); Fri, 30 Apr 2021 08:36:12 -0400 Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [IPv6:2a00:1450:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C01DC06138D for ; Fri, 30 Apr 2021 05:35:23 -0700 (PDT) Received: by mail-ej1-x629.google.com with SMTP id zg3so23399439ejb.8 for ; Fri, 30 Apr 2021 05:35:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sartura-hr.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=EFs7L5e2ICQbQU3zEtC2UFHPBcpNTWgH/d2niDhfdDA=; b=qG3u5EKd3EYArbSxfgXycYhJUwLsuX679AjHs+5XsDAsvr6Vqu+QZdiweWYTUV/SUp n/ti64M+rZfKLgt7lFLdaxJGDIkcNe4k3UxlfHBetmc4K1QYOa93XsHmhLb+mPFwJ2ck hsFqMenR9of1JAR7FpY18XoEzHCljmNCNKO4ucxxSdHLCq9V8ZnJSu6qd3Z/pqw9TGOK ev3t4piRFQqx1uzhFqYHptpGcCHyVFbDtireqvdBoBW2t5DaKQjCt3dLlvHNTWNtp5bv 4AyHp7vNqbGNFeqfxJtxVaaHaOoSYbUipmfO8w3p4hlXI1D60VpfJp32Yl0a6kDL+gtv inKw== 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:mime-version :content-transfer-encoding; bh=EFs7L5e2ICQbQU3zEtC2UFHPBcpNTWgH/d2niDhfdDA=; b=TnhkM/ezRysymlNezNDI1LBfj5LVX4ecq+TDCcCDGSuT20n/hJucn6x6HWtEKoaozw pS9TQcAa+WVlQrOQqqT8UO4P++qW3ffZrP+qGkepoEZCxc/ue7UHzSJ6IsoI5UkGCGkD GqweInIb+lPicWpRGd14S6XEpsPm3VrPi8ZUiKy68f4IoCSlWAlg11gSQ4zx2balSj8X oV6GXVSLMCdzAUZAd+YrLnbKANV7Bdlx16zI5v7nezgTwZ8xtXImZGd49hjmduL5OO// 3SwEco3lT8RCLzx7JpVWjb+zl+Ga93YSPgbY/QZoBKgOQTkUiI3OljcuOWq6u6RU1bWa K2DQ== X-Gm-Message-State: AOAM532khRFGZjubVrp3853zl795oOygLOg/aznLpgR7EdP6k/X9Tk5c bLVuzhX2GiyxQsRoUcp2xqvUQQ== X-Google-Smtp-Source: ABdhPJxp7LwL0cFAMV0aJSYBcj3ZbLngIAwieRg6R3F+waTsfcY0hjwoD8vTJt5PnnWArMrsntnGkw== X-Received: by 2002:a17:906:3f88:: with SMTP id b8mr4195085ejj.36.1619786121639; Fri, 30 Apr 2021 05:35:21 -0700 (PDT) Received: from localhost.localdomain (dh207-97-15.xnet.hr. [88.207.97.15]) by smtp.googlemail.com with ESMTPSA id d15sm1822988ejj.42.2021.04.30.05.35.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Apr 2021 05:35:21 -0700 (PDT) From: Robert Marko To: lee.jones@linaro.org, robh+dt@kernel.org, linus.walleij@linaro.org, bgolaszewski@baylibre.com, jdelvare@suse.com, linux@roeck-us.net, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, linux-hwmon@vger.kernel.org Cc: luka.perkov@sartura.hr, jmp@epiphyte.org, pmenzel@molgen.mpg.de, buczek@molgen.mpg.de, Robert Marko Subject: [PATCH 1/6] mfd: Add Delta TN48M CPLD driver Date: Fri, 30 Apr 2021 14:35:06 +0200 Message-Id: <20210430123511.116057-1-robert.marko@sartura.hr> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Delta TN48M switches have a Lattice CPLD that serves multiple purposes including being a GPIO expander. So lets add the MFD core driver for it. Signed-off-by: Robert Marko Reported-by: kernel test robot --- drivers/mfd/Kconfig | 13 +++ drivers/mfd/Makefile | 1 + drivers/mfd/tn48m-cpld.c | 181 ++++++++++++++++++++++++++++++++++++++ include/linux/mfd/tn48m.h | 30 +++++++ 4 files changed, 225 insertions(+) create mode 100644 drivers/mfd/tn48m-cpld.c create mode 100644 include/linux/mfd/tn48m.h diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig index b74efa469e90..809041f98d71 100644 --- a/drivers/mfd/Kconfig +++ b/drivers/mfd/Kconfig @@ -297,6 +297,19 @@ config MFD_ASIC3 This driver supports the ASIC3 multifunction chip found on many PDAs (mainly iPAQ and HTC based ones) +config MFD_TN48M_CPLD + tristate "Delta Networks TN48M switch CPLD driver" + depends on I2C + select MFD_CORE + select REGMAP_I2C + help + Select this option to enable support for Delta Networks TN48M switch + CPLD. It consists of GPIO and hwmon drivers. + CPLD provides GPIOS-s for the SFP slots as well as power supply + related information. + Driver provides debugfs information about the board model as + well as hardware and CPLD revision information. + config PMIC_DA903X bool "Dialog Semiconductor DA9030/DA9034 PMIC Support" depends on I2C=y diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile index 834f5463af28..974663341f08 100644 --- a/drivers/mfd/Makefile +++ b/drivers/mfd/Makefile @@ -27,6 +27,7 @@ obj-$(CONFIG_MFD_TI_LP87565) += lp87565.o obj-$(CONFIG_MFD_DAVINCI_VOICECODEC) += davinci_voicecodec.o obj-$(CONFIG_MFD_DM355EVM_MSP) += dm355evm_msp.o obj-$(CONFIG_MFD_TI_AM335X_TSCADC) += ti_am335x_tscadc.o +obj-$(CONFIG_MFD_TN48M_CPLD) += tn48m-cpld.o obj-$(CONFIG_MFD_STA2X11) += sta2x11-mfd.o obj-$(CONFIG_MFD_STMPE) += stmpe.o diff --git a/drivers/mfd/tn48m-cpld.c b/drivers/mfd/tn48m-cpld.c new file mode 100644 index 000000000000..b84510fb630a --- /dev/null +++ b/drivers/mfd/tn48m-cpld.c @@ -0,0 +1,181 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Delta TN48M CPLD parent driver + * + * Copyright 2020 Sartura Ltd + * + * Author: Robert Marko + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static const struct mfd_cell tn48m_cell[] = {}; + +static const struct regmap_config tn48m_regmap_config = { + .reg_bits = 8, + .val_bits = 8, + .max_register = 0x40, +}; + +static int hardware_version_show(struct seq_file *s, void *data) +{ + struct tn48m_data *priv = s->private; + unsigned int regval; + char *buf; + + regmap_read(priv->regmap, HARDWARE_VERSION_ID, ®val); + + switch (FIELD_GET(HARDWARE_VERSION_MASK, regval)) { + case HARDWARE_VERSION_EVT1: + buf = "EVT1"; + break; + case HARDWARE_VERSION_EVT2: + buf = "EVT2"; + break; + case HARDWARE_VERSION_DVT: + buf = "DVT"; + break; + case HARDWARE_VERSION_PVT: + buf = "PVT"; + break; + default: + buf = "Unknown"; + break; + } + + seq_printf(s, "%s\n", buf); + + return 0; +} + +DEFINE_SHOW_ATTRIBUTE(hardware_version); + +static int board_id_show(struct seq_file *s, void *data) +{ + struct tn48m_data *priv = s->private; + unsigned int regval; + char *buf; + + regmap_read(priv->regmap, BOARD_ID, ®val); + + switch (regval) { + case BOARD_ID_TN48M: + buf = "TN48M"; + break; + case BOARD_ID_TN48M_P: + buf = "TN48-P"; + break; + default: + buf = "Unknown"; + break; + } + + seq_printf(s, "%s\n", buf); + + return 0; +} + +DEFINE_SHOW_ATTRIBUTE(board_id); + +static int code_version_show(struct seq_file *s, void *data) +{ + struct tn48m_data *priv = s->private; + unsigned int regval; + + regmap_read(priv->regmap, CPLD_CODE_VERSION, ®val); + + seq_printf(s, "%d\n", regval); + + return 0; +} + +DEFINE_SHOW_ATTRIBUTE(code_version); + +static void tn48m_init_debugfs(struct tn48m_data *data) +{ + data->debugfs_dir = debugfs_create_dir(data->client->name, NULL); + + debugfs_create_file("hardware_version", + 0400, + data->debugfs_dir, + data, + &hardware_version_fops); + + debugfs_create_file("board_id", + 0400, + data->debugfs_dir, + data, + &board_id_fops); + + debugfs_create_file("code_version", + 0400, + data->debugfs_dir, + data, + &code_version_fops); +} + +static int tn48m_probe(struct i2c_client *client) +{ + struct tn48m_data *data; + int ret; + + data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL); + if (!data) + return -ENOMEM; + + data->client = client; + data->dev = &client->dev; + i2c_set_clientdata(client, data); + + data->regmap = devm_regmap_init_i2c(client, &tn48m_regmap_config); + if (IS_ERR(data->regmap)) { + dev_err(data->dev, "Failed to allocate regmap\n"); + return PTR_ERR(data->regmap); + } + + ret = devm_mfd_add_devices(data->dev, PLATFORM_DEVID_AUTO, tn48m_cell, + ARRAY_SIZE(tn48m_cell), NULL, 0, NULL); + if (ret) + dev_err(data->dev, "Failed to register sub-devices %d\n", ret); + + tn48m_init_debugfs(data); + + return ret; +} + +static int tn48m_remove(struct i2c_client *client) +{ + struct tn48m_data *data = i2c_get_clientdata(client); + + debugfs_remove_recursive(data->debugfs_dir); + + return 0; +} + +static const struct of_device_id tn48m_of_match[] = { + { .compatible = "delta,tn48m-cpld"}, + { } +}; +MODULE_DEVICE_TABLE(of, tn48m_of_match); + +static struct i2c_driver tn48m_driver = { + .driver = { + .name = "tn48m-cpld", + .of_match_table = tn48m_of_match, + }, + .probe_new = tn48m_probe, + .remove = tn48m_remove, +}; +module_i2c_driver(tn48m_driver); + +MODULE_AUTHOR("Robert Marko "); +MODULE_DESCRIPTION("Delta TN48M CPLD parent driver"); +MODULE_LICENSE("GPL"); diff --git a/include/linux/mfd/tn48m.h b/include/linux/mfd/tn48m.h new file mode 100644 index 000000000000..551c550efa54 --- /dev/null +++ b/include/linux/mfd/tn48m.h @@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright 2020 Sartura Ltd + */ + +#ifndef __TN48M_H__ +#define __TN48M_H__ + +#include +#include + +#define HARDWARE_VERSION_ID 0x0 +#define HARDWARE_VERSION_MASK GENMASK(3, 0) +#define HARDWARE_VERSION_EVT1 0 +#define HARDWARE_VERSION_EVT2 1 +#define HARDWARE_VERSION_DVT 2 +#define HARDWARE_VERSION_PVT 3 +#define BOARD_ID 0x1 +#define BOARD_ID_TN48M 0xa +#define BOARD_ID_TN48M_P 0xb +#define CPLD_CODE_VERSION 0x2 + +struct tn48m_data { + struct device *dev; + struct regmap *regmap; + struct i2c_client *client; + struct dentry *debugfs_dir; +}; + +#endif From patchwork Fri Apr 30 12:35:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Marko X-Patchwork-Id: 12233263 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=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable 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 7260EC43460 for ; Fri, 30 Apr 2021 12:35:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 484306145A for ; Fri, 30 Apr 2021 12:35:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232177AbhD3MgO (ORCPT ); Fri, 30 Apr 2021 08:36:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50142 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232064AbhD3MgN (ORCPT ); Fri, 30 Apr 2021 08:36:13 -0400 Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A5EDEC06138E for ; Fri, 30 Apr 2021 05:35:24 -0700 (PDT) Received: by mail-ej1-x634.google.com with SMTP id y7so6118410ejj.9 for ; Fri, 30 Apr 2021 05:35:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sartura-hr.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=k1xgkQIQAXFIiUoyaG4mWCe3d5IAOycQwU/Qso6LJ1Q=; b=mHj4oOVWHkjSWEixwh283R2+eii9GUPhAXQjx8b2ssCcBqe3rOTw0PN5aLBzzGLu7M 36unXq22romf3vSfJfm+iZhhiffE+0yY6VYia5/cTvbq5GFsLrjZNmcNWUYkTE0m3Upc Ptd9An7vCjHFAKWeWZ1hrUjAOVEDobeFmzMfhGt4Uf02xwYmdBZVl/vt55CUiQpGbR6C e8gaNKzcnUqxy9wYsqbOLf+LBQDS3zHcPR3RIYbqkKb3GfmrZ6Xsv4OHQ2+cRX9H4lGl GuCIvhR/74RX64gcvOURLP9vAc5157kmDUBEG6nm7Vt5FEnAinFDqw/PgLEeHttyBJfR Atgw== 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=k1xgkQIQAXFIiUoyaG4mWCe3d5IAOycQwU/Qso6LJ1Q=; b=i8rdKdv1pZIUw69EhEzRvNvdHTZQadJOeYSNrAqs/qnO4xIDyckqLGNI+XNOEHczXy 8+DRyDDSjAumEe9XJ4QJ1A8h4aHQmJc/XWcTPk7GZV+MpTXJlsa6arXbRQ4v9f3xOPLi L+1FHi5j+WDxb4XVRXn7Br52/r6igqfjmMRdcaKq43lR34de4TCa539zyAXPY2pYlb1t 8ypFsc2DfpDjscCre9sBN2HqXdcRjyV0jk4YvhzevBQfTvbUiGzgtq18CIC9RTOemGQQ 7Mws54eOiAnamdCzBrtV2nvJscwsjP7+707CgCVwIXreHt3azVxvWDU5AXG4b5WYoAZX UY2g== X-Gm-Message-State: AOAM530wloEWiTe4+sGPl3Ics+kGsWnoNtoMGwI1p/YubfNdWuA/jz8a fdjGwAq/kLm+I/bsYWTlfJUE6taI+e+WqQ9FhqQ= X-Google-Smtp-Source: ABdhPJzY310x0/M6PR54dBF4kM3yoLIWCb2LRVDpaEmyWtp04drhNKX4L8OS+/jY30OiUs/NzjMLYg== X-Received: by 2002:a17:906:6044:: with SMTP id p4mr4221114ejj.82.1619786123449; Fri, 30 Apr 2021 05:35:23 -0700 (PDT) Received: from localhost.localdomain (dh207-97-15.xnet.hr. [88.207.97.15]) by smtp.googlemail.com with ESMTPSA id d15sm1822988ejj.42.2021.04.30.05.35.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Apr 2021 05:35:22 -0700 (PDT) From: Robert Marko To: lee.jones@linaro.org, robh+dt@kernel.org, linus.walleij@linaro.org, bgolaszewski@baylibre.com, jdelvare@suse.com, linux@roeck-us.net, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, linux-hwmon@vger.kernel.org Cc: luka.perkov@sartura.hr, jmp@epiphyte.org, pmenzel@molgen.mpg.de, buczek@molgen.mpg.de, Robert Marko Subject: [PATCH 2/6] dt-bindings: gpio: Add Delta TN48M CPLD GPIO bindings Date: Fri, 30 Apr 2021 14:35:07 +0200 Message-Id: <20210430123511.116057-2-robert.marko@sartura.hr> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210430123511.116057-1-robert.marko@sartura.hr> References: <20210430123511.116057-1-robert.marko@sartura.hr> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org CPLD inside of the Delta TN48M does not number GPIOs at all, so in order to ensure numbering lets use bindigs. Signed-off-by: Robert Marko --- include/dt-bindings/gpio/tn48m-gpio.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 include/dt-bindings/gpio/tn48m-gpio.h diff --git a/include/dt-bindings/gpio/tn48m-gpio.h b/include/dt-bindings/gpio/tn48m-gpio.h new file mode 100644 index 000000000000..4ece4826d746 --- /dev/null +++ b/include/dt-bindings/gpio/tn48m-gpio.h @@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * GPIO definitions for Delta TN48M CPLD GPIO driver + * + * Copyright 2020 Sartura Ltd + * + * Author: Robert Marko + */ + +#ifndef _DT_BINDINGS_TN48M_GPIO_H +#define _DT_BINDINGS_TN48M_GPIO_H + +#define SFP_TX_DISABLE_52 0 +#define SFP_TX_DISABLE_51 1 +#define SFP_TX_DISABLE_50 2 +#define SFP_TX_DISABLE_49 3 +#define SFP_PRESENT_52 4 +#define SFP_PRESENT_51 5 +#define SFP_PRESENT_50 6 +#define SFP_PRESENT_49 7 +#define SFP_LOS_52 8 +#define SFP_LOS_51 9 +#define SFP_LOS_50 10 +#define SFP_LOS_49 11 + +#endif /* _DT_BINDINGS_TN48M_GPIO_H */ From patchwork Fri Apr 30 12:35:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Marko X-Patchwork-Id: 12233265 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=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 B3B55C43603 for ; Fri, 30 Apr 2021 12:35:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 974536145A for ; Fri, 30 Apr 2021 12:35:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232224AbhD3MgP (ORCPT ); Fri, 30 Apr 2021 08:36:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232200AbhD3MgO (ORCPT ); Fri, 30 Apr 2021 08:36:14 -0400 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C14DC06138B for ; Fri, 30 Apr 2021 05:35:26 -0700 (PDT) Received: by mail-ed1-x52c.google.com with SMTP id y26so2800926eds.4 for ; Fri, 30 Apr 2021 05:35:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sartura-hr.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=i0cSCbcDHWG/8GaSaPh7T/5+VrTGI0FCz2o91j0PTnQ=; b=h3hpWtCxwdwT6lTCfhAxK3+Ql8i6N0Igt1R4A0SuVHRuIqBS9JWrX7dv87ptzXCw9j hV3EECstOGdU7Ue3xtbR5fdUG3b7deYCIR0fo2IhFotkqWtuhV50pb11AzvFgLWAlo59 MT/2PyU09yq159Fq4Zh+oonB76JhyFHhjJ8QIGPB92+pCfLu4S9JtGcpNLOCanOjWLhK slHB7JtuKOLoBjlzLnsr4HBAaH9fLFzgeLIDgcVNWG6VRPMOrrR2bSp6dgo4rMFGqCzl 1/W5xOSQ/Us4nB0fbdWrsOcqnk3ZDWGxKkJnaAmuOk1fvEIYCooQT71YYC58F6q77Y7s TE2A== 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=i0cSCbcDHWG/8GaSaPh7T/5+VrTGI0FCz2o91j0PTnQ=; b=YQvx0Xzouk+Gcu1e5ZuiejT65ZivFbfXz1JTzFnC4KQr9AwJop+ICGwjVM2IFGnk0M Qx3pQOBUQXIU6VOHS0EZzFWQ6sADPrOei+i5Q6PM0K2ByoZ3CepqVV+Pp5Vy5m0wC4eW quBIVXroasUZYR9Q0o+kCD0/VRyK31mYniSJKBhIROUxuLEkUjwsRZzSz16Z1pjXjgOu 7IybS/3DWdo/DM/AkZ3EiaHSadrLeHfVa2/z0Ah3M8L3+ngVQOmdN/fiENKCGpHGBHTl p74i2I+u5/y9NRI1eoZiILBidEfKyTgZibh9Xg7E8fvoggqzDJKejrZ/iefcRPCRoqj5 7Hdw== X-Gm-Message-State: AOAM530Nhxthfm+km6foqVuL56eTNbMW5+OaNb8QtueiP3eM9aJKoGxc 6E1isX5qdBTgHwt6pGZ7xYCIEA== X-Google-Smtp-Source: ABdhPJytqxGq0ddEG+C0dxahGrKQzDVHu5R9tF/X8QdWH3+ovV8Syn3VuMaxGGTS7Lf6fLtxLtjUWw== X-Received: by 2002:aa7:c7cc:: with SMTP id o12mr5720466eds.291.1619786125022; Fri, 30 Apr 2021 05:35:25 -0700 (PDT) Received: from localhost.localdomain (dh207-97-15.xnet.hr. [88.207.97.15]) by smtp.googlemail.com with ESMTPSA id d15sm1822988ejj.42.2021.04.30.05.35.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Apr 2021 05:35:24 -0700 (PDT) From: Robert Marko To: lee.jones@linaro.org, robh+dt@kernel.org, linus.walleij@linaro.org, bgolaszewski@baylibre.com, jdelvare@suse.com, linux@roeck-us.net, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, linux-hwmon@vger.kernel.org Cc: luka.perkov@sartura.hr, jmp@epiphyte.org, pmenzel@molgen.mpg.de, buczek@molgen.mpg.de, Robert Marko Subject: [PATCH 3/6] gpio: Add Delta TN48M CPLD GPIO driver Date: Fri, 30 Apr 2021 14:35:08 +0200 Message-Id: <20210430123511.116057-3-robert.marko@sartura.hr> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210430123511.116057-1-robert.marko@sartura.hr> References: <20210430123511.116057-1-robert.marko@sartura.hr> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Delta TN48M CPLD is used as a GPIO expander for the SFP GPIOs. It is a mix of input only and output only pins. Since there is no logical GPIO numbering arbitrary one is used along dt-bindings to make it humanly readable. Signed-off-by: Robert Marko --- drivers/gpio/Kconfig | 12 +++ drivers/gpio/Makefile | 1 + drivers/gpio/gpio-tn48m.c | 191 ++++++++++++++++++++++++++++++++++++++ drivers/mfd/tn48m-cpld.c | 6 +- include/linux/mfd/tn48m.h | 3 + 5 files changed, 212 insertions(+), 1 deletion(-) create mode 100644 drivers/gpio/gpio-tn48m.c diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig index e3607ec4c2e8..e17d4416786a 100644 --- a/drivers/gpio/Kconfig +++ b/drivers/gpio/Kconfig @@ -1310,6 +1310,18 @@ config GPIO_TIMBERDALE help Add support for the GPIO IP in the timberdale FPGA. +config GPIO_TN48M_CPLD + tristate "Delta Networks TN48M switch CPLD GPIO driver" + depends on MFD_TN48M_CPLD + depends on OF_GPIO + help + This enables support for the GPIOs found on the Delta + Networks TN48M switch CPLD. + They are used for inputs and outputs on the SFP slots. + + This driver can also be built as a module. If so, the + module will be called gpio-tn48m. + config GPIO_TPS65086 tristate "TI TPS65086 GPO" depends on MFD_TPS65086 diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile index c58a90a3c3b1..271fb806475e 100644 --- a/drivers/gpio/Makefile +++ b/drivers/gpio/Makefile @@ -145,6 +145,7 @@ obj-$(CONFIG_GPIO_TEGRA186) += gpio-tegra186.o obj-$(CONFIG_GPIO_TEGRA) += gpio-tegra.o obj-$(CONFIG_GPIO_THUNDERX) += gpio-thunderx.o obj-$(CONFIG_GPIO_TIMBERDALE) += gpio-timberdale.o +obj-$(CONFIG_GPIO_TN48M_CPLD) += gpio-tn48m.o obj-$(CONFIG_GPIO_TPIC2810) += gpio-tpic2810.o obj-$(CONFIG_GPIO_TPS65086) += gpio-tps65086.o obj-$(CONFIG_GPIO_TPS65218) += gpio-tps65218.o diff --git a/drivers/gpio/gpio-tn48m.c b/drivers/gpio/gpio-tn48m.c new file mode 100644 index 000000000000..4e859e4c339c --- /dev/null +++ b/drivers/gpio/gpio-tn48m.c @@ -0,0 +1,191 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Delta TN48M CPLD GPIO driver + * + * Copyright 2020 Sartura Ltd + * + * Author: Robert Marko + */ + +#include +#include +#include + +#include +#include + +struct tn48m_gpio { + struct gpio_chip chip; + struct tn48m_data *data; +}; + +static int tn48m_gpio_get_direction(struct gpio_chip *chip, + unsigned int offset) +{ + switch (offset) { + case SFP_TX_DISABLE_52: + case SFP_TX_DISABLE_51: + case SFP_TX_DISABLE_50: + case SFP_TX_DISABLE_49: + return GPIO_LINE_DIRECTION_OUT; + case SFP_PRESENT_52: + case SFP_PRESENT_51: + case SFP_PRESENT_50: + case SFP_PRESENT_49: + case SFP_LOS_52: + case SFP_LOS_51: + case SFP_LOS_50: + case SFP_LOS_49: + return GPIO_LINE_DIRECTION_IN; + default: + return -EINVAL; + } +} + +static int tn48m_gpio_get_reg(unsigned int offset) +{ + switch (offset) { + case SFP_TX_DISABLE_52: + case SFP_TX_DISABLE_51: + case SFP_TX_DISABLE_50: + case SFP_TX_DISABLE_49: + return SFP_TX_DISABLE; + case SFP_PRESENT_52: + case SFP_PRESENT_51: + case SFP_PRESENT_50: + case SFP_PRESENT_49: + return SFP_PRESENT; + case SFP_LOS_52: + case SFP_LOS_51: + case SFP_LOS_50: + case SFP_LOS_49: + return SFP_LOS; + default: + return -EINVAL; + } +} + +static int tn48m_gpio_get_mask(unsigned int offset) +{ + switch (offset) { + case SFP_TX_DISABLE_52: + case SFP_PRESENT_52: + case SFP_LOS_52: + return BIT(3); + case SFP_TX_DISABLE_51: + case SFP_PRESENT_51: + case SFP_LOS_51: + return BIT(2); + case SFP_TX_DISABLE_50: + case SFP_PRESENT_50: + case SFP_LOS_50: + return BIT(1); + case SFP_TX_DISABLE_49: + case SFP_PRESENT_49: + case SFP_LOS_49: + return BIT(0); + default: + return -EINVAL; + } +} + +static int tn48m_gpio_get(struct gpio_chip *chip, unsigned int offset) +{ + struct tn48m_gpio *gpio = gpiochip_get_data(chip); + unsigned int regval; + int ret; + + ret = regmap_read(gpio->data->regmap, + tn48m_gpio_get_reg(offset), + ®val); + if (ret < 0) + return ret; + + return regval & tn48m_gpio_get_mask(offset); +} + +static void tn48m_gpio_set(struct gpio_chip *chip, unsigned int offset, + int value) +{ + struct tn48m_gpio *gpio = gpiochip_get_data(chip); + + regmap_update_bits(gpio->data->regmap, + tn48m_gpio_get_reg(offset), + tn48m_gpio_get_mask(offset), + value ? tn48m_gpio_get_mask(offset) : 0); +} + +static int tn48m_gpio_direction_output(struct gpio_chip *chip, + unsigned int offset, int value) +{ + tn48m_gpio_set(chip, offset, value); + + return 0; +} + +/* + * Required for SFP as it calls gpiod_direction_input() + * and if its missing TX disable GPIO will print an + * error and not be controlled anymore. + */ +static int tn48m_gpio_direction_input(struct gpio_chip *chip, + unsigned int offset) +{ + return 0; +} + +static const struct gpio_chip tn48m_template_chip = { + .label = "tn48m-gpio", + .owner = THIS_MODULE, + .get_direction = tn48m_gpio_get_direction, + .direction_output = tn48m_gpio_direction_output, + .direction_input = tn48m_gpio_direction_input, + .get = tn48m_gpio_get, + .set = tn48m_gpio_set, + .base = -1, + .ngpio = 12, + .can_sleep = true, +}; + +static int tn48m_gpio_probe(struct platform_device *pdev) +{ + struct tn48m_gpio *gpio; + int ret; + + gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL); + if (!gpio) + return -ENOMEM; + + platform_set_drvdata(pdev, gpio); + + gpio->data = dev_get_drvdata(pdev->dev.parent); + gpio->chip = tn48m_template_chip; + gpio->chip.parent = gpio->data->dev; + + ret = devm_gpiochip_add_data(&pdev->dev, &gpio->chip, gpio); + if (ret < 0) { + dev_err(&pdev->dev, "Could not register gpiochip, %d\n", ret); + return ret; + } + + return 0; +} + +static const struct platform_device_id tn48m_gpio_id_table[] = { + { "delta,tn48m-gpio", }, + { } +}; +MODULE_DEVICE_TABLE(platform, tn48m_gpio_id_table); + +static struct platform_driver tn48m_gpio_driver = { + .driver = { + .name = "tn48m-gpio", + }, + .probe = tn48m_gpio_probe, + .id_table = tn48m_gpio_id_table, +}; +module_platform_driver(tn48m_gpio_driver); + +MODULE_AUTHOR("Robert Marko "); +MODULE_DESCRIPTION("Delta TN48M CPLD GPIO driver"); +MODULE_LICENSE("GPL"); diff --git a/drivers/mfd/tn48m-cpld.c b/drivers/mfd/tn48m-cpld.c index b84510fb630a..f22a15ddd22d 100644 --- a/drivers/mfd/tn48m-cpld.c +++ b/drivers/mfd/tn48m-cpld.c @@ -17,7 +17,11 @@ #include #include -static const struct mfd_cell tn48m_cell[] = {}; +static const struct mfd_cell tn48m_cell[] = { + { + .name = "delta,tn48m-gpio", + } +}; static const struct regmap_config tn48m_regmap_config = { .reg_bits = 8, diff --git a/include/linux/mfd/tn48m.h b/include/linux/mfd/tn48m.h index 551c550efa54..9cc2b04c8d69 100644 --- a/include/linux/mfd/tn48m.h +++ b/include/linux/mfd/tn48m.h @@ -19,6 +19,9 @@ #define BOARD_ID_TN48M 0xa #define BOARD_ID_TN48M_P 0xb #define CPLD_CODE_VERSION 0x2 +#define SFP_TX_DISABLE 0x31 +#define SFP_PRESENT 0x3a +#define SFP_LOS 0x40 struct tn48m_data { struct device *dev; From patchwork Fri Apr 30 12:35:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Marko X-Patchwork-Id: 12233267 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=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 ED98FC433B4 for ; Fri, 30 Apr 2021 12:35:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D320B6145A for ; Fri, 30 Apr 2021 12:35:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232308AbhD3MgV (ORCPT ); Fri, 30 Apr 2021 08:36:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232089AbhD3MgR (ORCPT ); Fri, 30 Apr 2021 08:36:17 -0400 Received: from mail-ed1-x544.google.com (mail-ed1-x544.google.com [IPv6:2a00:1450:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 181F8C06138D for ; Fri, 30 Apr 2021 05:35:28 -0700 (PDT) Received: by mail-ed1-x544.google.com with SMTP id g10so14484595edb.0 for ; Fri, 30 Apr 2021 05:35:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sartura-hr.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PPM6nNPsrjG/byTfy/KGfZqX+cnw8iNV1tv+faDfK+8=; b=CK1FBwDn7z+sU+N/bokoUYBF3+F3QP21ick2LXXMLwUzvByuMiR/2n3iE5b5KA1Ivo u/ZHCMD5SgquTZ5Y3zb3hGIZukDlXsNkaVjKTFA6QNApr0JJAsh5uwY2F8kOfhyybOz1 Dw9Iv1G1yilUSGNlqqHI5jaSsVnP7++64198PGGDdDzohevYnAQbRN2FFOei7L3gCaZF QOqwPa3NGDTBPjlNC0/Y4yv8DSd7sFCQzuhfqOIUMGY7CLTYQZCtN08cuseLcZIXD4Fd ACme/KCjuAbHdpC4db0uyIfuwO1EUX+aAZYkB2IS6NTk/dCDzFEfyQt/QtzMuNfR6zP2 Re2w== 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=PPM6nNPsrjG/byTfy/KGfZqX+cnw8iNV1tv+faDfK+8=; b=PaiQ2wqRDO6hRfxG8wdQXu3n5yhTWXokApiW+5WVbpsxxuhSzbtYaOCOx11yW8pljR 3ogBRES2VPfOgPYpmSdwvpD09pEfLmkns38y6lk0lvBixi4aW4Rnbo1G3lvvTjPYHR/q DVTQmVUzieA8nijkfd36YtkMvO/KfpHYgkqhoC5h5CF9ufkggABRI7+Dra7/qX6ib68r lw4MQb6mT3oCBXgx+1yK43UsBbugZHC9TZXtmHwr5c9JZXxX9cIcGwtBhKLt4Ve3j0tZ F7FrAaHR8yPI7jz52c8f/75pibaSuWoUnheiJFUfM1w6GmtyGLyCx6cJ9Uh6+O0DeW/+ OsCQ== X-Gm-Message-State: AOAM532GPA5ThW8tgbxYK4TjYr782nMIvvyKTRpyk7NfS++ci1fpAgwg BU+kBkAIG6+IzOg0L81gYS3iYA== X-Google-Smtp-Source: ABdhPJzQC0UT6ZaLyj8ZmvqfpHXYjIf2BHGZc8oEbMCim3eNmD2vNJZUL2tzwVP+MkNifabF473gJA== X-Received: by 2002:a50:eb45:: with SMTP id z5mr5712942edp.243.1619786126736; Fri, 30 Apr 2021 05:35:26 -0700 (PDT) Received: from localhost.localdomain (dh207-97-15.xnet.hr. [88.207.97.15]) by smtp.googlemail.com with ESMTPSA id d15sm1822988ejj.42.2021.04.30.05.35.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Apr 2021 05:35:26 -0700 (PDT) From: Robert Marko To: lee.jones@linaro.org, robh+dt@kernel.org, linus.walleij@linaro.org, bgolaszewski@baylibre.com, jdelvare@suse.com, linux@roeck-us.net, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, linux-hwmon@vger.kernel.org Cc: luka.perkov@sartura.hr, jmp@epiphyte.org, pmenzel@molgen.mpg.de, buczek@molgen.mpg.de, Robert Marko Subject: [PATCH 4/6] hwmon: Add Delta TN48M CPLD HWMON driver Date: Fri, 30 Apr 2021 14:35:09 +0200 Message-Id: <20210430123511.116057-4-robert.marko@sartura.hr> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210430123511.116057-1-robert.marko@sartura.hr> References: <20210430123511.116057-1-robert.marko@sartura.hr> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Delta TN48M has a CPLD that also monitors the power supply statuses. These are useful to be presented to the users, so lets add a driver for HWMON part of the CPLD. Signed-off-by: Robert Marko --- drivers/hwmon/Kconfig | 10 +++ drivers/hwmon/Makefile | 1 + drivers/hwmon/tn48m-hwmon.c | 148 ++++++++++++++++++++++++++++++++++++ drivers/mfd/tn48m-cpld.c | 3 + include/linux/mfd/tn48m.h | 1 + 5 files changed, 163 insertions(+) create mode 100644 drivers/hwmon/tn48m-hwmon.c diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig index 54f04e61fb83..89271dfeb775 100644 --- a/drivers/hwmon/Kconfig +++ b/drivers/hwmon/Kconfig @@ -1924,6 +1924,16 @@ config SENSORS_TMP513 This driver can also be built as a module. If so, the module will be called tmp513. +config SENSORS_TN48M + tristate "Delta Networks TN48M switch CPLD HWMON driver" + depends on MFD_TN48M_CPLD + help + If you say yes here you get support for Delta Networks TN48M + CPLD. + + This driver can also be built as a module. If so, the module + will be called tn48m-hwmon. + config SENSORS_VEXPRESS tristate "Versatile Express" depends on VEXPRESS_CONFIG diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile index fe38e8a5c979..22e470057ffe 100644 --- a/drivers/hwmon/Makefile +++ b/drivers/hwmon/Makefile @@ -187,6 +187,7 @@ obj-$(CONFIG_SENSORS_TMP108) += tmp108.o obj-$(CONFIG_SENSORS_TMP401) += tmp401.o obj-$(CONFIG_SENSORS_TMP421) += tmp421.o obj-$(CONFIG_SENSORS_TMP513) += tmp513.o +obj-$(CONFIG_SENSORS_TN48M) += tn48m-hwmon.o obj-$(CONFIG_SENSORS_VEXPRESS) += vexpress-hwmon.o obj-$(CONFIG_SENSORS_VIA_CPUTEMP)+= via-cputemp.o obj-$(CONFIG_SENSORS_VIA686A) += via686a.o diff --git a/drivers/hwmon/tn48m-hwmon.c b/drivers/hwmon/tn48m-hwmon.c new file mode 100644 index 000000000000..80fd18d74f1d --- /dev/null +++ b/drivers/hwmon/tn48m-hwmon.c @@ -0,0 +1,148 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Delta TN48M CPLD HWMON driver + * + * Copyright 2020 Sartura Ltd + * + * Author: Robert Marko + */ + +#include +#include +#include +#include +#include +#include +#include + +#include + +#define PSU1_PRESENT_MASK BIT(0) +#define PSU2_PRESENT_MASK BIT(1) +#define PSU1_POWERGOOD_MASK BIT(2) +#define PSU2_POWERGOOD_MASK BIT(3) +#define PSU1_ALERT_MASK BIT(4) +#define PSU2_ALERT_MASK BIT(5) + +static int board_id_get(struct tn48m_data *data) +{ + unsigned int regval; + + regmap_read(data->regmap, BOARD_ID, ®val); + + switch (regval) { + case BOARD_ID_TN48M: + return BOARD_ID_TN48M; + case BOARD_ID_TN48M_P: + return BOARD_ID_TN48M_P; + default: + return -EINVAL; + } +} + +static ssize_t psu_present_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct sensor_device_attribute_2 *attr2 = to_sensor_dev_attr_2(attr); + struct tn48m_data *data = dev_get_drvdata(dev); + unsigned int regval, status; + + if (board_id_get(data) == BOARD_ID_TN48M_P) { + regmap_read(data->regmap, attr2->nr, ®val); + + if (attr2->index == 1) + status = !FIELD_GET(PSU1_PRESENT_MASK, regval); + else + status = !FIELD_GET(PSU2_PRESENT_MASK, regval); + } else + status = 0; + + return sprintf(buf, "%d\n", status); +} + +static ssize_t psu_pg_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct sensor_device_attribute_2 *attr2 = to_sensor_dev_attr_2(attr); + struct tn48m_data *data = dev_get_drvdata(dev); + unsigned int regval, status; + + regmap_read(data->regmap, attr2->nr, ®val); + + if (attr2->index == 1) + status = FIELD_GET(PSU1_POWERGOOD_MASK, regval); + else + status = FIELD_GET(PSU2_POWERGOOD_MASK, regval); + + return sprintf(buf, "%d\n", status); +} + +static ssize_t psu_alert_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct sensor_device_attribute_2 *attr2 = to_sensor_dev_attr_2(attr); + struct tn48m_data *data = dev_get_drvdata(dev); + unsigned int regval, status; + + if (board_id_get(data) == BOARD_ID_TN48M_P) { + regmap_read(data->regmap, attr2->nr, ®val); + + if (attr2->index == 1) + status = !FIELD_GET(PSU1_ALERT_MASK, regval); + else + status = !FIELD_GET(PSU2_ALERT_MASK, regval); + } else + status = 0; + + return sprintf(buf, "%d\n", status); +} + +static SENSOR_DEVICE_ATTR_2_RO(psu1_present, psu_present, PSU_STATUS, 1); +static SENSOR_DEVICE_ATTR_2_RO(psu2_present, psu_present, PSU_STATUS, 2); +static SENSOR_DEVICE_ATTR_2_RO(psu1_pg, psu_pg, PSU_STATUS, 1); +static SENSOR_DEVICE_ATTR_2_RO(psu2_pg, psu_pg, PSU_STATUS, 2); +static SENSOR_DEVICE_ATTR_2_RO(psu1_alert, psu_alert, PSU_STATUS, 1); +static SENSOR_DEVICE_ATTR_2_RO(psu2_alert, psu_alert, PSU_STATUS, 2); + +static struct attribute *tn48m_hwmon_attrs[] = { + &sensor_dev_attr_psu1_present.dev_attr.attr, + &sensor_dev_attr_psu2_present.dev_attr.attr, + &sensor_dev_attr_psu1_pg.dev_attr.attr, + &sensor_dev_attr_psu2_pg.dev_attr.attr, + &sensor_dev_attr_psu1_alert.dev_attr.attr, + &sensor_dev_attr_psu2_alert.dev_attr.attr, + NULL +}; + +ATTRIBUTE_GROUPS(tn48m_hwmon); + +static int tn48m_hwmon_probe(struct platform_device *pdev) +{ + struct tn48m_data *data = dev_get_drvdata(pdev->dev.parent); + struct device *hwmon_dev; + + hwmon_dev = devm_hwmon_device_register_with_groups(&pdev->dev, + "tn48m_hwmon", + data, + tn48m_hwmon_groups); + return PTR_ERR_OR_ZERO(hwmon_dev); +} + +static const struct platform_device_id tn48m_hwmon_id_table[] = { + { "delta,tn48m-hwmon", }, + { } +}; +MODULE_DEVICE_TABLE(platform, tn48m_hwmon_id_table); + +static struct platform_driver tn48m_hwmon_driver = { + .driver = { + .name = "tn48m-hwmon", + }, + .probe = tn48m_hwmon_probe, + .id_table = tn48m_hwmon_id_table, +}; +module_platform_driver(tn48m_hwmon_driver); + +MODULE_AUTHOR("Robert Marko "); +MODULE_DESCRIPTION("Delta TN48M CPLD HWMON driver"); +MODULE_LICENSE("GPL"); diff --git a/drivers/mfd/tn48m-cpld.c b/drivers/mfd/tn48m-cpld.c index f22a15ddd22d..4d837aca01e7 100644 --- a/drivers/mfd/tn48m-cpld.c +++ b/drivers/mfd/tn48m-cpld.c @@ -20,6 +20,9 @@ static const struct mfd_cell tn48m_cell[] = { { .name = "delta,tn48m-gpio", + }, + { + .name = "delta,tn48m-hwmon", } }; diff --git a/include/linux/mfd/tn48m.h b/include/linux/mfd/tn48m.h index 9cc2b04c8d69..eb2cfc3a5db7 100644 --- a/include/linux/mfd/tn48m.h +++ b/include/linux/mfd/tn48m.h @@ -22,6 +22,7 @@ #define SFP_TX_DISABLE 0x31 #define SFP_PRESENT 0x3a #define SFP_LOS 0x40 +#define PSU_STATUS 0xa struct tn48m_data { struct device *dev; From patchwork Fri Apr 30 12:35:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Marko X-Patchwork-Id: 12233271 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=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable 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 81427C433B4 for ; Fri, 30 Apr 2021 12:35:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5AFEF61477 for ; Fri, 30 Apr 2021 12:35:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232380AbhD3Mgd (ORCPT ); Fri, 30 Apr 2021 08:36:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50178 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232364AbhD3MgY (ORCPT ); Fri, 30 Apr 2021 08:36:24 -0400 Received: from mail-ej1-x642.google.com (mail-ej1-x642.google.com [IPv6:2a00:1450:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B8325C061346 for ; Fri, 30 Apr 2021 05:35:29 -0700 (PDT) Received: by mail-ej1-x642.google.com with SMTP id l4so104959236ejc.10 for ; Fri, 30 Apr 2021 05:35:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sartura-hr.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=KDQBYbM7HXMZFTesh6PlprpTxhf7UowLSjGjy7RFSWo=; b=M1/4WFchbemJs63V5CScpuwlBM3mkoQqhLQSOm8P8AHZHAy9FM6TkIWpHkFKBk+sVs v7pagiPQLLoowSD2ax4Lzf6MV5CJASaDSgFCI9WDPrWNHt7UZZCimg7y8w+Cv96UHmb7 v6cleL0KaFz+m9K7rQpqN1fQ4/9/daoZ1o6kvQIh1HA5hwHqnkltCwJlKkAK1CsnCJ/1 9TupZDt1/Oinpo6EZPxUvsEkkpDXqCHUHuHhVgTdraJlb4Vfu9j8OKIfv6GNIRIOw81O EsobQ1l+yjZ7h+MijUsY2nCg/UHfjFBM7NSmi4cUEGwry1stZTg6ocPLFEhkjcqIoOpb 6wOA== 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=KDQBYbM7HXMZFTesh6PlprpTxhf7UowLSjGjy7RFSWo=; b=adzUktDHRWf2voQEPocARQ9GG0tYKZAQ6djIK+OurZbfleTlFZg++MHZxodH6N3ohS +D64TdwKOWQ3ze9U6aRT2Fh7KRxZGFnk5HHr8+d5Upo6zTQYb2T7jZf4w4ZYOi2DDJ6V iYcOl13gz7UeBFr6+EaFgthRe2nXPV3gCEh/qJzNXFEk1WPt2EXTJ9uAOkm/XoZEkAAe f4AXVtGLQZJlYKASiyh1lFQsxPvhR2v1+0HTj4Lw7q7UD6xqLflHV265T00irHukfQIN 2E7Bvh+Vv7XAMJLJ1dWGN1MMji/OL/U4eyexp3MKIVwIKO67mqVXwVGiLfV3UQBwS9F8 +DJg== X-Gm-Message-State: AOAM531pEYAHizoT3eO3b3HBESk+g0N/7OO7HPVc6owu9MnsoiNpypWY jCxNqLpt5YbtBD/vXnwALa56lQ== X-Google-Smtp-Source: ABdhPJzviriv9V3GeCgo9rSUitIUOcEjs2xNWPfe/AL43zNEkj1RGEP4jwP08JE9C/nhZIy07gRj8Q== X-Received: by 2002:a17:906:5d13:: with SMTP id g19mr4179389ejt.206.1619786128374; Fri, 30 Apr 2021 05:35:28 -0700 (PDT) Received: from localhost.localdomain (dh207-97-15.xnet.hr. [88.207.97.15]) by smtp.googlemail.com with ESMTPSA id d15sm1822988ejj.42.2021.04.30.05.35.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Apr 2021 05:35:28 -0700 (PDT) From: Robert Marko To: lee.jones@linaro.org, robh+dt@kernel.org, linus.walleij@linaro.org, bgolaszewski@baylibre.com, jdelvare@suse.com, linux@roeck-us.net, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, linux-hwmon@vger.kernel.org Cc: luka.perkov@sartura.hr, jmp@epiphyte.org, pmenzel@molgen.mpg.de, buczek@molgen.mpg.de, Robert Marko Subject: [PATCH 5/6] dt-bindings: mfd: Add Delta TN48M CPLD drivers bindings Date: Fri, 30 Apr 2021 14:35:10 +0200 Message-Id: <20210430123511.116057-5-robert.marko@sartura.hr> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210430123511.116057-1-robert.marko@sartura.hr> References: <20210430123511.116057-1-robert.marko@sartura.hr> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Add binding document for the Delta TN48M CPLD drivers. Signed-off-by: Robert Marko Reviewed-by: Rob Herring --- .../bindings/mfd/delta,tn48m-cpld.yaml | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 Documentation/devicetree/bindings/mfd/delta,tn48m-cpld.yaml diff --git a/Documentation/devicetree/bindings/mfd/delta,tn48m-cpld.yaml b/Documentation/devicetree/bindings/mfd/delta,tn48m-cpld.yaml new file mode 100644 index 000000000000..7d81943d3d27 --- /dev/null +++ b/Documentation/devicetree/bindings/mfd/delta,tn48m-cpld.yaml @@ -0,0 +1,59 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/mfd/delta,tn48m-cpld.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Delta Networks TN48M CPLD controller + +maintainers: + - Robert Marko + +description: | + Lattice CPLD onboard the TN48M switches is used for system + management. + + It provides information about the hardware model, revision, + PSU status etc. + + It is also being used as a GPIO expander for the SFP slots. + +properties: + compatible: + const: delta,tn48m-cpld + + reg: + description: + I2C device address. + maxItems: 1 + + gpio-controller: true + + "#gpio-cells": + const: 2 + description: + The first cell is the pin number and the second cell is used to specify + the gpio active state. + +required: + - compatible + - reg + - gpio-controller + - "#gpio-cells" + +additionalProperties: false + +examples: + - | + i2c { + #address-cells = <1>; + #size-cells = <0>; + + cpld@41 { + compatible = "delta,tn48m-cpld"; + reg = <0x41>; + + gpio-controller; + #gpio-cells = <2>; + }; + }; From patchwork Fri Apr 30 12:35:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Marko X-Patchwork-Id: 12233269 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=-21.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 9D94EC43460 for ; Fri, 30 Apr 2021 12:35:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 812D461477 for ; Fri, 30 Apr 2021 12:35:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232418AbhD3Mgc (ORCPT ); Fri, 30 Apr 2021 08:36:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230133AbhD3MgX (ORCPT ); Fri, 30 Apr 2021 08:36:23 -0400 Received: from mail-ej1-x643.google.com (mail-ej1-x643.google.com [IPv6:2a00:1450:4864:20::643]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3114FC06134D for ; Fri, 30 Apr 2021 05:35:31 -0700 (PDT) Received: by mail-ej1-x643.google.com with SMTP id l4so104959370ejc.10 for ; Fri, 30 Apr 2021 05:35:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sartura-hr.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=cLF6UjbQpAiSk+1C2cRPJjTl6Fxr5nN+XcLDFX38OUc=; b=xGmTOesTxL8g9FKL+MsqLAHEbz8FjAV+meUFhGiuUAZNOpO4VhDYCpnpM5baKZZ4yT DLNBm97Zsdsba4Fhcc6sJetAeNnW8gqYXy+PUzt93NeD3tkNdfm7e68mzGXCy9fqP4+D jQwXe9wS0xdCgcukD7CpPUvaLRezu44FKeLtwWgK99jegz3BwmCpPMXWLn5Z4l7vJJ9c m3MgKDZfENJvnY1gryDs0bNANjYtsEhGQqFPcWItwTeqYc71eeRqvXnPrO7rv6/zDug6 LhJIAE1NWkAP7pLfIXaCgEXkub1qT6301YSlytbQsXotlkjENoygk9NsDFTfxOqdx2Xh cI4w== 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=cLF6UjbQpAiSk+1C2cRPJjTl6Fxr5nN+XcLDFX38OUc=; b=kAFV2oTE1NuXlkKR4pKCSs0kuFeYBzZM3Su3spY2DB+kslcbYCxJbo8RhW7mDXD7tt IRMt2cJSYxUSoFXSzXpjUYfVRgH6MgibkDqDQFJ7qXL3jYPPCVqUTxS4G4GzGjWkwFgt 8DFsJa2ZK0nh2mGKJGjBDWNCHlucWDkzzGobW1YHbjp57DMdmZSQd9KMhpBAi7S4o3zd RIA/UJDLRoWrloNC0sOWsqhNALtB+RB6IXURSikO5Qa2T/FRKrz191726Wy6PMzUPc/Q LzSw+kd7YgTwxVwiVNJzoQxGrBOwIFk1VyWGaLbNcKMLzJplQ4RbEfzi7UdgPp1eyr1i 6ZDQ== X-Gm-Message-State: AOAM533HtjzRDVXnds6W0Jyy1+YzYN555Y2NonA3I3BbfGLZAq/RrgNC Abv+3O7K2larxOWaHqy/iKhEcQ== X-Google-Smtp-Source: ABdhPJwFg3XdDCuqkDBWAZNT1Y6uM9fsvwP/FCRzFDiREFeamN2RNu0EO4UoCJ8H64rkgg060yRFhg== X-Received: by 2002:a17:907:7216:: with SMTP id dr22mr4177146ejc.185.1619786129968; Fri, 30 Apr 2021 05:35:29 -0700 (PDT) Received: from localhost.localdomain (dh207-97-15.xnet.hr. [88.207.97.15]) by smtp.googlemail.com with ESMTPSA id d15sm1822988ejj.42.2021.04.30.05.35.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Apr 2021 05:35:29 -0700 (PDT) From: Robert Marko To: lee.jones@linaro.org, robh+dt@kernel.org, linus.walleij@linaro.org, bgolaszewski@baylibre.com, jdelvare@suse.com, linux@roeck-us.net, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, linux-hwmon@vger.kernel.org Cc: luka.perkov@sartura.hr, jmp@epiphyte.org, pmenzel@molgen.mpg.de, buczek@molgen.mpg.de, Robert Marko Subject: [PATCH 6/6] MAINTAINERS: Add Delta Networks TN48M CPLD drivers Date: Fri, 30 Apr 2021 14:35:11 +0200 Message-Id: <20210430123511.116057-6-robert.marko@sartura.hr> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210430123511.116057-1-robert.marko@sartura.hr> References: <20210430123511.116057-1-robert.marko@sartura.hr> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Add maintainers entry for the Delta Networks TN48M CPLD MFD drivers. Signed-off-by: Robert Marko --- MAINTAINERS | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 9450e052f1b1..7193624868c7 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -5096,6 +5096,16 @@ W: https://linuxtv.org T: git git://linuxtv.org/media_tree.git F: drivers/media/platform/sti/delta +DELTA NETWORKS TN48M CPLD DRIVERS +M: Robert Marko +S: Maintained +F: Documentation/devicetree/bindings/mfd/delta,tn48m-cpld.yaml +F: drivers/gpio/gpio-tn48m.c +F: drivers/hwmon/tn48m-hwmon.c +F: drivers/mfd/tn48m-cpld.c +F: include/dt-bindings/gpio/tn48m-gpio.h +F: include/linux/mfd/tn48m.h + DENALI NAND DRIVER L: linux-mtd@lists.infradead.org S: Orphan