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