blob: 4b0c2dfaaaa412305ae301ef93e7c9d0dd58277b [file] [log] [blame]
Kyungmin Parkaf3d11c2007-09-10 17:15:14 +09001/*
2 * linux/include/linux/mtd/onenand.h
3 *
4 * Copyright (C) 2005-2007 Samsung Electronics
5 * Kyungmin Park <kyungmin.park@samsung.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#ifndef __LINUX_MTD_ONENAND_H
13#define __LINUX_MTD_ONENAND_H
14
15#include <linux/mtd/onenand_regs.h>
16
17/* Note: The header order is impoertant */
18#include <onenand_uboot.h>
19
20#include <linux/mtd/bbm.h>
21
22#define MAX_BUFFERRAM 2
23#define MAX_ONENAND_PAGESIZE (2048 + 64)
24
25/* Scan and identify a OneNAND device */
26extern int onenand_scan (struct mtd_info *mtd, int max_chips);
27/* Free resources held by the OneNAND device */
28extern void onenand_release (struct mtd_info *mtd);
29
30/**
31 * onenand_state_t - chip states
32 * Enumeration for OneNAND flash chip state
33 */
34typedef enum {
35 FL_READY,
36 FL_READING,
37 FL_WRITING,
38 FL_ERASING,
39 FL_SYNCING,
40 FL_UNLOCKING,
41 FL_LOCKING,
42} onenand_state_t;
43
44/**
45 * struct onenand_bufferram - OneNAND BufferRAM Data
46 * @param block block address in BufferRAM
47 * @param page page address in BufferRAM
48 * @param valid valid flag
49 */
50struct onenand_bufferram {
51 int block;
52 int page;
53 int valid;
54};
55
56/**
57 * struct onenand_chip - OneNAND Private Flash Chip Data
58 * @param base [BOARDSPECIFIC] address to access OneNAND
59 * @param chipsize [INTERN] the size of one chip for multichip arrays
60 * @param device_id [INTERN] device ID
61 * @param verstion_id [INTERN] version ID
62 * @param options [BOARDSPECIFIC] various chip options. They can partly be set to inform onenand_scan about
63 * @param erase_shift [INTERN] number of address bits in a block
64 * @param page_shift [INTERN] number of address bits in a page
65 * @param ppb_shift [INTERN] number of address bits in a pages per block
66 * @param page_mask [INTERN] a page per block mask
67 * @param bufferam_index [INTERN] BufferRAM index
68 * @param bufferam [INTERN] BufferRAM info
69 * @param readw [REPLACEABLE] hardware specific function for read short
70 * @param writew [REPLACEABLE] hardware specific function for write short
71 * @param command [REPLACEABLE] hardware specific function for writing commands to the chip
72 * @param wait [REPLACEABLE] hardware specific function for wait on ready
73 * @param read_bufferram [REPLACEABLE] hardware specific function for BufferRAM Area
74 * @param write_bufferram [REPLACEABLE] hardware specific function for BufferRAM Area
75 * @param chip_lock [INTERN] spinlock used to protect access to this structure and the chip
76 * @param wq [INTERN] wait queue to sleep on if a OneNAND operation is in progress
77 * @param state [INTERN] the current state of the OneNAND device
78 * @param autooob [REPLACEABLE] the default (auto)placement scheme
79 * @param priv [OPTIONAL] pointer to private chip date
80 */
81struct onenand_chip {
82 void __iomem *base;
83 unsigned int chipsize;
84 unsigned int device_id;
85 unsigned int options;
86
87 unsigned int erase_shift;
88 unsigned int page_shift;
89 unsigned int ppb_shift; /* Pages per block shift */
90 unsigned int page_mask;
91
92 unsigned int bufferram_index;
93 struct onenand_bufferram bufferram[MAX_BUFFERRAM];
94
95 int (*command) (struct mtd_info * mtd, int cmd, loff_t address,
96 size_t len);
97 int (*wait) (struct mtd_info * mtd, int state);
98 int (*read_bufferram) (struct mtd_info * mtd, int area,
99 unsigned char *buffer, int offset, size_t count);
100 int (*write_bufferram) (struct mtd_info * mtd, int area,
101 const unsigned char *buffer, int offset,
102 size_t count);
103 unsigned short (*read_word) (void __iomem * addr);
104 void (*write_word) (unsigned short value, void __iomem * addr);
105 void (*mmcontrol) (struct mtd_info * mtd, int sync_read);
106
107 spinlock_t chip_lock;
108 wait_queue_head_t wq;
109 onenand_state_t state;
110
111 struct nand_oobinfo *autooob;
112
113 void *bbm;
114
115 void *priv;
116};
117
118#define ONENAND_CURRENT_BUFFERRAM(this) (this->bufferram_index)
119#define ONENAND_NEXT_BUFFERRAM(this) (this->bufferram_index ^ 1)
120#define ONENAND_SET_NEXT_BUFFERRAM(this) (this->bufferram_index ^= 1)
121
122/*
123 * Options bits
124 */
125#define ONENAND_CONT_LOCK (0x0001)
126
127/*
128 * OneNAND Flash Manufacturer ID Codes
129 */
130#define ONENAND_MFR_SAMSUNG 0xec
131#define ONENAND_MFR_UNKNOWN 0x00
132
133/**
134 * struct nand_manufacturers - NAND Flash Manufacturer ID Structure
135 * @param name: Manufacturer name
136 * @param id: manufacturer ID code of device.
137*/
138struct onenand_manufacturers {
139 int id;
140 char *name;
141};
142
143#endif /* __LINUX_MTD_ONENAND_H */