]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - sys/arm/freescale/imx/imx6_machdep.c
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / sys / arm / freescale / imx / imx6_machdep.c
1 /*-
2  * Copyright (c) 2013 Ian Lepore <ian@freebsd.org>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  */
26
27 #include "opt_platform.h"
28
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
31
32 #include <sys/param.h>
33 #include <sys/systm.h>
34 #include <sys/bus.h>
35 #include <sys/reboot.h>
36
37 #include <vm/vm.h>
38
39 #include <machine/bus.h>
40 #include <machine/devmap.h>
41 #include <machine/intr.h>
42 #include <machine/machdep.h>
43
44 #include <arm/arm/mpcore_timervar.h>
45 #include <arm/freescale/imx/imx6_anatopreg.h>
46 #include <arm/freescale/imx/imx6_anatopvar.h>
47 #include <arm/freescale/imx/imx_machdep.h>
48
49 #include <dev/fdt/fdt_common.h>
50 #include <dev/ofw/openfirm.h>
51
52 struct fdt_fixup_entry fdt_fixup_table[] = {
53         { NULL, NULL }
54 };
55
56 static uint32_t gpio1_node;
57
58 /*
59  * Work around the linux workaround for imx6 erratum 006687, in which some
60  * ethernet interrupts don't go to the GPC and thus won't wake the system from
61  * Wait mode. We don't use Wait mode (which halts the GIC, leaving only GPC
62  * interrupts able to wake the system), so we don't experience the bug at all.
63  * The linux workaround is to reconfigure GPIO1_6 as the ENET interrupt by
64  * writing magic values to an undocumented IOMUX register, then letting the gpio
65  * interrupt driver notify the ethernet driver.  We'll be able to do all that
66  * (even though we don't need to) once the INTRNG project is committed and the
67  * imx_gpio driver becomes an interrupt driver.  Until then, this crazy little
68  * workaround watches for requests to map an interrupt 6 with the interrupt
69  * controller node referring to gpio1, and it substitutes the proper ffec
70  * interrupt number.
71  */
72 static int
73 imx6_decode_fdt(uint32_t iparent, uint32_t *intr, int *interrupt,
74     int *trig, int *pol)
75 {
76
77         if (fdt32_to_cpu(intr[0]) == 6 && 
78             OF_node_from_xref(iparent) == gpio1_node) {
79                 *interrupt = 150;
80                 *trig = INTR_TRIGGER_CONFORM;
81                 *pol  = INTR_POLARITY_CONFORM;
82                 return (0);
83         }
84         return (gic_decode_fdt(iparent, intr, interrupt, trig, pol));
85 }
86
87 fdt_pic_decode_t fdt_pic_table[] = {
88         &imx6_decode_fdt,
89         NULL
90 };
91
92 vm_offset_t
93 initarm_lastaddr(void)
94 {
95
96         return (arm_devmap_lastaddr());
97 }
98
99 void
100 initarm_early_init(void)
101 {
102
103         /* Inform the MPCore timer driver that its clock is variable. */
104         arm_tmr_change_frequency(ARM_TMR_FREQUENCY_VARIES);
105 }
106
107 void
108 initarm_gpio_init(void)
109 {
110
111 }
112
113 void
114 initarm_late_init(void)
115 {
116
117         /* Cache the gpio1 node handle for imx6_decode_fdt() workaround code. */
118         gpio1_node = OF_node_from_xref(
119             OF_finddevice("/soc/aips-bus@02000000/gpio@0209c000"));
120 }
121
122 /*
123  * Set up static device mappings.
124  *
125  * This attempts to cover the most-used devices with 1MB section mappings, which
126  * is good for performance (uses fewer TLB entries for device access).
127  *
128  * ARMMP covers the interrupt controller, MPCore timers, global timer, and the
129  * L2 cache controller.  Most of the 1MB range is unused reserved space.
130  *
131  * AIPS1/AIPS2 cover most of the on-chip devices such as uart, spi, i2c, etc.
132  *
133  * Notably not mapped right now are HDMI, GPU, and other devices below ARMMP in
134  * the memory map.  When we get support for graphics it might make sense to
135  * static map some of that area.  Be careful with other things in that area such
136  * as OCRAM that probably shouldn't be mapped as PTE_DEVICE memory.
137  */
138 int
139 initarm_devmap_init(void)
140 {
141         const uint32_t IMX6_ARMMP_PHYS = 0x00a00000;
142         const uint32_t IMX6_ARMMP_SIZE = 0x00100000;
143         const uint32_t IMX6_AIPS1_PHYS = 0x02000000;
144         const uint32_t IMX6_AIPS1_SIZE = 0x00100000;
145         const uint32_t IMX6_AIPS2_PHYS = 0x02100000;
146         const uint32_t IMX6_AIPS2_SIZE = 0x00100000;
147
148         arm_devmap_add_entry(IMX6_ARMMP_PHYS, IMX6_ARMMP_SIZE);
149         arm_devmap_add_entry(IMX6_AIPS1_PHYS, IMX6_AIPS1_SIZE);
150         arm_devmap_add_entry(IMX6_AIPS2_PHYS, IMX6_AIPS2_SIZE);
151
152         return (0);
153 }
154
155 void
156 cpu_reset(void)
157 {
158         const uint32_t IMX6_WDOG_CR_PHYS = 0x020bc000;
159
160         imx_wdog_cpu_reset(IMX6_WDOG_CR_PHYS);
161 }
162
163 /*
164  * Determine what flavor of imx6 we're running on.
165  *
166  * This code is based on the way u-boot does it.  Information found on the web
167  * indicates that Freescale themselves were the original source of this logic,
168  * including the strange check for number of CPUs in the SCU configuration
169  * register, which is apparently needed on some revisions of the SOLO.
170  *
171  * According to the documentation, there is such a thing as an i.MX6 Dual
172  * (non-lite flavor).  However, Freescale doesn't seem to have assigned it a
173  * number or provided any logic to handle it in their detection code.
174  *
175  * Note that the ANALOG_DIGPROG and SCU configuration registers are not
176  * documented in the chip reference manual.  (SCU configuration is mentioned,
177  * but not mapped out in detail.)  I think the bottom two bits of the scu config
178  * register may be ncpu-1.
179  *
180  * This hasn't been tested yet on a dual[-lite].
181  *
182  * On a solo:
183  *      digprog    = 0x00610001
184  *      hwsoc      = 0x00000062
185  *      scu config = 0x00000500
186  * On a quad:
187  *      digprog    = 0x00630002
188  *      hwsoc      = 0x00000063
189  *      scu config = 0x00005503
190  */
191 u_int imx_soc_type()
192 {
193         uint32_t digprog, hwsoc;
194         uint32_t *pcr;
195         static u_int soctype;
196         const vm_offset_t SCU_CONFIG_PHYSADDR = 0x00a00004;
197 #define HWSOC_MX6SL     0x60
198 #define HWSOC_MX6DL     0x61
199 #define HWSOC_MX6SOLO   0x62
200 #define HWSOC_MX6Q      0x63
201
202         if (soctype != 0)
203                 return (soctype);
204
205         digprog = imx6_anatop_read_4(IMX6_ANALOG_DIGPROG_SL);
206         hwsoc = (digprog >> IMX6_ANALOG_DIGPROG_SOCTYPE_SHIFT) & 
207             IMX6_ANALOG_DIGPROG_SOCTYPE_MASK;
208
209         if (hwsoc != HWSOC_MX6SL) {
210                 digprog = imx6_anatop_read_4(IMX6_ANALOG_DIGPROG);
211                 hwsoc = (digprog & IMX6_ANALOG_DIGPROG_SOCTYPE_MASK) >>
212                     IMX6_ANALOG_DIGPROG_SOCTYPE_SHIFT;
213                 /*printf("digprog = 0x%08x\n", digprog);*/
214                 if (hwsoc == HWSOC_MX6DL) {
215                         pcr = arm_devmap_ptov(SCU_CONFIG_PHYSADDR, 4);
216                         if (pcr != NULL) {
217                                 /*printf("scu config = 0x%08x\n", *pcr);*/
218                                 if ((*pcr & 0x03) == 0) {
219                                         hwsoc = HWSOC_MX6SOLO;
220                                 }
221                         }
222                 }
223         }
224         /* printf("hwsoc 0x%08x\n", hwsoc); */
225
226         switch (hwsoc) {
227         case HWSOC_MX6SL:
228                 soctype = IMXSOC_6SL;
229                 break;
230         case HWSOC_MX6SOLO:
231                 soctype = IMXSOC_6S;
232                 break;
233         case HWSOC_MX6DL:
234                 soctype = IMXSOC_6DL;
235                 break;
236         case HWSOC_MX6Q :
237                 soctype = IMXSOC_6Q;
238                 break;
239         default:
240                 printf("imx_soc_type: Don't understand hwsoc 0x%02x, "
241                     "digprog 0x%08x; assuming IMXSOC_6Q\n", hwsoc, digprog);
242                 soctype = IMXSOC_6Q;
243                 break;
244         }
245
246         return (soctype);
247 }
248
249 /*
250  * Early putc routine for EARLY_PRINTF support.  To use, add to kernel config:
251  *   option SOCDEV_PA=0x02000000
252  *   option SOCDEV_VA=0x02000000
253  *   option EARLY_PRINTF
254  * Resist the temptation to change the #if 0 to #ifdef EARLY_PRINTF here. It
255  * makes sense now, but if multiple SOCs do that it will make early_putc another
256  * duplicate symbol to be eliminated on the path to a generic kernel.
257  */
258 #if 0 
259 static void 
260 imx6_early_putc(int c)
261 {
262         volatile uint32_t * UART_STAT_REG = (uint32_t *)0x02020098;
263         volatile uint32_t * UART_TX_REG   = (uint32_t *)0x02020040;
264         const uint32_t      UART_TXRDY    = (1 << 3);
265
266         while ((*UART_STAT_REG & UART_TXRDY) == 0)
267                 continue;
268         *UART_TX_REG = c;
269 }
270 early_putc_t *early_putc = imx6_early_putc;
271 #endif
272