1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * (C) Copyright 2010
4 * Vipin Kumar, ST Micoelectronics, vipin.kumar@st.com.
5 */
6
7 #include <common.h>
8 #include <command.h>
9 #include <init.h>
10 #include <asm/io.h>
11 #include <asm/arch/hardware.h>
12 #include <asm/arch/spr_misc.h>
13
arch_cpu_init(void)14 int arch_cpu_init(void)
15 {
16 struct misc_regs *const misc_p =
17 (struct misc_regs *)CONFIG_SPEAR_MISCBASE;
18 u32 periph1_clken, periph_clk_cfg;
19
20 periph1_clken = readl(&misc_p->periph1_clken);
21
22 #if defined(CONFIG_SPEAR3XX)
23 periph1_clken |= MISC_GPT2ENB;
24 #elif defined(CONFIG_SPEAR600)
25 periph1_clken |= MISC_GPT3ENB;
26 #endif
27
28 #if defined(CONFIG_PL011_SERIAL)
29 periph1_clken |= MISC_UART0ENB;
30
31 periph_clk_cfg = readl(&misc_p->periph_clk_cfg);
32 periph_clk_cfg &= ~CONFIG_SPEAR_UARTCLKMSK;
33 periph_clk_cfg |= CONFIG_SPEAR_UART48M;
34 writel(periph_clk_cfg, &misc_p->periph_clk_cfg);
35 #endif
36 #if defined(CONFIG_ETH_DESIGNWARE)
37 periph1_clken |= MISC_ETHENB;
38 #endif
39 #if defined(CONFIG_DW_UDC)
40 periph1_clken |= MISC_USBDENB;
41 #endif
42 #if defined(CONFIG_SYS_I2C_DW)
43 periph1_clken |= MISC_I2CENB;
44 #endif
45 #if defined(CONFIG_ST_SMI)
46 periph1_clken |= MISC_SMIENB;
47 #endif
48 #if defined(CONFIG_NAND_FSMC)
49 periph1_clken |= MISC_FSMCENB;
50 #endif
51 #if defined(CONFIG_USB_EHCI_SPEAR)
52 periph1_clken |= PERIPH_USBH1 | PERIPH_USBH2;
53 #endif
54 #if defined(CONFIG_SPEAR_GPIO)
55 periph1_clken |= MISC_GPIO3ENB | MISC_GPIO4ENB;
56 #endif
57 #if defined(CONFIG_PL022_SPI)
58 periph1_clken |= MISC_SSP1ENB | MISC_SSP2ENB | MISC_SSP3ENB;
59 #endif
60
61 writel(periph1_clken, &misc_p->periph1_clken);
62
63 return 0;
64 }
65
66 #ifdef CONFIG_DISPLAY_CPUINFO
print_cpuinfo(void)67 int print_cpuinfo(void)
68 {
69 #ifdef CONFIG_SPEAR300
70 printf("CPU: SPEAr300\n");
71 #elif defined(CONFIG_SPEAR310)
72 printf("CPU: SPEAr310\n");
73 #elif defined(CONFIG_SPEAR320)
74 printf("CPU: SPEAr320\n");
75 #elif defined(CONFIG_SPEAR600)
76 printf("CPU: SPEAr600\n");
77 #else
78 #error CPU not supported in spear platform
79 #endif
80 return 0;
81 }
82 #endif
83
84 #if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_NAND_ECC_BCH) && defined(CONFIG_NAND_FSMC)
do_switch_ecc(struct cmd_tbl * cmdtp,int flag,int argc,char * const argv[])85 static int do_switch_ecc(struct cmd_tbl *cmdtp, int flag, int argc,
86 char *const argv[])
87 {
88 if (argc != 2)
89 goto usage;
90
91 if (strncmp(argv[1], "hw", 2) == 0) {
92 /* 1-bit HW ECC */
93 printf("Switching to 1-bit HW ECC\n");
94 fsmc_nand_switch_ecc(1);
95 } else if (strncmp(argv[1], "bch4", 2) == 0) {
96 /* 4-bit SW ECC BCH4 */
97 printf("Switching to 4-bit SW ECC (BCH4)\n");
98 fsmc_nand_switch_ecc(4);
99 } else {
100 goto usage;
101 }
102
103 return 0;
104
105 usage:
106 printf("Usage: nandecc %s\n", cmdtp->usage);
107 return 1;
108 }
109
110 U_BOOT_CMD(
111 nandecc, 2, 0, do_switch_ecc,
112 "switch NAND ECC calculation algorithm",
113 "hw|bch4 - Switch between NAND hardware 1-bit HW and"
114 " 4-bit SW BCH\n"
115 );
116 #endif
117