blob: fa237a3c3291cee1fc5bcd9aa4eb408067d1ba4e [file] [log] [blame]
Guenter Roeckdcb7d062011-01-26 20:14:26 -08001/*
2 * Hardware monitoring driver for Maxim MAX16064
3 *
4 * Copyright (c) 2011 Ericsson AB.
5 *
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.
10 *
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.
15 *
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.
19 */
20
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>
26#include "pmbus.h"
27
Guenter Roeck8ebed852011-07-09 13:10:19 -070028#define MAX16064_MFR_VOUT_PEAK 0xd4
29#define MAX16064_MFR_TEMPERATURE_PEAK 0xd6
30
31static int max16064_read_word_data(struct i2c_client *client, int page, int reg)
32{
33 int ret;
34
35 switch (reg) {
36 case PMBUS_VIRT_READ_VOUT_MAX:
37 ret = pmbus_read_word_data(client, page,
38 MAX16064_MFR_VOUT_PEAK);
39 break;
40 case PMBUS_VIRT_READ_TEMP_MAX:
41 ret = pmbus_read_word_data(client, page,
42 MAX16064_MFR_TEMPERATURE_PEAK);
43 break;
44 case PMBUS_VIRT_RESET_VOUT_HISTORY:
45 case PMBUS_VIRT_RESET_TEMP_HISTORY:
46 ret = 0;
47 break;
48 default:
49 ret = -ENODATA;
50 break;
51 }
52 return ret;
53}
54
55static int max16064_write_word_data(struct i2c_client *client, int page,
56 int reg, u16 word)
57{
58 int ret;
59
60 switch (reg) {
61 case PMBUS_VIRT_RESET_VOUT_HISTORY:
62 ret = pmbus_write_word_data(client, page,
63 MAX16064_MFR_VOUT_PEAK, 0);
64 break;
65 case PMBUS_VIRT_RESET_TEMP_HISTORY:
66 ret = pmbus_write_word_data(client, page,
67 MAX16064_MFR_TEMPERATURE_PEAK,
68 0xffff);
69 break;
70 default:
71 ret = -ENODATA;
72 break;
73 }
74 return ret;
75}
76
Guenter Roeckdcb7d062011-01-26 20:14:26 -080077static struct pmbus_driver_info max16064_info = {
78 .pages = 4,
Guenter Roeck1061d852011-06-25 11:21:49 -070079 .format[PSC_VOLTAGE_IN] = direct,
80 .format[PSC_VOLTAGE_OUT] = direct,
81 .format[PSC_TEMPERATURE] = direct,
Guenter Roeckdcb7d062011-01-26 20:14:26 -080082 .m[PSC_VOLTAGE_IN] = 19995,
83 .b[PSC_VOLTAGE_IN] = 0,
84 .R[PSC_VOLTAGE_IN] = -1,
85 .m[PSC_VOLTAGE_OUT] = 19995,
86 .b[PSC_VOLTAGE_OUT] = 0,
87 .R[PSC_VOLTAGE_OUT] = -1,
88 .m[PSC_TEMPERATURE] = -7612,
89 .b[PSC_TEMPERATURE] = 335,
90 .R[PSC_TEMPERATURE] = -3,
91 .func[0] = PMBUS_HAVE_VOUT | PMBUS_HAVE_TEMP
92 | PMBUS_HAVE_STATUS_VOUT | PMBUS_HAVE_STATUS_TEMP,
93 .func[1] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT,
94 .func[2] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT,
95 .func[3] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT,
Guenter Roeck8ebed852011-07-09 13:10:19 -070096 .read_word_data = max16064_read_word_data,
97 .write_word_data = max16064_write_word_data,
Guenter Roeckdcb7d062011-01-26 20:14:26 -080098};
99
100static int max16064_probe(struct i2c_client *client,
101 const struct i2c_device_id *id)
102{
103 return pmbus_do_probe(client, id, &max16064_info);
104}
105
Guenter Roeckdcb7d062011-01-26 20:14:26 -0800106static const struct i2c_device_id max16064_id[] = {
107 {"max16064", 0},
108 {}
109};
110
111MODULE_DEVICE_TABLE(i2c, max16064_id);
112
113/* This is the driver that will be inserted */
114static struct i2c_driver max16064_driver = {
115 .driver = {
116 .name = "max16064",
117 },
118 .probe = max16064_probe,
Guenter Roeckdd285ad2012-02-22 08:56:44 -0800119 .remove = pmbus_do_remove,
Guenter Roeckdcb7d062011-01-26 20:14:26 -0800120 .id_table = max16064_id,
121};
122
Axel Linf0967ee2012-01-20 15:38:18 +0800123module_i2c_driver(max16064_driver);
Guenter Roeckdcb7d062011-01-26 20:14:26 -0800124
125MODULE_AUTHOR("Guenter Roeck");
126MODULE_DESCRIPTION("PMBus driver for Maxim MAX16064");
127MODULE_LICENSE("GPL");