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, see <http://www.gnu.org/licenses/>.
23 #define REG_FMT "0x%02lx"
27 typedef struct ScoopInfo ScoopInfo
;
46 #define SCOOP_MCR 0x00
47 #define SCOOP_CDR 0x04
48 #define SCOOP_CSR 0x08
49 #define SCOOP_CPR 0x0c
50 #define SCOOP_CCR 0x10
51 #define SCOOP_IRR_IRM 0x14
52 #define SCOOP_IMR 0x18
53 #define SCOOP_ISR 0x1c
54 #define SCOOP_GPCR 0x20
55 #define SCOOP_GPWR 0x24
56 #define SCOOP_GPRR 0x28
58 static inline void scoop_gpio_handler_update(ScoopInfo
*s
) {
61 level
= s
->gpio_level
& s
->gpio_dir
;
63 for (diff
= s
->prev_level
^ level
; diff
; diff
^= 1 << bit
) {
65 qemu_set_irq(s
->handler
[bit
], (level
>> bit
) & 1);
68 s
->prev_level
= level
;
71 static uint64_t scoop_read(void *opaque
, target_phys_addr_t addr
,
74 ScoopInfo
*s
= (ScoopInfo
*) opaque
;
76 switch (addr
& 0x3f) {
99 zaurus_printf("Bad register offset " REG_FMT
"\n", (unsigned long)addr
);
105 static void scoop_write(void *opaque
, target_phys_addr_t addr
,
106 uint64_t value
, unsigned size
)
108 ScoopInfo
*s
= (ScoopInfo
*) opaque
;
111 switch (addr
& 0x3f) {
137 scoop_gpio_handler_update(s
);
140 case SCOOP_GPRR
: /* GPRR is probably R/O in real HW */
141 s
->gpio_level
= value
& s
->gpio_dir
;
142 scoop_gpio_handler_update(s
);
145 zaurus_printf("Bad register offset " REG_FMT
"\n", (unsigned long)addr
);
149 static const MemoryRegionOps scoop_ops
= {
151 .write
= scoop_write
,
152 .endianness
= DEVICE_NATIVE_ENDIAN
,
155 static void scoop_gpio_set(void *opaque
, int line
, int level
)
157 ScoopInfo
*s
= (ScoopInfo
*) opaque
;
160 s
->gpio_level
|= (1 << line
);
162 s
->gpio_level
&= ~(1 << line
);
165 static int scoop_init(SysBusDevice
*dev
)
167 ScoopInfo
*s
= FROM_SYSBUS(ScoopInfo
, dev
);
170 qdev_init_gpio_out(&s
->busdev
.qdev
, s
->handler
, 16);
171 qdev_init_gpio_in(&s
->busdev
.qdev
, scoop_gpio_set
, 16);
172 memory_region_init_io(&s
->iomem
, &scoop_ops
, s
, "scoop", 0x1000);
174 sysbus_init_mmio(dev
, &s
->iomem
);
179 static int scoop_post_load(void *opaque
, int version_id
)
181 ScoopInfo
*s
= (ScoopInfo
*) opaque
;
185 level
= s
->gpio_level
& s
->gpio_dir
;
187 for (i
= 0; i
< 16; i
++) {
188 qemu_set_irq(s
->handler
[i
], (level
>> i
) & 1);
191 s
->prev_level
= level
;
196 static bool is_version_0 (void *opaque
, int version_id
)
198 return version_id
== 0;
201 static const VMStateDescription vmstate_scoop_regs
= {
204 .minimum_version_id
= 0,
205 .minimum_version_id_old
= 0,
206 .post_load
= scoop_post_load
,
207 .fields
= (VMStateField
[]) {
208 VMSTATE_UINT16(status
, ScoopInfo
),
209 VMSTATE_UINT16(power
, ScoopInfo
),
210 VMSTATE_UINT32(gpio_level
, ScoopInfo
),
211 VMSTATE_UINT32(gpio_dir
, ScoopInfo
),
212 VMSTATE_UINT32(prev_level
, ScoopInfo
),
213 VMSTATE_UINT16(mcr
, ScoopInfo
),
214 VMSTATE_UINT16(cdr
, ScoopInfo
),
215 VMSTATE_UINT16(ccr
, ScoopInfo
),
216 VMSTATE_UINT16(irr
, ScoopInfo
),
217 VMSTATE_UINT16(imr
, ScoopInfo
),
218 VMSTATE_UINT16(isr
, ScoopInfo
),
219 VMSTATE_UNUSED_TEST(is_version_0
, 2),
220 VMSTATE_END_OF_LIST(),
224 static SysBusDeviceInfo scoop_sysbus_info
= {
226 .qdev
.name
= "scoop",
227 .qdev
.desc
= "Scoop2 Sharp custom ASIC",
228 .qdev
.size
= sizeof(ScoopInfo
),
229 .qdev
.vmsd
= &vmstate_scoop_regs
,
230 .qdev
.props
= (Property
[]) {
231 DEFINE_PROP_END_OF_LIST(),
235 static void scoop_register(void)
237 sysbus_register_withprop(&scoop_sysbus_info
);
239 device_init(scoop_register
);
241 /* Write the bootloader parameters memory area. */
243 #define MAGIC_CHG(a, b, c, d) ((d << 24) | (c << 16) | (b << 8) | a)
245 static struct QEMU_PACKED sl_param_info
{
246 uint32_t comadj_keyword
;
249 uint32_t uuid_keyword
;
252 uint32_t touch_keyword
;
258 uint32_t adadj_keyword
;
261 uint32_t phad_keyword
;
263 } zaurus_bootparam
= {
264 .comadj_keyword
= MAGIC_CHG('C', 'M', 'A', 'D'),
266 .uuid_keyword
= MAGIC_CHG('U', 'U', 'I', 'D'),
268 .touch_keyword
= MAGIC_CHG('T', 'U', 'C', 'H'),
270 .adadj_keyword
= MAGIC_CHG('B', 'V', 'A', 'D'),
272 .phad_keyword
= MAGIC_CHG('P', 'H', 'A', 'D'),
276 void sl_bootparam_write(target_phys_addr_t ptr
)
278 cpu_physical_memory_write(ptr
, (void *)&zaurus_bootparam
,
279 sizeof(struct sl_param_info
));