The SMpro co-processor on Ampere Altra processor family is to monitor
and report various data included hwmon-related info, RAS errors, and
other miscellaneous information. The SMPro MFD driver intializes the
register map and instantiates all sub-devices. All the specifics will
be handled in the child drivers.
This patch set includes support for Ampere SMpro hwmon, errmon, and
misc as the child drivers. The hwmon driver supports accessing various
CPU sensors provided by the SMpro co-processor including temperature,
power, voltages, and current found on Ampere Altra processor family.
The errmon driver supports monitoring and reporting RAS-related errors.
The misc driver is to support reporting boot progress and other
miscellaneous information.
v6:
+ Introduced smpro-errmon, smpro-misc as smpro-mfd sub-device [Quan]
+ Comments for v5: https://lkml.org/lkml/2021/7/13/49
v5:
+ Introduced the smpro-mfd driver and drop the use of
simple-mfd-i2c driver to avoid DT node with no resource in child
device DT nodes [Rob]
+ Removed the use of reg DT property in child driver [Quan]
+ Validated ManufactureID when probing smpro-mfd drivers [Quan]
+ As child devices are instantiated by SMPro MFD driver, drop the
ManufacturerID checking in child driver, ie: smpro-hwmon [Quan]
+ Revised commit messages [Quan]
v4:
+ Revised commit message [Quan]
+ Fixed build issue found by kernel test robot [Guenter]
+ Returned regmap_read() error code [Guenter]
v3:
+ Supported list of compatible string [Rob]
+ Introduced reg property in DT to specify reg offset [Rob]
+ Updated description and other minor changes in yaml file [Rob]
+ Handled negative temperature value [Guenter]
+ Returned -ENODEV if Manufacturer ID is wrong [Guenter]
+ Refactored smpro_read_string() and smpro_temp_read() [Guenter]
+ Removed smpro_write() function [Guenter]
+ Added minor refactor changes [Quan]
v2:
+ Used 'struct of_device_id's .data attribute [Lee Jones]
+ Removed "virtual" sensors [Guenter]
+ Fixed typo "mili" to "milli", "nanoWatt" to "microWatt" [Guenter]
+ Reported SOC_TDP as "Socket TDP" using max attributes [Guenter]
+ Clarified "highest" meaning in documentation [Guenter]
+ Corrected return error code when host is turn off [Guenter]
+ Reported MEM HOT Threshold for all DIMMs as temp*_crit [Guenter]
+ Removed license info as SPDX-License-Identifier existed [Guenter]
+ Added is_visible() support [Guenter]
+ Used HWMON_CHANNEL_INFO() macro and LABEL attributes [Guenter]
+ Made is_valid_id() return boolean [Guenter]
+ Returned -EPROBE_DEFER when smpro reg inaccessible [Guenter]
+ Removed unnecessary error message when dev register fail [Guenter]
+ Removed Socket TDP sensor [Quan]
+ Changed "ampere,ac01-smpro" to "ampere,smpro" [Quan]
+ Included sensor type and channel in labels [Quan]
+ Refactorized code to fix checkpatch.pl --strict complaint [Quan]
Quan Nguyen (9):
dt-bindings: mfd: Add bindings for Ampere Altra SMPro MFD driver
mfd: smpro-mfd: Adds Ampere's Altra SMpro MFD driver
hwmon: smpro: Add Ampere's Altra smpro-hwmon driver
docs: hwmon: (smpro-hwmon) Add documentation
regmap: Introduces regmap lock helpers
misc: smpro-errmon: Add Ampere's SMpro error monitor driver
docs: misc-devices: (smpro-errmon) Add documentation
misc: smpro-misc: Add Ampere's Altra SMpro misc driver
docs: misc-devices: (smpro-misc) Add documentation
.../devicetree/bindings/mfd/ampere,smpro.yaml | 48 ++
Documentation/hwmon/index.rst | 1 +
Documentation/hwmon/smpro-hwmon.rst | 101 ++++
Documentation/misc-devices/index.rst | 2 +
Documentation/misc-devices/smpro-errmon.rst | 206 +++++++
Documentation/misc-devices/smpro-misc.rst | 82 +++
drivers/base/regmap/regmap.c | 12 +
drivers/hwmon/Kconfig | 8 +
drivers/hwmon/Makefile | 1 +
drivers/hwmon/smpro-hwmon.c | 463 ++++++++++++++
drivers/mfd/Kconfig | 12 +
drivers/mfd/Makefile | 1 +
drivers/mfd/smpro-mfd.c | 78 +++
drivers/misc/Kconfig | 14 +
drivers/misc/Makefile | 2 +
drivers/misc/smpro-errmon.c | 571 ++++++++++++++++++
drivers/misc/smpro-misc.c | 177 ++++++
include/linux/regmap.h | 2 +
18 files changed, 1781 insertions(+)
create mode 100644 Documentation/devicetree/bindings/mfd/ampere,smpro.yaml
create mode 100644 Documentation/hwmon/smpro-hwmon.rst
create mode 100644 Documentation/misc-devices/smpro-errmon.rst
create mode 100644 Documentation/misc-devices/smpro-misc.rst
create mode 100644 drivers/hwmon/smpro-hwmon.c
create mode 100644 drivers/mfd/smpro-mfd.c
create mode 100644 drivers/misc/smpro-errmon.c
create mode 100644 drivers/misc/smpro-misc.c
--
2.28.0
Adds device tree bindings for SMPro MFD driver found on the Mt.Jade
hardware reference platform with Ampere's Altra Processor family.
The SMpro co-processor on Ampere Altra processor family is to monitor
and report various data included hwmon-related info, RAS errors, and
other miscellaneous information.
Signed-off-by: Quan Nguyen <[email protected]>
Reviewed-by: Rob Herring <[email protected]>
---
Changes in v6:
+ None
Changes in v5:
+ Dropped ../bindings/hwmon/ampere,ac01-hwmon.yaml file [Quan]
+ Removed patternProperties section and child DT nodes in example
section [Quan]
+ Revised commit message [Quan]
Changes in v4:
+ Revised the commit message to clarify how the specific info will
be handled commented by Rob.
Changes in v3:
+ Supported list of compatible string [Rob]
+ Introduced reg property in DT to specify reg offset [Rob]
+ Updated description and other minor changes in yaml file [Rob]
Changes in v2:
+ Changed "ampere,ac01-smpro" to "ampere,smpro" [Quan]
.../devicetree/bindings/mfd/ampere,smpro.yaml | 48 +++++++++++++++++++
1 file changed, 48 insertions(+)
create mode 100644 Documentation/devicetree/bindings/mfd/ampere,smpro.yaml
diff --git a/Documentation/devicetree/bindings/mfd/ampere,smpro.yaml b/Documentation/devicetree/bindings/mfd/ampere,smpro.yaml
new file mode 100644
index 000000000000..c29d975c1bc3
--- /dev/null
+++ b/Documentation/devicetree/bindings/mfd/ampere,smpro.yaml
@@ -0,0 +1,48 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/mfd/ampere,smpro.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Ampere Altra SMPro firmware driver
+
+maintainers:
+ - Quan Nguyen <[email protected]>
+
+description: |
+ Ampere Altra SMPro firmware may contain different blocks like hardware
+ monitoring, error monitoring and other miscellaneous features.
+
+properties:
+ compatible:
+ enum:
+ - ampere,smpro
+
+ reg:
+ description:
+ I2C device address.
+ maxItems: 1
+
+ "#address-cells":
+ const: 1
+
+ "#size-cells":
+ const: 0
+
+required:
+ - compatible
+ - reg
+
+additionalProperties: false
+
+examples:
+ - |
+ i2c {
+ #address-cells = <1>;
+ #size-cells = <0>;
+
+ smpro@4f {
+ compatible = "ampere,smpro";
+ reg = <0x4f>;
+ };
+ };
--
2.28.0
Adds Multi-function devices driver for SMpro co-processor found on the
Mt.Jade hardware reference platform with Ampere's Altra processor family.
Signed-off-by: Quan Nguyen <[email protected]>
---
Changes in v6:
+ Update license part to reflect that this driver is clone from
simple-mfd-i2c driver [Quan]
Changes in v5:
+ Dropped the use of simple-mfd-i2c driver [Quan]
+ Introduced drivers/mfd/smpro-mfd.c driver to instantiate
sub-devices. This is to avoid DT nodes without resource issue [Quan]
+ Revised commit message [Quan]
Changes in v4:
+ Add "depends on I2C" to fix build issue found by kernel test
robot [Guenter]
Changes in v3:
+ None
Changes in v2:
+ Used 'struct of_device_id's .data attribute [Lee Jones]
drivers/mfd/Kconfig | 12 +++++++
drivers/mfd/Makefile | 1 +
drivers/mfd/smpro-mfd.c | 76 +++++++++++++++++++++++++++++++++++++++++
3 files changed, 89 insertions(+)
create mode 100644 drivers/mfd/smpro-mfd.c
diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index a21cbdf89477..a886da5018b1 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -77,6 +77,18 @@ config MFD_AS3711
help
Support for the AS3711 PMIC from AMS
+config MFD_SMPRO
+ tristate "Ampere Computing MFD SMpro core driver"
+ depends on I2C
+ select MFD_CORE
+ select REGMAP_I2C
+ help
+ Say yes here to enable SMpro driver support for Ampere's Altra
+ processor family.
+
+ Ampere's Altra SMpro exposes an I2C regmap interface that can
+ be accessed by child devices.
+
config MFD_AS3722
tristate "ams AS3722 Power Management IC"
select MFD_CORE
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index 4d53e951a92d..fbcd09dce5ce 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -267,6 +267,7 @@ obj-$(CONFIG_MFD_QCOM_PM8008) += qcom-pm8008.o
obj-$(CONFIG_SGI_MFD_IOC3) += ioc3.o
obj-$(CONFIG_MFD_SIMPLE_MFD_I2C) += simple-mfd-i2c.o
+obj-$(CONFIG_MFD_SMPRO) += smpro-mfd.o
obj-$(CONFIG_MFD_INTEL_M10_BMC) += intel-m10-bmc.o
obj-$(CONFIG_MFD_ATC260X) += atc260x-core.o
diff --git a/drivers/mfd/smpro-mfd.c b/drivers/mfd/smpro-mfd.c
new file mode 100644
index 000000000000..132d4e2dde12
--- /dev/null
+++ b/drivers/mfd/smpro-mfd.c
@@ -0,0 +1,76 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Ampere Altra Family SMPro MFD - I2C
+ *
+ * Copyright (c) 2021, Ampere Computing LLC
+ * Author: Quan Nguyen <[email protected]>
+ *
+ * Based on simple-mfd-i2c.c:
+ * Copyright (c) by Michael Walle <[email protected]>
+ */
+
+#include <linux/i2c.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/of_platform.h>
+#include <linux/mfd/core.h>
+#include <linux/regmap.h>
+
+/* Identification Registers */
+#define MANUFACTURER_ID_REG 0x02
+#define AMPERE_MANUFACTURER_ID 0xCD3A
+
+static const struct regmap_config simple_word_regmap_config = {
+ .reg_bits = 8,
+ .val_bits = 16,
+};
+
+static const struct mfd_cell smpro_devs[] = {
+ MFD_CELL_NAME("smpro-hwmon"),
+};
+
+static int smpro_mfd_probe(struct i2c_client *i2c)
+{
+ const struct regmap_config *config;
+ struct regmap *regmap;
+ unsigned int val;
+ int ret;
+
+ config = device_get_match_data(&i2c->dev);
+ if (!config)
+ config = &simple_word_regmap_config;
+
+ regmap = devm_regmap_init_i2c(i2c, config);
+ if (IS_ERR(regmap))
+ return PTR_ERR(regmap);
+
+ /* Check for valid ID */
+ ret = regmap_read(regmap, MANUFACTURER_ID_REG, &val);
+ if (ret)
+ return ret;
+
+ if (val != AMPERE_MANUFACTURER_ID)
+ return -ENODEV;
+
+ return devm_mfd_add_devices(&i2c->dev, PLATFORM_DEVID_AUTO,
+ smpro_devs, ARRAY_SIZE(smpro_devs), NULL, 0, NULL);
+}
+
+static const struct of_device_id smpro_mfd_of_match[] = {
+ { .compatible = "ampere,smpro", .data = &simple_word_regmap_config },
+ {}
+};
+MODULE_DEVICE_TABLE(of, smpro_mfd_of_match);
+
+static struct i2c_driver smpro_mfd_driver = {
+ .probe_new = smpro_mfd_probe,
+ .driver = {
+ .name = "smpro-mfd-i2c",
+ .of_match_table = smpro_mfd_of_match,
+ },
+};
+module_i2c_driver(smpro_mfd_driver);
+
+MODULE_AUTHOR("Quan Nguyen <[email protected]>");
+MODULE_DESCRIPTION("SMPRO MFD - I2C driver");
+MODULE_LICENSE("GPL v2");
--
2.28.0
This commit adds support for Ampere SMpro hwmon driver. This driver
supports accessing various CPU sensors provided by the SMpro co-processor
including temperature, power, voltages, and current.
Signed-off-by: Quan Nguyen <[email protected]>
Reviewed-by: Guenter Roeck <[email protected]>
---
Changes in v6:
+ None
Changes in v5:
+ Drop ManufacturerID checking when probe as it was checked during
smpro-mfd probing [Quan]
+ Drop the use of register offset [Quan]
+ Removed the use of compatible string as it is instantiated by
smpro-mfd driver [Quan]
+ Thanks Guenter for the Reviewed-by in last version, but it was
not added because there's some changes in this version. Really
appreciate if you could help again, thank you.
Changes in v4:
+ Returned regmap_read() error code [Guenter]
Changes in v3:
+ Handled negative temperature value [Guenter]
+ Returned -ENODEV if Manufacturer ID is wrong [Guenter]
+ Refactored smpro_read_string() and smpro_temp_read() [Guenter]
+ Removed smpro_write() function [Guenter]
+ Added minor refactor changes [Quan]
Changes in v2:
+ Removed "virtual" sensors [Guenter]
+ Reported SOC_TDP as "Socket TDP" using max attributes [Guenter]
+ Corrected return error code when host is turn off [Guenter]
+ Reported MEM HOT Threshold for all DIMMs as temp*_crit [Guenter]
+ Removed license info as SPDX-License-Identifier existed [Guenter]
+ Added is_visible() support [Guenter]
+ Used HWMON_CHANNEL_INFO() macro and LABEL attributes [Guenter]
+ Made is_valid_id() return boolean [Guenter]
+ Returned -EPROBE_DEFER when smpro reg inaccessible [Guenter]
+ Removed unnecessary error message when dev register fail [Guenter]
+ Removed Socket TDP sensor [Quan]
+ Included sensor type and channel in labels [Quan]
+ Refactorized code to fix checkpatch.pl --strict complaint [Quan]
drivers/hwmon/Kconfig | 8 +
drivers/hwmon/Makefile | 1 +
drivers/hwmon/smpro-hwmon.c | 463 ++++++++++++++++++++++++++++++++++++
3 files changed, 472 insertions(+)
create mode 100644 drivers/hwmon/smpro-hwmon.c
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index 8df25f1079ba..493e44577317 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -67,6 +67,14 @@ config SENSORS_ABITUGURU3
This driver can also be built as a module. If so, the module
will be called abituguru3.
+config SENSORS_SMPRO
+ tristate "Ampere's Altra SMpro hardware monitoring driver"
+ depends on MFD_SMPRO
+ help
+ If you say yes here you get support for the thermal, voltage,
+ current and power sensors of Ampere's Altra processor family SoC
+ with SMpro co-processor.
+
config SENSORS_AD7314
tristate "Analog Devices AD7314 and compatibles"
depends on SPI
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index 185f946d698b..0365015b8bae 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -181,6 +181,7 @@ obj-$(CONFIG_SENSORS_SHT4x) += sht4x.o
obj-$(CONFIG_SENSORS_SHTC1) += shtc1.o
obj-$(CONFIG_SENSORS_SIS5595) += sis5595.o
obj-$(CONFIG_SENSORS_SMM665) += smm665.o
+obj-$(CONFIG_SENSORS_SMPRO) += smpro-hwmon.o
obj-$(CONFIG_SENSORS_SMSC47B397)+= smsc47b397.o
obj-$(CONFIG_SENSORS_SMSC47M1) += smsc47m1.o
obj-$(CONFIG_SENSORS_SMSC47M192)+= smsc47m192.o
diff --git a/drivers/hwmon/smpro-hwmon.c b/drivers/hwmon/smpro-hwmon.c
new file mode 100644
index 000000000000..b01ceea33ddd
--- /dev/null
+++ b/drivers/hwmon/smpro-hwmon.c
@@ -0,0 +1,463 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Ampere Computing SoC's SMPro Hardware Monitoring Driver
+ *
+ * Copyright (c) 2021, Ampere Computing LLC
+ */
+#include <linux/bitfield.h>
+#include <linux/bitops.h>
+#include <linux/hwmon.h>
+#include <linux/hwmon-sysfs.h>
+#include <linux/kernel.h>
+#include <linux/mod_devicetable.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/property.h>
+#include <linux/regmap.h>
+
+/* Logical Power Sensor Registers */
+#define SOC_TEMP 0x10
+#define SOC_VRD_TEMP 0x11
+#define DIMM_VRD_TEMP 0x12
+#define CORE_VRD_TEMP 0x13
+#define CH0_DIMM_TEMP 0x14
+#define CH1_DIMM_TEMP 0x15
+#define CH2_DIMM_TEMP 0x16
+#define CH3_DIMM_TEMP 0x17
+#define CH4_DIMM_TEMP 0x18
+#define CH5_DIMM_TEMP 0x19
+#define CH6_DIMM_TEMP 0x1A
+#define CH7_DIMM_TEMP 0x1B
+#define RCA_VRD_TEMP 0x1C
+
+#define CORE_VRD_PWR 0x20
+#define SOC_PWR 0x21
+#define DIMM_VRD1_PWR 0x22
+#define DIMM_VRD2_PWR 0x23
+#define CORE_VRD_PWR_MW 0x26
+#define SOC_PWR_MW 0x27
+#define DIMM_VRD1_PWR_MW 0x28
+#define DIMM_VRD2_PWR_MW 0x29
+#define RCA_VRD_PWR 0x2A
+#define RCA_VRD_PWR_MW 0x2B
+
+#define MEM_HOT_THRESHOLD 0x32
+#define SOC_VR_HOT_THRESHOLD 0x33
+#define CORE_VRD_VOLT 0x34
+#define SOC_VRD_VOLT 0x35
+#define DIMM_VRD1_VOLT 0x36
+#define DIMM_VRD2_VOLT 0x37
+#define RCA_VRD_VOLT 0x38
+
+#define CORE_VRD_CURR 0x39
+#define SOC_VRD_CURR 0x3A
+#define DIMM_VRD1_CURR 0x3B
+#define DIMM_VRD2_CURR 0x3C
+#define RCA_VRD_CURR 0x3D
+
+struct smpro_hwmon {
+ struct regmap *regmap;
+};
+
+struct smpro_sensor {
+ const u8 reg;
+ const u8 reg_ext;
+ const char *label;
+};
+
+static const struct smpro_sensor temperature[] = {
+ {
+ .reg = SOC_TEMP,
+ .label = "temp1 SoC"
+ },
+ {
+ .reg = SOC_VRD_TEMP,
+ .reg_ext = SOC_VR_HOT_THRESHOLD,
+ .label = "temp2 SoC VRD"
+ },
+ {
+ .reg = DIMM_VRD_TEMP,
+ .label = "temp3 DIMM VRD"
+ },
+ {
+ .reg = CORE_VRD_TEMP,
+ .label = "temp4 CORE VRD"
+ },
+ {
+ .reg = CH0_DIMM_TEMP,
+ .reg_ext = MEM_HOT_THRESHOLD,
+ .label = "temp5 CH0 DIMM"
+ },
+ {
+ .reg = CH1_DIMM_TEMP,
+ .reg_ext = MEM_HOT_THRESHOLD,
+ .label = "temp6 CH1 DIMM"
+ },
+ {
+ .reg = CH2_DIMM_TEMP,
+ .reg_ext = MEM_HOT_THRESHOLD,
+ .label = "temp7 CH2 DIMM"
+ },
+ {
+ .reg = CH3_DIMM_TEMP,
+ .reg_ext = MEM_HOT_THRESHOLD,
+ .label = "temp8 CH3 DIMM"
+ },
+ {
+ .reg = CH4_DIMM_TEMP,
+ .reg_ext = MEM_HOT_THRESHOLD,
+ .label = "temp9 CH4 DIMM"
+ },
+ {
+ .reg = CH5_DIMM_TEMP,
+ .reg_ext = MEM_HOT_THRESHOLD,
+ .label = "temp10 CH5 DIMM"
+ },
+ {
+ .reg = CH6_DIMM_TEMP,
+ .reg_ext = MEM_HOT_THRESHOLD,
+ .label = "temp11 CH6 DIMM"
+ },
+ {
+ .reg = CH7_DIMM_TEMP,
+ .reg_ext = MEM_HOT_THRESHOLD,
+ .label = "temp12 CH7 DIMM"
+ },
+ {
+ .reg = RCA_VRD_TEMP,
+ .label = "temp13 RCA VRD"
+ },
+};
+
+static const struct smpro_sensor voltage[] = {
+ {
+ .reg = CORE_VRD_VOLT,
+ .label = "vout0 CORE VRD"
+ },
+ {
+ .reg = SOC_VRD_VOLT,
+ .label = "vout1 SoC VRD"
+ },
+ {
+ .reg = DIMM_VRD1_VOLT,
+ .label = "vout2 DIMM VRD1"
+ },
+ {
+ .reg = DIMM_VRD2_VOLT,
+ .label = "vout3 DIMM VRD2"
+ },
+ {
+ .reg = RCA_VRD_VOLT,
+ .label = "vout4 RCA VRD"
+ },
+};
+
+static const struct smpro_sensor curr_sensor[] = {
+ {
+ .reg = CORE_VRD_CURR,
+ .label = "iout1 CORE VRD"
+ },
+ {
+ .reg = SOC_VRD_CURR,
+ .label = "iout2 SoC VRD"
+ },
+ {
+ .reg = DIMM_VRD1_CURR,
+ .label = "iout3 DIMM VRD1"
+ },
+ {
+ .reg = DIMM_VRD2_CURR,
+ .label = "iout4 DIMM VRD2"
+ },
+ {
+ .reg = RCA_VRD_CURR,
+ .label = "iout5 RCA VRD"
+ },
+};
+
+static const struct smpro_sensor power[] = {
+ {
+ .reg = CORE_VRD_PWR,
+ .reg_ext = CORE_VRD_PWR_MW,
+ .label = "power1 CORE VRD"
+ },
+ {
+ .reg = SOC_PWR,
+ .reg_ext = SOC_PWR_MW,
+ .label = "power2 SoC"
+ },
+ {
+ .reg = DIMM_VRD1_PWR,
+ .reg_ext = DIMM_VRD1_PWR_MW,
+ .label = "power3 DIMM VRD1"
+ },
+ {
+ .reg = DIMM_VRD2_PWR,
+ .reg_ext = DIMM_VRD2_PWR_MW,
+ .label = "power4 DIMM VRD2"
+ },
+ {
+ .reg = RCA_VRD_PWR,
+ .reg_ext = RCA_VRD_PWR_MW,
+ .label = "power5 RCA VRD"
+ },
+};
+
+static int smpro_read_temp(struct device *dev, u32 attr, int channel, long *val)
+{
+ struct smpro_hwmon *hwmon = dev_get_drvdata(dev);
+ unsigned int value;
+ int ret;
+
+ switch (attr) {
+ case hwmon_temp_input:
+ ret = regmap_read(hwmon->regmap, temperature[channel].reg, &value);
+ if (ret)
+ return ret;
+ break;
+ case hwmon_temp_crit:
+ ret = regmap_read(hwmon->regmap, temperature[channel].reg_ext, &value);
+ if (ret)
+ return ret;
+ break;
+ default:
+ return -EOPNOTSUPP;
+ }
+
+ *val = sign_extend32(value, 8) * 1000;
+ return 0;
+}
+
+static int smpro_read_in(struct device *dev, u32 attr, int channel, long *val)
+{
+ struct smpro_hwmon *hwmon = dev_get_drvdata(dev);
+ unsigned int value;
+ int ret;
+
+ switch (attr) {
+ case hwmon_in_input:
+ ret = regmap_read(hwmon->regmap, voltage[channel].reg, &value);
+ if (ret < 0)
+ return ret;
+ /* 15-bit value in 1mV */
+ *val = value & 0x7fff;
+ return 0;
+ default:
+ return -EOPNOTSUPP;
+ }
+}
+
+static int smpro_read_curr(struct device *dev, u32 attr, int channel, long *val)
+{
+ struct smpro_hwmon *hwmon = dev_get_drvdata(dev);
+ unsigned int value;
+ int ret;
+
+ switch (attr) {
+ case hwmon_curr_input:
+ ret = regmap_read(hwmon->regmap, curr_sensor[channel].reg, &value);
+ if (ret < 0)
+ return ret;
+ /* Scale reported by the hardware is 1mA */
+ *val = value & 0x7fff;
+ return 0;
+ default:
+ return -EOPNOTSUPP;
+ }
+}
+
+static int smpro_read_power(struct device *dev, u32 attr, int channel, long *val_pwr)
+{
+ struct smpro_hwmon *hwmon = dev_get_drvdata(dev);
+ unsigned int val = 0, val_mw = 0;
+ int ret;
+
+ switch (attr) {
+ case hwmon_power_input:
+ ret = regmap_read(hwmon->regmap, power[channel].reg, &val);
+ if (ret)
+ return ret;
+
+ ret = regmap_read(hwmon->regmap, power[channel].reg_ext, &val_mw);
+ if (ret)
+ return ret;
+
+ *val_pwr = val * 1000000 + val_mw * 1000;
+ return 0;
+
+ default:
+ return -EOPNOTSUPP;
+ }
+}
+
+static int smpro_read(struct device *dev, enum hwmon_sensor_types type,
+ u32 attr, int channel, long *val)
+{
+ switch (type) {
+ case hwmon_temp:
+ return smpro_read_temp(dev, attr, channel, val);
+ case hwmon_in:
+ return smpro_read_in(dev, attr, channel, val);
+ case hwmon_power:
+ return smpro_read_power(dev, attr, channel, val);
+ case hwmon_curr:
+ return smpro_read_curr(dev, attr, channel, val);
+ default:
+ return -EOPNOTSUPP;
+ }
+}
+
+static int smpro_read_string(struct device *dev, enum hwmon_sensor_types type,
+ u32 attr, int channel, const char **str)
+{
+ switch (type) {
+ case hwmon_temp:
+ switch (attr) {
+ case hwmon_temp_label:
+ *str = temperature[channel].label;
+ return 0;
+ default:
+ break;
+ }
+ break;
+
+ case hwmon_in:
+ switch (attr) {
+ case hwmon_in_label:
+ *str = voltage[channel].label;
+ return 0;
+ default:
+ break;
+ }
+ break;
+
+ case hwmon_curr:
+ switch (attr) {
+ case hwmon_curr_label:
+ *str = curr_sensor[channel].label;
+ return 0;
+ default:
+ break;
+ }
+ break;
+
+ case hwmon_power:
+ switch (attr) {
+ case hwmon_power_label:
+ *str = power[channel].label;
+ return 0;
+ default:
+ break;
+ }
+ break;
+ default:
+ break;
+ }
+
+ return -EOPNOTSUPP;
+}
+
+static umode_t smpro_is_visible(const void *data, enum hwmon_sensor_types type,
+ u32 attr, int channel)
+{
+ const struct smpro_hwmon *hwmon = data;
+ unsigned int value;
+ int ret;
+
+ switch (type) {
+ case hwmon_temp:
+ switch (attr) {
+ case hwmon_temp_input:
+ case hwmon_temp_label:
+ case hwmon_temp_crit:
+ ret = regmap_read(hwmon->regmap, temperature[channel].reg, &value);
+ if (ret || value == 0xFFFF)
+ return 0;
+ break;
+ }
+ default:
+ break;
+ }
+
+ return 0444;
+}
+
+static const struct hwmon_channel_info *smpro_info[] = {
+ HWMON_CHANNEL_INFO(temp,
+ HWMON_T_INPUT | HWMON_T_LABEL,
+ HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_CRIT,
+ HWMON_T_INPUT | HWMON_T_LABEL,
+ HWMON_T_INPUT | HWMON_T_LABEL,
+ HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_CRIT,
+ HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_CRIT,
+ HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_CRIT,
+ HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_CRIT,
+ HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_CRIT,
+ HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_CRIT,
+ HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_CRIT,
+ HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_CRIT,
+ HWMON_T_INPUT | HWMON_T_LABEL),
+ HWMON_CHANNEL_INFO(in,
+ HWMON_I_INPUT | HWMON_I_LABEL,
+ HWMON_I_INPUT | HWMON_I_LABEL,
+ HWMON_I_INPUT | HWMON_I_LABEL,
+ HWMON_I_INPUT | HWMON_I_LABEL,
+ HWMON_I_INPUT | HWMON_I_LABEL),
+ HWMON_CHANNEL_INFO(power,
+ HWMON_P_INPUT | HWMON_P_LABEL,
+ HWMON_P_INPUT | HWMON_P_LABEL,
+ HWMON_P_INPUT | HWMON_P_LABEL,
+ HWMON_P_INPUT | HWMON_P_LABEL,
+ HWMON_P_INPUT | HWMON_P_LABEL),
+ HWMON_CHANNEL_INFO(curr,
+ HWMON_C_INPUT | HWMON_C_LABEL,
+ HWMON_C_INPUT | HWMON_C_LABEL,
+ HWMON_C_INPUT | HWMON_C_LABEL,
+ HWMON_C_INPUT | HWMON_C_LABEL,
+ HWMON_C_INPUT | HWMON_C_LABEL),
+ NULL
+};
+
+static const struct hwmon_ops smpro_hwmon_ops = {
+ .is_visible = smpro_is_visible,
+ .read = smpro_read,
+ .read_string = smpro_read_string,
+};
+
+static const struct hwmon_chip_info smpro_chip_info = {
+ .ops = &smpro_hwmon_ops,
+ .info = smpro_info,
+};
+
+static int smpro_hwmon_probe(struct platform_device *pdev)
+{
+ struct smpro_hwmon *hwmon;
+ struct device *hwmon_dev;
+
+ hwmon = devm_kzalloc(&pdev->dev, sizeof(struct smpro_hwmon), GFP_KERNEL);
+ if (!hwmon)
+ return -ENOMEM;
+
+ hwmon->regmap = dev_get_regmap(pdev->dev.parent, NULL);
+ if (!hwmon->regmap)
+ return -ENODEV;
+
+ hwmon_dev = devm_hwmon_device_register_with_info(&pdev->dev, "smpro_hwmon",
+ hwmon, &smpro_chip_info, NULL);
+
+ return PTR_ERR_OR_ZERO(hwmon_dev);
+}
+
+static struct platform_driver smpro_hwmon_driver = {
+ .probe = smpro_hwmon_probe,
+ .driver = {
+ .name = "smpro-hwmon",
+ },
+};
+
+module_platform_driver(smpro_hwmon_driver);
+
+MODULE_AUTHOR("Thu Nguyen <[email protected]>");
+MODULE_AUTHOR("Quan Nguyen <[email protected]>");
+MODULE_DESCRIPTION("Ampere Altra SMPro hwmon driver");
+MODULE_LICENSE("GPL v2");
--
2.28.0
Add documentation for the Ampere(R)'s Altra(R) SMpro hwmon driver.
Signed-off-by: Thu Nguyen <[email protected]>
Signed-off-by: Quan Nguyen <[email protected]>
Reviewed-by: Guenter Roeck <[email protected]>
---
Changes in v6:
+ None
Changes in v5:
+ None
Changes in v4:
+ None
Changes in v3:
+ None
Changes in v2:
+ Removed "virtual" sensors [Guenter]
+ Fixed typo "mili" to "milli", "nanoWatt" to "microWatt" [Guenter]
+ Reported SOC_TDP as "Socket TDP" using max attributes [Guenter]
+ Clarified "highest" meaning in documentation [Guenter]
+ Reported MEM HOT Threshold for all DIMMs as temp*_crit [Guenter]
+ Removed Socket TDP sensor [Quan]
+ Included sensor type and channel in labels [Quan]
Documentation/hwmon/index.rst | 1 +
Documentation/hwmon/smpro-hwmon.rst | 101 ++++++++++++++++++++++++++++
2 files changed, 102 insertions(+)
create mode 100644 Documentation/hwmon/smpro-hwmon.rst
diff --git a/Documentation/hwmon/index.rst b/Documentation/hwmon/index.rst
index df20022c741f..79d1b8023186 100644
--- a/Documentation/hwmon/index.rst
+++ b/Documentation/hwmon/index.rst
@@ -180,6 +180,7 @@ Hardware Monitoring Kernel Drivers
sis5595
sl28cpld
smm665
+ smpro-hwmon
smsc47b397
smsc47m192
smsc47m1
diff --git a/Documentation/hwmon/smpro-hwmon.rst b/Documentation/hwmon/smpro-hwmon.rst
new file mode 100644
index 000000000000..f978b1370e16
--- /dev/null
+++ b/Documentation/hwmon/smpro-hwmon.rst
@@ -0,0 +1,101 @@
+.. SPDX-License-Identifier: GPL-2.0-or-later
+
+Kernel driver Ampere(R)'s Altra(R) SMpro hwmon
+==============================================
+
+Supported chips:
+
+ * Ampere(R) Altra(R)
+
+ Prefix: 'smpro'
+
+ Reference: Altra SoC BMC Interface Specification
+
+Author: Thu Nguyen <[email protected]>
+
+Description
+-----------
+This driver supports hardware monitoring for Ampere(R) Altra(R) SoC's based on the
+SMpro co-processor (SMpro).
+The following sensor types are supported by the driver:
+
+ * temperature
+ * voltage
+ * current
+ * power
+
+The SMpro interface provides the registers to query the various sensors and
+their values which are then exported to userspace by this driver.
+
+Usage Notes
+-----------
+
+SMpro hwmon driver creates at least two sysfs files for each sensor.
+
+* File ``<sensor_type><idx>_label`` reports the sensor label.
+* File ``<sensor_type><idx>_input`` returns the sensor value.
+
+The sysfs files are allocated in the SMpro root fs folder.
+There is one root folder for each SMpro instance.
+
+When the SoC is turned off, the driver will fail to read registers
+and return -ENXIO.
+
+Sysfs entries
+-------------
+
+The following sysfs files are supported:
+
+* Ampere(R) Altra(R):
+
+============ ============= ====== ===============================================
+Name Unit Perm Description
+temp1_input milli Celsius RO SoC temperature
+temp2_input milli Celsius RO Max temperature reported among SoC VRDs
+temp2_crit milli Celsius RO SoC VRD HOT Threshold temperature
+temp3_input milli Celsius RO Max temperature reported among DIMM VRDs
+temp4_input milli Celsius RO Max temperature reported among Core VRDs
+temp5_input milli Celsius RO Temperature of DIMM0 on CH0
+temp5_crit milli Celsius RO MEM HOT Threshold for all DIMMs
+temp6_input milli Celsius RO Temperature of DIMM0 on CH1
+temp6_crit milli Celsius RO MEM HOT Threshold for all DIMMs
+temp7_input milli Celsius RO Temperature of DIMM0 on CH2
+temp7_crit milli Celsius RO MEM HOT Threshold for all DIMMs
+temp8_input milli Celsius RO Temperature of DIMM0 on CH3
+temp8_crit milli Celsius RO MEM HOT Threshold for all DIMMs
+temp9_input milli Celsius RO Temperature of DIMM0 on CH4
+temp9_crit milli Celsius RO MEM HOT Threshold for all DIMMs
+temp10_input milli Celsius RO Temperature of DIMM0 on CH5
+temp10_crit milli Celsius RO MEM HOT Threshold for all DIMMs
+temp11_input milli Celsius RO Temperature of DIMM0 on CH6
+temp11_crit milli Celsius RO MEM HOT Threshold for all DIMMs
+temp12_input milli Celsius RO Temperature of DIMM0 on CH7
+temp12_crit milli Celsius RO MEM HOT Threshold for all DIMMs
+temp13_input milli Celsius RO Max temperature reported among RCA VRDs
+in0_input milli Volts RO Core voltage
+in1_input milli Volts RO SoC voltage
+in2_input milli Volts RO DIMM VRD1 voltage
+in3_input milli Volts RO DIMM VRD2 voltage
+in4_input milli Volts RO RCA VRD voltage
+cur1_input milli Amperes RO Core VRD current
+cur2_input milli Amperes RO SoC VRD current
+cur3_input milli Amperes RO DIMM VRD1 current
+cur4_input milli Amperes RO DIMM VRD2 current
+cur5_input milli Amperes RO RCA VRD current
+power1_input micro Watts RO Core VRD power
+power2_input micro Watts RO SoC VRD power
+power3_input micro Watts RO DIMM VRD1 power
+power4_input micro Watts RO DIMM VRD2 power
+power5_input micro Watts RO RCA VRD power
+============ ============= ====== ===============================================
+
+Example::
+
+ # cat in0_input
+ 830
+ # cat temp1_input
+ 37000
+ # cat curr1_input
+ 9000
+ # cat power5_input
+ 19500000
--
2.28.0
This commit introduces regmap_acquire/release_lock() functions and makes
them available for drivers that need atomic access of regmap registers
Signed-off-by: Quan Nguyen <[email protected]>
---
Change in v6:
+ First introduced in v6 [Quan]
drivers/base/regmap/regmap.c | 12 ++++++++++++
include/linux/regmap.h | 2 ++
2 files changed, 14 insertions(+)
diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index 2d74f9f82aa9..36921309725b 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -87,6 +87,18 @@ bool regmap_check_range_table(struct regmap *map, unsigned int reg,
}
EXPORT_SYMBOL_GPL(regmap_check_range_table);
+void regmap_acquire_lock(struct regmap *map)
+{
+ map->lock(map->lock_arg);
+}
+EXPORT_SYMBOL_GPL(regmap_acquire_lock);
+
+void regmap_release_lock(struct regmap *map)
+{
+ map->unlock(map->lock_arg);
+}
+EXPORT_SYMBOL_GPL(regmap_release_lock);
+
bool regmap_writeable(struct regmap *map, unsigned int reg)
{
if (map->max_register && reg > map->max_register)
diff --git a/include/linux/regmap.h b/include/linux/regmap.h
index 22652e5fbc38..0ed12e6ad4fb 100644
--- a/include/linux/regmap.h
+++ b/include/linux/regmap.h
@@ -1194,6 +1194,8 @@ int regmap_async_complete(struct regmap *map);
bool regmap_can_raw_write(struct regmap *map);
size_t regmap_get_raw_read_max(struct regmap *map);
size_t regmap_get_raw_write_max(struct regmap *map);
+void regmap_acquire_lock(struct regmap *map);
+void regmap_release_lock(struct regmap *map);
int regcache_sync(struct regmap *map);
int regcache_sync_region(struct regmap *map, unsigned int min,
--
2.28.0
This commit adds Ampere's SMpro error monitor driver for monitoring
and reporting RAS-related errors as reported by SMpro co-processor
found on Ampere's Altra processor family.
Signed-off-by: Quan Nguyen <[email protected]>
---
Change in v6:
+ First introduced in v6 [Quan]
drivers/mfd/smpro-mfd.c | 1 +
drivers/misc/Kconfig | 7 +
drivers/misc/Makefile | 1 +
drivers/misc/smpro-errmon.c | 571 ++++++++++++++++++++++++++++++++++++
4 files changed, 580 insertions(+)
create mode 100644 drivers/misc/smpro-errmon.c
diff --git a/drivers/mfd/smpro-mfd.c b/drivers/mfd/smpro-mfd.c
index 132d4e2dde12..a7cd64bf9eaa 100644
--- a/drivers/mfd/smpro-mfd.c
+++ b/drivers/mfd/smpro-mfd.c
@@ -27,6 +27,7 @@ static const struct regmap_config simple_word_regmap_config = {
static const struct mfd_cell smpro_devs[] = {
MFD_CELL_NAME("smpro-hwmon"),
+ MFD_CELL_NAME("smpro-errmon"),
};
static int smpro_mfd_probe(struct i2c_client *i2c)
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index 0f5a49fc7c9e..0cbd8a2561a7 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -176,6 +176,13 @@ config SGI_XP
this feature will allow for direct communication between SSIs
based on a network adapter and DMA messaging.
+config SMPRO_ERRMON
+ tristate "Ampere Computing SMPro error monitor driver"
+ depends on MFD_SMPRO || COMPILE_TEST
+ help
+ If you say yes here you get support for error monitor function
+ provides by Ampere Computing's SoC with SMpro processor.
+
config CS5535_MFGPT
tristate "CS5535/CS5536 Geode Multi-Function General Purpose Timer (MFGPT) support"
depends on MFD_CS5535
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index a086197af544..8ec9961b941b 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -23,6 +23,7 @@ obj-$(CONFIG_ENCLOSURE_SERVICES) += enclosure.o
obj-$(CONFIG_KGDB_TESTS) += kgdbts.o
obj-$(CONFIG_SGI_XP) += sgi-xp/
obj-$(CONFIG_SGI_GRU) += sgi-gru/
+obj-$(CONFIG_SMPRO_ERRMON) += smpro-errmon.o
obj-$(CONFIG_CS5535_MFGPT) += cs5535-mfgpt.o
obj-$(CONFIG_GEHC_ACHC) += gehc-achc.o
obj-$(CONFIG_HP_ILO) += hpilo.o
diff --git a/drivers/misc/smpro-errmon.c b/drivers/misc/smpro-errmon.c
new file mode 100644
index 000000000000..d694ebb06977
--- /dev/null
+++ b/drivers/misc/smpro-errmon.c
@@ -0,0 +1,571 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Ampere Computing SoC's SMpro Error Monitoring Driver
+ *
+ * Copyright (c) 2021, Ampere Computing LLC
+ *
+ */
+
+#include <linux/i2c.h>
+#include <linux/mod_devicetable.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/regmap.h>
+
+/* GPI RAS Error Registers */
+#define GPI_RAS_ERR 0x7E
+
+/* Core and L2C Error Registers */
+#define CORE_CE_ERR_CNT 0x80
+#define CORE_CE_ERR_LEN 0x81
+#define CORE_CE_ERR_DATA 0x82
+#define CORE_UE_ERR_CNT 0x83
+#define CORE_UE_ERR_LEN 0x84
+#define CORE_UE_ERR_DATA 0x85
+
+/* Memory Error Registers */
+#define MEM_CE_ERR_CNT 0x90
+#define MEM_CE_ERR_LEN 0x91
+#define MEM_CE_ERR_DATA 0x92
+#define MEM_UE_ERR_CNT 0x93
+#define MEM_UE_ERR_LEN 0x94
+#define MEM_UE_ERR_DATA 0x95
+
+/* RAS Error/Warning Registers */
+#define ERR_SMPRO_TYPE 0xA0
+#define ERR_PMPRO_TYPE 0xA1
+#define ERR_SMPRO_INFO_LO 0xA2
+#define ERR_SMPRO_INFO_HI 0xA3
+#define ERR_SMPRO_DATA_LO 0xA4
+#define ERR_SMPRO_DATA_HI 0xA5
+#define WARN_SMPRO_INFO_LO 0xAA
+#define WARN_SMPRO_INFO_HI 0xAB
+#define ERR_PMPRO_INFO_LO 0xA6
+#define ERR_PMPRO_INFO_HI 0xA7
+#define ERR_PMPRO_DATA_LO 0xA8
+#define ERR_PMPRO_DATA_HI 0xA9
+#define WARN_PMPRO_INFO_LO 0xAC
+#define WARN_PMPRO_INFO_HI 0xAD
+
+/* PCIE Error Registers */
+#define PCIE_CE_ERR_CNT 0xC0
+#define PCIE_CE_ERR_LEN 0xC1
+#define PCIE_CE_ERR_DATA 0xC2
+#define PCIE_UE_ERR_CNT 0xC3
+#define PCIE_UE_ERR_LEN 0xC4
+#define PCIE_UE_ERR_DATA 0xC5
+
+/* Other Error Registers */
+#define OTHER_CE_ERR_CNT 0xD0
+#define OTHER_CE_ERR_LEN 0xD1
+#define OTHER_CE_ERR_DATA 0xD2
+#define OTHER_UE_ERR_CNT 0xD8
+#define OTHER_UE_ERR_LEN 0xD9
+#define OTHER_UE_ERR_DATA 0xDA
+
+/* Event Source Registers */
+#define EVENT_SRC1 0x62
+#define EVENT_SRC2 0x63
+
+/* Event Data Registers */
+#define VRD_WARN_FAULT_EVENT_DATA 0x78
+#define VRD_HOT_EVENT_DATA 0x79
+#define DIMM_HOT_EVENT_DATA 0x7A
+#define DIMM_2X_REFRESH_EVENT_DATA 0x96
+
+#define MAX_READ_BLOCK_LENGTH 48
+#define NUM_I2C_MESSAGES 2
+#define MAX_READ_ERROR 35
+#define MAX_MSG_LEN 128
+
+#define RAS_SMPRO_ERRS 0
+#define RAS_PMPRO_ERRS 1
+
+enum RAS_48BYTES_ERR_TYPES {
+ CORE_CE_ERRS,
+ CORE_UE_ERRS,
+ MEM_CE_ERRS,
+ MEM_UE_ERRS,
+ PCIE_CE_ERRS,
+ PCIE_UE_ERRS,
+ OTHER_CE_ERRS,
+ OTHER_UE_ERRS,
+ NUM_48BYTES_ERR_TYPE,
+};
+
+struct smpro_error_hdr {
+ u8 err_count; /* Number of the RAS errors */
+ u8 err_len; /* Number of data bytes */
+ u8 err_data; /* Start of 48-byte data */
+};
+
+/*
+ * Included Address of registers to get Count, Length of data and Data
+ * of the 48 bytes error data
+ */
+struct smpro_error_hdr smpro_error_table[NUM_48BYTES_ERR_TYPE] = {
+ {CORE_CE_ERR_CNT, CORE_CE_ERR_LEN, CORE_CE_ERR_DATA},
+ {CORE_UE_ERR_CNT, CORE_UE_ERR_LEN, CORE_UE_ERR_DATA},
+ {MEM_CE_ERR_CNT, MEM_CE_ERR_LEN, MEM_CE_ERR_DATA},
+ {MEM_UE_ERR_CNT, MEM_UE_ERR_LEN, MEM_UE_ERR_DATA},
+ {PCIE_CE_ERR_CNT, PCIE_CE_ERR_LEN, PCIE_CE_ERR_DATA},
+ {PCIE_UE_ERR_CNT, PCIE_UE_ERR_LEN, PCIE_UE_ERR_DATA},
+ {OTHER_CE_ERR_CNT, OTHER_CE_ERR_LEN, OTHER_CE_ERR_DATA},
+ {OTHER_UE_ERR_CNT, OTHER_UE_ERR_LEN, OTHER_UE_ERR_DATA},
+};
+
+/*
+ * List of SCP registers which are used to get
+ * one type of RAS Internal errors.
+ */
+struct smpro_int_error_hdr {
+ u8 err_type;
+ u8 err_info_low;
+ u8 err_info_high;
+ u8 err_data_high;
+ u8 err_data_low;
+ u8 warn_info_low;
+ u8 warn_info_high;
+};
+
+struct smpro_int_error_hdr list_smpro_int_error_hdr[2] = {
+ {
+ ERR_SMPRO_TYPE,
+ ERR_SMPRO_INFO_LO, ERR_SMPRO_INFO_HI,
+ ERR_SMPRO_DATA_LO, ERR_SMPRO_DATA_HI,
+ WARN_SMPRO_INFO_LO, WARN_SMPRO_INFO_HI
+ },
+ {
+ ERR_PMPRO_TYPE,
+ ERR_PMPRO_INFO_LO, ERR_PMPRO_INFO_HI,
+ ERR_PMPRO_DATA_LO, ERR_PMPRO_DATA_HI,
+ WARN_PMPRO_INFO_LO, WARN_PMPRO_INFO_HI
+ },
+};
+
+struct smpro_errmon {
+ struct regmap *regmap;
+};
+
+enum EVENT_TYPES {
+ VRD_WARN_FAULT_EVENTS,
+ VRD_HOT_EVENTS,
+ DIMM_HOT_EVENTS,
+ NUM_EVENTS_TYPE,
+};
+
+struct smpro_event_hdr {
+ u8 event_src; /* Source register of event type */
+ u8 event_data; /* Data register of event type */
+};
+
+/* Included Address of event source and data registers */
+struct smpro_event_hdr smpro_event_table[NUM_EVENTS_TYPE] = {
+ {EVENT_SRC1, VRD_WARN_FAULT_EVENT_DATA},
+ {EVENT_SRC1, VRD_HOT_EVENT_DATA},
+ {EVENT_SRC2, DIMM_HOT_EVENT_DATA}
+};
+
+static int read_i2c_block_data(struct i2c_client *client, u16 address, u16 length, u8 *data)
+{
+ unsigned char outbuf[MAX_READ_BLOCK_LENGTH];
+ unsigned char inbuf[2];
+ struct i2c_msg msgs[2];
+ ssize_t ret;
+
+ inbuf[0] = (address & 0xff);
+ inbuf[1] = length;
+
+ msgs[0].addr = client->addr;
+ msgs[0].flags = client->flags & I2C_M_TEN;
+ msgs[0].len = 2;
+ msgs[0].buf = inbuf;
+
+ msgs[1].addr = client->addr;
+ msgs[1].flags = (client->flags & I2C_M_TEN) | I2C_M_RD;
+ msgs[1].len = length;
+ msgs[1].buf = outbuf;
+
+ ret = i2c_transfer(client->adapter, msgs, NUM_I2C_MESSAGES);
+ if (ret < 0)
+ return ret;
+
+ if (ret != NUM_I2C_MESSAGES)
+ return -EIO;
+
+ memcpy(data, outbuf, length);
+
+ return length;
+}
+
+static int errmon_read_block(struct regmap *map, u16 address, u16 length, u8 *data)
+{
+ struct i2c_client *client = to_i2c_client(regmap_get_device(map));
+ int ret;
+
+ regmap_acquire_lock(map);
+
+ ret = read_i2c_block_data(client, address, length, data);
+
+ regmap_release_lock(map);
+
+ return ret;
+}
+
+static ssize_t smpro_event_data_read(struct device *dev,
+ struct device_attribute *da, char *buf,
+ int channel)
+{
+ struct smpro_errmon *errmon = dev_get_drvdata(dev);
+ unsigned char msg[MAX_MSG_LEN] = {'\0'};
+ struct smpro_event_hdr event_info;
+ s32 event_data = 0;
+ int ret;
+
+ *buf = 0;
+ if (channel >= NUM_EVENTS_TYPE)
+ goto done;
+
+ event_info = smpro_event_table[channel];
+ ret = regmap_read(errmon->regmap, event_info.event_data, &event_data);
+ if (ret)
+ goto done;
+
+ ret = scnprintf(msg, MAX_MSG_LEN, "%02x %04x\n", channel, event_data);
+ strncat(buf, msg, ret);
+done:
+ return strlen(buf);
+}
+
+static ssize_t smpro_error_data_read(struct device *dev, struct device_attribute *da,
+ char *buf, int channel)
+{
+ struct smpro_errmon *errmon = dev_get_drvdata(dev);
+ unsigned char err_data[MAX_READ_BLOCK_LENGTH];
+ unsigned char msg[MAX_MSG_LEN] = {'\0'};
+ struct smpro_error_hdr err_info;
+ s32 err_count = 1, err_length = 0;
+ u8 i = 0;
+ int len;
+ int ret;
+
+ *buf = 0;
+ if (channel >= NUM_48BYTES_ERR_TYPE)
+ goto done;
+
+ err_info = smpro_error_table[channel];
+
+ ret = regmap_read(errmon->regmap, err_info.err_count, &err_count);
+ if (ret || err_count <= 0)
+ goto done;
+
+ /* Bit 8 indentifies the overflow status of one error type */
+ if (err_count & BIT(8)) {
+ len = scnprintf(msg, MAX_MSG_LEN,
+ "%02x %02x %04x %08x %016llx %016llx %016llx %016llx %016llx\n",
+ 0xFF, 0xFF, 0, 0, 0LL, 0LL, 0LL, 0LL, 0LL);
+ strncat(buf, msg, len);
+ }
+
+ /* Error count is the low byte */
+ err_count = err_count & 0xff;
+
+ if (err_count > MAX_READ_ERROR)
+ err_count = MAX_READ_ERROR;
+
+ for (i = 0; i < err_count; i++) {
+ ret = regmap_read(errmon->regmap, err_info.err_len, &err_length);
+ if (ret || err_length <= 0)
+ break;
+
+ if (err_length > MAX_READ_BLOCK_LENGTH)
+ err_length = MAX_READ_BLOCK_LENGTH;
+
+ ret = errmon_read_block(errmon->regmap, err_info.err_data, err_length, err_data);
+ if (ret < 0)
+ break;
+ /*
+ * The output of Core/Memory/PCIe/Others UE/CE errors follows below format:
+ * <Error Type> <Error SubType> <Instance> <Error Status> \
+ * <Error Address> <Error Misc 0> <Error Misc 1> <Error Misc2> <Error Misc 3>
+ * Where:
+ * + Error Type: The hardwares cause the errors. (1 byte)
+ * + SubType: Sub type of error in the specified hardware error. (1 byte)
+ * + Instance: Combination of the socket, channel,
+ * slot cause the error. (2 bytes)
+ * + Error Status: Encode of error status. (4 bytes)
+ * + Error Address: The address in device causes the errors. (8 bytes)
+ * + Error Misc 0/1/2/3: Addition info about the errors. (8 bytes for each)
+ * Reference Altra SOC BMC Interface specification.
+ */
+ len = scnprintf(msg, MAX_MSG_LEN,
+ "%02x %02x %04x %08x %016llx %016llx %016llx %016llx %016llx\n",
+ err_data[0], err_data[1], *(u16 *)&err_data[2],
+ *(u32 *)&err_data[4], *(u64 *)&err_data[8],
+ *(u64 *)&err_data[16], *(u64 *)&err_data[24],
+ *(u64 *)&err_data[32], *(u64 *)&err_data[40]);
+
+ /* go to next error */
+ ret = regmap_write(errmon->regmap, err_info.err_count, 0x100);
+ if (ret)
+ break;
+
+ /* add error message to buffer */
+ strncat(buf, msg, len);
+ }
+done:
+ return strlen(buf);
+}
+
+static s32 smpro_internal_err_get_info(struct regmap *regmap, u8 addr, u8 addr1, u8 addr2, u8 addr3,
+ u8 subtype, char *buf)
+{
+ unsigned int ret_hi = 0, ret_lo = 0, data_lo = 0, data_hi = 0;
+ int ret;
+
+ ret = regmap_read(regmap, addr, &ret_lo);
+ if (ret)
+ return ret;
+
+ ret = regmap_read(regmap, addr1, &ret_hi);
+ if (ret)
+ return ret;
+
+ if (addr2 != 0xff) {
+ ret = regmap_read(regmap, addr2, &data_lo);
+ if (ret)
+ return ret;
+ ret = regmap_read(regmap, addr3, &data_hi);
+ if (ret)
+ return ret;
+ }
+ /*
+ * Output format:
+ * <errType> <image> <dir> <Location> <errorCode> <data>
+ * Where:
+ * + errType: SCP Error Type (3 bits)
+ * 1: Warning
+ * 2: Error
+ * 4: Error with data
+ * + image: SCP Image Code (8 bits)
+ * + dir: Direction (1 bit)
+ * 0: Enter
+ * 1: Exit
+ * + location: SCP Module Location Code (8 bits)
+ * + errorCode: SCP Error Code (16 bits)
+ * + data : Extensive data (32 bits)
+ * All bits are 0 when errType is warning or error.
+ */
+ return scnprintf(buf, MAX_MSG_LEN, "%01x %02x %01x %02x %04x %04x%04x\n",
+ subtype, (ret_hi & 0xf000) >> 12, (ret_hi & 0x0800) >> 11,
+ ret_hi & 0xff, ret_lo, data_hi, data_lo);
+}
+
+static ssize_t smpro_internal_err_read(struct device *dev, struct device_attribute *da,
+ char *buf, int channel)
+{
+ struct smpro_errmon *errmon = dev_get_drvdata(dev);
+ struct smpro_int_error_hdr err_info;
+ unsigned char msg[MAX_MSG_LEN] = {'\0'};
+ unsigned int err_type;
+ unsigned int value;
+ int ret = 0;
+
+ *buf = 0;
+ /* read error status */
+ ret = regmap_read(errmon->regmap, GPI_RAS_ERR, &value);
+ if (ret)
+ goto done;
+
+ if (!((channel == RAS_SMPRO_ERRS && (value & BIT(0))) ||
+ (channel == RAS_PMPRO_ERRS && (value & BIT(1)))))
+ goto done;
+
+ err_info = list_smpro_int_error_hdr[channel];
+ ret = regmap_read(errmon->regmap, err_info.err_type, &err_type);
+ if (ret)
+ goto done;
+
+ /* Warning type */
+ if (err_type & BIT(0)) {
+ ret = smpro_internal_err_get_info(errmon->regmap, err_info.warn_info_low,
+ err_info.warn_info_high, 0xff, 0xff, 1, msg);
+ if (ret < 0)
+ goto done;
+
+ strncat(buf, msg, ret);
+ }
+
+ /* Error with data type */
+ if (err_type & BIT(2)) {
+ ret = smpro_internal_err_get_info(errmon->regmap, err_info.err_info_low,
+ err_info.err_info_high, err_info.err_data_low,
+ err_info.err_data_high, 4, msg);
+ if (ret < 0)
+ goto done;
+
+ strncat(buf, msg, ret);
+ }
+ /* Error type */
+ else if (err_type & BIT(1)) {
+ ret = smpro_internal_err_get_info(errmon->regmap, err_info.err_info_low,
+ err_info.err_info_high, 0xff, 0xff, 2, msg);
+ if (ret < 0)
+ goto done;
+
+ strncat(buf, msg, ret);
+ }
+
+ /* clear the read errors */
+ regmap_write(errmon->regmap, err_info.err_type, err_type);
+
+done:
+ return strlen(buf);
+}
+
+static int errors_core_ce_show(struct device *dev, struct device_attribute *da, char *buf)
+{
+ return smpro_error_data_read(dev, da, buf, CORE_CE_ERRS);
+}
+static DEVICE_ATTR_RO(errors_core_ce);
+
+static int errors_core_ue_show(struct device *dev, struct device_attribute *da, char *buf)
+{
+ return smpro_error_data_read(dev, da, buf, CORE_UE_ERRS);
+}
+static DEVICE_ATTR_RO(errors_core_ue);
+
+static int errors_mem_ce_show(struct device *dev, struct device_attribute *da, char *buf)
+{
+ return smpro_error_data_read(dev, da, buf, MEM_CE_ERRS);
+}
+static DEVICE_ATTR_RO(errors_mem_ce);
+
+static int errors_mem_ue_show(struct device *dev, struct device_attribute *da, char *buf)
+{
+ return smpro_error_data_read(dev, da, buf, MEM_UE_ERRS);
+}
+static DEVICE_ATTR_RO(errors_mem_ue);
+
+static int errors_pcie_ce_show(struct device *dev, struct device_attribute *da, char *buf)
+{
+ return smpro_error_data_read(dev, da, buf, PCIE_CE_ERRS);
+}
+static DEVICE_ATTR_RO(errors_pcie_ce);
+
+static int errors_pcie_ue_show(struct device *dev, struct device_attribute *da, char *buf)
+{
+ return smpro_error_data_read(dev, da, buf, PCIE_UE_ERRS);
+}
+static DEVICE_ATTR_RO(errors_pcie_ue);
+
+static int errors_other_ce_show(struct device *dev, struct device_attribute *da, char *buf)
+{
+ return smpro_error_data_read(dev, da, buf, OTHER_CE_ERRS);
+}
+static DEVICE_ATTR_RO(errors_other_ce);
+
+static int errors_other_ue_show(struct device *dev, struct device_attribute *da, char *buf)
+{
+ return smpro_error_data_read(dev, da, buf, OTHER_UE_ERRS);
+}
+static DEVICE_ATTR_RO(errors_other_ue);
+
+static int errors_smpro_show(struct device *dev, struct device_attribute *da, char *buf)
+{
+ return smpro_internal_err_read(dev, da, buf, RAS_SMPRO_ERRS);
+}
+static DEVICE_ATTR_RO(errors_smpro);
+
+static int errors_pmpro_show(struct device *dev, struct device_attribute *da, char *buf)
+{
+ return smpro_internal_err_read(dev, da, buf, RAS_PMPRO_ERRS);
+}
+static DEVICE_ATTR_RO(errors_pmpro);
+
+static int event_vrd_warn_fault_show(struct device *dev, struct device_attribute *da, char *buf)
+{
+ return smpro_event_data_read(dev, da, buf, VRD_WARN_FAULT_EVENTS);
+}
+static DEVICE_ATTR_RO(event_vrd_warn_fault);
+
+static int event_vrd_hot_show(struct device *dev, struct device_attribute *da, char *buf)
+{
+ return smpro_event_data_read(dev, da, buf, VRD_HOT_EVENTS);
+}
+static DEVICE_ATTR_RO(event_vrd_hot);
+
+static int event_dimm_hot_show(struct device *dev, struct device_attribute *da, char *buf)
+{
+ return smpro_event_data_read(dev, da, buf, DIMM_HOT_EVENTS);
+}
+static DEVICE_ATTR_RO(event_dimm_hot);
+
+static struct attribute *smpro_errmon_attrs[] = {
+ &dev_attr_errors_core_ce.attr,
+ &dev_attr_errors_core_ue.attr,
+ &dev_attr_errors_mem_ce.attr,
+ &dev_attr_errors_mem_ue.attr,
+ &dev_attr_errors_pcie_ce.attr,
+ &dev_attr_errors_pcie_ue.attr,
+ &dev_attr_errors_other_ce.attr,
+ &dev_attr_errors_other_ue.attr,
+ &dev_attr_errors_smpro.attr,
+ &dev_attr_errors_pmpro.attr,
+ &dev_attr_event_vrd_warn_fault.attr,
+ &dev_attr_event_vrd_hot.attr,
+ &dev_attr_event_dimm_hot.attr,
+ NULL
+};
+
+static const struct attribute_group smpro_errmon_attr_group = {
+ .attrs = smpro_errmon_attrs
+};
+
+static int smpro_errmon_probe(struct platform_device *pdev)
+{
+ struct smpro_errmon *errmon;
+ int ret;
+
+ errmon = devm_kzalloc(&pdev->dev, sizeof(struct smpro_errmon), GFP_KERNEL);
+ if (!errmon)
+ return -ENOMEM;
+
+ platform_set_drvdata(pdev, errmon);
+
+ errmon->regmap = dev_get_regmap(pdev->dev.parent, NULL);
+ if (!errmon->regmap)
+ return -ENODEV;
+
+ ret = sysfs_create_group(&pdev->dev.kobj, &smpro_errmon_attr_group);
+ if (ret)
+ dev_err(&pdev->dev, "SMPro errmon sysfs registration failed\n");
+
+ return 0;
+}
+
+static int smpro_errmon_remove(struct platform_device *pdev)
+{
+ sysfs_remove_group(&pdev->dev.kobj, &smpro_errmon_attr_group);
+ pr_info("SMPro errmon sysfs entries removed");
+
+ return 0;
+}
+
+static struct platform_driver smpro_errmon_driver = {
+ .probe = smpro_errmon_probe,
+ .remove = smpro_errmon_remove,
+ .driver = {
+ .name = "smpro-errmon",
+ },
+};
+
+module_platform_driver(smpro_errmon_driver);
+
+MODULE_AUTHOR("Tung Nguyen <[email protected]>");
+MODULE_AUTHOR("Thinh Pham <[email protected]>");
+MODULE_AUTHOR("Hoang Nguyen <[email protected]>");
+MODULE_AUTHOR("Thu Nguyen <[email protected]>");
+MODULE_AUTHOR("Quan Nguyen <[email protected]>");
+MODULE_DESCRIPTION("Ampere Altra SMpro driver");
+MODULE_LICENSE("GPL");
--
2.28.0
Adds documentation for Ampere(R)'s Altra(R) SMpro errmon driver.
Signed-off-by: Thu Nguyen <[email protected]>
Signed-off-by: Quan Nguyen <[email protected]>
---
Change in v6:
+ First introduced in v6 [Quan]
Documentation/misc-devices/index.rst | 1 +
Documentation/misc-devices/smpro-errmon.rst | 206 ++++++++++++++++++++
2 files changed, 207 insertions(+)
create mode 100644 Documentation/misc-devices/smpro-errmon.rst
diff --git a/Documentation/misc-devices/index.rst b/Documentation/misc-devices/index.rst
index 30ac58f81901..7a6a6263cbab 100644
--- a/Documentation/misc-devices/index.rst
+++ b/Documentation/misc-devices/index.rst
@@ -26,6 +26,7 @@ fit into other categories.
lis3lv02d
max6875
pci-endpoint-test
+ smpro-errmon
spear-pcie-gadget
uacce
xilinx_sdfec
diff --git a/Documentation/misc-devices/smpro-errmon.rst b/Documentation/misc-devices/smpro-errmon.rst
new file mode 100644
index 000000000000..e05d19412c07
--- /dev/null
+++ b/Documentation/misc-devices/smpro-errmon.rst
@@ -0,0 +1,206 @@
+.. SPDX-License-Identifier: GPL-2.0-or-later
+
+Kernel driver Ampere(R)'s Altra(R) SMpro errmon
+===============================================
+
+Supported chips:
+
+ * Ampere(R) Altra(R)
+
+ Prefix: 'smpro'
+
+ Preference: Altra SoC BMC Interface Specification
+
+Author: Thu Nguyen <[email protected]>
+
+Description
+-----------
+
+This driver supports hardware monitoring for Ampere(R) Altra(R) SoC's based on the
+SMpro co-processor (SMpro).
+The following SoC alert/event types are supported by the errmon driver:
+
+* Core CE/UE errors
+* Memory CE/UE errors
+* PCIe CE/UE errors
+* Other CE/UE errors
+* Internal SMpro/PMpro errors
+* VRD hot
+* VRD warn/fault
+* DIMM Hot
+* DIMM 2x refresh rate
+
+The SMpro interface provides the registers to query the status of the SoC alerts/events
+and their data and export to userspace by this driver.
+
+Usage Notes
+-----------
+
+SMpro errmon driver creates the sysfs files for each host alert/event type.
+Example: ``errors_core_ce`` to get Core CE error type.
+
+To get a host alert/event type, the user will read the corresponding sysfs file.
+
+* If the alert/event is absented, the sysfs file returns empty.
+* If the alerts/events are presented, the existing alerts/events will be reported as the error lines.
+
+The format of the error lines is defended on the alert/event type.
+
+1) Type 1 for Core/Memory/PCIe/Other CE/UE alert types::
+
+ <Error Type> <Error SubType> <Instance> <Error Status> <Error Address> <Error Misc 0> <Error Misc 1> <Error Misc2> <Error Misc 3>
+
+ Where:
+ * Error Type: The hardwares cause the errors in format of two hex characters.
+ * SubType: Sub type of error in the specified hardware error in format of two hex characters.
+ * Instance: Combination of the socket, channel, slot cause the error in format of four hex characters.
+ * Error Status: Encode of error status in format of eight hex characters.
+ * Error Address: The address in device causes the errors in format of sixteen hex characters.
+ * Error Misc 0/1/2/3: Addition info about the errors. Each field is in format of sixteen hex characters.
+
+ Example:
+ # cat errors_other_ce
+ 0a 02 0000 000030e4 0000000000000080 0000020000000000 0000000000000000 0000000000000000 0000000000000000
+ 0a 01 0000 000030e4 0000000000000080 0000020000000000 0000000000000000 0000000000000000 0000000000000000
+
+ The size of the alert buffer for this error type is 8 alerts.
+ When the buffer is overflowed, the errmon driver will be added the overflowed alert line to sysfs output.
+
+ ff ff 0000 00000000 0000000000000080 0000000000000000 0000000000000000 0000000000000000 0000000000000000
+
+Below table defines the value of Error types, Sub Types, Sub component and instance:
+
+ ============ ========== ========= =============== ================
+ Error Group Error Type Sub type Sub component Instance
+ CPM 0 0 Snoop-Logic CPM #
+ CPM 0 2 Armv8 Core 1 CPM #
+ MCU 1 1 ERR1 MCU # | SLOT << 11
+ MCU 1 2 ERR2 MCU # | SLOT << 11
+ MCU 1 3 ERR3 MCU #
+ MCU 1 4 ERR4 MCU #
+ MCU 1 5 ERR5 MCU #
+ MCU 1 6 ERR6 MCU #
+ MCU 1 7 Link Error MCU #
+ Mesh 2 0 Cross Point X | (Y << 5) | NS <<11
+ Mesh 2 1 Home Node(IO) X | (Y << 5) | NS <<11
+ Mesh 2 2 Home Node(Mem) X | (Y << 5) | NS <<11 | device<<12
+ Mesh 2 4 CCIX Node X | (Y << 5) | NS <<11
+ 2P Link 3 0 N/A Altra 2P Link #
+ GIC 5 0 ERR0 0
+ GIC 5 1 ERR1 0
+ GIC 5 2 ERR2 0
+ GIC 5 3 ERR3 0
+ GIC 5 4 ERR4 0
+ GIC 5 5 ERR5 0
+ GIC 5 6 ERR6 0
+ GIC 5 7 ERR7 0
+ GIC 5 8 ERR8 0
+ GIC 5 9 ERR9 0
+ GIC 5 10 ERR10 0
+ GIC 5 11 ERR11 0
+ GIC 5 12 ERR12 0
+ GIC 5 13-21 ERR13 RC# + 1
+ SMMU 6 TCU 100 RC #
+ SMMU 6 TBU0 0 RC #
+ SMMU 6 TBU1 1 RC #
+ SMMU 6 TBU2 2 RC #
+ SMMU 6 TBU3 3 RC #
+ SMMU 6 TBU4 4 RC #
+ SMMU 6 TBU5 5 RC #
+ SMMU 6 TBU6 6 RC #
+ SMMU 6 TBU7 7 RC #
+ SMMU 6 TBU8 8 RC #
+ SMMU 6 TBU9 9 RC #
+ PCIe AER 7 Root 0 RC #
+ PCIe AER 7 Device 1 RC #
+ PCIe RC 8 RCA HB 0 RC #
+ PCIe RC 8 RCB HB 1 RC #
+ PCIe RC 8 RASDP 8 RC #
+ OCM 9 ERR0 0 0
+ OCM 9 ERR1 1 0
+ OCM 9 ERR2 2 0
+ SMpro 10 ERR0 0 0
+ SMpro 10 ERR1 1 0
+ SMpro 10 MPA_ERR 2 0
+ PMpro 11 ERR0 0 0
+ PMpro 11 ERR1 1 0
+ PMpro 11 MPA_ERR 2 0
+ ============= ========== ========= =============== ================
+
+
+2) Type 2 for the Internal SMpro/PMpro alert types::
+
+ <Error Type> <Error SubType> <Direction> <Error Location> <Error Code> <Error Data>
+
+ Where:
+ * Error Type: SMpro/PMpro Error types in format of two hex characters.
+ + 1: Warning
+ + 2: Error
+ + 4: Error with data
+ * Error SubType: SMpro/PMpro Image Code in format of two hex characters.
+ * Direction: Direction in format of two hex characters.
+ + 0: Enter
+ + 1: Exit
+ * Error Location: SMpro/PMpro Module Location code in format of two hex characters.
+ * Error Code: SMpro/PMpro Error code in format of four hex characters.
+ * Error Data: Extensive datae in format of eight hex characters.
+ All bits are 0 when Error Type is warning or error.
+
+ Example:
+ # cat errors_smpro
+ 01 04 01 08 0035 00000000
+
+3) Type 3 for the VRD hot, VRD /warn/fault, DIMM Hot, DIMM 2x refresh rate event::
+
+ <Event Type> <Event SubType> <Direction> <Event Location> [Event Data]
+
+ Where:
+ * Event Type: event type in format of two hex characters.
+ * Event SubType: event sub type in format of two hex characters.
+ * Direction: Direction in format of two hex characters.
+ + 0: Asserted
+ + 1: De-asserted
+ * Event Location: The index of component cause the alert in format of two hex characters.
+ * Event Data: Extensive data if have in format of four hex characters.
+
+ Example:
+ #cat event_vr_hot
+ 00 02 00 00 -> /* DIMM VRD hot event is asserted at channel 0 */
+ 00 02 01 00 -> /* DIMM VRD hot event is de-asserted at channel 0 */
+ 00 01 00 03 -> /* Core VRD hot event is asserted at channel 3 */
+ 00 00 00 00 -> /* SoC VRD hot event is asserted */
+ 00 00 00 00 -> /* SoC VRD hot event is de-asserted */
+ 00 02 00 06 -> /* DIMM VRD hot event is de-asserted at channel 6 */
+
+Sysfs entries
+-------------
+
+The following sysfs files are supported:
+
+* Ampere(R) Altra(R):
+
+Alert Types:
+
+ ================= =============== =========================================================== =======
+ Alert Type Sysfs name Description Format
+ Core CE Errors errors_core_ce Triggered by CPU when Core has an CE error 1
+ Core UE Errors errors_core_ue Triggered by CPU when Core has an UE error 1
+ Memory CE Errors errors_mem_ce Triggered by CPU when Memory has an CE error 1
+ Memory UE Errors errors_mem_ue Triggered by CPU when Memory has an UE error 1
+ PCIe CE Errors errors_pcie_ce Triggered by CPU when any PCIe controller has any CE error 1
+ PCIe UE Errors errors_pcie_ue Triggered by CPU when any PCIe controller has any UE error 1
+ Other CE Errors errors_other_ce Triggered by CPU when any Others CE error 1
+ Other UE Errors errors_other_ue Triggered by CPU when any Others UE error 1
+ SMpro Errors errors_smpro Triggered by CPU when system have SMpro error 2
+ PMpro Errors errors_pmpro Triggered by CPU when system have PMpro error 2
+ ================= =============== =========================================================== =======
+
+Event Type:
+
+ ============================ ========================== =========== ========================
+ Event Type Sysfs name Event Type Sub Type
+ VRD HOT event_vrd_hot 0 0: SoC, 1: Core, 2: DIMM
+ VR Warn/Fault event_vrd_warn_fault 1 0: SoC, 1: Core, 2: DIMM
+ DIMM Hot event_dimm_hot 2 NA (Default 0)
+ DIMM 2x refresh rate status event_dimm_2x_refresh 3 NA (Default 0)
+ ============================ ========================== =========== ========================
--
2.28.0
This commit adds driver support for accessing various information
reported by Ampere's SMpro co-processor such as Boot Progress and
other miscellaneous data.
Signed-off-by: Quan Nguyen <[email protected]>
---
Change in v6:
+ First introduced in v6 [Quan]
drivers/mfd/smpro-mfd.c | 1 +
drivers/misc/Kconfig | 7 ++
drivers/misc/Makefile | 1 +
drivers/misc/smpro-misc.c | 177 ++++++++++++++++++++++++++++++++++++++
4 files changed, 186 insertions(+)
create mode 100644 drivers/misc/smpro-misc.c
diff --git a/drivers/mfd/smpro-mfd.c b/drivers/mfd/smpro-mfd.c
index a7cd64bf9eaa..5611dd30f8f4 100644
--- a/drivers/mfd/smpro-mfd.c
+++ b/drivers/mfd/smpro-mfd.c
@@ -28,6 +28,7 @@ static const struct regmap_config simple_word_regmap_config = {
static const struct mfd_cell smpro_devs[] = {
MFD_CELL_NAME("smpro-hwmon"),
MFD_CELL_NAME("smpro-errmon"),
+ MFD_CELL_NAME("smpro-misc"),
};
static int smpro_mfd_probe(struct i2c_client *i2c)
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index 0cbd8a2561a7..df53cbf62931 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -183,6 +183,13 @@ config SMPRO_ERRMON
If you say yes here you get support for error monitor function
provides by Ampere Computing's SoC with SMpro processor.
+config SMPRO_MISC
+ tristate "Ampere Computing SMPro miscellaneous driver"
+ depends on MFD_SMPRO || COMPILE_TEST
+ help
+ If you say yes here you get support for the miscellaleous function
+ provides by Ampere Computing's SoC with SMpro processor.
+
config CS5535_MFGPT
tristate "CS5535/CS5536 Geode Multi-Function General Purpose Timer (MFGPT) support"
depends on MFD_CS5535
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index 8ec9961b941b..bbfee81499de 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -24,6 +24,7 @@ obj-$(CONFIG_KGDB_TESTS) += kgdbts.o
obj-$(CONFIG_SGI_XP) += sgi-xp/
obj-$(CONFIG_SGI_GRU) += sgi-gru/
obj-$(CONFIG_SMPRO_ERRMON) += smpro-errmon.o
+obj-$(CONFIG_SMPRO_MISC) += smpro-misc.o
obj-$(CONFIG_CS5535_MFGPT) += cs5535-mfgpt.o
obj-$(CONFIG_GEHC_ACHC) += gehc-achc.o
obj-$(CONFIG_HP_ILO) += hpilo.o
diff --git a/drivers/misc/smpro-misc.c b/drivers/misc/smpro-misc.c
new file mode 100644
index 000000000000..6fe9d25ce31c
--- /dev/null
+++ b/drivers/misc/smpro-misc.c
@@ -0,0 +1,177 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Ampere Computing SoC's SMpro Misc Driver
+ *
+ * Copyright (c) 2021, Ampere Computing LLC
+ */
+#include <linux/mod_devicetable.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/regmap.h>
+
+/* Boot Stage/Progress Registers */
+#define BOOTSTAGE_SELECT 0xB0
+#define BOOTSTAGE_STATUS_LO 0xB1
+#define BOOTSTAGE_CUR_STAGE 0xB2
+#define BOOTSTAGE_STATUS_HI 0xB3
+
+/* SOC State Registers */
+#define SOC_POWER_LIMIT 0xE5
+
+/* Boot stages */
+enum {
+ BOOTSTAGE_SMPRO = 0,
+ BOOTSTAGE_PMPRO,
+ BOOTSTAGE_ATF_BL1,
+ BOOTSTAGE_DDR_INIT,
+ BOOTSTAGE_DDR_INIT_PROGRESS,
+ BOOTSTAGE_ATF_BL2,
+ BOOTSTAGE_ATF_BL31,
+ BOOTSTAGE_ATF_BL32,
+ BOOTSTAGE_UEFI,
+ BOOTSTAGE_OS,
+ BOOTSTAGE_MAX
+};
+
+struct smpro_misc {
+ struct regmap *regmap;
+};
+
+static int boot_progress_show(struct device *dev, struct device_attribute *da, char *buf)
+{
+ struct smpro_misc *misc = dev_get_drvdata(dev);
+ u32 boot_progress;
+ u8 current_stage;
+ u8 boot_status;
+ u8 boot_stage;
+ u32 select;
+ u32 reg_lo;
+ u32 reg;
+ int ret;
+
+ /* Read current boot stage */
+ ret = regmap_read(misc->regmap, BOOTSTAGE_CUR_STAGE, ®);
+ if (ret)
+ return ret;
+
+ current_stage = reg & 0xff;
+
+ /* Read the boot progress */
+ ret = regmap_read(misc->regmap, BOOTSTAGE_SELECT, &select);
+ if (ret)
+ return ret;
+
+ boot_stage = (select >> 8) & 0xff;
+ boot_status = select & 0xff;
+
+ if (boot_stage > current_stage)
+ return -EINVAL;
+
+ ret = regmap_read(misc->regmap, BOOTSTAGE_STATUS_LO, ®_lo);
+ if (!ret)
+ ret = regmap_read(misc->regmap, BOOTSTAGE_STATUS_HI, ®);
+ if (ret)
+ return ret;
+
+ boot_progress = swab16(reg) << 16 | swab16(reg_lo);
+
+ /* Tell firmware to provide next boot stage next time */
+ if (boot_stage < current_stage) {
+ ret = regmap_write(misc->regmap, BOOTSTAGE_SELECT, ((select & 0xff00) | 0x1));
+ if (ret)
+ return ret;
+ }
+
+ return snprintf(buf, PAGE_SIZE, "0x%02x 0x%02x 0x%08x\n",
+ boot_stage, boot_status, boot_progress);
+}
+
+static DEVICE_ATTR_RO(boot_progress);
+
+static int soc_power_limit_show(struct device *dev, struct device_attribute *da, char *buf)
+{
+ struct smpro_misc *misc = dev_get_drvdata(dev);
+ unsigned int value;
+ int ret;
+
+ ret = regmap_read(misc->regmap, SOC_POWER_LIMIT, &value);
+ if (ret)
+ return ret;
+
+ return snprintf(buf, PAGE_SIZE, "%d\n", value);
+}
+
+static int soc_power_limit_store(struct device *dev, struct device_attribute *da,
+ const char *buf, size_t count)
+{
+ struct smpro_misc *misc = dev_get_drvdata(dev);
+ unsigned long val;
+ s32 ret;
+
+ ret = kstrtoul(buf, 0, &val);
+ if (ret)
+ return ret;
+
+ ret = regmap_write(misc->regmap, SOC_POWER_LIMIT, (unsigned int)val);
+ if (ret)
+ return -EPROTO;
+
+ return count;
+}
+
+static DEVICE_ATTR_RW(soc_power_limit);
+
+static struct attribute *smpro_misc_attrs[] = {
+ &dev_attr_boot_progress.attr,
+ &dev_attr_soc_power_limit.attr,
+ NULL
+};
+
+static const struct attribute_group smpro_misc_attr_group = {
+ .attrs = smpro_misc_attrs
+};
+
+static int smpro_misc_probe(struct platform_device *pdev)
+{
+ struct smpro_misc *misc;
+ int ret;
+
+ misc = devm_kzalloc(&pdev->dev, sizeof(struct smpro_misc), GFP_KERNEL);
+ if (!misc)
+ return -ENOMEM;
+
+ platform_set_drvdata(pdev, misc);
+
+ misc->regmap = dev_get_regmap(pdev->dev.parent, NULL);
+ if (!misc->regmap)
+ return -ENODEV;
+
+ ret = sysfs_create_group(&pdev->dev.kobj, &smpro_misc_attr_group);
+ if (ret)
+ dev_err(&pdev->dev, "SMPro misc sysfs registration failed\n");
+
+ return 0;
+}
+
+static int smpro_misc_remove(struct platform_device *pdev)
+{
+ sysfs_remove_group(&pdev->dev.kobj, &smpro_misc_attr_group);
+ pr_info("SMPro misc sysfs entries removed");
+
+ return 0;
+}
+
+static struct platform_driver smpro_misc_driver = {
+ .probe = smpro_misc_probe,
+ .remove = smpro_misc_remove,
+ .driver = {
+ .name = "smpro-misc",
+ },
+};
+
+module_platform_driver(smpro_misc_driver);
+
+MODULE_AUTHOR("Tung Nguyen <[email protected]>");
+MODULE_AUTHOR("Quan Nguyen <[email protected]>");
+MODULE_DESCRIPTION("Ampere Altra SMpro Misc driver");
+MODULE_LICENSE("GPL");
--
2.28.0
Adds documentation for the Ampere(R)'s Altra(R) SMpro misc driver.
Signed-off-by: Thu Nguyen <[email protected]>
Signed-off-by: Quan Nguyen <[email protected]>
---
Change in v6:
+ First introduced in v6 [Quan]
Documentation/misc-devices/index.rst | 1 +
Documentation/misc-devices/smpro-misc.rst | 82 +++++++++++++++++++++++
2 files changed, 83 insertions(+)
create mode 100644 Documentation/misc-devices/smpro-misc.rst
diff --git a/Documentation/misc-devices/index.rst b/Documentation/misc-devices/index.rst
index 7a6a6263cbab..284568eca747 100644
--- a/Documentation/misc-devices/index.rst
+++ b/Documentation/misc-devices/index.rst
@@ -27,6 +27,7 @@ fit into other categories.
max6875
pci-endpoint-test
smpro-errmon
+ smpro-misc
spear-pcie-gadget
uacce
xilinx_sdfec
diff --git a/Documentation/misc-devices/smpro-misc.rst b/Documentation/misc-devices/smpro-misc.rst
new file mode 100644
index 000000000000..7c856eb1a7f3
--- /dev/null
+++ b/Documentation/misc-devices/smpro-misc.rst
@@ -0,0 +1,82 @@
+.. SPDX-License-Identifier: GPL-2.0-or-later
+
+Kernel driver Ampere(R) Altra(R) SMpro miscellaneous
+====================================================
+
+Supported chips:
+
+ * Ampere(R) Altra(R)
+
+ Prefix: 'smpro'
+
+ Reference: Altra SoC BMC Interface Specification
+
+Author: Thu Nguyen <[email protected]>
+
+Description
+-----------
+
+This driver support the monitoring and configuration of various miscellaneous
+data provided by Ampere(R) Altra(R) SMpro processor.
+At this time, these include:
+
+ * Reading Boot Progress information
+ * Configuring SoC Power Limit
+
+Sysfs entries
+-------------
+
+1) Boot progress
+
+SMpro misc driver creates the sysfs files ``boot_progress``.
+The format of ``boot_progress`` file is as below::
+
+<boot stage> <boot status> <boot progress>
+
+Where:
+
+* Boot stage::
+
+ 0: SMpro firmware booting.
+ 1: PMpro firmware booting.
+ 2: ATF BL1 firmware booting.
+ 3: DDR initialization.
+ 4: DDR training report status.
+ 5: ATF BL2 firmware booting.
+ 6: ATF BL31 firmware booting.
+ 7: ATF BL32 firmware booting.
+ 8: UEFI firmware booting.
+ 9: OS booting.
+
+* Boot status::
+
+ 0: Not started.
+ 1: Started.
+ 2: Complete without error.
+ 3: Failure.
+
+* boot progress: 32 bits boot progress code
+
+The sysfs ``boot_progress`` only reports the boot state when the host is booting.
+If the host is already booted, it returns latest state.
+
+Example::
+
+ #cat boot_progress
+ 0x01 0x02 0x808454A8
+
+2) SoC Power Limit
+
+SMpro misc driver creates the sysfs file ``soc_power_limit`` to get/set the SoC Power Limit.
+
+Reading this sysfs return the current setting of SoC Power Limit (W) in decimal string.
+Writing the desired value in decimal string to set the SoC Power Limit in Watt (W).
+The range of SoC Power Limit is 90-500(W) and will be ignored if out of range.
+
+Example::
+
+ #cat soc_power_limit
+ 90
+ #echo 95 > soc_power_limit
+ #cat soc_power_limit
+ 95
--
2.28.0
On Fri, Dec 24, 2021 at 11:13:49AM +0700, Quan Nguyen wrote:
> This commit adds Ampere's SMpro error monitor driver for monitoring
> and reporting RAS-related errors as reported by SMpro co-processor
> found on Ampere's Altra processor family.
>
> Signed-off-by: Quan Nguyen <[email protected]>
> ---
> Change in v6:
> + First introduced in v6 [Quan]
>
> drivers/mfd/smpro-mfd.c | 1 +
> drivers/misc/Kconfig | 7 +
> drivers/misc/Makefile | 1 +
> drivers/misc/smpro-errmon.c | 571 ++++++++++++++++++++++++++++++++++++
> 4 files changed, 580 insertions(+)
> create mode 100644 drivers/misc/smpro-errmon.c
You need Documentation/ABI/ updates when you add sysfs files. Please do
that for your next version of this patch.
Also remember that sysfs is only "one value per file", this driver seems
to violate that in huge ways and is not ok.
thanks,
greg k-h
On Fri, Dec 24, 2021 at 11:13:48AM +0700, Quan Nguyen wrote:
> This commit introduces regmap_acquire/release_lock() functions and makes
> them available for drivers that need atomic access of regmap registers
You've not explained what something would need this for and how
it's expected to work - we don't provide unlocked access to the
regmap to client drivers so I don't see how one could safely use
this. It's unclear to me what this would mean or why it's not
better implemented in the client driver.
On Fri, Dec 24, 2021 at 11:13:49AM +0700, Quan Nguyen wrote:
> +static int read_i2c_block_data(struct i2c_client *client, u16 address, u16 length, u8 *data)
> +{
> + unsigned char outbuf[MAX_READ_BLOCK_LENGTH];
> + unsigned char inbuf[2];
> + struct i2c_msg msgs[2];
> + ssize_t ret;
> +
> + inbuf[0] = (address & 0xff);
> + inbuf[1] = length;
> +
> + msgs[0].addr = client->addr;
> + msgs[0].flags = client->flags & I2C_M_TEN;
> + msgs[0].len = 2;
> + msgs[0].buf = inbuf;
> +
> + msgs[1].addr = client->addr;
> + msgs[1].flags = (client->flags & I2C_M_TEN) | I2C_M_RD;
> + msgs[1].len = length;
> + msgs[1].buf = outbuf;
> +
> + ret = i2c_transfer(client->adapter, msgs, NUM_I2C_MESSAGES);
> + if (ret < 0)
regmap already supports bulk data access so it's not clear why we
would open code this. Given that this is a single I2C transfer
it's also unclear why we'd need to export the regmap lock - a
single I2C transfer is atomic at the bus level so the regmap lock
isn't providing any additional concurrency protection.
On Fri, 24 Dec 2021, Quan Nguyen wrote:
> This commit adds Ampere's SMpro error monitor driver for monitoring
> and reporting RAS-related errors as reported by SMpro co-processor
> found on Ampere's Altra processor family.
>
> Signed-off-by: Quan Nguyen <[email protected]>
> ---
> Change in v6:
> + First introduced in v6 [Quan]
>
> drivers/mfd/smpro-mfd.c | 1 +
Separate patch please.
> drivers/misc/Kconfig | 7 +
> drivers/misc/Makefile | 1 +
> drivers/misc/smpro-errmon.c | 571 ++++++++++++++++++++++++++++++++++++
> 4 files changed, 580 insertions(+)
> create mode 100644 drivers/misc/smpro-errmon.c
--
Lee Jones [李琼斯]
Senior Technical Lead - Developer Services
Linaro.org │ Open source software for Arm SoCs
Follow Linaro: Facebook | Twitter | Blog
On Fri, 24 Dec 2021, Quan Nguyen wrote:
> This commit adds driver support for accessing various information
> reported by Ampere's SMpro co-processor such as Boot Progress and
> other miscellaneous data.
>
> Signed-off-by: Quan Nguyen <[email protected]>
> ---
> Change in v6:
> + First introduced in v6 [Quan]
>
> drivers/mfd/smpro-mfd.c | 1 +
Please pull all of these patches out.
There are no build dependencies here.
> drivers/misc/Kconfig | 7 ++
> drivers/misc/Makefile | 1 +
> drivers/misc/smpro-misc.c | 177 ++++++++++++++++++++++++++++++++++++++
> 4 files changed, 186 insertions(+)
> create mode 100644 drivers/misc/smpro-misc.c
>
> diff --git a/drivers/mfd/smpro-mfd.c b/drivers/mfd/smpro-mfd.c
> index a7cd64bf9eaa..5611dd30f8f4 100644
> --- a/drivers/mfd/smpro-mfd.c
> +++ b/drivers/mfd/smpro-mfd.c
> @@ -28,6 +28,7 @@ static const struct regmap_config simple_word_regmap_config = {
> static const struct mfd_cell smpro_devs[] = {
> MFD_CELL_NAME("smpro-hwmon"),
> MFD_CELL_NAME("smpro-errmon"),
> + MFD_CELL_NAME("smpro-misc"),
Misc is a Linuxisum which are not allowed in DT.
What does this driver actually do?
--
Lee Jones [李琼斯]
Senior Technical Lead - Developer Services
Linaro.org │ Open source software for Arm SoCs
Follow Linaro: Facebook | Twitter | Blog
On Fri, 24 Dec 2021, Quan Nguyen wrote:
> Adds Multi-function devices driver for SMpro co-processor found on the
> Mt.Jade hardware reference platform with Ampere's Altra processor family.
>
> Signed-off-by: Quan Nguyen <[email protected]>
> ---
> Changes in v6:
> + Update license part to reflect that this driver is clone from
> simple-mfd-i2c driver [Quan]
>
> Changes in v5:
> + Dropped the use of simple-mfd-i2c driver [Quan]
> + Introduced drivers/mfd/smpro-mfd.c driver to instantiate
> sub-devices. This is to avoid DT nodes without resource issue [Quan]
> + Revised commit message [Quan]
>
> Changes in v4:
> + Add "depends on I2C" to fix build issue found by kernel test
> robot [Guenter]
>
> Changes in v3:
> + None
>
> Changes in v2:
> + Used 'struct of_device_id's .data attribute [Lee Jones]
>
> drivers/mfd/Kconfig | 12 +++++++
> drivers/mfd/Makefile | 1 +
> drivers/mfd/smpro-mfd.c | 76 +++++++++++++++++++++++++++++++++++++++++
> 3 files changed, 89 insertions(+)
> create mode 100644 drivers/mfd/smpro-mfd.c
>
> diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
> index a21cbdf89477..a886da5018b1 100644
> --- a/drivers/mfd/Kconfig
> +++ b/drivers/mfd/Kconfig
> @@ -77,6 +77,18 @@ config MFD_AS3711
> help
> Support for the AS3711 PMIC from AMS
>
> +config MFD_SMPRO
> + tristate "Ampere Computing MFD SMpro core driver"
> + depends on I2C
> + select MFD_CORE
> + select REGMAP_I2C
> + help
> + Say yes here to enable SMpro driver support for Ampere's Altra
> + processor family.
> +
> + Ampere's Altra SMpro exposes an I2C regmap interface that can
> + be accessed by child devices.
> +
> config MFD_AS3722
> tristate "ams AS3722 Power Management IC"
> select MFD_CORE
> diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
> index 4d53e951a92d..fbcd09dce5ce 100644
> --- a/drivers/mfd/Makefile
> +++ b/drivers/mfd/Makefile
> @@ -267,6 +267,7 @@ obj-$(CONFIG_MFD_QCOM_PM8008) += qcom-pm8008.o
>
> obj-$(CONFIG_SGI_MFD_IOC3) += ioc3.o
> obj-$(CONFIG_MFD_SIMPLE_MFD_I2C) += simple-mfd-i2c.o
> +obj-$(CONFIG_MFD_SMPRO) += smpro-mfd.o
> obj-$(CONFIG_MFD_INTEL_M10_BMC) += intel-m10-bmc.o
>
> obj-$(CONFIG_MFD_ATC260X) += atc260x-core.o
> diff --git a/drivers/mfd/smpro-mfd.c b/drivers/mfd/smpro-mfd.c
> new file mode 100644
> index 000000000000..132d4e2dde12
> --- /dev/null
> +++ b/drivers/mfd/smpro-mfd.c
> @@ -0,0 +1,76 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * Ampere Altra Family SMPro MFD - I2C
> + *
> + * Copyright (c) 2021, Ampere Computing LLC
> + * Author: Quan Nguyen <[email protected]>
> + *
> + * Based on simple-mfd-i2c.c:
Why aren't you just using this?
> + * Copyright (c) by Michael Walle <[email protected]>
> + */
> +
> +#include <linux/i2c.h>
> +#include <linux/kernel.h>
> +#include <linux/module.h>
> +#include <linux/of_platform.h>
> +#include <linux/mfd/core.h>
> +#include <linux/regmap.h>
> +
> +/* Identification Registers */
> +#define MANUFACTURER_ID_REG 0x02
> +#define AMPERE_MANUFACTURER_ID 0xCD3A
> +
> +static const struct regmap_config simple_word_regmap_config = {
> + .reg_bits = 8,
> + .val_bits = 16,
> +};
> +
> +static const struct mfd_cell smpro_devs[] = {
> + MFD_CELL_NAME("smpro-hwmon"),
> +};
What are the other devices?
> +static int smpro_mfd_probe(struct i2c_client *i2c)
> +{
> + const struct regmap_config *config;
> + struct regmap *regmap;
> + unsigned int val;
> + int ret;
> +
> + config = device_get_match_data(&i2c->dev);
> + if (!config)
> + config = &simple_word_regmap_config;
> +
> + regmap = devm_regmap_init_i2c(i2c, config);
> + if (IS_ERR(regmap))
> + return PTR_ERR(regmap);
> +
> + /* Check for valid ID */
> + ret = regmap_read(regmap, MANUFACTURER_ID_REG, &val);
> + if (ret)
> + return ret;
> +
> + if (val != AMPERE_MANUFACTURER_ID)
> + return -ENODEV;
> +
> + return devm_mfd_add_devices(&i2c->dev, PLATFORM_DEVID_AUTO,
> + smpro_devs, ARRAY_SIZE(smpro_devs), NULL, 0, NULL);
> +}
> +
> +static const struct of_device_id smpro_mfd_of_match[] = {
> + { .compatible = "ampere,smpro", .data = &simple_word_regmap_config },
> + {}
> +};
> +MODULE_DEVICE_TABLE(of, smpro_mfd_of_match);
> +
> +static struct i2c_driver smpro_mfd_driver = {
> + .probe_new = smpro_mfd_probe,
> + .driver = {
> + .name = "smpro-mfd-i2c",
> + .of_match_table = smpro_mfd_of_match,
> + },
> +};
> +module_i2c_driver(smpro_mfd_driver);
> +
> +MODULE_AUTHOR("Quan Nguyen <[email protected]>");
> +MODULE_DESCRIPTION("SMPRO MFD - I2C driver");
> +MODULE_LICENSE("GPL v2");
--
Lee Jones [李琼斯]
Principal Technical Lead - Developer Services
Linaro.org │ Open source software for Arm SoCs
Follow Linaro: Facebook | Twitter | Blog
Dear Lee Jone,
My apologize as I did not see any of your replys for this series. Maybe
due to my bad junk setting,
So this email is to address your comment in
https://lkml.org/lkml/2022/2/8/254
Please see my inline below.
Thanks for the review,
- Quan
On 24/12/2021 11:13, Quan Nguyen wrote:
> Adds Multi-function devices driver for SMpro co-processor found on the
> Mt.Jade hardware reference platform with Ampere's Altra processor family.
>
> Signed-off-by: Quan Nguyen <[email protected]>
> ---
> Changes in v6:
> + Update license part to reflect that this driver is clone from
> simple-mfd-i2c driver [Quan]
>
> Changes in v5:
> + Dropped the use of simple-mfd-i2c driver [Quan]
> + Introduced drivers/mfd/smpro-mfd.c driver to instantiate
> sub-devices. This is to avoid DT nodes without resource issue [Quan]
> + Revised commit message [Quan]
>
> Changes in v4:
> + Add "depends on I2C" to fix build issue found by kernel test
> robot [Guenter]
>
> Changes in v3:
> + None
>
> Changes in v2:
> + Used 'struct of_device_id's .data attribute [Lee Jones]
>
> drivers/mfd/Kconfig | 12 +++++++
> drivers/mfd/Makefile | 1 +
> drivers/mfd/smpro-mfd.c | 76 +++++++++++++++++++++++++++++++++++++++++
> 3 files changed, 89 insertions(+)
> create mode 100644 drivers/mfd/smpro-mfd.c
>
> diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
> index a21cbdf89477..a886da5018b1 100644
> --- a/drivers/mfd/Kconfig
> +++ b/drivers/mfd/Kconfig
> @@ -77,6 +77,18 @@ config MFD_AS3711
> help
> Support for the AS3711 PMIC from AMS
>
> +config MFD_SMPRO
> + tristate "Ampere Computing MFD SMpro core driver"
> + depends on I2C
> + select MFD_CORE
> + select REGMAP_I2C
> + help
> + Say yes here to enable SMpro driver support for Ampere's Altra
> + processor family.
> +
> + Ampere's Altra SMpro exposes an I2C regmap interface that can
> + be accessed by child devices.
> +
> config MFD_AS3722
> tristate "ams AS3722 Power Management IC"
> select MFD_CORE
> diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
> index 4d53e951a92d..fbcd09dce5ce 100644
> --- a/drivers/mfd/Makefile
> +++ b/drivers/mfd/Makefile
> @@ -267,6 +267,7 @@ obj-$(CONFIG_MFD_QCOM_PM8008) += qcom-pm8008.o
>
> obj-$(CONFIG_SGI_MFD_IOC3) += ioc3.o
> obj-$(CONFIG_MFD_SIMPLE_MFD_I2C) += simple-mfd-i2c.o
> +obj-$(CONFIG_MFD_SMPRO) += smpro-mfd.o
> obj-$(CONFIG_MFD_INTEL_M10_BMC) += intel-m10-bmc.o
>
> obj-$(CONFIG_MFD_ATC260X) += atc260x-core.o
> diff --git a/drivers/mfd/smpro-mfd.c b/drivers/mfd/smpro-mfd.c
> new file mode 100644
> index 000000000000..132d4e2dde12
> --- /dev/null
> +++ b/drivers/mfd/smpro-mfd.c
> @@ -0,0 +1,76 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * Ampere Altra Family SMPro MFD - I2C
> + *
> + * Copyright (c) 2021, Ampere Computing LLC
> + * Author: Quan Nguyen <[email protected]>
> + *
> + * Based on simple-mfd-i2c.c:
[Lee Jones] Why aren't you just using this?
Mainly, on this series, is because we need to add empty DT nodes for
child drivers to be instantiated which was NAK because DT nodes should
be for describe HW specific other than to instantiate drivers.
And, as other reason, in my new version, I found that we will need
separate MFD driver so that multiple type of bus access could be handled
(by using regmap_bus->read/write()).
> + * Copyright (c) by Michael Walle <[email protected]>
> + */
> +
> +#include <linux/i2c.h>
> +#include <linux/kernel.h>
> +#include <linux/module.h>
> +#include <linux/of_platform.h>
> +#include <linux/mfd/core.h>
> +#include <linux/regmap.h>
> +
> +/* Identification Registers */
> +#define MANUFACTURER_ID_REG 0x02
> +#define AMPERE_MANUFACTURER_ID 0xCD3A
> +
> +static const struct regmap_config simple_word_regmap_config = {
> + .reg_bits = 8,
> + .val_bits = 16,
> +};
> +
> +static const struct mfd_cell smpro_devs[] = {
> + MFD_CELL_NAME("smpro-hwmon"),
> +};
[Lee Jones] What are the other devices?
The other devices are smpro-errmon (to query HW error reported by Altra
Family processor) and smpro-misc (to handle other miscellaneous info).
> +
> +static int smpro_mfd_probe(struct i2c_client *i2c)
> +{
> + const struct regmap_config *config;
> + struct regmap *regmap;
> + unsigned int val;
> + int ret;
> +
> + config = device_get_match_data(&i2c->dev);
> + if (!config)
> + config = &simple_word_regmap_config;
> +
> + regmap = devm_regmap_init_i2c(i2c, config);
> + if (IS_ERR(regmap))
> + return PTR_ERR(regmap);
> +
> + /* Check for valid ID */
> + ret = regmap_read(regmap, MANUFACTURER_ID_REG, &val);
> + if (ret)
> + return ret;
> +
> + if (val != AMPERE_MANUFACTURER_ID)
> + return -ENODEV;
> +
> + return devm_mfd_add_devices(&i2c->dev, PLATFORM_DEVID_AUTO,
> + smpro_devs, ARRAY_SIZE(smpro_devs), NULL, 0, NULL);
> +}
> +
> +static const struct of_device_id smpro_mfd_of_match[] = {
> + { .compatible = "ampere,smpro", .data = &simple_word_regmap_config },
> + {}
> +};
> +MODULE_DEVICE_TABLE(of, smpro_mfd_of_match);
> +
> +static struct i2c_driver smpro_mfd_driver = {
> + .probe_new = smpro_mfd_probe,
> + .driver = {
> + .name = "smpro-mfd-i2c",
> + .of_match_table = smpro_mfd_of_match,
> + },
> +};
> +module_i2c_driver(smpro_mfd_driver);
> +
> +MODULE_AUTHOR("Quan Nguyen <[email protected]>");
> +MODULE_DESCRIPTION("SMPRO MFD - I2C driver");
> +MODULE_LICENSE("GPL v2");
On 24/12/2021 20:19, Mark Brown wrote:
> On Fri, Dec 24, 2021 at 11:13:48AM +0700, Quan Nguyen wrote:
>> This commit introduces regmap_acquire/release_lock() functions and makes
>> them available for drivers that need atomic access of regmap registers
>
> You've not explained what something would need this for and how
> it's expected to work - we don't provide unlocked access to the
> regmap to client drivers so I don't see how one could safely use
> this. It's unclear to me what this would mean or why it's not
> better implemented in the client driver.
Thanks a lot for the review, Mark.
As per my comment in the other email, this code will be removed in my
next version.
Thanks,
- Quan
Dear Lee Jones,
This mail is to reply your comment in https://lkml.org/lkml/2021/12/29/120
Thanks for the review,
- Quan
On 24/12/2021 11:13, Quan Nguyen wrote:
> This commit adds Ampere's SMpro error monitor driver for monitoring
> and reporting RAS-related errors as reported by SMpro co-processor
> found on Ampere's Altra processor family.
>
> Signed-off-by: Quan Nguyen <[email protected]>
> ---
> Change in v6:
> + First introduced in v6 [Quan]
>
> drivers/mfd/smpro-mfd.c | 1 +
[Lee Jones] Separate patch please
Will separate this smpro-mfd.c in single patch only in my next version
> drivers/misc/Kconfig | 7 +
> drivers/misc/Makefile | 1 +
> drivers/misc/smpro-errmon.c | 571 ++++++++++++++++++++++++++++++++++++
> 4 files changed, 580 insertions(+)
> create mode 100644 drivers/misc/smpro-errmon.c
>
On 24/12/2021 15:32, Greg Kroah-Hartman wrote:
> On Fri, Dec 24, 2021 at 11:13:49AM +0700, Quan Nguyen wrote:
>> This commit adds Ampere's SMpro error monitor driver for monitoring
>> and reporting RAS-related errors as reported by SMpro co-processor
>> found on Ampere's Altra processor family.
>>
>> Signed-off-by: Quan Nguyen <[email protected]>
>> ---
>> Change in v6:
>> + First introduced in v6 [Quan]
>>
>> drivers/mfd/smpro-mfd.c | 1 +
>> drivers/misc/Kconfig | 7 +
>> drivers/misc/Makefile | 1 +
>> drivers/misc/smpro-errmon.c | 571 ++++++++++++++++++++++++++++++++++++
>> 4 files changed, 580 insertions(+)
>> create mode 100644 drivers/misc/smpro-errmon.c
>
> You need Documentation/ABI/ updates when you add sysfs files. Please do
> that for your next version of this patch.
>
Thanks greg for the review,
Will update Documentation/ABI/testing/sysfs-* file in next version.
> Also remember that sysfs is only "one value per file", this driver seems
> to violate that in huge ways and is not ok.
>
These sysfs's does not return "multi value per file" but a single record
of data, one example is to return the 48-byte ARM RAS Vendor specific
error record.
Thanks
- Quan
Dear Lee Jones,
This to reply your comment in https://lkml.org/lkml/2021/12/29/121
Thanks for the review,
- Quan
On 24/12/2021 11:13, Quan Nguyen wrote:
> This commit adds driver support for accessing various information
> reported by Ampere's SMpro co-processor such as Boot Progress and
> other miscellaneous data.
>
> Signed-off-by: Quan Nguyen <[email protected]>
> ---
> Change in v6:
> + First introduced in v6 [Quan]
>
> drivers/mfd/smpro-mfd.c | 1 +
[Lee Jones]
Please pull all of these patches out.
There are no build dependencies here.
[Quan]
Will separate this smpro-mfd and other child drivers in next version
> drivers/misc/Kconfig | 7 ++
> drivers/misc/Makefile | 1 +
> drivers/misc/smpro-misc.c | 177 ++++++++++++++++++++++++++++++++++++++
> 4 files changed, 186 insertions(+)
> create mode 100644 drivers/misc/smpro-misc.c
>
> diff --git a/drivers/mfd/smpro-mfd.c b/drivers/mfd/smpro-mfd.c
> index a7cd64bf9eaa..5611dd30f8f4 100644
> --- a/drivers/mfd/smpro-mfd.c
> +++ b/drivers/mfd/smpro-mfd.c
> @@ -28,6 +28,7 @@ static const struct regmap_config simple_word_regmap_config = {
> static const struct mfd_cell smpro_devs[] = {
> MFD_CELL_NAME("smpro-hwmon"),
> MFD_CELL_NAME("smpro-errmon"),
> + MFD_CELL_NAME("smpro-misc"),
[Lee Jones]
Misc is a Linuxisum which are not allowed in DT.
What does this driver actually do?
[Quan]
This drivers is to report the boot progress to BMC and allow BMC to
configure the Soc Power Limit of Ampere's Altra family processor.
On 24/12/2021 20:28, Mark Brown wrote:
> On Fri, Dec 24, 2021 at 11:13:49AM +0700, Quan Nguyen wrote:
>
>> +static int read_i2c_block_data(struct i2c_client *client, u16 address, u16 length, u8 *data)
>> +{
>> + unsigned char outbuf[MAX_READ_BLOCK_LENGTH];
>> + unsigned char inbuf[2];
>> + struct i2c_msg msgs[2];
>> + ssize_t ret;
>> +
>> + inbuf[0] = (address & 0xff);
>> + inbuf[1] = length;
>> +
>> + msgs[0].addr = client->addr;
>> + msgs[0].flags = client->flags & I2C_M_TEN;
>> + msgs[0].len = 2;
>> + msgs[0].buf = inbuf;
>> +
>> + msgs[1].addr = client->addr;
>> + msgs[1].flags = (client->flags & I2C_M_TEN) | I2C_M_RD;
>> + msgs[1].len = length;
>> + msgs[1].buf = outbuf;
>> +
>> + ret = i2c_transfer(client->adapter, msgs, NUM_I2C_MESSAGES);
>> + if (ret < 0)
>
> regmap already supports bulk data access so it's not clear why we
> would open code this. Given that this is a single I2C transfer
> it's also unclear why we'd need to export the regmap lock - a
> single I2C transfer is atomic at the bus level so the regmap lock
> isn't providing any additional concurrency protection.
Thanks a lot for the review, Mark.
Even though the single i2c transfer is atomic at the bus level, but my
concerns is that the transfer may be interlaced with some other
transaction from the regmap which was guarded by regmap's lock. And so
making these accesses atomic in regmap level should be done as well.
That is why I need the regmap's lock export for user driver.
But your comment made re-think about the code, and I think we can handle
multiple types of transfer by using remap_bus->read/write(). The
read_i2c_block_data() is now replaced by regmap_noinc_read() and hence,
remove the use of regmap's lock. These changes will be included in my
next version.
Thanks,
- Quan
On Mon, Mar 7, 2022 at 9:32 AM Quan Nguyen <[email protected]> wrote:
> > diff --git a/drivers/mfd/smpro-mfd.c b/drivers/mfd/smpro-mfd.c
> > index a7cd64bf9eaa..5611dd30f8f4 100644
> > --- a/drivers/mfd/smpro-mfd.c
> > +++ b/drivers/mfd/smpro-mfd.c
> > @@ -28,6 +28,7 @@ static const struct regmap_config simple_word_regmap_config = {
> > static const struct mfd_cell smpro_devs[] = {
> > MFD_CELL_NAME("smpro-hwmon"),
> > MFD_CELL_NAME("smpro-errmon"),
> > + MFD_CELL_NAME("smpro-misc"),
>
> [Lee Jones]
> Misc is a Linuxisum which are not allowed in DT.
>
> What does this driver actually do?
>
> [Quan]
> This drivers is to report the boot progress to BMC and allow BMC to
> configure the Soc Power Limit of Ampere's Altra family processor.
That doesn't sound like it should be platform specific at all, but rather
a generic BMC interface. I see you already have the openbmc list on Cc,
so I assume the right people can see this. Presumably this is a BMC that
already runs on openbmc and can have a platform-independent interface
for doing this.
Arnd