Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Heiko Schocher | f5895d1 | 2014-06-24 10:10:04 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Copyright © 2000 Red Hat UK Limited |
| 4 | * Copyright © 2000-2010 David Woodhouse <dwmw2@infradead.org> |
| 5 | * |
Heiko Schocher | f5895d1 | 2014-06-24 10:10:04 +0200 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #ifndef __MTD_FLASHCHIP_H__ |
| 9 | #define __MTD_FLASHCHIP_H__ |
| 10 | |
Heiko Schocher | f5895d1 | 2014-06-24 10:10:04 +0200 | [diff] [blame] | 11 | #ifndef __UBOOT__ |
| 12 | /* For spinlocks. sched.h includes spinlock.h from whichever directory it |
| 13 | * happens to be in - so we don't have to care whether we're on 2.2, which |
| 14 | * has asm/spinlock.h, or 2.4, which has linux/spinlock.h |
| 15 | */ |
| 16 | #include <linux/sched.h> |
| 17 | #include <linux/mutex.h> |
| 18 | #endif |
| 19 | |
| 20 | typedef enum { |
| 21 | FL_READY, |
| 22 | FL_STATUS, |
| 23 | FL_CFI_QUERY, |
| 24 | FL_JEDEC_QUERY, |
| 25 | FL_ERASING, |
| 26 | FL_ERASE_SUSPENDING, |
| 27 | FL_ERASE_SUSPENDED, |
| 28 | FL_WRITING, |
| 29 | FL_WRITING_TO_BUFFER, |
| 30 | FL_OTP_WRITE, |
| 31 | FL_WRITE_SUSPENDING, |
| 32 | FL_WRITE_SUSPENDED, |
| 33 | FL_PM_SUSPENDED, |
| 34 | FL_SYNCING, |
| 35 | FL_UNLOADING, |
| 36 | FL_LOCKING, |
| 37 | FL_UNLOCKING, |
| 38 | FL_POINT, |
| 39 | FL_XIP_WHILE_ERASING, |
| 40 | FL_XIP_WHILE_WRITING, |
| 41 | FL_SHUTDOWN, |
| 42 | /* These 2 come from nand_state_t, which has been unified here */ |
| 43 | FL_READING, |
| 44 | FL_CACHEDPRG, |
| 45 | /* These 4 come from onenand_state_t, which has been unified here */ |
| 46 | FL_RESETING, |
| 47 | FL_OTPING, |
| 48 | FL_PREPARING_ERASE, |
| 49 | FL_VERIFYING_ERASE, |
| 50 | |
| 51 | FL_UNKNOWN |
| 52 | } flstate_t; |
| 53 | |
| 54 | |
Heiko Schocher | f5895d1 | 2014-06-24 10:10:04 +0200 | [diff] [blame] | 55 | /* NOTE: confusingly, this can be used to refer to more than one chip at a time, |
| 56 | if they're interleaved. This can even refer to individual partitions on |
| 57 | the same physical chip when present. */ |
| 58 | |
| 59 | struct flchip { |
| 60 | unsigned long start; /* Offset within the map */ |
| 61 | // unsigned long len; |
| 62 | /* We omit len for now, because when we group them together |
| 63 | we insist that they're all of the same size, and the chip size |
| 64 | is held in the next level up. If we get more versatile later, |
| 65 | it'll make it a damn sight harder to find which chip we want from |
| 66 | a given offset, and we'll want to add the per-chip length field |
| 67 | back in. |
| 68 | */ |
| 69 | int ref_point_counter; |
| 70 | flstate_t state; |
| 71 | flstate_t oldstate; |
| 72 | |
| 73 | unsigned int write_suspended:1; |
| 74 | unsigned int erase_suspended:1; |
| 75 | unsigned long in_progress_block_addr; |
| 76 | |
| 77 | struct mutex mutex; |
| 78 | #ifndef __UBOOT__ |
| 79 | wait_queue_head_t wq; /* Wait on here when we're waiting for the chip |
| 80 | to be ready */ |
| 81 | #endif |
| 82 | int word_write_time; |
| 83 | int buffer_write_time; |
| 84 | int erase_time; |
| 85 | |
| 86 | int word_write_time_max; |
| 87 | int buffer_write_time_max; |
| 88 | int erase_time_max; |
| 89 | |
| 90 | void *priv; |
| 91 | }; |
| 92 | |
| 93 | /* This is used to handle contention on write/erase operations |
| 94 | between partitions of the same physical chip. */ |
| 95 | struct flchip_shared { |
| 96 | struct mutex lock; |
| 97 | struct flchip *writing; |
| 98 | struct flchip *erasing; |
| 99 | }; |
| 100 | |
| 101 | |
| 102 | #endif /* __MTD_FLASHCHIP_H__ */ |