Blame view

include/nand.h 4.42 KB
932394ac4   Wolfgang Denk   Rewrite of NAND c...
1
2
3
4
5
  /*
   * (C) Copyright 2005
   * 2N Telekomunikace, a.s. <www.2n.cz>
   * Ladislav Michl <michl@2n.cz>
   *
5b8031ccb   Tom Rini   Add more SPDX-Lic...
6
   * SPDX-License-Identifier:	GPL-2.0
932394ac4   Wolfgang Denk   Rewrite of NAND c...
7
8
9
10
   */
  
  #ifndef _NAND_H_
  #define _NAND_H_
c17834749   Scott Wood   nand/fsl_elbc: Co...
11
12
13
14
15
16
17
  #include <config.h>
  
  /*
   * All boards using a given driver must convert to self-init
   * at the same time, so do it here.  When all drivers are
   * converted, this will go away.
   */
0b0b4f598   Bo Shen   mtd: nand: atmel:...
18
19
20
21
22
  #ifdef CONFIG_SPL_BUILD
  #if defined(CONFIG_NAND_FSL_ELBC) || defined(CONFIG_NAND_FSL_IFC)
  #define CONFIG_SYS_NAND_SELF_INIT
  #endif
  #else
a1b81ab26   Prabhakar Kushwaha   nand/fsl_ifc: Con...
23
24
  #if defined(CONFIG_NAND_FSL_ELBC) || defined(CONFIG_NAND_ATMEL)\
  	|| defined(CONFIG_NAND_FSL_IFC)
c17834749   Scott Wood   nand/fsl_elbc: Co...
25
26
  #define CONFIG_SYS_NAND_SELF_INIT
  #endif
0b0b4f598   Bo Shen   mtd: nand: atmel:...
27
  #endif
c17834749   Scott Wood   nand/fsl_elbc: Co...
28

9d2e3947b   Scott Wood   NAND: ifdef-prote...
29
  extern void nand_init(void);
203db38a9   Hou Zhiqiang   mtd: nand: remove...
30
  unsigned long nand_size(void);
9d2e3947b   Scott Wood   NAND: ifdef-prote...
31

7b15e2bb9   Mike Frysinger   linux/compat.h: r...
32
  #include <linux/compat.h>
932394ac4   Wolfgang Denk   Rewrite of NAND c...
33
  #include <linux/mtd/mtd.h>
6ae3900a8   Masahiro Yamada   mtd: nand: Rename...
34
  #include <linux/mtd/rawnand.h>
932394ac4   Wolfgang Denk   Rewrite of NAND c...
35

b616d9b0a   Scott Wood   nand: Embed mtd_i...
36
  int nand_mtd_to_devnum(struct mtd_info *mtd);
578931b34   Scott Wood   nand: Introduce C...
37
38
  #ifdef CONFIG_SYS_NAND_SELF_INIT
  void board_nand_init(void);
b616d9b0a   Scott Wood   nand: Embed mtd_i...
39
  int nand_register(int devnum, struct mtd_info *mtd);
578931b34   Scott Wood   nand: Introduce C...
40
  #else
69fb8be4f   Mike Frysinger   NAND: move board_...
41
  extern int board_nand_init(struct nand_chip *nand);
578931b34   Scott Wood   nand: Introduce C...
42
  #endif
69fb8be4f   Mike Frysinger   NAND: move board_...
43

932394ac4   Wolfgang Denk   Rewrite of NAND c...
44
  extern int nand_curr_device;
932394ac4   Wolfgang Denk   Rewrite of NAND c...
45

151c06ec6   Scott Wood   mtd: nand: Remove...
46
47
  static inline int nand_read(struct mtd_info *info, loff_t ofs, size_t *len,
  			    u_char *buf)
932394ac4   Wolfgang Denk   Rewrite of NAND c...
48
  {
dfe64e2c8   Sergey Lapin   mtd: resync with ...
49
  	return mtd_read(info, ofs, *len, (size_t *)len, buf);
932394ac4   Wolfgang Denk   Rewrite of NAND c...
50
  }
151c06ec6   Scott Wood   mtd: nand: Remove...
51
52
  static inline int nand_write(struct mtd_info *info, loff_t ofs, size_t *len,
  			     u_char *buf)
932394ac4   Wolfgang Denk   Rewrite of NAND c...
53
  {
dfe64e2c8   Sergey Lapin   mtd: resync with ...
54
  	return mtd_write(info, ofs, *len, (size_t *)len, buf);
932394ac4   Wolfgang Denk   Rewrite of NAND c...
55
  }
151c06ec6   Scott Wood   mtd: nand: Remove...
56
  static inline int nand_block_isbad(struct mtd_info *info, loff_t ofs)
932394ac4   Wolfgang Denk   Rewrite of NAND c...
57
  {
dfe64e2c8   Sergey Lapin   mtd: resync with ...
58
  	return mtd_block_isbad(info, ofs);
932394ac4   Wolfgang Denk   Rewrite of NAND c...
59
  }
151c06ec6   Scott Wood   mtd: nand: Remove...
60
  static inline int nand_erase(struct mtd_info *info, loff_t off, size_t size)
932394ac4   Wolfgang Denk   Rewrite of NAND c...
61
  {
8e9655f86   Wolfgang Denk   * Add hook to NAN...
62
63
64
65
66
67
  	struct erase_info instr;
  
  	instr.mtd = info;
  	instr.addr = off;
  	instr.len = size;
  	instr.callback = 0;
dfe64e2c8   Sergey Lapin   mtd: resync with ...
68
  	return mtd_erase(info, &instr);
932394ac4   Wolfgang Denk   Rewrite of NAND c...
69
  }
2255b2d20   Stefan Roese   * Several improve...
70
71
72
73
  
  /*****************************************************************************
   * declarations from nand_util.c
   ****************************************************************************/
cfa460adf   William Juul   Update MTD to tha...
74
  typedef struct mtd_oob_ops mtd_oob_ops_t;
2255b2d20   Stefan Roese   * Several improve...
75

2255b2d20   Stefan Roese   * Several improve...
76
  struct nand_erase_options {
304863225   Scott Wood   nand erase: .spre...
77
78
  	loff_t length;		/* number of bytes to erase */
  	loff_t offset;		/* first address in NAND to erase */
2255b2d20   Stefan Roese   * Several improve...
79
80
81
82
83
  	int quiet;		/* don't display progress messages */
  	int jffs2;		/* if true: format for jffs2 usage
  				 * (write appropriate cleanmarker blocks) */
  	int scrub;		/* if true, really clean NAND by erasing
  				 * bad blocks (UNSAFE) */
304863225   Scott Wood   nand erase: .spre...
84
85
86
  
  	/* Don't include skipped bad blocks in size to be erased */
  	int spread;
a67cc37e6   Heiko Schocher   dfu, nand: before...
87
88
  	/* maximum size that actual may be in order to not exceed the buf */
  	loff_t lim;
2255b2d20   Stefan Roese   * Several improve...
89
90
91
  };
  
  typedef struct nand_erase_options nand_erase_options_t;
151c06ec6   Scott Wood   mtd: nand: Remove...
92
  int nand_read_skip_bad(struct mtd_info *mtd, loff_t offset, size_t *length,
c39d6a0ea   Tom Rini   nand: Extend nand...
93
  		       size_t *actual, loff_t lim, u_char *buffer);
a6c9aa1f9   Ben Gardiner   nand_util: conver...
94

004a1fdb4   Peter Tyser   nand: yaffs: Remo...
95
96
  #define WITH_DROP_FFS	(1 << 0) /* drop trailing all-0xff pages */
  #define WITH_WR_VERIFY	(1 << 1) /* verify data was written correctly */
a6c9aa1f9   Ben Gardiner   nand_util: conver...
97

151c06ec6   Scott Wood   mtd: nand: Remove...
98
  int nand_write_skip_bad(struct mtd_info *mtd, loff_t offset, size_t *length,
c39d6a0ea   Tom Rini   nand: Extend nand...
99
  			size_t *actual, loff_t lim, u_char *buffer, int flags);
151c06ec6   Scott Wood   mtd: nand: Remove...
100
101
102
103
104
105
  int nand_erase_opts(struct mtd_info *mtd,
  		    const nand_erase_options_t *opts);
  int nand_torture(struct mtd_info *mtd, loff_t offset);
  int nand_verify_page_oob(struct mtd_info *mtd, struct mtd_oob_ops *ops,
  			 loff_t ofs);
  int nand_verify(struct mtd_info *mtd, loff_t ofs, size_t len, u_char *buf);
2255b2d20   Stefan Roese   * Several improve...
106
107
  
  #define NAND_LOCK_STATUS_TIGHT	0x01
2255b2d20   Stefan Roese   * Several improve...
108
  #define NAND_LOCK_STATUS_UNLOCK 0x04
151c06ec6   Scott Wood   mtd: nand: Remove...
109
110
111
112
  int nand_lock(struct mtd_info *mtd, int tight);
  int nand_unlock(struct mtd_info *mtd, loff_t start, size_t length,
  		int allexcept);
  int nand_get_lock_status(struct mtd_info *mtd, loff_t offset);
2255b2d20   Stefan Roese   * Several improve...
113

12c2f1ee3   Simon Schwarz   spl: add NAND Lib...
114
  int nand_spl_load_image(uint32_t offs, unsigned int size, void *dst);
e1a89e935   Thomas Gleixner   nand_spl_simple: ...
115
  int nand_spl_read_block(int block, int offset, int len, void *dst);
bb085b87e   Simon Schwarz   omap-common: add ...
116
  void nand_deselect(void);
6d0f6bcf3   Jean-Christophe PLAGNIOL-VILLARD   rename CFG_ macro...
117
  #ifdef CONFIG_SYS_NAND_SELECT_DEVICE
43a2b0e76   Stefan Roese   Add board/cpu spe...
118
119
  void board_nand_select_device(struct nand_chip *nand, int chip);
  #endif
e4c095085   Scott Wood   NAND boot: MPC831...
120
  __attribute__((noreturn)) void nand_boot(void);
c9f7351b5   Ben Gardiner   NAND: environment...
121
122
123
124
125
126
  #ifdef CONFIG_ENV_OFFSET_OOB
  #define ENV_OOB_MARKER 0x30425645 /*"EVB0" in little-endian -- offset is stored
  				    as block number*/
  #define ENV_OOB_MARKER_OLD 0x30564e45 /*"ENV0" in little-endian -- offset is
  					stored as byte number */
  #define ENV_OFFSET_SIZE 8
151c06ec6   Scott Wood   mtd: nand: Remove...
127
  int get_nand_env_oob(struct mtd_info *mtd, unsigned long *result);
c9f7351b5   Ben Gardiner   NAND: environment...
128
  #endif
4dfd36058   Heiko Schocher   spl, nand, atmel_...
129
  int spl_nand_erase_one(int block, int page);
4ccae81cd   Boris Brezillon   mtd: nand: Add th...
130
131
132
  
  /* platform specific init functions */
  void sunxi_nand_init(void);
2afc741a2   Mugunthan V N   include: nand: mo...
133

ad92dff28   Mugunthan V N   cmd: nand: abstra...
134
135
136
137
138
139
140
141
  /*
   * get_nand_dev_by_index - Get the nand info based in index.
   *
   * @dev - index to the nand device.
   *
   * returns pointer to the nand device info structure or NULL on failure.
   */
  struct mtd_info *get_nand_dev_by_index(int dev);
2afc741a2   Mugunthan V N   include: nand: mo...
142
  #endif /* _NAND_H_ */