xref: /qemu/hw/arm/fsl-imx25.c (revision 32b9523ad5b44dea87792d5d8f71a87e8cc5803b)
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 
41eaa9a878SPhilippe Mathieu-Daudé     object_initialize_child(obj, "cpu", &s->cpu, sizeof(s->cpu),
42eaa9a878SPhilippe Mathieu-Daudé                             ARM_CPU_TYPE_NAME("arm926"),
43eaa9a878SPhilippe Mathieu-Daudé                             &error_abort, NULL);
44ee708c99SJean-Christophe Dubois 
4551dd12acSThomas Huth     sysbus_init_child_obj(obj, "avic", &s->avic, sizeof(s->avic),
4651dd12acSThomas Huth                           TYPE_IMX_AVIC);
47ee708c99SJean-Christophe Dubois 
4851dd12acSThomas Huth     sysbus_init_child_obj(obj, "ccm", &s->ccm, sizeof(s->ccm), TYPE_IMX25_CCM);
49ee708c99SJean-Christophe Dubois 
50ee708c99SJean-Christophe Dubois     for (i = 0; i < FSL_IMX25_NUM_UARTS; i++) {
5151dd12acSThomas Huth         sysbus_init_child_obj(obj, "uart[*]", &s->uart[i], sizeof(s->uart[i]),
5251dd12acSThomas Huth                               TYPE_IMX_SERIAL);
53ee708c99SJean-Christophe Dubois     }
54ee708c99SJean-Christophe Dubois 
55ee708c99SJean-Christophe Dubois     for (i = 0; i < FSL_IMX25_NUM_GPTS; i++) {
5651dd12acSThomas Huth         sysbus_init_child_obj(obj, "gpt[*]", &s->gpt[i], sizeof(s->gpt[i]),
5751dd12acSThomas Huth                               TYPE_IMX25_GPT);
58ee708c99SJean-Christophe Dubois     }
59ee708c99SJean-Christophe Dubois 
60ee708c99SJean-Christophe Dubois     for (i = 0; i < FSL_IMX25_NUM_EPITS; i++) {
6151dd12acSThomas Huth         sysbus_init_child_obj(obj, "epit[*]", &s->epit[i], sizeof(s->epit[i]),
6251dd12acSThomas Huth                               TYPE_IMX_EPIT);
63ee708c99SJean-Christophe Dubois     }
64ee708c99SJean-Christophe Dubois 
6551dd12acSThomas Huth     sysbus_init_child_obj(obj, "fec", &s->fec, sizeof(s->fec), TYPE_IMX_FEC);
66ee708c99SJean-Christophe Dubois 
67f0396549SMartin Kaiser     sysbus_init_child_obj(obj, "rngc", &s->rngc, sizeof(s->rngc),
68f0396549SMartin Kaiser                           TYPE_IMX_RNGC);
69f0396549SMartin Kaiser 
70ee708c99SJean-Christophe Dubois     for (i = 0; i < FSL_IMX25_NUM_I2CS; i++) {
7151dd12acSThomas Huth         sysbus_init_child_obj(obj, "i2c[*]", &s->i2c[i], sizeof(s->i2c[i]),
7251dd12acSThomas Huth                               TYPE_IMX_I2C);
73ee708c99SJean-Christophe Dubois     }
746abc7158SJean-Christophe Dubois 
756abc7158SJean-Christophe Dubois     for (i = 0; i < FSL_IMX25_NUM_GPIOS; i++) {
7651dd12acSThomas Huth         sysbus_init_child_obj(obj, "gpio[*]", &s->gpio[i], sizeof(s->gpio[i]),
7751dd12acSThomas Huth                               TYPE_IMX_GPIO);
786abc7158SJean-Christophe Dubois     }
79bfae1772SGuenter Roeck 
80bfae1772SGuenter Roeck     for (i = 0; i < FSL_IMX25_NUM_ESDHCS; i++) {
81bfae1772SGuenter Roeck         sysbus_init_child_obj(obj, "sdhc[*]", &s->esdhc[i], sizeof(s->esdhc[i]),
82bfae1772SGuenter Roeck                               TYPE_IMX_USDHC);
83bfae1772SGuenter Roeck     }
8467f52ebeSGuenter Roeck 
8567f52ebeSGuenter Roeck     for (i = 0; i < FSL_IMX25_NUM_USBS; i++) {
8667f52ebeSGuenter Roeck         sysbus_init_child_obj(obj, "usb[*]", &s->usb[i], sizeof(s->usb[i]),
8767f52ebeSGuenter Roeck                               TYPE_CHIPIDEA);
8867f52ebeSGuenter Roeck     }
8967f52ebeSGuenter Roeck 
90ee708c99SJean-Christophe Dubois }
91ee708c99SJean-Christophe Dubois 
92ee708c99SJean-Christophe Dubois static void fsl_imx25_realize(DeviceState *dev, Error **errp)
93ee708c99SJean-Christophe Dubois {
94ee708c99SJean-Christophe Dubois     FslIMX25State *s = FSL_IMX25(dev);
95ee708c99SJean-Christophe Dubois     uint8_t i;
96ee708c99SJean-Christophe Dubois     Error *err = NULL;
97ee708c99SJean-Christophe Dubois 
98ee708c99SJean-Christophe Dubois     object_property_set_bool(OBJECT(&s->cpu), true, "realized", &err);
99ee708c99SJean-Christophe Dubois     if (err) {
100ee708c99SJean-Christophe Dubois         error_propagate(errp, err);
101ee708c99SJean-Christophe Dubois         return;
102ee708c99SJean-Christophe Dubois     }
103ee708c99SJean-Christophe Dubois 
104ee708c99SJean-Christophe Dubois     object_property_set_bool(OBJECT(&s->avic), true, "realized", &err);
105ee708c99SJean-Christophe Dubois     if (err) {
106ee708c99SJean-Christophe Dubois         error_propagate(errp, err);
107ee708c99SJean-Christophe Dubois         return;
108ee708c99SJean-Christophe Dubois     }
109ee708c99SJean-Christophe Dubois     sysbus_mmio_map(SYS_BUS_DEVICE(&s->avic), 0, FSL_IMX25_AVIC_ADDR);
110ee708c99SJean-Christophe Dubois     sysbus_connect_irq(SYS_BUS_DEVICE(&s->avic), 0,
111ee708c99SJean-Christophe Dubois                        qdev_get_gpio_in(DEVICE(&s->cpu), ARM_CPU_IRQ));
112ee708c99SJean-Christophe Dubois     sysbus_connect_irq(SYS_BUS_DEVICE(&s->avic), 1,
113ee708c99SJean-Christophe Dubois                        qdev_get_gpio_in(DEVICE(&s->cpu), ARM_CPU_FIQ));
114ee708c99SJean-Christophe Dubois 
115ee708c99SJean-Christophe Dubois     object_property_set_bool(OBJECT(&s->ccm), true, "realized", &err);
116ee708c99SJean-Christophe Dubois     if (err) {
117ee708c99SJean-Christophe Dubois         error_propagate(errp, err);
118ee708c99SJean-Christophe Dubois         return;
119ee708c99SJean-Christophe Dubois     }
120ee708c99SJean-Christophe Dubois     sysbus_mmio_map(SYS_BUS_DEVICE(&s->ccm), 0, FSL_IMX25_CCM_ADDR);
121ee708c99SJean-Christophe Dubois 
122ee708c99SJean-Christophe Dubois     /* Initialize all UARTs */
123ee708c99SJean-Christophe Dubois     for (i = 0; i < FSL_IMX25_NUM_UARTS; i++) {
124ee708c99SJean-Christophe Dubois         static const struct {
125ee708c99SJean-Christophe Dubois             hwaddr addr;
126ee708c99SJean-Christophe Dubois             unsigned int irq;
127ee708c99SJean-Christophe Dubois         } serial_table[FSL_IMX25_NUM_UARTS] = {
128ee708c99SJean-Christophe Dubois             { FSL_IMX25_UART1_ADDR, FSL_IMX25_UART1_IRQ },
129ee708c99SJean-Christophe Dubois             { FSL_IMX25_UART2_ADDR, FSL_IMX25_UART2_IRQ },
130ee708c99SJean-Christophe Dubois             { FSL_IMX25_UART3_ADDR, FSL_IMX25_UART3_IRQ },
131ee708c99SJean-Christophe Dubois             { FSL_IMX25_UART4_ADDR, FSL_IMX25_UART4_IRQ },
132ee708c99SJean-Christophe Dubois             { FSL_IMX25_UART5_ADDR, FSL_IMX25_UART5_IRQ }
133ee708c99SJean-Christophe Dubois         };
134ee708c99SJean-Christophe Dubois 
1359bca0edbSPeter Maydell         qdev_prop_set_chr(DEVICE(&s->uart[i]), "chardev", serial_hd(i));
136ee708c99SJean-Christophe Dubois 
137ee708c99SJean-Christophe Dubois         object_property_set_bool(OBJECT(&s->uart[i]), true, "realized", &err);
138ee708c99SJean-Christophe Dubois         if (err) {
139ee708c99SJean-Christophe Dubois             error_propagate(errp, err);
140ee708c99SJean-Christophe Dubois             return;
141ee708c99SJean-Christophe Dubois         }
142ee708c99SJean-Christophe Dubois         sysbus_mmio_map(SYS_BUS_DEVICE(&s->uart[i]), 0, serial_table[i].addr);
143ee708c99SJean-Christophe Dubois         sysbus_connect_irq(SYS_BUS_DEVICE(&s->uart[i]), 0,
144ee708c99SJean-Christophe Dubois                            qdev_get_gpio_in(DEVICE(&s->avic),
145ee708c99SJean-Christophe Dubois                                             serial_table[i].irq));
146ee708c99SJean-Christophe Dubois     }
147ee708c99SJean-Christophe Dubois 
148ee708c99SJean-Christophe Dubois     /* Initialize all GPT timers */
149ee708c99SJean-Christophe Dubois     for (i = 0; i < FSL_IMX25_NUM_GPTS; i++) {
150ee708c99SJean-Christophe Dubois         static const struct {
151ee708c99SJean-Christophe Dubois             hwaddr addr;
152ee708c99SJean-Christophe Dubois             unsigned int irq;
153ee708c99SJean-Christophe Dubois         } gpt_table[FSL_IMX25_NUM_GPTS] = {
154ee708c99SJean-Christophe Dubois             { FSL_IMX25_GPT1_ADDR, FSL_IMX25_GPT1_IRQ },
155ee708c99SJean-Christophe Dubois             { FSL_IMX25_GPT2_ADDR, FSL_IMX25_GPT2_IRQ },
156ee708c99SJean-Christophe Dubois             { FSL_IMX25_GPT3_ADDR, FSL_IMX25_GPT3_IRQ },
157ee708c99SJean-Christophe Dubois             { FSL_IMX25_GPT4_ADDR, FSL_IMX25_GPT4_IRQ }
158ee708c99SJean-Christophe Dubois         };
159ee708c99SJean-Christophe Dubois 
160cb54d868SJean-Christophe Dubois         s->gpt[i].ccm = IMX_CCM(&s->ccm);
161ee708c99SJean-Christophe Dubois 
162ee708c99SJean-Christophe Dubois         object_property_set_bool(OBJECT(&s->gpt[i]), true, "realized", &err);
163ee708c99SJean-Christophe Dubois         if (err) {
164ee708c99SJean-Christophe Dubois             error_propagate(errp, err);
165ee708c99SJean-Christophe Dubois             return;
166ee708c99SJean-Christophe Dubois         }
167ee708c99SJean-Christophe Dubois         sysbus_mmio_map(SYS_BUS_DEVICE(&s->gpt[i]), 0, gpt_table[i].addr);
168ee708c99SJean-Christophe Dubois         sysbus_connect_irq(SYS_BUS_DEVICE(&s->gpt[i]), 0,
169ee708c99SJean-Christophe Dubois                            qdev_get_gpio_in(DEVICE(&s->avic),
170ee708c99SJean-Christophe Dubois                                             gpt_table[i].irq));
171ee708c99SJean-Christophe Dubois     }
172ee708c99SJean-Christophe Dubois 
173ee708c99SJean-Christophe Dubois     /* Initialize all EPIT timers */
174ee708c99SJean-Christophe Dubois     for (i = 0; i < FSL_IMX25_NUM_EPITS; i++) {
175ee708c99SJean-Christophe Dubois         static const struct {
176ee708c99SJean-Christophe Dubois             hwaddr addr;
177ee708c99SJean-Christophe Dubois             unsigned int irq;
178ee708c99SJean-Christophe Dubois         } epit_table[FSL_IMX25_NUM_EPITS] = {
179ee708c99SJean-Christophe Dubois             { FSL_IMX25_EPIT1_ADDR, FSL_IMX25_EPIT1_IRQ },
180ee708c99SJean-Christophe Dubois             { FSL_IMX25_EPIT2_ADDR, FSL_IMX25_EPIT2_IRQ }
181ee708c99SJean-Christophe Dubois         };
182ee708c99SJean-Christophe Dubois 
183cb54d868SJean-Christophe Dubois         s->epit[i].ccm = IMX_CCM(&s->ccm);
184ee708c99SJean-Christophe Dubois 
185ee708c99SJean-Christophe Dubois         object_property_set_bool(OBJECT(&s->epit[i]), true, "realized", &err);
186ee708c99SJean-Christophe Dubois         if (err) {
187ee708c99SJean-Christophe Dubois             error_propagate(errp, err);
188ee708c99SJean-Christophe Dubois             return;
189ee708c99SJean-Christophe Dubois         }
190ee708c99SJean-Christophe Dubois         sysbus_mmio_map(SYS_BUS_DEVICE(&s->epit[i]), 0, epit_table[i].addr);
191ee708c99SJean-Christophe Dubois         sysbus_connect_irq(SYS_BUS_DEVICE(&s->epit[i]), 0,
192ee708c99SJean-Christophe Dubois                            qdev_get_gpio_in(DEVICE(&s->avic),
193ee708c99SJean-Christophe Dubois                                             epit_table[i].irq));
194ee708c99SJean-Christophe Dubois     }
195ee708c99SJean-Christophe Dubois 
196ee708c99SJean-Christophe Dubois     qdev_set_nic_properties(DEVICE(&s->fec), &nd_table[0]);
197a699b410SJean-Christophe Dubois 
198ee708c99SJean-Christophe Dubois     object_property_set_bool(OBJECT(&s->fec), true, "realized", &err);
199ee708c99SJean-Christophe Dubois     if (err) {
200ee708c99SJean-Christophe Dubois         error_propagate(errp, err);
201ee708c99SJean-Christophe Dubois         return;
202ee708c99SJean-Christophe Dubois     }
203ee708c99SJean-Christophe Dubois     sysbus_mmio_map(SYS_BUS_DEVICE(&s->fec), 0, FSL_IMX25_FEC_ADDR);
204ee708c99SJean-Christophe Dubois     sysbus_connect_irq(SYS_BUS_DEVICE(&s->fec), 0,
205ee708c99SJean-Christophe Dubois                        qdev_get_gpio_in(DEVICE(&s->avic), FSL_IMX25_FEC_IRQ));
206ee708c99SJean-Christophe Dubois 
207f0396549SMartin Kaiser     object_property_set_bool(OBJECT(&s->rngc), true, "realized", &err);
208f0396549SMartin Kaiser     if (err) {
209f0396549SMartin Kaiser         error_propagate(errp, err);
210f0396549SMartin Kaiser         return;
211f0396549SMartin Kaiser     }
212f0396549SMartin Kaiser     sysbus_mmio_map(SYS_BUS_DEVICE(&s->rngc), 0, FSL_IMX25_RNGC_ADDR);
213f0396549SMartin Kaiser     sysbus_connect_irq(SYS_BUS_DEVICE(&s->rngc), 0,
214f0396549SMartin Kaiser                        qdev_get_gpio_in(DEVICE(&s->avic), FSL_IMX25_RNGC_IRQ));
215ee708c99SJean-Christophe Dubois 
216ee708c99SJean-Christophe Dubois     /* Initialize all I2C */
217ee708c99SJean-Christophe Dubois     for (i = 0; i < FSL_IMX25_NUM_I2CS; i++) {
218ee708c99SJean-Christophe Dubois         static const struct {
219ee708c99SJean-Christophe Dubois             hwaddr addr;
220ee708c99SJean-Christophe Dubois             unsigned int irq;
221ee708c99SJean-Christophe Dubois         } i2c_table[FSL_IMX25_NUM_I2CS] = {
222ee708c99SJean-Christophe Dubois             { FSL_IMX25_I2C1_ADDR, FSL_IMX25_I2C1_IRQ },
223ee708c99SJean-Christophe Dubois             { FSL_IMX25_I2C2_ADDR, FSL_IMX25_I2C2_IRQ },
224ee708c99SJean-Christophe Dubois             { FSL_IMX25_I2C3_ADDR, FSL_IMX25_I2C3_IRQ }
225ee708c99SJean-Christophe Dubois         };
226ee708c99SJean-Christophe Dubois 
227ee708c99SJean-Christophe Dubois         object_property_set_bool(OBJECT(&s->i2c[i]), true, "realized", &err);
228ee708c99SJean-Christophe Dubois         if (err) {
229ee708c99SJean-Christophe Dubois             error_propagate(errp, err);
230ee708c99SJean-Christophe Dubois             return;
231ee708c99SJean-Christophe Dubois         }
232ee708c99SJean-Christophe Dubois         sysbus_mmio_map(SYS_BUS_DEVICE(&s->i2c[i]), 0, i2c_table[i].addr);
233ee708c99SJean-Christophe Dubois         sysbus_connect_irq(SYS_BUS_DEVICE(&s->i2c[i]), 0,
234ee708c99SJean-Christophe Dubois                            qdev_get_gpio_in(DEVICE(&s->avic),
235ee708c99SJean-Christophe Dubois                                             i2c_table[i].irq));
236ee708c99SJean-Christophe Dubois     }
237ee708c99SJean-Christophe Dubois 
2386abc7158SJean-Christophe Dubois     /* Initialize all GPIOs */
2396abc7158SJean-Christophe Dubois     for (i = 0; i < FSL_IMX25_NUM_GPIOS; i++) {
2406abc7158SJean-Christophe Dubois         static const struct {
2416abc7158SJean-Christophe Dubois             hwaddr addr;
2426abc7158SJean-Christophe Dubois             unsigned int irq;
2436abc7158SJean-Christophe Dubois         } gpio_table[FSL_IMX25_NUM_GPIOS] = {
2446abc7158SJean-Christophe Dubois             { FSL_IMX25_GPIO1_ADDR, FSL_IMX25_GPIO1_IRQ },
2456abc7158SJean-Christophe Dubois             { FSL_IMX25_GPIO2_ADDR, FSL_IMX25_GPIO2_IRQ },
2466abc7158SJean-Christophe Dubois             { FSL_IMX25_GPIO3_ADDR, FSL_IMX25_GPIO3_IRQ },
2476abc7158SJean-Christophe Dubois             { FSL_IMX25_GPIO4_ADDR, FSL_IMX25_GPIO4_IRQ }
2486abc7158SJean-Christophe Dubois         };
2496abc7158SJean-Christophe Dubois 
2506abc7158SJean-Christophe Dubois         object_property_set_bool(OBJECT(&s->gpio[i]), true, "realized", &err);
2516abc7158SJean-Christophe Dubois         if (err) {
2526abc7158SJean-Christophe Dubois             error_propagate(errp, err);
2536abc7158SJean-Christophe Dubois             return;
2546abc7158SJean-Christophe Dubois         }
2556abc7158SJean-Christophe Dubois         sysbus_mmio_map(SYS_BUS_DEVICE(&s->gpio[i]), 0, gpio_table[i].addr);
2566abc7158SJean-Christophe Dubois         /* Connect GPIO IRQ to PIC */
2576abc7158SJean-Christophe Dubois         sysbus_connect_irq(SYS_BUS_DEVICE(&s->gpio[i]), 0,
2586abc7158SJean-Christophe Dubois                            qdev_get_gpio_in(DEVICE(&s->avic),
2596abc7158SJean-Christophe Dubois                                             gpio_table[i].irq));
2606abc7158SJean-Christophe Dubois     }
2616abc7158SJean-Christophe Dubois 
262bfae1772SGuenter Roeck     /* Initialize all SDHC */
263bfae1772SGuenter Roeck     for (i = 0; i < FSL_IMX25_NUM_ESDHCS; i++) {
264bfae1772SGuenter Roeck         static const struct {
265bfae1772SGuenter Roeck             hwaddr addr;
266bfae1772SGuenter Roeck             unsigned int irq;
267bfae1772SGuenter Roeck         } esdhc_table[FSL_IMX25_NUM_ESDHCS] = {
268bfae1772SGuenter Roeck             { FSL_IMX25_ESDHC1_ADDR, FSL_IMX25_ESDHC1_IRQ },
269bfae1772SGuenter Roeck             { FSL_IMX25_ESDHC2_ADDR, FSL_IMX25_ESDHC2_IRQ },
270bfae1772SGuenter Roeck         };
271bfae1772SGuenter Roeck 
272bfae1772SGuenter Roeck         object_property_set_uint(OBJECT(&s->esdhc[i]), 2, "sd-spec-version",
273bfae1772SGuenter Roeck                                  &err);
274bfae1772SGuenter Roeck         object_property_set_uint(OBJECT(&s->esdhc[i]), IMX25_ESDHC_CAPABILITIES,
275bfae1772SGuenter Roeck                                  "capareg", &err);
276bfae1772SGuenter Roeck         object_property_set_bool(OBJECT(&s->esdhc[i]), true, "realized", &err);
277bfae1772SGuenter Roeck         if (err) {
278bfae1772SGuenter Roeck             error_propagate(errp, err);
279bfae1772SGuenter Roeck             return;
280bfae1772SGuenter Roeck         }
281bfae1772SGuenter Roeck         sysbus_mmio_map(SYS_BUS_DEVICE(&s->esdhc[i]), 0, esdhc_table[i].addr);
282bfae1772SGuenter Roeck         sysbus_connect_irq(SYS_BUS_DEVICE(&s->esdhc[i]), 0,
283bfae1772SGuenter Roeck                            qdev_get_gpio_in(DEVICE(&s->avic),
284bfae1772SGuenter Roeck                                             esdhc_table[i].irq));
285bfae1772SGuenter Roeck     }
286bfae1772SGuenter Roeck 
28767f52ebeSGuenter Roeck     /* USB */
28867f52ebeSGuenter Roeck     for (i = 0; i < FSL_IMX25_NUM_USBS; i++) {
28967f52ebeSGuenter Roeck         static const struct {
29067f52ebeSGuenter Roeck             hwaddr addr;
29167f52ebeSGuenter Roeck             unsigned int irq;
29267f52ebeSGuenter Roeck         } usb_table[FSL_IMX25_NUM_USBS] = {
29367f52ebeSGuenter Roeck             { FSL_IMX25_USB1_ADDR, FSL_IMX25_USB1_IRQ },
29467f52ebeSGuenter Roeck             { FSL_IMX25_USB2_ADDR, FSL_IMX25_USB2_IRQ },
29567f52ebeSGuenter Roeck         };
29667f52ebeSGuenter Roeck 
29767f52ebeSGuenter Roeck         object_property_set_bool(OBJECT(&s->usb[i]), true, "realized",
29867f52ebeSGuenter Roeck                                  &error_abort);
29967f52ebeSGuenter Roeck         sysbus_mmio_map(SYS_BUS_DEVICE(&s->usb[i]), 0, usb_table[i].addr);
30067f52ebeSGuenter Roeck         sysbus_connect_irq(SYS_BUS_DEVICE(&s->usb[i]), 0,
30167f52ebeSGuenter Roeck                            qdev_get_gpio_in(DEVICE(&s->avic),
30267f52ebeSGuenter Roeck                                             usb_table[i].irq));
30367f52ebeSGuenter Roeck     }
30467f52ebeSGuenter Roeck 
305ee708c99SJean-Christophe Dubois     /* initialize 2 x 16 KB ROM */
306*32b9523aSPhilippe Mathieu-Daudé     memory_region_init_rom(&s->rom[0], OBJECT(dev), "imx25.rom0",
307*32b9523aSPhilippe Mathieu-Daudé                            FSL_IMX25_ROM0_SIZE, &err);
308ee708c99SJean-Christophe Dubois     if (err) {
309ee708c99SJean-Christophe Dubois         error_propagate(errp, err);
310ee708c99SJean-Christophe Dubois         return;
311ee708c99SJean-Christophe Dubois     }
312ee708c99SJean-Christophe Dubois     memory_region_add_subregion(get_system_memory(), FSL_IMX25_ROM0_ADDR,
313ee708c99SJean-Christophe Dubois                                 &s->rom[0]);
314*32b9523aSPhilippe Mathieu-Daudé     memory_region_init_rom(&s->rom[1], OBJECT(dev), "imx25.rom1",
315*32b9523aSPhilippe Mathieu-Daudé                            FSL_IMX25_ROM1_SIZE, &err);
316ee708c99SJean-Christophe Dubois     if (err) {
317ee708c99SJean-Christophe Dubois         error_propagate(errp, err);
318ee708c99SJean-Christophe Dubois         return;
319ee708c99SJean-Christophe Dubois     }
320ee708c99SJean-Christophe Dubois     memory_region_add_subregion(get_system_memory(), FSL_IMX25_ROM1_ADDR,
321ee708c99SJean-Christophe Dubois                                 &s->rom[1]);
322ee708c99SJean-Christophe Dubois 
323ee708c99SJean-Christophe Dubois     /* initialize internal RAM (128 KB) */
32498a99ce0SPeter Maydell     memory_region_init_ram(&s->iram, NULL, "imx25.iram", FSL_IMX25_IRAM_SIZE,
325ee708c99SJean-Christophe Dubois                            &err);
326ee708c99SJean-Christophe Dubois     if (err) {
327ee708c99SJean-Christophe Dubois         error_propagate(errp, err);
328ee708c99SJean-Christophe Dubois         return;
329ee708c99SJean-Christophe Dubois     }
330ee708c99SJean-Christophe Dubois     memory_region_add_subregion(get_system_memory(), FSL_IMX25_IRAM_ADDR,
331ee708c99SJean-Christophe Dubois                                 &s->iram);
332ee708c99SJean-Christophe Dubois 
333ee708c99SJean-Christophe Dubois     /* internal RAM (128 KB) is aliased over 128 MB - 128 KB */
334*32b9523aSPhilippe Mathieu-Daudé     memory_region_init_alias(&s->iram_alias, OBJECT(dev), "imx25.iram_alias",
335ee708c99SJean-Christophe Dubois                              &s->iram, 0, FSL_IMX25_IRAM_ALIAS_SIZE);
336ee708c99SJean-Christophe Dubois     memory_region_add_subregion(get_system_memory(), FSL_IMX25_IRAM_ALIAS_ADDR,
337ee708c99SJean-Christophe Dubois                                 &s->iram_alias);
338ee708c99SJean-Christophe Dubois }
339ee708c99SJean-Christophe Dubois 
340ee708c99SJean-Christophe Dubois static void fsl_imx25_class_init(ObjectClass *oc, void *data)
341ee708c99SJean-Christophe Dubois {
342ee708c99SJean-Christophe Dubois     DeviceClass *dc = DEVICE_CLASS(oc);
343ee708c99SJean-Christophe Dubois 
344ee708c99SJean-Christophe Dubois     dc->realize = fsl_imx25_realize;
345eccfa35eSJean-Christophe Dubois     dc->desc = "i.MX25 SOC";
3465e0c7044SThomas Huth     /*
3475e0c7044SThomas Huth      * Reason: uses serial_hds in realize and the imx25 board does not
3485e0c7044SThomas Huth      * support multiple CPUs
3495e0c7044SThomas Huth      */
3505e0c7044SThomas Huth     dc->user_creatable = false;
351ee708c99SJean-Christophe Dubois }
352ee708c99SJean-Christophe Dubois 
353ee708c99SJean-Christophe Dubois static const TypeInfo fsl_imx25_type_info = {
354ee708c99SJean-Christophe Dubois     .name = TYPE_FSL_IMX25,
355ee708c99SJean-Christophe Dubois     .parent = TYPE_DEVICE,
356ee708c99SJean-Christophe Dubois     .instance_size = sizeof(FslIMX25State),
357ee708c99SJean-Christophe Dubois     .instance_init = fsl_imx25_init,
358ee708c99SJean-Christophe Dubois     .class_init = fsl_imx25_class_init,
359ee708c99SJean-Christophe Dubois };
360ee708c99SJean-Christophe Dubois 
361ee708c99SJean-Christophe Dubois static void fsl_imx25_register_types(void)
362ee708c99SJean-Christophe Dubois {
363ee708c99SJean-Christophe Dubois     type_register_static(&fsl_imx25_type_info);
364ee708c99SJean-Christophe Dubois }
365ee708c99SJean-Christophe Dubois 
366ee708c99SJean-Christophe Dubois type_init(fsl_imx25_register_types)
367