Dong Aisheng | bc3a59c | 2012-03-31 21:26:57 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 Freescale Semiconductor, Inc. |
| 3 | * Copyright 2012 Linaro Ltd. |
| 4 | * |
| 5 | * The code contained herein is licensed under the GNU General Public |
| 6 | * License. You may obtain a copy of the GNU General Public License |
| 7 | * Version 2 or later at the following locations: |
| 8 | * |
| 9 | * http://www.opensource.org/licenses/gpl-license.html |
| 10 | * http://www.gnu.org/copyleft/gpl.html |
| 11 | */ |
| 12 | |
| 13 | #include <linux/clk.h> |
Shawn Guo | 3cb7825 | 2013-03-29 13:36:05 +0800 | [diff] [blame] | 14 | #include <linux/clk/mxs.h> |
Dong Aisheng | bc3a59c | 2012-03-31 21:26:57 +0800 | [diff] [blame] | 15 | #include <linux/clkdev.h> |
Shawn Guo | 633ef4c | 2013-03-25 14:53:08 +0800 | [diff] [blame] | 16 | #include <linux/clocksource.h> |
Shawn Guo | 44ffb78 | 2012-08-06 22:00:45 +0800 | [diff] [blame] | 17 | #include <linux/can/platform/flexcan.h> |
Shawn Guo | 2c7c2c1 | 2012-07-13 14:15:34 +0800 | [diff] [blame] | 18 | #include <linux/delay.h> |
Dong Aisheng | bc3a59c | 2012-03-31 21:26:57 +0800 | [diff] [blame] | 19 | #include <linux/err.h> |
Shawn Guo | 2c7c2c1 | 2012-07-13 14:15:34 +0800 | [diff] [blame] | 20 | #include <linux/gpio.h> |
Dong Aisheng | bc3a59c | 2012-03-31 21:26:57 +0800 | [diff] [blame] | 21 | #include <linux/init.h> |
Shawn Guo | 6a8e95b | 2013-03-25 21:34:51 +0800 | [diff] [blame] | 22 | #include <linux/irqchip.h> |
| 23 | #include <linux/irqchip/mxs.h> |
Shawn Guo | 3143bbb | 2012-07-07 23:12:03 +0800 | [diff] [blame] | 24 | #include <linux/micrel_phy.h> |
Shawn Guo | ab2815c | 2012-06-25 21:21:46 +0800 | [diff] [blame] | 25 | #include <linux/mxsfb.h> |
Shawn Guo | 974a9af | 2013-03-29 09:45:31 +0800 | [diff] [blame] | 26 | #include <linux/of_address.h> |
Dong Aisheng | bc3a59c | 2012-03-31 21:26:57 +0800 | [diff] [blame] | 27 | #include <linux/of_platform.h> |
Shawn Guo | 3143bbb | 2012-07-07 23:12:03 +0800 | [diff] [blame] | 28 | #include <linux/phy.h> |
Shawn Guo | 2c7c2c1 | 2012-07-13 14:15:34 +0800 | [diff] [blame] | 29 | #include <linux/pinctrl/consumer.h> |
Dong Aisheng | bc3a59c | 2012-03-31 21:26:57 +0800 | [diff] [blame] | 30 | #include <asm/mach/arch.h> |
Shawn Guo | 1f62956 | 2013-03-29 13:07:34 +0800 | [diff] [blame] | 31 | #include <asm/mach/map.h> |
Dong Aisheng | bc3a59c | 2012-03-31 21:26:57 +0800 | [diff] [blame] | 32 | #include <asm/mach/time.h> |
Shawn Guo | 974a9af | 2013-03-29 09:45:31 +0800 | [diff] [blame] | 33 | #include <asm/system_misc.h> |
Shawn Guo | 0b48d3a | 2013-03-29 13:53:11 +0800 | [diff] [blame^] | 34 | |
| 35 | /* MXS DIGCTL SAIF CLKMUX */ |
| 36 | #define MXS_DIGCTL_SAIF_CLKMUX_DIRECT 0x0 |
| 37 | #define MXS_DIGCTL_SAIF_CLKMUX_CROSSINPUT 0x1 |
| 38 | #define MXS_DIGCTL_SAIF_CLKMUX_EXTMSTR0 0x2 |
| 39 | #define MXS_DIGCTL_SAIF_CLKMUX_EXTMSTR1 0x3 |
| 40 | |
| 41 | #define MXS_GPIO_NR(bank, nr) ((bank) * 32 + (nr)) |
| 42 | |
| 43 | #define MXS_SET_ADDR 0x4 |
| 44 | #define MXS_CLR_ADDR 0x8 |
| 45 | #define MXS_TOG_ADDR 0xc |
| 46 | |
| 47 | static inline void __mxs_setl(u32 mask, void __iomem *reg) |
| 48 | { |
| 49 | __raw_writel(mask, reg + MXS_SET_ADDR); |
| 50 | } |
| 51 | |
| 52 | static inline void __mxs_clrl(u32 mask, void __iomem *reg) |
| 53 | { |
| 54 | __raw_writel(mask, reg + MXS_CLR_ADDR); |
| 55 | } |
| 56 | |
| 57 | static inline void __mxs_togl(u32 mask, void __iomem *reg) |
| 58 | { |
| 59 | __raw_writel(mask, reg + MXS_TOG_ADDR); |
| 60 | } |
Dong Aisheng | bc3a59c | 2012-03-31 21:26:57 +0800 | [diff] [blame] | 61 | |
Shawn Guo | ab2815c | 2012-06-25 21:21:46 +0800 | [diff] [blame] | 62 | static struct fb_videomode mx23evk_video_modes[] = { |
| 63 | { |
| 64 | .name = "Samsung-LMS430HF02", |
| 65 | .refresh = 60, |
| 66 | .xres = 480, |
| 67 | .yres = 272, |
| 68 | .pixclock = 108096, /* picosecond (9.2 MHz) */ |
| 69 | .left_margin = 15, |
| 70 | .right_margin = 8, |
| 71 | .upper_margin = 12, |
| 72 | .lower_margin = 4, |
| 73 | .hsync_len = 1, |
| 74 | .vsync_len = 1, |
Shawn Guo | ab2815c | 2012-06-25 21:21:46 +0800 | [diff] [blame] | 75 | }, |
| 76 | }; |
| 77 | |
| 78 | static struct fb_videomode mx28evk_video_modes[] = { |
| 79 | { |
| 80 | .name = "Seiko-43WVF1G", |
| 81 | .refresh = 60, |
| 82 | .xres = 800, |
| 83 | .yres = 480, |
| 84 | .pixclock = 29851, /* picosecond (33.5 MHz) */ |
| 85 | .left_margin = 89, |
| 86 | .right_margin = 164, |
| 87 | .upper_margin = 23, |
| 88 | .lower_margin = 10, |
| 89 | .hsync_len = 10, |
| 90 | .vsync_len = 10, |
Shawn Guo | ab2815c | 2012-06-25 21:21:46 +0800 | [diff] [blame] | 91 | }, |
| 92 | }; |
| 93 | |
Marek Vasut | 8fa62e1 | 2012-07-07 21:21:38 +0800 | [diff] [blame] | 94 | static struct fb_videomode m28evk_video_modes[] = { |
| 95 | { |
| 96 | .name = "Ampire AM-800480R2TMQW-T01H", |
| 97 | .refresh = 60, |
| 98 | .xres = 800, |
| 99 | .yres = 480, |
| 100 | .pixclock = 30066, /* picosecond (33.26 MHz) */ |
| 101 | .left_margin = 0, |
| 102 | .right_margin = 256, |
| 103 | .upper_margin = 0, |
| 104 | .lower_margin = 45, |
| 105 | .hsync_len = 1, |
| 106 | .vsync_len = 1, |
Marek Vasut | 8fa62e1 | 2012-07-07 21:21:38 +0800 | [diff] [blame] | 107 | }, |
| 108 | }; |
| 109 | |
Lauri Hintsala | d8bb823 | 2012-07-10 10:08:08 +0300 | [diff] [blame] | 110 | static struct fb_videomode apx4devkit_video_modes[] = { |
| 111 | { |
| 112 | .name = "HannStar PJ70112A", |
| 113 | .refresh = 60, |
| 114 | .xres = 800, |
| 115 | .yres = 480, |
| 116 | .pixclock = 33333, /* picosecond (30.00 MHz) */ |
| 117 | .left_margin = 88, |
| 118 | .right_margin = 40, |
| 119 | .upper_margin = 32, |
| 120 | .lower_margin = 13, |
| 121 | .hsync_len = 48, |
| 122 | .vsync_len = 3, |
Marek Vasut | 6a15075 | 2013-03-18 19:24:02 +0100 | [diff] [blame] | 123 | .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, |
Lauri Hintsala | d8bb823 | 2012-07-10 10:08:08 +0300 | [diff] [blame] | 124 | }, |
| 125 | }; |
| 126 | |
Gwenhael Goavec-Merou | a4dabca | 2012-11-02 19:01:48 +0100 | [diff] [blame] | 127 | static struct fb_videomode apf28dev_video_modes[] = { |
| 128 | { |
| 129 | .name = "LW700", |
| 130 | .refresh = 60, |
| 131 | .xres = 800, |
| 132 | .yres = 480, |
| 133 | .pixclock = 30303, /* picosecond */ |
| 134 | .left_margin = 96, |
| 135 | .right_margin = 96, /* at least 3 & 1 */ |
| 136 | .upper_margin = 0x14, |
| 137 | .lower_margin = 0x15, |
| 138 | .hsync_len = 64, |
| 139 | .vsync_len = 4, |
Marek Vasut | 6a15075 | 2013-03-18 19:24:02 +0100 | [diff] [blame] | 140 | .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, |
Gwenhael Goavec-Merou | a4dabca | 2012-11-02 19:01:48 +0100 | [diff] [blame] | 141 | }, |
| 142 | }; |
| 143 | |
Maxime Ripard | 1fe4274 | 2013-01-25 09:54:07 +0100 | [diff] [blame] | 144 | static struct fb_videomode cfa10049_video_modes[] = { |
| 145 | { |
| 146 | .name = "Himax HX8357-B", |
| 147 | .refresh = 60, |
| 148 | .xres = 320, |
| 149 | .yres = 480, |
| 150 | .pixclock = 108506, /* picosecond (9.216 MHz) */ |
| 151 | .left_margin = 2, |
| 152 | .right_margin = 2, |
| 153 | .upper_margin = 2, |
| 154 | .lower_margin = 2, |
| 155 | .hsync_len = 15, |
| 156 | .vsync_len = 15, |
Maxime Ripard | 1fe4274 | 2013-01-25 09:54:07 +0100 | [diff] [blame] | 157 | }, |
| 158 | }; |
| 159 | |
Shawn Guo | ab2815c | 2012-06-25 21:21:46 +0800 | [diff] [blame] | 160 | static struct mxsfb_platform_data mxsfb_pdata __initdata; |
| 161 | |
Shawn Guo | 44ffb78 | 2012-08-06 22:00:45 +0800 | [diff] [blame] | 162 | /* |
| 163 | * MX28EVK_FLEXCAN_SWITCH is shared between both flexcan controllers |
| 164 | */ |
| 165 | #define MX28EVK_FLEXCAN_SWITCH MXS_GPIO_NR(2, 13) |
| 166 | |
| 167 | static int flexcan0_en, flexcan1_en; |
| 168 | |
| 169 | static void mx28evk_flexcan_switch(void) |
| 170 | { |
| 171 | if (flexcan0_en || flexcan1_en) |
| 172 | gpio_set_value(MX28EVK_FLEXCAN_SWITCH, 1); |
| 173 | else |
| 174 | gpio_set_value(MX28EVK_FLEXCAN_SWITCH, 0); |
| 175 | } |
| 176 | |
| 177 | static void mx28evk_flexcan0_switch(int enable) |
| 178 | { |
| 179 | flexcan0_en = enable; |
| 180 | mx28evk_flexcan_switch(); |
| 181 | } |
| 182 | |
| 183 | static void mx28evk_flexcan1_switch(int enable) |
| 184 | { |
| 185 | flexcan1_en = enable; |
| 186 | mx28evk_flexcan_switch(); |
| 187 | } |
| 188 | |
| 189 | static struct flexcan_platform_data flexcan_pdata[2]; |
| 190 | |
Shawn Guo | ab2815c | 2012-06-25 21:21:46 +0800 | [diff] [blame] | 191 | static struct of_dev_auxdata mxs_auxdata_lookup[] __initdata = { |
| 192 | OF_DEV_AUXDATA("fsl,imx23-lcdif", 0x80030000, NULL, &mxsfb_pdata), |
| 193 | OF_DEV_AUXDATA("fsl,imx28-lcdif", 0x80030000, NULL, &mxsfb_pdata), |
Shawn Guo | 44ffb78 | 2012-08-06 22:00:45 +0800 | [diff] [blame] | 194 | OF_DEV_AUXDATA("fsl,imx28-flexcan", 0x80032000, NULL, &flexcan_pdata[0]), |
| 195 | OF_DEV_AUXDATA("fsl,imx28-flexcan", 0x80034000, NULL, &flexcan_pdata[1]), |
Shawn Guo | ab2815c | 2012-06-25 21:21:46 +0800 | [diff] [blame] | 196 | { /* sentinel */ } |
| 197 | }; |
| 198 | |
Shawn Guo | 1bff2d7 | 2013-03-29 13:27:55 +0800 | [diff] [blame] | 199 | #define OCOTP_WORD_OFFSET 0x20 |
| 200 | #define OCOTP_WORD_COUNT 0x20 |
| 201 | |
| 202 | #define BM_OCOTP_CTRL_BUSY (1 << 8) |
| 203 | #define BM_OCOTP_CTRL_ERROR (1 << 9) |
| 204 | #define BM_OCOTP_CTRL_RD_BANK_OPEN (1 << 12) |
| 205 | |
| 206 | static DEFINE_MUTEX(ocotp_mutex); |
| 207 | static u32 ocotp_words[OCOTP_WORD_COUNT]; |
| 208 | |
| 209 | static const u32 *mxs_get_ocotp(void) |
| 210 | { |
| 211 | struct device_node *np; |
| 212 | void __iomem *ocotp_base; |
| 213 | int timeout = 0x400; |
| 214 | size_t i; |
| 215 | static int once; |
| 216 | |
| 217 | if (once) |
| 218 | return ocotp_words; |
| 219 | |
| 220 | np = of_find_compatible_node(NULL, NULL, "fsl,ocotp"); |
| 221 | ocotp_base = of_iomap(np, 0); |
| 222 | WARN_ON(!ocotp_base); |
| 223 | |
| 224 | mutex_lock(&ocotp_mutex); |
| 225 | |
| 226 | /* |
| 227 | * clk_enable(hbus_clk) for ocotp can be skipped |
| 228 | * as it must be on when system is running. |
| 229 | */ |
| 230 | |
| 231 | /* try to clear ERROR bit */ |
| 232 | __mxs_clrl(BM_OCOTP_CTRL_ERROR, ocotp_base); |
| 233 | |
| 234 | /* check both BUSY and ERROR cleared */ |
| 235 | while ((__raw_readl(ocotp_base) & |
| 236 | (BM_OCOTP_CTRL_BUSY | BM_OCOTP_CTRL_ERROR)) && --timeout) |
| 237 | cpu_relax(); |
| 238 | |
| 239 | if (unlikely(!timeout)) |
| 240 | goto error_unlock; |
| 241 | |
| 242 | /* open OCOTP banks for read */ |
| 243 | __mxs_setl(BM_OCOTP_CTRL_RD_BANK_OPEN, ocotp_base); |
| 244 | |
| 245 | /* approximately wait 32 hclk cycles */ |
| 246 | udelay(1); |
| 247 | |
| 248 | /* poll BUSY bit becoming cleared */ |
| 249 | timeout = 0x400; |
| 250 | while ((__raw_readl(ocotp_base) & BM_OCOTP_CTRL_BUSY) && --timeout) |
| 251 | cpu_relax(); |
| 252 | |
| 253 | if (unlikely(!timeout)) |
| 254 | goto error_unlock; |
| 255 | |
| 256 | for (i = 0; i < OCOTP_WORD_COUNT; i++) |
| 257 | ocotp_words[i] = __raw_readl(ocotp_base + OCOTP_WORD_OFFSET + |
| 258 | i * 0x10); |
| 259 | |
| 260 | /* close banks for power saving */ |
| 261 | __mxs_clrl(BM_OCOTP_CTRL_RD_BANK_OPEN, ocotp_base); |
| 262 | |
| 263 | once = 1; |
| 264 | |
| 265 | mutex_unlock(&ocotp_mutex); |
| 266 | |
| 267 | return ocotp_words; |
| 268 | |
| 269 | error_unlock: |
| 270 | mutex_unlock(&ocotp_mutex); |
| 271 | pr_err("%s: timeout in reading OCOTP\n", __func__); |
| 272 | return NULL; |
| 273 | } |
| 274 | |
Shawn Guo | 5653acc | 2012-06-19 22:38:14 +0800 | [diff] [blame] | 275 | enum mac_oui { |
| 276 | OUI_FSL, |
| 277 | OUI_DENX, |
Maxime Ripard | 8eec4b3 | 2012-10-07 10:36:28 +0800 | [diff] [blame] | 278 | OUI_CRYSTALFONTZ, |
Shawn Guo | 5653acc | 2012-06-19 22:38:14 +0800 | [diff] [blame] | 279 | }; |
| 280 | |
| 281 | static void __init update_fec_mac_prop(enum mac_oui oui) |
| 282 | { |
| 283 | struct device_node *np, *from = NULL; |
Shawn Guo | fa7c865 | 2012-07-13 14:13:55 +0800 | [diff] [blame] | 284 | struct property *newmac; |
Shawn Guo | 5653acc | 2012-06-19 22:38:14 +0800 | [diff] [blame] | 285 | const u32 *ocotp = mxs_get_ocotp(); |
| 286 | u8 *macaddr; |
| 287 | u32 val; |
| 288 | int i; |
| 289 | |
| 290 | for (i = 0; i < 2; i++) { |
| 291 | np = of_find_compatible_node(from, NULL, "fsl,imx28-fec"); |
| 292 | if (!np) |
| 293 | return; |
Marek Vasut | 16d4770 | 2012-09-25 13:32:18 +0200 | [diff] [blame] | 294 | |
Shawn Guo | 5653acc | 2012-06-19 22:38:14 +0800 | [diff] [blame] | 295 | from = np; |
| 296 | |
Marek Vasut | 16d4770 | 2012-09-25 13:32:18 +0200 | [diff] [blame] | 297 | if (of_get_property(np, "local-mac-address", NULL)) |
| 298 | continue; |
| 299 | |
Shawn Guo | 5653acc | 2012-06-19 22:38:14 +0800 | [diff] [blame] | 300 | newmac = kzalloc(sizeof(*newmac) + 6, GFP_KERNEL); |
| 301 | if (!newmac) |
| 302 | return; |
| 303 | newmac->value = newmac + 1; |
| 304 | newmac->length = 6; |
| 305 | |
| 306 | newmac->name = kstrdup("local-mac-address", GFP_KERNEL); |
| 307 | if (!newmac->name) { |
| 308 | kfree(newmac); |
| 309 | return; |
| 310 | } |
| 311 | |
| 312 | /* |
| 313 | * OCOTP only stores the last 4 octets for each mac address, |
| 314 | * so hard-code OUI here. |
| 315 | */ |
| 316 | macaddr = newmac->value; |
| 317 | switch (oui) { |
| 318 | case OUI_FSL: |
| 319 | macaddr[0] = 0x00; |
| 320 | macaddr[1] = 0x04; |
| 321 | macaddr[2] = 0x9f; |
| 322 | break; |
| 323 | case OUI_DENX: |
| 324 | macaddr[0] = 0xc0; |
| 325 | macaddr[1] = 0xe5; |
| 326 | macaddr[2] = 0x4e; |
| 327 | break; |
Maxime Ripard | 8eec4b3 | 2012-10-07 10:36:28 +0800 | [diff] [blame] | 328 | case OUI_CRYSTALFONTZ: |
| 329 | macaddr[0] = 0x58; |
| 330 | macaddr[1] = 0xb9; |
| 331 | macaddr[2] = 0xe1; |
| 332 | break; |
Shawn Guo | 5653acc | 2012-06-19 22:38:14 +0800 | [diff] [blame] | 333 | } |
| 334 | val = ocotp[i]; |
| 335 | macaddr[3] = (val >> 16) & 0xff; |
| 336 | macaddr[4] = (val >> 8) & 0xff; |
| 337 | macaddr[5] = (val >> 0) & 0xff; |
| 338 | |
Nathan Fontenot | 79d1c71 | 2012-10-02 16:58:46 +0000 | [diff] [blame] | 339 | of_update_property(np, newmac); |
Shawn Guo | 5653acc | 2012-06-19 22:38:14 +0800 | [diff] [blame] | 340 | } |
| 341 | } |
| 342 | |
Shawn Guo | ab2815c | 2012-06-25 21:21:46 +0800 | [diff] [blame] | 343 | static void __init imx23_evk_init(void) |
| 344 | { |
| 345 | mxsfb_pdata.mode_list = mx23evk_video_modes; |
| 346 | mxsfb_pdata.mode_count = ARRAY_SIZE(mx23evk_video_modes); |
| 347 | mxsfb_pdata.default_bpp = 32; |
| 348 | mxsfb_pdata.ld_intf_width = STMLCDIF_24BIT; |
Marek Vasut | 6a15075 | 2013-03-18 19:24:02 +0100 | [diff] [blame] | 349 | mxsfb_pdata.sync = MXSFB_SYNC_DATA_ENABLE_HIGH_ACT | |
| 350 | MXSFB_SYNC_DOTCLK_FAILING_ACT; |
Shawn Guo | ab2815c | 2012-06-25 21:21:46 +0800 | [diff] [blame] | 351 | } |
| 352 | |
Marek Vasut | 8fa62e1 | 2012-07-07 21:21:38 +0800 | [diff] [blame] | 353 | static inline void enable_clk_enet_out(void) |
Dong Aisheng | bc3a59c | 2012-03-31 21:26:57 +0800 | [diff] [blame] | 354 | { |
Marek Vasut | 8fa62e1 | 2012-07-07 21:21:38 +0800 | [diff] [blame] | 355 | struct clk *clk = clk_get_sys("enet_out", NULL); |
Dong Aisheng | bc3a59c | 2012-03-31 21:26:57 +0800 | [diff] [blame] | 356 | |
Dong Aisheng | bc3a59c | 2012-03-31 21:26:57 +0800 | [diff] [blame] | 357 | if (!IS_ERR(clk)) |
| 358 | clk_prepare_enable(clk); |
Marek Vasut | 8fa62e1 | 2012-07-07 21:21:38 +0800 | [diff] [blame] | 359 | } |
Shawn Guo | 5653acc | 2012-06-19 22:38:14 +0800 | [diff] [blame] | 360 | |
Marek Vasut | 8fa62e1 | 2012-07-07 21:21:38 +0800 | [diff] [blame] | 361 | static void __init imx28_evk_init(void) |
| 362 | { |
| 363 | enable_clk_enet_out(); |
Shawn Guo | 5653acc | 2012-06-19 22:38:14 +0800 | [diff] [blame] | 364 | update_fec_mac_prop(OUI_FSL); |
Shawn Guo | ab2815c | 2012-06-25 21:21:46 +0800 | [diff] [blame] | 365 | |
| 366 | mxsfb_pdata.mode_list = mx28evk_video_modes; |
| 367 | mxsfb_pdata.mode_count = ARRAY_SIZE(mx28evk_video_modes); |
| 368 | mxsfb_pdata.default_bpp = 32; |
| 369 | mxsfb_pdata.ld_intf_width = STMLCDIF_24BIT; |
Marek Vasut | 6a15075 | 2013-03-18 19:24:02 +0100 | [diff] [blame] | 370 | mxsfb_pdata.sync = MXSFB_SYNC_DATA_ENABLE_HIGH_ACT | |
| 371 | MXSFB_SYNC_DOTCLK_FAILING_ACT; |
Dong Aisheng | e317317 | 2012-08-01 11:20:16 +0800 | [diff] [blame] | 372 | |
| 373 | mxs_saif_clkmux_select(MXS_DIGCTL_SAIF_CLKMUX_EXTMSTR0); |
Dong Aisheng | bc3a59c | 2012-03-31 21:26:57 +0800 | [diff] [blame] | 374 | } |
| 375 | |
Shawn Guo | 44ffb78 | 2012-08-06 22:00:45 +0800 | [diff] [blame] | 376 | static void __init imx28_evk_post_init(void) |
| 377 | { |
| 378 | if (!gpio_request_one(MX28EVK_FLEXCAN_SWITCH, GPIOF_DIR_OUT, |
| 379 | "flexcan-switch")) { |
| 380 | flexcan_pdata[0].transceiver_switch = mx28evk_flexcan0_switch; |
| 381 | flexcan_pdata[1].transceiver_switch = mx28evk_flexcan1_switch; |
| 382 | } |
Dong Aisheng | bc3a59c | 2012-03-31 21:26:57 +0800 | [diff] [blame] | 383 | } |
| 384 | |
Marek Vasut | 8fa62e1 | 2012-07-07 21:21:38 +0800 | [diff] [blame] | 385 | static void __init m28evk_init(void) |
| 386 | { |
Marek Vasut | 8fa62e1 | 2012-07-07 21:21:38 +0800 | [diff] [blame] | 387 | mxsfb_pdata.mode_list = m28evk_video_modes; |
| 388 | mxsfb_pdata.mode_count = ARRAY_SIZE(m28evk_video_modes); |
| 389 | mxsfb_pdata.default_bpp = 16; |
| 390 | mxsfb_pdata.ld_intf_width = STMLCDIF_18BIT; |
Marek Vasut | 6a15075 | 2013-03-18 19:24:02 +0100 | [diff] [blame] | 391 | mxsfb_pdata.sync = MXSFB_SYNC_DATA_ENABLE_HIGH_ACT; |
Marek Vasut | 8fa62e1 | 2012-07-07 21:21:38 +0800 | [diff] [blame] | 392 | } |
| 393 | |
Marek Vasut | 160d5f2 | 2012-11-18 22:08:29 +0100 | [diff] [blame] | 394 | static void __init sc_sps1_init(void) |
| 395 | { |
| 396 | enable_clk_enet_out(); |
| 397 | } |
| 398 | |
Shawn Guo | 3143bbb | 2012-07-07 23:12:03 +0800 | [diff] [blame] | 399 | static int apx4devkit_phy_fixup(struct phy_device *phy) |
| 400 | { |
| 401 | phy->dev_flags |= MICREL_PHY_50MHZ_CLK; |
| 402 | return 0; |
| 403 | } |
| 404 | |
| 405 | static void __init apx4devkit_init(void) |
| 406 | { |
| 407 | enable_clk_enet_out(); |
| 408 | |
| 409 | if (IS_BUILTIN(CONFIG_PHYLIB)) |
Marek Vasut | 510d573 | 2012-09-23 16:58:50 +0000 | [diff] [blame] | 410 | phy_register_fixup_for_uid(PHY_ID_KSZ8051, MICREL_PHY_ID_MASK, |
Shawn Guo | 3143bbb | 2012-07-07 23:12:03 +0800 | [diff] [blame] | 411 | apx4devkit_phy_fixup); |
Lauri Hintsala | d8bb823 | 2012-07-10 10:08:08 +0300 | [diff] [blame] | 412 | |
| 413 | mxsfb_pdata.mode_list = apx4devkit_video_modes; |
| 414 | mxsfb_pdata.mode_count = ARRAY_SIZE(apx4devkit_video_modes); |
| 415 | mxsfb_pdata.default_bpp = 32; |
| 416 | mxsfb_pdata.ld_intf_width = STMLCDIF_24BIT; |
Marek Vasut | 6a15075 | 2013-03-18 19:24:02 +0100 | [diff] [blame] | 417 | mxsfb_pdata.sync = MXSFB_SYNC_DATA_ENABLE_HIGH_ACT | |
| 418 | MXSFB_SYNC_DOTCLK_FAILING_ACT; |
Shawn Guo | 3143bbb | 2012-07-07 23:12:03 +0800 | [diff] [blame] | 419 | } |
| 420 | |
Shawn Guo | 2c7c2c1 | 2012-07-13 14:15:34 +0800 | [diff] [blame] | 421 | #define ENET0_MDC__GPIO_4_0 MXS_GPIO_NR(4, 0) |
| 422 | #define ENET0_MDIO__GPIO_4_1 MXS_GPIO_NR(4, 1) |
| 423 | #define ENET0_RX_EN__GPIO_4_2 MXS_GPIO_NR(4, 2) |
| 424 | #define ENET0_RXD0__GPIO_4_3 MXS_GPIO_NR(4, 3) |
| 425 | #define ENET0_RXD1__GPIO_4_4 MXS_GPIO_NR(4, 4) |
| 426 | #define ENET0_TX_EN__GPIO_4_6 MXS_GPIO_NR(4, 6) |
| 427 | #define ENET0_TXD0__GPIO_4_7 MXS_GPIO_NR(4, 7) |
| 428 | #define ENET0_TXD1__GPIO_4_8 MXS_GPIO_NR(4, 8) |
| 429 | #define ENET_CLK__GPIO_4_16 MXS_GPIO_NR(4, 16) |
| 430 | |
| 431 | #define TX28_FEC_PHY_POWER MXS_GPIO_NR(3, 29) |
| 432 | #define TX28_FEC_PHY_RESET MXS_GPIO_NR(4, 13) |
| 433 | #define TX28_FEC_nINT MXS_GPIO_NR(4, 5) |
| 434 | |
| 435 | static const struct gpio tx28_gpios[] __initconst = { |
| 436 | { ENET0_MDC__GPIO_4_0, GPIOF_OUT_INIT_LOW, "GPIO_4_0" }, |
| 437 | { ENET0_MDIO__GPIO_4_1, GPIOF_OUT_INIT_LOW, "GPIO_4_1" }, |
| 438 | { ENET0_RX_EN__GPIO_4_2, GPIOF_OUT_INIT_LOW, "GPIO_4_2" }, |
| 439 | { ENET0_RXD0__GPIO_4_3, GPIOF_OUT_INIT_LOW, "GPIO_4_3" }, |
| 440 | { ENET0_RXD1__GPIO_4_4, GPIOF_OUT_INIT_LOW, "GPIO_4_4" }, |
| 441 | { ENET0_TX_EN__GPIO_4_6, GPIOF_OUT_INIT_LOW, "GPIO_4_6" }, |
| 442 | { ENET0_TXD0__GPIO_4_7, GPIOF_OUT_INIT_LOW, "GPIO_4_7" }, |
| 443 | { ENET0_TXD1__GPIO_4_8, GPIOF_OUT_INIT_LOW, "GPIO_4_8" }, |
| 444 | { ENET_CLK__GPIO_4_16, GPIOF_OUT_INIT_LOW, "GPIO_4_16" }, |
| 445 | { TX28_FEC_PHY_POWER, GPIOF_OUT_INIT_LOW, "fec-phy-power" }, |
| 446 | { TX28_FEC_PHY_RESET, GPIOF_OUT_INIT_LOW, "fec-phy-reset" }, |
| 447 | { TX28_FEC_nINT, GPIOF_DIR_IN, "fec-int" }, |
| 448 | }; |
| 449 | |
| 450 | static void __init tx28_post_init(void) |
| 451 | { |
| 452 | struct device_node *np; |
| 453 | struct platform_device *pdev; |
| 454 | struct pinctrl *pctl; |
| 455 | int ret; |
| 456 | |
| 457 | enable_clk_enet_out(); |
| 458 | |
| 459 | np = of_find_compatible_node(NULL, NULL, "fsl,imx28-fec"); |
| 460 | pdev = of_find_device_by_node(np); |
| 461 | if (!pdev) { |
| 462 | pr_err("%s: failed to find fec device\n", __func__); |
| 463 | return; |
| 464 | } |
| 465 | |
| 466 | pctl = pinctrl_get_select(&pdev->dev, "gpio_mode"); |
| 467 | if (IS_ERR(pctl)) { |
| 468 | pr_err("%s: failed to get pinctrl state\n", __func__); |
| 469 | return; |
| 470 | } |
| 471 | |
| 472 | ret = gpio_request_array(tx28_gpios, ARRAY_SIZE(tx28_gpios)); |
| 473 | if (ret) { |
| 474 | pr_err("%s: failed to request gpios: %d\n", __func__, ret); |
| 475 | return; |
| 476 | } |
| 477 | |
| 478 | /* Power up fec phy */ |
| 479 | gpio_set_value(TX28_FEC_PHY_POWER, 1); |
| 480 | msleep(26); /* 25ms according to data sheet */ |
| 481 | |
| 482 | /* Mode strap pins */ |
| 483 | gpio_set_value(ENET0_RX_EN__GPIO_4_2, 1); |
| 484 | gpio_set_value(ENET0_RXD0__GPIO_4_3, 1); |
| 485 | gpio_set_value(ENET0_RXD1__GPIO_4_4, 1); |
| 486 | |
| 487 | udelay(100); /* minimum assertion time for nRST */ |
| 488 | |
| 489 | /* Deasserting FEC PHY RESET */ |
| 490 | gpio_set_value(TX28_FEC_PHY_RESET, 1); |
| 491 | |
| 492 | pinctrl_put(pctl); |
| 493 | } |
| 494 | |
Maxime Ripard | 8eec4b3 | 2012-10-07 10:36:28 +0800 | [diff] [blame] | 495 | static void __init cfa10049_init(void) |
| 496 | { |
| 497 | enable_clk_enet_out(); |
| 498 | update_fec_mac_prop(OUI_CRYSTALFONTZ); |
Maxime Ripard | 4a38a85 | 2013-03-05 16:13:35 +0100 | [diff] [blame] | 499 | |
| 500 | mxsfb_pdata.mode_list = cfa10049_video_modes; |
| 501 | mxsfb_pdata.mode_count = ARRAY_SIZE(cfa10049_video_modes); |
| 502 | mxsfb_pdata.default_bpp = 32; |
| 503 | mxsfb_pdata.ld_intf_width = STMLCDIF_18BIT; |
Marek Vasut | 6a15075 | 2013-03-18 19:24:02 +0100 | [diff] [blame] | 504 | mxsfb_pdata.sync = MXSFB_SYNC_DATA_ENABLE_HIGH_ACT; |
Maxime Ripard | 8eec4b3 | 2012-10-07 10:36:28 +0800 | [diff] [blame] | 505 | } |
| 506 | |
Maxime Ripard | e0f7d90 | 2013-01-26 13:40:37 +0800 | [diff] [blame] | 507 | static void __init cfa10037_init(void) |
| 508 | { |
| 509 | enable_clk_enet_out(); |
| 510 | update_fec_mac_prop(OUI_CRYSTALFONTZ); |
| 511 | } |
| 512 | |
Julien Boibessot | a957fdc | 2012-10-18 11:50:26 +0200 | [diff] [blame] | 513 | static void __init apf28_init(void) |
| 514 | { |
| 515 | enable_clk_enet_out(); |
Gwenhael Goavec-Merou | a4dabca | 2012-11-02 19:01:48 +0100 | [diff] [blame] | 516 | |
| 517 | mxsfb_pdata.mode_list = apf28dev_video_modes; |
| 518 | mxsfb_pdata.mode_count = ARRAY_SIZE(apf28dev_video_modes); |
| 519 | mxsfb_pdata.default_bpp = 16; |
| 520 | mxsfb_pdata.ld_intf_width = STMLCDIF_16BIT; |
Marek Vasut | 6a15075 | 2013-03-18 19:24:02 +0100 | [diff] [blame] | 521 | mxsfb_pdata.sync = MXSFB_SYNC_DATA_ENABLE_HIGH_ACT | |
| 522 | MXSFB_SYNC_DOTCLK_FAILING_ACT; |
Julien Boibessot | a957fdc | 2012-10-18 11:50:26 +0200 | [diff] [blame] | 523 | } |
| 524 | |
Dong Aisheng | bc3a59c | 2012-03-31 21:26:57 +0800 | [diff] [blame] | 525 | static void __init mxs_machine_init(void) |
| 526 | { |
| 527 | if (of_machine_is_compatible("fsl,imx28-evk")) |
| 528 | imx28_evk_init(); |
Shawn Guo | ab2815c | 2012-06-25 21:21:46 +0800 | [diff] [blame] | 529 | else if (of_machine_is_compatible("fsl,imx23-evk")) |
| 530 | imx23_evk_init(); |
Marek Vasut | 8fa62e1 | 2012-07-07 21:21:38 +0800 | [diff] [blame] | 531 | else if (of_machine_is_compatible("denx,m28evk")) |
| 532 | m28evk_init(); |
Shawn Guo | 3143bbb | 2012-07-07 23:12:03 +0800 | [diff] [blame] | 533 | else if (of_machine_is_compatible("bluegiga,apx4devkit")) |
| 534 | apx4devkit_init(); |
Maxime Ripard | e0f7d90 | 2013-01-26 13:40:37 +0800 | [diff] [blame] | 535 | else if (of_machine_is_compatible("crystalfontz,cfa10037")) |
| 536 | cfa10037_init(); |
Maxime Ripard | 8eec4b3 | 2012-10-07 10:36:28 +0800 | [diff] [blame] | 537 | else if (of_machine_is_compatible("crystalfontz,cfa10049")) |
| 538 | cfa10049_init(); |
Julien Boibessot | a957fdc | 2012-10-18 11:50:26 +0200 | [diff] [blame] | 539 | else if (of_machine_is_compatible("armadeus,imx28-apf28")) |
| 540 | apf28_init(); |
Marek Vasut | 160d5f2 | 2012-11-18 22:08:29 +0100 | [diff] [blame] | 541 | else if (of_machine_is_compatible("schulercontrol,imx28-sps1")) |
| 542 | sc_sps1_init(); |
Dong Aisheng | bc3a59c | 2012-03-31 21:26:57 +0800 | [diff] [blame] | 543 | |
| 544 | of_platform_populate(NULL, of_default_bus_match_table, |
Shawn Guo | ab2815c | 2012-06-25 21:21:46 +0800 | [diff] [blame] | 545 | mxs_auxdata_lookup, NULL); |
Shawn Guo | 2c7c2c1 | 2012-07-13 14:15:34 +0800 | [diff] [blame] | 546 | |
| 547 | if (of_machine_is_compatible("karo,tx28")) |
| 548 | tx28_post_init(); |
Shawn Guo | 44ffb78 | 2012-08-06 22:00:45 +0800 | [diff] [blame] | 549 | |
| 550 | if (of_machine_is_compatible("fsl,imx28-evk")) |
| 551 | imx28_evk_post_init(); |
Dong Aisheng | bc3a59c | 2012-03-31 21:26:57 +0800 | [diff] [blame] | 552 | } |
| 553 | |
Shawn Guo | 974a9af | 2013-03-29 09:45:31 +0800 | [diff] [blame] | 554 | #define MX23_CLKCTRL_RESET_OFFSET 0x120 |
| 555 | #define MX28_CLKCTRL_RESET_OFFSET 0x1e0 |
| 556 | #define MXS_CLKCTRL_RESET_CHIP (1 << 1) |
| 557 | |
| 558 | /* |
| 559 | * Reset the system. It is called by machine_restart(). |
| 560 | */ |
| 561 | static void mxs_restart(char mode, const char *cmd) |
| 562 | { |
| 563 | struct device_node *np; |
| 564 | void __iomem *reset_addr; |
| 565 | |
| 566 | np = of_find_compatible_node(NULL, NULL, "fsl,clkctrl"); |
| 567 | reset_addr = of_iomap(np, 0); |
| 568 | if (!reset_addr) |
| 569 | goto soft; |
| 570 | |
| 571 | if (of_device_is_compatible(np, "fsl,imx23-clkctrl")) |
| 572 | reset_addr += MX23_CLKCTRL_RESET_OFFSET; |
| 573 | else |
| 574 | reset_addr += MX28_CLKCTRL_RESET_OFFSET; |
| 575 | |
| 576 | /* reset the chip */ |
| 577 | __mxs_setl(MXS_CLKCTRL_RESET_CHIP, reset_addr); |
| 578 | |
| 579 | pr_err("Failed to assert the chip reset\n"); |
| 580 | |
| 581 | /* Delay to allow the serial port to show the message */ |
| 582 | mdelay(50); |
| 583 | |
| 584 | soft: |
| 585 | /* We'll take a jump through zero as a poor second */ |
| 586 | soft_restart(0); |
| 587 | } |
| 588 | |
Shawn Guo | 39490ab | 2013-03-29 14:04:07 +0800 | [diff] [blame] | 589 | static void __init mxs_timer_init(void) |
| 590 | { |
| 591 | if (of_machine_is_compatible("fsl,imx23")) |
| 592 | mx23_clocks_init(); |
| 593 | else |
| 594 | mx28_clocks_init(); |
| 595 | clocksource_of_init(); |
| 596 | } |
| 597 | |
| 598 | static const char *mxs_dt_compat[] __initdata = { |
| 599 | "fsl,imx28", |
Shawn Guo | 2954ff3 | 2012-05-04 21:33:42 +0800 | [diff] [blame] | 600 | "fsl,imx23", |
| 601 | NULL, |
| 602 | }; |
| 603 | |
Shawn Guo | 39490ab | 2013-03-29 14:04:07 +0800 | [diff] [blame] | 604 | DT_MACHINE_START(MXS, "Freescale MXS (Device Tree)") |
Shawn Guo | 1f62956 | 2013-03-29 13:07:34 +0800 | [diff] [blame] | 605 | .map_io = debug_ll_io_init, |
Shawn Guo | 6a8e95b | 2013-03-25 21:34:51 +0800 | [diff] [blame] | 606 | .init_irq = irqchip_init, |
Shawn Guo | 4e0a1b8 | 2012-08-20 10:14:56 +0800 | [diff] [blame] | 607 | .handle_irq = icoll_handle_irq, |
Shawn Guo | 39490ab | 2013-03-29 14:04:07 +0800 | [diff] [blame] | 608 | .init_time = mxs_timer_init, |
Shawn Guo | 2954ff3 | 2012-05-04 21:33:42 +0800 | [diff] [blame] | 609 | .init_machine = mxs_machine_init, |
Shawn Guo | 39490ab | 2013-03-29 14:04:07 +0800 | [diff] [blame] | 610 | .dt_compat = mxs_dt_compat, |
Dong Aisheng | bc3a59c | 2012-03-31 21:26:57 +0800 | [diff] [blame] | 611 | .restart = mxs_restart, |
| 612 | MACHINE_END |