Skip to content

Commit 1e40633

Browse files
metormotegroeck
authored andcommitted
hwmon: (pmbus) Add pmbus driver for MAX15301
Add pmbus driver support for Maxim MAX15301 InTune Automatically Compensated Digital PoL Controller with Driver and PMBus Telemetry Even though the specification does not specifically mention it, extensive empirical testing has revealed that auto-detection of limit-registers will fail in a random fashion unless the delay parameter is set to above about 80us. The default delay is set to 100us to include some safety margin. This patch is tested on a Flex BMR461 converter module. Signed-off-by: Erik Rosen <erik.rosen@metormote.com> Link: https://lore.kernel.org/r/20210419101251.24840-1-erik.rosen@metormote.com [groeck: Added rationale for delay to driver header] Signed-off-by: Guenter Roeck <linux@roeck-us.net>
1 parent bab10bf commit 1e40633

6 files changed

Lines changed: 294 additions & 0 deletions

File tree

Documentation/hwmon/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ Hardware Monitoring Kernel Drivers
115115
ltc4260
116116
ltc4261
117117
max127
118+
max15301
118119
max16064
119120
max16065
120121
max1619

Documentation/hwmon/max15301.rst

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
.. SPDX-License-Identifier: GPL-2.0
2+
3+
Kernel driver max15301
4+
======================
5+
6+
Supported chips:
7+
8+
* Maxim MAX15301
9+
10+
Prefix: 'max15301', 'bmr461'
11+
12+
Addresses scanned: -
13+
14+
Datasheet: https://datasheets.maximintegrated.com/en/ds/MAX15301.pdf
15+
16+
Author: Erik Rosen <erik.rosen@metormote.com>
17+
18+
19+
Description
20+
-----------
21+
22+
This driver supports hardware monitoring for Maxim MAX15301 controller chip and
23+
compatible modules.
24+
25+
The driver is a client driver to the core PMBus driver. Please see
26+
Documentation/hwmon/pmbus.rst and Documentation.hwmon/pmbus-core for details
27+
on PMBus client drivers.
28+
29+
30+
Usage Notes
31+
-----------
32+
33+
This driver does not auto-detect devices. You will have to instantiate the
34+
devices explicitly. Please see Documentation/i2c/instantiating-devices.rst for
35+
details.
36+
37+
38+
Platform data support
39+
---------------------
40+
41+
The driver supports standard PMBus driver platform data.
42+
43+
44+
Module parameters
45+
-----------------
46+
47+
delay
48+
-----
49+
50+
The controller requires a minimum interval between I2C bus accesses.
51+
The default interval is set to 100 us. For manual override, the driver
52+
provides a writeable module parameter, 'delay', which can be used to
53+
set the interval to a value between 0 and 65,535 microseconds.
54+
55+
56+
Sysfs entries
57+
-------------
58+
59+
The following attributes are supported. Limits are read-write; all other
60+
attributes are read-only.
61+
62+
======================= ========================================================
63+
in1_label "vin"
64+
in1_input Measured input voltage.
65+
in1_lcrit Critical minimum input voltage.
66+
in1_crit Critical maximum input voltage.
67+
in1_lcrit_alarm Input voltage critical low alarm.
68+
in1_crit_alarm Input voltage critical high alarm.
69+
70+
in2_label "vout1"
71+
in2_input Measured output voltage.
72+
in2_lcrit Critical minimum output Voltage.
73+
in2_crit Critical maximum output voltage.
74+
in2_lcrit_alarm Critical output voltage critical low alarm.
75+
in2_crit_alarm Critical output voltage critical high alarm.
76+
77+
curr1_label "iout1"
78+
curr1_input Measured output current.
79+
curr1_crit Critical maximum output current.
80+
curr1_crit_alarm Output current critical high alarm.
81+
82+
temp1_input Measured maximum temperature of all phases.
83+
temp1_max Maximum temperature limit.
84+
temp1_max_alarm High temperature alarm.
85+
temp1_crit Critical maximum temperature limit.
86+
temp1_crit_alarm Critical maximum temperature alarm.
87+
======================= ========================================================

MAINTAINERS

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10791,6 +10791,13 @@ S: Orphan
1079110791
F: drivers/video/fbdev/matrox/matroxfb_*
1079210792
F: include/uapi/linux/matroxfb.h
1079310793

10794+
MAX15301 DRIVER
10795+
M: Daniel Nilsson <daniel.nilsson@flex.com>
10796+
L: linux-hwmon@vger.kernel.org
10797+
S: Maintained
10798+
F: Documentation/hwmon/max15301.rst
10799+
F: drivers/hwmon/pmbus/max15301.c
10800+
1079410801
MAX16065 HARDWARE MONITOR DRIVER
1079510802
M: Guenter Roeck <linux@roeck-us.net>
1079610803
L: linux-hwmon@vger.kernel.org

drivers/hwmon/pmbus/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,15 @@ config SENSORS_LTC3815
176176
This driver can also be built as a module. If so, the module will
177177
be called ltc3815.
178178

179+
config SENSORS_MAX15301
180+
tristate "Maxim MAX15301"
181+
help
182+
If you say yes here you get hardware monitoring support for Maxim
183+
MAX15301, as well as for Flex BMR461.
184+
185+
This driver can also be built as a module. If so, the module will
186+
be called max15301.
187+
179188
config SENSORS_MAX16064
180189
tristate "Maxim MAX16064"
181190
help

drivers/hwmon/pmbus/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ obj-$(CONFIG_SENSORS_ISL68137) += isl68137.o
2020
obj-$(CONFIG_SENSORS_LM25066) += lm25066.o
2121
obj-$(CONFIG_SENSORS_LTC2978) += ltc2978.o
2222
obj-$(CONFIG_SENSORS_LTC3815) += ltc3815.o
23+
obj-$(CONFIG_SENSORS_MAX15301) += max15301.o
2324
obj-$(CONFIG_SENSORS_MAX16064) += max16064.o
2425
obj-$(CONFIG_SENSORS_MAX16601) += max16601.o
2526
obj-$(CONFIG_SENSORS_MAX20730) += max20730.o

drivers/hwmon/pmbus/max15301.c

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
// SPDX-License-Identifier: GPL-2.0-or-later
2+
/*
3+
* Hardware monitoring driver for Maxim MAX15301
4+
*
5+
* Copyright (c) 2021 Flextronics International Sweden AB
6+
*
7+
* Even though the specification does not specifically mention it,
8+
* extensive empirical testing has revealed that auto-detection of
9+
* limit-registers will fail in a random fashion unless the delay
10+
* parameter is set to above about 80us. The default delay is set
11+
* to 100us to include some safety margin.
12+
*/
13+
14+
#include <linux/kernel.h>
15+
#include <linux/module.h>
16+
#include <linux/init.h>
17+
#include <linux/err.h>
18+
#include <linux/slab.h>
19+
#include <linux/i2c.h>
20+
#include <linux/ktime.h>
21+
#include <linux/delay.h>
22+
#include <linux/pmbus.h>
23+
#include "pmbus.h"
24+
25+
static const struct i2c_device_id max15301_id[] = {
26+
{"bmr461", 0},
27+
{"max15301", 0},
28+
{}
29+
};
30+
MODULE_DEVICE_TABLE(i2c, max15301_id);
31+
32+
struct max15301_data {
33+
int id;
34+
ktime_t access; /* Chip access time */
35+
int delay; /* Delay between chip accesses in us */
36+
struct pmbus_driver_info info;
37+
};
38+
39+
#define to_max15301_data(x) container_of(x, struct max15301_data, info)
40+
41+
#define MAX15301_WAIT_TIME 100 /* us */
42+
43+
static ushort delay = MAX15301_WAIT_TIME;
44+
module_param(delay, ushort, 0644);
45+
MODULE_PARM_DESC(delay, "Delay between chip accesses in us");
46+
47+
static struct max15301_data max15301_data = {
48+
.info = {
49+
.pages = 1,
50+
.func[0] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT
51+
| PMBUS_HAVE_VIN | PMBUS_HAVE_STATUS_INPUT
52+
| PMBUS_HAVE_TEMP | PMBUS_HAVE_TEMP2
53+
| PMBUS_HAVE_STATUS_TEMP
54+
| PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT,
55+
}
56+
};
57+
58+
/* This chip needs a delay between accesses */
59+
static inline void max15301_wait(const struct max15301_data *data)
60+
{
61+
if (data->delay) {
62+
s64 delta = ktime_us_delta(ktime_get(), data->access);
63+
64+
if (delta < data->delay)
65+
udelay(data->delay - delta);
66+
}
67+
}
68+
69+
static int max15301_read_word_data(struct i2c_client *client, int page,
70+
int phase, int reg)
71+
{
72+
const struct pmbus_driver_info *info = pmbus_get_driver_info(client);
73+
struct max15301_data *data = to_max15301_data(info);
74+
int ret;
75+
76+
if (page > 0)
77+
return -ENXIO;
78+
79+
if (reg >= PMBUS_VIRT_BASE)
80+
return -ENXIO;
81+
82+
max15301_wait(data);
83+
ret = pmbus_read_word_data(client, page, phase, reg);
84+
data->access = ktime_get();
85+
86+
return ret;
87+
}
88+
89+
static int max15301_read_byte_data(struct i2c_client *client, int page, int reg)
90+
{
91+
const struct pmbus_driver_info *info = pmbus_get_driver_info(client);
92+
struct max15301_data *data = to_max15301_data(info);
93+
int ret;
94+
95+
if (page > 0)
96+
return -ENXIO;
97+
98+
max15301_wait(data);
99+
ret = pmbus_read_byte_data(client, page, reg);
100+
data->access = ktime_get();
101+
102+
return ret;
103+
}
104+
105+
static int max15301_write_word_data(struct i2c_client *client, int page, int reg,
106+
u16 word)
107+
{
108+
const struct pmbus_driver_info *info = pmbus_get_driver_info(client);
109+
struct max15301_data *data = to_max15301_data(info);
110+
int ret;
111+
112+
if (page > 0)
113+
return -ENXIO;
114+
115+
if (reg >= PMBUS_VIRT_BASE)
116+
return -ENXIO;
117+
118+
max15301_wait(data);
119+
ret = pmbus_write_word_data(client, page, reg, word);
120+
data->access = ktime_get();
121+
122+
return ret;
123+
}
124+
125+
static int max15301_write_byte(struct i2c_client *client, int page, u8 value)
126+
{
127+
const struct pmbus_driver_info *info = pmbus_get_driver_info(client);
128+
struct max15301_data *data = to_max15301_data(info);
129+
int ret;
130+
131+
if (page > 0)
132+
return -ENXIO;
133+
134+
max15301_wait(data);
135+
ret = pmbus_write_byte(client, page, value);
136+
data->access = ktime_get();
137+
138+
return ret;
139+
}
140+
141+
static int max15301_probe(struct i2c_client *client)
142+
{
143+
int status;
144+
u8 device_id[I2C_SMBUS_BLOCK_MAX + 1];
145+
const struct i2c_device_id *mid;
146+
struct pmbus_driver_info *info = &max15301_data.info;
147+
148+
if (!i2c_check_functionality(client->adapter,
149+
I2C_FUNC_SMBUS_READ_BYTE_DATA
150+
| I2C_FUNC_SMBUS_BLOCK_DATA))
151+
return -ENODEV;
152+
153+
status = i2c_smbus_read_block_data(client, PMBUS_IC_DEVICE_ID, device_id);
154+
if (status < 0) {
155+
dev_err(&client->dev, "Failed to read Device Id\n");
156+
return status;
157+
}
158+
for (mid = max15301_id; mid->name[0]; mid++) {
159+
if (!strncasecmp(mid->name, device_id, strlen(mid->name)))
160+
break;
161+
}
162+
if (!mid->name[0]) {
163+
dev_err(&client->dev, "Unsupported device\n");
164+
return -ENODEV;
165+
}
166+
167+
max15301_data.delay = delay;
168+
169+
info->read_byte_data = max15301_read_byte_data;
170+
info->read_word_data = max15301_read_word_data;
171+
info->write_byte = max15301_write_byte;
172+
info->write_word_data = max15301_write_word_data;
173+
174+
return pmbus_do_probe(client, info);
175+
}
176+
177+
static struct i2c_driver max15301_driver = {
178+
.driver = {
179+
.name = "max15301",
180+
},
181+
.probe_new = max15301_probe,
182+
.id_table = max15301_id,
183+
};
184+
185+
module_i2c_driver(max15301_driver);
186+
187+
MODULE_AUTHOR("Erik Rosen <erik.rosen@metormote.com>");
188+
MODULE_DESCRIPTION("PMBus driver for Maxim MAX15301");
189+
MODULE_LICENSE("GPL");

0 commit comments

Comments
 (0)