Skip to content

Commit 81d8537

Browse files
committed
Merge remote-tracking branch 'remotes/clg/tags/pull-aspeed-20211012' into staging
Aspeed patches : * I2C QOMify (Cedric) * SMC model cleanup and QOMify (Cedric) * ADC model (Peter and Andrew) * GPIO fixes (Peter) # gpg: Signature made Tue 12 Oct 2021 12:36:22 AM PDT # gpg: using RSA key A0F66548F04895EBFE6B0B6051A343C7CFFBECA1 # gpg: Good signature from "Cédric Le Goater <[email protected]>" [marginal] # gpg: WARNING: This key is not certified with sufficiently trusted signatures! # gpg: It is not certain that the signature belongs to the owner. # Primary key fingerprint: A0F6 6548 F048 95EB FE6B 0B60 51A3 43C7 CFFB ECA1 * remotes/clg/tags/pull-aspeed-20211012: aspeed/smc: Dump address offset in trace events aspeed/wdt: Add trace events hw/arm: Integrate ADC model into Aspeed SoC hw/adc: Add basic Aspeed ADC model hw: aspeed_gpio: Fix GPIO array indexing hw: aspeed_gpio: Fix pin I/O type declarations aspeed/i2c: QOMify AspeedI2CBus aspeed/smc: Remove unused attribute 'irqline' aspeed/smc: Introduce a new addr_width() class handler aspeed/smc: Add default reset values aspeed/smc: QOMify AspeedSMCFlash aspeed/smc: Rename AspeedSMCFlash 'id' to 'cs' aspeed/smc: Remove the 'size' attribute from AspeedSMCFlash aspeed/smc: Remove the 'flash' attribute from AspeedSMCFlash aspeed/smc: Drop AspeedSMCController structure aspeed/smc: Stop using the model name for the memory regions aspeed/smc: Introduce aspeed_smc_error() helper aspeed/smc: Add watchdog Control/Status Registers Signed-off-by: Richard Henderson <[email protected]>
2 parents c09124d + e2804a1 commit 81d8537

File tree

16 files changed

+1352
-618
lines changed

16 files changed

+1352
-618
lines changed

hw/adc/aspeed_adc.c

Lines changed: 427 additions & 0 deletions
Large diffs are not rendered by default.

hw/adc/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
softmmu_ss.add(when: 'CONFIG_STM32F2XX_ADC', if_true: files('stm32f2xx_adc.c'))
2+
softmmu_ss.add(when: 'CONFIG_ASPEED_SOC', if_true: files('aspeed_adc.c'))
23
softmmu_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx_adc.c'))
34
softmmu_ss.add(when: 'CONFIG_ZYNQ', if_true: files('zynq-xadc.c'))
45
softmmu_ss.add(when: 'CONFIG_MAX111X', if_true: files('max111x.c'))

hw/adc/trace-events

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@
33
# npcm7xx_adc.c
44
npcm7xx_adc_read(const char *id, uint64_t offset, uint32_t value) " %s offset: 0x%04" PRIx64 " value 0x%04" PRIx32
55
npcm7xx_adc_write(const char *id, uint64_t offset, uint32_t value) "%s offset: 0x%04" PRIx64 " value 0x%04" PRIx32
6+
7+
aspeed_adc_engine_read(uint32_t engine_id, uint64_t addr, uint64_t value) "engine[%u] 0x%" PRIx64 " 0x%" PRIx64
8+
aspeed_adc_engine_write(uint32_t engine_id, uint64_t addr, uint64_t value) "engine[%u] 0x%" PRIx64 " 0x%" PRIx64

hw/arm/aspeed.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -274,18 +274,17 @@ static void aspeed_board_init_flashes(AspeedSMCState *s,
274274
int i ;
275275

276276
for (i = 0; i < s->num_cs; ++i) {
277-
AspeedSMCFlash *fl = &s->flashes[i];
278277
DriveInfo *dinfo = drive_get_next(IF_MTD);
279278
qemu_irq cs_line;
279+
DeviceState *dev;
280280

281-
fl->flash = qdev_new(flashtype);
281+
dev = qdev_new(flashtype);
282282
if (dinfo) {
283-
qdev_prop_set_drive(fl->flash, "drive",
284-
blk_by_legacy_dinfo(dinfo));
283+
qdev_prop_set_drive(dev, "drive", blk_by_legacy_dinfo(dinfo));
285284
}
286-
qdev_realize_and_unref(fl->flash, BUS(s->spi), &error_fatal);
285+
qdev_realize_and_unref(dev, BUS(s->spi), &error_fatal);
287286

288-
cs_line = qdev_get_gpio_in_named(fl->flash, SSI_GPIO_CS, 0);
287+
cs_line = qdev_get_gpio_in_named(dev, SSI_GPIO_CS, 0);
289288
sysbus_connect_irq(SYS_BUS_DEVICE(s), i + 1, cs_line);
290289
}
291290
}
@@ -377,6 +376,7 @@ static void aspeed_machine_init(MachineState *machine)
377376
if (drive0) {
378377
AspeedSMCFlash *fl = &bmc->soc.fmc.flashes[0];
379378
MemoryRegion *boot_rom = g_new(MemoryRegion, 1);
379+
uint64_t size = memory_region_size(&fl->mmio);
380380

381381
/*
382382
* create a ROM region using the default mapping window size of
@@ -386,15 +386,15 @@ static void aspeed_machine_init(MachineState *machine)
386386
*/
387387
if (ASPEED_MACHINE(machine)->mmio_exec) {
388388
memory_region_init_alias(boot_rom, NULL, "aspeed.boot_rom",
389-
&fl->mmio, 0, fl->size);
389+
&fl->mmio, 0, size);
390390
memory_region_add_subregion(get_system_memory(), FIRMWARE_ADDR,
391391
boot_rom);
392392
} else {
393393
memory_region_init_rom(boot_rom, NULL, "aspeed.boot_rom",
394-
fl->size, &error_abort);
394+
size, &error_abort);
395395
memory_region_add_subregion(get_system_memory(), FIRMWARE_ADDR,
396396
boot_rom);
397-
write_boot_rom(drive0, FIRMWARE_ADDR, fl->size, &error_abort);
397+
write_boot_rom(drive0, FIRMWARE_ADDR, size, &error_abort);
398398
}
399399
}
400400

hw/arm/aspeed_ast2600.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ static void aspeed_soc_ast2600_init(Object *obj)
148148
snprintf(typename, sizeof(typename), "aspeed.timer-%s", socname);
149149
object_initialize_child(obj, "timerctrl", &s->timerctrl, typename);
150150

151+
snprintf(typename, sizeof(typename), "aspeed.adc-%s", socname);
152+
object_initialize_child(obj, "adc", &s->adc, typename);
153+
151154
snprintf(typename, sizeof(typename), "aspeed.i2c-%s", socname);
152155
object_initialize_child(obj, "i2c", &s->i2c, typename);
153156

@@ -322,6 +325,14 @@ static void aspeed_soc_ast2600_realize(DeviceState *dev, Error **errp)
322325
sysbus_connect_irq(SYS_BUS_DEVICE(&s->timerctrl), i, irq);
323326
}
324327

328+
/* ADC */
329+
if (!sysbus_realize(SYS_BUS_DEVICE(&s->adc), errp)) {
330+
return;
331+
}
332+
sysbus_mmio_map(SYS_BUS_DEVICE(&s->adc), 0, sc->memmap[ASPEED_DEV_ADC]);
333+
sysbus_connect_irq(SYS_BUS_DEVICE(&s->adc), 0,
334+
aspeed_soc_get_irq(s, ASPEED_DEV_ADC));
335+
325336
/* UART - attach an 8250 to the IO space as our UART */
326337
serial_mm_init(get_system_memory(), sc->memmap[s->uart_default], 2,
327338
aspeed_soc_get_irq(s, s->uart_default), 38400,
@@ -337,11 +348,8 @@ static void aspeed_soc_ast2600_realize(DeviceState *dev, Error **errp)
337348
for (i = 0; i < ASPEED_I2C_GET_CLASS(&s->i2c)->num_busses; i++) {
338349
qemu_irq irq = qdev_get_gpio_in(DEVICE(&s->a7mpcore),
339350
sc->irqmap[ASPEED_DEV_I2C] + i);
340-
/*
341-
* The AST2600 SoC has one IRQ per I2C bus. Skip the common
342-
* IRQ (AST2400 and AST2500) and connect all bussses.
343-
*/
344-
sysbus_connect_irq(SYS_BUS_DEVICE(&s->i2c), i + 1, irq);
351+
/* The AST2600 I2C controller has one IRQ per bus. */
352+
sysbus_connect_irq(SYS_BUS_DEVICE(&s->i2c.busses[i]), 0, irq);
345353
}
346354

347355
/* FMC, The number of CS is set at the board level */
@@ -352,7 +360,7 @@ static void aspeed_soc_ast2600_realize(DeviceState *dev, Error **errp)
352360
}
353361
sysbus_mmio_map(SYS_BUS_DEVICE(&s->fmc), 0, sc->memmap[ASPEED_DEV_FMC]);
354362
sysbus_mmio_map(SYS_BUS_DEVICE(&s->fmc), 1,
355-
s->fmc.ctrl->flash_window_base);
363+
ASPEED_SMC_GET_CLASS(&s->fmc)->flash_window_base);
356364
sysbus_connect_irq(SYS_BUS_DEVICE(&s->fmc), 0,
357365
aspeed_soc_get_irq(s, ASPEED_DEV_FMC));
358366

@@ -367,7 +375,7 @@ static void aspeed_soc_ast2600_realize(DeviceState *dev, Error **errp)
367375
sysbus_mmio_map(SYS_BUS_DEVICE(&s->spi[i]), 0,
368376
sc->memmap[ASPEED_DEV_SPI1 + i]);
369377
sysbus_mmio_map(SYS_BUS_DEVICE(&s->spi[i]), 1,
370-
s->spi[i].ctrl->flash_window_base);
378+
ASPEED_SMC_GET_CLASS(&s->spi[i])->flash_window_base);
371379
}
372380

373381
/* EHCI */

hw/arm/aspeed_soc.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ static void aspeed_soc_init(Object *obj)
162162
snprintf(typename, sizeof(typename), "aspeed.timer-%s", socname);
163163
object_initialize_child(obj, "timerctrl", &s->timerctrl, typename);
164164

165+
snprintf(typename, sizeof(typename), "aspeed.adc-%s", socname);
166+
object_initialize_child(obj, "adc", &s->adc, typename);
167+
165168
snprintf(typename, sizeof(typename), "aspeed.i2c-%s", socname);
166169
object_initialize_child(obj, "i2c", &s->i2c, typename);
167170

@@ -287,6 +290,14 @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp)
287290
sysbus_connect_irq(SYS_BUS_DEVICE(&s->timerctrl), i, irq);
288291
}
289292

293+
/* ADC */
294+
if (!sysbus_realize(SYS_BUS_DEVICE(&s->adc), errp)) {
295+
return;
296+
}
297+
sysbus_mmio_map(SYS_BUS_DEVICE(&s->adc), 0, sc->memmap[ASPEED_DEV_ADC]);
298+
sysbus_connect_irq(SYS_BUS_DEVICE(&s->adc), 0,
299+
aspeed_soc_get_irq(s, ASPEED_DEV_ADC));
300+
290301
/* UART - attach an 8250 to the IO space as our UART */
291302
serial_mm_init(get_system_memory(), sc->memmap[s->uart_default], 2,
292303
aspeed_soc_get_irq(s, s->uart_default), 38400,
@@ -310,7 +321,7 @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp)
310321
}
311322
sysbus_mmio_map(SYS_BUS_DEVICE(&s->fmc), 0, sc->memmap[ASPEED_DEV_FMC]);
312323
sysbus_mmio_map(SYS_BUS_DEVICE(&s->fmc), 1,
313-
s->fmc.ctrl->flash_window_base);
324+
ASPEED_SMC_GET_CLASS(&s->fmc)->flash_window_base);
314325
sysbus_connect_irq(SYS_BUS_DEVICE(&s->fmc), 0,
315326
aspeed_soc_get_irq(s, ASPEED_DEV_FMC));
316327

@@ -323,7 +334,7 @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp)
323334
sysbus_mmio_map(SYS_BUS_DEVICE(&s->spi[i]), 0,
324335
sc->memmap[ASPEED_DEV_SPI1 + i]);
325336
sysbus_mmio_map(SYS_BUS_DEVICE(&s->spi[i]), 1,
326-
s->spi[i].ctrl->flash_window_base);
337+
ASPEED_SMC_GET_CLASS(&s->spi[i])->flash_window_base);
327338
}
328339

329340
/* EHCI */

hw/gpio/aspeed_gpio.c

Lines changed: 37 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,7 @@
1616
#include "hw/irq.h"
1717
#include "migration/vmstate.h"
1818

19-
#define GPIOS_PER_REG 32
20-
#define GPIOS_PER_SET GPIOS_PER_REG
21-
#define GPIO_PIN_GAP_SIZE 4
2219
#define GPIOS_PER_GROUP 8
23-
#define GPIO_GROUP_SHIFT 3
2420

2521
/* GPIO Source Types */
2622
#define ASPEED_CMD_SRC_MASK 0x01010101
@@ -259,7 +255,7 @@ static void aspeed_gpio_update(AspeedGPIOState *s, GPIOSets *regs,
259255

260256
diff = old ^ new;
261257
if (diff) {
262-
for (gpio = 0; gpio < GPIOS_PER_REG; gpio++) {
258+
for (gpio = 0; gpio < ASPEED_GPIOS_PER_SET; gpio++) {
263259
uint32_t mask = 1 << gpio;
264260

265261
/* If the gpio needs to be updated... */
@@ -283,8 +279,7 @@ static void aspeed_gpio_update(AspeedGPIOState *s, GPIOSets *regs,
283279
if (direction & mask) {
284280
/* ...trigger the line-state IRQ */
285281
ptrdiff_t set = aspeed_gpio_set_idx(s, regs);
286-
size_t offset = set * GPIOS_PER_SET + gpio;
287-
qemu_set_irq(s->gpios[offset], !!(new & mask));
282+
qemu_set_irq(s->gpios[set][gpio], !!(new & mask));
288283
} else {
289284
/* ...otherwise if we meet the line's current IRQ policy... */
290285
if (aspeed_evaluate_irq(regs, old & mask, gpio)) {
@@ -297,21 +292,6 @@ static void aspeed_gpio_update(AspeedGPIOState *s, GPIOSets *regs,
297292
qemu_set_irq(s->irq, !!(s->pending));
298293
}
299294

300-
static uint32_t aspeed_adjust_pin(AspeedGPIOState *s, uint32_t pin)
301-
{
302-
AspeedGPIOClass *agc = ASPEED_GPIO_GET_CLASS(s);
303-
/*
304-
* The 2500 has a 4 pin gap in group AB and the 2400 has a 4 pin
305-
* gap in group Y (and only four pins in AB but this is the last group so
306-
* it doesn't matter).
307-
*/
308-
if (agc->gap && pin >= agc->gap) {
309-
pin += GPIO_PIN_GAP_SIZE;
310-
}
311-
312-
return pin;
313-
}
314-
315295
static bool aspeed_gpio_get_pin_level(AspeedGPIOState *s, uint32_t set_idx,
316296
uint32_t pin)
317297
{
@@ -367,7 +347,7 @@ static uint32_t update_value_control_source(GPIOSets *regs, uint32_t old_value,
367347
uint32_t new_value = 0;
368348

369349
/* for each group in set */
370-
for (i = 0; i < GPIOS_PER_REG; i += GPIOS_PER_GROUP) {
350+
for (i = 0; i < ASPEED_GPIOS_PER_SET; i += GPIOS_PER_GROUP) {
371351
cmd_source = extract32(regs->cmd_source_0, i, 1)
372352
| (extract32(regs->cmd_source_1, i, 1) << 1);
373353

@@ -637,7 +617,7 @@ static void aspeed_gpio_write(void *opaque, hwaddr offset, uint64_t data,
637617
* bidirectional | 1 | 1 | data
638618
* input only | 1 | 0 | 0
639619
* output only | 0 | 1 | 1
640-
* no pin / gap | 0 | 0 | 0
620+
* no pin | 0 | 0 | 0
641621
*
642622
* which is captured by:
643623
* data = ( data | ~input) & output;
@@ -779,7 +759,7 @@ static void aspeed_gpio_set_pin(Object *obj, Visitor *v, const char *name,
779759
}
780760

781761
/****************** Setup functions ******************/
782-
static const GPIOSetProperties ast2400_set_props[] = {
762+
static const GPIOSetProperties ast2400_set_props[ASPEED_GPIO_MAX_NR_SETS] = {
783763
[0] = {0xffffffff, 0xffffffff, {"A", "B", "C", "D"} },
784764
[1] = {0xffffffff, 0xffffffff, {"E", "F", "G", "H"} },
785765
[2] = {0xffffffff, 0xffffffff, {"I", "J", "K", "L"} },
@@ -789,28 +769,28 @@ static const GPIOSetProperties ast2400_set_props[] = {
789769
[6] = {0x0000000f, 0x0fffff0f, {"Y", "Z", "AA", "AB"} },
790770
};
791771

792-
static const GPIOSetProperties ast2500_set_props[] = {
772+
static const GPIOSetProperties ast2500_set_props[ASPEED_GPIO_MAX_NR_SETS] = {
793773
[0] = {0xffffffff, 0xffffffff, {"A", "B", "C", "D"} },
794774
[1] = {0xffffffff, 0xffffffff, {"E", "F", "G", "H"} },
795775
[2] = {0xffffffff, 0xffffffff, {"I", "J", "K", "L"} },
796776
[3] = {0xffffffff, 0xffffffff, {"M", "N", "O", "P"} },
797777
[4] = {0xffffffff, 0xffffffff, {"Q", "R", "S", "T"} },
798778
[5] = {0xffffffff, 0x0000ffff, {"U", "V", "W", "X"} },
799-
[6] = {0xffffff0f, 0x0fffff0f, {"Y", "Z", "AA", "AB"} },
779+
[6] = {0x0fffffff, 0x0fffffff, {"Y", "Z", "AA", "AB"} },
800780
[7] = {0x000000ff, 0x000000ff, {"AC"} },
801781
};
802782

803-
static GPIOSetProperties ast2600_3_3v_set_props[] = {
783+
static GPIOSetProperties ast2600_3_3v_set_props[ASPEED_GPIO_MAX_NR_SETS] = {
804784
[0] = {0xffffffff, 0xffffffff, {"A", "B", "C", "D"} },
805785
[1] = {0xffffffff, 0xffffffff, {"E", "F", "G", "H"} },
806786
[2] = {0xffffffff, 0xffffffff, {"I", "J", "K", "L"} },
807787
[3] = {0xffffffff, 0xffffffff, {"M", "N", "O", "P"} },
808-
[4] = {0xffffffff, 0xffffffff, {"Q", "R", "S", "T"} },
809-
[5] = {0xffffffff, 0x0000ffff, {"U", "V", "W", "X"} },
810-
[6] = {0xffff0000, 0x0fff0000, {"Y", "Z", "", ""} },
788+
[4] = {0xffffffff, 0x00ffffff, {"Q", "R", "S", "T"} },
789+
[5] = {0xffffffff, 0xffffff00, {"U", "V", "W", "X"} },
790+
[6] = {0x0000ffff, 0x0000ffff, {"Y", "Z"} },
811791
};
812792

813-
static GPIOSetProperties ast2600_1_8v_set_props[] = {
793+
static GPIOSetProperties ast2600_1_8v_set_props[ASPEED_GPIO_MAX_NR_SETS] = {
814794
[0] = {0xffffffff, 0xffffffff, {"18A", "18B", "18C", "18D"} },
815795
[1] = {0x0000000f, 0x0000000f, {"18E"} },
816796
};
@@ -836,14 +816,20 @@ static void aspeed_gpio_realize(DeviceState *dev, Error **errp)
836816
AspeedGPIOState *s = ASPEED_GPIO(dev);
837817
SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
838818
AspeedGPIOClass *agc = ASPEED_GPIO_GET_CLASS(s);
839-
int pin;
840819

841820
/* Interrupt parent line */
842821
sysbus_init_irq(sbd, &s->irq);
843822

844823
/* Individual GPIOs */
845-
for (pin = 0; pin < agc->nr_gpio_pins; pin++) {
846-
sysbus_init_irq(sbd, &s->gpios[pin]);
824+
for (int i = 0; i < ASPEED_GPIO_MAX_NR_SETS; i++) {
825+
const GPIOSetProperties *props = &agc->props[i];
826+
uint32_t skip = ~(props->input | props->output);
827+
for (int j = 0; j < ASPEED_GPIOS_PER_SET; j++) {
828+
if (skip >> j & 1) {
829+
continue;
830+
}
831+
sysbus_init_irq(sbd, &s->gpios[i][j]);
832+
}
847833
}
848834

849835
memory_region_init_io(&s->iomem, OBJECT(s), &aspeed_gpio_ops, s,
@@ -856,20 +842,22 @@ static void aspeed_gpio_init(Object *obj)
856842
{
857843
AspeedGPIOState *s = ASPEED_GPIO(obj);
858844
AspeedGPIOClass *agc = ASPEED_GPIO_GET_CLASS(s);
859-
int pin;
860-
861-
for (pin = 0; pin < agc->nr_gpio_pins; pin++) {
862-
char *name;
863-
int set_idx = pin / GPIOS_PER_SET;
864-
int pin_idx = aspeed_adjust_pin(s, pin) - (set_idx * GPIOS_PER_SET);
865-
int group_idx = pin_idx >> GPIO_GROUP_SHIFT;
866-
const GPIOSetProperties *props = &agc->props[set_idx];
867-
868-
name = g_strdup_printf("gpio%s%d", props->group_label[group_idx],
869-
pin_idx % GPIOS_PER_GROUP);
870-
object_property_add(obj, name, "bool", aspeed_gpio_get_pin,
871-
aspeed_gpio_set_pin, NULL, NULL);
872-
g_free(name);
845+
846+
for (int i = 0; i < ASPEED_GPIO_MAX_NR_SETS; i++) {
847+
const GPIOSetProperties *props = &agc->props[i];
848+
uint32_t skip = ~(props->input | props->output);
849+
for (int j = 0; j < ASPEED_GPIOS_PER_SET; j++) {
850+
if (skip >> j & 1) {
851+
continue;
852+
}
853+
int group_idx = j / GPIOS_PER_GROUP;
854+
int pin_idx = j % GPIOS_PER_GROUP;
855+
const char *group = &props->group_label[group_idx][0];
856+
char *name = g_strdup_printf("gpio%s%d", group, pin_idx);
857+
object_property_add(obj, name, "bool", aspeed_gpio_get_pin,
858+
aspeed_gpio_set_pin, NULL, NULL);
859+
g_free(name);
860+
}
873861
}
874862
}
875863

@@ -926,7 +914,6 @@ static void aspeed_gpio_ast2400_class_init(ObjectClass *klass, void *data)
926914
agc->props = ast2400_set_props;
927915
agc->nr_gpio_pins = 216;
928916
agc->nr_gpio_sets = 7;
929-
agc->gap = 196;
930917
agc->reg_table = aspeed_3_3v_gpios;
931918
}
932919

@@ -937,7 +924,6 @@ static void aspeed_gpio_2500_class_init(ObjectClass *klass, void *data)
937924
agc->props = ast2500_set_props;
938925
agc->nr_gpio_pins = 228;
939926
agc->nr_gpio_sets = 8;
940-
agc->gap = 220;
941927
agc->reg_table = aspeed_3_3v_gpios;
942928
}
943929

0 commit comments

Comments
 (0)