GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / shared / hndsoc.c
blob6927d66475f3361b9d46a70839ded57321dca09b
1 /*
2 * Broadcom HNDSoC utlities, only for AP router
3 * File: hndsoc.c
5 * Copyright (C) 2012, Broadcom Corporation. All Rights Reserved.
6 *
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
14 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
16 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
17 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 * $Id$
22 #include <typedefs.h>
23 #include <osl.h>
24 #include <siutils.h>
25 #include <hndsoc.h>
26 #include <sbchipc.h>
27 #include <bcmdevs.h>
28 #include <bcmnvram.h>
29 #include <nand_core.h>
31 static int bootdev = -1;
32 static int knldev = -1;
34 int
35 soc_boot_dev(void *socp)
37 si_t *sih = (si_t *)socp;
38 int bootfrom = SOC_BOOTDEV_SFLASH;
39 uint32 origidx;
40 uint32 option;
42 if (bootdev != -1)
43 return bootdev;
45 origidx = si_coreidx(sih);
47 /* Check 4707 (NorthStar) */
48 if (sih->ccrev == 42) {
49 if (si_setcore(sih, NS_ROM_CORE_ID, 0) != NULL) {
50 option = si_core_sflags(sih, 0, 0) & SISF_NS_BOOTDEV_MASK;
51 if (option == SISF_NS_BOOTDEV_NOR) {
52 bootfrom = SOC_BOOTDEV_SFLASH;
54 else if (option == SISF_NS_BOOTDEV_NAND) {
55 bootfrom = SOC_BOOTDEV_NANDFLASH;
57 else {
58 /* This must be SISF_NS_BOOTDEV_ROM */
59 bootfrom = SOC_BOOTDEV_ROM;
63 else {
64 chipcregs_t *cc;
66 /* Check 5357 */
67 if (sih->ccrev == 38) {
68 if ((sih->chipst & (1 << 4)) != 0) {
69 bootfrom = SOC_BOOTDEV_NANDFLASH;
70 goto found;
72 else if ((sih->chipst & (1 << 5)) != 0) {
73 bootfrom = SOC_BOOTDEV_ROM;
74 goto found;
78 /* Handle old soc, 4704, 4718 */
79 if ((cc = (chipcregs_t *)si_setcoreidx(sih, SI_CC_IDX))) {
80 option = R_REG(NULL, &cc->capabilities) & CC_CAP_FLASH_MASK;
81 if (option == PFLASH)
82 bootfrom = SOC_BOOTDEV_PFLASH;
83 else
84 bootfrom = SOC_BOOTDEV_SFLASH;
88 found:
89 si_setcoreidx(sih, origidx);
91 bootdev = bootfrom;
92 return bootdev;
95 int
96 soc_knl_dev(void *socp)
98 si_t *sih = (si_t *)socp;
99 char *val;
100 int knlfrom = SOC_KNLDEV_NORFLASH;
102 if (knldev != -1)
103 return knldev;
105 if (soc_boot_dev(socp) == SOC_BOOTDEV_NANDFLASH) {
106 knlfrom = SOC_KNLDEV_NANDFLASH;
107 goto found;
110 if (((CHIPID(sih->chip) == BCM4706_CHIP_ID) || sih->ccrev == 38) &&
111 (sih->cccaps & CC_CAP_NFLASH)) {
112 goto check_nv;
114 else if (sih->ccrev == 42) {
115 uint32 origidx;
116 nandregs_t *nc;
117 uint32 id = 0;
119 origidx = si_coreidx(sih);
120 if ((nc = (nandregs_t *)si_setcore(sih, NS_NAND_CORE_ID, 0)) != NULL) {
121 id = R_REG(NULL, &nc->flash_device_id);
123 si_setcoreidx(sih, origidx);
125 if (id != 0)
126 goto check_nv;
128 else {
129 /* Break through */
132 /* Default set to nor boot */
133 goto found;
135 check_nv:
136 /* Check NVRAM here */
137 if ((val = nvram_get("bootflags")) != NULL) {
138 int bootflags;
139 #ifdef linux
140 bootflags = simple_strtol(val, NULL, 0);
141 #else
142 bootflags = atoi(val);
143 #endif
144 if (bootflags & FLASH_KERNEL_NFLASH)
145 knlfrom = SOC_KNLDEV_NANDFLASH;
148 found:
149 knldev = knlfrom;
150 return knldev;