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