2 * Broadcom chipcommon NAND flash interface
4 * Copyright (C) 2013, Broadcom Corporation. All Rights Reserved.
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.
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.
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 */
40 hndnand_init(si_t
*sih
)
46 /* Already initialized ? */
50 origidx
= si_coreidx(sih
);
54 hndnand
= nflash_init(sih
);
56 #ifdef __ARM_ARCH_7A__
58 hndnand
= nandcore_init(sih
);
61 si_setcoreidx(sih
, origidx
);
66 hndnand_enable(hndnand_t
*nfl
, int enable
)
71 /* Should spinlock here */
72 (nfl
->enable
)(nfl
, enable
);
78 /* Read len bytes starting at offset into buf. Returns number of bytes read. */
80 hndnand_read(hndnand_t
*nfl
, uint64 offset
, uint len
, uchar
*buf
)
85 return (nfl
->read
)(nfl
, offset
, len
, buf
);
88 /* Write len bytes starting at offset into buf. Returns number of bytes
92 hndnand_write(hndnand_t
*nfl
, uint64 offset
, uint len
, const uchar
*buf
)
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
)
109 return (nfl
->erase
)(nfl
, offset
);
113 hndnand_checkbadb(hndnand_t
*nfl
, uint64 offset
)
116 ASSERT(nfl
->checkbadb
);
118 return (nfl
->checkbadb
)(nfl
, offset
);
122 hndnand_mark_badb(hndnand_t
*nfl
, uint64 offset
)
125 ASSERT(nfl
->markbadb
);
127 return (nfl
->markbadb
)(nfl
, offset
);
132 hndnand_dev_ready(hndnand_t
*nfl
)
135 ASSERT(nfl
->dev_ready
);
137 return (nfl
->dev_ready
)(nfl
);
141 hndnand_select_chip(hndnand_t
*nfl
, int chip
)
144 ASSERT(nfl
->select_chip
);
146 return (nfl
->select_chip
)(nfl
, chip
);
149 int hndnand_cmdfunc(hndnand_t
*nfl
, uint64 addr
, int cmd
)
152 ASSERT(nfl
->cmdfunc
);
154 return (nfl
->cmdfunc
)(nfl
, addr
, cmd
);
158 hndnand_waitfunc(hndnand_t
*nfl
, int *status
)
161 ASSERT(nfl
->waitfunc
);
163 return (nfl
->waitfunc
)(nfl
, status
);
167 hndnand_read_oob(hndnand_t
*nfl
, uint64 addr
, uint8
*oob
)
170 ASSERT(nfl
->read_oob
);
172 return (nfl
->read_oob
)(nfl
, addr
, oob
);
176 hndnand_write_oob(hndnand_t
*nfl
, uint64 addr
, uint8
*oob
)
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
)
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
)
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
)
206 ASSERT(nfl
->cmd_read_byte
);
208 return (nfl
->cmd_read_byte
)(nfl
, cmd
, arg
);