root / hw / tosa.c @ 7aff0f21
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 | 89cdb6af | balrog | |
24 | 89cdb6af | balrog | #define TOSA_RAM 0x04000000 |
25 | 89cdb6af | balrog | #define TOSA_ROM 0x00800000 |
26 | 89cdb6af | balrog | |
27 | 2e4b4e79 | Dmitry Eremin-Solenikov | #define TOSA_GPIO_USB_IN (5) |
28 | 89cdb6af | balrog | #define TOSA_GPIO_nSD_DETECT (9) |
29 | 89cdb6af | balrog | #define TOSA_GPIO_ON_RESET (19) |
30 | 89cdb6af | balrog | #define TOSA_GPIO_CF_IRQ (21) /* CF slot0 Ready */ |
31 | 89cdb6af | balrog | #define TOSA_GPIO_CF_CD (13) |
32 | 5d98751b | balrog | #define TOSA_GPIO_TC6393XB_INT (15) |
33 | 89cdb6af | balrog | #define TOSA_GPIO_JC_CF_IRQ (36) /* CF slot1 Ready */ |
34 | 89cdb6af | balrog | |
35 | 6bc1d858 | balrog | #define TOSA_SCOOP_GPIO_BASE 1 |
36 | 89cdb6af | balrog | #define TOSA_GPIO_IR_POWERDWN (TOSA_SCOOP_GPIO_BASE + 2) |
37 | 89cdb6af | balrog | #define TOSA_GPIO_SD_WP (TOSA_SCOOP_GPIO_BASE + 3) |
38 | 89cdb6af | balrog | #define TOSA_GPIO_PWR_ON (TOSA_SCOOP_GPIO_BASE + 4) |
39 | 89cdb6af | balrog | |
40 | 6bc1d858 | balrog | #define TOSA_SCOOP_JC_GPIO_BASE 1 |
41 | 6bc1d858 | balrog | #define TOSA_GPIO_BT_LED (TOSA_SCOOP_JC_GPIO_BASE + 0) |
42 | 6bc1d858 | balrog | #define TOSA_GPIO_NOTE_LED (TOSA_SCOOP_JC_GPIO_BASE + 1) |
43 | 6bc1d858 | balrog | #define TOSA_GPIO_CHRG_ERR_LED (TOSA_SCOOP_JC_GPIO_BASE + 2) |
44 | 64b40bc5 | balrog | #define TOSA_GPIO_TC6393XB_L3V_ON (TOSA_SCOOP_JC_GPIO_BASE + 5) |
45 | 6bc1d858 | balrog | #define TOSA_GPIO_WLAN_LED (TOSA_SCOOP_JC_GPIO_BASE + 7) |
46 | 6bc1d858 | balrog | |
47 | 4ea29f74 | balrog | #define DAC_BASE 0x4e |
48 | 4ea29f74 | balrog | #define DAC_CH1 0 |
49 | 4ea29f74 | balrog | #define DAC_CH2 1 |
50 | 4ea29f74 | balrog | |
51 | bc24a225 | Paul Brook | static void tosa_microdrive_attach(PXA2xxState *cpu) |
52 | 89cdb6af | balrog | { |
53 | bc24a225 | Paul Brook | PCMCIACardState *md; |
54 | 89cdb6af | balrog | BlockDriverState *bs; |
55 | 751c6a17 | Gerd Hoffmann | DriveInfo *dinfo; |
56 | 89cdb6af | balrog | |
57 | 751c6a17 | Gerd Hoffmann | dinfo = drive_get(IF_IDE, 0, 0); |
58 | 751c6a17 | Gerd Hoffmann | if (!dinfo)
|
59 | 89cdb6af | balrog | return;
|
60 | 751c6a17 | Gerd Hoffmann | bs = dinfo->bdrv; |
61 | 89cdb6af | balrog | if (bdrv_is_inserted(bs) && !bdrv_is_removable(bs)) {
|
62 | f455e98c | Gerd Hoffmann | md = dscm1xxxx_init(dinfo); |
63 | 89cdb6af | balrog | pxa2xx_pcmcia_attach(cpu->pcmcia[0], md);
|
64 | 89cdb6af | balrog | } |
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 | 4ea29f74 | balrog | i2c_slave i2c; |
137 | 4ea29f74 | balrog | int len;
|
138 | 4ea29f74 | balrog | char buf[3]; |
139 | d3151521 | Paul Brook | } TosaDACState; |
140 | 4ea29f74 | balrog | |
141 | 4ea29f74 | balrog | static int tosa_dac_send(i2c_slave *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 | 4ea29f74 | balrog | static void tosa_dac_event(i2c_slave *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 | dfb021bc | aurel32 | static int tosa_dac_recv(i2c_slave *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 | 81a322d4 | Gerd Hoffmann | static int tosa_dac_init(i2c_slave *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 | bc24a225 | Paul Brook | PXA2xxState *cpu; |
214 | bc24a225 | Paul Brook | TC6393xbState *tmio; |
215 | 383d01c6 | Dmitry Eremin-Solenikov | DeviceState *scp0, *scp1; |
216 | 89cdb6af | balrog | |
217 | 89cdb6af | balrog | if (!cpu_model)
|
218 | 89cdb6af | balrog | cpu_model = "pxa255";
|
219 | 89cdb6af | balrog | |
220 | 3023f332 | aliguori | cpu = pxa255_init(tosa_binfo.ram_size); |
221 | 89cdb6af | balrog | |
222 | 89cdb6af | balrog | cpu_register_physical_memory(0, TOSA_ROM,
|
223 | 1724f049 | Alex Williamson | qemu_ram_alloc(NULL, "tosa.rom", TOSA_ROM) | IO_MEM_ROM); |
224 | 89cdb6af | balrog | |
225 | 64b40bc5 | balrog | tmio = tc6393xb_init(0x10000000,
|
226 | 0bb53337 | Dmitry Eremin-Solenikov | qdev_get_gpio_in(cpu->gpio, TOSA_GPIO_TC6393XB_INT)); |
227 | 89cdb6af | balrog | |
228 | 383d01c6 | Dmitry Eremin-Solenikov | scp0 = sysbus_create_simple("scoop", 0x08800000, NULL); |
229 | 383d01c6 | Dmitry Eremin-Solenikov | scp1 = sysbus_create_simple("scoop", 0x14800040, NULL); |
230 | 89cdb6af | balrog | |
231 | 64b40bc5 | balrog | tosa_gpio_setup(cpu, scp0, scp1, tmio); |
232 | 89cdb6af | balrog | |
233 | 89cdb6af | balrog | tosa_microdrive_attach(cpu); |
234 | 89cdb6af | balrog | |
235 | 4ea29f74 | balrog | tosa_tg_init(cpu); |
236 | 4ea29f74 | balrog | |
237 | 89cdb6af | balrog | tosa_binfo.kernel_filename = kernel_filename; |
238 | 89cdb6af | balrog | tosa_binfo.kernel_cmdline = kernel_cmdline; |
239 | 89cdb6af | balrog | tosa_binfo.initrd_filename = initrd_filename; |
240 | 89cdb6af | balrog | tosa_binfo.board_id = 0x208;
|
241 | 89cdb6af | balrog | arm_load_kernel(cpu->env, &tosa_binfo); |
242 | f78630ab | pbrook | sl_bootparam_write(SL_PXA_PARAM_BASE); |
243 | 89cdb6af | balrog | } |
244 | 89cdb6af | balrog | |
245 | f80f9ec9 | Anthony Liguori | static QEMUMachine tosapda_machine = {
|
246 | 4b32e168 | aliguori | .name = "tosa",
|
247 | 4b32e168 | aliguori | .desc = "Tosa PDA (PXA255)",
|
248 | 4b32e168 | aliguori | .init = tosa_init, |
249 | 89cdb6af | balrog | }; |
250 | fd1eb2ea | Paul Brook | |
251 | f80f9ec9 | Anthony Liguori | static void tosapda_machine_init(void) |
252 | f80f9ec9 | Anthony Liguori | { |
253 | f80f9ec9 | Anthony Liguori | qemu_register_machine(&tosapda_machine); |
254 | f80f9ec9 | Anthony Liguori | } |
255 | f80f9ec9 | Anthony Liguori | |
256 | f80f9ec9 | Anthony Liguori | machine_init(tosapda_machine_init); |
257 | f80f9ec9 | Anthony Liguori | |
258 | fd1eb2ea | Paul Brook | static I2CSlaveInfo tosa_dac_info = {
|
259 | 074f2fff | Gerd Hoffmann | .qdev.name = "tosa_dac",
|
260 | 074f2fff | Gerd Hoffmann | .qdev.size = sizeof(TosaDACState),
|
261 | fd1eb2ea | Paul Brook | .init = tosa_dac_init, |
262 | fd1eb2ea | Paul Brook | .event = tosa_dac_event, |
263 | fd1eb2ea | Paul Brook | .recv = tosa_dac_recv, |
264 | fd1eb2ea | Paul Brook | .send = tosa_dac_send |
265 | fd1eb2ea | Paul Brook | }; |
266 | fd1eb2ea | Paul Brook | |
267 | a984a69e | Paul Brook | static SSISlaveInfo tosa_ssp_info = {
|
268 | 074f2fff | Gerd Hoffmann | .qdev.name = "tosa-ssp",
|
269 | 074f2fff | Gerd Hoffmann | .qdev.size = sizeof(SSISlave),
|
270 | a984a69e | Paul Brook | .init = tosa_ssp_init, |
271 | a984a69e | Paul Brook | .transfer = tosa_ssp_tansfer |
272 | a984a69e | Paul Brook | }; |
273 | a984a69e | Paul Brook | |
274 | fd1eb2ea | Paul Brook | static void tosa_register_devices(void) |
275 | fd1eb2ea | Paul Brook | { |
276 | 074f2fff | Gerd Hoffmann | i2c_register_slave(&tosa_dac_info); |
277 | 074f2fff | Gerd Hoffmann | ssi_register_slave(&tosa_ssp_info); |
278 | fd1eb2ea | Paul Brook | } |
279 | fd1eb2ea | Paul Brook | |
280 | fd1eb2ea | Paul Brook | device_init(tosa_register_devices) |