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