xref: /qemu/hw/arm/fsl-imx25.c (revision ce189ab230bd3472ada876bf7568221342ee6dbb)
1ee708c99SJean-Christophe Dubois /*
2ee708c99SJean-Christophe Dubois  * Copyright (c) 2013 Jean-Christophe Dubois <jcd@tribudubois.net>
3ee708c99SJean-Christophe Dubois  *
4ee708c99SJean-Christophe Dubois  * i.MX25 SOC emulation.
5ee708c99SJean-Christophe Dubois  *
6ee708c99SJean-Christophe Dubois  * Based on hw/arm/xlnx-zynqmp.c
7ee708c99SJean-Christophe Dubois  *
8ee708c99SJean-Christophe Dubois  * Copyright (C) 2015 Xilinx Inc
9ee708c99SJean-Christophe Dubois  * Written by Peter Crosthwaite <peter.crosthwaite@xilinx.com>
10ee708c99SJean-Christophe Dubois  *
11ee708c99SJean-Christophe Dubois  *  This program is free software; you can redistribute it and/or modify it
12ee708c99SJean-Christophe Dubois  *  under the terms of the GNU General Public License as published by the
13ee708c99SJean-Christophe Dubois  *  Free Software Foundation; either version 2 of the License, or
14ee708c99SJean-Christophe Dubois  *  (at your option) any later version.
15ee708c99SJean-Christophe Dubois  *
16ee708c99SJean-Christophe Dubois  *  This program is distributed in the hope that it will be useful, but WITHOUT
17ee708c99SJean-Christophe Dubois  *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18ee708c99SJean-Christophe Dubois  *  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19ee708c99SJean-Christophe Dubois  *  for more details.
20ee708c99SJean-Christophe Dubois  *
21ee708c99SJean-Christophe Dubois  *  You should have received a copy of the GNU General Public License along
22ee708c99SJean-Christophe Dubois  *  with this program; if not, see <http://www.gnu.org/licenses/>.
23ee708c99SJean-Christophe Dubois  */
24ee708c99SJean-Christophe Dubois 
2512b16722SPeter Maydell #include "qemu/osdep.h"
26da34e65cSMarkus Armbruster #include "qapi/error.h"
274771d756SPaolo Bonzini #include "cpu.h"
28ee708c99SJean-Christophe Dubois #include "hw/arm/fsl-imx25.h"
29ee708c99SJean-Christophe Dubois #include "sysemu/sysemu.h"
30ee708c99SJean-Christophe Dubois #include "exec/address-spaces.h"
31a27bd6c7SMarkus Armbruster #include "hw/qdev-properties.h"
328228e353SMarc-André Lureau #include "chardev/char.h"
33ee708c99SJean-Christophe Dubois 
34bfae1772SGuenter Roeck #define IMX25_ESDHC_CAPABILITIES     0x07e20000
35bfae1772SGuenter Roeck 
36ee708c99SJean-Christophe Dubois static void fsl_imx25_init(Object *obj)
37ee708c99SJean-Christophe Dubois {
38ee708c99SJean-Christophe Dubois     FslIMX25State *s = FSL_IMX25(obj);
39ee708c99SJean-Christophe Dubois     int i;
40ee708c99SJean-Christophe Dubois 
419fc7fc4dSMarkus Armbruster     object_initialize_child(obj, "cpu", &s->cpu, ARM_CPU_TYPE_NAME("arm926"));
42ee708c99SJean-Christophe Dubois 
43db873cc5SMarkus Armbruster     object_initialize_child(obj, "avic", &s->avic, TYPE_IMX_AVIC);
44ee708c99SJean-Christophe Dubois 
45db873cc5SMarkus Armbruster     object_initialize_child(obj, "ccm", &s->ccm, TYPE_IMX25_CCM);
46ee708c99SJean-Christophe Dubois 
47ee708c99SJean-Christophe Dubois     for (i = 0; i < FSL_IMX25_NUM_UARTS; i++) {
48db873cc5SMarkus Armbruster         object_initialize_child(obj, "uart[*]", &s->uart[i], TYPE_IMX_SERIAL);
49ee708c99SJean-Christophe Dubois     }
50ee708c99SJean-Christophe Dubois 
51ee708c99SJean-Christophe Dubois     for (i = 0; i < FSL_IMX25_NUM_GPTS; i++) {
52db873cc5SMarkus Armbruster         object_initialize_child(obj, "gpt[*]", &s->gpt[i], TYPE_IMX25_GPT);
53ee708c99SJean-Christophe Dubois     }
54ee708c99SJean-Christophe Dubois 
55ee708c99SJean-Christophe Dubois     for (i = 0; i < FSL_IMX25_NUM_EPITS; i++) {
56db873cc5SMarkus Armbruster         object_initialize_child(obj, "epit[*]", &s->epit[i], TYPE_IMX_EPIT);
57ee708c99SJean-Christophe Dubois     }
58ee708c99SJean-Christophe Dubois 
59db873cc5SMarkus Armbruster     object_initialize_child(obj, "fec", &s->fec, TYPE_IMX_FEC);
60ee708c99SJean-Christophe Dubois 
61db873cc5SMarkus Armbruster     object_initialize_child(obj, "rngc", &s->rngc, TYPE_IMX_RNGC);
62f0396549SMartin Kaiser 
63ee708c99SJean-Christophe Dubois     for (i = 0; i < FSL_IMX25_NUM_I2CS; i++) {
64db873cc5SMarkus Armbruster         object_initialize_child(obj, "i2c[*]", &s->i2c[i], TYPE_IMX_I2C);
65ee708c99SJean-Christophe Dubois     }
666abc7158SJean-Christophe Dubois 
676abc7158SJean-Christophe Dubois     for (i = 0; i < FSL_IMX25_NUM_GPIOS; i++) {
68db873cc5SMarkus Armbruster         object_initialize_child(obj, "gpio[*]", &s->gpio[i], TYPE_IMX_GPIO);
696abc7158SJean-Christophe Dubois     }
70bfae1772SGuenter Roeck 
71bfae1772SGuenter Roeck     for (i = 0; i < FSL_IMX25_NUM_ESDHCS; i++) {
72db873cc5SMarkus Armbruster         object_initialize_child(obj, "sdhc[*]", &s->esdhc[i], TYPE_IMX_USDHC);
73bfae1772SGuenter Roeck     }
7467f52ebeSGuenter Roeck 
7567f52ebeSGuenter Roeck     for (i = 0; i < FSL_IMX25_NUM_USBS; i++) {
76db873cc5SMarkus Armbruster         object_initialize_child(obj, "usb[*]", &s->usb[i], TYPE_CHIPIDEA);
7767f52ebeSGuenter Roeck     }
7867f52ebeSGuenter Roeck 
79db873cc5SMarkus Armbruster     object_initialize_child(obj, "wdt", &s->wdt, TYPE_IMX2_WDT);
80ee708c99SJean-Christophe Dubois }
81ee708c99SJean-Christophe Dubois 
82ee708c99SJean-Christophe Dubois static void fsl_imx25_realize(DeviceState *dev, Error **errp)
83ee708c99SJean-Christophe Dubois {
84ee708c99SJean-Christophe Dubois     FslIMX25State *s = FSL_IMX25(dev);
85ee708c99SJean-Christophe Dubois     uint8_t i;
86ee708c99SJean-Christophe Dubois     Error *err = NULL;
87ee708c99SJean-Christophe Dubois 
88*ce189ab2SMarkus Armbruster     qdev_realize(DEVICE(&s->cpu), NULL, &err);
89ee708c99SJean-Christophe Dubois     if (err) {
90ee708c99SJean-Christophe Dubois         error_propagate(errp, err);
91ee708c99SJean-Christophe Dubois         return;
92ee708c99SJean-Christophe Dubois     }
93ee708c99SJean-Christophe Dubois 
94db873cc5SMarkus Armbruster     sysbus_realize(SYS_BUS_DEVICE(&s->avic), &err);
95ee708c99SJean-Christophe Dubois     if (err) {
96ee708c99SJean-Christophe Dubois         error_propagate(errp, err);
97ee708c99SJean-Christophe Dubois         return;
98ee708c99SJean-Christophe Dubois     }
99ee708c99SJean-Christophe Dubois     sysbus_mmio_map(SYS_BUS_DEVICE(&s->avic), 0, FSL_IMX25_AVIC_ADDR);
100ee708c99SJean-Christophe Dubois     sysbus_connect_irq(SYS_BUS_DEVICE(&s->avic), 0,
101ee708c99SJean-Christophe Dubois                        qdev_get_gpio_in(DEVICE(&s->cpu), ARM_CPU_IRQ));
102ee708c99SJean-Christophe Dubois     sysbus_connect_irq(SYS_BUS_DEVICE(&s->avic), 1,
103ee708c99SJean-Christophe Dubois                        qdev_get_gpio_in(DEVICE(&s->cpu), ARM_CPU_FIQ));
104ee708c99SJean-Christophe Dubois 
105db873cc5SMarkus Armbruster     sysbus_realize(SYS_BUS_DEVICE(&s->ccm), &err);
106ee708c99SJean-Christophe Dubois     if (err) {
107ee708c99SJean-Christophe Dubois         error_propagate(errp, err);
108ee708c99SJean-Christophe Dubois         return;
109ee708c99SJean-Christophe Dubois     }
110ee708c99SJean-Christophe Dubois     sysbus_mmio_map(SYS_BUS_DEVICE(&s->ccm), 0, FSL_IMX25_CCM_ADDR);
111ee708c99SJean-Christophe Dubois 
112ee708c99SJean-Christophe Dubois     /* Initialize all UARTs */
113ee708c99SJean-Christophe Dubois     for (i = 0; i < FSL_IMX25_NUM_UARTS; i++) {
114ee708c99SJean-Christophe Dubois         static const struct {
115ee708c99SJean-Christophe Dubois             hwaddr addr;
116ee708c99SJean-Christophe Dubois             unsigned int irq;
117ee708c99SJean-Christophe Dubois         } serial_table[FSL_IMX25_NUM_UARTS] = {
118ee708c99SJean-Christophe Dubois             { FSL_IMX25_UART1_ADDR, FSL_IMX25_UART1_IRQ },
119ee708c99SJean-Christophe Dubois             { FSL_IMX25_UART2_ADDR, FSL_IMX25_UART2_IRQ },
120ee708c99SJean-Christophe Dubois             { FSL_IMX25_UART3_ADDR, FSL_IMX25_UART3_IRQ },
121ee708c99SJean-Christophe Dubois             { FSL_IMX25_UART4_ADDR, FSL_IMX25_UART4_IRQ },
122ee708c99SJean-Christophe Dubois             { FSL_IMX25_UART5_ADDR, FSL_IMX25_UART5_IRQ }
123ee708c99SJean-Christophe Dubois         };
124ee708c99SJean-Christophe Dubois 
1259bca0edbSPeter Maydell         qdev_prop_set_chr(DEVICE(&s->uart[i]), "chardev", serial_hd(i));
126ee708c99SJean-Christophe Dubois 
127db873cc5SMarkus Armbruster         sysbus_realize(SYS_BUS_DEVICE(&s->uart[i]), &err);
128ee708c99SJean-Christophe Dubois         if (err) {
129ee708c99SJean-Christophe Dubois             error_propagate(errp, err);
130ee708c99SJean-Christophe Dubois             return;
131ee708c99SJean-Christophe Dubois         }
132ee708c99SJean-Christophe Dubois         sysbus_mmio_map(SYS_BUS_DEVICE(&s->uart[i]), 0, serial_table[i].addr);
133ee708c99SJean-Christophe Dubois         sysbus_connect_irq(SYS_BUS_DEVICE(&s->uart[i]), 0,
134ee708c99SJean-Christophe Dubois                            qdev_get_gpio_in(DEVICE(&s->avic),
135ee708c99SJean-Christophe Dubois                                             serial_table[i].irq));
136ee708c99SJean-Christophe Dubois     }
137ee708c99SJean-Christophe Dubois 
138ee708c99SJean-Christophe Dubois     /* Initialize all GPT timers */
139ee708c99SJean-Christophe Dubois     for (i = 0; i < FSL_IMX25_NUM_GPTS; i++) {
140ee708c99SJean-Christophe Dubois         static const struct {
141ee708c99SJean-Christophe Dubois             hwaddr addr;
142ee708c99SJean-Christophe Dubois             unsigned int irq;
143ee708c99SJean-Christophe Dubois         } gpt_table[FSL_IMX25_NUM_GPTS] = {
144ee708c99SJean-Christophe Dubois             { FSL_IMX25_GPT1_ADDR, FSL_IMX25_GPT1_IRQ },
145ee708c99SJean-Christophe Dubois             { FSL_IMX25_GPT2_ADDR, FSL_IMX25_GPT2_IRQ },
146ee708c99SJean-Christophe Dubois             { FSL_IMX25_GPT3_ADDR, FSL_IMX25_GPT3_IRQ },
147ee708c99SJean-Christophe Dubois             { FSL_IMX25_GPT4_ADDR, FSL_IMX25_GPT4_IRQ }
148ee708c99SJean-Christophe Dubois         };
149ee708c99SJean-Christophe Dubois 
150cb54d868SJean-Christophe Dubois         s->gpt[i].ccm = IMX_CCM(&s->ccm);
151ee708c99SJean-Christophe Dubois 
152db873cc5SMarkus Armbruster         sysbus_realize(SYS_BUS_DEVICE(&s->gpt[i]), &err);
153ee708c99SJean-Christophe Dubois         if (err) {
154ee708c99SJean-Christophe Dubois             error_propagate(errp, err);
155ee708c99SJean-Christophe Dubois             return;
156ee708c99SJean-Christophe Dubois         }
157ee708c99SJean-Christophe Dubois         sysbus_mmio_map(SYS_BUS_DEVICE(&s->gpt[i]), 0, gpt_table[i].addr);
158ee708c99SJean-Christophe Dubois         sysbus_connect_irq(SYS_BUS_DEVICE(&s->gpt[i]), 0,
159ee708c99SJean-Christophe Dubois                            qdev_get_gpio_in(DEVICE(&s->avic),
160ee708c99SJean-Christophe Dubois                                             gpt_table[i].irq));
161ee708c99SJean-Christophe Dubois     }
162ee708c99SJean-Christophe Dubois 
163ee708c99SJean-Christophe Dubois     /* Initialize all EPIT timers */
164ee708c99SJean-Christophe Dubois     for (i = 0; i < FSL_IMX25_NUM_EPITS; i++) {
165ee708c99SJean-Christophe Dubois         static const struct {
166ee708c99SJean-Christophe Dubois             hwaddr addr;
167ee708c99SJean-Christophe Dubois             unsigned int irq;
168ee708c99SJean-Christophe Dubois         } epit_table[FSL_IMX25_NUM_EPITS] = {
169ee708c99SJean-Christophe Dubois             { FSL_IMX25_EPIT1_ADDR, FSL_IMX25_EPIT1_IRQ },
170ee708c99SJean-Christophe Dubois             { FSL_IMX25_EPIT2_ADDR, FSL_IMX25_EPIT2_IRQ }
171ee708c99SJean-Christophe Dubois         };
172ee708c99SJean-Christophe Dubois 
173cb54d868SJean-Christophe Dubois         s->epit[i].ccm = IMX_CCM(&s->ccm);
174ee708c99SJean-Christophe Dubois 
175db873cc5SMarkus Armbruster         sysbus_realize(SYS_BUS_DEVICE(&s->epit[i]), &err);
176ee708c99SJean-Christophe Dubois         if (err) {
177ee708c99SJean-Christophe Dubois             error_propagate(errp, err);
178ee708c99SJean-Christophe Dubois             return;
179ee708c99SJean-Christophe Dubois         }
180ee708c99SJean-Christophe Dubois         sysbus_mmio_map(SYS_BUS_DEVICE(&s->epit[i]), 0, epit_table[i].addr);
181ee708c99SJean-Christophe Dubois         sysbus_connect_irq(SYS_BUS_DEVICE(&s->epit[i]), 0,
182ee708c99SJean-Christophe Dubois                            qdev_get_gpio_in(DEVICE(&s->avic),
183ee708c99SJean-Christophe Dubois                                             epit_table[i].irq));
184ee708c99SJean-Christophe Dubois     }
185ee708c99SJean-Christophe Dubois 
186ee708c99SJean-Christophe Dubois     qdev_set_nic_properties(DEVICE(&s->fec), &nd_table[0]);
187a699b410SJean-Christophe Dubois 
188db873cc5SMarkus Armbruster     sysbus_realize(SYS_BUS_DEVICE(&s->fec), &err);
189ee708c99SJean-Christophe Dubois     if (err) {
190ee708c99SJean-Christophe Dubois         error_propagate(errp, err);
191ee708c99SJean-Christophe Dubois         return;
192ee708c99SJean-Christophe Dubois     }
193ee708c99SJean-Christophe Dubois     sysbus_mmio_map(SYS_BUS_DEVICE(&s->fec), 0, FSL_IMX25_FEC_ADDR);
194ee708c99SJean-Christophe Dubois     sysbus_connect_irq(SYS_BUS_DEVICE(&s->fec), 0,
195ee708c99SJean-Christophe Dubois                        qdev_get_gpio_in(DEVICE(&s->avic), FSL_IMX25_FEC_IRQ));
196ee708c99SJean-Christophe Dubois 
197db873cc5SMarkus Armbruster     sysbus_realize(SYS_BUS_DEVICE(&s->rngc), &err);
198f0396549SMartin Kaiser     if (err) {
199f0396549SMartin Kaiser         error_propagate(errp, err);
200f0396549SMartin Kaiser         return;
201f0396549SMartin Kaiser     }
202f0396549SMartin Kaiser     sysbus_mmio_map(SYS_BUS_DEVICE(&s->rngc), 0, FSL_IMX25_RNGC_ADDR);
203f0396549SMartin Kaiser     sysbus_connect_irq(SYS_BUS_DEVICE(&s->rngc), 0,
204f0396549SMartin Kaiser                        qdev_get_gpio_in(DEVICE(&s->avic), FSL_IMX25_RNGC_IRQ));
205ee708c99SJean-Christophe Dubois 
206ee708c99SJean-Christophe Dubois     /* Initialize all I2C */
207ee708c99SJean-Christophe Dubois     for (i = 0; i < FSL_IMX25_NUM_I2CS; i++) {
208ee708c99SJean-Christophe Dubois         static const struct {
209ee708c99SJean-Christophe Dubois             hwaddr addr;
210ee708c99SJean-Christophe Dubois             unsigned int irq;
211ee708c99SJean-Christophe Dubois         } i2c_table[FSL_IMX25_NUM_I2CS] = {
212ee708c99SJean-Christophe Dubois             { FSL_IMX25_I2C1_ADDR, FSL_IMX25_I2C1_IRQ },
213ee708c99SJean-Christophe Dubois             { FSL_IMX25_I2C2_ADDR, FSL_IMX25_I2C2_IRQ },
214ee708c99SJean-Christophe Dubois             { FSL_IMX25_I2C3_ADDR, FSL_IMX25_I2C3_IRQ }
215ee708c99SJean-Christophe Dubois         };
216ee708c99SJean-Christophe Dubois 
217db873cc5SMarkus Armbruster         sysbus_realize(SYS_BUS_DEVICE(&s->i2c[i]), &err);
218ee708c99SJean-Christophe Dubois         if (err) {
219ee708c99SJean-Christophe Dubois             error_propagate(errp, err);
220ee708c99SJean-Christophe Dubois             return;
221ee708c99SJean-Christophe Dubois         }
222ee708c99SJean-Christophe Dubois         sysbus_mmio_map(SYS_BUS_DEVICE(&s->i2c[i]), 0, i2c_table[i].addr);
223ee708c99SJean-Christophe Dubois         sysbus_connect_irq(SYS_BUS_DEVICE(&s->i2c[i]), 0,
224ee708c99SJean-Christophe Dubois                            qdev_get_gpio_in(DEVICE(&s->avic),
225ee708c99SJean-Christophe Dubois                                             i2c_table[i].irq));
226ee708c99SJean-Christophe Dubois     }
227ee708c99SJean-Christophe Dubois 
2286abc7158SJean-Christophe Dubois     /* Initialize all GPIOs */
2296abc7158SJean-Christophe Dubois     for (i = 0; i < FSL_IMX25_NUM_GPIOS; i++) {
2306abc7158SJean-Christophe Dubois         static const struct {
2316abc7158SJean-Christophe Dubois             hwaddr addr;
2326abc7158SJean-Christophe Dubois             unsigned int irq;
2336abc7158SJean-Christophe Dubois         } gpio_table[FSL_IMX25_NUM_GPIOS] = {
2346abc7158SJean-Christophe Dubois             { FSL_IMX25_GPIO1_ADDR, FSL_IMX25_GPIO1_IRQ },
2356abc7158SJean-Christophe Dubois             { FSL_IMX25_GPIO2_ADDR, FSL_IMX25_GPIO2_IRQ },
2366abc7158SJean-Christophe Dubois             { FSL_IMX25_GPIO3_ADDR, FSL_IMX25_GPIO3_IRQ },
2376abc7158SJean-Christophe Dubois             { FSL_IMX25_GPIO4_ADDR, FSL_IMX25_GPIO4_IRQ }
2386abc7158SJean-Christophe Dubois         };
2396abc7158SJean-Christophe Dubois 
240db873cc5SMarkus Armbruster         sysbus_realize(SYS_BUS_DEVICE(&s->gpio[i]), &err);
2416abc7158SJean-Christophe Dubois         if (err) {
2426abc7158SJean-Christophe Dubois             error_propagate(errp, err);
2436abc7158SJean-Christophe Dubois             return;
2446abc7158SJean-Christophe Dubois         }
2456abc7158SJean-Christophe Dubois         sysbus_mmio_map(SYS_BUS_DEVICE(&s->gpio[i]), 0, gpio_table[i].addr);
2466abc7158SJean-Christophe Dubois         /* Connect GPIO IRQ to PIC */
2476abc7158SJean-Christophe Dubois         sysbus_connect_irq(SYS_BUS_DEVICE(&s->gpio[i]), 0,
2486abc7158SJean-Christophe Dubois                            qdev_get_gpio_in(DEVICE(&s->avic),
2496abc7158SJean-Christophe Dubois                                             gpio_table[i].irq));
2506abc7158SJean-Christophe Dubois     }
2516abc7158SJean-Christophe Dubois 
252bfae1772SGuenter Roeck     /* Initialize all SDHC */
253bfae1772SGuenter Roeck     for (i = 0; i < FSL_IMX25_NUM_ESDHCS; i++) {
254bfae1772SGuenter Roeck         static const struct {
255bfae1772SGuenter Roeck             hwaddr addr;
256bfae1772SGuenter Roeck             unsigned int irq;
257bfae1772SGuenter Roeck         } esdhc_table[FSL_IMX25_NUM_ESDHCS] = {
258bfae1772SGuenter Roeck             { FSL_IMX25_ESDHC1_ADDR, FSL_IMX25_ESDHC1_IRQ },
259bfae1772SGuenter Roeck             { FSL_IMX25_ESDHC2_ADDR, FSL_IMX25_ESDHC2_IRQ },
260bfae1772SGuenter Roeck         };
261bfae1772SGuenter Roeck 
262bfae1772SGuenter Roeck         object_property_set_uint(OBJECT(&s->esdhc[i]), 2, "sd-spec-version",
263bfae1772SGuenter Roeck                                  &err);
264bfae1772SGuenter Roeck         object_property_set_uint(OBJECT(&s->esdhc[i]), IMX25_ESDHC_CAPABILITIES,
265bfae1772SGuenter Roeck                                  "capareg", &err);
266db873cc5SMarkus Armbruster         sysbus_realize(SYS_BUS_DEVICE(&s->esdhc[i]), &err);
267bfae1772SGuenter Roeck         if (err) {
268bfae1772SGuenter Roeck             error_propagate(errp, err);
269bfae1772SGuenter Roeck             return;
270bfae1772SGuenter Roeck         }
271bfae1772SGuenter Roeck         sysbus_mmio_map(SYS_BUS_DEVICE(&s->esdhc[i]), 0, esdhc_table[i].addr);
272bfae1772SGuenter Roeck         sysbus_connect_irq(SYS_BUS_DEVICE(&s->esdhc[i]), 0,
273bfae1772SGuenter Roeck                            qdev_get_gpio_in(DEVICE(&s->avic),
274bfae1772SGuenter Roeck                                             esdhc_table[i].irq));
275bfae1772SGuenter Roeck     }
276bfae1772SGuenter Roeck 
27767f52ebeSGuenter Roeck     /* USB */
27867f52ebeSGuenter Roeck     for (i = 0; i < FSL_IMX25_NUM_USBS; i++) {
27967f52ebeSGuenter Roeck         static const struct {
28067f52ebeSGuenter Roeck             hwaddr addr;
28167f52ebeSGuenter Roeck             unsigned int irq;
28267f52ebeSGuenter Roeck         } usb_table[FSL_IMX25_NUM_USBS] = {
28367f52ebeSGuenter Roeck             { FSL_IMX25_USB1_ADDR, FSL_IMX25_USB1_IRQ },
28467f52ebeSGuenter Roeck             { FSL_IMX25_USB2_ADDR, FSL_IMX25_USB2_IRQ },
28567f52ebeSGuenter Roeck         };
28667f52ebeSGuenter Roeck 
287db873cc5SMarkus Armbruster         sysbus_realize(SYS_BUS_DEVICE(&s->usb[i]), &error_abort);
28867f52ebeSGuenter Roeck         sysbus_mmio_map(SYS_BUS_DEVICE(&s->usb[i]), 0, usb_table[i].addr);
28967f52ebeSGuenter Roeck         sysbus_connect_irq(SYS_BUS_DEVICE(&s->usb[i]), 0,
29067f52ebeSGuenter Roeck                            qdev_get_gpio_in(DEVICE(&s->avic),
29167f52ebeSGuenter Roeck                                             usb_table[i].irq));
29267f52ebeSGuenter Roeck     }
29367f52ebeSGuenter Roeck 
2944f0aff00SGuenter Roeck     /* Watchdog */
2954f0aff00SGuenter Roeck     object_property_set_bool(OBJECT(&s->wdt), true, "pretimeout-support",
2964f0aff00SGuenter Roeck                              &error_abort);
297db873cc5SMarkus Armbruster     sysbus_realize(SYS_BUS_DEVICE(&s->wdt), &error_abort);
2984f0aff00SGuenter Roeck     sysbus_mmio_map(SYS_BUS_DEVICE(&s->wdt), 0, FSL_IMX25_WDT_ADDR);
2994f0aff00SGuenter Roeck     sysbus_connect_irq(SYS_BUS_DEVICE(&s->wdt), 0,
3004f0aff00SGuenter Roeck                                       qdev_get_gpio_in(DEVICE(&s->avic),
3014f0aff00SGuenter Roeck                                                        FSL_IMX25_WDT_IRQ));
3024f0aff00SGuenter Roeck 
303ee708c99SJean-Christophe Dubois     /* initialize 2 x 16 KB ROM */
30432b9523aSPhilippe Mathieu-Daudé     memory_region_init_rom(&s->rom[0], OBJECT(dev), "imx25.rom0",
30532b9523aSPhilippe Mathieu-Daudé                            FSL_IMX25_ROM0_SIZE, &err);
306ee708c99SJean-Christophe Dubois     if (err) {
307ee708c99SJean-Christophe Dubois         error_propagate(errp, err);
308ee708c99SJean-Christophe Dubois         return;
309ee708c99SJean-Christophe Dubois     }
310ee708c99SJean-Christophe Dubois     memory_region_add_subregion(get_system_memory(), FSL_IMX25_ROM0_ADDR,
311ee708c99SJean-Christophe Dubois                                 &s->rom[0]);
31232b9523aSPhilippe Mathieu-Daudé     memory_region_init_rom(&s->rom[1], OBJECT(dev), "imx25.rom1",
31332b9523aSPhilippe Mathieu-Daudé                            FSL_IMX25_ROM1_SIZE, &err);
314ee708c99SJean-Christophe Dubois     if (err) {
315ee708c99SJean-Christophe Dubois         error_propagate(errp, err);
316ee708c99SJean-Christophe Dubois         return;
317ee708c99SJean-Christophe Dubois     }
318ee708c99SJean-Christophe Dubois     memory_region_add_subregion(get_system_memory(), FSL_IMX25_ROM1_ADDR,
319ee708c99SJean-Christophe Dubois                                 &s->rom[1]);
320ee708c99SJean-Christophe Dubois 
321ee708c99SJean-Christophe Dubois     /* initialize internal RAM (128 KB) */
32298a99ce0SPeter Maydell     memory_region_init_ram(&s->iram, NULL, "imx25.iram", FSL_IMX25_IRAM_SIZE,
323ee708c99SJean-Christophe Dubois                            &err);
324ee708c99SJean-Christophe Dubois     if (err) {
325ee708c99SJean-Christophe Dubois         error_propagate(errp, err);
326ee708c99SJean-Christophe Dubois         return;
327ee708c99SJean-Christophe Dubois     }
328ee708c99SJean-Christophe Dubois     memory_region_add_subregion(get_system_memory(), FSL_IMX25_IRAM_ADDR,
329ee708c99SJean-Christophe Dubois                                 &s->iram);
330ee708c99SJean-Christophe Dubois 
331ee708c99SJean-Christophe Dubois     /* internal RAM (128 KB) is aliased over 128 MB - 128 KB */
33232b9523aSPhilippe Mathieu-Daudé     memory_region_init_alias(&s->iram_alias, OBJECT(dev), "imx25.iram_alias",
333ee708c99SJean-Christophe Dubois                              &s->iram, 0, FSL_IMX25_IRAM_ALIAS_SIZE);
334ee708c99SJean-Christophe Dubois     memory_region_add_subregion(get_system_memory(), FSL_IMX25_IRAM_ALIAS_ADDR,
335ee708c99SJean-Christophe Dubois                                 &s->iram_alias);
336ee708c99SJean-Christophe Dubois }
337ee708c99SJean-Christophe Dubois 
338ee708c99SJean-Christophe Dubois static void fsl_imx25_class_init(ObjectClass *oc, void *data)
339ee708c99SJean-Christophe Dubois {
340ee708c99SJean-Christophe Dubois     DeviceClass *dc = DEVICE_CLASS(oc);
341ee708c99SJean-Christophe Dubois 
342ee708c99SJean-Christophe Dubois     dc->realize = fsl_imx25_realize;
343eccfa35eSJean-Christophe Dubois     dc->desc = "i.MX25 SOC";
3445e0c7044SThomas Huth     /*
3455e0c7044SThomas Huth      * Reason: uses serial_hds in realize and the imx25 board does not
3465e0c7044SThomas Huth      * support multiple CPUs
3475e0c7044SThomas Huth      */
3485e0c7044SThomas Huth     dc->user_creatable = false;
349ee708c99SJean-Christophe Dubois }
350ee708c99SJean-Christophe Dubois 
351ee708c99SJean-Christophe Dubois static const TypeInfo fsl_imx25_type_info = {
352ee708c99SJean-Christophe Dubois     .name = TYPE_FSL_IMX25,
353ee708c99SJean-Christophe Dubois     .parent = TYPE_DEVICE,
354ee708c99SJean-Christophe Dubois     .instance_size = sizeof(FslIMX25State),
355ee708c99SJean-Christophe Dubois     .instance_init = fsl_imx25_init,
356ee708c99SJean-Christophe Dubois     .class_init = fsl_imx25_class_init,
357ee708c99SJean-Christophe Dubois };
358ee708c99SJean-Christophe Dubois 
359ee708c99SJean-Christophe Dubois static void fsl_imx25_register_types(void)
360ee708c99SJean-Christophe Dubois {
361ee708c99SJean-Christophe Dubois     type_register_static(&fsl_imx25_type_info);
362ee708c99SJean-Christophe Dubois }
363ee708c99SJean-Christophe Dubois 
364ee708c99SJean-Christophe Dubois type_init(fsl_imx25_register_types)
365