ucd9000.c 17 KB

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