blob: f29383dc30149fb4c255025b24caa48664639d6d [file] [log] [blame]
Mingkai Huf3a8e2b2015-10-26 19:47:52 +08001/*
2 * Copyright 2015 Freescale Semiconductor
3 *
4 * SPDX-License-Identifier: GPL-2.0+
5 *
6 * Freescale LS1043ARDB board-specific CPLD controlling supports.
7 */
8
9#include <common.h>
10#include <command.h>
11#include <asm/io.h>
12#include "cpld.h"
13
14u8 cpld_read(unsigned int reg)
15{
16 void *p = (void *)CONFIG_SYS_CPLD_BASE;
17
18 return in_8(p + reg);
19}
20
21void cpld_write(unsigned int reg, u8 value)
22{
23 void *p = (void *)CONFIG_SYS_CPLD_BASE;
24
25 out_8(p + reg, value);
26}
27
28/* Set the boot bank to the alternate bank */
29void cpld_set_altbank(void)
30{
31 u8 reg4 = CPLD_READ(soft_mux_on);
32 u8 reg7 = CPLD_READ(vbank);
33
34 CPLD_WRITE(soft_mux_on, reg4 | CPLD_SW_MUX_BANK_SEL);
35
36 reg7 = (reg7 & ~CPLD_BANK_SEL_MASK) | CPLD_BANK_SEL_ALTBANK;
37 CPLD_WRITE(vbank, reg7);
38
39 CPLD_WRITE(system_rst, 1);
40}
41
42/* Set the boot bank to the default bank */
43void cpld_set_defbank(void)
44{
45 CPLD_WRITE(global_rst, 1);
46}
47
Gong Qianyu3ad44722015-10-26 19:47:53 +080048void cpld_set_nand(void)
49{
50 u16 reg = CPLD_CFG_RCW_SRC_NAND;
51 u8 reg5 = (u8)(reg >> 1);
52 u8 reg6 = (u8)(reg & 1);
53
54 cpld_rev_bit(&reg5);
55
56 CPLD_WRITE(soft_mux_on, 1);
57
58 CPLD_WRITE(cfg_rcw_src1, reg5);
59 CPLD_WRITE(cfg_rcw_src2, reg6);
60
61 CPLD_WRITE(system_rst, 1);
62}
63
Mingkai Huf3a8e2b2015-10-26 19:47:52 +080064#ifdef DEBUG
65static void cpld_dump_regs(void)
66{
67 printf("cpld_ver = %x\n", CPLD_READ(cpld_ver));
68 printf("cpld_ver_sub = %x\n", CPLD_READ(cpld_ver_sub));
69 printf("pcba_ver = %x\n", CPLD_READ(pcba_ver));
70 printf("soft_mux_on = %x\n", CPLD_READ(soft_mux_on));
71 printf("cfg_rcw_src1 = %x\n", CPLD_READ(cfg_rcw_src1));
72 printf("cfg_rcw_src2 = %x\n", CPLD_READ(cfg_rcw_src2));
73 printf("vbank = %x\n", CPLD_READ(vbank));
74 printf("sysclk_sel = %x\n", CPLD_READ(sysclk_sel));
75 printf("uart_sel = %x\n", CPLD_READ(uart_sel));
76 printf("sd1refclk_sel = %x\n", CPLD_READ(sd1refclk_sel));
77 printf("tdmclk_mux_sel = %x\n", CPLD_READ(tdmclk_mux_sel));
78 printf("sdhc_spics_sel = %x\n", CPLD_READ(sdhc_spics_sel));
79 printf("status_led = %x\n", CPLD_READ(status_led));
80 putc('\n');
81}
82#endif
83
84void cpld_rev_bit(unsigned char *value)
85{
86 u8 rev_val, val;
87 int i;
88
89 val = *value;
90 rev_val = val & 1;
91 for (i = 1; i <= 7; i++) {
92 val >>= 1;
93 rev_val <<= 1;
94 rev_val |= val & 1;
95 }
96
97 *value = rev_val;
98}
99
100int do_cpld(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
101{
102 int rc = 0;
103
104 if (argc <= 1)
105 return cmd_usage(cmdtp);
106
107 if (strcmp(argv[1], "reset") == 0) {
108 if (strcmp(argv[2], "altbank") == 0)
109 cpld_set_altbank();
Gong Qianyu3ad44722015-10-26 19:47:53 +0800110 else if (strcmp(argv[2], "nand") == 0)
111 cpld_set_nand();
Mingkai Huf3a8e2b2015-10-26 19:47:52 +0800112 else
113 cpld_set_defbank();
114#ifdef DEBUG
115 } else if (strcmp(argv[1], "dump") == 0) {
116 cpld_dump_regs();
117#endif
118 } else {
119 rc = cmd_usage(cmdtp);
120 }
121
122 return rc;
123}
124
125U_BOOT_CMD(
126 cpld, CONFIG_SYS_MAXARGS, 1, do_cpld,
127 "Reset the board or alternate bank",
128 "reset: reset to default bank\n"
129 "cpld reset altbank: reset to alternate bank\n"
Gong Qianyu3ad44722015-10-26 19:47:53 +0800130 "cpld reset nand: reset to boot from NAND flash\n"
Mingkai Huf3a8e2b2015-10-26 19:47:52 +0800131#ifdef DEBUG
132 "cpld dump - display the CPLD registers\n"
133#endif
134);