Thomas Gleixner | fcaf203 | 2019-05-27 08:55:08 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Dong Aisheng | bc3a59c | 2012-03-31 21:26:57 +0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright 2012 Freescale Semiconductor, Inc. |
| 4 | * Copyright 2012 Linaro Ltd. |
Dong Aisheng | bc3a59c | 2012-03-31 21:26:57 +0800 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <linux/clk.h> |
Shawn Guo | 3cb7825 | 2013-03-29 13:36:05 +0800 | [diff] [blame] | 8 | #include <linux/clk/mxs.h> |
Dong Aisheng | bc3a59c | 2012-03-31 21:26:57 +0800 | [diff] [blame] | 9 | #include <linux/clkdev.h> |
Shawn Guo | 2c7c2c1 | 2012-07-13 14:15:34 +0800 | [diff] [blame] | 10 | #include <linux/delay.h> |
Dong Aisheng | bc3a59c | 2012-03-31 21:26:57 +0800 | [diff] [blame] | 11 | #include <linux/err.h> |
Shawn Guo | 2c7c2c1 | 2012-07-13 14:15:34 +0800 | [diff] [blame] | 12 | #include <linux/gpio.h> |
Dong Aisheng | bc3a59c | 2012-03-31 21:26:57 +0800 | [diff] [blame] | 13 | #include <linux/init.h> |
Shawn Guo | 6a8e95b | 2013-03-25 21:34:51 +0800 | [diff] [blame] | 14 | #include <linux/irqchip/mxs.h> |
Robin Holt | 7b6d864 | 2013-07-08 16:01:40 -0700 | [diff] [blame] | 15 | #include <linux/reboot.h> |
Shawn Guo | 3143bbb | 2012-07-07 23:12:03 +0800 | [diff] [blame] | 16 | #include <linux/micrel_phy.h> |
Shawn Guo | 974a9af | 2013-03-29 09:45:31 +0800 | [diff] [blame] | 17 | #include <linux/of_address.h> |
Dong Aisheng | bc3a59c | 2012-03-31 21:26:57 +0800 | [diff] [blame] | 18 | #include <linux/of_platform.h> |
Shawn Guo | 3143bbb | 2012-07-07 23:12:03 +0800 | [diff] [blame] | 19 | #include <linux/phy.h> |
Shawn Guo | 2c7c2c1 | 2012-07-13 14:15:34 +0800 | [diff] [blame] | 20 | #include <linux/pinctrl/consumer.h> |
Fabio Estevam | 2046338 | 2013-06-04 10:18:45 -0300 | [diff] [blame] | 21 | #include <linux/sys_soc.h> |
Dong Aisheng | bc3a59c | 2012-03-31 21:26:57 +0800 | [diff] [blame] | 22 | #include <asm/mach/arch.h> |
Shawn Guo | 1f62956 | 2013-03-29 13:07:34 +0800 | [diff] [blame] | 23 | #include <asm/mach/map.h> |
Dong Aisheng | bc3a59c | 2012-03-31 21:26:57 +0800 | [diff] [blame] | 24 | #include <asm/mach/time.h> |
Ivan Zaentsev | 4ba79e2 | 2020-11-16 19:58:26 +0300 | [diff] [blame] | 25 | #include <asm/system_info.h> |
Shawn Guo | 974a9af | 2013-03-29 09:45:31 +0800 | [diff] [blame] | 26 | #include <asm/system_misc.h> |
Shawn Guo | 0b48d3a | 2013-03-29 13:53:11 +0800 | [diff] [blame] | 27 | |
Shawn Guo | 4568099 | 2013-03-29 14:41:27 +0800 | [diff] [blame] | 28 | #include "pm.h" |
| 29 | |
Shawn Guo | 0b48d3a | 2013-03-29 13:53:11 +0800 | [diff] [blame] | 30 | /* MXS DIGCTL SAIF CLKMUX */ |
| 31 | #define MXS_DIGCTL_SAIF_CLKMUX_DIRECT 0x0 |
| 32 | #define MXS_DIGCTL_SAIF_CLKMUX_CROSSINPUT 0x1 |
| 33 | #define MXS_DIGCTL_SAIF_CLKMUX_EXTMSTR0 0x2 |
| 34 | #define MXS_DIGCTL_SAIF_CLKMUX_EXTMSTR1 0x3 |
| 35 | |
Fabio Estevam | 2046338 | 2013-06-04 10:18:45 -0300 | [diff] [blame] | 36 | #define HW_DIGCTL_CHIPID 0x310 |
| 37 | #define HW_DIGCTL_CHIPID_MASK (0xffff << 16) |
| 38 | #define HW_DIGCTL_REV_MASK 0xff |
| 39 | #define HW_DIGCTL_CHIPID_MX23 (0x3780 << 16) |
| 40 | #define HW_DIGCTL_CHIPID_MX28 (0x2800 << 16) |
| 41 | |
| 42 | #define MXS_CHIP_REVISION_1_0 0x10 |
| 43 | #define MXS_CHIP_REVISION_1_1 0x11 |
| 44 | #define MXS_CHIP_REVISION_1_2 0x12 |
| 45 | #define MXS_CHIP_REVISION_1_3 0x13 |
| 46 | #define MXS_CHIP_REVISION_1_4 0x14 |
| 47 | #define MXS_CHIP_REV_UNKNOWN 0xff |
| 48 | |
Shawn Guo | 0b48d3a | 2013-03-29 13:53:11 +0800 | [diff] [blame] | 49 | #define MXS_GPIO_NR(bank, nr) ((bank) * 32 + (nr)) |
| 50 | |
| 51 | #define MXS_SET_ADDR 0x4 |
| 52 | #define MXS_CLR_ADDR 0x8 |
| 53 | #define MXS_TOG_ADDR 0xc |
| 54 | |
Ivan Zaentsev | 4ba79e2 | 2020-11-16 19:58:26 +0300 | [diff] [blame] | 55 | #define HW_OCOTP_OPS2 19 /* offset 0x150 */ |
| 56 | #define HW_OCOTP_OPS3 20 /* offset 0x160 */ |
| 57 | |
Fabio Estevam | 2046338 | 2013-06-04 10:18:45 -0300 | [diff] [blame] | 58 | static u32 chipid; |
| 59 | static u32 socid; |
| 60 | |
Lothar Waßmann | 56b7eec | 2013-08-05 10:51:14 +0200 | [diff] [blame] | 61 | static void __iomem *reset_addr; |
| 62 | |
Shawn Guo | 0b48d3a | 2013-03-29 13:53:11 +0800 | [diff] [blame] | 63 | static inline void __mxs_setl(u32 mask, void __iomem *reg) |
| 64 | { |
| 65 | __raw_writel(mask, reg + MXS_SET_ADDR); |
| 66 | } |
| 67 | |
| 68 | static inline void __mxs_clrl(u32 mask, void __iomem *reg) |
| 69 | { |
| 70 | __raw_writel(mask, reg + MXS_CLR_ADDR); |
| 71 | } |
| 72 | |
| 73 | static inline void __mxs_togl(u32 mask, void __iomem *reg) |
| 74 | { |
| 75 | __raw_writel(mask, reg + MXS_TOG_ADDR); |
| 76 | } |
Dong Aisheng | bc3a59c | 2012-03-31 21:26:57 +0800 | [diff] [blame] | 77 | |
Shawn Guo | 1bff2d7 | 2013-03-29 13:27:55 +0800 | [diff] [blame] | 78 | #define OCOTP_WORD_OFFSET 0x20 |
| 79 | #define OCOTP_WORD_COUNT 0x20 |
| 80 | |
| 81 | #define BM_OCOTP_CTRL_BUSY (1 << 8) |
| 82 | #define BM_OCOTP_CTRL_ERROR (1 << 9) |
| 83 | #define BM_OCOTP_CTRL_RD_BANK_OPEN (1 << 12) |
| 84 | |
| 85 | static DEFINE_MUTEX(ocotp_mutex); |
| 86 | static u32 ocotp_words[OCOTP_WORD_COUNT]; |
| 87 | |
| 88 | static const u32 *mxs_get_ocotp(void) |
| 89 | { |
| 90 | struct device_node *np; |
| 91 | void __iomem *ocotp_base; |
| 92 | int timeout = 0x400; |
| 93 | size_t i; |
| 94 | static int once; |
| 95 | |
| 96 | if (once) |
| 97 | return ocotp_words; |
| 98 | |
| 99 | np = of_find_compatible_node(NULL, NULL, "fsl,ocotp"); |
| 100 | ocotp_base = of_iomap(np, 0); |
| 101 | WARN_ON(!ocotp_base); |
| 102 | |
| 103 | mutex_lock(&ocotp_mutex); |
| 104 | |
| 105 | /* |
| 106 | * clk_enable(hbus_clk) for ocotp can be skipped |
| 107 | * as it must be on when system is running. |
| 108 | */ |
| 109 | |
| 110 | /* try to clear ERROR bit */ |
| 111 | __mxs_clrl(BM_OCOTP_CTRL_ERROR, ocotp_base); |
| 112 | |
| 113 | /* check both BUSY and ERROR cleared */ |
| 114 | while ((__raw_readl(ocotp_base) & |
| 115 | (BM_OCOTP_CTRL_BUSY | BM_OCOTP_CTRL_ERROR)) && --timeout) |
| 116 | cpu_relax(); |
| 117 | |
| 118 | if (unlikely(!timeout)) |
| 119 | goto error_unlock; |
| 120 | |
| 121 | /* open OCOTP banks for read */ |
| 122 | __mxs_setl(BM_OCOTP_CTRL_RD_BANK_OPEN, ocotp_base); |
| 123 | |
| 124 | /* approximately wait 32 hclk cycles */ |
| 125 | udelay(1); |
| 126 | |
| 127 | /* poll BUSY bit becoming cleared */ |
| 128 | timeout = 0x400; |
| 129 | while ((__raw_readl(ocotp_base) & BM_OCOTP_CTRL_BUSY) && --timeout) |
| 130 | cpu_relax(); |
| 131 | |
| 132 | if (unlikely(!timeout)) |
| 133 | goto error_unlock; |
| 134 | |
| 135 | for (i = 0; i < OCOTP_WORD_COUNT; i++) |
| 136 | ocotp_words[i] = __raw_readl(ocotp_base + OCOTP_WORD_OFFSET + |
| 137 | i * 0x10); |
| 138 | |
| 139 | /* close banks for power saving */ |
| 140 | __mxs_clrl(BM_OCOTP_CTRL_RD_BANK_OPEN, ocotp_base); |
| 141 | |
| 142 | once = 1; |
| 143 | |
| 144 | mutex_unlock(&ocotp_mutex); |
| 145 | |
| 146 | return ocotp_words; |
| 147 | |
| 148 | error_unlock: |
| 149 | mutex_unlock(&ocotp_mutex); |
| 150 | pr_err("%s: timeout in reading OCOTP\n", __func__); |
| 151 | return NULL; |
| 152 | } |
| 153 | |
Shawn Guo | 5653acc | 2012-06-19 22:38:14 +0800 | [diff] [blame] | 154 | enum mac_oui { |
| 155 | OUI_FSL, |
| 156 | OUI_DENX, |
Maxime Ripard | 8eec4b3 | 2012-10-07 10:36:28 +0800 | [diff] [blame] | 157 | OUI_CRYSTALFONTZ, |
Michael Heimpold | df0355f | 2013-11-09 12:14:16 +0100 | [diff] [blame] | 158 | OUI_I2SE, |
Gwenhael Goavec-Merou | 9648b2e | 2013-11-30 09:51:12 +0100 | [diff] [blame] | 159 | OUI_ARMADEUS, |
Shawn Guo | 5653acc | 2012-06-19 22:38:14 +0800 | [diff] [blame] | 160 | }; |
| 161 | |
| 162 | static void __init update_fec_mac_prop(enum mac_oui oui) |
| 163 | { |
| 164 | struct device_node *np, *from = NULL; |
Shawn Guo | fa7c865 | 2012-07-13 14:13:55 +0800 | [diff] [blame] | 165 | struct property *newmac; |
Shawn Guo | 5653acc | 2012-06-19 22:38:14 +0800 | [diff] [blame] | 166 | const u32 *ocotp = mxs_get_ocotp(); |
| 167 | u8 *macaddr; |
| 168 | u32 val; |
| 169 | int i; |
| 170 | |
| 171 | for (i = 0; i < 2; i++) { |
| 172 | np = of_find_compatible_node(from, NULL, "fsl,imx28-fec"); |
| 173 | if (!np) |
| 174 | return; |
Marek Vasut | 16d4770 | 2012-09-25 13:32:18 +0200 | [diff] [blame] | 175 | |
Shawn Guo | 5653acc | 2012-06-19 22:38:14 +0800 | [diff] [blame] | 176 | from = np; |
| 177 | |
Marek Vasut | 16d4770 | 2012-09-25 13:32:18 +0200 | [diff] [blame] | 178 | if (of_get_property(np, "local-mac-address", NULL)) |
| 179 | continue; |
| 180 | |
Shawn Guo | 5653acc | 2012-06-19 22:38:14 +0800 | [diff] [blame] | 181 | newmac = kzalloc(sizeof(*newmac) + 6, GFP_KERNEL); |
| 182 | if (!newmac) |
| 183 | return; |
| 184 | newmac->value = newmac + 1; |
| 185 | newmac->length = 6; |
| 186 | |
| 187 | newmac->name = kstrdup("local-mac-address", GFP_KERNEL); |
| 188 | if (!newmac->name) { |
| 189 | kfree(newmac); |
| 190 | return; |
| 191 | } |
| 192 | |
| 193 | /* |
| 194 | * OCOTP only stores the last 4 octets for each mac address, |
| 195 | * so hard-code OUI here. |
| 196 | */ |
| 197 | macaddr = newmac->value; |
| 198 | switch (oui) { |
| 199 | case OUI_FSL: |
| 200 | macaddr[0] = 0x00; |
| 201 | macaddr[1] = 0x04; |
| 202 | macaddr[2] = 0x9f; |
| 203 | break; |
| 204 | case OUI_DENX: |
| 205 | macaddr[0] = 0xc0; |
| 206 | macaddr[1] = 0xe5; |
| 207 | macaddr[2] = 0x4e; |
| 208 | break; |
Maxime Ripard | 8eec4b3 | 2012-10-07 10:36:28 +0800 | [diff] [blame] | 209 | case OUI_CRYSTALFONTZ: |
| 210 | macaddr[0] = 0x58; |
| 211 | macaddr[1] = 0xb9; |
| 212 | macaddr[2] = 0xe1; |
| 213 | break; |
Michael Heimpold | df0355f | 2013-11-09 12:14:16 +0100 | [diff] [blame] | 214 | case OUI_I2SE: |
| 215 | macaddr[0] = 0x00; |
| 216 | macaddr[1] = 0x01; |
| 217 | macaddr[2] = 0x87; |
| 218 | break; |
Gwenhael Goavec-Merou | 9648b2e | 2013-11-30 09:51:12 +0100 | [diff] [blame] | 219 | case OUI_ARMADEUS: |
| 220 | macaddr[0] = 0x00; |
| 221 | macaddr[1] = 0x1e; |
| 222 | macaddr[2] = 0xac; |
| 223 | break; |
Shawn Guo | 5653acc | 2012-06-19 22:38:14 +0800 | [diff] [blame] | 224 | } |
| 225 | val = ocotp[i]; |
| 226 | macaddr[3] = (val >> 16) & 0xff; |
| 227 | macaddr[4] = (val >> 8) & 0xff; |
| 228 | macaddr[5] = (val >> 0) & 0xff; |
| 229 | |
Nathan Fontenot | 79d1c71 | 2012-10-02 16:58:46 +0000 | [diff] [blame] | 230 | of_update_property(np, newmac); |
Shawn Guo | 5653acc | 2012-06-19 22:38:14 +0800 | [diff] [blame] | 231 | } |
| 232 | } |
| 233 | |
Marek Vasut | 8fa62e1 | 2012-07-07 21:21:38 +0800 | [diff] [blame] | 234 | static inline void enable_clk_enet_out(void) |
Dong Aisheng | bc3a59c | 2012-03-31 21:26:57 +0800 | [diff] [blame] | 235 | { |
Marek Vasut | 8fa62e1 | 2012-07-07 21:21:38 +0800 | [diff] [blame] | 236 | struct clk *clk = clk_get_sys("enet_out", NULL); |
Dong Aisheng | bc3a59c | 2012-03-31 21:26:57 +0800 | [diff] [blame] | 237 | |
Dong Aisheng | bc3a59c | 2012-03-31 21:26:57 +0800 | [diff] [blame] | 238 | if (!IS_ERR(clk)) |
| 239 | clk_prepare_enable(clk); |
Marek Vasut | 8fa62e1 | 2012-07-07 21:21:38 +0800 | [diff] [blame] | 240 | } |
Shawn Guo | 5653acc | 2012-06-19 22:38:14 +0800 | [diff] [blame] | 241 | |
Marek Vasut | 8fa62e1 | 2012-07-07 21:21:38 +0800 | [diff] [blame] | 242 | static void __init imx28_evk_init(void) |
| 243 | { |
Shawn Guo | 5653acc | 2012-06-19 22:38:14 +0800 | [diff] [blame] | 244 | update_fec_mac_prop(OUI_FSL); |
Shawn Guo | ab2815c | 2012-06-25 21:21:46 +0800 | [diff] [blame] | 245 | |
Dong Aisheng | e317317 | 2012-08-01 11:20:16 +0800 | [diff] [blame] | 246 | mxs_saif_clkmux_select(MXS_DIGCTL_SAIF_CLKMUX_EXTMSTR0); |
Dong Aisheng | bc3a59c | 2012-03-31 21:26:57 +0800 | [diff] [blame] | 247 | } |
| 248 | |
Gwenhael Goavec-Merou | 9648b2e | 2013-11-30 09:51:12 +0100 | [diff] [blame] | 249 | static void __init imx28_apf28_init(void) |
| 250 | { |
| 251 | update_fec_mac_prop(OUI_ARMADEUS); |
| 252 | } |
| 253 | |
Shawn Guo | 3143bbb | 2012-07-07 23:12:03 +0800 | [diff] [blame] | 254 | static int apx4devkit_phy_fixup(struct phy_device *phy) |
| 255 | { |
| 256 | phy->dev_flags |= MICREL_PHY_50MHZ_CLK; |
| 257 | return 0; |
| 258 | } |
| 259 | |
| 260 | static void __init apx4devkit_init(void) |
| 261 | { |
| 262 | enable_clk_enet_out(); |
| 263 | |
| 264 | if (IS_BUILTIN(CONFIG_PHYLIB)) |
Marek Vasut | 510d573 | 2012-09-23 16:58:50 +0000 | [diff] [blame] | 265 | phy_register_fixup_for_uid(PHY_ID_KSZ8051, MICREL_PHY_ID_MASK, |
Shawn Guo | 3143bbb | 2012-07-07 23:12:03 +0800 | [diff] [blame] | 266 | apx4devkit_phy_fixup); |
| 267 | } |
| 268 | |
Brian Lilly | ed138c3 | 2013-06-13 15:43:44 +0200 | [diff] [blame] | 269 | static void __init crystalfontz_init(void) |
Maxime Ripard | 8eec4b3 | 2012-10-07 10:36:28 +0800 | [diff] [blame] | 270 | { |
Maxime Ripard | 8eec4b3 | 2012-10-07 10:36:28 +0800 | [diff] [blame] | 271 | update_fec_mac_prop(OUI_CRYSTALFONTZ); |
| 272 | } |
| 273 | |
Michael Heimpold | df0355f | 2013-11-09 12:14:16 +0100 | [diff] [blame] | 274 | static void __init duckbill_init(void) |
| 275 | { |
| 276 | update_fec_mac_prop(OUI_I2SE); |
| 277 | } |
| 278 | |
Marek Vasut | e0ec2f3 | 2013-09-30 00:41:29 +0200 | [diff] [blame] | 279 | static void __init m28cu3_init(void) |
| 280 | { |
| 281 | update_fec_mac_prop(OUI_DENX); |
| 282 | } |
| 283 | |
Fabio Estevam | 2046338 | 2013-06-04 10:18:45 -0300 | [diff] [blame] | 284 | static const char __init *mxs_get_soc_id(void) |
Maxime Ripard | e0f7d90 | 2013-01-26 13:40:37 +0800 | [diff] [blame] | 285 | { |
Fabio Estevam | 2046338 | 2013-06-04 10:18:45 -0300 | [diff] [blame] | 286 | struct device_node *np; |
| 287 | void __iomem *digctl_base; |
| 288 | |
| 289 | np = of_find_compatible_node(NULL, NULL, "fsl,imx23-digctl"); |
| 290 | digctl_base = of_iomap(np, 0); |
| 291 | WARN_ON(!digctl_base); |
| 292 | |
| 293 | chipid = readl(digctl_base + HW_DIGCTL_CHIPID); |
| 294 | socid = chipid & HW_DIGCTL_CHIPID_MASK; |
| 295 | |
| 296 | iounmap(digctl_base); |
| 297 | of_node_put(np); |
| 298 | |
| 299 | switch (socid) { |
| 300 | case HW_DIGCTL_CHIPID_MX23: |
| 301 | return "i.MX23"; |
| 302 | case HW_DIGCTL_CHIPID_MX28: |
| 303 | return "i.MX28"; |
| 304 | default: |
| 305 | return "Unknown"; |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | static u32 __init mxs_get_cpu_rev(void) |
| 310 | { |
| 311 | u32 rev = chipid & HW_DIGCTL_REV_MASK; |
| 312 | |
| 313 | switch (socid) { |
| 314 | case HW_DIGCTL_CHIPID_MX23: |
| 315 | switch (rev) { |
| 316 | case 0x0: |
| 317 | return MXS_CHIP_REVISION_1_0; |
| 318 | case 0x1: |
| 319 | return MXS_CHIP_REVISION_1_1; |
| 320 | case 0x2: |
| 321 | return MXS_CHIP_REVISION_1_2; |
| 322 | case 0x3: |
| 323 | return MXS_CHIP_REVISION_1_3; |
| 324 | case 0x4: |
| 325 | return MXS_CHIP_REVISION_1_4; |
| 326 | default: |
| 327 | return MXS_CHIP_REV_UNKNOWN; |
| 328 | } |
| 329 | case HW_DIGCTL_CHIPID_MX28: |
| 330 | switch (rev) { |
| 331 | case 0x0: |
| 332 | return MXS_CHIP_REVISION_1_1; |
| 333 | case 0x1: |
| 334 | return MXS_CHIP_REVISION_1_2; |
| 335 | default: |
| 336 | return MXS_CHIP_REV_UNKNOWN; |
| 337 | } |
| 338 | default: |
| 339 | return MXS_CHIP_REV_UNKNOWN; |
| 340 | } |
| 341 | } |
| 342 | |
| 343 | static const char __init *mxs_get_revision(void) |
| 344 | { |
| 345 | u32 rev = mxs_get_cpu_rev(); |
| 346 | |
| 347 | if (rev != MXS_CHIP_REV_UNKNOWN) |
Fabio Estevam | e115d63 | 2013-08-13 10:28:02 -0300 | [diff] [blame] | 348 | return kasprintf(GFP_KERNEL, "%d.%d", (rev >> 4) & 0xf, |
Fabio Estevam | 2046338 | 2013-06-04 10:18:45 -0300 | [diff] [blame] | 349 | rev & 0xf); |
| 350 | else |
| 351 | return kasprintf(GFP_KERNEL, "%s", "Unknown"); |
Maxime Ripard | e0f7d90 | 2013-01-26 13:40:37 +0800 | [diff] [blame] | 352 | } |
| 353 | |
Lothar Waßmann | 56b7eec | 2013-08-05 10:51:14 +0200 | [diff] [blame] | 354 | #define MX23_CLKCTRL_RESET_OFFSET 0x120 |
| 355 | #define MX28_CLKCTRL_RESET_OFFSET 0x1e0 |
| 356 | |
| 357 | static int __init mxs_restart_init(void) |
| 358 | { |
| 359 | struct device_node *np; |
| 360 | |
| 361 | np = of_find_compatible_node(NULL, NULL, "fsl,clkctrl"); |
| 362 | reset_addr = of_iomap(np, 0); |
| 363 | if (!reset_addr) |
| 364 | return -ENODEV; |
| 365 | |
| 366 | if (of_device_is_compatible(np, "fsl,imx23-clkctrl")) |
| 367 | reset_addr += MX23_CLKCTRL_RESET_OFFSET; |
| 368 | else |
| 369 | reset_addr += MX28_CLKCTRL_RESET_OFFSET; |
| 370 | of_node_put(np); |
| 371 | |
| 372 | return 0; |
| 373 | } |
| 374 | |
Eric Bénard | 9a4cc05 | 2013-12-05 14:28:06 +0100 | [diff] [blame] | 375 | static void __init eukrea_mbmx283lc_init(void) |
| 376 | { |
| 377 | mxs_saif_clkmux_select(MXS_DIGCTL_SAIF_CLKMUX_EXTMSTR0); |
| 378 | } |
| 379 | |
Dong Aisheng | bc3a59c | 2012-03-31 21:26:57 +0800 | [diff] [blame] | 380 | static void __init mxs_machine_init(void) |
| 381 | { |
Fabio Estevam | 2046338 | 2013-06-04 10:18:45 -0300 | [diff] [blame] | 382 | struct device_node *root; |
| 383 | struct device *parent; |
| 384 | struct soc_device *soc_dev; |
| 385 | struct soc_device_attribute *soc_dev_attr; |
Ivan Zaentsev | 4ba79e2 | 2020-11-16 19:58:26 +0300 | [diff] [blame] | 386 | u64 soc_uid = 0; |
| 387 | const u32 *ocotp = mxs_get_ocotp(); |
Fabio Estevam | 2046338 | 2013-06-04 10:18:45 -0300 | [diff] [blame] | 388 | int ret; |
| 389 | |
| 390 | soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL); |
| 391 | if (!soc_dev_attr) |
| 392 | return; |
| 393 | |
| 394 | root = of_find_node_by_path("/"); |
| 395 | ret = of_property_read_string(root, "model", &soc_dev_attr->machine); |
| 396 | if (ret) |
| 397 | return; |
| 398 | |
| 399 | soc_dev_attr->family = "Freescale MXS Family"; |
| 400 | soc_dev_attr->soc_id = mxs_get_soc_id(); |
| 401 | soc_dev_attr->revision = mxs_get_revision(); |
| 402 | |
Ivan Zaentsev | 4ba79e2 | 2020-11-16 19:58:26 +0300 | [diff] [blame] | 403 | if (socid == HW_DIGCTL_CHIPID_MX23) { |
| 404 | soc_uid = system_serial_low = ocotp[HW_OCOTP_OPS3]; |
| 405 | } else if (socid == HW_DIGCTL_CHIPID_MX28) { |
| 406 | soc_uid = system_serial_high = ocotp[HW_OCOTP_OPS2]; |
| 407 | soc_uid <<= 32; |
| 408 | system_serial_low = ocotp[HW_OCOTP_OPS3]; |
| 409 | soc_uid |= system_serial_low; |
| 410 | } |
| 411 | |
| 412 | if (soc_uid) |
| 413 | soc_dev_attr->serial_number = kasprintf(GFP_KERNEL, "%016llX", soc_uid); |
| 414 | |
Fabio Estevam | 2046338 | 2013-06-04 10:18:45 -0300 | [diff] [blame] | 415 | soc_dev = soc_device_register(soc_dev_attr); |
| 416 | if (IS_ERR(soc_dev)) { |
Ivan Zaentsev | 4ba79e2 | 2020-11-16 19:58:26 +0300 | [diff] [blame] | 417 | kfree(soc_dev_attr->serial_number); |
Fabio Estevam | 2046338 | 2013-06-04 10:18:45 -0300 | [diff] [blame] | 418 | kfree(soc_dev_attr->revision); |
| 419 | kfree(soc_dev_attr); |
| 420 | return; |
| 421 | } |
| 422 | |
| 423 | parent = soc_device_to_device(soc_dev); |
| 424 | |
Dong Aisheng | bc3a59c | 2012-03-31 21:26:57 +0800 | [diff] [blame] | 425 | if (of_machine_is_compatible("fsl,imx28-evk")) |
| 426 | imx28_evk_init(); |
Gwenhael Goavec-Merou | 9648b2e | 2013-11-30 09:51:12 +0100 | [diff] [blame] | 427 | if (of_machine_is_compatible("armadeus,imx28-apf28")) |
| 428 | imx28_apf28_init(); |
Shawn Guo | 3143bbb | 2012-07-07 23:12:03 +0800 | [diff] [blame] | 429 | else if (of_machine_is_compatible("bluegiga,apx4devkit")) |
| 430 | apx4devkit_init(); |
Alexandre Belloni | f71f2e9 | 2013-07-01 15:23:22 +0200 | [diff] [blame] | 431 | else if (of_machine_is_compatible("crystalfontz,cfa10036")) |
Brian Lilly | ed138c3 | 2013-06-13 15:43:44 +0200 | [diff] [blame] | 432 | crystalfontz_init(); |
Eric Bénard | 9a4cc05 | 2013-12-05 14:28:06 +0100 | [diff] [blame] | 433 | else if (of_machine_is_compatible("eukrea,mbmx283lc")) |
| 434 | eukrea_mbmx283lc_init(); |
Michael Heimpold | ff8abc2 | 2017-04-10 11:08:55 +0200 | [diff] [blame] | 435 | else if (of_machine_is_compatible("i2se,duckbill") || |
| 436 | of_machine_is_compatible("i2se,duckbill-2")) |
Michael Heimpold | df0355f | 2013-11-09 12:14:16 +0100 | [diff] [blame] | 437 | duckbill_init(); |
Marek Vasut | e0ec2f3 | 2013-09-30 00:41:29 +0200 | [diff] [blame] | 438 | else if (of_machine_is_compatible("msr,m28cu3")) |
| 439 | m28cu3_init(); |
Dong Aisheng | bc3a59c | 2012-03-31 21:26:57 +0800 | [diff] [blame] | 440 | |
Kefeng Wang | 435ebcb | 2016-06-01 14:53:05 +0800 | [diff] [blame] | 441 | of_platform_default_populate(NULL, NULL, parent); |
Shawn Guo | 2c7c2c1 | 2012-07-13 14:15:34 +0800 | [diff] [blame] | 442 | |
Lothar Waßmann | 56b7eec | 2013-08-05 10:51:14 +0200 | [diff] [blame] | 443 | mxs_restart_init(); |
Dong Aisheng | bc3a59c | 2012-03-31 21:26:57 +0800 | [diff] [blame] | 444 | } |
| 445 | |
Shawn Guo | 974a9af | 2013-03-29 09:45:31 +0800 | [diff] [blame] | 446 | #define MXS_CLKCTRL_RESET_CHIP (1 << 1) |
| 447 | |
| 448 | /* |
| 449 | * Reset the system. It is called by machine_restart(). |
| 450 | */ |
Robin Holt | 7b6d864 | 2013-07-08 16:01:40 -0700 | [diff] [blame] | 451 | static void mxs_restart(enum reboot_mode mode, const char *cmd) |
Shawn Guo | 974a9af | 2013-03-29 09:45:31 +0800 | [diff] [blame] | 452 | { |
Lothar Waßmann | 56b7eec | 2013-08-05 10:51:14 +0200 | [diff] [blame] | 453 | if (reset_addr) { |
| 454 | /* reset the chip */ |
| 455 | __mxs_setl(MXS_CLKCTRL_RESET_CHIP, reset_addr); |
Shawn Guo | 974a9af | 2013-03-29 09:45:31 +0800 | [diff] [blame] | 456 | |
Lothar Waßmann | 56b7eec | 2013-08-05 10:51:14 +0200 | [diff] [blame] | 457 | pr_err("Failed to assert the chip reset\n"); |
Shawn Guo | 974a9af | 2013-03-29 09:45:31 +0800 | [diff] [blame] | 458 | |
Lothar Waßmann | 56b7eec | 2013-08-05 10:51:14 +0200 | [diff] [blame] | 459 | /* Delay to allow the serial port to show the message */ |
| 460 | mdelay(50); |
| 461 | } |
Shawn Guo | 974a9af | 2013-03-29 09:45:31 +0800 | [diff] [blame] | 462 | |
Shawn Guo | 974a9af | 2013-03-29 09:45:31 +0800 | [diff] [blame] | 463 | /* We'll take a jump through zero as a poor second */ |
| 464 | soft_restart(0); |
| 465 | } |
| 466 | |
Nicolas Pitre | 19c233b | 2015-07-27 18:27:52 -0400 | [diff] [blame] | 467 | static const char *const mxs_dt_compat[] __initconst = { |
Shawn Guo | 39490ab | 2013-03-29 14:04:07 +0800 | [diff] [blame] | 468 | "fsl,imx28", |
Shawn Guo | 2954ff3 | 2012-05-04 21:33:42 +0800 | [diff] [blame] | 469 | "fsl,imx23", |
| 470 | NULL, |
| 471 | }; |
| 472 | |
Shawn Guo | 39490ab | 2013-03-29 14:04:07 +0800 | [diff] [blame] | 473 | DT_MACHINE_START(MXS, "Freescale MXS (Device Tree)") |
Shawn Guo | 4e0a1b8 | 2012-08-20 10:14:56 +0800 | [diff] [blame] | 474 | .handle_irq = icoll_handle_irq, |
Shawn Guo | 2954ff3 | 2012-05-04 21:33:42 +0800 | [diff] [blame] | 475 | .init_machine = mxs_machine_init, |
Shawn Guo | 4568099 | 2013-03-29 14:41:27 +0800 | [diff] [blame] | 476 | .init_late = mxs_pm_init, |
Shawn Guo | 39490ab | 2013-03-29 14:04:07 +0800 | [diff] [blame] | 477 | .dt_compat = mxs_dt_compat, |
Dong Aisheng | bc3a59c | 2012-03-31 21:26:57 +0800 | [diff] [blame] | 478 | .restart = mxs_restart, |
| 479 | MACHINE_END |