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