]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/karo/tx48/tx48.c
Merge branch 'tx51-bugfix' into karo-tx-merge
[karo-tx-uboot.git] / board / karo / tx48 / tx48.c
1 /*
2  * tx48.c
3  * Copyright (C) 2012 Lothar Waßmann <LW@KARO-electronics.de>
4  *
5  * based on evm.c
6  * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License as
10  * published by the Free Software Foundation version 2.
11  *
12  * This program is distributed "as is" WITHOUT ANY WARRANTY of any
13  * kind, whether express or implied; without even the implied warranty
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  */
17
18 #include <common.h>
19 #include <errno.h>
20 #include <miiphy.h>
21 #include <netdev.h>
22 #include <serial.h>
23 #include <libfdt.h>
24 #include <lcd.h>
25 #include <fdt_support.h>
26 #include <nand.h>
27 #include <net.h>
28 #include <linux/mtd/nand.h>
29 #include <asm/gpio.h>
30 #include <asm/cache.h>
31 #include <asm/omap_common.h>
32 #include <asm/io.h>
33 #include <asm/arch/cpu.h>
34 #include <asm/arch/hardware.h>
35 #include <asm/arch/mmc_host_def.h>
36 #include <asm/arch/sys_proto.h>
37 #include <asm/arch/nand.h>
38 #include <asm/arch/clock.h>
39 #include <video_fb.h>
40 #include <asm/arch/da8xx-fb.h>
41
42 #include "../common/karo.h"
43
44 DECLARE_GLOBAL_DATA_PTR;
45
46 #define TX48_LED_GPIO           AM33XX_GPIO_NR(1, 26)
47 #define TX48_ETH_PHY_RST_GPIO   AM33XX_GPIO_NR(3, 8)
48 #define TX48_LCD_RST_GPIO       AM33XX_GPIO_NR(1, 19)
49 #define TX48_LCD_PWR_GPIO       AM33XX_GPIO_NR(1, 22)
50 #define TX48_LCD_BACKLIGHT_GPIO AM33XX_GPIO_NR(3, 14)
51
52 #define GMII_SEL                (CTRL_BASE + 0x650)
53
54 /* UART Defines */
55 #define UART_SYSCFG_OFFSET      0x54
56 #define UART_SYSSTS_OFFSET      0x58
57
58 #define UART_RESET              (0x1 << 1)
59 #define UART_CLK_RUNNING_MASK   0x1
60 #define UART_SMART_IDLE_EN      (0x1 << 0x3)
61
62 /* Timer Defines */
63 #define TSICR_REG               0x54
64 #define TIOCP_CFG_REG           0x10
65 #define TCLR_REG                0x38
66
67 /* RGMII mode define */
68 #define RGMII_MODE_ENABLE       0xA
69 #define RMII_MODE_ENABLE        0x5
70 #define MII_MODE_ENABLE         0x0
71
72 #define NO_OF_MAC_ADDR          1
73 #define ETH_ALEN                6
74
75 #define MUX_CFG(value, offset)  {                                       \
76         __raw_writel(value, (CTRL_BASE + (offset)));                    \
77         }
78
79 /* PAD Control Fields */
80 #define SLEWCTRL        (0x1 << 6)
81 #define RXACTIVE        (0x1 << 5)
82 #define PULLUP_EN       (0x1 << 4) /* Pull UP Selection */
83 #define PULLUDEN        (0x0 << 3) /* Pull up enabled */
84 #define PULLUDDIS       (0x1 << 3) /* Pull up disabled */
85 #define MODE(val)       (val)
86
87 /*
88  * PAD CONTROL OFFSETS
89  * Field names corresponds to the pad signal name
90  */
91 struct pad_signals {
92         int gpmc_ad0;
93         int gpmc_ad1;
94         int gpmc_ad2;
95         int gpmc_ad3;
96         int gpmc_ad4;
97         int gpmc_ad5;
98         int gpmc_ad6;
99         int gpmc_ad7;
100         int gpmc_ad8;
101         int gpmc_ad9;
102         int gpmc_ad10;
103         int gpmc_ad11;
104         int gpmc_ad12;
105         int gpmc_ad13;
106         int gpmc_ad14;
107         int gpmc_ad15;
108         int gpmc_a0;
109         int gpmc_a1;
110         int gpmc_a2;
111         int gpmc_a3;
112         int gpmc_a4;
113         int gpmc_a5;
114         int gpmc_a6;
115         int gpmc_a7;
116         int gpmc_a8;
117         int gpmc_a9;
118         int gpmc_a10;
119         int gpmc_a11;
120         int gpmc_wait0;
121         int gpmc_wpn;
122         int gpmc_be1n;
123         int gpmc_csn0;
124         int gpmc_csn1;
125         int gpmc_csn2;
126         int gpmc_csn3;
127         int gpmc_clk;
128         int gpmc_advn_ale;
129         int gpmc_oen_ren;
130         int gpmc_wen;
131         int gpmc_be0n_cle;
132         int lcd_data0;
133         int lcd_data1;
134         int lcd_data2;
135         int lcd_data3;
136         int lcd_data4;
137         int lcd_data5;
138         int lcd_data6;
139         int lcd_data7;
140         int lcd_data8;
141         int lcd_data9;
142         int lcd_data10;
143         int lcd_data11;
144         int lcd_data12;
145         int lcd_data13;
146         int lcd_data14;
147         int lcd_data15;
148         int lcd_vsync;
149         int lcd_hsync;
150         int lcd_pclk;
151         int lcd_ac_bias_en;
152         int mmc0_dat3;
153         int mmc0_dat2;
154         int mmc0_dat1;
155         int mmc0_dat0;
156         int mmc0_clk;
157         int mmc0_cmd;
158         int mii1_col;
159         int mii1_crs;
160         int mii1_rxerr;
161         int mii1_txen;
162         int mii1_rxdv;
163         int mii1_txd3;
164         int mii1_txd2;
165         int mii1_txd1;
166         int mii1_txd0;
167         int mii1_txclk;
168         int mii1_rxclk;
169         int mii1_rxd3;
170         int mii1_rxd2;
171         int mii1_rxd1;
172         int mii1_rxd0;
173         int rmii1_refclk;
174         int mdio_data;
175         int mdio_clk;
176         int spi0_sclk;
177         int spi0_d0;
178         int spi0_d1;
179         int spi0_cs0;
180         int spi0_cs1;
181         int ecap0_in_pwm0_out;
182         int uart0_ctsn;
183         int uart0_rtsn;
184         int uart0_rxd;
185         int uart0_txd;
186         int uart1_ctsn;
187         int uart1_rtsn;
188         int uart1_rxd;
189         int uart1_txd;
190         int i2c0_sda;
191         int i2c0_scl;
192         int mcasp0_aclkx;
193         int mcasp0_fsx;
194         int mcasp0_axr0;
195         int mcasp0_ahclkr;
196         int mcasp0_aclkr;
197         int mcasp0_fsr;
198         int mcasp0_axr1;
199         int mcasp0_ahclkx;
200         int xdma_event_intr0;
201         int xdma_event_intr1;
202         int nresetin_out;
203         int porz;
204         int nnmi;
205         int osc0_in;
206         int osc0_out;
207         int rsvd1;
208         int tms;
209         int tdi;
210         int tdo;
211         int tck;
212         int ntrst;
213         int emu0;
214         int emu1;
215         int osc1_in;
216         int osc1_out;
217         int pmic_power_en;
218         int rtc_porz;
219         int rsvd2;
220         int ext_wakeup;
221         int enz_kaldo_1p8v;
222         int usb0_dm;
223         int usb0_dp;
224         int usb0_ce;
225         int usb0_id;
226         int usb0_vbus;
227         int usb0_drvvbus;
228         int usb1_dm;
229         int usb1_dp;
230         int usb1_ce;
231         int usb1_id;
232         int usb1_vbus;
233         int usb1_drvvbus;
234         int ddr_resetn;
235         int ddr_csn0;
236         int ddr_cke;
237         int ddr_ck;
238         int ddr_nck;
239         int ddr_casn;
240         int ddr_rasn;
241         int ddr_wen;
242         int ddr_ba0;
243         int ddr_ba1;
244         int ddr_ba2;
245         int ddr_a0;
246         int ddr_a1;
247         int ddr_a2;
248         int ddr_a3;
249         int ddr_a4;
250         int ddr_a5;
251         int ddr_a6;
252         int ddr_a7;
253         int ddr_a8;
254         int ddr_a9;
255         int ddr_a10;
256         int ddr_a11;
257         int ddr_a12;
258         int ddr_a13;
259         int ddr_a14;
260         int ddr_a15;
261         int ddr_odt;
262         int ddr_d0;
263         int ddr_d1;
264         int ddr_d2;
265         int ddr_d3;
266         int ddr_d4;
267         int ddr_d5;
268         int ddr_d6;
269         int ddr_d7;
270         int ddr_d8;
271         int ddr_d9;
272         int ddr_d10;
273         int ddr_d11;
274         int ddr_d12;
275         int ddr_d13;
276         int ddr_d14;
277         int ddr_d15;
278         int ddr_dqm0;
279         int ddr_dqm1;
280         int ddr_dqs0;
281         int ddr_dqsn0;
282         int ddr_dqs1;
283         int ddr_dqsn1;
284         int ddr_vref;
285         int ddr_vtp;
286         int ddr_strben0;
287         int ddr_strben1;
288         int ain7;
289         int ain6;
290         int ain5;
291         int ain4;
292         int ain3;
293         int ain2;
294         int ain1;
295         int ain0;
296         int vrefp;
297         int vrefn;
298 };
299
300 struct pin_mux {
301         short reg_offset;
302         uint8_t val;
303 };
304
305 #define PAD_CTRL_BASE   0x800
306 #define OFFSET(x)       (unsigned int) (&((struct pad_signals *) \
307                                 (PAD_CTRL_BASE))->x)
308
309 /*
310  * Configure the pin mux for the module
311  */
312 static inline void tx48_set_pin_mux(const struct pin_mux *pin_mux,
313                         int num_pins)
314 {
315         int i;
316
317         for (i = 0; i < num_pins; i++)
318                 MUX_CFG(pin_mux[i].val, pin_mux[i].reg_offset);
319 }
320
321 #define PRM_RSTST_GLOBAL_COLD_RST       (1 << 0)
322 #define PRM_RSTST_GLOBAL_WARM_SW_RST    (1 << 1)
323 #define PRM_RSTST_WDT1_RST              (1 << 4)
324 #define PRM_RSTST_EXTERNAL_WARM_RST     (1 << 5)
325 #define PRM_RSTST_ICEPICK_RST           (1 << 9)
326
327 static u32 prm_rstst __attribute__((section(".data")));
328
329 /*
330  * Basic board specific setup
331  */
332 static const struct pin_mux stk5_pads[] = {
333         /* heartbeat LED */
334         { OFFSET(gpmc_a10), MODE(7) | PULLUDEN, },
335         /* LCD RESET */
336         { OFFSET(gpmc_a3), MODE(7) | PULLUDEN, },
337         /* LCD POWER_ENABLE */
338         { OFFSET(gpmc_a6), MODE(7) | PULLUDEN, },
339         /* LCD Backlight (PWM) */
340         { OFFSET(mcasp0_aclkx), MODE(7) | PULLUDEN, },
341 };
342
343 static const struct pin_mux stk5_lcd_pads[] = {
344         /* LCD data bus */
345         { OFFSET(lcd_data0), MODE(0) | PULLUDEN, },
346         { OFFSET(lcd_data1), MODE(0) | PULLUDEN, },
347         { OFFSET(lcd_data2), MODE(0) | PULLUDEN, },
348         { OFFSET(lcd_data3), MODE(0) | PULLUDEN, },
349         { OFFSET(lcd_data4), MODE(0) | PULLUDEN, },
350         { OFFSET(lcd_data5), MODE(0) | PULLUDEN, },
351         { OFFSET(lcd_data6), MODE(0) | PULLUDEN, },
352         { OFFSET(lcd_data7), MODE(0) | PULLUDEN, },
353         { OFFSET(lcd_data8), MODE(0) | PULLUDEN, },
354         { OFFSET(lcd_data9), MODE(0) | PULLUDEN, },
355         { OFFSET(lcd_data10), MODE(0) | PULLUDEN, },
356         { OFFSET(lcd_data11), MODE(0) | PULLUDEN, },
357         { OFFSET(lcd_data12), MODE(0) | PULLUDEN, },
358         { OFFSET(lcd_data13), MODE(0) | PULLUDEN, },
359         { OFFSET(lcd_data14), MODE(0) | PULLUDEN, },
360         { OFFSET(lcd_data15), MODE(0) | PULLUDEN, },
361         /* LCD control signals */
362         { OFFSET(lcd_hsync), MODE(0) | PULLUDEN, },
363         { OFFSET(lcd_vsync), MODE(0) | PULLUDEN, },
364         { OFFSET(lcd_pclk), MODE(0) | PULLUDEN, },
365         { OFFSET(lcd_ac_bias_en), MODE(0) | PULLUDEN, },
366 };
367
368 static const struct gpio stk5_gpios[] = {
369         { AM33XX_GPIO_NR(1, 26), GPIOF_OUTPUT_INIT_LOW, "HEARTBEAT LED", },
370 };
371
372 static const struct gpio stk5_lcd_gpios[] = {
373         { AM33XX_GPIO_NR(1, 19), GPIOF_OUTPUT_INIT_LOW, "LCD RESET", },
374         { AM33XX_GPIO_NR(1, 22), GPIOF_OUTPUT_INIT_LOW, "LCD POWER", },
375         { AM33XX_GPIO_NR(3, 14), GPIOF_OUTPUT_INIT_HIGH, "LCD BACKLIGHT", },
376 };
377
378 static const struct pin_mux stk5v5_pads[] = {
379         /* CAN transceiver control */
380         { OFFSET(gpmc_ad8), MODE(7) | PULLUDEN, },
381 };
382
383 static const struct gpio stk5v5_gpios[] = {
384         { AM33XX_GPIO_NR(0, 22), GPIOF_OUTPUT_INIT_HIGH, "CAN XCVR", },
385 };
386
387 #ifdef CONFIG_LCD
388 static u16 tx48_cmap[256];
389 vidinfo_t panel_info = {
390         /* set to max. size supported by SoC */
391         .vl_col = 1366,
392         .vl_row = 768,
393
394         .vl_bpix = LCD_COLOR24,    /* Bits per pixel, 0: 1bpp, 1: 2bpp, 2: 4bpp, 3: 8bpp ... */
395         .cmap = tx48_cmap,
396 };
397
398 static struct da8xx_panel tx48_lcd_panel = {
399         .name = "640x480MR@60",
400         .width = 640,
401         .height = 480,
402         .hfp = 12,
403         .hbp = 144,
404         .hsw = 30,
405         .vfp = 10,
406         .vbp = 35,
407         .vsw = 3,
408         .pxl_clk = 25000000,
409         .invert_pxl_clk = 1,
410 };
411
412 void *lcd_base;                 /* Start of framebuffer memory  */
413 void *lcd_console_address;      /* Start of console buffer      */
414
415 int lcd_color_fg;
416 int lcd_color_bg;
417
418 short console_col;
419 short console_row;
420
421 static int lcd_enabled = 1;
422
423 void lcd_initcolregs(void)
424 {
425 }
426
427 void lcd_setcolreg(ushort regno, ushort red, ushort green, ushort blue)
428 {
429 }
430
431 void lcd_enable(void)
432 {
433         /* HACK ALERT:
434          * global variable from common/lcd.c
435          * Set to 0 here to prevent messages from going to LCD
436          * rather than serial console
437          */
438         lcd_is_enabled = 0;
439
440         if (lcd_enabled) {
441                 karo_load_splashimage(1);
442
443                 gpio_set_value(TX48_LCD_PWR_GPIO, 1);
444                 gpio_set_value(TX48_LCD_RST_GPIO, 1);
445                 udelay(300000);
446                 gpio_set_value(TX48_LCD_BACKLIGHT_GPIO, 0);
447         }
448 }
449
450 void lcd_disable(void)
451 {
452         if (lcd_enabled) {
453                 da8xx_fb_disable();
454                 lcd_enabled = 0;
455         }
456 }
457
458 void lcd_panel_disable(void)
459 {
460         if (lcd_enabled) {
461                 gpio_set_value(TX48_LCD_BACKLIGHT_GPIO, 1);
462                 gpio_set_value(TX48_LCD_PWR_GPIO, 0);
463                 gpio_set_value(TX48_LCD_RST_GPIO, 0);
464         }
465 }
466
467 void lcd_ctrl_init(void *lcdbase)
468 {
469         int color_depth = 24;
470         char *vm, *v;
471         unsigned long val;
472         struct da8xx_panel *p = &tx48_lcd_panel;
473         int refresh = 60;
474
475         if (!lcd_enabled) {
476                 printf("LCD disabled\n");
477                 return;
478         }
479
480         if (tstc() || (prm_rstst & PRM_RSTST_WDT1_RST)) {
481                 lcd_enabled = 0;
482                 return;
483         }
484
485         vm = getenv("video_mode");
486         if (vm == NULL) {
487                 lcd_enabled = 0;
488                 return;
489         }
490
491         if ((v = strstr(vm, ":")))
492                 vm = v + 1;
493
494         strncpy((char *)p->name, vm, sizeof(p->name));
495
496         val = simple_strtoul(vm, &vm, 10);
497         if (val != 0) {
498                 if (val > panel_info.vl_col)
499                         val = panel_info.vl_col;
500                 p->width = val;
501                 panel_info.vl_col = val;
502         }
503         if (*vm == 'x') {
504                 val = simple_strtoul(vm + 1, &vm, 10);
505                 if (val > panel_info.vl_row)
506                         val = panel_info.vl_row;
507                 p->height = val;
508                 panel_info.vl_row = val;
509         }
510         while (*vm != '\0') {
511                 switch (*vm) {
512                 case 'M':
513                 case 'R':
514                         vm++;
515                         break;
516
517                 case '-':
518                         color_depth = simple_strtoul(vm + 1, &vm, 10);
519                         break;
520
521                 case '@':
522                         refresh = simple_strtoul(vm + 1, &vm, 10);
523                         break;
524
525                 default:
526                         debug("Ignoring '%c'\n", *vm);
527                         vm++;
528                 }
529         }
530         switch (color_depth) {
531         case 8:
532                 panel_info.vl_bpix = 3;
533                 break;
534
535         case 16:
536                 panel_info.vl_bpix = 4;
537                 break;
538
539         case 24:
540                 panel_info.vl_bpix = 5;
541                 break;
542
543         default:
544                 printf("Invalid color_depth %u from video_mode '%s'; using default: %u\n",
545                         color_depth, getenv("video_mode"), 24);
546         }
547         lcd_line_length = NBITS(panel_info.vl_bpix) / 8 * panel_info.vl_col;
548         p->pxl_clk = refresh *
549                 (p->width + p->hfp + p->hbp + p->hsw) *
550                 (p->height + p->vfp + p->vbp + p->vsw);
551         debug("Pixel clock set to %u.%03uMHz\n",
552                 p->pxl_clk / 1000000, p->pxl_clk / 1000 % 1000);
553
554         gpio_request_array(stk5_lcd_gpios, ARRAY_SIZE(stk5_lcd_gpios));
555         tx48_set_pin_mux(stk5_lcd_pads, ARRAY_SIZE(stk5_lcd_pads));
556         debug("Initializing FB driver\n");
557         da8xx_video_init(&tx48_lcd_panel, color_depth);
558
559         if (karo_load_splashimage(0) == 0) {
560                 debug("Initializing LCD controller\n");
561                 video_hw_init();
562         } else {
563                 debug("Skipping initialization of LCD controller\n");
564         }
565 }
566 #else
567 #define lcd_enabled 0
568 #endif /* CONFIG_LCD */
569
570 static void stk5_board_init(void)
571 {
572         tx48_set_pin_mux(stk5_pads, ARRAY_SIZE(stk5_pads));
573 }
574
575 static void stk5v3_board_init(void)
576 {
577         stk5_board_init();
578 }
579
580 static void stk5v5_board_init(void)
581 {
582         stk5_board_init();
583         tx48_set_pin_mux(stk5v5_pads, ARRAY_SIZE(stk5v5_pads));
584         gpio_request_array(stk5v5_gpios, ARRAY_SIZE(stk5v5_gpios));
585 }
586
587 /* called with default environment! */
588 int board_init(void)
589 {
590         /* mach type passed to kernel */
591 #ifdef CONFIG_OF_LIBFDT
592         gd->bd->bi_arch_number = -1;
593 #endif
594         /* address of boot parameters */
595         gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
596
597         return 0;
598 }
599
600 static void show_reset_cause(u32 prm_rstst)
601 {
602         const char *dlm = "";
603
604         printf("RESET cause: ");
605         if (prm_rstst & PRM_RSTST_GLOBAL_COLD_RST) {
606                 printf("%sPOR", dlm);
607                 dlm = " | ";
608         }
609         if (prm_rstst & PRM_RSTST_GLOBAL_WARM_SW_RST) {
610                 printf("%sSW", dlm);
611                 dlm = " | ";
612         }
613         if (prm_rstst & PRM_RSTST_WDT1_RST) {
614                 printf("%sWATCHDOG", dlm);
615                 dlm = " | ";
616         }
617         if (prm_rstst & PRM_RSTST_EXTERNAL_WARM_RST) {
618                 printf("%sWARM", dlm);
619                 dlm = " | ";
620         }
621         if (prm_rstst & PRM_RSTST_ICEPICK_RST) {
622                 printf("%sJTAG", dlm);
623                 dlm = " | ";
624         }
625         if (*dlm == '\0')
626                 printf("unknown");
627
628         printf(" RESET\n");
629 }
630
631 /* called with default environment! */
632 int checkboard(void)
633 {
634         prm_rstst = readl(PRM_RSTST);
635         show_reset_cause(prm_rstst);
636
637 #ifdef CONFIG_OF_LIBFDT
638         printf("Board: Ka-Ro TX48-7020 with FDT support\n");
639 #else
640         printf("Board: Ka-Ro TX48-7020\n");
641 #endif
642         timer_init();
643         return 0;
644 }
645
646 static void tx48_set_cpu_clock(void)
647 {
648         unsigned long cpu_clk = getenv_ulong("cpu_clk", 10, 0);
649
650         if (tstc() || (prm_rstst & PRM_RSTST_WDT1_RST))
651                 return;
652
653         if (cpu_clk == 0 || cpu_clk == mpu_clk_rate() / 1000000)
654                 return;
655
656         mpu_pll_config_val(cpu_clk);
657
658         printf("CPU clock set to %lu.%03lu MHz\n",
659                 mpu_clk_rate() / 1000000,
660                 mpu_clk_rate() / 1000 % 1000);
661 }
662
663 /* called with environment from NAND or MMC */
664 int board_late_init(void)
665 {
666         const char *baseboard;
667
668         tx48_set_cpu_clock();
669 #ifdef CONFIG_OF_BOARD_SETUP
670         karo_fdt_move_fdt();
671 #endif
672         baseboard = getenv("baseboard");
673         if (!baseboard)
674                 return 0;
675
676         if (strncmp(baseboard, "stk5", 4) == 0) {
677                 printf("Baseboard: %s\n", baseboard);
678                 if ((strlen(baseboard) == 4) ||
679                         strcmp(baseboard, "stk5-v3") == 0) {
680                         stk5v3_board_init();
681                 } else if (strcmp(baseboard, "stk5-v5") == 0) {
682                         stk5v5_board_init();
683                 } else {
684                         printf("WARNING: Unsupported STK5 board rev.: %s\n",
685                                 baseboard + 4);
686                 }
687         } else {
688                 printf("WARNING: Unsupported baseboard: '%s'\n",
689                         baseboard);
690                 return -EINVAL;
691         }
692
693         return 0;
694 }
695
696 #ifdef CONFIG_DRIVER_TI_CPSW
697 static void tx48_phy_init(char *name, int addr)
698 {
699         debug("%s: Resetting ethernet PHY\n", __func__);
700
701         gpio_direction_output(TX48_ETH_PHY_RST_GPIO, 0);
702
703         udelay(100);
704
705         /* Release nRST */
706         gpio_set_value(TX48_ETH_PHY_RST_GPIO, 1);
707
708         /* Wait for PHY internal POR signal to deassert */
709         udelay(25000);
710 }
711
712 static void cpsw_control(int enabled)
713 {
714         /* nothing for now */
715         /* TODO : VTP was here before */
716 }
717
718 static struct cpsw_slave_data cpsw_slaves[] = {
719         {
720                 .slave_reg_ofs  = 0x208,
721                 .sliver_reg_ofs = 0xd80,
722                 .phy_id         = 0,
723                 .phy_if         = PHY_INTERFACE_MODE_RMII,
724         },
725 };
726
727 void s_init(void)
728 {
729         /* Nothing to be done here */
730 }
731
732 static struct cpsw_platform_data cpsw_data = {
733         .mdio_base              = CPSW_MDIO_BASE,
734         .cpsw_base              = CPSW_BASE,
735         .mdio_div               = 0xff,
736         .channels               = 8,
737         .cpdma_reg_ofs          = 0x800,
738         .slaves                 = ARRAY_SIZE(cpsw_slaves),
739         .slave_data             = cpsw_slaves,
740         .ale_reg_ofs            = 0xd00,
741         .ale_entries            = 1024,
742         .host_port_reg_ofs      = 0x108,
743         .hw_stats_reg_ofs       = 0x900,
744         .mac_control            = (1 << 5) /* MIIEN */,
745         .control                = cpsw_control,
746         .phy_init               = tx48_phy_init,
747         .gigabit_en             = 0,
748         .host_port_num          = 0,
749         .version                = CPSW_CTRL_VERSION_2,
750 };
751
752 int board_eth_init(bd_t *bis)
753 {
754         uint8_t mac_addr[ETH_ALEN];
755         uint32_t mac_hi, mac_lo;
756
757         /* try reading mac address from efuse */
758         mac_lo = __raw_readl(MAC_ID0_LO);
759         mac_hi = __raw_readl(MAC_ID0_HI);
760
761         mac_addr[0] = mac_hi & 0xFF;
762         mac_addr[1] = (mac_hi & 0xFF00) >> 8;
763         mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
764         mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
765         mac_addr[4] = mac_lo & 0xFF;
766         mac_addr[5] = (mac_lo & 0xFF00) >> 8;
767
768         if (is_valid_ether_addr(mac_addr)) {
769                 printf("MAC addr from fuse: %pM\n", mac_addr);
770                 eth_setenv_enetaddr("ethaddr", mac_addr);
771         } else {
772                 printf("ERROR: Did not find a valid mac address in e-fuse\n");
773         }
774
775         __raw_writel(RMII_MODE_ENABLE, MAC_MII_SEL);
776         __raw_writel(0x5D, GMII_SEL);
777         return cpsw_register(&cpsw_data);
778 }
779 #endif /* CONFIG_DRIVER_TI_CPSW */
780
781 void tx48_disable_watchdog(void)
782 {
783         struct wd_timer *wdtimer = (struct wd_timer *)WDT_BASE;
784
785         while (readl(&wdtimer->wdtwwps) & (1 << 4))
786                 ;
787         writel(0xaaaa, &wdtimer->wdtwspr);
788         while (readl(&wdtimer->wdtwwps) & (1 << 4))
789                 ;
790         writel(0x5555, &wdtimer->wdtwspr);
791 }
792
793 enum {
794         LED_STATE_INIT = -1,
795         LED_STATE_OFF,
796         LED_STATE_ON,
797 };
798
799 void show_activity(int arg)
800 {
801         static int led_state = LED_STATE_INIT;
802         static ulong last;
803
804         if (led_state == LED_STATE_INIT) {
805                 last = get_timer(0);
806                 gpio_set_value(TX48_LED_GPIO, 1);
807                 led_state = LED_STATE_ON;
808         } else {
809                 if (get_timer(last) > CONFIG_SYS_HZ) {
810                         last = get_timer(0);
811                         if (led_state == LED_STATE_ON) {
812                                 gpio_set_value(TX48_LED_GPIO, 0);
813                         } else {
814                                 gpio_set_value(TX48_LED_GPIO, 1);
815                         }
816                         led_state = 1 - led_state;
817                 }
818         }
819 }
820
821 #ifdef CONFIG_OF_BOARD_SETUP
822 #ifdef CONFIG_FDT_FIXUP_PARTITIONS
823 #include <jffs2/jffs2.h>
824 #include <mtd_node.h>
825 struct node_info nodes[] = {
826         { "ti,omap2-nand", MTD_DEV_TYPE_NAND, },
827 };
828
829 #else
830 #define fdt_fixup_mtdparts(b,n,c) do { } while (0)
831 #endif /* CONFIG_FDT_FIXUP_PARTITIONS */
832
833 static void tx48_fixup_flexcan(void *blob)
834 {
835         const char *baseboard = getenv("baseboard");
836
837         if (baseboard && strcmp(baseboard, "stk5-v5") == 0)
838                 return;
839
840         karo_fdt_del_prop(blob, "ti,dcan", 0x481cc000, "can-xcvr-enable");
841         karo_fdt_del_prop(blob, "ti,dcan", 0x481d0000, "can-xcvr-enable");
842 }
843
844 void ft_board_setup(void *blob, bd_t *bd)
845 {
846         fdt_fixup_mtdparts(blob, nodes, ARRAY_SIZE(nodes));
847         fdt_fixup_ethernet(blob);
848
849         karo_fdt_fixup_touchpanel(blob);
850         tx48_fixup_flexcan(blob);
851
852         tx48_disable_watchdog();
853 }
854 #endif /* CONFIG_OF_BOARD_SETUP */