davinci: omapl138-lcdk: remove unneeded includes
[platform/kernel/u-boot.git] / board / davinci / da8xxevm / omapl138_lcdk.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com/
4  *
5  * Based on da850evm.c. Original Copyrights follow:
6  *
7  * Copyright (C) 2009 Nick Thompson, GE Fanuc, Ltd. <nick.thompson@gefanuc.com>
8  * Copyright (C) 2007 Sergey Kubushyn <ksi@koi8.net>
9  */
10
11 #include <common.h>
12 #include <i2c.h>
13 #include <net.h>
14 #include <asm/arch/hardware.h>
15 #include <asm/ti-common/davinci_nand.h>
16 #include <asm/io.h>
17 #include <linux/errno.h>
18 #include <asm/mach-types.h>
19 #include <asm/arch/davinci_misc.h>
20 #ifdef CONFIG_MMC_DAVINCI
21 #include <mmc.h>
22 #include <asm/arch/sdmmc_defs.h>
23 #endif
24
25 DECLARE_GLOBAL_DATA_PTR;
26
27 #define pinmux(x)       (&davinci_syscfg_regs->pinmux[x])
28
29 #ifdef CONFIG_MMC_DAVINCI
30 /* MMC0 pin muxer settings */
31 const struct pinmux_config mmc0_pins[] = {
32         /* GP0[11] is required for SD to work on Rev 3 EVMs */
33         { pinmux(0),  8, 4 },   /* GP0[11] */
34         { pinmux(10), 2, 0 },   /* MMCSD0_CLK */
35         { pinmux(10), 2, 1 },   /* MMCSD0_CMD */
36         { pinmux(10), 2, 2 },   /* MMCSD0_DAT_0 */
37         { pinmux(10), 2, 3 },   /* MMCSD0_DAT_1 */
38         { pinmux(10), 2, 4 },   /* MMCSD0_DAT_2 */
39         { pinmux(10), 2, 5 },   /* MMCSD0_DAT_3 */
40         /* LCDK supports only 4-bit mode, remaining pins are not configured */
41 };
42 #endif
43
44 /* UART pin muxer settings */
45 static const struct pinmux_config uart_pins[] = {
46         { pinmux(0), 4, 6 },
47         { pinmux(0), 4, 7 },
48         { pinmux(4), 2, 4 },
49         { pinmux(4), 2, 5 }
50 };
51
52 #ifdef CONFIG_DRIVER_TI_EMAC
53 static const struct pinmux_config emac_pins[] = {
54         { pinmux(2), 8, 1 },
55         { pinmux(2), 8, 2 },
56         { pinmux(2), 8, 3 },
57         { pinmux(2), 8, 4 },
58         { pinmux(2), 8, 5 },
59         { pinmux(2), 8, 6 },
60         { pinmux(2), 8, 7 },
61         { pinmux(3), 8, 0 },
62         { pinmux(3), 8, 1 },
63         { pinmux(3), 8, 2 },
64         { pinmux(3), 8, 3 },
65         { pinmux(3), 8, 4 },
66         { pinmux(3), 8, 5 },
67         { pinmux(3), 8, 6 },
68         { pinmux(3), 8, 7 },
69         { pinmux(4), 8, 0 },
70         { pinmux(4), 8, 1 }
71 };
72 #endif /* CONFIG_DRIVER_TI_EMAC */
73
74 /* I2C pin muxer settings */
75 static const struct pinmux_config i2c_pins[] = {
76         { pinmux(4), 2, 2 },
77         { pinmux(4), 2, 3 }
78 };
79
80 #ifdef CONFIG_NAND_DAVINCI
81 const struct pinmux_config nand_pins[] = {
82         { pinmux(7), 1, 1 },
83         { pinmux(7), 1, 2 },
84         { pinmux(7), 1, 4 },
85         { pinmux(7), 1, 5 },
86         { pinmux(8), 1, 0 },
87         { pinmux(8), 1, 1 },
88         { pinmux(8), 1, 2 },
89         { pinmux(8), 1, 3 },
90         { pinmux(8), 1, 4 },
91         { pinmux(8), 1, 5 },
92         { pinmux(8), 1, 6 },
93         { pinmux(8), 1, 7 },
94         { pinmux(9), 1, 0 },
95         { pinmux(9), 1, 1 },
96         { pinmux(9), 1, 2 },
97         { pinmux(9), 1, 3 },
98         { pinmux(9), 1, 4 },
99         { pinmux(9), 1, 5 },
100         { pinmux(9), 1, 6 },
101         { pinmux(9), 1, 7 },
102         { pinmux(12), 1, 5 },
103         { pinmux(12), 1, 6 }
104 };
105
106 #endif
107
108 #ifdef CONFIG_DRIVER_TI_EMAC_USE_RMII
109 #define HAS_RMII 1
110 #else
111 #define HAS_RMII 0
112 #endif
113
114 const struct pinmux_resource pinmuxes[] = {
115         PINMUX_ITEM(uart_pins),
116         PINMUX_ITEM(i2c_pins),
117 #ifdef CONFIG_NAND_DAVINCI
118         PINMUX_ITEM(nand_pins),
119 #endif
120 };
121
122 const int pinmuxes_size = ARRAY_SIZE(pinmuxes);
123
124 const struct lpsc_resource lpsc[] = {
125         { DAVINCI_LPSC_AEMIF }, /* NAND, NOR */
126         { DAVINCI_LPSC_SPI1 },  /* Serial Flash */
127         { DAVINCI_LPSC_EMAC },  /* image download */
128         { DAVINCI_LPSC_UART2 }, /* console */
129         { DAVINCI_LPSC_GPIO },
130 #ifdef CONFIG_MMC_DAVINCI
131         { DAVINCI_LPSC_MMC_SD },
132 #endif
133 };
134
135 const int lpsc_size = ARRAY_SIZE(lpsc);
136
137 #ifndef CONFIG_DA850_EVM_MAX_CPU_CLK
138 #define CONFIG_DA850_EVM_MAX_CPU_CLK    456000000
139 #endif
140
141 /*
142  * get_board_rev() - setup to pass kernel board revision information
143  * Returns:
144  * bit[0-3]     Maximum cpu clock rate supported by onboard SoC
145  *              0000b - 300 MHz
146  *              0001b - 372 MHz
147  *              0010b - 408 MHz
148  *              0011b - 456 MHz
149  */
150 u32 get_board_rev(void)
151 {
152         return 0;
153 }
154
155 int board_early_init_f(void)
156 {
157         /*
158          * Power on required peripherals
159          * ARM does not have access by default to PSC0 and PSC1
160          * assuming here that the DSP bootloader has set the IOPU
161          * such that PSC access is available to ARM
162          */
163         if (da8xx_configure_lpsc_items(lpsc, ARRAY_SIZE(lpsc)))
164                 return 1;
165
166         return 0;
167 }
168
169 int board_init(void)
170 {
171         irq_init();
172
173         /* arch number of the board */
174         gd->bd->bi_arch_number = MACH_TYPE_OMAPL138_LCDK;
175
176         /* address of boot parameters */
177         gd->bd->bi_boot_params = LINUX_BOOT_PARAM_ADDR;
178
179
180         /* setup the SUSPSRC for ARM to control emulation suspend */
181         writel(readl(&davinci_syscfg_regs->suspsrc) &
182                ~(DAVINCI_SYSCFG_SUSPSRC_EMAC | DAVINCI_SYSCFG_SUSPSRC_I2C |
183                  DAVINCI_SYSCFG_SUSPSRC_SPI1 | DAVINCI_SYSCFG_SUSPSRC_TIMER0 |
184                  DAVINCI_SYSCFG_SUSPSRC_UART2),
185                &davinci_syscfg_regs->suspsrc);
186
187         /* configure pinmux settings */
188         if (davinci_configure_pin_mux_items(pinmuxes, ARRAY_SIZE(pinmuxes)))
189                 return 1;
190
191 #ifdef CONFIG_NAND_DAVINCI
192         /*
193          * NAND CS setup - cycle counts based on da850evm NAND timings in the
194          * Linux kernel @ 25MHz EMIFA
195          */
196         writel((DAVINCI_ABCR_WSETUP(15) |
197                 DAVINCI_ABCR_WSTROBE(63) |
198                 DAVINCI_ABCR_WHOLD(7) |
199                 DAVINCI_ABCR_RSETUP(15) |
200                 DAVINCI_ABCR_RSTROBE(63) |
201                 DAVINCI_ABCR_RHOLD(7) |
202                 DAVINCI_ABCR_TA(3) |
203                 DAVINCI_ABCR_ASIZE_16BIT),
204                &davinci_emif_regs->ab2cr); /* CS3 */
205 #endif
206
207
208 #ifdef CONFIG_MMC_DAVINCI
209         if (davinci_configure_pin_mux(mmc0_pins, ARRAY_SIZE(mmc0_pins)) != 0)
210                 return 1;
211 #endif
212
213 #ifdef CONFIG_DRIVER_TI_EMAC
214         if (davinci_configure_pin_mux(emac_pins, ARRAY_SIZE(emac_pins)) != 0)
215                 return 1;
216         davinci_emac_mii_mode_sel(HAS_RMII);
217 #endif /* CONFIG_DRIVER_TI_EMAC */
218
219         /* enable the console UART */
220         writel((DAVINCI_UART_PWREMU_MGMT_FREE | DAVINCI_UART_PWREMU_MGMT_URRST |
221                 DAVINCI_UART_PWREMU_MGMT_UTRST),
222                &davinci_uart2_ctrl_regs->pwremu_mgmt);
223
224         return 0;
225 }
226
227 #ifdef CONFIG_DRIVER_TI_EMAC
228
229 #endif /* CONFIG_DRIVER_TI_EMAC */
230
231 #define CFG_MAC_ADDR_SPI_BUS    0
232 #define CFG_MAC_ADDR_SPI_CS     0
233 #define CFG_MAC_ADDR_SPI_MAX_HZ CONFIG_SF_DEFAULT_SPEED
234 #define CFG_MAC_ADDR_SPI_MODE   SPI_MODE_3
235
236 #define CFG_MAC_ADDR_OFFSET     (flash->size - SZ_64K)
237
238 static int  get_mac_addr(u8 *addr)
239 {
240         /* Need to find a way to get MAC ADDRESS */
241         return 0;
242 }
243
244 void dsp_lpsc_on(unsigned domain, unsigned int id)
245 {
246         dv_reg_p mdstat, mdctl, ptstat, ptcmd;
247         struct davinci_psc_regs *psc_regs;
248
249         psc_regs = davinci_psc0_regs;
250         mdstat = &psc_regs->psc0.mdstat[id];
251         mdctl = &psc_regs->psc0.mdctl[id];
252         ptstat = &psc_regs->ptstat;
253         ptcmd = &psc_regs->ptcmd;
254
255         while (*ptstat & (0x1 << domain))
256                 ;
257
258         if ((*mdstat & 0x1f) == 0x03)
259                 return;                 /* Already on and enabled */
260
261         *mdctl |= 0x03;
262
263         *ptcmd = 0x1 << domain;
264
265         while (*ptstat & (0x1 << domain))
266                 ;
267         while ((*mdstat & 0x1f) != 0x03)
268                 ;               /* Probably an overkill... */
269 }
270
271 static void dspwake(void)
272 {
273         unsigned *resetvect = (unsigned *)DAVINCI_L3CBARAM_BASE;
274
275         /* if the device is ARM only, return */
276         if ((REG(CHIP_REV_ID_REG) & 0x3f) == 0x10)
277                 return;
278
279         if (!strcmp(env_get("dspwake"), "no"))
280                 return;
281
282         *resetvect++ = 0x1E000; /* DSP Idle */
283         /* clear out the next 10 words as NOP */
284         memset(resetvect, 0, sizeof(unsigned) * 10);
285
286         /* setup the DSP reset vector */
287         REG(HOST1CFG) = DAVINCI_L3CBARAM_BASE;
288
289         dsp_lpsc_on(1, DAVINCI_LPSC_GEM);
290         REG(PSC0_MDCTL + (15 * 4)) |= 0x100;
291 }
292
293 #ifdef CONFIG_DRIVER_TI_EMAC_USE_RMII
294 /**
295  * rmii_hw_init
296  *
297  */
298 int rmii_hw_init(void)
299 {
300         return 0;
301 }
302 #endif /* CONFIG_DRIVER_TI_EMAC_USE_RMII */
303
304 int misc_init_r(void)
305 {
306         uint8_t tmp[20], addr[10];
307
308
309         if (env_get("ethaddr") == NULL) {
310                 /* Read Ethernet MAC address from EEPROM */
311                 if (dvevm_read_mac_address(addr)) {
312                         /* Set Ethernet MAC address from EEPROM */
313                         davinci_sync_env_enetaddr(addr);
314                 } else {
315                         get_mac_addr(addr);
316                 }
317
318                 if (!is_multicast_ethaddr(addr) && !is_zero_ethaddr(addr)) {
319                         sprintf((char *)tmp, "%02x:%02x:%02x:%02x:%02x:%02x",
320                                 addr[0], addr[1], addr[2], addr[3], addr[4],
321                                 addr[5]);
322
323                         env_set("ethaddr", (char *)tmp);
324                 } else {
325                         printf("Invalid MAC address read.\n");
326                 }
327         }
328
329 #ifdef CONFIG_DRIVER_TI_EMAC_USE_RMII
330         /* Select RMII fucntion through the expander */
331         if (rmii_hw_init())
332                 printf("RMII hardware init failed!!!\n");
333 #endif
334
335         dspwake();
336
337         return 0;
338 }
339
340 #if !CONFIG_IS_ENABLED(DM_MMC)
341 #ifdef CONFIG_MMC_DAVINCI
342 static struct davinci_mmc mmc_sd0 = {
343         .reg_base = (struct davinci_mmc_regs *)DAVINCI_MMC_SD0_BASE,
344         .host_caps = MMC_MODE_4BIT,     /* DA850 supports only 4-bit SD/MMC */
345         .voltages = MMC_VDD_32_33 | MMC_VDD_33_34,
346         .version = MMC_CTLR_VERSION_2,
347 };
348
349 int board_mmc_init(bd_t *bis)
350 {
351         mmc_sd0.input_clk = clk_get(DAVINCI_MMCSD_CLKID);
352
353         /* Add slot-0 to mmc subsystem */
354         return davinci_mmc_init(bis, &mmc_sd0);
355 }
356 #endif
357 #endif