blob: f908db8027168828ca317bfb6bd1581cb0c1c232 [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;
Sridhar Parasuramfb0d9c82015-02-02 15:23:13 -080044 unsigned id2;
Shashank Mittal83d16d02009-11-18 16:54:42 -080045 unsigned type;
Dima Zavinfbde0ac2009-03-02 16:39:18 -080046 unsigned vendor;
47 unsigned device;
48 unsigned page_size;
49 unsigned block_size;
50 unsigned spare_size;
51 unsigned num_blocks;
Deepa Dinamanie4573be2012-08-03 16:32:29 -070052 enum nand_ecc_width ecc_width;
53 unsigned num_pages_per_blk;
54 unsigned num_pages_per_blk_mask;
55 unsigned widebus;
56 unsigned density;
57 unsigned cw_size;
58 unsigned cws_per_page;
59 unsigned bad_blk_loc;
60 unsigned blksize;
61 unsigned dev_cfg;
Dima Zavinfbde0ac2009-03-02 16:39:18 -080062};
63
Dima Zavine5f64352009-03-02 16:04:20 -080064void flash_init(void);
Dima Zavine12b4112009-01-23 16:36:23 -080065struct ptable *flash_get_ptable(void);
Dima Zavine5f64352009-03-02 16:04:20 -080066void flash_set_ptable(struct ptable *ptable);
Dima Zavinfbde0ac2009-03-02 16:39:18 -080067struct flash_info *flash_get_info(void);
Dima Zavine12b4112009-01-23 16:36:23 -080068
69/* flash operations */
70int flash_erase(struct ptentry *ptn);
71int flash_read_ext(struct ptentry *ptn, unsigned extra_per_page,
72 unsigned offset, void *data, unsigned bytes);
Deepa Dinamani0fd7e4b2013-04-30 15:46:04 -070073int flash_write(struct ptentry *ptn, unsigned write_extra_bytes, const void *data,
Dima Zavine12b4112009-01-23 16:36:23 -080074 unsigned bytes);
Dima Zavine12b4112009-01-23 16:36:23 -080075static inline int flash_read(struct ptentry *ptn, unsigned offset, void *data,
76 unsigned bytes)
77{
78 return flash_read_ext(ptn, 0, offset, data, bytes);
79}
Gaurav Nebhwani64092f22016-05-20 13:58:21 +053080
81unsigned flash_num_pages_per_blk(void);
Shashank Mittaldcc2e352009-11-19 19:11:16 -080082unsigned flash_page_size(void);
Tanya Brokhman72b44dc2015-01-07 10:20:05 +020083unsigned flash_block_size(void);
84unsigned flash_spare_size(void);
Channagoud Kadabi404a7062011-03-21 19:27:50 +053085int flash_ecc_bch_enabled(void);
Dima Zavine12b4112009-01-23 16:36:23 -080086
87
88#endif /* __DEV_FLASH_H */