Skip to content

Commit 443b39c

Browse files
mwallegroeck
authored andcommitted
hwmon: add SMARC-sAM67 support
Add a new driver for the Kontron SMARC-sAM67 board management controller. It has two voltage sensors and one temperature sensor. Signed-off-by: Michael Walle <mwalle@kernel.org> Link: https://lore.kernel.org/r/20250912120745.2295115-7-mwalle@kernel.org [groeck: Added sa67 to index.rst] Signed-off-by: Guenter Roeck <linux@roeck-us.net>
1 parent 0f6eae8 commit 443b39c

6 files changed

Lines changed: 215 additions & 0 deletions

File tree

Documentation/hwmon/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ Hardware Monitoring Kernel Drivers
214214
q54sj108a2
215215
qnap-mcu-hwmon
216216
raspberrypi-hwmon
217+
sa67
217218
sbrmi
218219
sbtsi_temp
219220
sch5627

Documentation/hwmon/sa67.rst

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
.. SPDX-License-Identifier: GPL-2.0-only
2+
3+
Kernel driver sa67mcu
4+
=====================
5+
6+
Supported chips:
7+
8+
* Kontron sa67mcu
9+
10+
Prefix: 'sa67mcu'
11+
12+
Datasheet: not available
13+
14+
Authors: Michael Walle <mwalle@kernel.org>
15+
16+
Description
17+
-----------
18+
19+
The sa67mcu is a board management controller which also exposes a hardware
20+
monitoring controller.
21+
22+
The controller has two voltage and one temperature sensor. The values are
23+
hold in two 8 bit registers to form one 16 bit value. Reading the lower byte
24+
will also capture the high byte to make the access atomic. The unit of the
25+
volatge sensors are 1mV and the unit of the temperature sensor is 0.1degC.
26+
27+
Sysfs entries
28+
-------------
29+
30+
The following attributes are supported.
31+
32+
======================= ========================================================
33+
in0_label "VDDIN"
34+
in0_input Measured VDDIN voltage.
35+
36+
in1_label "VDD_RTC"
37+
in1_input Measured VDD_RTC voltage.
38+
39+
temp1_input MCU temperature. Roughly the board temperature.
40+
======================= ========================================================
41+

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23231,6 +23231,7 @@ F: Documentation/devicetree/bindings/mfd/kontron,sl28cpld.yaml
2323123231
F: Documentation/devicetree/bindings/pwm/kontron,sl28cpld-pwm.yaml
2323223232
F: Documentation/devicetree/bindings/watchdog/kontron,sl28cpld-wdt.yaml
2323323233
F: drivers/gpio/gpio-sl28cpld.c
23234+
F: drivers/hwmon/sa67mcu-hwmon.c
2323423235
F: drivers/hwmon/sl28cpld-hwmon.c
2323523236
F: drivers/irqchip/irq-sl28cpld.c
2323623237
F: drivers/pwm/pwm-sl28cpld.c

drivers/hwmon/Kconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1905,6 +1905,16 @@ config SENSORS_RASPBERRYPI_HWMON
19051905
This driver can also be built as a module. If so, the module
19061906
will be called raspberrypi-hwmon.
19071907

1908+
config SENSORS_SA67MCU
1909+
tristate "Kontron sa67mcu hardware monitoring driver"
1910+
depends on MFD_SL28CPLD || COMPILE_TEST
1911+
help
1912+
If you say yes here you get support for the voltage and temperature
1913+
monitor of the sa67 board management controller.
1914+
1915+
This driver can also be built as a module. If so, the module
1916+
will be called sa67mcu-hwmon.
1917+
19081918
config SENSORS_SL28CPLD
19091919
tristate "Kontron sl28cpld hardware monitoring driver"
19101920
depends on MFD_SL28CPLD || COMPILE_TEST

drivers/hwmon/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ obj-$(CONFIG_SENSORS_PT5161L) += pt5161l.o
197197
obj-$(CONFIG_SENSORS_PWM_FAN) += pwm-fan.o
198198
obj-$(CONFIG_SENSORS_QNAP_MCU_HWMON) += qnap-mcu-hwmon.o
199199
obj-$(CONFIG_SENSORS_RASPBERRYPI_HWMON) += raspberrypi-hwmon.o
200+
obj-$(CONFIG_SENSORS_SA67MCU) += sa67mcu-hwmon.o
200201
obj-$(CONFIG_SENSORS_SBTSI) += sbtsi_temp.o
201202
obj-$(CONFIG_SENSORS_SBRMI) += sbrmi.o
202203
obj-$(CONFIG_SENSORS_SCH56XX_COMMON)+= sch56xx-common.o

drivers/hwmon/sa67mcu-hwmon.c

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
// SPDX-License-Identifier: GPL-2.0-only
2+
/*
3+
* sl67mcu hardware monitoring driver
4+
*
5+
* Copyright 2025 Kontron Europe GmbH
6+
*/
7+
8+
#include <linux/bitfield.h>
9+
#include <linux/hwmon.h>
10+
#include <linux/kernel.h>
11+
#include <linux/mod_devicetable.h>
12+
#include <linux/module.h>
13+
#include <linux/platform_device.h>
14+
#include <linux/property.h>
15+
#include <linux/regmap.h>
16+
17+
#define SA67MCU_VOLTAGE(n) (0x00 + ((n) * 2))
18+
#define SA67MCU_TEMP(n) (0x04 + ((n) * 2))
19+
20+
struct sa67mcu_hwmon {
21+
struct regmap *regmap;
22+
u32 offset;
23+
};
24+
25+
static int sa67mcu_hwmon_read(struct device *dev,
26+
enum hwmon_sensor_types type, u32 attr,
27+
int channel, long *input)
28+
{
29+
struct sa67mcu_hwmon *hwmon = dev_get_drvdata(dev);
30+
unsigned int offset;
31+
u8 reg[2];
32+
int ret;
33+
34+
switch (type) {
35+
case hwmon_in:
36+
switch (attr) {
37+
case hwmon_in_input:
38+
offset = hwmon->offset + SA67MCU_VOLTAGE(channel);
39+
break;
40+
default:
41+
return -EOPNOTSUPP;
42+
}
43+
break;
44+
case hwmon_temp:
45+
switch (attr) {
46+
case hwmon_temp_input:
47+
offset = hwmon->offset + SA67MCU_TEMP(channel);
48+
break;
49+
default:
50+
return -EOPNOTSUPP;
51+
}
52+
break;
53+
default:
54+
return -EOPNOTSUPP;
55+
}
56+
57+
/* Reading the low byte will capture the value */
58+
ret = regmap_bulk_read(hwmon->regmap, offset, reg, ARRAY_SIZE(reg));
59+
if (ret)
60+
return ret;
61+
62+
*input = reg[1] << 8 | reg[0];
63+
64+
/* Temperatures are s16 and in 0.1degC steps. */
65+
if (type == hwmon_temp)
66+
*input = sign_extend32(*input, 15) * 100;
67+
68+
return 0;
69+
}
70+
71+
static const struct hwmon_channel_info * const sa67mcu_hwmon_info[] = {
72+
HWMON_CHANNEL_INFO(in,
73+
HWMON_I_INPUT | HWMON_I_LABEL,
74+
HWMON_I_INPUT | HWMON_I_LABEL),
75+
HWMON_CHANNEL_INFO(temp, HWMON_T_INPUT),
76+
NULL
77+
};
78+
79+
static const char *const sa67mcu_hwmon_in_labels[] = {
80+
"VDDIN",
81+
"VDD_RTC",
82+
};
83+
84+
static int sa67mcu_hwmon_read_string(struct device *dev,
85+
enum hwmon_sensor_types type, u32 attr,
86+
int channel, const char **str)
87+
{
88+
switch (type) {
89+
case hwmon_in:
90+
switch (attr) {
91+
case hwmon_in_label:
92+
*str = sa67mcu_hwmon_in_labels[channel];
93+
return 0;
94+
default:
95+
return -EOPNOTSUPP;
96+
}
97+
default:
98+
return -EOPNOTSUPP;
99+
}
100+
}
101+
102+
static const struct hwmon_ops sa67mcu_hwmon_ops = {
103+
.visible = 0444,
104+
.read = sa67mcu_hwmon_read,
105+
.read_string = sa67mcu_hwmon_read_string,
106+
};
107+
108+
static const struct hwmon_chip_info sa67mcu_hwmon_chip_info = {
109+
.ops = &sa67mcu_hwmon_ops,
110+
.info = sa67mcu_hwmon_info,
111+
};
112+
113+
static int sa67mcu_hwmon_probe(struct platform_device *pdev)
114+
{
115+
struct sa67mcu_hwmon *hwmon;
116+
struct device *hwmon_dev;
117+
int ret;
118+
119+
if (!pdev->dev.parent)
120+
return -ENODEV;
121+
122+
hwmon = devm_kzalloc(&pdev->dev, sizeof(*hwmon), GFP_KERNEL);
123+
if (!hwmon)
124+
return -ENOMEM;
125+
126+
hwmon->regmap = dev_get_regmap(pdev->dev.parent, NULL);
127+
if (!hwmon->regmap)
128+
return -ENODEV;
129+
130+
ret = device_property_read_u32(&pdev->dev, "reg", &hwmon->offset);
131+
if (ret)
132+
return -EINVAL;
133+
134+
hwmon_dev = devm_hwmon_device_register_with_info(&pdev->dev,
135+
"sa67mcu_hwmon", hwmon,
136+
&sa67mcu_hwmon_chip_info,
137+
NULL);
138+
if (IS_ERR(hwmon_dev))
139+
dev_err(&pdev->dev, "failed to register as hwmon device");
140+
141+
return PTR_ERR_OR_ZERO(hwmon_dev);
142+
}
143+
144+
static const struct of_device_id sa67mcu_hwmon_of_match[] = {
145+
{ .compatible = "kontron,sa67mcu-hwmon", },
146+
{}
147+
};
148+
MODULE_DEVICE_TABLE(of, sa67mcu_hwmon_of_match);
149+
150+
static struct platform_driver sa67mcu_hwmon_driver = {
151+
.probe = sa67mcu_hwmon_probe,
152+
.driver = {
153+
.name = "sa67mcu-hwmon",
154+
.of_match_table = sa67mcu_hwmon_of_match,
155+
},
156+
};
157+
module_platform_driver(sa67mcu_hwmon_driver);
158+
159+
MODULE_DESCRIPTION("sa67mcu Hardware Monitoring Driver");
160+
MODULE_AUTHOR("Michael Walle <mwalle@kernel.org>");
161+
MODULE_LICENSE("GPL");

0 commit comments

Comments
 (0)