@@ -21,16 +21,70 @@
#include <linux/i2c.h>
#include "pmbus.h"
+#define TPS40422_STEP_VREF_MARGIN_HIGH 0xd5
+#define TPS40422_STEP_VREF_MARGIN_LOW 0xd6
+#define TPS40422_VREF 600
+
+static int tps40422_read_word_data(struct i2c_client *client, int page, int reg)
+{
+ int ret;
+
+ switch (reg) {
+ case PMBUS_VOUT_MARGIN_HIGH:
+ reg = TPS40422_STEP_VREF_MARGIN_HIGH;
+ break;
+ case PMBUS_VOUT_MARGIN_LOW:
+ reg = TPS40422_STEP_VREF_MARGIN_LOW;
+ break;
+ default:
+ return -ENODATA;
+ }
+
+ ret = pmbus_read_word_data(client, page, reg);
+ if (ret < 0)
+ return ret;
+
+ ret = (TPS40422_VREF + ((s16)ret) * 2) << 9;
+ ret = DIV_ROUND_CLOSEST(ret, 1000);
+
+ return ret;
+}
+
+static int tps40422_write_word_data(struct i2c_client *client, int page,
+ int reg, u16 word)
+{
+ u16 val;
+
+ switch (reg) {
+ case PMBUS_VOUT_MARGIN_HIGH:
+ reg = TPS40422_STEP_VREF_MARGIN_HIGH;
+ break;
+ case PMBUS_VOUT_MARGIN_LOW:
+ reg = TPS40422_STEP_VREF_MARGIN_LOW;
+ break;
+ default:
+ return -ENODATA;
+ }
+
+ val = ((((long)word * 1000) >> 9) - TPS40422_VREF + 1) / 2;
+ return pmbus_write_word_data(client, page, reg, val);
+}
+
+
static struct pmbus_driver_info tps40422_info = {
.pages = 2,
+ .read_word_data = tps40422_read_word_data,
+ .write_word_data = tps40422_write_word_data,
.format[PSC_VOLTAGE_IN] = linear,
.format[PSC_VOLTAGE_OUT] = linear,
.format[PSC_TEMPERATURE] = linear,
.func[0] = PMBUS_HAVE_VOUT | PMBUS_HAVE_TEMP2
| PMBUS_HAVE_STATUS_VOUT | PMBUS_HAVE_STATUS_TEMP
+ | PMBUS_HAVE_VOUT_MARGIN_HIGH | PMBUS_HAVE_VOUT_MARGIN_LOW
| PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT,
.func[1] = PMBUS_HAVE_VOUT | PMBUS_HAVE_TEMP2
| PMBUS_HAVE_STATUS_VOUT | PMBUS_HAVE_STATUS_TEMP
+ | PMBUS_HAVE_VOUT_MARGIN_HIGH | PMBUS_HAVE_VOUT_MARGIN_LOW
| PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT,
};