flashchip.h 3.0 KB
Newer Older
1
/*
D
David Woodhouse 已提交
2 3 4 5 6 7 8 9 10 11 12 13
 * Copyright © 2000      Red Hat UK Limited
 * Copyright © 2000-2010 David Woodhouse <dwmw2@infradead.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
14
 *
D
David Woodhouse 已提交
15 16 17
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
L
Linus Torvalds 已提交
18 19 20 21 22 23 24 25
 *
 */

#ifndef __MTD_FLASHCHIP_H__
#define __MTD_FLASHCHIP_H__

/* For spinlocks. sched.h includes spinlock.h from whichever directory it
 * happens to be in - so we don't have to care whether we're on 2.2, which
26
 * has asm/spinlock.h, or 2.4, which has linux/spinlock.h
L
Linus Torvalds 已提交
27 28
 */
#include <linux/sched.h>
29
#include <linux/mutex.h>
L
Linus Torvalds 已提交
30

31
typedef enum {
L
Linus Torvalds 已提交
32 33 34 35 36 37 38 39 40
	FL_READY,
	FL_STATUS,
	FL_CFI_QUERY,
	FL_JEDEC_QUERY,
	FL_ERASING,
	FL_ERASE_SUSPENDING,
	FL_ERASE_SUSPENDED,
	FL_WRITING,
	FL_WRITING_TO_BUFFER,
41
	FL_OTP_WRITE,
L
Linus Torvalds 已提交
42 43 44 45 46 47 48 49 50 51
	FL_WRITE_SUSPENDING,
	FL_WRITE_SUSPENDED,
	FL_PM_SUSPENDED,
	FL_SYNCING,
	FL_UNLOADING,
	FL_LOCKING,
	FL_UNLOCKING,
	FL_POINT,
	FL_XIP_WHILE_ERASING,
	FL_XIP_WHILE_WRITING,
52
	FL_SHUTDOWN,
53 54 55
	/* These 2 come from nand_state_t, which has been unified here */
	FL_READING,
	FL_CACHEDPRG,
56
	/* These 4 come from onenand_state_t, which has been unified here */
57 58
	FL_RESETING,
	FL_OTPING,
59 60
	FL_PREPARING_ERASE,
	FL_VERIFYING_ERASE,
61

L
Linus Torvalds 已提交
62 63 64 65 66
	FL_UNKNOWN
} flstate_t;



67
/* NOTE: confusingly, this can be used to refer to more than one chip at a time,
L
Linus Torvalds 已提交
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
   if they're interleaved.  This can even refer to individual partitions on
   the same physical chip when present. */

struct flchip {
	unsigned long start; /* Offset within the map */
	//	unsigned long len;
	/* We omit len for now, because when we group them together
	   we insist that they're all of the same size, and the chip size
	   is held in the next level up. If we get more versatile later,
	   it'll make it a damn sight harder to find which chip we want from
	   a given offset, and we'll want to add the per-chip length field
	   back in.
	*/
	int ref_point_counter;
	flstate_t state;
	flstate_t oldstate;

B
Ben Dooks 已提交
85 86
	unsigned int write_suspended:1;
	unsigned int erase_suspended:1;
L
Linus Torvalds 已提交
87 88
	unsigned long in_progress_block_addr;

89
	struct mutex mutex;
L
Linus Torvalds 已提交
90 91 92 93 94 95
	wait_queue_head_t wq; /* Wait on here when we're waiting for the chip
			     to be ready */
	int word_write_time;
	int buffer_write_time;
	int erase_time;

96 97 98 99
	int word_write_time_max;
	int buffer_write_time_max;
	int erase_time_max;

L
Linus Torvalds 已提交
100 101 102 103 104 105
	void *priv;
};

/* This is used to handle contention on write/erase operations
   between partitions of the same physical chip. */
struct flchip_shared {
106
	struct mutex lock;
L
Linus Torvalds 已提交
107 108 109 110 111 112
	struct flchip *writing;
	struct flchip *erasing;
};


#endif /* __MTD_FLASHCHIP_H__ */