xref: /openbmc/linux/drivers/hwmon/pmbus/ucd9000.c (revision 12109610)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Hardware monitoring driver for UCD90xxx Sequencer and System Health
4  * Controller series
5  *
6  * Copyright (C) 2011 Ericsson AB.
7  */
8 
9 #include <linux/debugfs.h>
10 #include <linux/delay.h>
11 #include <linux/kernel.h>
12 #include <linux/module.h>
13 #include <linux/of_device.h>
14 #include <linux/init.h>
15 #include <linux/err.h>
16 #include <linux/slab.h>
17 #include <linux/i2c.h>
18 #include <linux/pmbus.h>
19 #include <linux/gpio/driver.h>
20 #include <linux/timekeeping.h>
21 #include "pmbus.h"
22 
23 enum chips { ucd9000, ucd90120, ucd90124, ucd90160, ucd90320, ucd9090,
24 	     ucd90910 };
25 
26 #define UCD9000_MONITOR_CONFIG		0xd5
27 #define UCD9000_NUM_PAGES		0xd6
28 #define UCD9000_FAN_CONFIG_INDEX	0xe7
29 #define UCD9000_FAN_CONFIG		0xe8
30 #define UCD9000_MFR_STATUS		0xf3
31 #define UCD9000_GPIO_SELECT		0xfa
32 #define UCD9000_GPIO_CONFIG		0xfb
33 #define UCD9000_DEVICE_ID		0xfd
34 
35 /* GPIO CONFIG bits */
36 #define UCD9000_GPIO_CONFIG_ENABLE	BIT(0)
37 #define UCD9000_GPIO_CONFIG_OUT_ENABLE	BIT(1)
38 #define UCD9000_GPIO_CONFIG_OUT_VALUE	BIT(2)
39 #define UCD9000_GPIO_CONFIG_STATUS	BIT(3)
40 #define UCD9000_GPIO_INPUT		0
41 #define UCD9000_GPIO_OUTPUT		1
42 
43 #define UCD9000_MON_TYPE(x)	(((x) >> 5) & 0x07)
44 #define UCD9000_MON_PAGE(x)	((x) & 0x1f)
45 
46 #define UCD9000_MON_VOLTAGE	1
47 #define UCD9000_MON_TEMPERATURE	2
48 #define UCD9000_MON_CURRENT	3
49 #define UCD9000_MON_VOLTAGE_HW	4
50 
51 #define UCD9000_NUM_FAN		4
52 
53 #define UCD9000_GPIO_NAME_LEN	16
54 #define UCD9090_NUM_GPIOS	23
55 #define UCD901XX_NUM_GPIOS	26
56 #define UCD90320_NUM_GPIOS	84
57 #define UCD90910_NUM_GPIOS	26
58 
59 #define UCD9000_DEBUGFS_NAME_LEN	24
60 #define UCD9000_GPI_COUNT		8
61 #define UCD90320_GPI_COUNT		32
62 
63 struct ucd9000_data {
64 	u8 fan_data[UCD9000_NUM_FAN][I2C_SMBUS_BLOCK_MAX];
65 	struct pmbus_driver_info info;
66 #ifdef CONFIG_GPIOLIB
67 	struct gpio_chip gpio;
68 #endif
69 	struct dentry *debugfs;
70 	ktime_t write_time;
71 };
72 #define to_ucd9000_data(_info) container_of(_info, struct ucd9000_data, info)
73 
74 struct ucd9000_debugfs_entry {
75 	struct i2c_client *client;
76 	u8 index;
77 };
78 
79 /*
80  * It has been observed that the UCD90320 randomly fails register access when
81  * doing another access right on the back of a register write. To mitigate this
82  * make sure that there is a minimum delay between a write access and the
83  * following access. The 250us is based on experimental data. At a delay of
84  * 200us the issue seems to go away. Add a bit of extra margin to allow for
85  * system to system differences.
86  */
87 #define UCD90320_WAIT_DELAY_US 250
88 
89 static inline void ucd90320_wait(const struct ucd9000_data *data)
90 {
91 	s64 delta = ktime_us_delta(ktime_get(), data->write_time);
92 
93 	if (delta < UCD90320_WAIT_DELAY_US)
94 		udelay(UCD90320_WAIT_DELAY_US - delta);
95 }
96 
97 static int ucd90320_read_word_data(struct i2c_client *client, int page,
98 				   int phase, int reg)
99 {
100 	const struct pmbus_driver_info *info = pmbus_get_driver_info(client);
101 	struct ucd9000_data *data = to_ucd9000_data(info);
102 
103 	if (reg >= PMBUS_VIRT_BASE)
104 		return -ENXIO;
105 
106 	ucd90320_wait(data);
107 	return pmbus_read_word_data(client, page, phase, reg);
108 }
109 
110 static int ucd90320_read_byte_data(struct i2c_client *client, int page, int reg)
111 {
112 	const struct pmbus_driver_info *info = pmbus_get_driver_info(client);
113 	struct ucd9000_data *data = to_ucd9000_data(info);
114 
115 	ucd90320_wait(data);
116 	return pmbus_read_byte_data(client, page, reg);
117 }
118 
119 static int ucd90320_write_word_data(struct i2c_client *client, int page,
120 				    int reg, u16 word)
121 {
122 	const struct pmbus_driver_info *info = pmbus_get_driver_info(client);
123 	struct ucd9000_data *data = to_ucd9000_data(info);
124 	int ret;
125 
126 	ucd90320_wait(data);
127 	ret = pmbus_write_word_data(client, page, reg, word);
128 	data->write_time = ktime_get();
129 
130 	return ret;
131 }
132 
133 static int ucd90320_write_byte(struct i2c_client *client, int page, u8 value)
134 {
135 	const struct pmbus_driver_info *info = pmbus_get_driver_info(client);
136 	struct ucd9000_data *data = to_ucd9000_data(info);
137 	int ret;
138 
139 	ucd90320_wait(data);
140 	ret = pmbus_write_byte(client, page, value);
141 	data->write_time = ktime_get();
142 
143 	return ret;
144 }
145 
146 static int ucd9000_get_fan_config(struct i2c_client *client, int fan)
147 {
148 	int fan_config = 0;
149 	struct ucd9000_data *data
150 	  = to_ucd9000_data(pmbus_get_driver_info(client));
151 
152 	if (data->fan_data[fan][3] & 1)
153 		fan_config |= PB_FAN_2_INSTALLED;   /* Use lower bit position */
154 
155 	/* Pulses/revolution */
156 	fan_config |= (data->fan_data[fan][3] & 0x06) >> 1;
157 
158 	return fan_config;
159 }
160 
161 static int ucd9000_read_byte_data(struct i2c_client *client, int page, int reg)
162 {
163 	int ret = 0;
164 	int fan_config;
165 
166 	switch (reg) {
167 	case PMBUS_FAN_CONFIG_12:
168 		if (page > 0)
169 			return -ENXIO;
170 
171 		ret = ucd9000_get_fan_config(client, 0);
172 		if (ret < 0)
173 			return ret;
174 		fan_config = ret << 4;
175 		ret = ucd9000_get_fan_config(client, 1);
176 		if (ret < 0)
177 			return ret;
178 		fan_config |= ret;
179 		ret = fan_config;
180 		break;
181 	case PMBUS_FAN_CONFIG_34:
182 		if (page > 0)
183 			return -ENXIO;
184 
185 		ret = ucd9000_get_fan_config(client, 2);
186 		if (ret < 0)
187 			return ret;
188 		fan_config = ret << 4;
189 		ret = ucd9000_get_fan_config(client, 3);
190 		if (ret < 0)
191 			return ret;
192 		fan_config |= ret;
193 		ret = fan_config;
194 		break;
195 	default:
196 		ret = -ENODATA;
197 		break;
198 	}
199 	return ret;
200 }
201 
202 static const struct i2c_device_id ucd9000_id[] = {
203 	{"ucd9000", ucd9000},
204 	{"ucd90120", ucd90120},
205 	{"ucd90124", ucd90124},
206 	{"ucd90160", ucd90160},
207 	{"ucd90320", ucd90320},
208 	{"ucd9090", ucd9090},
209 	{"ucd90910", ucd90910},
210 	{}
211 };
212 MODULE_DEVICE_TABLE(i2c, ucd9000_id);
213 
214 static const struct of_device_id __maybe_unused ucd9000_of_match[] = {
215 	{
216 		.compatible = "ti,ucd9000",
217 		.data = (void *)ucd9000
218 	},
219 	{
220 		.compatible = "ti,ucd90120",
221 		.data = (void *)ucd90120
222 	},
223 	{
224 		.compatible = "ti,ucd90124",
225 		.data = (void *)ucd90124
226 	},
227 	{
228 		.compatible = "ti,ucd90160",
229 		.data = (void *)ucd90160
230 	},
231 	{
232 		.compatible = "ti,ucd90320",
233 		.data = (void *)ucd90320
234 	},
235 	{
236 		.compatible = "ti,ucd9090",
237 		.data = (void *)ucd9090
238 	},
239 	{
240 		.compatible = "ti,ucd90910",
241 		.data = (void *)ucd90910
242 	},
243 	{ },
244 };
245 MODULE_DEVICE_TABLE(of, ucd9000_of_match);
246 
247 #ifdef CONFIG_GPIOLIB
248 static int ucd9000_gpio_read_config(struct i2c_client *client,
249 				    unsigned int offset)
250 {
251 	int ret;
252 
253 	/* No page set required */
254 	ret = i2c_smbus_write_byte_data(client, UCD9000_GPIO_SELECT, offset);
255 	if (ret < 0)
256 		return ret;
257 
258 	return i2c_smbus_read_byte_data(client, UCD9000_GPIO_CONFIG);
259 }
260 
261 static int ucd9000_gpio_get(struct gpio_chip *gc, unsigned int offset)
262 {
263 	struct i2c_client *client  = gpiochip_get_data(gc);
264 	int ret;
265 
266 	ret = ucd9000_gpio_read_config(client, offset);
267 	if (ret < 0)
268 		return ret;
269 
270 	return !!(ret & UCD9000_GPIO_CONFIG_STATUS);
271 }
272 
273 static void ucd9000_gpio_set(struct gpio_chip *gc, unsigned int offset,
274 			     int value)
275 {
276 	struct i2c_client *client = gpiochip_get_data(gc);
277 	int ret;
278 
279 	ret = ucd9000_gpio_read_config(client, offset);
280 	if (ret < 0) {
281 		dev_dbg(&client->dev, "failed to read GPIO %d config: %d\n",
282 			offset, ret);
283 		return;
284 	}
285 
286 	if (value) {
287 		if (ret & UCD9000_GPIO_CONFIG_STATUS)
288 			return;
289 
290 		ret |= UCD9000_GPIO_CONFIG_STATUS;
291 	} else {
292 		if (!(ret & UCD9000_GPIO_CONFIG_STATUS))
293 			return;
294 
295 		ret &= ~UCD9000_GPIO_CONFIG_STATUS;
296 	}
297 
298 	ret |= UCD9000_GPIO_CONFIG_ENABLE;
299 
300 	/* Page set not required */
301 	ret = i2c_smbus_write_byte_data(client, UCD9000_GPIO_CONFIG, ret);
302 	if (ret < 0) {
303 		dev_dbg(&client->dev, "Failed to write GPIO %d config: %d\n",
304 			offset, ret);
305 		return;
306 	}
307 
308 	ret &= ~UCD9000_GPIO_CONFIG_ENABLE;
309 
310 	ret = i2c_smbus_write_byte_data(client, UCD9000_GPIO_CONFIG, ret);
311 	if (ret < 0)
312 		dev_dbg(&client->dev, "Failed to write GPIO %d config: %d\n",
313 			offset, ret);
314 }
315 
316 static int ucd9000_gpio_get_direction(struct gpio_chip *gc,
317 				      unsigned int offset)
318 {
319 	struct i2c_client *client = gpiochip_get_data(gc);
320 	int ret;
321 
322 	ret = ucd9000_gpio_read_config(client, offset);
323 	if (ret < 0)
324 		return ret;
325 
326 	return !(ret & UCD9000_GPIO_CONFIG_OUT_ENABLE);
327 }
328 
329 static int ucd9000_gpio_set_direction(struct gpio_chip *gc,
330 				      unsigned int offset, bool direction_out,
331 				      int requested_out)
332 {
333 	struct i2c_client *client = gpiochip_get_data(gc);
334 	int ret, config, out_val;
335 
336 	ret = ucd9000_gpio_read_config(client, offset);
337 	if (ret < 0)
338 		return ret;
339 
340 	if (direction_out) {
341 		out_val = requested_out ? UCD9000_GPIO_CONFIG_OUT_VALUE : 0;
342 
343 		if (ret & UCD9000_GPIO_CONFIG_OUT_ENABLE) {
344 			if ((ret & UCD9000_GPIO_CONFIG_OUT_VALUE) == out_val)
345 				return 0;
346 		} else {
347 			ret |= UCD9000_GPIO_CONFIG_OUT_ENABLE;
348 		}
349 
350 		if (out_val)
351 			ret |= UCD9000_GPIO_CONFIG_OUT_VALUE;
352 		else
353 			ret &= ~UCD9000_GPIO_CONFIG_OUT_VALUE;
354 
355 	} else {
356 		if (!(ret & UCD9000_GPIO_CONFIG_OUT_ENABLE))
357 			return 0;
358 
359 		ret &= ~UCD9000_GPIO_CONFIG_OUT_ENABLE;
360 	}
361 
362 	ret |= UCD9000_GPIO_CONFIG_ENABLE;
363 	config = ret;
364 
365 	/* Page set not required */
366 	ret = i2c_smbus_write_byte_data(client, UCD9000_GPIO_CONFIG, config);
367 	if (ret < 0)
368 		return ret;
369 
370 	config &= ~UCD9000_GPIO_CONFIG_ENABLE;
371 
372 	return i2c_smbus_write_byte_data(client, UCD9000_GPIO_CONFIG, config);
373 }
374 
375 static int ucd9000_gpio_direction_input(struct gpio_chip *gc,
376 					unsigned int offset)
377 {
378 	return ucd9000_gpio_set_direction(gc, offset, UCD9000_GPIO_INPUT, 0);
379 }
380 
381 static int ucd9000_gpio_direction_output(struct gpio_chip *gc,
382 					 unsigned int offset, int val)
383 {
384 	return ucd9000_gpio_set_direction(gc, offset, UCD9000_GPIO_OUTPUT,
385 					  val);
386 }
387 
388 static void ucd9000_probe_gpio(struct i2c_client *client,
389 			       const struct i2c_device_id *mid,
390 			       struct ucd9000_data *data)
391 {
392 	int rc;
393 
394 	switch (mid->driver_data) {
395 	case ucd9090:
396 		data->gpio.ngpio = UCD9090_NUM_GPIOS;
397 		break;
398 	case ucd90120:
399 	case ucd90124:
400 	case ucd90160:
401 		data->gpio.ngpio = UCD901XX_NUM_GPIOS;
402 		break;
403 	case ucd90320:
404 		data->gpio.ngpio = UCD90320_NUM_GPIOS;
405 		break;
406 	case ucd90910:
407 		data->gpio.ngpio = UCD90910_NUM_GPIOS;
408 		break;
409 	default:
410 		return; /* GPIO support is optional. */
411 	}
412 
413 	/*
414 	 * Pinmux support has not been added to the new gpio_chip.
415 	 * This support should be added when possible given the mux
416 	 * behavior of these IO devices.
417 	 */
418 	data->gpio.label = client->name;
419 	data->gpio.get_direction = ucd9000_gpio_get_direction;
420 	data->gpio.direction_input = ucd9000_gpio_direction_input;
421 	data->gpio.direction_output = ucd9000_gpio_direction_output;
422 	data->gpio.get = ucd9000_gpio_get;
423 	data->gpio.set = ucd9000_gpio_set;
424 	data->gpio.can_sleep = true;
425 	data->gpio.base = -1;
426 	data->gpio.parent = &client->dev;
427 
428 	rc = devm_gpiochip_add_data(&client->dev, &data->gpio, client);
429 	if (rc)
430 		dev_warn(&client->dev, "Could not add gpiochip: %d\n", rc);
431 }
432 #else
433 static void ucd9000_probe_gpio(struct i2c_client *client,
434 			       const struct i2c_device_id *mid,
435 			       struct ucd9000_data *data)
436 {
437 }
438 #endif /* CONFIG_GPIOLIB */
439 
440 #ifdef CONFIG_DEBUG_FS
441 static int ucd9000_get_mfr_status(struct i2c_client *client, u8 *buffer)
442 {
443 	int ret = pmbus_set_page(client, 0, 0xff);
444 
445 	if (ret < 0)
446 		return ret;
447 
448 	return i2c_smbus_read_block_data(client, UCD9000_MFR_STATUS, buffer);
449 }
450 
451 static int ucd9000_debugfs_show_mfr_status_bit(void *data, u64 *val)
452 {
453 	struct ucd9000_debugfs_entry *entry = data;
454 	struct i2c_client *client = entry->client;
455 	u8 buffer[I2C_SMBUS_BLOCK_MAX];
456 	int ret, i;
457 
458 	ret = ucd9000_get_mfr_status(client, buffer);
459 	if (ret < 0)
460 		return ret;
461 
462 	/*
463 	 * GPI fault bits are in sets of 8, two bytes from end of response.
464 	 */
465 	i = ret - 3 - entry->index / 8;
466 	if (i >= 0)
467 		*val = !!(buffer[i] & BIT(entry->index % 8));
468 
469 	return 0;
470 }
471 DEFINE_DEBUGFS_ATTRIBUTE(ucd9000_debugfs_mfr_status_bit,
472 			 ucd9000_debugfs_show_mfr_status_bit, NULL, "%1lld\n");
473 
474 static ssize_t ucd9000_debugfs_read_mfr_status(struct file *file,
475 					       char __user *buf, size_t count,
476 					       loff_t *ppos)
477 {
478 	struct i2c_client *client = file->private_data;
479 	u8 buffer[I2C_SMBUS_BLOCK_MAX];
480 	char str[(I2C_SMBUS_BLOCK_MAX * 2) + 2];
481 	char *res;
482 	int rc;
483 
484 	rc = ucd9000_get_mfr_status(client, buffer);
485 	if (rc < 0)
486 		return rc;
487 
488 	res = bin2hex(str, buffer, min(rc, I2C_SMBUS_BLOCK_MAX));
489 	*res++ = '\n';
490 	*res = 0;
491 
492 	return simple_read_from_buffer(buf, count, ppos, str, res - str);
493 }
494 
495 static const struct file_operations ucd9000_debugfs_show_mfr_status_fops = {
496 	.llseek = noop_llseek,
497 	.read = ucd9000_debugfs_read_mfr_status,
498 	.open = simple_open,
499 };
500 
501 static int ucd9000_init_debugfs(struct i2c_client *client,
502 				const struct i2c_device_id *mid,
503 				struct ucd9000_data *data)
504 {
505 	struct dentry *debugfs;
506 	struct ucd9000_debugfs_entry *entries;
507 	int i, gpi_count;
508 	char name[UCD9000_DEBUGFS_NAME_LEN];
509 
510 	debugfs = pmbus_get_debugfs_dir(client);
511 	if (!debugfs)
512 		return -ENOENT;
513 
514 	data->debugfs = debugfs_create_dir(client->name, debugfs);
515 	if (!data->debugfs)
516 		return -ENOENT;
517 
518 	/*
519 	 * Of the chips this driver supports, only the UCD9090, UCD90160,
520 	 * UCD90320, and UCD90910 report GPI faults in their MFR_STATUS
521 	 * register, so only create the GPI fault debugfs attributes for those
522 	 * chips.
523 	 */
524 	if (mid->driver_data == ucd9090 || mid->driver_data == ucd90160 ||
525 	    mid->driver_data == ucd90320 || mid->driver_data == ucd90910) {
526 		gpi_count = mid->driver_data == ucd90320 ? UCD90320_GPI_COUNT
527 							 : UCD9000_GPI_COUNT;
528 		entries = devm_kcalloc(&client->dev,
529 				       gpi_count, sizeof(*entries),
530 				       GFP_KERNEL);
531 		if (!entries)
532 			return -ENOMEM;
533 
534 		for (i = 0; i < gpi_count; i++) {
535 			entries[i].client = client;
536 			entries[i].index = i;
537 			scnprintf(name, UCD9000_DEBUGFS_NAME_LEN,
538 				  "gpi%d_alarm", i + 1);
539 			debugfs_create_file(name, 0444, data->debugfs,
540 					    &entries[i],
541 					    &ucd9000_debugfs_mfr_status_bit);
542 		}
543 	}
544 
545 	scnprintf(name, UCD9000_DEBUGFS_NAME_LEN, "mfr_status");
546 	debugfs_create_file(name, 0444, data->debugfs, client,
547 			    &ucd9000_debugfs_show_mfr_status_fops);
548 
549 	return 0;
550 }
551 #else
552 static int ucd9000_init_debugfs(struct i2c_client *client,
553 				const struct i2c_device_id *mid,
554 				struct ucd9000_data *data)
555 {
556 	return 0;
557 }
558 #endif /* CONFIG_DEBUG_FS */
559 
560 static int ucd9000_probe(struct i2c_client *client)
561 {
562 	u8 block_buffer[I2C_SMBUS_BLOCK_MAX + 1];
563 	struct ucd9000_data *data;
564 	struct pmbus_driver_info *info;
565 	const struct i2c_device_id *mid;
566 	enum chips chip;
567 	int i, ret;
568 
569 	if (!i2c_check_functionality(client->adapter,
570 				     I2C_FUNC_SMBUS_BYTE_DATA |
571 				     I2C_FUNC_SMBUS_BLOCK_DATA))
572 		return -ENODEV;
573 
574 	ret = i2c_smbus_read_block_data(client, UCD9000_DEVICE_ID,
575 					block_buffer);
576 	if (ret < 0) {
577 		dev_err(&client->dev, "Failed to read device ID\n");
578 		return ret;
579 	}
580 	block_buffer[ret] = '\0';
581 	dev_info(&client->dev, "Device ID %s\n", block_buffer);
582 
583 	for (mid = ucd9000_id; mid->name[0]; mid++) {
584 		if (!strncasecmp(mid->name, block_buffer, strlen(mid->name)))
585 			break;
586 	}
587 	if (!mid->name[0]) {
588 		dev_err(&client->dev, "Unsupported device\n");
589 		return -ENODEV;
590 	}
591 
592 	if (client->dev.of_node)
593 		chip = (enum chips)of_device_get_match_data(&client->dev);
594 	else
595 		chip = mid->driver_data;
596 
597 	if (chip != ucd9000 && strcmp(client->name, mid->name) != 0)
598 		dev_notice(&client->dev,
599 			   "Device mismatch: Configured %s, detected %s\n",
600 			   client->name, mid->name);
601 
602 	data = devm_kzalloc(&client->dev, sizeof(struct ucd9000_data),
603 			    GFP_KERNEL);
604 	if (!data)
605 		return -ENOMEM;
606 	info = &data->info;
607 
608 	ret = i2c_smbus_read_byte_data(client, UCD9000_NUM_PAGES);
609 	if (ret < 0) {
610 		dev_err(&client->dev,
611 			"Failed to read number of active pages\n");
612 		return ret;
613 	}
614 	info->pages = ret;
615 	if (!info->pages) {
616 		dev_err(&client->dev, "No pages configured\n");
617 		return -ENODEV;
618 	}
619 
620 	/* The internal temperature sensor is always active */
621 	info->func[0] = PMBUS_HAVE_TEMP;
622 
623 	/* Everything else is configurable */
624 	ret = i2c_smbus_read_block_data(client, UCD9000_MONITOR_CONFIG,
625 					block_buffer);
626 	if (ret <= 0) {
627 		dev_err(&client->dev, "Failed to read configuration data\n");
628 		return -ENODEV;
629 	}
630 	for (i = 0; i < ret; i++) {
631 		int page = UCD9000_MON_PAGE(block_buffer[i]);
632 
633 		if (page >= info->pages)
634 			continue;
635 
636 		switch (UCD9000_MON_TYPE(block_buffer[i])) {
637 		case UCD9000_MON_VOLTAGE:
638 		case UCD9000_MON_VOLTAGE_HW:
639 			info->func[page] |= PMBUS_HAVE_VOUT
640 			  | PMBUS_HAVE_STATUS_VOUT;
641 			break;
642 		case UCD9000_MON_TEMPERATURE:
643 			info->func[page] |= PMBUS_HAVE_TEMP2
644 			  | PMBUS_HAVE_STATUS_TEMP;
645 			break;
646 		case UCD9000_MON_CURRENT:
647 			info->func[page] |= PMBUS_HAVE_IOUT
648 			  | PMBUS_HAVE_STATUS_IOUT;
649 			break;
650 		default:
651 			break;
652 		}
653 	}
654 
655 	/* Fan configuration */
656 	if (mid->driver_data == ucd90124) {
657 		for (i = 0; i < UCD9000_NUM_FAN; i++) {
658 			i2c_smbus_write_byte_data(client,
659 						  UCD9000_FAN_CONFIG_INDEX, i);
660 			ret = i2c_smbus_read_block_data(client,
661 							UCD9000_FAN_CONFIG,
662 							data->fan_data[i]);
663 			if (ret < 0)
664 				return ret;
665 		}
666 		i2c_smbus_write_byte_data(client, UCD9000_FAN_CONFIG_INDEX, 0);
667 
668 		info->read_byte_data = ucd9000_read_byte_data;
669 		info->func[0] |= PMBUS_HAVE_FAN12 | PMBUS_HAVE_STATUS_FAN12
670 		  | PMBUS_HAVE_FAN34 | PMBUS_HAVE_STATUS_FAN34;
671 	} else if (mid->driver_data == ucd90320) {
672 		info->read_byte_data = ucd90320_read_byte_data;
673 		info->read_word_data = ucd90320_read_word_data;
674 		info->write_byte = ucd90320_write_byte;
675 		info->write_word_data = ucd90320_write_word_data;
676 	}
677 
678 	ucd9000_probe_gpio(client, mid, data);
679 
680 	ret = pmbus_do_probe(client, info);
681 	if (ret)
682 		return ret;
683 
684 	ret = ucd9000_init_debugfs(client, mid, data);
685 	if (ret)
686 		dev_warn(&client->dev, "Failed to register debugfs: %d\n",
687 			 ret);
688 
689 	return 0;
690 }
691 
692 /* This is the driver that will be inserted */
693 static struct i2c_driver ucd9000_driver = {
694 	.driver = {
695 		.name = "ucd9000",
696 		.of_match_table = of_match_ptr(ucd9000_of_match),
697 	},
698 	.probe_new = ucd9000_probe,
699 	.id_table = ucd9000_id,
700 };
701 
702 module_i2c_driver(ucd9000_driver);
703 
704 MODULE_AUTHOR("Guenter Roeck");
705 MODULE_DESCRIPTION("PMBus driver for TI UCD90xxx");
706 MODULE_LICENSE("GPL");
707 MODULE_IMPORT_NS(PMBUS);
708