Revision eee48504
b/hw/realview.c | ||
---|---|---|
15 | 15 |
#include "net.h" |
16 | 16 |
#include "sysemu.h" |
17 | 17 |
#include "boards.h" |
18 |
#include "bitbang_i2c.h" |
|
19 |
#include "sysbus.h" |
|
18 | 20 |
|
19 | 21 |
#define SMP_BOOT_ADDR 0xe0000000 |
22 |
|
|
23 |
typedef struct { |
|
24 |
SysBusDevice busdev; |
|
25 |
bitbang_i2c_interface *bitbang; |
|
26 |
int out; |
|
27 |
int in; |
|
28 |
} RealViewI2CState; |
|
29 |
|
|
30 |
static uint32_t realview_i2c_read(void *opaque, target_phys_addr_t offset) |
|
31 |
{ |
|
32 |
RealViewI2CState *s = (RealViewI2CState *)opaque; |
|
33 |
|
|
34 |
if (offset == 0) { |
|
35 |
return (s->out & 1) | (s->in << 1); |
|
36 |
} else { |
|
37 |
hw_error("realview_i2c_read: Bad offset 0x%x\n", (int)offset); |
|
38 |
return -1; |
|
39 |
} |
|
40 |
} |
|
41 |
|
|
42 |
static void realview_i2c_write(void *opaque, target_phys_addr_t offset, |
|
43 |
uint32_t value) |
|
44 |
{ |
|
45 |
RealViewI2CState *s = (RealViewI2CState *)opaque; |
|
46 |
|
|
47 |
switch (offset) { |
|
48 |
case 0: |
|
49 |
s->out |= value & 3; |
|
50 |
break; |
|
51 |
case 4: |
|
52 |
s->out &= ~value; |
|
53 |
break; |
|
54 |
default: |
|
55 |
hw_error("realview_i2c_write: Bad offset 0x%x\n", (int)offset); |
|
56 |
} |
|
57 |
bitbang_i2c_set(s->bitbang, BITBANG_I2C_SCL, (s->out & 1) != 0); |
|
58 |
s->in = bitbang_i2c_set(s->bitbang, BITBANG_I2C_SDA, (s->out & 2) != 0); |
|
59 |
} |
|
60 |
|
|
61 |
static CPUReadMemoryFunc * const realview_i2c_readfn[] = { |
|
62 |
realview_i2c_read, |
|
63 |
realview_i2c_read, |
|
64 |
realview_i2c_read |
|
65 |
}; |
|
66 |
|
|
67 |
static CPUWriteMemoryFunc * const realview_i2c_writefn[] = { |
|
68 |
realview_i2c_write, |
|
69 |
realview_i2c_write, |
|
70 |
realview_i2c_write |
|
71 |
}; |
|
72 |
|
|
73 |
static int realview_i2c_init(SysBusDevice *dev) |
|
74 |
{ |
|
75 |
RealViewI2CState *s = FROM_SYSBUS(RealViewI2CState, dev); |
|
76 |
i2c_bus *bus; |
|
77 |
int iomemtype; |
|
78 |
|
|
79 |
bus = i2c_init_bus(&dev->qdev, "i2c"); |
|
80 |
s->bitbang = bitbang_i2c_init(bus); |
|
81 |
iomemtype = cpu_register_io_memory(realview_i2c_readfn, |
|
82 |
realview_i2c_writefn, s); |
|
83 |
sysbus_init_mmio(dev, 0x1000, iomemtype); |
|
84 |
return 0; |
|
85 |
} |
|
86 |
|
|
87 |
static SysBusDeviceInfo realview_i2c_info = { |
|
88 |
.init = realview_i2c_init, |
|
89 |
.qdev.name = "realview_i2c", |
|
90 |
.qdev.size = sizeof(RealViewI2CState), |
|
91 |
}; |
|
92 |
|
|
93 |
static void realview_register_devices(void) |
|
94 |
{ |
|
95 |
sysbus_register_withprop(&realview_i2c_info); |
|
96 |
} |
|
97 |
|
|
20 | 98 |
/* Board init. */ |
21 | 99 |
|
22 | 100 |
static struct arm_boot_info realview_binfo = { |
... | ... | |
63 | 141 |
qemu_irq pic[64]; |
64 | 142 |
PCIBus *pci_bus; |
65 | 143 |
NICInfo *nd; |
144 |
i2c_bus *i2c; |
|
66 | 145 |
int n; |
67 | 146 |
int done_nic = 0; |
68 | 147 |
qemu_irq cpu_irq[4]; |
... | ... | |
202 | 281 |
} |
203 | 282 |
} |
204 | 283 |
|
284 |
dev = sysbus_create_simple("realview_i2c", 0x10002000, NULL); |
|
285 |
i2c = (i2c_bus *)qdev_get_child_bus(dev, "i2c"); |
|
286 |
i2c_create_slave(i2c, "ds1338", 0x68); |
|
287 |
|
|
205 | 288 |
/* Memory map for RealView Emulation Baseboard: */ |
206 | 289 |
/* 0x10000000 System registers. */ |
207 | 290 |
/* 0x10001000 System controller. */ |
208 |
/* 0x10002000 Two-Wire Serial Bus. */
|
|
291 |
/* 0x10002000 Two-Wire Serial Bus. */ |
|
209 | 292 |
/* 0x10003000 Reserved. */ |
210 | 293 |
/* 0x10004000 AACI. */ |
211 | 294 |
/* 0x10005000 MCI. */ |
... | ... | |
362 | 445 |
} |
363 | 446 |
|
364 | 447 |
machine_init(realview_machine_init); |
448 |
device_init(realview_register_devices) |
Also available in: Unified diff