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
|
/*
* PMBus device for Renesas Digital Multiphase Voltage Regulators
*
* Copyright 2021 Google LLC
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "qemu/osdep.h"
#include "hw/sensor/isl_pmbus_vr.h"
#include "hw/qdev-properties.h"
#include "qapi/visitor.h"
#include "qemu/log.h"
#include "qemu/module.h"
static uint8_t isl_pmbus_vr_read_byte(PMBusDevice *pmdev)
{
qemu_log_mask(LOG_GUEST_ERROR,
"%s: reading from unsupported register: 0x%02x\n",
__func__, pmdev->code);
return PMBUS_ERR_BYTE;
}
static int isl_pmbus_vr_write_data(PMBusDevice *pmdev, const uint8_t *buf,
uint8_t len)
{
qemu_log_mask(LOG_GUEST_ERROR,
"%s: write to unsupported register: 0x%02x\n",
__func__, pmdev->code);
return PMBUS_ERR_BYTE;
}
/* TODO: Implement coefficients support in pmbus_device.c for qmp */
static void isl_pmbus_vr_get(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp)
{
visit_type_uint16(v, name, (uint16_t *)opaque, errp);
}
static void isl_pmbus_vr_set(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp)
{
PMBusDevice *pmdev = PMBUS_DEVICE(obj);
uint16_t *internal = opaque;
uint16_t value;
if (!visit_type_uint16(v, name, &value, errp)) {
return;
}
*internal = value;
pmbus_check_limits(pmdev);
}
static void isl_pmbus_vr_exit_reset(Object *obj)
{
PMBusDevice *pmdev = PMBUS_DEVICE(obj);
pmdev->page = 0;
pmdev->capability = ISL_CAPABILITY_DEFAULT;
for (int i = 0; i < pmdev->num_pages; i++) {
pmdev->pages[i].operation = ISL_OPERATION_DEFAULT;
pmdev->pages[i].on_off_config = ISL_ON_OFF_CONFIG_DEFAULT;
pmdev->pages[i].vout_mode = ISL_VOUT_MODE_DEFAULT;
pmdev->pages[i].vout_command = ISL_VOUT_COMMAND_DEFAULT;
pmdev->pages[i].vout_max = ISL_VOUT_MAX_DEFAULT;
pmdev->pages[i].vout_margin_high = ISL_VOUT_MARGIN_HIGH_DEFAULT;
pmdev->pages[i].vout_margin_low = ISL_VOUT_MARGIN_LOW_DEFAULT;
pmdev->pages[i].vout_transition_rate = ISL_VOUT_TRANSITION_RATE_DEFAULT;
pmdev->pages[i].vout_ov_fault_limit = ISL_VOUT_OV_FAULT_LIMIT_DEFAULT;
pmdev->pages[i].ot_fault_limit = ISL_OT_FAULT_LIMIT_DEFAULT;
pmdev->pages[i].ot_warn_limit = ISL_OT_WARN_LIMIT_DEFAULT;
pmdev->pages[i].vin_ov_warn_limit = ISL_VIN_OV_WARN_LIMIT_DEFAULT;
pmdev->pages[i].vin_uv_warn_limit = ISL_VIN_UV_WARN_LIMIT_DEFAULT;
pmdev->pages[i].iin_oc_fault_limit = ISL_IIN_OC_FAULT_LIMIT_DEFAULT;
pmdev->pages[i].ton_delay = ISL_TON_DELAY_DEFAULT;
pmdev->pages[i].ton_rise = ISL_TON_RISE_DEFAULT;
pmdev->pages[i].toff_fall = ISL_TOFF_FALL_DEFAULT;
pmdev->pages[i].revision = ISL_REVISION_DEFAULT;
pmdev->pages[i].read_vout = ISL_READ_VOUT_DEFAULT;
pmdev->pages[i].read_iout = ISL_READ_IOUT_DEFAULT;
pmdev->pages[i].read_pout = ISL_READ_POUT_DEFAULT;
pmdev->pages[i].read_vin = ISL_READ_VIN_DEFAULT;
pmdev->pages[i].read_iin = ISL_READ_IIN_DEFAULT;
pmdev->pages[i].read_pin = ISL_READ_PIN_DEFAULT;
pmdev->pages[i].read_temperature_1 = ISL_READ_TEMP_DEFAULT;
pmdev->pages[i].read_temperature_2 = ISL_READ_TEMP_DEFAULT;
pmdev->pages[i].read_temperature_3 = ISL_READ_TEMP_DEFAULT;
}
}
static void isl_pmbus_vr_add_props(Object *obj, uint64_t *flags, uint8_t pages)
{
PMBusDevice *pmdev = PMBUS_DEVICE(obj);
for (int i = 0; i < pages; i++) {
if (flags[i] & PB_HAS_VIN) {
object_property_add(obj, "vin[*]", "uint16",
isl_pmbus_vr_get,
isl_pmbus_vr_set,
NULL, &pmdev->pages[i].read_vin);
}
if (flags[i] & PB_HAS_VOUT) {
object_property_add(obj, "vout[*]", "uint16",
isl_pmbus_vr_get,
isl_pmbus_vr_set,
NULL, &pmdev->pages[i].read_vout);
}
if (flags[i] & PB_HAS_IIN) {
object_property_add(obj, "iin[*]", "uint16",
isl_pmbus_vr_get,
isl_pmbus_vr_set,
NULL, &pmdev->pages[i].read_iin);
}
if (flags[i] & PB_HAS_IOUT) {
object_property_add(obj, "iout[*]", "uint16",
isl_pmbus_vr_get,
isl_pmbus_vr_set,
NULL, &pmdev->pages[i].read_iout);
}
if (flags[i] & PB_HAS_PIN) {
object_property_add(obj, "pin[*]", "uint16",
isl_pmbus_vr_get,
isl_pmbus_vr_set,
NULL, &pmdev->pages[i].read_pin);
}
if (flags[i] & PB_HAS_POUT) {
object_property_add(obj, "pout[*]", "uint16",
isl_pmbus_vr_get,
isl_pmbus_vr_set,
NULL, &pmdev->pages[i].read_pout);
}
if (flags[i] & PB_HAS_TEMPERATURE) {
object_property_add(obj, "temp1[*]", "uint16",
isl_pmbus_vr_get,
isl_pmbus_vr_set,
NULL, &pmdev->pages[i].read_temperature_1);
}
if (flags[i] & PB_HAS_TEMP2) {
object_property_add(obj, "temp2[*]", "uint16",
isl_pmbus_vr_get,
isl_pmbus_vr_set,
NULL, &pmdev->pages[i].read_temperature_2);
}
if (flags[i] & PB_HAS_TEMP3) {
object_property_add(obj, "temp3[*]", "uint16",
isl_pmbus_vr_get,
isl_pmbus_vr_set,
NULL, &pmdev->pages[i].read_temperature_3);
}
}
}
static void raa22xx_init(Object *obj)
{
PMBusDevice *pmdev = PMBUS_DEVICE(obj);
uint64_t flags[2];
flags[0] = PB_HAS_VIN | PB_HAS_VOUT | PB_HAS_VOUT_MODE |
PB_HAS_VOUT_RATING | PB_HAS_VOUT_MARGIN | PB_HAS_IIN |
PB_HAS_IOUT | PB_HAS_PIN | PB_HAS_POUT | PB_HAS_TEMPERATURE |
PB_HAS_TEMP2 | PB_HAS_TEMP3 | PB_HAS_STATUS_MFR_SPECIFIC;
flags[1] = PB_HAS_IIN | PB_HAS_PIN | PB_HAS_TEMPERATURE | PB_HAS_TEMP3 |
PB_HAS_VOUT | PB_HAS_VOUT_MODE | PB_HAS_VOUT_MARGIN |
PB_HAS_VOUT_RATING | PB_HAS_IOUT | PB_HAS_POUT |
PB_HAS_STATUS_MFR_SPECIFIC;
pmbus_page_config(pmdev, 0, flags[0]);
pmbus_page_config(pmdev, 1, flags[1]);
isl_pmbus_vr_add_props(obj, flags, ARRAY_SIZE(flags));
}
static void isl_pmbus_vr_class_init(ObjectClass *klass, void *data,
uint8_t pages)
{
PMBusDeviceClass *k = PMBUS_DEVICE_CLASS(klass);
k->write_data = isl_pmbus_vr_write_data;
k->receive_byte = isl_pmbus_vr_read_byte;
k->device_num_pages = pages;
}
static void isl69260_class_init(ObjectClass *klass, void *data)
{
ResettableClass *rc = RESETTABLE_CLASS(klass);
DeviceClass *dc = DEVICE_CLASS(klass);
dc->desc = "Renesas ISL69260 Digital Multiphase Voltage Regulator";
rc->phases.exit = isl_pmbus_vr_exit_reset;
isl_pmbus_vr_class_init(klass, data, 2);
}
static const TypeInfo isl69260_info = {
.name = TYPE_ISL69260,
.parent = TYPE_PMBUS_DEVICE,
.instance_size = sizeof(ISLState),
.instance_init = raa22xx_init,
.class_init = isl69260_class_init,
};
static void isl_pmbus_vr_register_types(void)
{
type_register_static(&isl69260_info);
}
type_init(isl_pmbus_vr_register_types)
|