2 * Hardware monitoring driver for Maxim MAX8688
4 * Copyright (c) 2011 Ericsson AB.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include <linux/kernel.h>
22 #include <linux/module.h>
23 #include <linux/init.h>
24 #include <linux/err.h>
25 #include <linux/i2c.h>
28 #define MAX8688_MFR_VOUT_PEAK 0xd4
29 #define MAX8688_MFR_IOUT_PEAK 0xd5
30 #define MAX8688_MFR_TEMPERATURE_PEAK 0xd6
31 #define MAX8688_MFG_STATUS 0xd8
33 #define MAX8688_STATUS_OC_FAULT (1 << 4)
34 #define MAX8688_STATUS_OV_FAULT (1 << 5)
35 #define MAX8688_STATUS_OV_WARNING (1 << 8)
36 #define MAX8688_STATUS_UV_FAULT (1 << 9)
37 #define MAX8688_STATUS_UV_WARNING (1 << 10)
38 #define MAX8688_STATUS_UC_FAULT (1 << 11)
39 #define MAX8688_STATUS_OC_WARNING (1 << 12)
40 #define MAX8688_STATUS_OT_FAULT (1 << 13)
41 #define MAX8688_STATUS_OT_WARNING (1 << 14)
43 static int max8688_read_word_data(struct i2c_client
*client
, int page
, int reg
)
51 case PMBUS_VIRT_READ_VOUT_MAX
:
52 ret
= pmbus_read_word_data(client
, 0, MAX8688_MFR_VOUT_PEAK
);
54 case PMBUS_VIRT_READ_IOUT_MAX
:
55 ret
= pmbus_read_word_data(client
, 0, MAX8688_MFR_IOUT_PEAK
);
57 case PMBUS_VIRT_READ_TEMP_MAX
:
58 ret
= pmbus_read_word_data(client
, 0,
59 MAX8688_MFR_TEMPERATURE_PEAK
);
61 case PMBUS_VIRT_RESET_VOUT_HISTORY
:
62 case PMBUS_VIRT_RESET_IOUT_HISTORY
:
63 case PMBUS_VIRT_RESET_TEMP_HISTORY
:
73 static int max8688_write_word_data(struct i2c_client
*client
, int page
, int reg
,
79 case PMBUS_VIRT_RESET_VOUT_HISTORY
:
80 ret
= pmbus_write_word_data(client
, 0, MAX8688_MFR_VOUT_PEAK
,
83 case PMBUS_VIRT_RESET_IOUT_HISTORY
:
84 ret
= pmbus_write_word_data(client
, 0, MAX8688_MFR_IOUT_PEAK
,
87 case PMBUS_VIRT_RESET_TEMP_HISTORY
:
88 ret
= pmbus_write_word_data(client
, 0,
89 MAX8688_MFR_TEMPERATURE_PEAK
,
99 static int max8688_read_byte_data(struct i2c_client
*client
, int page
, int reg
)
108 case PMBUS_STATUS_VOUT
:
109 mfg_status
= pmbus_read_word_data(client
, 0,
113 if (mfg_status
& MAX8688_STATUS_UV_WARNING
)
114 ret
|= PB_VOLTAGE_UV_WARNING
;
115 if (mfg_status
& MAX8688_STATUS_UV_FAULT
)
116 ret
|= PB_VOLTAGE_UV_FAULT
;
117 if (mfg_status
& MAX8688_STATUS_OV_WARNING
)
118 ret
|= PB_VOLTAGE_OV_WARNING
;
119 if (mfg_status
& MAX8688_STATUS_OV_FAULT
)
120 ret
|= PB_VOLTAGE_OV_FAULT
;
122 case PMBUS_STATUS_IOUT
:
123 mfg_status
= pmbus_read_word_data(client
, 0,
127 if (mfg_status
& MAX8688_STATUS_UC_FAULT
)
128 ret
|= PB_IOUT_UC_FAULT
;
129 if (mfg_status
& MAX8688_STATUS_OC_WARNING
)
130 ret
|= PB_IOUT_OC_WARNING
;
131 if (mfg_status
& MAX8688_STATUS_OC_FAULT
)
132 ret
|= PB_IOUT_OC_FAULT
;
134 case PMBUS_STATUS_TEMPERATURE
:
135 mfg_status
= pmbus_read_word_data(client
, 0,
139 if (mfg_status
& MAX8688_STATUS_OT_WARNING
)
140 ret
|= PB_TEMP_OT_WARNING
;
141 if (mfg_status
& MAX8688_STATUS_OT_FAULT
)
142 ret
|= PB_TEMP_OT_FAULT
;
151 static struct pmbus_driver_info max8688_info
= {
153 .format
[PSC_VOLTAGE_IN
] = direct
,
154 .format
[PSC_VOLTAGE_OUT
] = direct
,
155 .format
[PSC_TEMPERATURE
] = direct
,
156 .format
[PSC_CURRENT_OUT
] = direct
,
157 .m
[PSC_VOLTAGE_IN
] = 19995,
158 .b
[PSC_VOLTAGE_IN
] = 0,
159 .R
[PSC_VOLTAGE_IN
] = -1,
160 .m
[PSC_VOLTAGE_OUT
] = 19995,
161 .b
[PSC_VOLTAGE_OUT
] = 0,
162 .R
[PSC_VOLTAGE_OUT
] = -1,
163 .m
[PSC_CURRENT_OUT
] = 23109,
164 .b
[PSC_CURRENT_OUT
] = 0,
165 .R
[PSC_CURRENT_OUT
] = -2,
166 .m
[PSC_TEMPERATURE
] = -7612,
167 .b
[PSC_TEMPERATURE
] = 335,
168 .R
[PSC_TEMPERATURE
] = -3,
169 .func
[0] = PMBUS_HAVE_VOUT
| PMBUS_HAVE_IOUT
| PMBUS_HAVE_TEMP
170 | PMBUS_HAVE_STATUS_VOUT
| PMBUS_HAVE_STATUS_IOUT
171 | PMBUS_HAVE_STATUS_TEMP
,
172 .read_byte_data
= max8688_read_byte_data
,
173 .read_word_data
= max8688_read_word_data
,
174 .write_word_data
= max8688_write_word_data
,
177 static int max8688_probe(struct i2c_client
*client
,
178 const struct i2c_device_id
*id
)
180 return pmbus_do_probe(client
, id
, &max8688_info
);
183 static const struct i2c_device_id max8688_id
[] = {
188 MODULE_DEVICE_TABLE(i2c
, max8688_id
);
190 /* This is the driver that will be inserted */
191 static struct i2c_driver max8688_driver
= {
195 .probe
= max8688_probe
,
196 .remove
= pmbus_do_remove
,
197 .id_table
= max8688_id
,
200 module_i2c_driver(max8688_driver
);
202 MODULE_AUTHOR("Guenter Roeck");
203 MODULE_DESCRIPTION("PMBus driver for Maxim MAX8688");
204 MODULE_LICENSE("GPL");