aboutsummaryrefslogtreecommitdiff
path: root/tests/qtest/adm1272-test.c
blob: 63f8514801bd36724bb2114506b34447d72b6521 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
/*
 * QTests for the ADM1272 hotswap controller
 *
 * Copyright 2021 Google LLC
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

#include "qemu/osdep.h"
#include <math.h>
#include "hw/i2c/pmbus_device.h"
#include "libqtest-single.h"
#include "libqos/qgraph.h"
#include "libqos/i2c.h"
#include "qapi/qmp/qdict.h"
#include "qapi/qmp/qnum.h"
#include "qemu/bitops.h"

#define TEST_ID "adm1272-test"
#define TEST_ADDR (0x10)

#define ADM1272_RESTART_TIME            0xCC
#define ADM1272_MFR_PEAK_IOUT           0xD0
#define ADM1272_MFR_PEAK_VIN            0xD1
#define ADM1272_MFR_PEAK_VOUT           0xD2
#define ADM1272_MFR_PMON_CONTROL        0xD3
#define ADM1272_MFR_PMON_CONFIG         0xD4
#define ADM1272_MFR_ALERT1_CONFIG       0xD5
#define ADM1272_MFR_ALERT2_CONFIG       0xD6
#define ADM1272_MFR_PEAK_TEMPERATURE    0xD7
#define ADM1272_MFR_DEVICE_CONFIG       0xD8
#define ADM1272_MFR_POWER_CYCLE         0xD9
#define ADM1272_MFR_PEAK_PIN            0xDA
#define ADM1272_MFR_READ_PIN_EXT        0xDB
#define ADM1272_MFR_READ_EIN_EXT        0xDC

#define ADM1272_HYSTERESIS_LOW          0xF2
#define ADM1272_HYSTERESIS_HIGH         0xF3
#define ADM1272_STATUS_HYSTERESIS       0xF4
#define ADM1272_STATUS_GPIO             0xF5
#define ADM1272_STRT_UP_IOUT_LIM        0xF6

/* Defaults */
#define ADM1272_OPERATION_DEFAULT       0x80
#define ADM1272_CAPABILITY_DEFAULT      0xB0
#define ADM1272_CAPABILITY_NO_PEC       0x30
#define ADM1272_DIRECT_MODE             0x40
#define ADM1272_HIGH_LIMIT_DEFAULT      0x0FFF
#define ADM1272_PIN_OP_DEFAULT          0x7FFF
#define ADM1272_PMBUS_REVISION_DEFAULT  0x22
#define ADM1272_MFR_ID_DEFAULT          "ADI"
#define ADM1272_MODEL_DEFAULT           "ADM1272-A1"
#define ADM1272_MFR_DEFAULT_REVISION    "25"
#define ADM1272_DEFAULT_DATE            "160301"
#define ADM1272_RESTART_TIME_DEFAULT    0x64
#define ADM1272_PMON_CONTROL_DEFAULT    0x1
#define ADM1272_PMON_CONFIG_DEFAULT     0x3F35
#define ADM1272_DEVICE_CONFIG_DEFAULT   0x8
#define ADM1272_HYSTERESIS_HIGH_DEFAULT     0xFFFF
#define ADM1272_STRT_UP_IOUT_LIM_DEFAULT    0x000F
#define ADM1272_VOLT_DEFAULT            12000
#define ADM1272_IOUT_DEFAULT            25000
#define ADM1272_PWR_DEFAULT             300  /* 12V 25A */
#define ADM1272_SHUNT                   300 /* micro-ohms */
#define ADM1272_VOLTAGE_COEFF_DEFAULT   1
#define ADM1272_CURRENT_COEFF_DEFAULT   3
#define ADM1272_PWR_COEFF_DEFAULT       7
#define ADM1272_IOUT_OFFSET             0x5000
#define ADM1272_IOUT_OFFSET             0x5000

static const PMBusCoefficients adm1272_coefficients[] = {
    [0] = { 6770, 0, -2 },       /* voltage, vrange 60V */
    [1] = { 4062, 0, -2 },       /* voltage, vrange 100V */
    [2] = { 1326, 20480, -1 },   /* current, vsense range 15mV */
    [3] = { 663, 20480, -1 },    /* current, vsense range 30mV */
    [4] = { 3512, 0, -2 },       /* power, vrange 60V, irange 15mV */
    [5] = { 21071, 0, -3 },      /* power, vrange 100V, irange 15mV */
    [6] = { 17561, 0, -3 },      /* power, vrange 60V, irange 30mV */
    [7] = { 10535, 0, -3 },      /* power, vrange 100V, irange 30mV */
    [8] = { 42, 31871, -1 },     /* temperature */
};

uint16_t pmbus_data2direct_mode(PMBusCoefficients c, uint32_t value)
{
    /* R is usually negative to fit large readings into 16 bits */
    uint16_t y = (c.m * value + c.b) * pow(10, c.R);
    return y;
}

uint32_t pmbus_direct_mode2data(PMBusCoefficients c, uint16_t value)
{
    /* X = (Y * 10^-R - b) / m */
    uint32_t x = (value / pow(10, c.R) - c.b) / c.m;
    return x;
}


static uint16_t adm1272_millivolts_to_direct(uint32_t value)
{
    PMBusCoefficients c = adm1272_coefficients[ADM1272_VOLTAGE_COEFF_DEFAULT];
    c.b = c.b * 1000;
    c.R = c.R - 3;
    return pmbus_data2direct_mode(c, value);
}

static uint32_t adm1272_direct_to_millivolts(uint16_t value)
{
    PMBusCoefficients c = adm1272_coefficients[ADM1272_VOLTAGE_COEFF_DEFAULT];
    c.b = c.b * 1000;
    c.R = c.R - 3;
    return pmbus_direct_mode2data(c, value);
}

static uint16_t adm1272_milliamps_to_direct(uint32_t value)
{
    PMBusCoefficients c = adm1272_coefficients[ADM1272_CURRENT_COEFF_DEFAULT];
    /* Y = (m * r_sense * x - b) * 10^R */
    c.m = c.m * ADM1272_SHUNT / 1000; /* micro-ohms */
    c.b = c.b * 1000;
    c.R = c.R - 3;
    return pmbus_data2direct_mode(c, value);
}

static uint32_t adm1272_direct_to_milliamps(uint16_t value)
{
    PMBusCoefficients c = adm1272_coefficients[ADM1272_CURRENT_COEFF_DEFAULT];
    c.m = c.m * ADM1272_SHUNT / 1000;
    c.b = c.b * 1000;
    c.R = c.R - 3;
    return pmbus_direct_mode2data(c, value);
}

static uint16_t adm1272_watts_to_direct(uint32_t value)
{
    PMBusCoefficients c = adm1272_coefficients[ADM1272_PWR_COEFF_DEFAULT];
    c.m = c.m * ADM1272_SHUNT / 1000;
    return pmbus_data2direct_mode(c, value);
}

static uint32_t adm1272_direct_to_watts(uint16_t value)
{
    PMBusCoefficients c = adm1272_coefficients[ADM1272_PWR_COEFF_DEFAULT];
    c.m = c.m * ADM1272_SHUNT / 1000;
    return pmbus_direct_mode2data(c, value);
}

static uint16_t qmp_adm1272_get(const char *id, const char *property)
{
    QDict *response;
    uint64_t ret;

    response = qmp("{ 'execute': 'qom-get', 'arguments': { 'path': %s, "
                   "'property': %s } }", id, property);
    g_assert(qdict_haskey(response, "return"));
    ret = qnum_get_uint(qobject_to(QNum, qdict_get(response, "return")));
    qobject_unref(response);
    return ret;
}

static void qmp_adm1272_set(const char *id,
                            const char *property,
                            uint16_t value)
{
    QDict *response;

    response = qmp("{ 'execute': 'qom-set', 'arguments': { 'path': %s, "
                   "'property': %s, 'value': %u } }", id, property, value);
    g_assert(qdict_haskey(response, "return"));
    qobject_unref(response);
}

/* PMBus commands are little endian vs i2c_set16 in i2c.h which is big endian */
static uint16_t adm1272_i2c_get16(QI2CDevice *i2cdev, uint8_t reg)
{
    uint8_t resp[2];
    i2c_read_block(i2cdev, reg, resp, sizeof(resp));
    return (resp[1] << 8) | resp[0];
}

/* PMBus commands are little endian vs i2c_set16 in i2c.h which is big endian */
static void adm1272_i2c_set16(QI2CDevice *i2cdev, uint8_t reg, uint16_t value)
{
    uint8_t data[2];

    data[0] = value & 255;
    data[1] = value >> 8;
    i2c_write_block(i2cdev, reg, data, sizeof(data));
}

static void test_defaults(void *obj, void *data, QGuestAllocator *alloc)
{
    uint16_t value, i2c_value;
    int16_t err;
    QI2CDevice *i2cdev = (QI2CDevice *)obj;
    value = qmp_adm1272_get(TEST_ID, "vout");
    err = ADM1272_VOLT_DEFAULT - value;
    g_assert_cmpuint(abs(err), <, ADM1272_VOLT_DEFAULT / 20);

    i2c_value = i2c_get8(i2cdev, PMBUS_OPERATION);
    g_assert_cmphex(i2c_value, ==, ADM1272_OPERATION_DEFAULT);

    i2c_value = i2c_get8(i2cdev, PMBUS_VOUT_MODE);
    g_assert_cmphex(i2c_value, ==, ADM1272_DIRECT_MODE);

    i2c_value = adm1272_i2c_get16(i2cdev, PMBUS_VOUT_OV_WARN_LIMIT);
    g_assert_cmphex(i2c_value, ==, ADM1272_HIGH_LIMIT_DEFAULT);

    i2c_value = adm1272_i2c_get16(i2cdev, PMBUS_VOUT_UV_WARN_LIMIT);
    g_assert_cmphex(i2c_value, ==, 0);

    i2c_value = adm1272_i2c_get16(i2cdev, PMBUS_IOUT_OC_WARN_LIMIT);
    g_assert_cmphex(i2c_value, ==, ADM1272_HIGH_LIMIT_DEFAULT);

    i2c_value = adm1272_i2c_get16(i2cdev, PMBUS_OT_FAULT_LIMIT);
    g_assert_cmphex(i2c_value, ==, ADM1272_HIGH_LIMIT_DEFAULT);

    i2c_value = adm1272_i2c_get16(i2cdev, PMBUS_OT_WARN_LIMIT);
    g_assert_cmphex(i2c_value, ==, ADM1272_HIGH_LIMIT_DEFAULT);

    i2c_value = adm1272_i2c_get16(i2cdev, PMBUS_VIN_OV_WARN_LIMIT);
    g_assert_cmphex(i2c_value, ==, ADM1272_HIGH_LIMIT_DEFAULT);

    i2c_value = adm1272_i2c_get16(i2cdev, PMBUS_VIN_UV_WARN_LIMIT);
    g_assert_cmphex(i2c_value, ==, 0);

    i2c_value = adm1272_i2c_get16(i2cdev, PMBUS_PIN_OP_WARN_LIMIT);
    g_assert_cmphex(i2c_value, ==, ADM1272_PIN_OP_DEFAULT);

    i2c_value = i2c_get8(i2cdev, PMBUS_REVISION);
    g_assert_cmphex(i2c_value, ==, ADM1272_PMBUS_REVISION_DEFAULT);

    i2c_value = i2c_get8(i2cdev, ADM1272_MFR_PMON_CONTROL);
    g_assert_cmphex(i2c_value, ==, ADM1272_PMON_CONTROL_DEFAULT);

    i2c_value = adm1272_i2c_get16(i2cdev, ADM1272_MFR_PMON_CONFIG);
    g_assert_cmphex(i2c_value, ==, ADM1272_PMON_CONFIG_DEFAULT);

    i2c_value = adm1272_i2c_get16(i2cdev, ADM1272_MFR_DEVICE_CONFIG);
    g_assert_cmphex(i2c_value, ==, ADM1272_DEVICE_CONFIG_DEFAULT);

    i2c_value = adm1272_i2c_get16(i2cdev, ADM1272_HYSTERESIS_HIGH);
    g_assert_cmphex(i2c_value, ==, ADM1272_HYSTERESIS_HIGH_DEFAULT);

    i2c_value = adm1272_i2c_get16(i2cdev, ADM1272_STRT_UP_IOUT_LIM);
    g_assert_cmphex(i2c_value, ==, ADM1272_STRT_UP_IOUT_LIM_DEFAULT);
}

/* test qmp access */
static void test_tx_rx(void *obj, void *data, QGuestAllocator *alloc)
{
    uint16_t i2c_value, value, i2c_voltage, i2c_pwr, lossy_value;
    QI2CDevice *i2cdev = (QI2CDevice *)obj;

    /* converting to direct mode is lossy - we generate the same loss here */
    lossy_value =
        adm1272_direct_to_millivolts(adm1272_millivolts_to_direct(1000));
    qmp_adm1272_set(TEST_ID, "vin", 1000);
    value = qmp_adm1272_get(TEST_ID, "vin");
    i2c_value = adm1272_i2c_get16(i2cdev, PMBUS_READ_VIN);
    i2c_voltage = adm1272_direct_to_millivolts(i2c_value);
    g_assert_cmpuint(value, ==, i2c_voltage);
    g_assert_cmpuint(i2c_voltage, ==, lossy_value);

    lossy_value =
        adm1272_direct_to_millivolts(adm1272_millivolts_to_direct(1500));
    qmp_adm1272_set(TEST_ID, "vout", 1500);
    value = qmp_adm1272_get(TEST_ID, "vout");
    i2c_value = adm1272_i2c_get16(i2cdev, PMBUS_READ_VOUT);
    i2c_voltage = adm1272_direct_to_millivolts(i2c_value);
    g_assert_cmpuint(value, ==, i2c_voltage);
    g_assert_cmpuint(i2c_voltage, ==, lossy_value);

    lossy_value =
        adm1272_direct_to_milliamps(adm1272_milliamps_to_direct(1600));
    qmp_adm1272_set(TEST_ID, "iout", 1600);
    value = qmp_adm1272_get(TEST_ID, "iout");
    i2c_value = adm1272_i2c_get16(i2cdev, PMBUS_READ_IOUT);
    i2c_value = adm1272_direct_to_milliamps(i2c_value);
    g_assert_cmphex(value, ==, i2c_value);
    g_assert_cmphex(i2c_value, ==, lossy_value);

    lossy_value =
        adm1272_direct_to_watts(adm1272_watts_to_direct(320));
    qmp_adm1272_set(TEST_ID, "pin", 320);
    value = qmp_adm1272_get(TEST_ID, "pin");
    i2c_value = adm1272_i2c_get16(i2cdev, PMBUS_READ_PIN);
    i2c_pwr = adm1272_direct_to_watts(i2c_value);
    g_assert_cmphex(value, ==, i2c_pwr);
    g_assert_cmphex(i2c_pwr, ==, lossy_value);
}

/* test r/w registers */
static void test_rw_regs(void *obj, void *data, QGuestAllocator *alloc)
{
    uint16_t i2c_value;
    QI2CDevice *i2cdev = (QI2CDevice *)obj;

    adm1272_i2c_set16(i2cdev, PMBUS_VOUT_OV_WARN_LIMIT, 0xABCD);
    i2c_value = adm1272_i2c_get16(i2cdev, PMBUS_VOUT_OV_WARN_LIMIT);
    g_assert_cmphex(i2c_value, ==, 0xABCD);

    adm1272_i2c_set16(i2cdev, PMBUS_VOUT_UV_WARN_LIMIT, 0xCDEF);
    i2c_value = adm1272_i2c_get16(i2cdev, PMBUS_VOUT_UV_WARN_LIMIT);
    g_assert_cmphex(i2c_value, ==, 0xCDEF);

    adm1272_i2c_set16(i2cdev, PMBUS_IOUT_OC_WARN_LIMIT, 0x1234);
    i2c_value = adm1272_i2c_get16(i2cdev, PMBUS_IOUT_OC_WARN_LIMIT);
    g_assert_cmphex(i2c_value, ==, 0x1234);

    adm1272_i2c_set16(i2cdev, PMBUS_OT_FAULT_LIMIT, 0x5678);
    i2c_value = adm1272_i2c_get16(i2cdev, PMBUS_OT_FAULT_LIMIT);
    g_assert_cmphex(i2c_value, ==, 0x5678);

    adm1272_i2c_set16(i2cdev, PMBUS_OT_WARN_LIMIT, 0xABDC);
    i2c_value = adm1272_i2c_get16(i2cdev, PMBUS_OT_WARN_LIMIT);
    g_assert_cmphex(i2c_value, ==, 0xABDC);

    adm1272_i2c_set16(i2cdev, PMBUS_VIN_OV_WARN_LIMIT, 0xCDEF);
    i2c_value = adm1272_i2c_get16(i2cdev, PMBUS_VIN_OV_WARN_LIMIT);
    g_assert_cmphex(i2c_value, ==, 0xCDEF);

    adm1272_i2c_set16(i2cdev, PMBUS_VIN_UV_WARN_LIMIT, 0x2345);
    i2c_value = adm1272_i2c_get16(i2cdev, PMBUS_VIN_UV_WARN_LIMIT);
    g_assert_cmphex(i2c_value, ==, 0x2345);

    i2c_set8(i2cdev, ADM1272_RESTART_TIME, 0xF8);
    i2c_value = i2c_get8(i2cdev, ADM1272_RESTART_TIME);
    g_assert_cmphex(i2c_value, ==, 0xF8);

    i2c_set8(i2cdev, ADM1272_MFR_PMON_CONTROL, 0);
    i2c_value = i2c_get8(i2cdev, ADM1272_MFR_PMON_CONTROL);
    g_assert_cmpuint(i2c_value, ==, 0);

    adm1272_i2c_set16(i2cdev, ADM1272_MFR_PMON_CONFIG, 0xDEF0);
    i2c_value = adm1272_i2c_get16(i2cdev, ADM1272_MFR_PMON_CONFIG);
    g_assert_cmphex(i2c_value, ==, 0xDEF0);

    adm1272_i2c_set16(i2cdev, ADM1272_MFR_ALERT1_CONFIG, 0x0123);
    i2c_value = adm1272_i2c_get16(i2cdev, ADM1272_MFR_ALERT1_CONFIG);
    g_assert_cmphex(i2c_value, ==, 0x0123);

    adm1272_i2c_set16(i2cdev, ADM1272_MFR_ALERT2_CONFIG, 0x9876);
    i2c_value = adm1272_i2c_get16(i2cdev, ADM1272_MFR_ALERT2_CONFIG);
    g_assert_cmphex(i2c_value, ==, 0x9876);

    adm1272_i2c_set16(i2cdev, ADM1272_MFR_DEVICE_CONFIG, 0x3456);
    i2c_value = adm1272_i2c_get16(i2cdev, ADM1272_MFR_DEVICE_CONFIG);
    g_assert_cmphex(i2c_value, ==, 0x3456);

    adm1272_i2c_set16(i2cdev, ADM1272_HYSTERESIS_LOW, 0xCABA);
    i2c_value = adm1272_i2c_get16(i2cdev, ADM1272_HYSTERESIS_LOW);
    g_assert_cmphex(i2c_value, ==, 0xCABA);

    adm1272_i2c_set16(i2cdev, ADM1272_HYSTERESIS_HIGH, 0x6789);
    i2c_value = adm1272_i2c_get16(i2cdev, ADM1272_HYSTERESIS_HIGH);
    g_assert_cmphex(i2c_value, ==, 0x6789);

    adm1272_i2c_set16(i2cdev, ADM1272_STRT_UP_IOUT_LIM, 0x9876);
    i2c_value = adm1272_i2c_get16(i2cdev, ADM1272_STRT_UP_IOUT_LIM);
    g_assert_cmphex(i2c_value, ==, 0x9876);

    adm1272_i2c_set16(i2cdev, PMBUS_OPERATION, 0xA);
    i2c_value = i2c_get8(i2cdev, PMBUS_OPERATION);
    g_assert_cmphex(i2c_value, ==, 0xA);
}

/* test read-only registers */
static void test_ro_regs(void *obj, void *data, QGuestAllocator *alloc)
{
    uint16_t i2c_init_value, i2c_value;
    QI2CDevice *i2cdev = (QI2CDevice *)obj;

    i2c_init_value = adm1272_i2c_get16(i2cdev, PMBUS_READ_VIN);
    adm1272_i2c_set16(i2cdev, PMBUS_READ_VIN, 0xBEEF);
    i2c_value = adm1272_i2c_get16(i2cdev, PMBUS_READ_VIN);
    g_assert_cmphex(i2c_init_value, ==, i2c_value);

    i2c_init_value = adm1272_i2c_get16(i2cdev, PMBUS_READ_VOUT);
    adm1272_i2c_set16(i2cdev, PMBUS_READ_VOUT, 0x1234);
    i2c_value = adm1272_i2c_get16(i2cdev, PMBUS_READ_VOUT);
    g_assert_cmphex(i2c_init_value, ==, i2c_value);

    i2c_init_value = adm1272_i2c_get16(i2cdev, PMBUS_READ_IOUT);
    adm1272_i2c_set16(i2cdev, PMBUS_READ_IOUT, 0x6547);
    i2c_value = adm1272_i2c_get16(i2cdev, PMBUS_READ_IOUT);
    g_assert_cmphex(i2c_init_value, ==, i2c_value);

    i2c_init_value = adm1272_i2c_get16(i2cdev, PMBUS_READ_TEMPERATURE_1);
    adm1272_i2c_set16(i2cdev, PMBUS_READ_TEMPERATURE_1, 0x1597);
    i2c_value = adm1272_i2c_get16(i2cdev, PMBUS_READ_TEMPERATURE_1);
    g_assert_cmphex(i2c_init_value, ==, i2c_value);

    i2c_init_value = adm1272_i2c_get16(i2cdev, PMBUS_READ_PIN);
    adm1272_i2c_set16(i2cdev, PMBUS_READ_PIN, 0xDEAD);
    i2c_value = adm1272_i2c_get16(i2cdev, PMBUS_READ_PIN);
    g_assert_cmphex(i2c_init_value, ==, i2c_value);
}

/* test voltage fault handling */
static void test_voltage_faults(void *obj, void *data, QGuestAllocator *alloc)
{
    uint16_t i2c_value;
    uint8_t i2c_byte;
    QI2CDevice *i2cdev = (QI2CDevice *)obj;

    adm1272_i2c_set16(i2cdev, PMBUS_VOUT_OV_WARN_LIMIT,
                      adm1272_millivolts_to_direct(5000));
    qmp_adm1272_set(TEST_ID, "vout", 5100);

    i2c_value = adm1272_i2c_get16(i2cdev, PMBUS_STATUS_WORD);
    i2c_byte = i2c_get8(i2cdev, PMBUS_STATUS_VOUT);
    g_assert_true((i2c_value & PB_STATUS_VOUT) != 0);
    g_assert_true((i2c_byte & PB_STATUS_VOUT_OV_WARN) != 0);

    qmp_adm1272_set(TEST_ID, "vout", 4500);
    i2c_set8(i2cdev, PMBUS_CLEAR_FAULTS, 0);
    i2c_byte = i2c_get8(i2cdev, PMBUS_STATUS_VOUT);
    g_assert_true((i2c_byte & PB_STATUS_VOUT_OV_WARN) == 0);

    adm1272_i2c_set16(i2cdev, PMBUS_VOUT_UV_WARN_LIMIT,
                      adm1272_millivolts_to_direct(4600));
    i2c_value = adm1272_i2c_get16(i2cdev, PMBUS_STATUS_WORD);
    i2c_byte = i2c_get8(i2cdev, PMBUS_STATUS_VOUT);
    g_assert_true((i2c_value & PB_STATUS_VOUT) != 0);
    g_assert_true((i2c_byte & PB_STATUS_VOUT_UV_WARN) != 0);

}

static void adm1272_register_nodes(void)
{
    QOSGraphEdgeOptions opts = {
        .extra_device_opts = "id=" TEST_ID ",address=0x10"
    };
    add_qi2c_address(&opts, &(QI2CAddress) { TEST_ADDR });

    qos_node_create_driver("adm1272", i2c_device_create);
    qos_node_consumes("adm1272", "i2c-bus", &opts);

    qos_add_test("test_defaults", "adm1272", test_defaults, NULL);
    qos_add_test("test_tx_rx", "adm1272", test_tx_rx, NULL);
    qos_add_test("test_rw_regs", "adm1272", test_rw_regs, NULL);
    qos_add_test("test_ro_regs", "adm1272", test_ro_regs, NULL);
    qos_add_test("test_ov_faults", "adm1272", test_voltage_faults, NULL);
}
libqos_init(adm1272_register_nodes);