Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Enric Balletbo i Serra | 2ce268c | 2010-10-14 16:54:59 -0400 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2010 |
| 4 | * ISEE 2007 SL, <www.iseebcn.com> |
Enric Balletbo i Serra | 2ce268c | 2010-10-14 16:54:59 -0400 | [diff] [blame] | 5 | */ |
Tom Rini | f524eba | 2024-04-30 20:42:03 -0600 | [diff] [blame] | 6 | #include <config.h> |
Simon Glass | 5e6201b | 2019-08-01 09:46:51 -0600 | [diff] [blame] | 7 | #include <env.h> |
Simon Glass | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 8 | #include <init.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 9 | #include <malloc.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 10 | #include <net.h> |
Enric Balletbo i Serra | a66c887 | 2015-01-28 15:01:32 +0100 | [diff] [blame] | 11 | #include <status_led.h> |
Simon Glass | bc0f4ea | 2014-10-22 21:37:15 -0600 | [diff] [blame] | 12 | #include <dm.h> |
| 13 | #include <ns16550.h> |
Enric Balletbo i Serra | 2ce268c | 2010-10-14 16:54:59 -0400 | [diff] [blame] | 14 | #include <twl4030.h> |
Javier Martinez Canillas | e9b1452 | 2012-12-27 01:35:56 +0000 | [diff] [blame] | 15 | #include <netdev.h> |
Ladislav Michl | ac87036 | 2016-07-12 20:28:34 +0200 | [diff] [blame] | 16 | #include <spl.h> |
Sanjeev Premi | 7b3dc82 | 2011-09-08 10:51:01 -0400 | [diff] [blame] | 17 | #include <asm/gpio.h> |
Javier Martinez Canillas | e9b1452 | 2012-12-27 01:35:56 +0000 | [diff] [blame] | 18 | #include <asm/io.h> |
Enric Balletbo i Serra | 2ce268c | 2010-10-14 16:54:59 -0400 | [diff] [blame] | 19 | #include <asm/arch/mem.h> |
Enric Balletbo i Serra | da898a9 | 2010-11-04 15:34:33 -0400 | [diff] [blame] | 20 | #include <asm/arch/mmc_host_def.h> |
Enric Balletbo i Serra | 2ce268c | 2010-10-14 16:54:59 -0400 | [diff] [blame] | 21 | #include <asm/arch/mux.h> |
| 22 | #include <asm/arch/sys_proto.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 23 | #include <linux/delay.h> |
Ladislav Michl | c44e29f | 2016-07-12 20:28:33 +0200 | [diff] [blame] | 24 | #include <linux/mtd/mtd.h> |
Masahiro Yamada | 2b7a873 | 2017-11-30 13:45:24 +0900 | [diff] [blame] | 25 | #include <linux/mtd/rawnand.h> |
Ladislav Michl | 3e34928 | 2016-07-12 20:28:31 +0200 | [diff] [blame] | 26 | #include <linux/mtd/onenand.h> |
| 27 | #include <jffs2/load_kernel.h> |
Ladislav Michl | be8e06d | 2017-01-09 11:21:06 +0100 | [diff] [blame] | 28 | #include <mtd_node.h> |
| 29 | #include <fdt_support.h> |
Javier Martinez Canillas | e9b1452 | 2012-12-27 01:35:56 +0000 | [diff] [blame] | 30 | #include "igep00x0.h" |
Enric Balletbo i Serra | 2ce268c | 2010-10-14 16:54:59 -0400 | [diff] [blame] | 31 | |
Pau Pajuelo | 4ddc309 | 2017-08-17 03:09:14 +0200 | [diff] [blame] | 32 | /* |
| 33 | * Routine: get_board_revision |
| 34 | * Description: GPIO_28 and GPIO_129 are used to read board and revision from |
| 35 | * IGEP00x0 boards. First of all, it is necessary to reset USB transceiver from |
| 36 | * IGEP0030 in order to read GPIO_IGEP00X0_BOARD_DETECTION correctly, because |
| 37 | * this functionality is shared by USB HOST. |
Michal Simek | 50fa118 | 2023-05-17 09:17:16 +0200 | [diff] [blame] | 38 | * Once USB reset is applied, U-Boot configures these pins as input pullup to |
Pau Pajuelo | 4ddc309 | 2017-08-17 03:09:14 +0200 | [diff] [blame] | 39 | * detect board and revision: |
| 40 | * IGEP0020-RF = 0b00 |
| 41 | * IGEP0020-RC = 0b01 |
| 42 | * IGEP0030-RG = 0b10 |
| 43 | * IGEP0030-RE = 0b11 |
| 44 | */ |
| 45 | static int get_board_revision(void) |
| 46 | { |
| 47 | int revision; |
| 48 | |
| 49 | gpio_request(IGEP0030_USB_TRANSCEIVER_RESET, |
| 50 | "igep0030_usb_transceiver_reset"); |
| 51 | gpio_direction_output(IGEP0030_USB_TRANSCEIVER_RESET, 0); |
| 52 | |
| 53 | gpio_request(GPIO_IGEP00X0_BOARD_DETECTION, "igep00x0_board_detection"); |
| 54 | gpio_direction_input(GPIO_IGEP00X0_BOARD_DETECTION); |
| 55 | revision = 2 * gpio_get_value(GPIO_IGEP00X0_BOARD_DETECTION); |
| 56 | gpio_free(GPIO_IGEP00X0_BOARD_DETECTION); |
| 57 | |
| 58 | gpio_request(GPIO_IGEP00X0_REVISION_DETECTION, |
| 59 | "igep00x0_revision_detection"); |
| 60 | gpio_direction_input(GPIO_IGEP00X0_REVISION_DETECTION); |
| 61 | revision = revision + gpio_get_value(GPIO_IGEP00X0_REVISION_DETECTION); |
| 62 | gpio_free(GPIO_IGEP00X0_REVISION_DETECTION); |
| 63 | |
| 64 | gpio_free(IGEP0030_USB_TRANSCEIVER_RESET); |
| 65 | |
| 66 | return revision; |
| 67 | } |
| 68 | |
Ladislav Michl | 3e34928 | 2016-07-12 20:28:31 +0200 | [diff] [blame] | 69 | int onenand_board_init(struct mtd_info *mtd) |
| 70 | { |
| 71 | if (gpmc_cs0_flash == MTD_DEV_TYPE_ONENAND) { |
| 72 | struct onenand_chip *this = mtd->priv; |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 73 | this->base = (void *)CFG_SYS_ONENAND_BASE; |
Ladislav Michl | 3e34928 | 2016-07-12 20:28:31 +0200 | [diff] [blame] | 74 | return 0; |
| 75 | } |
| 76 | return 1; |
| 77 | } |
| 78 | |
Ladislav Michl | be8e06d | 2017-01-09 11:21:06 +0100 | [diff] [blame] | 79 | #ifdef CONFIG_OF_BOARD_SETUP |
Ladislav Michl | 4e7241a | 2017-02-19 00:24:49 +0100 | [diff] [blame] | 80 | static int ft_enable_by_compatible(void *blob, char *compat, int enable) |
| 81 | { |
| 82 | int off = fdt_node_offset_by_compatible(blob, -1, compat); |
| 83 | if (off < 0) |
| 84 | return off; |
| 85 | |
| 86 | if (enable) |
| 87 | fdt_status_okay(blob, off); |
| 88 | else |
| 89 | fdt_status_disabled(blob, off); |
| 90 | |
| 91 | return 0; |
| 92 | } |
| 93 | |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 94 | int ft_board_setup(void *blob, struct bd_info *bd) |
Ladislav Michl | be8e06d | 2017-01-09 11:21:06 +0100 | [diff] [blame] | 95 | { |
| 96 | #ifdef CONFIG_FDT_FIXUP_PARTITIONS |
Masahiro Yamada | 20ead6f | 2018-07-19 16:28:23 +0900 | [diff] [blame] | 97 | static const struct node_info nodes[] = { |
Ladislav Michl | be8e06d | 2017-01-09 11:21:06 +0100 | [diff] [blame] | 98 | { "ti,omap2-nand", MTD_DEV_TYPE_NAND, }, |
| 99 | { "ti,omap2-onenand", MTD_DEV_TYPE_ONENAND, }, |
| 100 | }; |
| 101 | |
| 102 | fdt_fixup_mtdparts(blob, nodes, ARRAY_SIZE(nodes)); |
| 103 | #endif |
Ladislav Michl | 4e7241a | 2017-02-19 00:24:49 +0100 | [diff] [blame] | 104 | ft_enable_by_compatible(blob, "ti,omap2-nand", |
| 105 | gpmc_cs0_flash == MTD_DEV_TYPE_NAND); |
| 106 | ft_enable_by_compatible(blob, "ti,omap2-onenand", |
| 107 | gpmc_cs0_flash == MTD_DEV_TYPE_ONENAND); |
| 108 | |
Ladislav Michl | be8e06d | 2017-01-09 11:21:06 +0100 | [diff] [blame] | 109 | return 0; |
| 110 | } |
| 111 | #endif |
| 112 | |
Pau Pajuelo | 4ddc309 | 2017-08-17 03:09:14 +0200 | [diff] [blame] | 113 | void set_led(void) |
Javier Martinez Canillas | 7a0155e | 2013-08-07 17:53:19 +0200 | [diff] [blame] | 114 | { |
Pau Pajuelo | 4ddc309 | 2017-08-17 03:09:14 +0200 | [diff] [blame] | 115 | switch (get_board_revision()) { |
| 116 | case 0: |
| 117 | case 1: |
| 118 | gpio_request(IGEP0020_GPIO_LED, "igep0020_gpio_led"); |
| 119 | gpio_direction_output(IGEP0020_GPIO_LED, 1); |
Javier Martinez Canillas | 7a0155e | 2013-08-07 17:53:19 +0200 | [diff] [blame] | 120 | break; |
Pau Pajuelo | 4ddc309 | 2017-08-17 03:09:14 +0200 | [diff] [blame] | 121 | case 2: |
| 122 | case 3: |
| 123 | gpio_request(IGEP0030_GPIO_LED, "igep0030_gpio_led"); |
| 124 | gpio_direction_output(IGEP0030_GPIO_LED, 0); |
| 125 | break; |
| 126 | default: |
| 127 | /* Should not happen... */ |
Javier Martinez Canillas | 7a0155e | 2013-08-07 17:53:19 +0200 | [diff] [blame] | 128 | break; |
| 129 | } |
| 130 | } |
| 131 | |
Pau Pajuelo | 4ddc309 | 2017-08-17 03:09:14 +0200 | [diff] [blame] | 132 | void set_boardname(void) |
| 133 | { |
| 134 | char rev[5] = { 'F','C','G','E', }; |
| 135 | int i = get_board_revision(); |
| 136 | |
| 137 | rev[i+1] = 0; |
| 138 | env_set("board_rev", rev + i); |
| 139 | env_set("board_name", i < 2 ? "igep0020" : "igep0030"); |
| 140 | } |
| 141 | |
Enric Balletbo i Serra | 2ce268c | 2010-10-14 16:54:59 -0400 | [diff] [blame] | 142 | /* |
| 143 | * Routine: misc_init_r |
| 144 | * Description: Configure board specific parts |
| 145 | */ |
| 146 | int misc_init_r(void) |
| 147 | { |
Pau Pajuelo | 4ddc309 | 2017-08-17 03:09:14 +0200 | [diff] [blame] | 148 | t2_t *t2_base = (t2_t *)T2_BASE; |
| 149 | u32 pbias_lite; |
| 150 | |
Enric Balletbo i Serra | 2ce268c | 2010-10-14 16:54:59 -0400 | [diff] [blame] | 151 | twl4030_power_init(); |
| 152 | |
Pau Pajuelo | 4ddc309 | 2017-08-17 03:09:14 +0200 | [diff] [blame] | 153 | /* set VSIM to 1.8V */ |
| 154 | twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VSIM_DEDICATED, |
| 155 | TWL4030_PM_RECEIVER_VSIM_VSEL_18, |
| 156 | TWL4030_PM_RECEIVER_VSIM_DEV_GRP, |
| 157 | TWL4030_PM_RECEIVER_DEV_GRP_P1); |
| 158 | |
| 159 | /* set up dual-voltage GPIOs to 1.8V */ |
| 160 | pbias_lite = readl(&t2_base->pbias_lite); |
| 161 | pbias_lite &= ~PBIASLITEVMODE1; |
| 162 | pbias_lite |= PBIASLITEPWRDNZ1; |
| 163 | writel(pbias_lite, &t2_base->pbias_lite); |
| 164 | if (get_cpu_family() == CPU_OMAP36XX) |
| 165 | writel(readl(OMAP34XX_CTRL_WKUP_CTRL) | |
| 166 | OMAP34XX_CTRL_WKUP_CTRL_GPIO_IO_PWRDNZ, |
| 167 | OMAP34XX_CTRL_WKUP_CTRL); |
| 168 | |
Paul Kocialkowski | 6bc318e | 2015-08-27 19:37:13 +0200 | [diff] [blame] | 169 | omap_die_id_display(); |
Enric Balletbo i Serra | 2ce268c | 2010-10-14 16:54:59 -0400 | [diff] [blame] | 170 | |
Pau Pajuelo | 4ddc309 | 2017-08-17 03:09:14 +0200 | [diff] [blame] | 171 | set_led(); |
| 172 | |
| 173 | set_boardname(); |
Javier Martinez Canillas | 7a0155e | 2013-08-07 17:53:19 +0200 | [diff] [blame] | 174 | |
Enric Balletbo i Serra | 2ce268c | 2010-10-14 16:54:59 -0400 | [diff] [blame] | 175 | return 0; |
| 176 | } |
| 177 | |
Ladislav Michl | c44e29f | 2016-07-12 20:28:33 +0200 | [diff] [blame] | 178 | void board_mtdparts_default(const char **mtdids, const char **mtdparts) |
| 179 | { |
| 180 | struct mtd_info *mtd = get_mtd_device(NULL, 0); |
| 181 | if (mtd) { |
| 182 | static char ids[24]; |
| 183 | static char parts[48]; |
| 184 | const char *linux_name = "omap2-nand"; |
| 185 | if (strncmp(mtd->name, "onenand0", 8) == 0) |
| 186 | linux_name = "omap2-onenand"; |
| 187 | snprintf(ids, sizeof(ids), "%s=%s", mtd->name, linux_name); |
| 188 | snprintf(parts, sizeof(parts), "mtdparts=%s:%dk(SPL),-(UBI)", |
| 189 | linux_name, 4 * mtd->erasesize >> 10); |
| 190 | *mtdids = ids; |
| 191 | *mtdparts = parts; |
| 192 | } |
| 193 | } |