Skip to content

Commit 7ad8966

Browse files
committed
Merge tag 'mfd-hwmon-leds-watchdog-v3.18' into hwmon-next
Immutable branch between MFD, HWMON, LEDs and Watchdog for v3.18
2 parents c08860f + 9643569 commit 7ad8966

13 files changed

Lines changed: 794 additions & 0 deletions

File tree

‎Documentation/hwmon/menf21bmc‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
Kernel driver menf21bmc_hwmon
2+
=============================
3+
4+
Supported chips:
5+
* MEN 14F021P00
6+
Prefix: 'menf21bmc_hwmon'
7+
Adresses scanned: -
8+
9+
Author: Andreas Werner <andreas.werner@men.de>
10+
11+
Description
12+
-----------
13+
14+
The menf21bmc is a Board Management Controller (BMC) which provides an I2C
15+
interface to the host to access the features implemented in the BMC.
16+
17+
This driver gives access to the voltage monitoring feature of the main
18+
voltages of the board.
19+
The voltage sensors are connected to the ADC inputs of the BMC which is
20+
a PIC16F917 Mikrocontroller.
21+
22+
Usage Notes
23+
-----------
24+
25+
This driver is part of the MFD driver named "menf21bmc" and does
26+
not auto-detect devices.
27+
You will have to instantiate the MFD driver explicitly.
28+
Please see Documentation/i2c/instantiating-devices for
29+
details.
30+
31+
Sysfs entries
32+
-------------
33+
34+
The following attributes are supported. All attributes are read only
35+
The Limits are read once by the driver.
36+
37+
in0_input +3.3V input voltage
38+
in1_input +5.0V input voltage
39+
in2_input +12.0V input voltage
40+
in3_input +5V Standby input voltage
41+
in4_input VBAT (on board battery)
42+
43+
in[0-4]_min Minimum voltage limit
44+
in[0-4]_max Maximum voltage limit
45+
46+
in0_label "MON_3_3V"
47+
in1_label "MON_5V"
48+
in2_label "MON_12V"
49+
in3_label "5V_STANDBY"
50+
in4_label "VBAT"

‎drivers/hwmon/Kconfig‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,16 @@ config SENSORS_MCP3021
839839
This driver can also be built as a module. If so, the module
840840
will be called mcp3021.
841841

842+
config SENSORS_MENF21BMC_HWMON
843+
tristate "MEN 14F021P00 BMC Hardware Monitoring"
844+
depends on MFD_MENF21BMC
845+
help
846+
Say Y here to include support for the MEN 14F021P00 BMC
847+
hardware monitoring.
848+
849+
This driver can also be built as a module. If so the module
850+
will be called menf21bmc_hwmon.
851+
842852
config SENSORS_ADCXX
843853
tristate "National Semiconductor ADCxxxSxxx"
844854
depends on SPI_MASTER

‎drivers/hwmon/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ obj-$(CONFIG_SENSORS_MAX6650) += max6650.o
115115
obj-$(CONFIG_SENSORS_MAX6697) += max6697.o
116116
obj-$(CONFIG_SENSORS_MC13783_ADC)+= mc13783-adc.o
117117
obj-$(CONFIG_SENSORS_MCP3021) += mcp3021.o
118+
obj-$(CONFIG_SENSORS_MENF21BMC_HWMON) += menf21bmc_hwmon.o
118119
obj-$(CONFIG_SENSORS_NCT6683) += nct6683.o
119120
obj-$(CONFIG_SENSORS_NCT6775) += nct6775.o
120121
obj-$(CONFIG_SENSORS_NTC_THERMISTOR) += ntc_thermistor.o

‎drivers/hwmon/menf21bmc_hwmon.c‎

Lines changed: 230 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,230 @@
1+
/*
2+
* MEN 14F021P00 Board Management Controller (BMC) hwmon driver.
3+
*
4+
* This is the core hwmon driver of the MEN 14F021P00 BMC.
5+
* The BMC monitors the board voltages which can be access with this
6+
* driver through sysfs.
7+
*
8+
* Copyright (C) 2014 MEN Mikro Elektronik Nuernberg GmbH
9+
*
10+
* This program is free software; you can redistribute it and/or modify it
11+
* under the terms of the GNU General Public License as published by the
12+
* Free Software Foundation; either version 2 of the License, or (at your
13+
* option) any later version.
14+
*/
15+
16+
#include <linux/module.h>
17+
#include <linux/kernel.h>
18+
#include <linux/platform_device.h>
19+
#include <linux/hwmon.h>
20+
#include <linux/hwmon-sysfs.h>
21+
#include <linux/jiffies.h>
22+
#include <linux/slab.h>
23+
#include <linux/i2c.h>
24+
25+
#define DRV_NAME "menf21bmc_hwmon"
26+
27+
#define BMC_VOLT_COUNT 5
28+
#define MENF21BMC_V33 0
29+
#define MENF21BMC_V5 1
30+
#define MENF21BMC_V12 2
31+
#define MENF21BMC_V5_SB 3
32+
#define MENF21BMC_VBAT 4
33+
34+
#define IDX_TO_VOLT_MIN_CMD(idx) (0x40 + idx)
35+
#define IDX_TO_VOLT_MAX_CMD(idx) (0x50 + idx)
36+
#define IDX_TO_VOLT_INP_CMD(idx) (0x60 + idx)
37+
38+
struct menf21bmc_hwmon {
39+
bool valid;
40+
struct i2c_client *i2c_client;
41+
unsigned long last_update;
42+
int in_val[BMC_VOLT_COUNT];
43+
int in_min[BMC_VOLT_COUNT];
44+
int in_max[BMC_VOLT_COUNT];
45+
};
46+
47+
static const char *const input_names[] = {
48+
[MENF21BMC_V33] = "MON_3_3V",
49+
[MENF21BMC_V5] = "MON_5V",
50+
[MENF21BMC_V12] = "MON_12V",
51+
[MENF21BMC_V5_SB] = "5V_STANDBY",
52+
[MENF21BMC_VBAT] = "VBAT"
53+
};
54+
55+
static struct menf21bmc_hwmon *menf21bmc_hwmon_update(struct device *dev)
56+
{
57+
int i;
58+
int val;
59+
struct menf21bmc_hwmon *drv_data = dev_get_drvdata(dev);
60+
struct menf21bmc_hwmon *data_ret = drv_data;
61+
62+
if (time_after(jiffies, drv_data->last_update + HZ)
63+
|| !drv_data->valid) {
64+
for (i = 0; i < BMC_VOLT_COUNT; i++) {
65+
val = i2c_smbus_read_word_data(drv_data->i2c_client,
66+
IDX_TO_VOLT_INP_CMD(i));
67+
if (val < 0) {
68+
data_ret = ERR_PTR(val);
69+
goto abort;
70+
}
71+
drv_data->in_val[i] = val;
72+
}
73+
drv_data->last_update = jiffies;
74+
drv_data->valid = true;
75+
}
76+
abort:
77+
return data_ret;
78+
}
79+
80+
static int menf21bmc_hwmon_get_volt_limits(struct menf21bmc_hwmon *drv_data)
81+
{
82+
int i, val;
83+
84+
for (i = 0; i < BMC_VOLT_COUNT; i++) {
85+
val = i2c_smbus_read_word_data(drv_data->i2c_client,
86+
IDX_TO_VOLT_MIN_CMD(i));
87+
if (val < 0)
88+
return val;
89+
90+
drv_data->in_min[i] = val;
91+
92+
val = i2c_smbus_read_word_data(drv_data->i2c_client,
93+
IDX_TO_VOLT_MAX_CMD(i));
94+
if (val < 0)
95+
return val;
96+
97+
drv_data->in_max[i] = val;
98+
}
99+
return 0;
100+
}
101+
102+
static ssize_t
103+
show_label(struct device *dev, struct device_attribute *devattr, char *buf)
104+
{
105+
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
106+
107+
return sprintf(buf, "%s\n", input_names[attr->index]);
108+
}
109+
110+
static ssize_t
111+
show_in(struct device *dev, struct device_attribute *devattr, char *buf)
112+
{
113+
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
114+
struct menf21bmc_hwmon *drv_data = menf21bmc_hwmon_update(dev);
115+
116+
if (IS_ERR(drv_data))
117+
return PTR_ERR(drv_data);
118+
119+
return sprintf(buf, "%d\n", drv_data->in_val[attr->index]);
120+
}
121+
122+
static ssize_t
123+
show_min(struct device *dev, struct device_attribute *devattr, char *buf)
124+
{
125+
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
126+
struct menf21bmc_hwmon *drv_data = dev_get_drvdata(dev);
127+
128+
return sprintf(buf, "%d\n", drv_data->in_min[attr->index]);
129+
}
130+
131+
static ssize_t
132+
show_max(struct device *dev, struct device_attribute *devattr, char *buf)
133+
{
134+
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
135+
struct menf21bmc_hwmon *drv_data = dev_get_drvdata(dev);
136+
137+
return sprintf(buf, "%d\n", drv_data->in_max[attr->index]);
138+
}
139+
140+
#define create_voltage_sysfs(idx) \
141+
static SENSOR_DEVICE_ATTR(in##idx##_input, S_IRUGO, \
142+
show_in, NULL, idx); \
143+
static SENSOR_DEVICE_ATTR(in##idx##_min, S_IRUGO, \
144+
show_min, NULL, idx); \
145+
static SENSOR_DEVICE_ATTR(in##idx##_max, S_IRUGO, \
146+
show_max, NULL, idx); \
147+
static SENSOR_DEVICE_ATTR(in##idx##_label, S_IRUGO, \
148+
show_label, NULL, idx);
149+
150+
create_voltage_sysfs(0);
151+
create_voltage_sysfs(1);
152+
create_voltage_sysfs(2);
153+
create_voltage_sysfs(3);
154+
create_voltage_sysfs(4);
155+
156+
static struct attribute *menf21bmc_hwmon_attrs[] = {
157+
&sensor_dev_attr_in0_input.dev_attr.attr,
158+
&sensor_dev_attr_in0_min.dev_attr.attr,
159+
&sensor_dev_attr_in0_max.dev_attr.attr,
160+
&sensor_dev_attr_in0_label.dev_attr.attr,
161+
162+
&sensor_dev_attr_in1_input.dev_attr.attr,
163+
&sensor_dev_attr_in1_min.dev_attr.attr,
164+
&sensor_dev_attr_in1_max.dev_attr.attr,
165+
&sensor_dev_attr_in1_label.dev_attr.attr,
166+
167+
&sensor_dev_attr_in2_input.dev_attr.attr,
168+
&sensor_dev_attr_in2_min.dev_attr.attr,
169+
&sensor_dev_attr_in2_max.dev_attr.attr,
170+
&sensor_dev_attr_in2_label.dev_attr.attr,
171+
172+
&sensor_dev_attr_in3_input.dev_attr.attr,
173+
&sensor_dev_attr_in3_min.dev_attr.attr,
174+
&sensor_dev_attr_in3_max.dev_attr.attr,
175+
&sensor_dev_attr_in3_label.dev_attr.attr,
176+
177+
&sensor_dev_attr_in4_input.dev_attr.attr,
178+
&sensor_dev_attr_in4_min.dev_attr.attr,
179+
&sensor_dev_attr_in4_max.dev_attr.attr,
180+
&sensor_dev_attr_in4_label.dev_attr.attr,
181+
NULL
182+
};
183+
184+
ATTRIBUTE_GROUPS(menf21bmc_hwmon);
185+
186+
static int menf21bmc_hwmon_probe(struct platform_device *pdev)
187+
{
188+
int ret;
189+
struct menf21bmc_hwmon *drv_data;
190+
struct i2c_client *i2c_client = to_i2c_client(pdev->dev.parent);
191+
struct device *hwmon_dev;
192+
193+
drv_data = devm_kzalloc(&pdev->dev, sizeof(struct menf21bmc_hwmon),
194+
GFP_KERNEL);
195+
if (!drv_data)
196+
return -ENOMEM;
197+
198+
drv_data->i2c_client = i2c_client;
199+
200+
ret = menf21bmc_hwmon_get_volt_limits(drv_data);
201+
if (ret) {
202+
dev_err(&pdev->dev, "failed to read sensor limits");
203+
return ret;
204+
}
205+
206+
hwmon_dev = devm_hwmon_device_register_with_groups(&pdev->dev,
207+
"menf21bmc", drv_data,
208+
menf21bmc_hwmon_groups);
209+
if (IS_ERR(hwmon_dev))
210+
return PTR_ERR(hwmon_dev);
211+
212+
dev_info(&pdev->dev, "MEN 14F021P00 BMC hwmon device enabled");
213+
214+
return 0;
215+
}
216+
217+
static struct platform_driver menf21bmc_hwmon = {
218+
.probe = menf21bmc_hwmon_probe,
219+
.driver = {
220+
.name = DRV_NAME,
221+
.owner = THIS_MODULE,
222+
},
223+
};
224+
225+
module_platform_driver(menf21bmc_hwmon);
226+
227+
MODULE_AUTHOR("Andreas Werner <andreas.werner@men.de>");
228+
MODULE_DESCRIPTION("MEN 14F021P00 BMC hwmon");
229+
MODULE_LICENSE("GPL v2");
230+
MODULE_ALIAS("platform:menf21bmc_hwmon");

‎drivers/leds/Kconfig‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,15 @@ config LEDS_OT200
468468
This option enables support for the LEDs on the Bachmann OT200.
469469
Say Y to enable LEDs on the Bachmann OT200.
470470

471+
config LEDS_MENF21BMC
472+
tristate "LED support for the MEN 14F021P00 BMC"
473+
depends on LEDS_CLASS && MFD_MENF21BMC
474+
help
475+
Say Y here to include support for the MEN 14F021P00 BMC LEDs.
476+
477+
This driver can also be built as a module. If so the module
478+
will be called leds-menf21bmc.
479+
471480
comment "LED driver for blink(1) USB RGB LED is under Special HID drivers (HID_THINGM)"
472481

473482
config LEDS_BLINKM

‎drivers/leds/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ obj-$(CONFIG_LEDS_MAX8997) += leds-max8997.o
5454
obj-$(CONFIG_LEDS_LM355x) += leds-lm355x.o
5555
obj-$(CONFIG_LEDS_BLINKM) += leds-blinkm.o
5656
obj-$(CONFIG_LEDS_VERSATILE) += leds-versatile.o
57+
obj-$(CONFIG_LEDS_MENF21BMC) += leds-menf21bmc.o
5758

5859
# LED SPI Drivers
5960
obj-$(CONFIG_LEDS_DAC124S085) += leds-dac124s085.o

0 commit comments

Comments
 (0)