2 * Broadcom chipcommon NAND flash interface
4 * Copyright (C) 2012, 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.
29 #include <hndsflash.h>
31 /* Private global state */
32 static hndsflash_t
*hndsflash
;
34 hndsflash_t
*ccsflash_init(si_t
*sih
);
35 hndsflash_t
*spiflash_init(si_t
*sih
);
37 /* Initialize nand flash access */
39 hndsflash_init(si_t
*sih
)
45 /* Already initialized ? */
50 origidx
= si_coreidx(sih
);
54 hndsflash
= ccsflash_init(sih
);
56 #ifdef __ARM_ARCH_7A__
58 hndsflash
= spiflash_init(sih
);
59 #endif /* __ARM_ARCH_7A__ */
61 si_setcoreidx(sih
, origidx
);
65 /* Read len bytes starting at offset into buf. Returns number of bytes read. */
67 hndsflash_read(hndsflash_t
*sfl
, uint offset
, uint len
, const uchar
*buf
)
72 return (sfl
->read
)(sfl
, offset
, len
, buf
);
75 /* Write len bytes starting at offset into buf. Returns number of bytes
79 hndsflash_write(hndsflash_t
*sfl
, uint offset
, uint len
, const uchar
*buf
)
84 return (sfl
->write
)(sfl
, offset
, len
, (const uchar
*)buf
);
87 /* Erase a region. Returns number of bytes scheduled for erasure.
88 * Caller should poll for completion.
91 hndsflash_erase(hndsflash_t
*sfl
, uint offset
)
96 return (sfl
->erase
)(sfl
, offset
);
100 * writes the appropriate range of flash, a NULL buf simply erases
101 * the region of flash
103 int hndsflash_commit(hndsflash_t
*sfl
, uint offset
, uint len
, const uchar
*buf
)
108 return (sfl
->commit
)(sfl
, offset
, len
, (const uchar
*)buf
);
111 /* Poll for command completion. Returns zero when complete. */
112 int hndsflash_poll(hndsflash_t
*sfl
, uint offset
)
119 return (sfl
->poll
)(sfl
, offset
);