2 * Copyright (c) 2006-2008 Openedhand Ltd.
3 * Written by Andrzej Zaborowski <balrog@zabor.org>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 or
8 * (at your option) version 3 of the License.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25 #if TARGET_PHYS_ADDR_BITS == 32
26 #define REG_FMT "0x%02x"
28 #define REG_FMT "0x%02lx"
50 #define SCOOP_MCR 0x00
51 #define SCOOP_CDR 0x04
52 #define SCOOP_CSR 0x08
53 #define SCOOP_CPR 0x0c
54 #define SCOOP_CCR 0x10
55 #define SCOOP_IRR_IRM 0x14
56 #define SCOOP_IMR 0x18
57 #define SCOOP_ISR 0x1c
58 #define SCOOP_GPCR 0x20
59 #define SCOOP_GPWR 0x24
60 #define SCOOP_GPRR 0x28
62 static inline void scoop_gpio_handler_update(struct scoop_info_s
*s
) {
65 level
= s
->gpio_level
& s
->gpio_dir
;
67 for (diff
= s
->prev_level
^ level
; diff
; diff
^= 1 << bit
) {
69 qemu_set_irq(s
->handler
[bit
], (level
>> bit
) & 1);
72 s
->prev_level
= level
;
75 static uint32_t scoop_readb(void *opaque
, target_phys_addr_t addr
)
77 struct scoop_info_s
*s
= (struct scoop_info_s
*) opaque
;
100 return s
->gpio_level
;
102 zaurus_printf("Bad register offset " REG_FMT
"\n", addr
);
108 static void scoop_writeb(void *opaque
, target_phys_addr_t addr
, uint32_t value
)
110 struct scoop_info_s
*s
= (struct scoop_info_s
*) opaque
;
139 scoop_gpio_handler_update(s
);
142 case SCOOP_GPRR
: /* GPRR is probably R/O in real HW */
143 s
->gpio_level
= value
& s
->gpio_dir
;
144 scoop_gpio_handler_update(s
);
147 zaurus_printf("Bad register offset " REG_FMT
"\n", addr
);
151 static CPUReadMemoryFunc
*scoop_readfn
[] = {
156 static CPUWriteMemoryFunc
*scoop_writefn
[] = {
162 void scoop_gpio_set(void *opaque
, int line
, int level
)
164 struct scoop_info_s
*s
= (struct scoop_info_s
*) s
;
167 s
->gpio_level
|= (1 << line
);
169 s
->gpio_level
&= ~(1 << line
);
172 qemu_irq
*scoop_gpio_in_get(struct scoop_info_s
*s
)
177 void scoop_gpio_out_set(struct scoop_info_s
*s
, int line
,
180 fprintf(stderr
, "No GPIO pin %i\n", line
);
184 s
->handler
[line
] = handler
;
187 static void scoop_save(QEMUFile
*f
, void *opaque
)
189 struct scoop_info_s
*s
= (struct scoop_info_s
*) opaque
;
190 qemu_put_be16s(f
, &s
->status
);
191 qemu_put_be16s(f
, &s
->power
);
192 qemu_put_be32s(f
, &s
->gpio_level
);
193 qemu_put_be32s(f
, &s
->gpio_dir
);
194 qemu_put_be32s(f
, &s
->prev_level
);
195 qemu_put_be16s(f
, &s
->mcr
);
196 qemu_put_be16s(f
, &s
->cdr
);
197 qemu_put_be16s(f
, &s
->ccr
);
198 qemu_put_be16s(f
, &s
->irr
);
199 qemu_put_be16s(f
, &s
->imr
);
200 qemu_put_be16s(f
, &s
->isr
);
203 static int scoop_load(QEMUFile
*f
, void *opaque
, int version_id
)
206 struct scoop_info_s
*s
= (struct scoop_info_s
*) opaque
;
207 qemu_get_be16s(f
, &s
->status
);
208 qemu_get_be16s(f
, &s
->power
);
209 qemu_get_be32s(f
, &s
->gpio_level
);
210 qemu_get_be32s(f
, &s
->gpio_dir
);
211 qemu_get_be32s(f
, &s
->prev_level
);
212 qemu_get_be16s(f
, &s
->mcr
);
213 qemu_get_be16s(f
, &s
->cdr
);
214 qemu_get_be16s(f
, &s
->ccr
);
215 qemu_get_be16s(f
, &s
->irr
);
216 qemu_get_be16s(f
, &s
->imr
);
217 qemu_get_be16s(f
, &s
->isr
);
219 qemu_get_be16s(f
, &dummy
);
224 struct scoop_info_s
*scoop_init(struct pxa2xx_state_s
*cpu
,
226 target_phys_addr_t target_base
) {
228 struct scoop_info_s
*s
;
230 s
= (struct scoop_info_s
*)
231 qemu_mallocz(sizeof(struct scoop_info_s
));
232 memset(s
, 0, sizeof(struct scoop_info_s
));
235 s
->in
= qemu_allocate_irqs(scoop_gpio_set
, s
, 16);
236 iomemtype
= cpu_register_io_memory(0, scoop_readfn
,
238 cpu_register_physical_memory(target_base
, 0x1000, iomemtype
);
239 register_savevm("scoop", instance
, 1, scoop_save
, scoop_load
, s
);
244 /* Write the bootloader parameters memory area. */
246 #define MAGIC_CHG(a, b, c, d) ((d << 24) | (c << 16) | (b << 8) | a)
248 static struct __attribute__ ((__packed__
)) sl_param_info
{
249 uint32_t comadj_keyword
;
252 uint32_t uuid_keyword
;
255 uint32_t touch_keyword
;
261 uint32_t adadj_keyword
;
264 uint32_t phad_keyword
;
266 } zaurus_bootparam
= {
267 .comadj_keyword
= MAGIC_CHG('C', 'M', 'A', 'D'),
269 .uuid_keyword
= MAGIC_CHG('U', 'U', 'I', 'D'),
271 .touch_keyword
= MAGIC_CHG('T', 'U', 'C', 'H'),
273 .adadj_keyword
= MAGIC_CHG('B', 'V', 'A', 'D'),
275 .phad_keyword
= MAGIC_CHG('P', 'H', 'A', 'D'),
279 void sl_bootparam_write(uint32_t ptr
)
281 memcpy(phys_ram_base
+ ptr
, &zaurus_bootparam
,
282 sizeof(struct sl_param_info
));