root / hw / tosa.c @ f76e1d81
History | View | Annotate | Download (8 kB)
1 | 89cdb6af | balrog | /* vim:set shiftwidth=4 ts=4 et: */
|
---|---|---|---|
2 | 89cdb6af | balrog | /*
|
3 | 89cdb6af | balrog | * PXA255 Sharp Zaurus SL-6000 PDA platform
|
4 | 89cdb6af | balrog | *
|
5 | 89cdb6af | balrog | * Copyright (c) 2008 Dmitry Baryshkov
|
6 | 89cdb6af | balrog | *
|
7 | 89cdb6af | balrog | * Code based on spitz platform by Andrzej Zaborowski <balrog@zabor.org>
|
8 | 89cdb6af | balrog | * This code is licensed under the GNU GPL v2.
|
9 | 6b620ca3 | Paolo Bonzini | *
|
10 | 6b620ca3 | Paolo Bonzini | * Contributions after 2012-01-13 are licensed under the terms of the
|
11 | 6b620ca3 | Paolo Bonzini | * GNU GPL, version 2 or (at your option) any later version.
|
12 | 89cdb6af | balrog | */
|
13 | 89cdb6af | balrog | |
14 | 89cdb6af | balrog | #include "hw.h" |
15 | 89cdb6af | balrog | #include "pxa.h" |
16 | 89cdb6af | balrog | #include "arm-misc.h" |
17 | 88d2c950 | balrog | #include "devices.h" |
18 | 89cdb6af | balrog | #include "sharpsl.h" |
19 | 89cdb6af | balrog | #include "pcmcia.h" |
20 | 89cdb6af | balrog | #include "block.h" |
21 | 89cdb6af | balrog | #include "boards.h" |
22 | 4ea29f74 | balrog | #include "i2c.h" |
23 | a984a69e | Paul Brook | #include "ssi.h" |
24 | 2446333c | Blue Swirl | #include "blockdev.h" |
25 | 383d01c6 | Dmitry Eremin-Solenikov | #include "sysbus.h" |
26 | a6dc4c2d | Richard Henderson | #include "exec-memory.h" |
27 | 89cdb6af | balrog | |
28 | 89cdb6af | balrog | #define TOSA_RAM 0x04000000 |
29 | 89cdb6af | balrog | #define TOSA_ROM 0x00800000 |
30 | 89cdb6af | balrog | |
31 | 2e4b4e79 | Dmitry Eremin-Solenikov | #define TOSA_GPIO_USB_IN (5) |
32 | 89cdb6af | balrog | #define TOSA_GPIO_nSD_DETECT (9) |
33 | 89cdb6af | balrog | #define TOSA_GPIO_ON_RESET (19) |
34 | 89cdb6af | balrog | #define TOSA_GPIO_CF_IRQ (21) /* CF slot0 Ready */ |
35 | 89cdb6af | balrog | #define TOSA_GPIO_CF_CD (13) |
36 | 5d98751b | balrog | #define TOSA_GPIO_TC6393XB_INT (15) |
37 | 89cdb6af | balrog | #define TOSA_GPIO_JC_CF_IRQ (36) /* CF slot1 Ready */ |
38 | 89cdb6af | balrog | |
39 | 6bc1d858 | balrog | #define TOSA_SCOOP_GPIO_BASE 1 |
40 | 89cdb6af | balrog | #define TOSA_GPIO_IR_POWERDWN (TOSA_SCOOP_GPIO_BASE + 2) |
41 | 89cdb6af | balrog | #define TOSA_GPIO_SD_WP (TOSA_SCOOP_GPIO_BASE + 3) |
42 | 89cdb6af | balrog | #define TOSA_GPIO_PWR_ON (TOSA_SCOOP_GPIO_BASE + 4) |
43 | 89cdb6af | balrog | |
44 | 6bc1d858 | balrog | #define TOSA_SCOOP_JC_GPIO_BASE 1 |
45 | 6bc1d858 | balrog | #define TOSA_GPIO_BT_LED (TOSA_SCOOP_JC_GPIO_BASE + 0) |
46 | 6bc1d858 | balrog | #define TOSA_GPIO_NOTE_LED (TOSA_SCOOP_JC_GPIO_BASE + 1) |
47 | 6bc1d858 | balrog | #define TOSA_GPIO_CHRG_ERR_LED (TOSA_SCOOP_JC_GPIO_BASE + 2) |
48 | 64b40bc5 | balrog | #define TOSA_GPIO_TC6393XB_L3V_ON (TOSA_SCOOP_JC_GPIO_BASE + 5) |
49 | 6bc1d858 | balrog | #define TOSA_GPIO_WLAN_LED (TOSA_SCOOP_JC_GPIO_BASE + 7) |
50 | 6bc1d858 | balrog | |
51 | 4ea29f74 | balrog | #define DAC_BASE 0x4e |
52 | 4ea29f74 | balrog | #define DAC_CH1 0 |
53 | 4ea29f74 | balrog | #define DAC_CH2 1 |
54 | 4ea29f74 | balrog | |
55 | bc24a225 | Paul Brook | static void tosa_microdrive_attach(PXA2xxState *cpu) |
56 | 89cdb6af | balrog | { |
57 | bc24a225 | Paul Brook | PCMCIACardState *md; |
58 | 751c6a17 | Gerd Hoffmann | DriveInfo *dinfo; |
59 | 89cdb6af | balrog | |
60 | 751c6a17 | Gerd Hoffmann | dinfo = drive_get(IF_IDE, 0, 0); |
61 | 124386cc | Markus Armbruster | if (!dinfo || dinfo->media_cd)
|
62 | 89cdb6af | balrog | return;
|
63 | 124386cc | Markus Armbruster | md = dscm1xxxx_init(dinfo); |
64 | 124386cc | Markus Armbruster | pxa2xx_pcmcia_attach(cpu->pcmcia[0], md);
|
65 | 89cdb6af | balrog | } |
66 | 89cdb6af | balrog | |
67 | 6bc1d858 | balrog | static void tosa_out_switch(void *opaque, int line, int level) |
68 | 6bc1d858 | balrog | { |
69 | 6bc1d858 | balrog | switch (line) {
|
70 | 6bc1d858 | balrog | case 0: |
71 | 6bc1d858 | balrog | fprintf(stderr, "blue LED %s.\n", level ? "on" : "off"); |
72 | 6bc1d858 | balrog | break;
|
73 | 6bc1d858 | balrog | case 1: |
74 | 6bc1d858 | balrog | fprintf(stderr, "green LED %s.\n", level ? "on" : "off"); |
75 | 6bc1d858 | balrog | break;
|
76 | 6bc1d858 | balrog | case 2: |
77 | 6bc1d858 | balrog | fprintf(stderr, "amber LED %s.\n", level ? "on" : "off"); |
78 | 6bc1d858 | balrog | break;
|
79 | 6bc1d858 | balrog | case 3: |
80 | 6bc1d858 | balrog | fprintf(stderr, "wlan LED %s.\n", level ? "on" : "off"); |
81 | 6bc1d858 | balrog | break;
|
82 | 6bc1d858 | balrog | default:
|
83 | 6bc1d858 | balrog | fprintf(stderr, "Uhandled out event: %d = %d\n", line, level);
|
84 | 6bc1d858 | balrog | break;
|
85 | 6bc1d858 | balrog | } |
86 | 6bc1d858 | balrog | } |
87 | 6bc1d858 | balrog | |
88 | 6bc1d858 | balrog | |
89 | bc24a225 | Paul Brook | static void tosa_gpio_setup(PXA2xxState *cpu, |
90 | 383d01c6 | Dmitry Eremin-Solenikov | DeviceState *scp0, |
91 | 383d01c6 | Dmitry Eremin-Solenikov | DeviceState *scp1, |
92 | bc24a225 | Paul Brook | TC6393xbState *tmio) |
93 | 89cdb6af | balrog | { |
94 | 6bc1d858 | balrog | qemu_irq *outsignals = qemu_allocate_irqs(tosa_out_switch, cpu, 4);
|
95 | 89cdb6af | balrog | /* MMC/SD host */
|
96 | 89cdb6af | balrog | pxa2xx_mmci_handlers(cpu->mmc, |
97 | 383d01c6 | Dmitry Eremin-Solenikov | qdev_get_gpio_in(scp0, TOSA_GPIO_SD_WP), |
98 | 0bb53337 | Dmitry Eremin-Solenikov | qemu_irq_invert(qdev_get_gpio_in(cpu->gpio, TOSA_GPIO_nSD_DETECT))); |
99 | 89cdb6af | balrog | |
100 | 89cdb6af | balrog | /* Handle reset */
|
101 | 0bb53337 | Dmitry Eremin-Solenikov | qdev_connect_gpio_out(cpu->gpio, TOSA_GPIO_ON_RESET, cpu->reset); |
102 | 89cdb6af | balrog | |
103 | 89cdb6af | balrog | /* PCMCIA signals: card's IRQ and Card-Detect */
|
104 | 89cdb6af | balrog | pxa2xx_pcmcia_set_irq_cb(cpu->pcmcia[0],
|
105 | 0bb53337 | Dmitry Eremin-Solenikov | qdev_get_gpio_in(cpu->gpio, TOSA_GPIO_CF_IRQ), |
106 | 0bb53337 | Dmitry Eremin-Solenikov | qdev_get_gpio_in(cpu->gpio, TOSA_GPIO_CF_CD)); |
107 | 89cdb6af | balrog | |
108 | 89cdb6af | balrog | pxa2xx_pcmcia_set_irq_cb(cpu->pcmcia[1],
|
109 | 0bb53337 | Dmitry Eremin-Solenikov | qdev_get_gpio_in(cpu->gpio, TOSA_GPIO_JC_CF_IRQ), |
110 | 89cdb6af | balrog | NULL);
|
111 | 89cdb6af | balrog | |
112 | 383d01c6 | Dmitry Eremin-Solenikov | qdev_connect_gpio_out(scp1, TOSA_GPIO_BT_LED, outsignals[0]);
|
113 | 383d01c6 | Dmitry Eremin-Solenikov | qdev_connect_gpio_out(scp1, TOSA_GPIO_NOTE_LED, outsignals[1]);
|
114 | 383d01c6 | Dmitry Eremin-Solenikov | qdev_connect_gpio_out(scp1, TOSA_GPIO_CHRG_ERR_LED, outsignals[2]);
|
115 | 383d01c6 | Dmitry Eremin-Solenikov | qdev_connect_gpio_out(scp1, TOSA_GPIO_WLAN_LED, outsignals[3]);
|
116 | 64b40bc5 | balrog | |
117 | 383d01c6 | Dmitry Eremin-Solenikov | qdev_connect_gpio_out(scp1, TOSA_GPIO_TC6393XB_L3V_ON, tc6393xb_l3v_get(tmio)); |
118 | 2e4b4e79 | Dmitry Eremin-Solenikov | |
119 | 2e4b4e79 | Dmitry Eremin-Solenikov | /* UDC Vbus */
|
120 | 2e4b4e79 | Dmitry Eremin-Solenikov | qemu_irq_raise(qdev_get_gpio_in(cpu->gpio, TOSA_GPIO_USB_IN)); |
121 | 89cdb6af | balrog | } |
122 | 89cdb6af | balrog | |
123 | a984a69e | Paul Brook | static uint32_t tosa_ssp_tansfer(SSISlave *dev, uint32_t value)
|
124 | 4ea29f74 | balrog | { |
125 | a984a69e | Paul Brook | fprintf(stderr, "TG: %d %02x\n", value >> 5, value & 0x1f); |
126 | 4ea29f74 | balrog | return 0; |
127 | 4ea29f74 | balrog | } |
128 | 4ea29f74 | balrog | |
129 | 81a322d4 | Gerd Hoffmann | static int tosa_ssp_init(SSISlave *dev) |
130 | 4ea29f74 | balrog | { |
131 | a984a69e | Paul Brook | /* Nothing to do. */
|
132 | 81a322d4 | Gerd Hoffmann | return 0; |
133 | 4ea29f74 | balrog | } |
134 | 4ea29f74 | balrog | |
135 | d3151521 | Paul Brook | typedef struct { |
136 | 9e07bdf8 | Anthony Liguori | I2CSlave i2c; |
137 | 4ea29f74 | balrog | int len;
|
138 | 4ea29f74 | balrog | char buf[3]; |
139 | d3151521 | Paul Brook | } TosaDACState; |
140 | 4ea29f74 | balrog | |
141 | 9e07bdf8 | Anthony Liguori | static int tosa_dac_send(I2CSlave *i2c, uint8_t data) |
142 | 4ea29f74 | balrog | { |
143 | fd1eb2ea | Paul Brook | TosaDACState *s = FROM_I2C_SLAVE(TosaDACState, i2c); |
144 | 4ea29f74 | balrog | s->buf[s->len] = data; |
145 | 4ea29f74 | balrog | if (s->len ++ > 2) { |
146 | 4ea29f74 | balrog | #ifdef VERBOSE
|
147 | 4ea29f74 | balrog | fprintf(stderr, "%s: message too long (%i bytes)\n", __FUNCTION__, s->len);
|
148 | 4ea29f74 | balrog | #endif
|
149 | 4ea29f74 | balrog | return 1; |
150 | 4ea29f74 | balrog | } |
151 | 4ea29f74 | balrog | |
152 | 4ea29f74 | balrog | if (s->len == 2) { |
153 | 4ea29f74 | balrog | fprintf(stderr, "dac: channel %d value 0x%02x\n",
|
154 | 4ea29f74 | balrog | s->buf[0], s->buf[1]); |
155 | 4ea29f74 | balrog | } |
156 | 4ea29f74 | balrog | |
157 | 4ea29f74 | balrog | return 0; |
158 | 4ea29f74 | balrog | } |
159 | 4ea29f74 | balrog | |
160 | 9e07bdf8 | Anthony Liguori | static void tosa_dac_event(I2CSlave *i2c, enum i2c_event event) |
161 | 4ea29f74 | balrog | { |
162 | fd1eb2ea | Paul Brook | TosaDACState *s = FROM_I2C_SLAVE(TosaDACState, i2c); |
163 | 4ea29f74 | balrog | s->len = 0;
|
164 | 4ea29f74 | balrog | switch (event) {
|
165 | 4ea29f74 | balrog | case I2C_START_SEND:
|
166 | 4ea29f74 | balrog | break;
|
167 | 4ea29f74 | balrog | case I2C_START_RECV:
|
168 | 4ea29f74 | balrog | printf("%s: recv not supported!!!\n", __FUNCTION__);
|
169 | 4ea29f74 | balrog | break;
|
170 | 4ea29f74 | balrog | case I2C_FINISH:
|
171 | 4ea29f74 | balrog | #ifdef VERBOSE
|
172 | 4ea29f74 | balrog | if (s->len < 2) |
173 | 4ea29f74 | balrog | printf("%s: message too short (%i bytes)\n", __FUNCTION__, s->len);
|
174 | 4ea29f74 | balrog | if (s->len > 2) |
175 | 4ea29f74 | balrog | printf("%s: message too long\n", __FUNCTION__);
|
176 | 4ea29f74 | balrog | #endif
|
177 | 4ea29f74 | balrog | break;
|
178 | 4ea29f74 | balrog | default:
|
179 | 4ea29f74 | balrog | break;
|
180 | 4ea29f74 | balrog | } |
181 | 4ea29f74 | balrog | } |
182 | 4ea29f74 | balrog | |
183 | 9e07bdf8 | Anthony Liguori | static int tosa_dac_recv(I2CSlave *s) |
184 | 4ea29f74 | balrog | { |
185 | 4ea29f74 | balrog | printf("%s: recv not supported!!!\n", __FUNCTION__);
|
186 | 4ea29f74 | balrog | return -1; |
187 | 4ea29f74 | balrog | } |
188 | 4ea29f74 | balrog | |
189 | 9e07bdf8 | Anthony Liguori | static int tosa_dac_init(I2CSlave *i2c) |
190 | fd1eb2ea | Paul Brook | { |
191 | fd1eb2ea | Paul Brook | /* Nothing to do. */
|
192 | 81a322d4 | Gerd Hoffmann | return 0; |
193 | fd1eb2ea | Paul Brook | } |
194 | fd1eb2ea | Paul Brook | |
195 | bc24a225 | Paul Brook | static void tosa_tg_init(PXA2xxState *cpu) |
196 | 4ea29f74 | balrog | { |
197 | d3151521 | Paul Brook | i2c_bus *bus = pxa2xx_i2c_bus(cpu->i2c[0]);
|
198 | fd1eb2ea | Paul Brook | i2c_create_slave(bus, "tosa_dac", DAC_BASE);
|
199 | a984a69e | Paul Brook | ssi_create_slave(cpu->ssp[1], "tosa-ssp"); |
200 | 4ea29f74 | balrog | } |
201 | 4ea29f74 | balrog | |
202 | 4ea29f74 | balrog | |
203 | 89cdb6af | balrog | static struct arm_boot_info tosa_binfo = { |
204 | 89cdb6af | balrog | .loader_start = PXA2XX_SDRAM_BASE, |
205 | 89cdb6af | balrog | .ram_size = 0x04000000,
|
206 | 89cdb6af | balrog | }; |
207 | 89cdb6af | balrog | |
208 | c227f099 | Anthony Liguori | static void tosa_init(ram_addr_t ram_size, |
209 | 3023f332 | aliguori | const char *boot_device, |
210 | 89cdb6af | balrog | const char *kernel_filename, const char *kernel_cmdline, |
211 | 89cdb6af | balrog | const char *initrd_filename, const char *cpu_model) |
212 | 89cdb6af | balrog | { |
213 | a6dc4c2d | Richard Henderson | MemoryRegion *address_space_mem = get_system_memory(); |
214 | 04d66689 | Avi Kivity | MemoryRegion *rom = g_new(MemoryRegion, 1);
|
215 | bc24a225 | Paul Brook | PXA2xxState *cpu; |
216 | bc24a225 | Paul Brook | TC6393xbState *tmio; |
217 | 383d01c6 | Dmitry Eremin-Solenikov | DeviceState *scp0, *scp1; |
218 | 89cdb6af | balrog | |
219 | 89cdb6af | balrog | if (!cpu_model)
|
220 | 89cdb6af | balrog | cpu_model = "pxa255";
|
221 | 89cdb6af | balrog | |
222 | a6dc4c2d | Richard Henderson | cpu = pxa255_init(address_space_mem, tosa_binfo.ram_size); |
223 | 89cdb6af | balrog | |
224 | c5705a77 | Avi Kivity | memory_region_init_ram(rom, "tosa.rom", TOSA_ROM);
|
225 | c5705a77 | Avi Kivity | vmstate_register_ram_global(rom); |
226 | 04d66689 | Avi Kivity | memory_region_set_readonly(rom, true);
|
227 | 04d66689 | Avi Kivity | memory_region_add_subregion(address_space_mem, 0, rom);
|
228 | 89cdb6af | balrog | |
229 | fe06bd93 | Avi Kivity | tmio = tc6393xb_init(address_space_mem, 0x10000000,
|
230 | 0bb53337 | Dmitry Eremin-Solenikov | qdev_get_gpio_in(cpu->gpio, TOSA_GPIO_TC6393XB_INT)); |
231 | 89cdb6af | balrog | |
232 | 383d01c6 | Dmitry Eremin-Solenikov | scp0 = sysbus_create_simple("scoop", 0x08800000, NULL); |
233 | 383d01c6 | Dmitry Eremin-Solenikov | scp1 = sysbus_create_simple("scoop", 0x14800040, NULL); |
234 | 89cdb6af | balrog | |
235 | 64b40bc5 | balrog | tosa_gpio_setup(cpu, scp0, scp1, tmio); |
236 | 89cdb6af | balrog | |
237 | 89cdb6af | balrog | tosa_microdrive_attach(cpu); |
238 | 89cdb6af | balrog | |
239 | 4ea29f74 | balrog | tosa_tg_init(cpu); |
240 | 4ea29f74 | balrog | |
241 | 89cdb6af | balrog | tosa_binfo.kernel_filename = kernel_filename; |
242 | 89cdb6af | balrog | tosa_binfo.kernel_cmdline = kernel_cmdline; |
243 | 89cdb6af | balrog | tosa_binfo.initrd_filename = initrd_filename; |
244 | 89cdb6af | balrog | tosa_binfo.board_id = 0x208;
|
245 | 89cdb6af | balrog | arm_load_kernel(cpu->env, &tosa_binfo); |
246 | f78630ab | pbrook | sl_bootparam_write(SL_PXA_PARAM_BASE); |
247 | 89cdb6af | balrog | } |
248 | 89cdb6af | balrog | |
249 | f80f9ec9 | Anthony Liguori | static QEMUMachine tosapda_machine = {
|
250 | 4b32e168 | aliguori | .name = "tosa",
|
251 | 4b32e168 | aliguori | .desc = "Tosa PDA (PXA255)",
|
252 | 4b32e168 | aliguori | .init = tosa_init, |
253 | 89cdb6af | balrog | }; |
254 | fd1eb2ea | Paul Brook | |
255 | f80f9ec9 | Anthony Liguori | static void tosapda_machine_init(void) |
256 | f80f9ec9 | Anthony Liguori | { |
257 | f80f9ec9 | Anthony Liguori | qemu_register_machine(&tosapda_machine); |
258 | f80f9ec9 | Anthony Liguori | } |
259 | f80f9ec9 | Anthony Liguori | |
260 | f80f9ec9 | Anthony Liguori | machine_init(tosapda_machine_init); |
261 | f80f9ec9 | Anthony Liguori | |
262 | b5ea9327 | Anthony Liguori | static void tosa_dac_class_init(ObjectClass *klass, void *data) |
263 | b5ea9327 | Anthony Liguori | { |
264 | b5ea9327 | Anthony Liguori | I2CSlaveClass *k = I2C_SLAVE_CLASS(klass); |
265 | b5ea9327 | Anthony Liguori | |
266 | b5ea9327 | Anthony Liguori | k->init = tosa_dac_init; |
267 | b5ea9327 | Anthony Liguori | k->event = tosa_dac_event; |
268 | b5ea9327 | Anthony Liguori | k->recv = tosa_dac_recv; |
269 | b5ea9327 | Anthony Liguori | k->send = tosa_dac_send; |
270 | b5ea9327 | Anthony Liguori | } |
271 | b5ea9327 | Anthony Liguori | |
272 | 39bffca2 | Anthony Liguori | static TypeInfo tosa_dac_info = {
|
273 | 39bffca2 | Anthony Liguori | .name = "tosa_dac",
|
274 | 39bffca2 | Anthony Liguori | .parent = TYPE_I2C_SLAVE, |
275 | 39bffca2 | Anthony Liguori | .instance_size = sizeof(TosaDACState),
|
276 | 39bffca2 | Anthony Liguori | .class_init = tosa_dac_class_init, |
277 | 39bffca2 | Anthony Liguori | }; |
278 | cd6c4cf2 | Anthony Liguori | |
279 | cd6c4cf2 | Anthony Liguori | static void tosa_ssp_class_init(ObjectClass *klass, void *data) |
280 | cd6c4cf2 | Anthony Liguori | { |
281 | cd6c4cf2 | Anthony Liguori | SSISlaveClass *k = SSI_SLAVE_CLASS(klass); |
282 | cd6c4cf2 | Anthony Liguori | |
283 | cd6c4cf2 | Anthony Liguori | k->init = tosa_ssp_init; |
284 | cd6c4cf2 | Anthony Liguori | k->transfer = tosa_ssp_tansfer; |
285 | cd6c4cf2 | Anthony Liguori | } |
286 | fd1eb2ea | Paul Brook | |
287 | 39bffca2 | Anthony Liguori | static TypeInfo tosa_ssp_info = {
|
288 | 39bffca2 | Anthony Liguori | .name = "tosa-ssp",
|
289 | 39bffca2 | Anthony Liguori | .parent = TYPE_SSI_SLAVE, |
290 | 39bffca2 | Anthony Liguori | .instance_size = sizeof(SSISlave),
|
291 | 39bffca2 | Anthony Liguori | .class_init = tosa_ssp_class_init, |
292 | a984a69e | Paul Brook | }; |
293 | a984a69e | Paul Brook | |
294 | fd1eb2ea | Paul Brook | static void tosa_register_devices(void) |
295 | fd1eb2ea | Paul Brook | { |
296 | 39bffca2 | Anthony Liguori | type_register_static(&tosa_dac_info); |
297 | 39bffca2 | Anthony Liguori | type_register_static(&tosa_ssp_info); |
298 | fd1eb2ea | Paul Brook | } |
299 | fd1eb2ea | Paul Brook | |
300 | fd1eb2ea | Paul Brook | device_init(tosa_register_devices) |