Add Ampere's Altra SMPro hwmon driver
v5 cover Add Ampere's Altra SMPro hwmon driver
This patch series 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 found on Ampere 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. The SMPro MFD driver intializes the register map and instantiates all sub-devices. All the specifics will be handled in the child drivers.
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 (4):
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
.../devicetree/bindings/mfd/ampere,smpro.yaml | 52 ++ Documentation/hwmon/index.rst | 1 + Documentation/hwmon/smpro-hwmon.rst | 101 ++++ 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 | 74 +++ 9 files changed, 713 insertions(+) create mode 100644 Documentation/devicetree/bindings/mfd/ampere,smpro.yaml create mode 100644 Documentation/hwmon/smpro-hwmon.rst create mode 100644 drivers/hwmon/smpro-hwmon.c create mode 100644 drivers/mfd/smpro-mfd.c
Signature · 1 line
2.28.0
PATCH v5 1/4 dt-bindings: mfd: Add bindings for Ampere Altra SMPro MFD driver
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.
---
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 | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 Documentation/devicetree/bindings/mfd/ampere,smpro.yaml
Documentation/devicetree/bindings/mfd/ampere,smpro.yaml new file +52 -0
@@ -0,0 +1,52 @@ +# 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: + - "#address-cells" + - "#size-cells" + - compatible + - reg + +additionalProperties: false + +examples: + - | + i2c { + #address-cells = <1>; + #size-cells = <0>; + + smpro at 4f { + compatible = "ampere,smpro"; + reg = <0x4f>; + #address-cells = <1>; + #size-cells = <0>; + }; + };
Signature · 1 line
2.28.0
Re: [PATCH v5 1/4] dt-bindings: mfd: Add bindings for Ampere Altra SMPro MFD driver
Quoted 24 lines · Quan Nguyen
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]>---
Changes in v5:
+ Dropped../bindings/hwmon/ampere,ac01-hwmon.yamlfile [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]
Quoted 7 lines
Changes in v2:
+ Changed "ampere,ac01-smpro" to "ampere,smpro" [Quan].../devicetree/bindings/mfd/ampere,smpro.yaml | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 Documentation/devicetree/bindings/mfd/ampere,smpro.yaml
Re: [PATCH v5 1/4] dt-bindings: mfd: Add bindings for Ampere Altra SMPro MFD driver
Quoted 28 lines · Rob Herring
Quoted 27 lines · Quan Nguyen
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]>---
Changes in v5:
+ Dropped../bindings/hwmon/ampere,ac01-hwmon.yamlfile [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]
Quoted 7 lines
Quoted 4 lines
.../devicetree/bindings/mfd/ampere,smpro.yaml | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+)create mode 100644
Documentation/devicetree/bindings/mfd/ampere,smpro.yamlReviewed-by Rob Herring <[email protected]>
Thanks Rob for the review.
- Quan
PATCH v5 2/4 mfd: smpro-mfd: Adds Ampere's Altra SMpro MFD driver
In reply to Quan NguyenAdds Multi-function devices driver for SMpro co-processor found on the Mt.Jade hardware reference platform with Ampere's Altra processor family.
---
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 | 74 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 87 insertions(+) create mode 100644 drivers/mfd/smpro-mfd.c
drivers/mfd/Kconfig +12 -0
@@ -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
drivers/mfd/Makefile +1 -0
@@ -268,6 +268,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
drivers/mfd/smpro-mfd.c new file +74 -0
74 lines not on this page · raw message
Signature · 1 line
2.28.0
Guenter Roeck
maintainerRe: [PATCH v5 2/4] mfd: smpro-mfd: Adds Ampere's Altra SMpro MFD driver
Quoted 4 lines · Quan Nguyen
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]>
Maybe that has been discussed, but is there anything else besides hardware monitoring connected to this i2c interface, and are there more child drivers coming ? I don't find the BMC Interface Specification mentioned in the documentation patch, but the hardware specification seems to suggest that the i2c bus is dedicated for hardware monitoring. If there is no other child driver, an mfd driver would not make sense.
Thanks,
Guenter
Quoted 139 lines
---
Changes in v5:
+ Dropped the use of simple-mfd-i2c driver [Quan]
+ Introduceddrivers/mfd/smpro-mfd.cdriver 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:
+ NoneChanges 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 | 74 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 87 insertions(+)create mode 100644
drivers/mfd/smpro-mfd.cdrivers/mfd/Kconfig +12
-0@@ -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_COREdrivers/mfd/Makefile +1
-0@@ -268,6 +268,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.odrivers/mfd/smpro-mfd.c new file +74
-0@@ -0,0 +1,74 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Ampere Altra Family SMPro MFD - I2C +* +* Copyright (c) 2021, Ampere Computing LLC +* +* Author: Quan Nguyen <[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" );
Re: [PATCH v5 2/4] mfd: smpro-mfd: Adds Ampere's Altra SMpro MFD driver
Quoted 6 lines · Guenter Roeck
Quoted 4 lines · Quan Nguyen
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]>
Quoted 7 lines
Maybe that has been discussed, but is there anything else besides hardware monitoring connected to this i2c interface, and are there more child drivers coming ? I don't find the BMC Interface Specification mentioned in the documentation patch, but the hardware specification seems to suggest that the i2c bus is dedicated for hardware monitoring. If there is no other child driver, an mfd driver would not make sense. Thanks for the comment.
Yes, there are more child drivers coming, one is to provide error monitoring and the other to provide other miscellaneous features. The child drivers used the register map exposed by this mfd driver.
-Quan
Quoted 141 lines
Thanks,
GuenterQuoted 137 lines
---
Changes in v5:
?? + Dropped the use of simple-mfd-i2c driver [Quan]
?? + Introduceddrivers/mfd/smpro-mfd.cdriver 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:
?? + NoneChanges 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 | 74 +++++++++++++++++++++++++++++++++++++++++? 3 files changed, 87 insertions(+)
? create mode 100644drivers/mfd/smpro-mfd.cdrivers/mfd/Kconfig +0
-0@@ -77,6 +77,18 @@ config MFD_AS3711????? help
??????? Support for the AS3711 PMIC from AMSdrivers/mfd/Kconfig +12
-0+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"
????? selectMFD_COREdrivers/mfd/Makefile +0
-0@@ -268,6 +268,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.odrivers/mfd/smpro-mfd.c new file +58
-0@@ -0,0 +1,74 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Ampere Altra Family SMPro MFD - I2C +* +* Copyright (c) 2021, Ampere Computing LLC +* +* Author: Quan Nguyen <[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},
+??? {}drivers/mfd/smpro-mfd.c new file +15
-0+}; +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" );
PATCH v5 3/4 hwmon: smpro: Add Ampere's Altra smpro-hwmon driver
In reply to Quan NguyenThis 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.
---
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
drivers/hwmon/Kconfig +8 -0
@@ -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
drivers/hwmon/Makefile +1 -0
@@ -175,6 +175,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
drivers/hwmon/smpro-hwmon.c new file +463 -0
463 lines not on this page · raw message
Signature · 1 line
2.28.0
Re: [PATCH v5 3/4] hwmon: smpro: Add Ampere's Altra smpro-hwmon driver
Quoted 5 lines · Quan Nguyen
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]>
For my reference:
Quoted 543 lines
---
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:
+ Returnedregmap_read()error code [Guenter]Changes in v3:
+ Handled negative temperature value [Guenter]
+ Returned-ENODEVif Manufacturer ID is wrong [Guenter]
+ Refactoredsmpro_read_string()andsmpro_temp_read()[Guenter]
+ Removedsmpro_write()function [Guenter]
+ Added minor refactor changes [Quan]Changes in v2:
+ Removed "virtual" sensors [Guenter]
+ ReportedSOC_TDPas "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]
+ Addedis_visible()support [Guenter]
+ UsedHWMON_CHANNEL_INFO()macro and LABEL attributes [Guenter]
+ Madeis_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.cdrivers/hwmon/Kconfig +8
-0@@ -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 SPIdrivers/hwmon/Makefile +1
-0@@ -175,6 +175,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.odrivers/hwmon/smpro-hwmon.c new file +463
-0@@ -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" );
Re: [PATCH v5 3/4] hwmon: smpro: Add Ampere's Altra smpro-hwmon driver
Quoted 11 lines · Guenter Roeck
Quoted 5 lines · Quan Nguyen
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]>For my reference:
Reviewed-by Guenter Roeck <[email protected]>
Thanks for the review.
- Quan
Quoted 556 lines
Quoted 555 lines
---
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:
?? + Returnedregmap_read()error code [Guenter]Changes in v3:
?? + Handled negative temperature value [Guenter]
?? + Returned-ENODEVif Manufacturer ID is wrong [Guenter] ?? + Refactoredsmpro_read_string()andsmpro_temp_read()[Guenter] ?? + Removedsmpro_write()function [Guenter]
?? + Added minor refactor changes [Quan]Changes in v2:
?? + Removed "virtual" sensors [Guenter]
?? + ReportedSOC_TDPas "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] ?? + Addedis_visible()support [Guenter]
?? + UsedHWMON_CHANNEL_INFO()macro and LABEL attributes [Guenter] ?? + Madeis_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 100644drivers/hwmon/smpro-hwmon.cdrivers/hwmon/Kconfig +0
-0@@ -67,6 +67,14 @@ config SENSORS_ABITUGURU3??????? This driver can also be built as a module. If so, the module ??????? will be called abituguru3.
drivers/hwmon/Kconfig +8
-0+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 SPIdrivers/hwmon/Makefile +0
-0@@ -175,6 +175,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.odrivers/hwmon/smpro-hwmon.c new file +206
-0@@ -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)
drivers/hwmon/smpro-hwmon.c new file +8
-0+{ +??? 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;
+??? casehwmon_temp_crit:
+??????? ret = regmap_read(hwmon->regmap,
temperature[channel].reg_ext, &value);
+??????? if (ret)
+??????????? return ret;
+??????? break;
+??? default:
+??????? return-EOPNOTSUPP;
+??? }drivers/hwmon/smpro-hwmon.c new file +6
-0+ +??? *val = sign_extend32(value, 8) * 1000; +??? return 0; +} + +static int smpro_read_in(struct device *dev, u32 attr, int channel,long *val)
drivers/hwmon/smpro-hwmon.c new file +19
-0+{ +??? 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)
drivers/hwmon/smpro-hwmon.c new file +8
-0+{ +??? 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;
+??? }drivers/hwmon/smpro-hwmon.c new file +3
-0+} + +static int smpro_read_power(struct device *dev, u32 attr, intchannel, long
*val_pwr)drivers/hwmon/smpro-hwmon.c new file +12
-0+{ +??? 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;drivers/hwmon/smpro-hwmon.c new file +27
-0+ +??????? *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_typestype,
+???????????????? u32 attr, int channel, const char **str)drivers/hwmon/smpro-hwmon.c new file +49
-0+{ +??? 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_typestype,
+??????????????? u32 attr, int channel)drivers/hwmon/smpro-hwmon.c new file +12
-0+{ +??? 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;
+??? }drivers/hwmon/smpro-hwmon.c new file +57
-0+ +??? 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;drivers/hwmon/smpro-hwmon.c new file +6
-0+ +??? 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);drivers/hwmon/smpro-hwmon.c new file +17
-0+ +??? 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" );
PATCH v5 4/4 docs: hwmon: (smpro-hwmon) Add documentation
In reply to Quan NguyenAdd documentation for the Ampere(R)'s Altra(R) SMpro hwmon driver.
---
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
Documentation/hwmon/index.rst +1 -0
@@ -172,6 +172,7 @@ Hardware Monitoring Kernel Drivers sis5595 sl28cpld smm665 + smpro-hwmon smsc47b397 smsc47m192 smsc47m1
Documentation/hwmon/smpro-hwmon.rst new file +101 -0
101 lines not on this page · raw message
Signature · 1 line
2.28.0