versatilepb: add i2c support
PATCH 1/1 versatilepb: add i2c support
--- hw/versatilepb.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 80 insertions(+), 0 deletions(-)
hw/versatilepb.c +80 -0
@@ -16,9 +16,18 @@#include "boards.h" #include "blockdev.h" #include "exec-memory.h" +#include "bitbang_i2c.h" /* Primary interrupt controller. */ +typedef struct { +SysBusDevice busdev; +MemoryRegion iomem; +bitbang_i2c_interface *bitbang; +int out; +int in; +}vpb_i2c_state ; + typedef struct vpb_sic_state { SysBusDevice busdev;
@@ -153,6 +162,64 @@ static int vpb_sic_init(SysBusDevice *dev)return 0 ; } +static uint64_t vpb_i2c_read (void *opaque,target_phys_addr_t offset, +unsigned size) +{ +vpb_i2c_state *s = (vpb_i2c_state *)opaque; + +if (offset ==0 ) { +return (s->out &1 ) | (s->in <<1 ); + }else { +hw_error ("%s: Bad offset 0x%x\n" , __func__, (int )offset); +return -1 ; + } +} + +static void vpb_i2c_write (void *opaque,target_phys_addr_t offset, +uint64_t value,unsigned size) +{ +vpb_i2c_state *s = (vpb_i2c_state *)opaque; + +switch (offset) { +case 0 : + s->out |= value &3 ; +break ; +case 4 : + s->out &= ~value; +break ; +default : +hw_error ("%s: Bad offset 0x%x\n" , __func__, (int )offset); + } +bitbang_i2c_set (s->bitbang,BITBANG_I2C_SCL , (s->out &1 ) !=0 ); + s->in =bitbang_i2c_set (s->bitbang,BITBANG_I2C_SDA , (s->out &2 ) !=0 ); +} + +static const MemoryRegionOps vpb_i2c_ops = { + .read = vpb_i2c_read, + .write = vpb_i2c_write, + .endianness =DEVICE_NATIVE_ENDIAN , +}; + +static int vpb_i2c_init (SysBusDevice *dev) +{ +vpb_i2c_state *s =FROM_SYSBUS (vpb_i2c_state, dev); +i2c_bus *bus; + + bus =i2c_init_bus (&dev->qdev,"i2c" ); + s->bitbang =bitbang_i2c_init (bus); +memory_region_init_io (&s->iomem, &vpb_i2c_ops, s, +"vpb-i2c" ,0x1000 ); +sysbus_init_mmio (dev, &s->iomem); +return 0 ; +} + +static void vpb_i2c_class_init (ObjectClass *klass,void *data) +{ +SysBusDeviceClass *k =SYS_BUS_DEVICE_CLASS (klass); + + k->init = vpb_i2c_init; +} +/* Board init. */ /* The AB and PB boards both use the same core, just with different
@@ -177,6 +244,7 @@ static void versatile_init(ram_addr_t ram_size,SysBusDevice *busdev;DeviceState *pl041;PCIBus *pci_bus; +i2c_bus *i2c;NICInfo *nd;int n;int done_smc =0 ;
@@ -268,6 +336,10 @@ static void versatile_init(ram_addr_t ram_size,/* Add PL031 Real Time Clock. */ sysbus_create_simple ("pl031" ,0x101e8000 , pic[10 ]); + dev =sysbus_create_simple ("vpb_i2c" ,0x10002000 ,NULL ); + i2c = (i2c_bus *)qdev_get_child_bus (dev,"i2c" ); +i2c_create_slave (i2c,"ds1338" ,0x68 ); +/* Add PL041 AACI Interface to the LM4549 codec */ pl041 =qdev_create (NULL ,"pl041" );qdev_prop_set_uint32 (pl041,"nc_fifo_depth" ,512 );
@@ -380,9 +452,17 @@ static TypeInfo vpb_sic_info = { .class_init = vpb_sic_class_init, }; +static TypeInfo vpb_i2c_info = { + .name ="vpb_i2c" , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (vpb_i2c_state), + .class_init = vpb_i2c_class_init, +}; +static void versatilepb_register_types (void ) {type_register_static (&vpb_sic_info); +type_register_static (&vpb_i2c_info); }type_init (versatilepb_register_types)
Signature · 1 line
1.7.3.4
Am 02.04.2012 22:17, schrieb Oskar Andero:
Quoted 14 lines
Signed-off-by Oskar Andero <[email protected]>--- hw/versatilepb.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 80 insertions(+), 0 deletions(-)hw/versatilepb.c +1
-0@@ -16,9 +16,18 @@#include "boards.h" #include "blockdev.h" #include "exec-memory.h" +#include "bitbang_i2c.h"
hw/versatilepb.c line 29
Quoted 10 lines
hw/versatilepb.c +7
-0/* Primary interrupt controller. */ +typedef struct { +SysBusDevice busdev; +MemoryRegion iomem; +bitbang_i2c_interface *bitbang; +int out; +int in; +}vpb_i2c_state ;
Please use Camel Case for new types, e.g., VPBI2CState.
Quoted 4 lines
hw/versatilepb.c +1
-0+ typedef struct vpb_sic_state { SysBusDevice busdev;
[...]
hw/versatilepb.c static TypeInfo vpb_sic_info = { · line 455
Quoted 5 lines
hw/versatilepb.c +1
-0@@ -380,9 +452,17 @@ static TypeInfo vpb_sic_info = { .class_init = vpb_sic_class_init, }; +static TypeInfo vpb_i2c_info = {
static const, please, since you don't modify it.
hw/versatilepb.c static TypeInfo vpb_sic_info = { · line 468
Quoted 13 lines
hw/versatilepb.c +7
-0+ .name = "vpb_i2c", + .parent = TYPE_SYS_BUS_DEVICE, + .instance_size = sizeof(vpb_i2c_state), + .class_init = vpb_i2c_class_init, +}; +static void versatilepb_register_types (void ) {type_register_static (&vpb_sic_info); +type_register_static (&vpb_i2c_info); }type_init (versatilepb_register_types)
Otherwise looks okay technically; don't know about I2C personally.
Andreas
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
Quoted 4 lines · Oskar Andero
Signed-off-by Oskar Andero <[email protected]>---
hw/versatilepb.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++1 files changed, 80 insertions(+), 0 deletions(-)
This is just a cut-n-paste of the i2c device in hw/realview.c. Instead of duplicating the code we should pull it out into its own source file, give it a name which doesn't have 'realview' in it (since it's the same thing in all these boards) and then use that new device in all the boards which have it.
-- PMM