blob: 25257f1daf7169a65553a740699780e9a4f9355d [file] [log] [blame]
Dima Zavine12b4112009-01-23 16:36:23 -08001/*
Tanya Brokhman0993da02015-01-29 09:36:10 +02002 * Copyright (c) 2014-2015, The Linux Foundation. All rights reserved.
Dima Zavine12b4112009-01-23 16:36:23 -08003 * Copyright (c) 2008, Google Inc.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
19 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
20 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
22 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
23 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
26 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30
31#ifndef __DEV_FLASH_H
32#define __DEV_FLASH_H
33
34#include <lib/ptable.h>
35
Deepa Dinamanie4573be2012-08-03 16:32:29 -070036enum nand_ecc_width
37{
38 NAND_WITH_4_BIT_ECC,
39 NAND_WITH_8_BIT_ECC,
40};
Shashank Mittaldcc2e352009-11-19 19:11:16 -080041
Dima Zavinfbde0ac2009-03-02 16:39:18 -080042struct flash_info {
Shashank Mittal83d16d02009-11-18 16:54:42 -080043 unsigned id;
44 unsigned type;
Dima Zavinfbde0ac2009-03-02 16:39:18 -080045 unsigned vendor;
46 unsigned device;
47 unsigned page_size;
48 unsigned block_size;
49 unsigned spare_size;
50 unsigned num_blocks;
Deepa Dinamanie4573be2012-08-03 16:32:29 -070051 enum nand_ecc_width ecc_width;
52 unsigned num_pages_per_blk;
53 unsigned num_pages_per_blk_mask;
54 unsigned widebus;
55 unsigned density;
56 unsigned cw_size;
57 unsigned cws_per_page;
58 unsigned bad_blk_loc;
59 unsigned blksize;
60 unsigned dev_cfg;
Dima Zavinfbde0ac2009-03-02 16:39:18 -080061};
62
Dima Zavine5f64352009-03-02 16:04:20 -080063void flash_init(void);
Dima Zavine12b4112009-01-23 16:36:23 -080064struct ptable *flash_get_ptable(void);
Dima Zavine5f64352009-03-02 16:04:20 -080065void flash_set_ptable(struct ptable *ptable);
Dima Zavinfbde0ac2009-03-02 16:39:18 -080066struct flash_info *flash_get_info(void);
Dima Zavine12b4112009-01-23 16:36:23 -080067
68/* flash operations */
69int flash_erase(struct ptentry *ptn);
70int flash_read_ext(struct ptentry *ptn, unsigned extra_per_page,
71 unsigned offset, void *data, unsigned bytes);
Deepa Dinamani0fd7e4b2013-04-30 15:46:04 -070072int flash_write(struct ptentry *ptn, unsigned write_extra_bytes, const void *data,
Dima Zavine12b4112009-01-23 16:36:23 -080073 unsigned bytes);
Dima Zavine12b4112009-01-23 16:36:23 -080074static inline int flash_read(struct ptentry *ptn, unsigned offset, void *data,
75 unsigned bytes)
76{
77 return flash_read_ext(ptn, 0, offset, data, bytes);
78}
Shashank Mittaldcc2e352009-11-19 19:11:16 -080079unsigned flash_page_size(void);
Tanya Brokhman72b44dc2015-01-07 10:20:05 +020080unsigned flash_block_size(void);
81unsigned flash_spare_size(void);
Channagoud Kadabi404a7062011-03-21 19:27:50 +053082int flash_ecc_bch_enabled(void);
Dima Zavine12b4112009-01-23 16:36:23 -080083
84
85#endif /* __DEV_FLASH_H */