174ba9207SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
29d2ecfb7SGuenter Roeck /*
39d2ecfb7SGuenter Roeck * Hardware monitoring driver for UCD90xxx Sequencer and System Health
49d2ecfb7SGuenter Roeck * Controller series
59d2ecfb7SGuenter Roeck *
69d2ecfb7SGuenter Roeck * Copyright (C) 2011 Ericsson AB.
79d2ecfb7SGuenter Roeck */
89d2ecfb7SGuenter Roeck
972816cb0SChristopher Bostic #include <linux/debugfs.h>
108d655e65SLars-Peter Clausen #include <linux/delay.h>
119d2ecfb7SGuenter Roeck #include <linux/kernel.h>
129d2ecfb7SGuenter Roeck #include <linux/module.h>
1339f03438SRob Herring #include <linux/of.h>
149d2ecfb7SGuenter Roeck #include <linux/init.h>
159d2ecfb7SGuenter Roeck #include <linux/err.h>
169d2ecfb7SGuenter Roeck #include <linux/slab.h>
179d2ecfb7SGuenter Roeck #include <linux/i2c.h>
184ba1bb12SWolfram Sang #include <linux/pmbus.h>
19ca781fb7SChristopher Bostic #include <linux/gpio/driver.h>
208d655e65SLars-Peter Clausen #include <linux/timekeeping.h>
219d2ecfb7SGuenter Roeck #include "pmbus.h"
229d2ecfb7SGuenter Roeck
23a470f11cSJim Wright enum chips { ucd9000, ucd90120, ucd90124, ucd90160, ucd90320, ucd9090,
24a470f11cSJim Wright ucd90910 };
259d2ecfb7SGuenter Roeck
269d2ecfb7SGuenter Roeck #define UCD9000_MONITOR_CONFIG 0xd5
279d2ecfb7SGuenter Roeck #define UCD9000_NUM_PAGES 0xd6
289d2ecfb7SGuenter Roeck #define UCD9000_FAN_CONFIG_INDEX 0xe7
299d2ecfb7SGuenter Roeck #define UCD9000_FAN_CONFIG 0xe8
3072816cb0SChristopher Bostic #define UCD9000_MFR_STATUS 0xf3
31ca781fb7SChristopher Bostic #define UCD9000_GPIO_SELECT 0xfa
32ca781fb7SChristopher Bostic #define UCD9000_GPIO_CONFIG 0xfb
339d2ecfb7SGuenter Roeck #define UCD9000_DEVICE_ID 0xfd
349d2ecfb7SGuenter Roeck
35ca781fb7SChristopher Bostic /* GPIO CONFIG bits */
36ca781fb7SChristopher Bostic #define UCD9000_GPIO_CONFIG_ENABLE BIT(0)
37ca781fb7SChristopher Bostic #define UCD9000_GPIO_CONFIG_OUT_ENABLE BIT(1)
38ca781fb7SChristopher Bostic #define UCD9000_GPIO_CONFIG_OUT_VALUE BIT(2)
39ca781fb7SChristopher Bostic #define UCD9000_GPIO_CONFIG_STATUS BIT(3)
40ca781fb7SChristopher Bostic #define UCD9000_GPIO_INPUT 0
41ca781fb7SChristopher Bostic #define UCD9000_GPIO_OUTPUT 1
42ca781fb7SChristopher Bostic
439d2ecfb7SGuenter Roeck #define UCD9000_MON_TYPE(x) (((x) >> 5) & 0x07)
44a470f11cSJim Wright #define UCD9000_MON_PAGE(x) ((x) & 0x1f)
459d2ecfb7SGuenter Roeck
469d2ecfb7SGuenter Roeck #define UCD9000_MON_VOLTAGE 1
479d2ecfb7SGuenter Roeck #define UCD9000_MON_TEMPERATURE 2
489d2ecfb7SGuenter Roeck #define UCD9000_MON_CURRENT 3
499d2ecfb7SGuenter Roeck #define UCD9000_MON_VOLTAGE_HW 4
509d2ecfb7SGuenter Roeck
519d2ecfb7SGuenter Roeck #define UCD9000_NUM_FAN 4
529d2ecfb7SGuenter Roeck
53ca781fb7SChristopher Bostic #define UCD9000_GPIO_NAME_LEN 16
54ca781fb7SChristopher Bostic #define UCD9090_NUM_GPIOS 23
55ca781fb7SChristopher Bostic #define UCD901XX_NUM_GPIOS 26
56a470f11cSJim Wright #define UCD90320_NUM_GPIOS 84
57ca781fb7SChristopher Bostic #define UCD90910_NUM_GPIOS 26
58ca781fb7SChristopher Bostic
5972816cb0SChristopher Bostic #define UCD9000_DEBUGFS_NAME_LEN 24
6072816cb0SChristopher Bostic #define UCD9000_GPI_COUNT 8
61a470f11cSJim Wright #define UCD90320_GPI_COUNT 32
6272816cb0SChristopher Bostic
639d2ecfb7SGuenter Roeck struct ucd9000_data {
649d2ecfb7SGuenter Roeck u8 fan_data[UCD9000_NUM_FAN][I2C_SMBUS_BLOCK_MAX];
659d2ecfb7SGuenter Roeck struct pmbus_driver_info info;
66ca781fb7SChristopher Bostic #ifdef CONFIG_GPIOLIB
67ca781fb7SChristopher Bostic struct gpio_chip gpio;
68ca781fb7SChristopher Bostic #endif
6972816cb0SChristopher Bostic struct dentry *debugfs;
708d655e65SLars-Peter Clausen ktime_t write_time;
719d2ecfb7SGuenter Roeck };
729d2ecfb7SGuenter Roeck #define to_ucd9000_data(_info) container_of(_info, struct ucd9000_data, info)
739d2ecfb7SGuenter Roeck
7472816cb0SChristopher Bostic struct ucd9000_debugfs_entry {
7572816cb0SChristopher Bostic struct i2c_client *client;
7672816cb0SChristopher Bostic u8 index;
7772816cb0SChristopher Bostic };
7872816cb0SChristopher Bostic
798d655e65SLars-Peter Clausen /*
808d655e65SLars-Peter Clausen * It has been observed that the UCD90320 randomly fails register access when
818d655e65SLars-Peter Clausen * doing another access right on the back of a register write. To mitigate this
828d655e65SLars-Peter Clausen * make sure that there is a minimum delay between a write access and the
83*6555d7c0SLakshmi Yadlapati * following access. The 500 is based on experimental data. At a delay of
84*6555d7c0SLakshmi Yadlapati * 350us the issue seems to go away. Add a bit of extra margin to allow for
858d655e65SLars-Peter Clausen * system to system differences.
868d655e65SLars-Peter Clausen */
87*6555d7c0SLakshmi Yadlapati #define UCD90320_WAIT_DELAY_US 500
888d655e65SLars-Peter Clausen
ucd90320_wait(const struct ucd9000_data * data)898d655e65SLars-Peter Clausen static inline void ucd90320_wait(const struct ucd9000_data *data)
908d655e65SLars-Peter Clausen {
918d655e65SLars-Peter Clausen s64 delta = ktime_us_delta(ktime_get(), data->write_time);
928d655e65SLars-Peter Clausen
938d655e65SLars-Peter Clausen if (delta < UCD90320_WAIT_DELAY_US)
948d655e65SLars-Peter Clausen udelay(UCD90320_WAIT_DELAY_US - delta);
958d655e65SLars-Peter Clausen }
968d655e65SLars-Peter Clausen
ucd90320_read_word_data(struct i2c_client * client,int page,int phase,int reg)978d655e65SLars-Peter Clausen static int ucd90320_read_word_data(struct i2c_client *client, int page,
988d655e65SLars-Peter Clausen int phase, int reg)
998d655e65SLars-Peter Clausen {
1008d655e65SLars-Peter Clausen const struct pmbus_driver_info *info = pmbus_get_driver_info(client);
1018d655e65SLars-Peter Clausen struct ucd9000_data *data = to_ucd9000_data(info);
1028d655e65SLars-Peter Clausen
1038d655e65SLars-Peter Clausen if (reg >= PMBUS_VIRT_BASE)
1048d655e65SLars-Peter Clausen return -ENXIO;
1058d655e65SLars-Peter Clausen
1068d655e65SLars-Peter Clausen ucd90320_wait(data);
1078d655e65SLars-Peter Clausen return pmbus_read_word_data(client, page, phase, reg);
1088d655e65SLars-Peter Clausen }
1098d655e65SLars-Peter Clausen
ucd90320_read_byte_data(struct i2c_client * client,int page,int reg)1108d655e65SLars-Peter Clausen static int ucd90320_read_byte_data(struct i2c_client *client, int page, int reg)
1118d655e65SLars-Peter Clausen {
1128d655e65SLars-Peter Clausen const struct pmbus_driver_info *info = pmbus_get_driver_info(client);
1138d655e65SLars-Peter Clausen struct ucd9000_data *data = to_ucd9000_data(info);
1148d655e65SLars-Peter Clausen
1158d655e65SLars-Peter Clausen ucd90320_wait(data);
1168d655e65SLars-Peter Clausen return pmbus_read_byte_data(client, page, reg);
1178d655e65SLars-Peter Clausen }
1188d655e65SLars-Peter Clausen
ucd90320_write_word_data(struct i2c_client * client,int page,int reg,u16 word)1198d655e65SLars-Peter Clausen static int ucd90320_write_word_data(struct i2c_client *client, int page,
1208d655e65SLars-Peter Clausen int reg, u16 word)
1218d655e65SLars-Peter Clausen {
1228d655e65SLars-Peter Clausen const struct pmbus_driver_info *info = pmbus_get_driver_info(client);
1238d655e65SLars-Peter Clausen struct ucd9000_data *data = to_ucd9000_data(info);
1248d655e65SLars-Peter Clausen int ret;
1258d655e65SLars-Peter Clausen
1268d655e65SLars-Peter Clausen ucd90320_wait(data);
1278d655e65SLars-Peter Clausen ret = pmbus_write_word_data(client, page, reg, word);
1288d655e65SLars-Peter Clausen data->write_time = ktime_get();
1298d655e65SLars-Peter Clausen
1308d655e65SLars-Peter Clausen return ret;
1318d655e65SLars-Peter Clausen }
1328d655e65SLars-Peter Clausen
ucd90320_write_byte(struct i2c_client * client,int page,u8 value)1338d655e65SLars-Peter Clausen static int ucd90320_write_byte(struct i2c_client *client, int page, u8 value)
1348d655e65SLars-Peter Clausen {
1358d655e65SLars-Peter Clausen const struct pmbus_driver_info *info = pmbus_get_driver_info(client);
1368d655e65SLars-Peter Clausen struct ucd9000_data *data = to_ucd9000_data(info);
1378d655e65SLars-Peter Clausen int ret;
1388d655e65SLars-Peter Clausen
1398d655e65SLars-Peter Clausen ucd90320_wait(data);
1408d655e65SLars-Peter Clausen ret = pmbus_write_byte(client, page, value);
1418d655e65SLars-Peter Clausen data->write_time = ktime_get();
1428d655e65SLars-Peter Clausen
1438d655e65SLars-Peter Clausen return ret;
1448d655e65SLars-Peter Clausen }
1458d655e65SLars-Peter Clausen
ucd9000_get_fan_config(struct i2c_client * client,int fan)1469d2ecfb7SGuenter Roeck static int ucd9000_get_fan_config(struct i2c_client *client, int fan)
1479d2ecfb7SGuenter Roeck {
1489d2ecfb7SGuenter Roeck int fan_config = 0;
1499d2ecfb7SGuenter Roeck struct ucd9000_data *data
1509d2ecfb7SGuenter Roeck = to_ucd9000_data(pmbus_get_driver_info(client));
1519d2ecfb7SGuenter Roeck
1529d2ecfb7SGuenter Roeck if (data->fan_data[fan][3] & 1)
1539d2ecfb7SGuenter Roeck fan_config |= PB_FAN_2_INSTALLED; /* Use lower bit position */
1549d2ecfb7SGuenter Roeck
1559d2ecfb7SGuenter Roeck /* Pulses/revolution */
1569d2ecfb7SGuenter Roeck fan_config |= (data->fan_data[fan][3] & 0x06) >> 1;
1579d2ecfb7SGuenter Roeck
1589d2ecfb7SGuenter Roeck return fan_config;
1599d2ecfb7SGuenter Roeck }
1609d2ecfb7SGuenter Roeck
ucd9000_read_byte_data(struct i2c_client * client,int page,int reg)1619d2ecfb7SGuenter Roeck static int ucd9000_read_byte_data(struct i2c_client *client, int page, int reg)
1629d2ecfb7SGuenter Roeck {
1639d2ecfb7SGuenter Roeck int ret = 0;
1649d2ecfb7SGuenter Roeck int fan_config;
1659d2ecfb7SGuenter Roeck
1669d2ecfb7SGuenter Roeck switch (reg) {
1679d2ecfb7SGuenter Roeck case PMBUS_FAN_CONFIG_12:
168da8e48abSGuenter Roeck if (page > 0)
169179144a0SGuenter Roeck return -ENXIO;
1709d2ecfb7SGuenter Roeck
1719d2ecfb7SGuenter Roeck ret = ucd9000_get_fan_config(client, 0);
1729d2ecfb7SGuenter Roeck if (ret < 0)
1739d2ecfb7SGuenter Roeck return ret;
1749d2ecfb7SGuenter Roeck fan_config = ret << 4;
1759d2ecfb7SGuenter Roeck ret = ucd9000_get_fan_config(client, 1);
1769d2ecfb7SGuenter Roeck if (ret < 0)
1779d2ecfb7SGuenter Roeck return ret;
1789d2ecfb7SGuenter Roeck fan_config |= ret;
1799d2ecfb7SGuenter Roeck ret = fan_config;
1809d2ecfb7SGuenter Roeck break;
1819d2ecfb7SGuenter Roeck case PMBUS_FAN_CONFIG_34:
182da8e48abSGuenter Roeck if (page > 0)
183179144a0SGuenter Roeck return -ENXIO;
1849d2ecfb7SGuenter Roeck
1859d2ecfb7SGuenter Roeck ret = ucd9000_get_fan_config(client, 2);
1869d2ecfb7SGuenter Roeck if (ret < 0)
1879d2ecfb7SGuenter Roeck return ret;
1889d2ecfb7SGuenter Roeck fan_config = ret << 4;
1899d2ecfb7SGuenter Roeck ret = ucd9000_get_fan_config(client, 3);
1909d2ecfb7SGuenter Roeck if (ret < 0)
1919d2ecfb7SGuenter Roeck return ret;
1929d2ecfb7SGuenter Roeck fan_config |= ret;
1939d2ecfb7SGuenter Roeck ret = fan_config;
1949d2ecfb7SGuenter Roeck break;
1959d2ecfb7SGuenter Roeck default:
1969d2ecfb7SGuenter Roeck ret = -ENODATA;
1979d2ecfb7SGuenter Roeck break;
1989d2ecfb7SGuenter Roeck }
1999d2ecfb7SGuenter Roeck return ret;
2009d2ecfb7SGuenter Roeck }
2019d2ecfb7SGuenter Roeck
2029d2ecfb7SGuenter Roeck static const struct i2c_device_id ucd9000_id[] = {
2039d2ecfb7SGuenter Roeck {"ucd9000", ucd9000},
2049d2ecfb7SGuenter Roeck {"ucd90120", ucd90120},
2059d2ecfb7SGuenter Roeck {"ucd90124", ucd90124},
20650b2b02cSMatt Weber {"ucd90160", ucd90160},
207a470f11cSJim Wright {"ucd90320", ucd90320},
2089d2ecfb7SGuenter Roeck {"ucd9090", ucd9090},
2099d2ecfb7SGuenter Roeck {"ucd90910", ucd90910},
2109d2ecfb7SGuenter Roeck {}
2119d2ecfb7SGuenter Roeck };
2129d2ecfb7SGuenter Roeck MODULE_DEVICE_TABLE(i2c, ucd9000_id);
2139d2ecfb7SGuenter Roeck
21464e51162SGuenter Roeck static const struct of_device_id __maybe_unused ucd9000_of_match[] = {
2158881a191SJavier Martinez Canillas {
2168881a191SJavier Martinez Canillas .compatible = "ti,ucd9000",
2178881a191SJavier Martinez Canillas .data = (void *)ucd9000
2188881a191SJavier Martinez Canillas },
2198881a191SJavier Martinez Canillas {
2208881a191SJavier Martinez Canillas .compatible = "ti,ucd90120",
2218881a191SJavier Martinez Canillas .data = (void *)ucd90120
2228881a191SJavier Martinez Canillas },
2238881a191SJavier Martinez Canillas {
2248881a191SJavier Martinez Canillas .compatible = "ti,ucd90124",
2258881a191SJavier Martinez Canillas .data = (void *)ucd90124
2268881a191SJavier Martinez Canillas },
2278881a191SJavier Martinez Canillas {
2288881a191SJavier Martinez Canillas .compatible = "ti,ucd90160",
2298881a191SJavier Martinez Canillas .data = (void *)ucd90160
2308881a191SJavier Martinez Canillas },
2318881a191SJavier Martinez Canillas {
232a470f11cSJim Wright .compatible = "ti,ucd90320",
233a470f11cSJim Wright .data = (void *)ucd90320
234a470f11cSJim Wright },
235a470f11cSJim Wright {
2368881a191SJavier Martinez Canillas .compatible = "ti,ucd9090",
2378881a191SJavier Martinez Canillas .data = (void *)ucd9090
2388881a191SJavier Martinez Canillas },
2398881a191SJavier Martinez Canillas {
2408881a191SJavier Martinez Canillas .compatible = "ti,ucd90910",
2418881a191SJavier Martinez Canillas .data = (void *)ucd90910
2428881a191SJavier Martinez Canillas },
2438881a191SJavier Martinez Canillas { },
2448881a191SJavier Martinez Canillas };
2458881a191SJavier Martinez Canillas MODULE_DEVICE_TABLE(of, ucd9000_of_match);
2468881a191SJavier Martinez Canillas
247ca781fb7SChristopher Bostic #ifdef CONFIG_GPIOLIB
ucd9000_gpio_read_config(struct i2c_client * client,unsigned int offset)248ca781fb7SChristopher Bostic static int ucd9000_gpio_read_config(struct i2c_client *client,
249ca781fb7SChristopher Bostic unsigned int offset)
250ca781fb7SChristopher Bostic {
251ca781fb7SChristopher Bostic int ret;
252ca781fb7SChristopher Bostic
253ca781fb7SChristopher Bostic /* No page set required */
254ca781fb7SChristopher Bostic ret = i2c_smbus_write_byte_data(client, UCD9000_GPIO_SELECT, offset);
255ca781fb7SChristopher Bostic if (ret < 0)
256ca781fb7SChristopher Bostic return ret;
257ca781fb7SChristopher Bostic
258ca781fb7SChristopher Bostic return i2c_smbus_read_byte_data(client, UCD9000_GPIO_CONFIG);
259ca781fb7SChristopher Bostic }
260ca781fb7SChristopher Bostic
ucd9000_gpio_get(struct gpio_chip * gc,unsigned int offset)261ca781fb7SChristopher Bostic static int ucd9000_gpio_get(struct gpio_chip *gc, unsigned int offset)
262ca781fb7SChristopher Bostic {
263ca781fb7SChristopher Bostic struct i2c_client *client = gpiochip_get_data(gc);
264ca781fb7SChristopher Bostic int ret;
265ca781fb7SChristopher Bostic
266ca781fb7SChristopher Bostic ret = ucd9000_gpio_read_config(client, offset);
267ca781fb7SChristopher Bostic if (ret < 0)
268ca781fb7SChristopher Bostic return ret;
269ca781fb7SChristopher Bostic
270ca781fb7SChristopher Bostic return !!(ret & UCD9000_GPIO_CONFIG_STATUS);
271ca781fb7SChristopher Bostic }
272ca781fb7SChristopher Bostic
ucd9000_gpio_set(struct gpio_chip * gc,unsigned int offset,int value)273ca781fb7SChristopher Bostic static void ucd9000_gpio_set(struct gpio_chip *gc, unsigned int offset,
274ca781fb7SChristopher Bostic int value)
275ca781fb7SChristopher Bostic {
276ca781fb7SChristopher Bostic struct i2c_client *client = gpiochip_get_data(gc);
277ca781fb7SChristopher Bostic int ret;
278ca781fb7SChristopher Bostic
279ca781fb7SChristopher Bostic ret = ucd9000_gpio_read_config(client, offset);
280ca781fb7SChristopher Bostic if (ret < 0) {
281ca781fb7SChristopher Bostic dev_dbg(&client->dev, "failed to read GPIO %d config: %d\n",
282ca781fb7SChristopher Bostic offset, ret);
283ca781fb7SChristopher Bostic return;
284ca781fb7SChristopher Bostic }
285ca781fb7SChristopher Bostic
286ca781fb7SChristopher Bostic if (value) {
287ca781fb7SChristopher Bostic if (ret & UCD9000_GPIO_CONFIG_STATUS)
288ca781fb7SChristopher Bostic return;
289ca781fb7SChristopher Bostic
290ca781fb7SChristopher Bostic ret |= UCD9000_GPIO_CONFIG_STATUS;
291ca781fb7SChristopher Bostic } else {
292ca781fb7SChristopher Bostic if (!(ret & UCD9000_GPIO_CONFIG_STATUS))
293ca781fb7SChristopher Bostic return;
294ca781fb7SChristopher Bostic
295ca781fb7SChristopher Bostic ret &= ~UCD9000_GPIO_CONFIG_STATUS;
296ca781fb7SChristopher Bostic }
297ca781fb7SChristopher Bostic
298ca781fb7SChristopher Bostic ret |= UCD9000_GPIO_CONFIG_ENABLE;
299ca781fb7SChristopher Bostic
300ca781fb7SChristopher Bostic /* Page set not required */
301ca781fb7SChristopher Bostic ret = i2c_smbus_write_byte_data(client, UCD9000_GPIO_CONFIG, ret);
302ca781fb7SChristopher Bostic if (ret < 0) {
303ca781fb7SChristopher Bostic dev_dbg(&client->dev, "Failed to write GPIO %d config: %d\n",
304ca781fb7SChristopher Bostic offset, ret);
305ca781fb7SChristopher Bostic return;
306ca781fb7SChristopher Bostic }
307ca781fb7SChristopher Bostic
308ca781fb7SChristopher Bostic ret &= ~UCD9000_GPIO_CONFIG_ENABLE;
309ca781fb7SChristopher Bostic
310ca781fb7SChristopher Bostic ret = i2c_smbus_write_byte_data(client, UCD9000_GPIO_CONFIG, ret);
311ca781fb7SChristopher Bostic if (ret < 0)
312ca781fb7SChristopher Bostic dev_dbg(&client->dev, "Failed to write GPIO %d config: %d\n",
313ca781fb7SChristopher Bostic offset, ret);
314ca781fb7SChristopher Bostic }
315ca781fb7SChristopher Bostic
ucd9000_gpio_get_direction(struct gpio_chip * gc,unsigned int offset)316ca781fb7SChristopher Bostic static int ucd9000_gpio_get_direction(struct gpio_chip *gc,
317ca781fb7SChristopher Bostic unsigned int offset)
318ca781fb7SChristopher Bostic {
319ca781fb7SChristopher Bostic struct i2c_client *client = gpiochip_get_data(gc);
320ca781fb7SChristopher Bostic int ret;
321ca781fb7SChristopher Bostic
322ca781fb7SChristopher Bostic ret = ucd9000_gpio_read_config(client, offset);
323ca781fb7SChristopher Bostic if (ret < 0)
324ca781fb7SChristopher Bostic return ret;
325ca781fb7SChristopher Bostic
326ca781fb7SChristopher Bostic return !(ret & UCD9000_GPIO_CONFIG_OUT_ENABLE);
327ca781fb7SChristopher Bostic }
328ca781fb7SChristopher Bostic
ucd9000_gpio_set_direction(struct gpio_chip * gc,unsigned int offset,bool direction_out,int requested_out)329ca781fb7SChristopher Bostic static int ucd9000_gpio_set_direction(struct gpio_chip *gc,
330ca781fb7SChristopher Bostic unsigned int offset, bool direction_out,
331ca781fb7SChristopher Bostic int requested_out)
332ca781fb7SChristopher Bostic {
333ca781fb7SChristopher Bostic struct i2c_client *client = gpiochip_get_data(gc);
334ca781fb7SChristopher Bostic int ret, config, out_val;
335ca781fb7SChristopher Bostic
336ca781fb7SChristopher Bostic ret = ucd9000_gpio_read_config(client, offset);
337ca781fb7SChristopher Bostic if (ret < 0)
338ca781fb7SChristopher Bostic return ret;
339ca781fb7SChristopher Bostic
340ca781fb7SChristopher Bostic if (direction_out) {
341ca781fb7SChristopher Bostic out_val = requested_out ? UCD9000_GPIO_CONFIG_OUT_VALUE : 0;
342ca781fb7SChristopher Bostic
343ca781fb7SChristopher Bostic if (ret & UCD9000_GPIO_CONFIG_OUT_ENABLE) {
344ca781fb7SChristopher Bostic if ((ret & UCD9000_GPIO_CONFIG_OUT_VALUE) == out_val)
345ca781fb7SChristopher Bostic return 0;
346ca781fb7SChristopher Bostic } else {
347ca781fb7SChristopher Bostic ret |= UCD9000_GPIO_CONFIG_OUT_ENABLE;
348ca781fb7SChristopher Bostic }
349ca781fb7SChristopher Bostic
350ca781fb7SChristopher Bostic if (out_val)
351ca781fb7SChristopher Bostic ret |= UCD9000_GPIO_CONFIG_OUT_VALUE;
352ca781fb7SChristopher Bostic else
353ca781fb7SChristopher Bostic ret &= ~UCD9000_GPIO_CONFIG_OUT_VALUE;
354ca781fb7SChristopher Bostic
355ca781fb7SChristopher Bostic } else {
356ca781fb7SChristopher Bostic if (!(ret & UCD9000_GPIO_CONFIG_OUT_ENABLE))
357ca781fb7SChristopher Bostic return 0;
358ca781fb7SChristopher Bostic
359ca781fb7SChristopher Bostic ret &= ~UCD9000_GPIO_CONFIG_OUT_ENABLE;
360ca781fb7SChristopher Bostic }
361ca781fb7SChristopher Bostic
362ca781fb7SChristopher Bostic ret |= UCD9000_GPIO_CONFIG_ENABLE;
363ca781fb7SChristopher Bostic config = ret;
364ca781fb7SChristopher Bostic
365ca781fb7SChristopher Bostic /* Page set not required */
366ca781fb7SChristopher Bostic ret = i2c_smbus_write_byte_data(client, UCD9000_GPIO_CONFIG, config);
367ca781fb7SChristopher Bostic if (ret < 0)
368ca781fb7SChristopher Bostic return ret;
369ca781fb7SChristopher Bostic
370ca781fb7SChristopher Bostic config &= ~UCD9000_GPIO_CONFIG_ENABLE;
371ca781fb7SChristopher Bostic
372ca781fb7SChristopher Bostic return i2c_smbus_write_byte_data(client, UCD9000_GPIO_CONFIG, config);
373ca781fb7SChristopher Bostic }
374ca781fb7SChristopher Bostic
ucd9000_gpio_direction_input(struct gpio_chip * gc,unsigned int offset)375ca781fb7SChristopher Bostic static int ucd9000_gpio_direction_input(struct gpio_chip *gc,
376ca781fb7SChristopher Bostic unsigned int offset)
377ca781fb7SChristopher Bostic {
378ca781fb7SChristopher Bostic return ucd9000_gpio_set_direction(gc, offset, UCD9000_GPIO_INPUT, 0);
379ca781fb7SChristopher Bostic }
380ca781fb7SChristopher Bostic
ucd9000_gpio_direction_output(struct gpio_chip * gc,unsigned int offset,int val)381ca781fb7SChristopher Bostic static int ucd9000_gpio_direction_output(struct gpio_chip *gc,
382ca781fb7SChristopher Bostic unsigned int offset, int val)
383ca781fb7SChristopher Bostic {
384ca781fb7SChristopher Bostic return ucd9000_gpio_set_direction(gc, offset, UCD9000_GPIO_OUTPUT,
385ca781fb7SChristopher Bostic val);
386ca781fb7SChristopher Bostic }
387ca781fb7SChristopher Bostic
ucd9000_probe_gpio(struct i2c_client * client,const struct i2c_device_id * mid,struct ucd9000_data * data)388ca781fb7SChristopher Bostic static void ucd9000_probe_gpio(struct i2c_client *client,
389ca781fb7SChristopher Bostic const struct i2c_device_id *mid,
390ca781fb7SChristopher Bostic struct ucd9000_data *data)
391ca781fb7SChristopher Bostic {
392ca781fb7SChristopher Bostic int rc;
393ca781fb7SChristopher Bostic
394ca781fb7SChristopher Bostic switch (mid->driver_data) {
395ca781fb7SChristopher Bostic case ucd9090:
396ca781fb7SChristopher Bostic data->gpio.ngpio = UCD9090_NUM_GPIOS;
397ca781fb7SChristopher Bostic break;
398ca781fb7SChristopher Bostic case ucd90120:
399ca781fb7SChristopher Bostic case ucd90124:
400ca781fb7SChristopher Bostic case ucd90160:
401ca781fb7SChristopher Bostic data->gpio.ngpio = UCD901XX_NUM_GPIOS;
402ca781fb7SChristopher Bostic break;
403a470f11cSJim Wright case ucd90320:
404a470f11cSJim Wright data->gpio.ngpio = UCD90320_NUM_GPIOS;
405a470f11cSJim Wright break;
406ca781fb7SChristopher Bostic case ucd90910:
407ca781fb7SChristopher Bostic data->gpio.ngpio = UCD90910_NUM_GPIOS;
408ca781fb7SChristopher Bostic break;
409ca781fb7SChristopher Bostic default:
410ca781fb7SChristopher Bostic return; /* GPIO support is optional. */
411ca781fb7SChristopher Bostic }
412ca781fb7SChristopher Bostic
413ca781fb7SChristopher Bostic /*
414ca781fb7SChristopher Bostic * Pinmux support has not been added to the new gpio_chip.
415ca781fb7SChristopher Bostic * This support should be added when possible given the mux
416ca781fb7SChristopher Bostic * behavior of these IO devices.
417ca781fb7SChristopher Bostic */
418ca781fb7SChristopher Bostic data->gpio.label = client->name;
419ca781fb7SChristopher Bostic data->gpio.get_direction = ucd9000_gpio_get_direction;
420ca781fb7SChristopher Bostic data->gpio.direction_input = ucd9000_gpio_direction_input;
421ca781fb7SChristopher Bostic data->gpio.direction_output = ucd9000_gpio_direction_output;
422ca781fb7SChristopher Bostic data->gpio.get = ucd9000_gpio_get;
423ca781fb7SChristopher Bostic data->gpio.set = ucd9000_gpio_set;
424ca781fb7SChristopher Bostic data->gpio.can_sleep = true;
425ca781fb7SChristopher Bostic data->gpio.base = -1;
426ca781fb7SChristopher Bostic data->gpio.parent = &client->dev;
427ca781fb7SChristopher Bostic
428ca781fb7SChristopher Bostic rc = devm_gpiochip_add_data(&client->dev, &data->gpio, client);
429ca781fb7SChristopher Bostic if (rc)
430ca781fb7SChristopher Bostic dev_warn(&client->dev, "Could not add gpiochip: %d\n", rc);
431ca781fb7SChristopher Bostic }
432ca781fb7SChristopher Bostic #else
ucd9000_probe_gpio(struct i2c_client * client,const struct i2c_device_id * mid,struct ucd9000_data * data)433ca781fb7SChristopher Bostic static void ucd9000_probe_gpio(struct i2c_client *client,
434ca781fb7SChristopher Bostic const struct i2c_device_id *mid,
435ca781fb7SChristopher Bostic struct ucd9000_data *data)
436ca781fb7SChristopher Bostic {
437ca781fb7SChristopher Bostic }
438ca781fb7SChristopher Bostic #endif /* CONFIG_GPIOLIB */
439ca781fb7SChristopher Bostic
44072816cb0SChristopher Bostic #ifdef CONFIG_DEBUG_FS
ucd9000_get_mfr_status(struct i2c_client * client,u8 * buffer)44172816cb0SChristopher Bostic static int ucd9000_get_mfr_status(struct i2c_client *client, u8 *buffer)
44272816cb0SChristopher Bostic {
44343f33b6eSGuenter Roeck int ret = pmbus_set_page(client, 0, 0xff);
44472816cb0SChristopher Bostic
44572816cb0SChristopher Bostic if (ret < 0)
44672816cb0SChristopher Bostic return ret;
44772816cb0SChristopher Bostic
44872816cb0SChristopher Bostic return i2c_smbus_read_block_data(client, UCD9000_MFR_STATUS, buffer);
44972816cb0SChristopher Bostic }
45072816cb0SChristopher Bostic
ucd9000_debugfs_show_mfr_status_bit(void * data,u64 * val)45172816cb0SChristopher Bostic static int ucd9000_debugfs_show_mfr_status_bit(void *data, u64 *val)
45272816cb0SChristopher Bostic {
45372816cb0SChristopher Bostic struct ucd9000_debugfs_entry *entry = data;
45472816cb0SChristopher Bostic struct i2c_client *client = entry->client;
45572816cb0SChristopher Bostic u8 buffer[I2C_SMBUS_BLOCK_MAX];
456a470f11cSJim Wright int ret, i;
45772816cb0SChristopher Bostic
45872816cb0SChristopher Bostic ret = ucd9000_get_mfr_status(client, buffer);
45972816cb0SChristopher Bostic if (ret < 0)
46072816cb0SChristopher Bostic return ret;
46172816cb0SChristopher Bostic
46272816cb0SChristopher Bostic /*
463a470f11cSJim Wright * GPI fault bits are in sets of 8, two bytes from end of response.
46472816cb0SChristopher Bostic */
465a470f11cSJim Wright i = ret - 3 - entry->index / 8;
466a470f11cSJim Wright if (i >= 0)
467a470f11cSJim Wright *val = !!(buffer[i] & BIT(entry->index % 8));
46872816cb0SChristopher Bostic
46972816cb0SChristopher Bostic return 0;
47072816cb0SChristopher Bostic }
47172816cb0SChristopher Bostic DEFINE_DEBUGFS_ATTRIBUTE(ucd9000_debugfs_mfr_status_bit,
47272816cb0SChristopher Bostic ucd9000_debugfs_show_mfr_status_bit, NULL, "%1lld\n");
47372816cb0SChristopher Bostic
ucd9000_debugfs_read_mfr_status(struct file * file,char __user * buf,size_t count,loff_t * ppos)47472816cb0SChristopher Bostic static ssize_t ucd9000_debugfs_read_mfr_status(struct file *file,
47572816cb0SChristopher Bostic char __user *buf, size_t count,
47672816cb0SChristopher Bostic loff_t *ppos)
47772816cb0SChristopher Bostic {
47872816cb0SChristopher Bostic struct i2c_client *client = file->private_data;
47972816cb0SChristopher Bostic u8 buffer[I2C_SMBUS_BLOCK_MAX];
48072816cb0SChristopher Bostic char str[(I2C_SMBUS_BLOCK_MAX * 2) + 2];
48172816cb0SChristopher Bostic char *res;
48272816cb0SChristopher Bostic int rc;
48372816cb0SChristopher Bostic
48472816cb0SChristopher Bostic rc = ucd9000_get_mfr_status(client, buffer);
48572816cb0SChristopher Bostic if (rc < 0)
48672816cb0SChristopher Bostic return rc;
48772816cb0SChristopher Bostic
48872816cb0SChristopher Bostic res = bin2hex(str, buffer, min(rc, I2C_SMBUS_BLOCK_MAX));
48972816cb0SChristopher Bostic *res++ = '\n';
49072816cb0SChristopher Bostic *res = 0;
49172816cb0SChristopher Bostic
49272816cb0SChristopher Bostic return simple_read_from_buffer(buf, count, ppos, str, res - str);
49372816cb0SChristopher Bostic }
49472816cb0SChristopher Bostic
49572816cb0SChristopher Bostic static const struct file_operations ucd9000_debugfs_show_mfr_status_fops = {
49672816cb0SChristopher Bostic .llseek = noop_llseek,
49772816cb0SChristopher Bostic .read = ucd9000_debugfs_read_mfr_status,
49872816cb0SChristopher Bostic .open = simple_open,
49972816cb0SChristopher Bostic };
50072816cb0SChristopher Bostic
ucd9000_init_debugfs(struct i2c_client * client,const struct i2c_device_id * mid,struct ucd9000_data * data)50172816cb0SChristopher Bostic static int ucd9000_init_debugfs(struct i2c_client *client,
50272816cb0SChristopher Bostic const struct i2c_device_id *mid,
50372816cb0SChristopher Bostic struct ucd9000_data *data)
50472816cb0SChristopher Bostic {
50572816cb0SChristopher Bostic struct dentry *debugfs;
50672816cb0SChristopher Bostic struct ucd9000_debugfs_entry *entries;
507a470f11cSJim Wright int i, gpi_count;
50872816cb0SChristopher Bostic char name[UCD9000_DEBUGFS_NAME_LEN];
50972816cb0SChristopher Bostic
51072816cb0SChristopher Bostic debugfs = pmbus_get_debugfs_dir(client);
51172816cb0SChristopher Bostic if (!debugfs)
51272816cb0SChristopher Bostic return -ENOENT;
51372816cb0SChristopher Bostic
51472816cb0SChristopher Bostic data->debugfs = debugfs_create_dir(client->name, debugfs);
51572816cb0SChristopher Bostic
51672816cb0SChristopher Bostic /*
51772816cb0SChristopher Bostic * Of the chips this driver supports, only the UCD9090, UCD90160,
518a470f11cSJim Wright * UCD90320, and UCD90910 report GPI faults in their MFR_STATUS
519a470f11cSJim Wright * register, so only create the GPI fault debugfs attributes for those
520a470f11cSJim Wright * chips.
52172816cb0SChristopher Bostic */
52272816cb0SChristopher Bostic if (mid->driver_data == ucd9090 || mid->driver_data == ucd90160 ||
523a470f11cSJim Wright mid->driver_data == ucd90320 || mid->driver_data == ucd90910) {
524a470f11cSJim Wright gpi_count = mid->driver_data == ucd90320 ? UCD90320_GPI_COUNT
525a470f11cSJim Wright : UCD9000_GPI_COUNT;
526a86854d0SKees Cook entries = devm_kcalloc(&client->dev,
527a470f11cSJim Wright gpi_count, sizeof(*entries),
52872816cb0SChristopher Bostic GFP_KERNEL);
52972816cb0SChristopher Bostic if (!entries)
53072816cb0SChristopher Bostic return -ENOMEM;
53172816cb0SChristopher Bostic
532a470f11cSJim Wright for (i = 0; i < gpi_count; i++) {
53372816cb0SChristopher Bostic entries[i].client = client;
53472816cb0SChristopher Bostic entries[i].index = i;
53572816cb0SChristopher Bostic scnprintf(name, UCD9000_DEBUGFS_NAME_LEN,
53672816cb0SChristopher Bostic "gpi%d_alarm", i + 1);
53772816cb0SChristopher Bostic debugfs_create_file(name, 0444, data->debugfs,
53872816cb0SChristopher Bostic &entries[i],
53972816cb0SChristopher Bostic &ucd9000_debugfs_mfr_status_bit);
54072816cb0SChristopher Bostic }
54172816cb0SChristopher Bostic }
54272816cb0SChristopher Bostic
54372816cb0SChristopher Bostic scnprintf(name, UCD9000_DEBUGFS_NAME_LEN, "mfr_status");
54472816cb0SChristopher Bostic debugfs_create_file(name, 0444, data->debugfs, client,
54572816cb0SChristopher Bostic &ucd9000_debugfs_show_mfr_status_fops);
54672816cb0SChristopher Bostic
54772816cb0SChristopher Bostic return 0;
54872816cb0SChristopher Bostic }
54972816cb0SChristopher Bostic #else
ucd9000_init_debugfs(struct i2c_client * client,const struct i2c_device_id * mid,struct ucd9000_data * data)55072816cb0SChristopher Bostic static int ucd9000_init_debugfs(struct i2c_client *client,
55172816cb0SChristopher Bostic const struct i2c_device_id *mid,
55272816cb0SChristopher Bostic struct ucd9000_data *data)
55372816cb0SChristopher Bostic {
55472816cb0SChristopher Bostic return 0;
55572816cb0SChristopher Bostic }
55672816cb0SChristopher Bostic #endif /* CONFIG_DEBUG_FS */
55772816cb0SChristopher Bostic
ucd9000_probe(struct i2c_client * client)558dd431939SStephen Kitt static int ucd9000_probe(struct i2c_client *client)
5599d2ecfb7SGuenter Roeck {
5609d2ecfb7SGuenter Roeck u8 block_buffer[I2C_SMBUS_BLOCK_MAX + 1];
5619d2ecfb7SGuenter Roeck struct ucd9000_data *data;
5629d2ecfb7SGuenter Roeck struct pmbus_driver_info *info;
5639d2ecfb7SGuenter Roeck const struct i2c_device_id *mid;
5648881a191SJavier Martinez Canillas enum chips chip;
5659d2ecfb7SGuenter Roeck int i, ret;
5669d2ecfb7SGuenter Roeck
5679d2ecfb7SGuenter Roeck if (!i2c_check_functionality(client->adapter,
5689d2ecfb7SGuenter Roeck I2C_FUNC_SMBUS_BYTE_DATA |
5699d2ecfb7SGuenter Roeck I2C_FUNC_SMBUS_BLOCK_DATA))
5709d2ecfb7SGuenter Roeck return -ENODEV;
5719d2ecfb7SGuenter Roeck
5729d2ecfb7SGuenter Roeck ret = i2c_smbus_read_block_data(client, UCD9000_DEVICE_ID,
5739d2ecfb7SGuenter Roeck block_buffer);
5749d2ecfb7SGuenter Roeck if (ret < 0) {
5759d2ecfb7SGuenter Roeck dev_err(&client->dev, "Failed to read device ID\n");
5769d2ecfb7SGuenter Roeck return ret;
5779d2ecfb7SGuenter Roeck }
5789d2ecfb7SGuenter Roeck block_buffer[ret] = '\0';
5799d2ecfb7SGuenter Roeck dev_info(&client->dev, "Device ID %s\n", block_buffer);
5809d2ecfb7SGuenter Roeck
581f020b007SJean Delvare for (mid = ucd9000_id; mid->name[0]; mid++) {
5829d2ecfb7SGuenter Roeck if (!strncasecmp(mid->name, block_buffer, strlen(mid->name)))
5839d2ecfb7SGuenter Roeck break;
5849d2ecfb7SGuenter Roeck }
585f020b007SJean Delvare if (!mid->name[0]) {
5869d2ecfb7SGuenter Roeck dev_err(&client->dev, "Unsupported device\n");
5879d2ecfb7SGuenter Roeck return -ENODEV;
5889d2ecfb7SGuenter Roeck }
5899d2ecfb7SGuenter Roeck
5908881a191SJavier Martinez Canillas if (client->dev.of_node)
591d29b763cSKrzysztof Kozlowski chip = (uintptr_t)of_device_get_match_data(&client->dev);
5928881a191SJavier Martinez Canillas else
593dd431939SStephen Kitt chip = mid->driver_data;
5948881a191SJavier Martinez Canillas
595dd431939SStephen Kitt if (chip != ucd9000 && strcmp(client->name, mid->name) != 0)
5969d2ecfb7SGuenter Roeck dev_notice(&client->dev,
5979d2ecfb7SGuenter Roeck "Device mismatch: Configured %s, detected %s\n",
598dd431939SStephen Kitt client->name, mid->name);
5999d2ecfb7SGuenter Roeck
6008b313ca7SGuenter Roeck data = devm_kzalloc(&client->dev, sizeof(struct ucd9000_data),
6018b313ca7SGuenter Roeck GFP_KERNEL);
6029d2ecfb7SGuenter Roeck if (!data)
6039d2ecfb7SGuenter Roeck return -ENOMEM;
6049d2ecfb7SGuenter Roeck info = &data->info;
6059d2ecfb7SGuenter Roeck
6069d2ecfb7SGuenter Roeck ret = i2c_smbus_read_byte_data(client, UCD9000_NUM_PAGES);
6079d2ecfb7SGuenter Roeck if (ret < 0) {
6089d2ecfb7SGuenter Roeck dev_err(&client->dev,
6099d2ecfb7SGuenter Roeck "Failed to read number of active pages\n");
6108b313ca7SGuenter Roeck return ret;
6119d2ecfb7SGuenter Roeck }
6129d2ecfb7SGuenter Roeck info->pages = ret;
6139d2ecfb7SGuenter Roeck if (!info->pages) {
6149d2ecfb7SGuenter Roeck dev_err(&client->dev, "No pages configured\n");
6158b313ca7SGuenter Roeck return -ENODEV;
6169d2ecfb7SGuenter Roeck }
6179d2ecfb7SGuenter Roeck
6189d2ecfb7SGuenter Roeck /* The internal temperature sensor is always active */
6199d2ecfb7SGuenter Roeck info->func[0] = PMBUS_HAVE_TEMP;
6209d2ecfb7SGuenter Roeck
6219d2ecfb7SGuenter Roeck /* Everything else is configurable */
6229d2ecfb7SGuenter Roeck ret = i2c_smbus_read_block_data(client, UCD9000_MONITOR_CONFIG,
6239d2ecfb7SGuenter Roeck block_buffer);
6249d2ecfb7SGuenter Roeck if (ret <= 0) {
6259d2ecfb7SGuenter Roeck dev_err(&client->dev, "Failed to read configuration data\n");
6268b313ca7SGuenter Roeck return -ENODEV;
6279d2ecfb7SGuenter Roeck }
6289d2ecfb7SGuenter Roeck for (i = 0; i < ret; i++) {
6299d2ecfb7SGuenter Roeck int page = UCD9000_MON_PAGE(block_buffer[i]);
6309d2ecfb7SGuenter Roeck
6319d2ecfb7SGuenter Roeck if (page >= info->pages)
6329d2ecfb7SGuenter Roeck continue;
6339d2ecfb7SGuenter Roeck
6349d2ecfb7SGuenter Roeck switch (UCD9000_MON_TYPE(block_buffer[i])) {
6359d2ecfb7SGuenter Roeck case UCD9000_MON_VOLTAGE:
6369d2ecfb7SGuenter Roeck case UCD9000_MON_VOLTAGE_HW:
6379d2ecfb7SGuenter Roeck info->func[page] |= PMBUS_HAVE_VOUT
6389d2ecfb7SGuenter Roeck | PMBUS_HAVE_STATUS_VOUT;
6399d2ecfb7SGuenter Roeck break;
6409d2ecfb7SGuenter Roeck case UCD9000_MON_TEMPERATURE:
6419d2ecfb7SGuenter Roeck info->func[page] |= PMBUS_HAVE_TEMP2
6429d2ecfb7SGuenter Roeck | PMBUS_HAVE_STATUS_TEMP;
6439d2ecfb7SGuenter Roeck break;
6449d2ecfb7SGuenter Roeck case UCD9000_MON_CURRENT:
6459d2ecfb7SGuenter Roeck info->func[page] |= PMBUS_HAVE_IOUT
6469d2ecfb7SGuenter Roeck | PMBUS_HAVE_STATUS_IOUT;
6479d2ecfb7SGuenter Roeck break;
6489d2ecfb7SGuenter Roeck default:
6499d2ecfb7SGuenter Roeck break;
6509d2ecfb7SGuenter Roeck }
6519d2ecfb7SGuenter Roeck }
6529d2ecfb7SGuenter Roeck
6539d2ecfb7SGuenter Roeck /* Fan configuration */
6549d2ecfb7SGuenter Roeck if (mid->driver_data == ucd90124) {
6559d2ecfb7SGuenter Roeck for (i = 0; i < UCD9000_NUM_FAN; i++) {
6569d2ecfb7SGuenter Roeck i2c_smbus_write_byte_data(client,
6579d2ecfb7SGuenter Roeck UCD9000_FAN_CONFIG_INDEX, i);
6589d2ecfb7SGuenter Roeck ret = i2c_smbus_read_block_data(client,
6599d2ecfb7SGuenter Roeck UCD9000_FAN_CONFIG,
6609d2ecfb7SGuenter Roeck data->fan_data[i]);
6619d2ecfb7SGuenter Roeck if (ret < 0)
6628b313ca7SGuenter Roeck return ret;
6639d2ecfb7SGuenter Roeck }
6649d2ecfb7SGuenter Roeck i2c_smbus_write_byte_data(client, UCD9000_FAN_CONFIG_INDEX, 0);
6659d2ecfb7SGuenter Roeck
6669d2ecfb7SGuenter Roeck info->read_byte_data = ucd9000_read_byte_data;
6679d2ecfb7SGuenter Roeck info->func[0] |= PMBUS_HAVE_FAN12 | PMBUS_HAVE_STATUS_FAN12
6689d2ecfb7SGuenter Roeck | PMBUS_HAVE_FAN34 | PMBUS_HAVE_STATUS_FAN34;
6698d655e65SLars-Peter Clausen } else if (mid->driver_data == ucd90320) {
6708d655e65SLars-Peter Clausen info->read_byte_data = ucd90320_read_byte_data;
6718d655e65SLars-Peter Clausen info->read_word_data = ucd90320_read_word_data;
6728d655e65SLars-Peter Clausen info->write_byte = ucd90320_write_byte;
6738d655e65SLars-Peter Clausen info->write_word_data = ucd90320_write_word_data;
6749d2ecfb7SGuenter Roeck }
6759d2ecfb7SGuenter Roeck
676ca781fb7SChristopher Bostic ucd9000_probe_gpio(client, mid, data);
677ca781fb7SChristopher Bostic
678dd431939SStephen Kitt ret = pmbus_do_probe(client, info);
67972816cb0SChristopher Bostic if (ret)
68072816cb0SChristopher Bostic return ret;
68172816cb0SChristopher Bostic
68272816cb0SChristopher Bostic ret = ucd9000_init_debugfs(client, mid, data);
68372816cb0SChristopher Bostic if (ret)
68472816cb0SChristopher Bostic dev_warn(&client->dev, "Failed to register debugfs: %d\n",
68572816cb0SChristopher Bostic ret);
68672816cb0SChristopher Bostic
68772816cb0SChristopher Bostic return 0;
6889d2ecfb7SGuenter Roeck }
6899d2ecfb7SGuenter Roeck
6909d2ecfb7SGuenter Roeck /* This is the driver that will be inserted */
6919d2ecfb7SGuenter Roeck static struct i2c_driver ucd9000_driver = {
6929d2ecfb7SGuenter Roeck .driver = {
6939d2ecfb7SGuenter Roeck .name = "ucd9000",
6948881a191SJavier Martinez Canillas .of_match_table = of_match_ptr(ucd9000_of_match),
6959d2ecfb7SGuenter Roeck },
6961975d167SUwe Kleine-König .probe = ucd9000_probe,
6979d2ecfb7SGuenter Roeck .id_table = ucd9000_id,
6989d2ecfb7SGuenter Roeck };
6999d2ecfb7SGuenter Roeck
700f0967eeaSAxel Lin module_i2c_driver(ucd9000_driver);
7019d2ecfb7SGuenter Roeck
7029d2ecfb7SGuenter Roeck MODULE_AUTHOR("Guenter Roeck");
7039d2ecfb7SGuenter Roeck MODULE_DESCRIPTION("PMBus driver for TI UCD90xxx");
7049d2ecfb7SGuenter Roeck MODULE_LICENSE("GPL");
705b94ca77eSGuenter Roeck MODULE_IMPORT_NS(PMBUS);
706