igep00x0: move SPL routines into separate file
[platform/kernel/u-boot.git] / board / isee / igep00x0 / igep00x0.c
1 /*
2  * (C) Copyright 2010
3  * ISEE 2007 SL, <www.iseebcn.com>
4  *
5  * SPDX-License-Identifier:     GPL-2.0+
6  */
7 #include <common.h>
8 #include <status_led.h>
9 #include <dm.h>
10 #include <ns16550.h>
11 #include <twl4030.h>
12 #include <netdev.h>
13 #include <spl.h>
14 #include <asm/gpio.h>
15 #include <asm/io.h>
16 #include <asm/arch/mem.h>
17 #include <asm/arch/mmc_host_def.h>
18 #include <asm/arch/mux.h>
19 #include <asm/arch/sys_proto.h>
20 #include <asm/mach-types.h>
21 #include <linux/mtd/mtd.h>
22 #include <linux/mtd/nand.h>
23 #include <linux/mtd/onenand.h>
24 #include <jffs2/load_kernel.h>
25 #include <mtd_node.h>
26 #include <fdt_support.h>
27 #include "igep00x0.h"
28
29 static const struct ns16550_platdata igep_serial = {
30         .base = OMAP34XX_UART3,
31         .reg_shift = 2,
32         .clock = V_NS16550_CLK,
33         .fcr = UART_FCR_DEFVAL,
34 };
35
36 U_BOOT_DEVICE(igep_uart) = {
37         "ns16550_serial",
38         &igep_serial
39 };
40
41 int onenand_board_init(struct mtd_info *mtd)
42 {
43         if (gpmc_cs0_flash == MTD_DEV_TYPE_ONENAND) {
44                 struct onenand_chip *this = mtd->priv;
45                 this->base = (void *)CONFIG_SYS_ONENAND_BASE;
46                 return 0;
47         }
48         return 1;
49 }
50
51 #if defined(CONFIG_CMD_NET)
52 static void reset_net_chip(int gpio)
53 {
54         if (!gpio_request(gpio, "eth nrst")) {
55                 gpio_direction_output(gpio, 1);
56                 udelay(1);
57                 gpio_set_value(gpio, 0);
58                 udelay(40);
59                 gpio_set_value(gpio, 1);
60                 mdelay(10);
61         }
62 }
63
64 /*
65  * Routine: setup_net_chip
66  * Description: Setting up the configuration GPMC registers specific to the
67  *              Ethernet hardware.
68  */
69 static void setup_net_chip(void)
70 {
71         struct ctrl *ctrl_base = (struct ctrl *)OMAP34XX_CTRL_BASE;
72         static const u32 gpmc_lan_config[] = {
73                 NET_LAN9221_GPMC_CONFIG1,
74                 NET_LAN9221_GPMC_CONFIG2,
75                 NET_LAN9221_GPMC_CONFIG3,
76                 NET_LAN9221_GPMC_CONFIG4,
77                 NET_LAN9221_GPMC_CONFIG5,
78                 NET_LAN9221_GPMC_CONFIG6,
79         };
80
81         enable_gpmc_cs_config(gpmc_lan_config, &gpmc_cfg->cs[5],
82                         CONFIG_SMC911X_BASE, GPMC_SIZE_16M);
83
84         /* Enable off mode for NWE in PADCONF_GPMC_NWE register */
85         writew(readw(&ctrl_base->gpmc_nwe) | 0x0E00, &ctrl_base->gpmc_nwe);
86         /* Enable off mode for NOE in PADCONF_GPMC_NADV_ALE register */
87         writew(readw(&ctrl_base->gpmc_noe) | 0x0E00, &ctrl_base->gpmc_noe);
88         /* Enable off mode for ALE in PADCONF_GPMC_NADV_ALE register */
89         writew(readw(&ctrl_base->gpmc_nadv_ale) | 0x0E00,
90                 &ctrl_base->gpmc_nadv_ale);
91
92         reset_net_chip(64);
93 }
94
95 int board_eth_init(bd_t *bis)
96 {
97 #ifdef CONFIG_SMC911X
98         return smc911x_initialize(0, CONFIG_SMC911X_BASE);
99 #else
100         return 0;
101 #endif
102 }
103 #else
104 static inline void setup_net_chip(void) {}
105 #endif
106
107 #ifdef CONFIG_OF_BOARD_SETUP
108 static int ft_enable_by_compatible(void *blob, char *compat, int enable)
109 {
110         int off = fdt_node_offset_by_compatible(blob, -1, compat);
111         if (off < 0)
112                 return off;
113
114         if (enable)
115                 fdt_status_okay(blob, off);
116         else
117                 fdt_status_disabled(blob, off);
118
119         return 0;
120 }
121
122 int ft_board_setup(void *blob, bd_t *bd)
123 {
124 #ifdef CONFIG_FDT_FIXUP_PARTITIONS
125         static struct node_info nodes[] = {
126                 { "ti,omap2-nand", MTD_DEV_TYPE_NAND, },
127                 { "ti,omap2-onenand", MTD_DEV_TYPE_ONENAND, },
128         };
129
130         fdt_fixup_mtdparts(blob, nodes, ARRAY_SIZE(nodes));
131 #endif
132         ft_enable_by_compatible(blob, "ti,omap2-nand",
133                                 gpmc_cs0_flash == MTD_DEV_TYPE_NAND);
134         ft_enable_by_compatible(blob, "ti,omap2-onenand",
135                                 gpmc_cs0_flash == MTD_DEV_TYPE_ONENAND);
136
137         return 0;
138 }
139 #endif
140
141 void set_fdt(void)
142 {
143         switch (gd->bd->bi_arch_number) {
144         case MACH_TYPE_IGEP0020:
145                 env_set("fdtfile", "omap3-igep0020.dtb");
146                 break;
147         case MACH_TYPE_IGEP0030:
148                 env_set("fdtfile", "omap3-igep0030.dtb");
149                 break;
150         }
151 }
152
153 /*
154  * Routine: misc_init_r
155  * Description: Configure board specific parts
156  */
157 int misc_init_r(void)
158 {
159         twl4030_power_init();
160
161         setup_net_chip();
162
163         omap_die_id_display();
164
165         set_fdt();
166
167         return 0;
168 }
169
170 void board_mtdparts_default(const char **mtdids, const char **mtdparts)
171 {
172         struct mtd_info *mtd = get_mtd_device(NULL, 0);
173         if (mtd) {
174                 static char ids[24];
175                 static char parts[48];
176                 const char *linux_name = "omap2-nand";
177                 if (strncmp(mtd->name, "onenand0", 8) == 0)
178                         linux_name = "omap2-onenand";
179                 snprintf(ids, sizeof(ids), "%s=%s", mtd->name, linux_name);
180                 snprintf(parts, sizeof(parts), "mtdparts=%s:%dk(SPL),-(UBI)",
181                          linux_name, 4 * mtd->erasesize >> 10);
182                 *mtdids = ids;
183                 *mtdparts = parts;
184         }
185 }