npcm7xx_boards.c (65d6ae4927d2974bcfe9326c3fdfa0fac5c6295b) npcm7xx_boards.c (a9d3d7b17e5a3c246ecf4e420d2d4bb089a8d7c3)
1/*
2 * Machine definitions for boards featuring an NPCM7xx SoC.
3 *
4 * Copyright 2020 Google LLC
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or

--- 7 unchanged lines hidden (view full) ---

16
17#include "qemu/osdep.h"
18
19#include "exec/address-spaces.h"
20#include "hw/arm/npcm7xx.h"
21#include "hw/core/cpu.h"
22#include "hw/i2c/smbus_eeprom.h"
23#include "hw/loader.h"
1/*
2 * Machine definitions for boards featuring an NPCM7xx SoC.
3 *
4 * Copyright 2020 Google LLC
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or

--- 7 unchanged lines hidden (view full) ---

16
17#include "qemu/osdep.h"
18
19#include "exec/address-spaces.h"
20#include "hw/arm/npcm7xx.h"
21#include "hw/core/cpu.h"
22#include "hw/i2c/smbus_eeprom.h"
23#include "hw/loader.h"
24#include "hw/qdev-core.h"
24#include "hw/qdev-properties.h"
25#include "qapi/error.h"
26#include "qemu-common.h"
27#include "qemu/datadir.h"
28#include "qemu/units.h"
29#include "sysemu/sysemu.h"
30
31#define NPCM750_EVB_POWER_ON_STRAPS 0x00001ff7

--- 79 unchanged lines hidden (view full) ---

111 I2CBus *i2c_bus = npcm7xx_i2c_get_bus(soc, bus);
112 I2CSlave *i2c_dev = i2c_slave_new("at24c-eeprom", addr);
113 DeviceState *dev = DEVICE(i2c_dev);
114
115 qdev_prop_set_uint32(dev, "rom-size", rsize);
116 i2c_slave_realize_and_unref(i2c_dev, i2c_bus, &error_abort);
117}
118
25#include "hw/qdev-properties.h"
26#include "qapi/error.h"
27#include "qemu-common.h"
28#include "qemu/datadir.h"
29#include "qemu/units.h"
30#include "sysemu/sysemu.h"
31
32#define NPCM750_EVB_POWER_ON_STRAPS 0x00001ff7

--- 79 unchanged lines hidden (view full) ---

112 I2CBus *i2c_bus = npcm7xx_i2c_get_bus(soc, bus);
113 I2CSlave *i2c_dev = i2c_slave_new("at24c-eeprom", addr);
114 DeviceState *dev = DEVICE(i2c_dev);
115
116 qdev_prop_set_uint32(dev, "rom-size", rsize);
117 i2c_slave_realize_and_unref(i2c_dev, i2c_bus, &error_abort);
118}
119
120static void npcm7xx_init_pwm_splitter(NPCM7xxMachine *machine,
121 NPCM7xxState *soc, const int *fan_counts)
122{
123 SplitIRQ *splitters = machine->fan_splitter;
124
125 /*
126 * PWM 0~3 belong to module 0 output 0~3.
127 * PWM 4~7 belong to module 1 output 0~3.
128 */
129 for (int i = 0; i < NPCM7XX_NR_PWM_MODULES; ++i) {
130 for (int j = 0; j < NPCM7XX_PWM_PER_MODULE; ++j) {
131 int splitter_no = i * NPCM7XX_PWM_PER_MODULE + j;
132 DeviceState *splitter;
133
134 if (fan_counts[splitter_no] < 1) {
135 continue;
136 }
137 object_initialize_child(OBJECT(machine), "fan-splitter[*]",
138 &splitters[splitter_no], TYPE_SPLIT_IRQ);
139 splitter = DEVICE(&splitters[splitter_no]);
140 qdev_prop_set_uint16(splitter, "num-lines",
141 fan_counts[splitter_no]);
142 qdev_realize(splitter, NULL, &error_abort);
143 qdev_connect_gpio_out_named(DEVICE(&soc->pwm[i]), "duty-gpio-out",
144 j, qdev_get_gpio_in(splitter, 0));
145 }
146 }
147}
148
149static void npcm7xx_connect_pwm_fan(NPCM7xxState *soc, SplitIRQ *splitter,
150 int fan_no, int output_no)
151{
152 DeviceState *fan;
153 int fan_input;
154 qemu_irq fan_duty_gpio;
155
156 g_assert(fan_no >= 0 && fan_no <= NPCM7XX_MFT_MAX_FAN_INPUT);
157 /*
158 * Fan 0~1 belong to module 0 input 0~1.
159 * Fan 2~3 belong to module 1 input 0~1.
160 * ...
161 * Fan 14~15 belong to module 7 input 0~1.
162 * Fan 16~17 belong to module 0 input 2~3.
163 * Fan 18~19 belong to module 1 input 2~3.
164 */
165 if (fan_no < 16) {
166 fan = DEVICE(&soc->mft[fan_no / 2]);
167 fan_input = fan_no % 2;
168 } else {
169 fan = DEVICE(&soc->mft[(fan_no - 16) / 2]);
170 fan_input = fan_no % 2 + 2;
171 }
172
173 /* Connect the Fan to PWM module */
174 fan_duty_gpio = qdev_get_gpio_in_named(fan, "duty", fan_input);
175 qdev_connect_gpio_out(DEVICE(splitter), output_no, fan_duty_gpio);
176}
177
119static void npcm750_evb_i2c_init(NPCM7xxState *soc)
120{
121 /* lm75 temperature sensor on SVB, tmp105 is compatible */
122 i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 0), "tmp105", 0x48);
123 /* lm75 temperature sensor on EB, tmp105 is compatible */
124 i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 1), "tmp105", 0x48);
125 /* tmp100 temperature sensor on EB, tmp105 is compatible */
126 i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 2), "tmp105", 0x48);
127 /* tmp100 temperature sensor on SVB, tmp105 is compatible */
128 i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 6), "tmp105", 0x48);
129}
130
178static void npcm750_evb_i2c_init(NPCM7xxState *soc)
179{
180 /* lm75 temperature sensor on SVB, tmp105 is compatible */
181 i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 0), "tmp105", 0x48);
182 /* lm75 temperature sensor on EB, tmp105 is compatible */
183 i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 1), "tmp105", 0x48);
184 /* tmp100 temperature sensor on EB, tmp105 is compatible */
185 i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 2), "tmp105", 0x48);
186 /* tmp100 temperature sensor on SVB, tmp105 is compatible */
187 i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 6), "tmp105", 0x48);
188}
189
190static void npcm750_evb_fan_init(NPCM7xxMachine *machine, NPCM7xxState *soc)
191{
192 SplitIRQ *splitter = machine->fan_splitter;
193 static const int fan_counts[] = {2, 2, 2, 2, 2, 2, 2, 2};
194
195 npcm7xx_init_pwm_splitter(machine, soc, fan_counts);
196 npcm7xx_connect_pwm_fan(soc, &splitter[0], 0x00, 0);
197 npcm7xx_connect_pwm_fan(soc, &splitter[0], 0x01, 1);
198 npcm7xx_connect_pwm_fan(soc, &splitter[1], 0x02, 0);
199 npcm7xx_connect_pwm_fan(soc, &splitter[1], 0x03, 1);
200 npcm7xx_connect_pwm_fan(soc, &splitter[2], 0x04, 0);
201 npcm7xx_connect_pwm_fan(soc, &splitter[2], 0x05, 1);
202 npcm7xx_connect_pwm_fan(soc, &splitter[3], 0x06, 0);
203 npcm7xx_connect_pwm_fan(soc, &splitter[3], 0x07, 1);
204 npcm7xx_connect_pwm_fan(soc, &splitter[4], 0x08, 0);
205 npcm7xx_connect_pwm_fan(soc, &splitter[4], 0x09, 1);
206 npcm7xx_connect_pwm_fan(soc, &splitter[5], 0x0a, 0);
207 npcm7xx_connect_pwm_fan(soc, &splitter[5], 0x0b, 1);
208 npcm7xx_connect_pwm_fan(soc, &splitter[6], 0x0c, 0);
209 npcm7xx_connect_pwm_fan(soc, &splitter[6], 0x0d, 1);
210 npcm7xx_connect_pwm_fan(soc, &splitter[7], 0x0e, 0);
211 npcm7xx_connect_pwm_fan(soc, &splitter[7], 0x0f, 1);
212}
213
131static void quanta_gsj_i2c_init(NPCM7xxState *soc)
132{
133 /* GSJ machine have 4 max31725 temperature sensors, tmp105 is compatible. */
134 i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 1), "tmp105", 0x5c);
135 i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 2), "tmp105", 0x5c);
136 i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 3), "tmp105", 0x5c);
137 i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 4), "tmp105", 0x5c);
138
139 at24c_eeprom_init(soc, 9, 0x55, 8192);
140 at24c_eeprom_init(soc, 10, 0x55, 8192);
141
142 /* TODO: Add additional i2c devices. */
143}
144
214static void quanta_gsj_i2c_init(NPCM7xxState *soc)
215{
216 /* GSJ machine have 4 max31725 temperature sensors, tmp105 is compatible. */
217 i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 1), "tmp105", 0x5c);
218 i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 2), "tmp105", 0x5c);
219 i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 3), "tmp105", 0x5c);
220 i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 4), "tmp105", 0x5c);
221
222 at24c_eeprom_init(soc, 9, 0x55, 8192);
223 at24c_eeprom_init(soc, 10, 0x55, 8192);
224
225 /* TODO: Add additional i2c devices. */
226}
227
228static void quanta_gsj_fan_init(NPCM7xxMachine *machine, NPCM7xxState *soc)
229{
230 SplitIRQ *splitter = machine->fan_splitter;
231 static const int fan_counts[] = {2, 2, 2, 0, 0, 0, 0, 0};
232
233 npcm7xx_init_pwm_splitter(machine, soc, fan_counts);
234 npcm7xx_connect_pwm_fan(soc, &splitter[0], 0x00, 0);
235 npcm7xx_connect_pwm_fan(soc, &splitter[0], 0x01, 1);
236 npcm7xx_connect_pwm_fan(soc, &splitter[1], 0x02, 0);
237 npcm7xx_connect_pwm_fan(soc, &splitter[1], 0x03, 1);
238 npcm7xx_connect_pwm_fan(soc, &splitter[2], 0x04, 0);
239 npcm7xx_connect_pwm_fan(soc, &splitter[2], 0x05, 1);
240}
241
145static void npcm750_evb_init(MachineState *machine)
146{
147 NPCM7xxState *soc;
148
149 soc = npcm7xx_create_soc(machine, NPCM750_EVB_POWER_ON_STRAPS);
150 npcm7xx_connect_dram(soc, machine->ram);
151 qdev_realize(DEVICE(soc), NULL, &error_fatal);
152
153 npcm7xx_load_bootrom(machine, soc);
154 npcm7xx_connect_flash(&soc->fiu[0], 0, "w25q256", drive_get(IF_MTD, 0, 0));
155 npcm750_evb_i2c_init(soc);
242static void npcm750_evb_init(MachineState *machine)
243{
244 NPCM7xxState *soc;
245
246 soc = npcm7xx_create_soc(machine, NPCM750_EVB_POWER_ON_STRAPS);
247 npcm7xx_connect_dram(soc, machine->ram);
248 qdev_realize(DEVICE(soc), NULL, &error_fatal);
249
250 npcm7xx_load_bootrom(machine, soc);
251 npcm7xx_connect_flash(&soc->fiu[0], 0, "w25q256", drive_get(IF_MTD, 0, 0));
252 npcm750_evb_i2c_init(soc);
253 npcm750_evb_fan_init(NPCM7XX_MACHINE(machine), soc);
156 npcm7xx_load_kernel(machine, soc);
157}
158
159static void quanta_gsj_init(MachineState *machine)
160{
161 NPCM7xxState *soc;
162
163 soc = npcm7xx_create_soc(machine, QUANTA_GSJ_POWER_ON_STRAPS);
164 npcm7xx_connect_dram(soc, machine->ram);
165 qdev_realize(DEVICE(soc), NULL, &error_fatal);
166
167 npcm7xx_load_bootrom(machine, soc);
168 npcm7xx_connect_flash(&soc->fiu[0], 0, "mx25l25635e",
169 drive_get(IF_MTD, 0, 0));
170 quanta_gsj_i2c_init(soc);
254 npcm7xx_load_kernel(machine, soc);
255}
256
257static void quanta_gsj_init(MachineState *machine)
258{
259 NPCM7xxState *soc;
260
261 soc = npcm7xx_create_soc(machine, QUANTA_GSJ_POWER_ON_STRAPS);
262 npcm7xx_connect_dram(soc, machine->ram);
263 qdev_realize(DEVICE(soc), NULL, &error_fatal);
264
265 npcm7xx_load_bootrom(machine, soc);
266 npcm7xx_connect_flash(&soc->fiu[0], 0, "mx25l25635e",
267 drive_get(IF_MTD, 0, 0));
268 quanta_gsj_i2c_init(soc);
269 quanta_gsj_fan_init(NPCM7XX_MACHINE(machine), soc);
171 npcm7xx_load_kernel(machine, soc);
172}
173
174static void npcm7xx_set_soc_type(NPCM7xxMachineClass *nmc, const char *type)
175{
176 NPCM7xxClass *sc = NPCM7XX_CLASS(object_class_by_name(type));
177 MachineClass *mc = MACHINE_CLASS(nmc);
178

--- 63 unchanged lines hidden ---
270 npcm7xx_load_kernel(machine, soc);
271}
272
273static void npcm7xx_set_soc_type(NPCM7xxMachineClass *nmc, const char *type)
274{
275 NPCM7xxClass *sc = NPCM7XX_CLASS(object_class_by_name(type));
276 MachineClass *mc = MACHINE_CLASS(nmc);
277

--- 63 unchanged lines hidden ---