Statistics
| Branch: | Revision:

root / hw / zaurus.c @ a214c598

History | View | Annotate | Download (7.1 kB)

1 e33d8cdb balrog
/*
2 e33d8cdb balrog
 * Copyright (c) 2006-2008 Openedhand Ltd.
3 e33d8cdb balrog
 * Written by Andrzej Zaborowski <balrog@zabor.org>
4 e33d8cdb balrog
 *
5 e33d8cdb balrog
 * This program is free software; you can redistribute it and/or
6 e33d8cdb balrog
 * modify it under the terms of the GNU General Public License as
7 e33d8cdb balrog
 * published by the Free Software Foundation; either version 2 or
8 e33d8cdb balrog
 * (at your option) version 3 of the License.
9 e33d8cdb balrog
 *
10 e33d8cdb balrog
 * This program is distributed in the hope that it will be useful,
11 e33d8cdb balrog
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 e33d8cdb balrog
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 e33d8cdb balrog
 * GNU General Public License for more details.
14 e33d8cdb balrog
 *
15 e33d8cdb balrog
 * You should have received a copy of the GNU General Public License
16 e33d8cdb balrog
 * along with this program; if not, write to the Free Software
17 e33d8cdb balrog
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
18 e33d8cdb balrog
 * MA 02111-1307 USA
19 e33d8cdb balrog
 */
20 e33d8cdb balrog
#include "hw.h"
21 e33d8cdb balrog
#include "pxa.h"
22 e33d8cdb balrog
#include "sharpsl.h"
23 e33d8cdb balrog
24 e33d8cdb balrog
#undef REG_FMT
25 e33d8cdb balrog
#if TARGET_PHYS_ADDR_BITS == 32
26 e33d8cdb balrog
#define REG_FMT                        "0x%02x"
27 e33d8cdb balrog
#else
28 e33d8cdb balrog
#define REG_FMT                        "0x%02lx"
29 e33d8cdb balrog
#endif
30 e33d8cdb balrog
31 e33d8cdb balrog
/* SCOOP devices */
32 e33d8cdb balrog
33 e33d8cdb balrog
struct scoop_info_s {
34 e33d8cdb balrog
    target_phys_addr_t target_base;
35 e33d8cdb balrog
    qemu_irq handler[16];
36 e33d8cdb balrog
    qemu_irq *in;
37 e33d8cdb balrog
    uint16_t status;
38 e33d8cdb balrog
    uint16_t power;
39 e33d8cdb balrog
    uint32_t gpio_level;
40 e33d8cdb balrog
    uint32_t gpio_dir;
41 e33d8cdb balrog
    uint32_t prev_level;
42 e33d8cdb balrog
43 e33d8cdb balrog
    uint16_t mcr;
44 e33d8cdb balrog
    uint16_t cdr;
45 e33d8cdb balrog
    uint16_t ccr;
46 e33d8cdb balrog
    uint16_t irr;
47 e33d8cdb balrog
    uint16_t imr;
48 e33d8cdb balrog
    uint16_t isr;
49 e33d8cdb balrog
    uint16_t gprr;
50 e33d8cdb balrog
};
51 e33d8cdb balrog
52 e33d8cdb balrog
#define SCOOP_MCR        0x00
53 e33d8cdb balrog
#define SCOOP_CDR        0x04
54 e33d8cdb balrog
#define SCOOP_CSR        0x08
55 e33d8cdb balrog
#define SCOOP_CPR        0x0c
56 e33d8cdb balrog
#define SCOOP_CCR        0x10
57 e33d8cdb balrog
#define SCOOP_IRR_IRM        0x14
58 e33d8cdb balrog
#define SCOOP_IMR        0x18
59 e33d8cdb balrog
#define SCOOP_ISR        0x1c
60 e33d8cdb balrog
#define SCOOP_GPCR        0x20
61 e33d8cdb balrog
#define SCOOP_GPWR        0x24
62 e33d8cdb balrog
#define SCOOP_GPRR        0x28
63 e33d8cdb balrog
64 e33d8cdb balrog
static inline void scoop_gpio_handler_update(struct scoop_info_s *s) {
65 e33d8cdb balrog
    uint32_t level, diff;
66 e33d8cdb balrog
    int bit;
67 e33d8cdb balrog
    level = s->gpio_level & s->gpio_dir;
68 e33d8cdb balrog
69 e33d8cdb balrog
    for (diff = s->prev_level ^ level; diff; diff ^= 1 << bit) {
70 e33d8cdb balrog
        bit = ffs(diff) - 1;
71 e33d8cdb balrog
        qemu_set_irq(s->handler[bit], (level >> bit) & 1);
72 e33d8cdb balrog
    }
73 e33d8cdb balrog
74 e33d8cdb balrog
    s->prev_level = level;
75 e33d8cdb balrog
}
76 e33d8cdb balrog
77 e33d8cdb balrog
static uint32_t scoop_readb(void *opaque, target_phys_addr_t addr)
78 e33d8cdb balrog
{
79 e33d8cdb balrog
    struct scoop_info_s *s = (struct scoop_info_s *) opaque;
80 e33d8cdb balrog
    addr -= s->target_base;
81 e33d8cdb balrog
82 e33d8cdb balrog
    switch (addr) {
83 e33d8cdb balrog
    case SCOOP_MCR:
84 e33d8cdb balrog
        return s->mcr;
85 e33d8cdb balrog
    case SCOOP_CDR:
86 e33d8cdb balrog
        return s->cdr;
87 e33d8cdb balrog
    case SCOOP_CSR:
88 e33d8cdb balrog
        return s->status;
89 e33d8cdb balrog
    case SCOOP_CPR:
90 e33d8cdb balrog
        return s->power;
91 e33d8cdb balrog
    case SCOOP_CCR:
92 e33d8cdb balrog
        return s->ccr;
93 e33d8cdb balrog
    case SCOOP_IRR_IRM:
94 e33d8cdb balrog
        return s->irr;
95 e33d8cdb balrog
    case SCOOP_IMR:
96 e33d8cdb balrog
        return s->imr;
97 e33d8cdb balrog
    case SCOOP_ISR:
98 e33d8cdb balrog
        return s->isr;
99 e33d8cdb balrog
    case SCOOP_GPCR:
100 e33d8cdb balrog
        return s->gpio_dir;
101 e33d8cdb balrog
    case SCOOP_GPWR:
102 e33d8cdb balrog
        return s->gpio_level;
103 e33d8cdb balrog
    case SCOOP_GPRR:
104 e33d8cdb balrog
        return s->gprr;
105 e33d8cdb balrog
    default:
106 e33d8cdb balrog
        zaurus_printf("Bad register offset " REG_FMT "\n", addr);
107 e33d8cdb balrog
    }
108 e33d8cdb balrog
109 e33d8cdb balrog
    return 0;
110 e33d8cdb balrog
}
111 e33d8cdb balrog
112 e33d8cdb balrog
static void scoop_writeb(void *opaque, target_phys_addr_t addr, uint32_t value)
113 e33d8cdb balrog
{
114 e33d8cdb balrog
    struct scoop_info_s *s = (struct scoop_info_s *) opaque;
115 e33d8cdb balrog
    addr -= s->target_base;
116 e33d8cdb balrog
    value &= 0xffff;
117 e33d8cdb balrog
118 e33d8cdb balrog
    switch (addr) {
119 e33d8cdb balrog
    case SCOOP_MCR:
120 e33d8cdb balrog
        s->mcr = value;
121 e33d8cdb balrog
        break;
122 e33d8cdb balrog
    case SCOOP_CDR:
123 e33d8cdb balrog
        s->cdr = value;
124 e33d8cdb balrog
        break;
125 e33d8cdb balrog
    case SCOOP_CPR:
126 e33d8cdb balrog
        s->power = value;
127 e33d8cdb balrog
        if (value & 0x80)
128 e33d8cdb balrog
            s->power |= 0x8040;
129 e33d8cdb balrog
        break;
130 e33d8cdb balrog
    case SCOOP_CCR:
131 e33d8cdb balrog
        s->ccr = value;
132 e33d8cdb balrog
        break;
133 e33d8cdb balrog
    case SCOOP_IRR_IRM:
134 e33d8cdb balrog
        s->irr = value;
135 e33d8cdb balrog
        break;
136 e33d8cdb balrog
    case SCOOP_IMR:
137 e33d8cdb balrog
        s->imr = value;
138 e33d8cdb balrog
        break;
139 e33d8cdb balrog
    case SCOOP_ISR:
140 e33d8cdb balrog
        s->isr = value;
141 e33d8cdb balrog
        break;
142 e33d8cdb balrog
    case SCOOP_GPCR:
143 e33d8cdb balrog
        s->gpio_dir = value;
144 e33d8cdb balrog
        scoop_gpio_handler_update(s);
145 e33d8cdb balrog
        break;
146 e33d8cdb balrog
    case SCOOP_GPWR:
147 e33d8cdb balrog
        s->gpio_level = value & s->gpio_dir;
148 e33d8cdb balrog
        scoop_gpio_handler_update(s);
149 e33d8cdb balrog
        break;
150 e33d8cdb balrog
    case SCOOP_GPRR:
151 e33d8cdb balrog
        s->gprr = value;
152 e33d8cdb balrog
        break;
153 e33d8cdb balrog
    default:
154 e33d8cdb balrog
        zaurus_printf("Bad register offset " REG_FMT "\n", addr);
155 e33d8cdb balrog
    }
156 e33d8cdb balrog
}
157 e33d8cdb balrog
158 e33d8cdb balrog
CPUReadMemoryFunc *scoop_readfn[] = {
159 e33d8cdb balrog
    scoop_readb,
160 e33d8cdb balrog
    scoop_readb,
161 e33d8cdb balrog
    scoop_readb,
162 e33d8cdb balrog
};
163 e33d8cdb balrog
CPUWriteMemoryFunc *scoop_writefn[] = {
164 e33d8cdb balrog
    scoop_writeb,
165 e33d8cdb balrog
    scoop_writeb,
166 e33d8cdb balrog
    scoop_writeb,
167 e33d8cdb balrog
};
168 e33d8cdb balrog
169 e33d8cdb balrog
void scoop_gpio_set(void *opaque, int line, int level)
170 e33d8cdb balrog
{
171 e33d8cdb balrog
    struct scoop_info_s *s = (struct scoop_info_s *) s;
172 e33d8cdb balrog
173 e33d8cdb balrog
    if (level)
174 e33d8cdb balrog
        s->gpio_level |= (1 << line);
175 e33d8cdb balrog
    else
176 e33d8cdb balrog
        s->gpio_level &= ~(1 << line);
177 e33d8cdb balrog
}
178 e33d8cdb balrog
179 e33d8cdb balrog
qemu_irq *scoop_gpio_in_get(struct scoop_info_s *s)
180 e33d8cdb balrog
{
181 e33d8cdb balrog
    return s->in;
182 e33d8cdb balrog
}
183 e33d8cdb balrog
184 e33d8cdb balrog
void scoop_gpio_out_set(struct scoop_info_s *s, int line,
185 e33d8cdb balrog
                qemu_irq handler) {
186 e33d8cdb balrog
    if (line >= 16) {
187 e33d8cdb balrog
        fprintf(stderr, "No GPIO pin %i\n", line);
188 e33d8cdb balrog
        exit(-1);
189 e33d8cdb balrog
    }
190 e33d8cdb balrog
191 e33d8cdb balrog
    s->handler[line] = handler;
192 e33d8cdb balrog
}
193 e33d8cdb balrog
194 e33d8cdb balrog
static void scoop_save(QEMUFile *f, void *opaque)
195 e33d8cdb balrog
{
196 e33d8cdb balrog
    struct scoop_info_s *s = (struct scoop_info_s *) opaque;
197 e33d8cdb balrog
    qemu_put_be16s(f, &s->status);
198 e33d8cdb balrog
    qemu_put_be16s(f, &s->power);
199 e33d8cdb balrog
    qemu_put_be32s(f, &s->gpio_level);
200 e33d8cdb balrog
    qemu_put_be32s(f, &s->gpio_dir);
201 e33d8cdb balrog
    qemu_put_be32s(f, &s->prev_level);
202 e33d8cdb balrog
    qemu_put_be16s(f, &s->mcr);
203 e33d8cdb balrog
    qemu_put_be16s(f, &s->cdr);
204 e33d8cdb balrog
    qemu_put_be16s(f, &s->ccr);
205 e33d8cdb balrog
    qemu_put_be16s(f, &s->irr);
206 e33d8cdb balrog
    qemu_put_be16s(f, &s->imr);
207 e33d8cdb balrog
    qemu_put_be16s(f, &s->isr);
208 e33d8cdb balrog
    qemu_put_be16s(f, &s->gprr);
209 e33d8cdb balrog
}
210 e33d8cdb balrog
211 e33d8cdb balrog
static int scoop_load(QEMUFile *f, void *opaque, int version_id)
212 e33d8cdb balrog
{
213 e33d8cdb balrog
    struct scoop_info_s *s = (struct scoop_info_s *) opaque;
214 e33d8cdb balrog
    qemu_get_be16s(f, &s->status);
215 e33d8cdb balrog
    qemu_get_be16s(f, &s->power);
216 e33d8cdb balrog
    qemu_get_be32s(f, &s->gpio_level);
217 e33d8cdb balrog
    qemu_get_be32s(f, &s->gpio_dir);
218 e33d8cdb balrog
    qemu_get_be32s(f, &s->prev_level);
219 e33d8cdb balrog
    qemu_get_be16s(f, &s->mcr);
220 e33d8cdb balrog
    qemu_get_be16s(f, &s->cdr);
221 e33d8cdb balrog
    qemu_get_be16s(f, &s->ccr);
222 e33d8cdb balrog
    qemu_get_be16s(f, &s->irr);
223 e33d8cdb balrog
    qemu_get_be16s(f, &s->imr);
224 e33d8cdb balrog
    qemu_get_be16s(f, &s->isr);
225 e33d8cdb balrog
    qemu_get_be16s(f, &s->gprr);
226 e33d8cdb balrog
227 e33d8cdb balrog
    return 0;
228 e33d8cdb balrog
}
229 e33d8cdb balrog
230 e33d8cdb balrog
struct scoop_info_s *scoop_init(struct pxa2xx_state_s *cpu,
231 e33d8cdb balrog
                int instance,
232 e33d8cdb balrog
                target_phys_addr_t target_base) {
233 e33d8cdb balrog
    int iomemtype;
234 e33d8cdb balrog
    struct scoop_info_s *s;
235 e33d8cdb balrog
236 e33d8cdb balrog
    s = (struct scoop_info_s *)
237 e33d8cdb balrog
            qemu_mallocz(sizeof(struct scoop_info_s));
238 e33d8cdb balrog
    memset(s, 0, sizeof(struct scoop_info_s));
239 e33d8cdb balrog
240 e33d8cdb balrog
    s->target_base = target_base;
241 e33d8cdb balrog
    s->status = 0x02;
242 e33d8cdb balrog
    s->in = qemu_allocate_irqs(scoop_gpio_set, s, 16);
243 e33d8cdb balrog
    iomemtype = cpu_register_io_memory(0, scoop_readfn,
244 e33d8cdb balrog
                    scoop_writefn, s);
245 e33d8cdb balrog
    cpu_register_physical_memory(s->target_base, 0x1000, iomemtype);
246 e33d8cdb balrog
    register_savevm("scoop", instance, 0, scoop_save, scoop_load, s);
247 e33d8cdb balrog
248 e33d8cdb balrog
    return s;
249 e33d8cdb balrog
}
250 e33d8cdb balrog
251 e33d8cdb balrog
/* Write the bootloader parameters memory area.  */
252 e33d8cdb balrog
253 e33d8cdb balrog
#define MAGIC_CHG(a, b, c, d)        ((d << 24) | (c << 16) | (b << 8) | a)
254 e33d8cdb balrog
255 e33d8cdb balrog
struct __attribute__ ((__packed__)) sl_param_info {
256 e33d8cdb balrog
    uint32_t comadj_keyword;
257 e33d8cdb balrog
    int32_t comadj;
258 e33d8cdb balrog
259 e33d8cdb balrog
    uint32_t uuid_keyword;
260 e33d8cdb balrog
    char uuid[16];
261 e33d8cdb balrog
262 e33d8cdb balrog
    uint32_t touch_keyword;
263 e33d8cdb balrog
    int32_t touch_xp;
264 e33d8cdb balrog
    int32_t touch_yp;
265 e33d8cdb balrog
    int32_t touch_xd;
266 e33d8cdb balrog
    int32_t touch_yd;
267 e33d8cdb balrog
268 e33d8cdb balrog
    uint32_t adadj_keyword;
269 e33d8cdb balrog
    int32_t adadj;
270 e33d8cdb balrog
271 e33d8cdb balrog
    uint32_t phad_keyword;
272 e33d8cdb balrog
    int32_t phadadj;
273 e33d8cdb balrog
} zaurus_bootparam = {
274 e33d8cdb balrog
    .comadj_keyword        = MAGIC_CHG('C', 'M', 'A', 'D'),
275 e33d8cdb balrog
    .comadj                = 125,
276 e33d8cdb balrog
    .uuid_keyword        = MAGIC_CHG('U', 'U', 'I', 'D'),
277 e33d8cdb balrog
    .uuid                = { -1 },
278 e33d8cdb balrog
    .touch_keyword        = MAGIC_CHG('T', 'U', 'C', 'H'),
279 e33d8cdb balrog
    .touch_xp                = -1,
280 e33d8cdb balrog
    .adadj_keyword        = MAGIC_CHG('B', 'V', 'A', 'D'),
281 e33d8cdb balrog
    .adadj                = -1,
282 e33d8cdb balrog
    .phad_keyword        = MAGIC_CHG('P', 'H', 'A', 'D'),
283 e33d8cdb balrog
    .phadadj                = 0x01,
284 e33d8cdb balrog
};
285 e33d8cdb balrog
286 e33d8cdb balrog
void sl_bootparam_write(uint32_t ptr)
287 e33d8cdb balrog
{
288 e33d8cdb balrog
    memcpy(phys_ram_base + ptr, &zaurus_bootparam,
289 e33d8cdb balrog
                    sizeof(struct sl_param_info));
290 e33d8cdb balrog
}