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