2 * Hardware monitoring driver for Analog Devices ADM1275 Hot-Swap Controller
3 * and Digital Power Monitor
5 * Copyright (c) 2011 Ericsson AB.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
18 #include <linux/kernel.h>
19 #include <linux/module.h>
20 #include <linux/init.h>
21 #include <linux/err.h>
22 #include <linux/slab.h>
23 #include <linux/i2c.h>
26 #define ADM1275_PMON_CONFIG 0xd4
28 #define ADM1275_VIN_VOUT_SELECT (1 << 6)
29 #define ADM1275_VRANGE (1 << 5)
31 static int adm1275_probe(struct i2c_client *client,
32 const struct i2c_device_id *id)
35 struct pmbus_driver_info *info;
37 if (!i2c_check_functionality(client->adapter,
38 I2C_FUNC_SMBUS_READ_BYTE_DATA))
41 info = kzalloc(sizeof(struct pmbus_driver_info), GFP_KERNEL);
45 config = i2c_smbus_read_byte_data(client, ADM1275_PMON_CONFIG);
50 info->direct[PSC_VOLTAGE_IN] = true;
51 info->direct[PSC_VOLTAGE_OUT] = true;
52 info->direct[PSC_CURRENT_OUT] = true;
53 info->m[PSC_CURRENT_OUT] = 800;
54 info->b[PSC_CURRENT_OUT] = 20475;
55 info->R[PSC_CURRENT_OUT] = -1;
56 info->func[0] = PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT;
58 if (config & ADM1275_VRANGE) {
59 info->m[PSC_VOLTAGE_IN] = 19045;
60 info->b[PSC_VOLTAGE_IN] = 0;
61 info->R[PSC_VOLTAGE_IN] = -2;
62 info->m[PSC_VOLTAGE_OUT] = 19045;
63 info->b[PSC_VOLTAGE_OUT] = 0;
64 info->R[PSC_VOLTAGE_OUT] = -2;
66 info->m[PSC_VOLTAGE_IN] = 6666;
67 info->b[PSC_VOLTAGE_IN] = 0;
68 info->R[PSC_VOLTAGE_IN] = -1;
69 info->m[PSC_VOLTAGE_OUT] = 6666;
70 info->b[PSC_VOLTAGE_OUT] = 0;
71 info->R[PSC_VOLTAGE_OUT] = -1;
74 if (config & ADM1275_VIN_VOUT_SELECT)
75 info->func[0] |= PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT;
77 info->func[0] |= PMBUS_HAVE_VIN | PMBUS_HAVE_STATUS_INPUT;
79 return pmbus_do_probe(client, id, info);
82 static int adm1275_remove(struct i2c_client *client)
84 const struct pmbus_driver_info *info = pmbus_get_driver_info(client);
87 ret = pmbus_do_remove(client);
92 static const struct i2c_device_id adm1275_id[] = {
96 MODULE_DEVICE_TABLE(i2c, adm1275_id);
98 static struct i2c_driver adm1275_driver = {
102 .probe = adm1275_probe,
103 .remove = adm1275_remove,
104 .id_table = adm1275_id,
107 static int __init adm1275_init(void)
109 return i2c_add_driver(&adm1275_driver);
112 static void __exit adm1275_exit(void)
114 i2c_del_driver(&adm1275_driver);
117 MODULE_AUTHOR("Guenter Roeck");
118 MODULE_DESCRIPTION("PMBus driver for Analog Devices ADM1275");
119 MODULE_LICENSE("GPL");
120 module_init(adm1275_init);
121 module_exit(adm1275_exit);