GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / shared / hndnand.c
blob090b817d5985935f24ccad969d5d5cf6427471f1
1 /*
2 * Broadcom chipcommon NAND flash interface
4 * Copyright (C) 2012, Broadcom Corporation. All Rights Reserved.
5 *
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
13 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
15 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
16 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 * $Id:$
21 #include <typedefs.h>
22 #include <osl.h>
23 #include <bcmutils.h>
24 #include <siutils.h>
25 #include <hndsoc.h>
26 #include <sbhndcpu.h>
27 #include <sbchipc.h>
28 #include <bcmdevs.h>
29 #include <hndnand.h>
30 #include <hndpmu.h>
32 /* Private global state */
33 static hndnand_t *hndnand = NULL;
35 extern hndnand_t *nflash_init(si_t *sih);
36 extern hndnand_t *nandcore_init(si_t *sih);
38 /* Initialize nand flash access */
39 hndnand_t *
40 hndnand_init(si_t *sih)
42 uint32 origidx;
44 ASSERT(sih);
46 /* Already initialized ? */
47 if (hndnand)
48 return hndnand;
50 origidx = si_coreidx(sih);
52 #ifdef __mips__
53 if (!hndnand)
54 hndnand = nflash_init(sih);
55 #endif
56 #ifdef __ARM_ARCH_7A__
57 if (!hndnand)
58 hndnand = nandcore_init(sih);
59 #endif
61 si_setcoreidx(sih, origidx);
62 return hndnand;
65 void
66 hndnand_enable(hndnand_t *nfl, int enable)
68 ASSERT(nfl);
70 if (nfl->enable) {
71 /* Should spinlock here */
72 (nfl->enable)(nfl, enable);
75 return;
78 /* Read len bytes starting at offset into buf. Returns number of bytes read. */
79 int
80 hndnand_read(hndnand_t *nfl, uint64 offset, uint len, uchar *buf)
82 ASSERT(nfl);
83 ASSERT(nfl->read);
85 return (nfl->read)(nfl, offset, len, buf);
88 /* Write len bytes starting at offset into buf. Returns number of bytes
89 * written.
91 int
92 hndnand_write(hndnand_t *nfl, uint64 offset, uint len, const uchar *buf)
94 ASSERT(nfl);
95 ASSERT(nfl->write);
97 return (nfl->write)(nfl, offset, len, buf);
100 /* Erase a region. Returns number of bytes scheduled for erasure.
101 * Caller should poll for completion.
104 hndnand_erase(hndnand_t *nfl, uint64 offset)
106 ASSERT(nfl);
107 ASSERT(nfl->erase);
109 return (nfl->erase)(nfl, offset);
113 hndnand_checkbadb(hndnand_t *nfl, uint64 offset)
115 ASSERT(nfl);
116 ASSERT(nfl->checkbadb);
118 return (nfl->checkbadb)(nfl, offset);
122 hndnand_mark_badb(hndnand_t *nfl, uint64 offset)
124 ASSERT(nfl);
125 ASSERT(nfl->markbadb);
127 return (nfl->markbadb)(nfl, offset);
130 #ifndef _CFE_
132 hndnand_dev_ready(hndnand_t *nfl)
134 ASSERT(nfl);
135 ASSERT(nfl->dev_ready);
137 return (nfl->dev_ready)(nfl);
141 hndnand_select_chip(hndnand_t *nfl, int chip)
143 ASSERT(nfl);
144 ASSERT(nfl->select_chip);
146 return (nfl->select_chip)(nfl, chip);
149 int hndnand_cmdfunc(hndnand_t *nfl, uint64 addr, int cmd)
151 ASSERT(nfl);
152 ASSERT(nfl->cmdfunc);
154 return (nfl->cmdfunc)(nfl, addr, cmd);
158 hndnand_waitfunc(hndnand_t *nfl, int *status)
160 ASSERT(nfl);
161 ASSERT(nfl->waitfunc);
163 return (nfl->waitfunc)(nfl, status);
167 hndnand_read_oob(hndnand_t *nfl, uint64 addr, uint8 *oob)
169 ASSERT(nfl);
170 ASSERT(nfl->read_oob);
172 return (nfl->read_oob)(nfl, addr, oob);
176 hndnand_write_oob(hndnand_t *nfl, uint64 addr, uint8 *oob)
178 ASSERT(nfl);
179 ASSERT(nfl->write_oob);
181 return (nfl->write_oob)(nfl, addr, oob);
184 hndnand_read_page(hndnand_t *nfl, uint64 addr, uint8 *buf, uint8 *oob, bool ecc,
185 uint32 *herr, uint32 *serr)
187 ASSERT(nfl);
188 ASSERT(nfl->read_page);
190 return (nfl->read_page)(nfl, addr, buf, oob, ecc, herr, serr);
194 hndnand_write_page(hndnand_t *nfl, uint64 addr, const uint8 *buf, uint8 *oob, bool ecc)
196 ASSERT(nfl);
197 ASSERT(nfl->write_page);
199 return (nfl->write_page)(nfl, addr, buf, oob, ecc);
203 hndnand_cmd_read_byte(hndnand_t *nfl, int cmd, int arg)
205 ASSERT(nfl);
206 ASSERT(nfl->cmd_read_byte);
208 return (nfl->cmd_read_byte)(nfl, cmd, arg);
210 #endif /* _CFE_ */