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