2 * Hardware monitoring driver for ucd9200 series Digital PWM System Controllers
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/slab.h>
26 #include <linux/i2c.h>
27 #include <linux/i2c/pmbus.h>
30 #define UCD9200_PHASE_INFO 0xd2
31 #define UCD9200_DEVICE_ID 0xfd
33 enum chips
{ ucd9200
, ucd9220
, ucd9222
, ucd9224
, ucd9240
, ucd9244
, ucd9246
,
36 static const struct i2c_device_id ucd9200_id
[] = {
47 MODULE_DEVICE_TABLE(i2c
, ucd9200_id
);
49 static int ucd9200_probe(struct i2c_client
*client
,
50 const struct i2c_device_id
*id
)
52 u8 block_buffer
[I2C_SMBUS_BLOCK_MAX
+ 1];
53 struct pmbus_driver_info
*info
;
54 const struct i2c_device_id
*mid
;
57 if (!i2c_check_functionality(client
->adapter
,
58 I2C_FUNC_SMBUS_BYTE_DATA
|
59 I2C_FUNC_SMBUS_BLOCK_DATA
))
62 ret
= i2c_smbus_read_block_data(client
, UCD9200_DEVICE_ID
,
65 dev_err(&client
->dev
, "Failed to read device ID\n");
68 block_buffer
[ret
] = '\0';
69 dev_info(&client
->dev
, "Device ID %s\n", block_buffer
);
72 for (i
= 0; i
< ARRAY_SIZE(ucd9200_id
); i
++) {
74 if (!strncasecmp(mid
->name
, block_buffer
, strlen(mid
->name
)))
77 if (!mid
|| !strlen(mid
->name
)) {
78 dev_err(&client
->dev
, "Unsupported device\n");
81 if (id
->driver_data
!= ucd9200
&& id
->driver_data
!= mid
->driver_data
)
82 dev_notice(&client
->dev
,
83 "Device mismatch: Configured %s, detected %s\n",
86 info
= kzalloc(sizeof(struct pmbus_driver_info
), GFP_KERNEL
);
90 ret
= i2c_smbus_read_block_data(client
, UCD9200_PHASE_INFO
,
93 dev_err(&client
->dev
, "Failed to read phase information\n");
98 * Calculate number of configured pages (rails) from PHASE_INFO
100 * Rails have to be sequential, so we can abort after finding
101 * the first unconfigured rail.
104 for (i
= 0; i
< ret
; i
++) {
105 if (!block_buffer
[i
])
110 dev_err(&client
->dev
, "No rails configured\n");
114 dev_info(&client
->dev
, "%d rails configured\n", info
->pages
);
117 * Set PHASE registers on all pages to 0xff to ensure that phase
118 * specific commands will apply to all phases of a given page (rail).
119 * This only affects the READ_IOUT and READ_TEMPERATURE2 registers.
120 * READ_IOUT will return the sum of currents of all phases of a rail,
121 * and READ_TEMPERATURE2 will return the maximum temperature detected
122 * for the the phases of the rail.
124 for (i
= 0; i
< info
->pages
; i
++) {
126 * Setting PAGE & PHASE fails once in a while for no obvious
127 * reason, so we need to retry a couple of times.
129 for (j
= 0; j
< 3; j
++) {
130 ret
= i2c_smbus_write_byte_data(client
, PMBUS_PAGE
, i
);
133 ret
= i2c_smbus_write_byte_data(client
, PMBUS_PHASE
,
140 dev_err(&client
->dev
,
141 "Failed to initialize PHASE registers\n");
146 i2c_smbus_write_byte_data(client
, PMBUS_PAGE
, 0);
148 info
->func
[0] = PMBUS_HAVE_VIN
| PMBUS_HAVE_STATUS_INPUT
|
149 PMBUS_HAVE_IIN
| PMBUS_HAVE_PIN
|
150 PMBUS_HAVE_VOUT
| PMBUS_HAVE_STATUS_VOUT
|
151 PMBUS_HAVE_IOUT
| PMBUS_HAVE_STATUS_IOUT
|
152 PMBUS_HAVE_POUT
| PMBUS_HAVE_TEMP
|
153 PMBUS_HAVE_TEMP2
| PMBUS_HAVE_STATUS_TEMP
;
155 for (i
= 1; i
< info
->pages
; i
++)
156 info
->func
[i
] = PMBUS_HAVE_VOUT
| PMBUS_HAVE_STATUS_VOUT
|
157 PMBUS_HAVE_IOUT
| PMBUS_HAVE_STATUS_IOUT
|
159 PMBUS_HAVE_TEMP2
| PMBUS_HAVE_STATUS_TEMP
;
161 /* ucd9240 supports a single fan */
162 if (mid
->driver_data
== ucd9240
)
163 info
->func
[0] |= PMBUS_HAVE_FAN12
| PMBUS_HAVE_STATUS_FAN12
;
165 ret
= pmbus_do_probe(client
, mid
, info
);
174 static int ucd9200_remove(struct i2c_client
*client
)
176 const struct pmbus_driver_info
*info
;
178 info
= pmbus_get_driver_info(client
);
179 pmbus_do_remove(client
);
185 /* This is the driver that will be inserted */
186 static struct i2c_driver ucd9200_driver
= {
190 .probe
= ucd9200_probe
,
191 .remove
= ucd9200_remove
,
192 .id_table
= ucd9200_id
,
195 static int __init
ucd9200_init(void)
197 return i2c_add_driver(&ucd9200_driver
);
200 static void __exit
ucd9200_exit(void)
202 i2c_del_driver(&ucd9200_driver
);
205 MODULE_AUTHOR("Guenter Roeck");
206 MODULE_DESCRIPTION("PMBus driver for TI UCD922x, UCD924x");
207 MODULE_LICENSE("GPL");
208 module_init(ucd9200_init
);
209 module_exit(ucd9200_exit
);