]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/freescale/mx23_evk/mx23_evk.c
applied patches from Freescale and Ka-Ro
[karo-tx-uboot.git] / board / freescale / mx23_evk / mx23_evk.c
1 /*
2  *
3  * (c) 2008 Embedded Alley Solutions, Inc.
4  *
5  * (C) Copyright 2009-2010 Freescale Semiconductor, Inc.
6  *
7  * See file CREDITS for list of people who contributed to this
8  * project.
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License as
12  * published by the Free Software Foundation; either version 2 of
13  * the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
23  * MA 02111-1307 USA
24  */
25
26
27 #include <common.h>
28 #include <asm/arch/mx23.h>
29 #include <asm/arch/clkctrl.h>
30 #include <asm/arch/pinmux.h>
31 #include <asm/arch/spi.h>
32
33 DECLARE_GLOBAL_DATA_PTR;
34
35 #define KHz     1000
36 #define MHz     (1000 * KHz)
37
38 static void set_pinmux(void)
39 {
40
41 #if defined(CONFIG_SPI_SSP1)
42
43         /* Configure SSP1 pins for ENC28j60: 8maA */
44         REG_CLR(PINCTRL_BASE + PINCTRL_MUXSEL(4), 0x00003fff);
45
46         REG_CLR(PINCTRL_BASE + PINCTRL_DRIVE(8), 0X03333333);
47         REG_SET(PINCTRL_BASE + PINCTRL_DRIVE(8), 0x01111111);
48
49         REG_CLR(PINCTRL_BASE + PINCTRL_PULL(2), 0x0000003f);
50 #endif
51
52 #if defined(CONFIG_SPI_SSP2)
53
54         /* Configure SSP2 pins for ENC28j60: 8maA */
55         REG_CLR(PINCTRL_BASE + PINCTRL_MUXSEL(0), 0x00000fc3);
56         REG_SET(PINCTRL_BASE + PINCTRL_MUXSEL(0), 0x00000a82);
57
58         REG_CLR(PINCTRL_BASE + PINCTRL_MUXSEL(1), 0x00030300);
59         REG_SET(PINCTRL_BASE + PINCTRL_MUXSEL(1), 0x00020200);
60
61         REG_CLR(PINCTRL_BASE + PINCTRL_DRIVE(0), 0X00333003);
62         REG_SET(PINCTRL_BASE + PINCTRL_DRIVE(0), 0x00111001);
63
64         REG_CLR(PINCTRL_BASE + PINCTRL_DRIVE(2), 0x00030000);
65         REG_SET(PINCTRL_BASE + PINCTRL_DRIVE(2), 0x00010000);
66
67         REG_CLR(PINCTRL_BASE + PINCTRL_DRIVE(3), 0x00000003);
68         REG_SET(PINCTRL_BASE + PINCTRL_DRIVE(3), 0x00000001);
69
70         REG_CLR(PINCTRL_BASE + PINCTRL_PULL(0), 0x00100039);
71 #endif
72
73 }
74
75 #define IO_DIVIDER      18
76 static void set_clocks(void)
77 {
78         u32 ssp_source_clk, ssp_clk;
79         u32 ssp_div = 1;
80         u32 val = 0;
81
82         /*
83          * Configure 480Mhz IO clock
84          */
85
86         /* Ungate IO_CLK and set divider */
87         REG_CLR(CLKCTRL_BASE + CLKCTRL_FRAC, FRAC_CLKGATEIO);
88         REG_CLR(CLKCTRL_BASE + CLKCTRL_FRAC, 0x3f << FRAC_IOFRAC);
89         REG_SET(CLKCTRL_BASE + CLKCTRL_FRAC, IO_DIVIDER << FRAC_IOFRAC);
90
91         /*
92          * Set SSP CLK to desired value
93          */
94
95         /* Calculate SSP_CLK divider relatively to 480Mhz IO_CLK*/
96         ssp_source_clk = 480 * MHz;
97         ssp_clk = CONFIG_SSP_CLK;
98         ssp_div = (ssp_source_clk + ssp_clk - 1) / ssp_clk;
99
100         /* Enable SSP clock */
101         val = REG_RD(CLKCTRL_BASE + CLKCTRL_SSP);
102         val &= ~SSP_CLKGATE;
103         REG_WR(CLKCTRL_BASE + CLKCTRL_SSP, val);
104
105         /* Wait while clock is gated */
106         while (REG_RD(CLKCTRL_BASE + CLKCTRL_SSP) & SSP_CLKGATE)
107                 ;
108
109         /* Set SSP clock divider */
110         val &= ~(0x1ff << SSP_DIV);
111         val |= ssp_div << SSP_DIV;
112         REG_WR(CLKCTRL_BASE + CLKCTRL_SSP, val);
113
114         /* Wait until new divider value is set */
115         while (REG_RD(CLKCTRL_BASE + CLKCTRL_SSP) & SSP_BUSY)
116                 ;
117
118         /* Set SSP clock source to IO_CLK */
119         REG_SET(CLKCTRL_BASE + CLKCTRL_CLKSEQ, CLKSEQ_BYPASS_SSP);
120         REG_CLR(CLKCTRL_BASE + CLKCTRL_CLKSEQ, CLKSEQ_BYPASS_SSP);
121 }
122
123 int dram_init(void)
124 {
125         gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
126         gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
127
128         return 0;
129 }
130
131 int board_init(void)
132 {
133         /* arch number of Freescale STMP 378x development board */
134         gd->bd->bi_arch_number = MACH_TYPE_MX23EVK;
135
136         /* adress of boot parameters */
137         gd->bd->bi_boot_params = LINUX_BOOT_PARAM_ADDR;
138
139         set_clocks();
140
141         set_pinmux();
142
143         /* Configure SPI on SSP1 or SSP2 */
144         spi_init();
145
146         return 0;
147 }
148
149 int misc_init_r(void)
150 {
151         return 0;
152 }
153
154 int checkboard(void)
155 {
156         printf("Board: MX23 EVK. \n");
157         return 0;
158 }