]> git.ipfire.org Git - people/ms/u-boot.git/blob - arch/arm/mach-uniphier/boot-mode/spl_board.c
854ab056dad4abcac5d0b976b5deb706db44f38c
[people/ms/u-boot.git] / arch / arm / mach-uniphier / boot-mode / spl_board.c
1 /*
2 * Copyright (C) 2016 Socionext Inc.
3 * Author: Masahiro Yamada <yamada.masahiro@socionext.com>
4 *
5 * SPDX-License-Identifier: GPL-2.0+
6 */
7
8 #include <common.h>
9 #include <spl.h>
10 #include <linux/io.h>
11 #include <asm/processor.h>
12
13 #include "../soc-info.h"
14
15 void spl_board_announce_boot_device(void)
16 {
17 printf("eMMC");
18 }
19
20 struct uniphier_romfunc_table {
21 void *mmc_send_cmd;
22 void *mmc_card_blockaddr;
23 void *mmc_switch_part;
24 void *mmc_load_image;
25 };
26
27 static const struct uniphier_romfunc_table uniphier_ld11_romfunc_table = {
28 .mmc_send_cmd = (void *)0x20d8,
29 .mmc_card_blockaddr = (void *)0x1b68,
30 .mmc_switch_part = (void *)0x1c38,
31 .mmc_load_image = (void *)0x2e48,
32 };
33
34 static const struct uniphier_romfunc_table uniphier_ld20_romfunc_table = {
35 .mmc_send_cmd = (void *)0x2130,
36 .mmc_card_blockaddr = (void *)0x1ba0,
37 .mmc_switch_part = (void *)0x1c70,
38 .mmc_load_image = (void *)0x2ef0,
39 };
40
41 int uniphier_rom_get_mmc_funcptr(int (**send_cmd)(u32, u32),
42 int (**card_blockaddr)(u32),
43 int (**switch_part)(int),
44 int (**load_image)(u32, uintptr_t, u32))
45 {
46 const struct uniphier_romfunc_table *table;
47
48 switch (uniphier_get_soc_type()) {
49 case SOC_UNIPHIER_LD11:
50 table = &uniphier_ld11_romfunc_table;
51 break;
52 case SOC_UNIPHIER_LD20:
53 table = &uniphier_ld20_romfunc_table;
54 break;
55 default:
56 printf("unsupported SoC\n");
57 return -EINVAL;
58 }
59
60 *send_cmd = table->mmc_send_cmd;
61 *card_blockaddr = table->mmc_card_blockaddr;
62 *switch_part = table->mmc_switch_part;
63 *load_image = table->mmc_load_image;
64
65 return 0;
66 }
67
68 static int spl_board_load_image(struct spl_image_info *spl_image,
69 struct spl_boot_device *bootdev)
70 {
71 int (*send_cmd)(u32 cmd, u32 arg);
72 int (*card_blockaddr)(u32 rca);
73 int (*switch_part)(int part);
74 int (*load_image)(u32 dev_addr, uintptr_t load_addr, u32 block_cnt);
75 u32 dev_addr = CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR;
76 const u32 rca = 0x1000; /* RCA assigned by Boot ROM */
77 int ret;
78
79 ret = uniphier_rom_get_mmc_funcptr(&send_cmd, &card_blockaddr,
80 &switch_part, &load_image);
81 if (ret)
82 return ret;
83
84 /*
85 * deselect card before SEND_CSD command.
86 * Do not check the return code. It fails, but it is OK.
87 */
88 (*send_cmd)(0x071a0000, 0); /* CMD7 (arg=0) */
89
90 /* reset CMD Line */
91 writeb(0x6, 0x5a00022f);
92 while (readb(0x5a00022f))
93 cpu_relax();
94
95 ret = (*card_blockaddr)(rca);
96 if (ret) {
97 debug("card is block addressing\n");
98 } else {
99 debug("card is byte addressing\n");
100 dev_addr *= 512;
101 }
102
103 ret = (*send_cmd)(0x071a0000, rca << 16); /* CMD7: select card again */
104 if (ret)
105 printf("failed to select card\n");
106
107 ret = (*switch_part)(1); /* Switch to Boot Partition 1 */
108 if (ret)
109 printf("failed to switch partition\n");
110
111 ret = (*load_image)(dev_addr, CONFIG_SYS_TEXT_BASE, 1);
112 if (ret) {
113 printf("failed to load image\n");
114 return ret;
115 }
116
117 ret = spl_parse_image_header(spl_image, (void *)CONFIG_SYS_TEXT_BASE);
118 if (ret)
119 return ret;
120
121 ret = (*load_image)(dev_addr, spl_image->load_addr,
122 spl_image->size / 512);
123 if (ret) {
124 printf("failed to load image\n");
125 return ret;
126 }
127
128 return 0;
129 }
130 SPL_LOAD_IMAGE_METHOD(0, BOOT_DEVICE_BOARD, spl_board_load_image);