Skip to contentSkip to conversation

I2C/SMBus framework

Qemu-devel Paul Brook 2 participants 2 messages May 12, 2007 – May 13, 2007 Kbuild

lore
Share & tools
lore

Paul Brook

author
#0 lore raw

The attached patch implements an I2C/SMBus framework for qemu.

It provides an API for connecting emulated I2C devices, and implements SMBus as a layer on top of that.

Currently the only i2c device in CVS is the piix eeprom. I've tested this as much as I can - linux successfully reads the eeprom contents. I've also used the same framework for several different boards.

I will apply in a day or so if there are no serious objections.

Paul

Index: Makefile.target
===================================================================
RCS file: /sources/qemu/qemu/Makefile.target,v
retrieving revision 1.169

Makefile.target +2 -0
diff -u -p -r1.169 Makefile.target
@@ -401,6 +401,8 @@ SOUND_HW += fmopl.o adlib.o
 endif
 AUDIODRV+= wavcapture.o
 
+VL_OBJS += i2c.o smbus.o
+
 # SCSI layer
 VL_OBJS+= scsi-disk.o cdrom.o lsi53c895a.o
 

Index: vl.h
===================================================================
RCS file: /sources/qemu/qemu/vl.h,v
retrieving revision 1.234

vl.h +3 -4
diff -u -p -r1.234 vl.h
@@ -1125,17 +1125,16 @@ int pit_get_out(PITState *pit, int chann
 void pcspk_init(PITState *);
 int pcspk_audio_init(AudioState *, qemu_irq *pic);
 
+#include "hw/i2c.h"
+
 #include "hw/smbus.h"
 
 /* acpi.c */
 extern int acpi_enabled;
-void piix4_pm_init(PCIBus *bus, int devfn);
+i2c_bus *piix4_pm_init(PCIBus *bus, int devfn);
 void piix4_smbus_register_device(SMBusDevice *dev, uint8_t addr);
 void acpi_bios_init(void);
 
-/* smbus_eeprom.c */
-SMBusDevice *smbus_eeprom_device_init(uint8_t addr, uint8_t *buf);
-
 /* pc.c */
 extern QEMUMachine pc_machine;
 extern QEMUMachine isapc_machine;

Index: hw/acpi.c
===================================================================
RCS file: /sources/qemu/qemu/hw/acpi.c,v
retrieving revision 1.10

acpi.c +18 -39

110 lines not on this page · raw message

Index: hw/i2c.c
===================================================================
RCS file: hw/i2c.c

i2c.c new file +117 -0

117 lines not on this page · raw message

Index: hw/i2c.h
===================================================================
RCS file: hw/i2c.h

i2c.h new file +49 -0

49 lines not on this page · raw message

Index: hw/pc.c
===================================================================
RCS file: /sources/qemu/qemu/hw/pc.c,v
retrieving revision 1.74

pc.c +5 -4
diff -u -p -r1.74 pc.c
@@ -758,11 +758,12 @@ static void pc_init1(int ram_size, int v
 
     if (pci_enabled && acpi_enabled) {
         uint8_t *eeprom_buf = qemu_mallocz(8 * 256); /* XXX: make this persistent */
-        piix4_pm_init(pci_bus, piix3_devfn + 3);
+        i2c_bus *smbus;
+
+        /* TODO: Populate SPD eeprom data.  */
+        smbus = piix4_pm_init(pci_bus, piix3_devfn + 3);
         for (i = 0; i < 8; i++) {
-            SMBusDevice *eeprom = smbus_eeprom_device_init(0x50 + i,
-                eeprom_buf + (i * 256));
-            piix4_smbus_register_device(eeprom, 0x50 + i);
+            smbus_eeprom_device_init(smbus, 0x50 + i, eeprom_buf + (i * 256));
         }
     }
     

Index: hw/smbus.c
===================================================================
RCS file: hw/smbus.c

smbus.c new file +303 -0

303 lines not on this page · raw message

Index: hw/smbus.h
===================================================================
RCS file: /sources/qemu/qemu/hw/smbus.h,v
retrieving revision 1.1

smbus.h +39 -7

53 lines not on this page · raw message

Index: hw/smbus_eeprom.c
===================================================================
RCS file: /sources/qemu/qemu/hw/smbus_eeprom.c,v
retrieving revision 1.1

smbus_eeprom.c +30 -16

67 lines not on this page · raw message

#1 lore raw
Quoted 10 lines · Paul Brook

The attached patch implements an I2C/SMBus framework for qemu.

It provides an API for connecting emulated I2C devices, and implements SMBus as a layer on top of that.

Currently the only i2c device in CVS is the piix eeprom. I've tested this as much as I can - linux successfully reads the eeprom contents. I've also used the same framework for several different boards.

I will apply in a day or so if there are no serious objections.

Minor niggle, a new compiler warning:

/home/ths/qemu/qemu-work/hw/acpi.c: In function smb_ioport_writeb':
/home/ths/qemu/qemu-work/hw/acpi.c:283: warning: 'val' might be used uninitialized in this function

aside from that it works well for me.

Thiemo