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 along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #if TARGET_PHYS_ADDR_BITS == 32
25 #define REG_FMT "0x%02x"
27 #define REG_FMT "0x%02lx"
49 #define SCOOP_MCR 0x00
50 #define SCOOP_CDR 0x04
51 #define SCOOP_CSR 0x08
52 #define SCOOP_CPR 0x0c
53 #define SCOOP_CCR 0x10
54 #define SCOOP_IRR_IRM 0x14
55 #define SCOOP_IMR 0x18
56 #define SCOOP_ISR 0x1c
57 #define SCOOP_GPCR 0x20
58 #define SCOOP_GPWR 0x24
59 #define SCOOP_GPRR 0x28
61 static inline void scoop_gpio_handler_update(ScoopInfo
*s
) {
64 level
= s
->gpio_level
& s
->gpio_dir
;
66 for (diff
= s
->prev_level
^ level
; diff
; diff
^= 1 << bit
) {
68 qemu_set_irq(s
->handler
[bit
], (level
>> bit
) & 1);
71 s
->prev_level
= level
;
74 static uint32_t scoop_readb(void *opaque
, target_phys_addr_t addr
)
76 ScoopInfo
*s
= (ScoopInfo
*) opaque
;
101 zaurus_printf("Bad register offset " REG_FMT
"\n", addr
);
107 static void scoop_writeb(void *opaque
, target_phys_addr_t addr
, uint32_t value
)
109 ScoopInfo
*s
= (ScoopInfo
*) opaque
;
138 scoop_gpio_handler_update(s
);
141 case SCOOP_GPRR
: /* GPRR is probably R/O in real HW */
142 s
->gpio_level
= value
& s
->gpio_dir
;
143 scoop_gpio_handler_update(s
);
146 zaurus_printf("Bad register offset " REG_FMT
"\n", addr
);
150 static CPUReadMemoryFunc
*scoop_readfn
[] = {
155 static CPUWriteMemoryFunc
*scoop_writefn
[] = {
161 void scoop_gpio_set(void *opaque
, int line
, int level
)
163 ScoopInfo
*s
= (ScoopInfo
*) s
;
166 s
->gpio_level
|= (1 << line
);
168 s
->gpio_level
&= ~(1 << line
);
171 qemu_irq
*scoop_gpio_in_get(ScoopInfo
*s
)
176 void scoop_gpio_out_set(ScoopInfo
*s
, int line
,
179 fprintf(stderr
, "No GPIO pin %i\n", line
);
183 s
->handler
[line
] = handler
;
186 static void scoop_save(QEMUFile
*f
, void *opaque
)
188 ScoopInfo
*s
= (ScoopInfo
*) opaque
;
189 qemu_put_be16s(f
, &s
->status
);
190 qemu_put_be16s(f
, &s
->power
);
191 qemu_put_be32s(f
, &s
->gpio_level
);
192 qemu_put_be32s(f
, &s
->gpio_dir
);
193 qemu_put_be32s(f
, &s
->prev_level
);
194 qemu_put_be16s(f
, &s
->mcr
);
195 qemu_put_be16s(f
, &s
->cdr
);
196 qemu_put_be16s(f
, &s
->ccr
);
197 qemu_put_be16s(f
, &s
->irr
);
198 qemu_put_be16s(f
, &s
->imr
);
199 qemu_put_be16s(f
, &s
->isr
);
202 static int scoop_load(QEMUFile
*f
, void *opaque
, int version_id
)
205 ScoopInfo
*s
= (ScoopInfo
*) opaque
;
206 qemu_get_be16s(f
, &s
->status
);
207 qemu_get_be16s(f
, &s
->power
);
208 qemu_get_be32s(f
, &s
->gpio_level
);
209 qemu_get_be32s(f
, &s
->gpio_dir
);
210 qemu_get_be32s(f
, &s
->prev_level
);
211 qemu_get_be16s(f
, &s
->mcr
);
212 qemu_get_be16s(f
, &s
->cdr
);
213 qemu_get_be16s(f
, &s
->ccr
);
214 qemu_get_be16s(f
, &s
->irr
);
215 qemu_get_be16s(f
, &s
->imr
);
216 qemu_get_be16s(f
, &s
->isr
);
218 qemu_get_be16s(f
, &dummy
);
223 ScoopInfo
*scoop_init(PXA2xxState
*cpu
,
225 target_phys_addr_t target_base
) {
230 qemu_mallocz(sizeof(ScoopInfo
));
231 memset(s
, 0, sizeof(ScoopInfo
));
234 s
->in
= qemu_allocate_irqs(scoop_gpio_set
, s
, 16);
235 iomemtype
= cpu_register_io_memory(0, scoop_readfn
,
237 cpu_register_physical_memory(target_base
, 0x1000, iomemtype
);
238 register_savevm("scoop", instance
, 1, scoop_save
, scoop_load
, s
);
243 /* Write the bootloader parameters memory area. */
245 #define MAGIC_CHG(a, b, c, d) ((d << 24) | (c << 16) | (b << 8) | a)
247 static struct __attribute__ ((__packed__
)) sl_param_info
{
248 uint32_t comadj_keyword
;
251 uint32_t uuid_keyword
;
254 uint32_t touch_keyword
;
260 uint32_t adadj_keyword
;
263 uint32_t phad_keyword
;
265 } zaurus_bootparam
= {
266 .comadj_keyword
= MAGIC_CHG('C', 'M', 'A', 'D'),
268 .uuid_keyword
= MAGIC_CHG('U', 'U', 'I', 'D'),
270 .touch_keyword
= MAGIC_CHG('T', 'U', 'C', 'H'),
272 .adadj_keyword
= MAGIC_CHG('B', 'V', 'A', 'D'),
274 .phad_keyword
= MAGIC_CHG('P', 'H', 'A', 'D'),
278 void sl_bootparam_write(target_phys_addr_t ptr
)
280 cpu_physical_memory_write(ptr
, (void *)&zaurus_bootparam
,
281 sizeof(struct sl_param_info
));