@samitouri / QOSamiQemu / commits / 50cbe23432

hw/riscv/atlantis: Add some i2c peripherals

Add an I2C RTC device and a temperature sensor. These are not present on the board but help for testing. The tmp105 is a lm75 compatible temperature sensor used by the SENSORS_LM75 Linux kernel driver. The ds1338 is a RTC device that is used by the RTC_DRV_DS1307 Linux kernel driver. Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Acked-by: Alistair Francis <alistair.francis@wdc.com> Signed-off-by: Nicholas Piggin <npiggin@gmail.com> Signed-off-by: Joel Stanley <joel@jms.id.au> Message-ID: <20260630024952.1520546-13-joel@jms.id.au> Signed-off-by: Alistair Francis <alistair.francis@wdc.com>

Joel Stanley committed Jun 30, 2026 at 12:19 UTC 50cbe2343214dfcb85000cdd157c8ecbda6a8020
2 files changed +29
hw/riscv/Kconfig
+2
@@ -130,6 +130,8 @@ config TENSTORRENT
130 select SERIAL_MM
131 select DEVICE_TREE
132 select DESIGNWARE_I2C
133 + select DS1338
134 + select TMP105
135
136 config XIANGSHAN_KUNMINGHU
137 bool
hw/riscv/tt_atlantis.c
+27
@@ -64,6 +64,13 @@ static const MemMapEntry tt_atlantis_memmap[] = {
64 [TT_ATL_DDR_HI] = { 0x100000000, 0x1000000000 },
65 };
66
67 +static I2CBus *i2c_get_bus(TTAtlantisState *s, unsigned busnr)
68 +{
69 + assert(busnr < TT_ATL_NUM_I2C);
70 +
71 + return s->i2c[busnr].bus;
72 +}
73 +
74 static uint32_t fdt_phandle = 1;
75 static uint32_t next_phandle(void)
76 {
@@ -309,6 +316,19 @@ static void create_fdt_i2c(void *fdt, const MemMapEntry *mem, uint32_t irq,
316 qemu_fdt_setprop_cell(fdt, name, "#size-cells", 0);
317 }
318
319 +static void create_fdt_i2c_device(TTAtlantisState *s, int bus,
320 + const char *compat, int addr)
321 +{
322 + void *fdt = MACHINE(s)->fdt;
323 + hwaddr base = s->memmap[TT_ATL_I2C0 + bus].base;
324 + g_autofree char *name = g_strdup_printf("/soc/i2c@%"HWADDR_PRIX"/sensor@%x",
325 + base, addr);
326 +
327 + qemu_fdt_add_subnode(fdt, name);
328 + qemu_fdt_setprop_string(fdt, name, "compatible", compat);
329 + qemu_fdt_setprop_cell(fdt, name, "reg", addr);
330 +}
331 +
332 static void finalize_fdt(TTAtlantisState *s)
333 {
334 uint32_t aplic_s_phandle = next_phandle();
@@ -336,6 +356,9 @@ static void finalize_fdt(TTAtlantisState *s)
356 TT_ATL_I2C0_IRQ + i,
357 aplic_s_phandle, periph_clk_phandle);
358 }
359 +
360 + create_fdt_i2c_device(s, 0, "dallas,ds1338", 0x6f);
361 + create_fdt_i2c_device(s, 4, "ti,tmp105", 0x48);
362 }
363
364 static void create_fdt(TTAtlantisState *s)
@@ -551,6 +574,10 @@ static void tt_atlantis_machine_init(MachineState *machine)
574 qdev_get_gpio_in(s->irqchip, TT_ATL_I2C0_IRQ + i));
575 }
576
577 + /* I2C peripherals: qemu specific */
578 + i2c_slave_create_simple(i2c_get_bus(s, 0), "ds1338", 0x6f);
579 + i2c_slave_create_simple(i2c_get_bus(s, 4), "tmp105", 0x48);
580 +
581 /* Load or create device tree */
582 if (machine->dtb) {
583 load_fdt(s);