1 diff -urN linux-2.6.21.1.old/drivers/mtd/chips/cfi_cmdset_0001.c linux-2.6.21.1.dev/drivers/mtd/chips/cfi_cmdset_0001.c
2 --- linux-2.6.21.1.old/drivers/mtd/chips/cfi_cmdset_0001.c 2007-04-27 23:49:26.000000000 +0200
3 +++ linux-2.6.21.1.dev/drivers/mtd/chips/cfi_cmdset_0001.c 2007-05-26 19:40:46.809023552 +0200
6 static int __xipram xip_wait_for_operation(
7 struct map_info *map, struct flchip *chip,
8 - unsigned long adr, unsigned int chip_op_time )
9 + unsigned long adr, int *chip_op_time )
11 struct cfi_private *cfi = map->fldrv_priv;
12 struct cfi_pri_intelext *cfip = cfi->cmdset_priv;
14 flstate_t oldstate, newstate;
16 start = xip_currtime();
17 - usec = chip_op_time * 8;
18 + usec = *chip_op_time * 8;
23 #define XIP_INVAL_CACHED_RANGE(map, from, size) \
24 INVALIDATE_CACHED_RANGE(map, from, size)
26 -#define INVAL_CACHE_AND_WAIT(map, chip, cmd_adr, inval_adr, inval_len, usec) \
27 - xip_wait_for_operation(map, chip, cmd_adr, usec)
28 +#define INVAL_CACHE_AND_WAIT(map, chip, cmd_adr, inval_adr, inval_len, p_usec) \
29 + xip_wait_for_operation(map, chip, cmd_adr, p_usec)
33 @@ -1051,65 +1051,65 @@
34 static int inval_cache_and_wait_for_operation(
35 struct map_info *map, struct flchip *chip,
36 unsigned long cmd_adr, unsigned long inval_adr, int inval_len,
37 - unsigned int chip_op_time)
40 struct cfi_private *cfi = map->fldrv_priv;
41 map_word status, status_OK = CMD(0x80);
42 - int chip_state = chip->state;
43 - unsigned int timeo, sleep_time;
44 + int z, chip_state = chip->state;
45 + unsigned long timeo;
47 spin_unlock(chip->mutex);
49 INVALIDATE_CACHED_RANGE(map, inval_adr, inval_len);
51 + cfi_udelay(*chip_op_time);
52 spin_lock(chip->mutex);
54 - /* set our timeout to 8 times the expected delay */
55 - timeo = chip_op_time * 8;
58 - sleep_time = chip_op_time / 2;
59 + timeo = *chip_op_time * 8 * HZ / 1000000;
66 + if (chip->state != chip_state) {
67 + /* Someone's suspended the operation: sleep */
68 + DECLARE_WAITQUEUE(wait, current);
70 + set_current_state(TASK_UNINTERRUPTIBLE);
71 + add_wait_queue(&chip->wq, &wait);
72 + spin_unlock(chip->mutex);
74 + remove_wait_queue(&chip->wq, &wait);
75 + timeo = jiffies + (HZ / 2); /* FIXME */
76 + spin_lock(chip->mutex);
80 status = map_read(map, cmd_adr);
81 if (map_word_andequal(map, status, status_OK, status_OK))
85 + /* OK Still waiting */
86 + if (time_after(jiffies, timeo)) {
87 map_write(map, CMD(0x70), cmd_adr);
88 chip->state = FL_STATUS;
92 - /* OK Still waiting. Drop the lock, wait a while and retry. */
93 + /* Latency issues. Drop the lock, wait a while and retry */
95 spin_unlock(chip->mutex);
96 - if (sleep_time >= 1000000/HZ) {
98 - * Half of the normal delay still remaining
99 - * can be performed with a sleeping delay instead
102 - msleep(sleep_time/1000);
103 - timeo -= sleep_time;
104 - sleep_time = 1000000/HZ;
111 spin_lock(chip->mutex);
113 - while (chip->state != chip_state) {
114 - /* Someone's suspended the operation: sleep */
115 - DECLARE_WAITQUEUE(wait, current);
116 - set_current_state(TASK_UNINTERRUPTIBLE);
117 - add_wait_queue(&chip->wq, &wait);
118 - spin_unlock(chip->mutex);
120 - remove_wait_queue(&chip->wq, &wait);
121 - spin_lock(chip->mutex);
126 + if (!--(*chip_op_time))
131 /* Done and happy. */
132 chip->state = FL_STATUS;
134 @@ -1118,7 +1118,8 @@
137 #define WAIT_TIMEOUT(map, chip, adr, udelay) \
138 - INVAL_CACHE_AND_WAIT(map, chip, adr, 0, 0, udelay);
139 + ({ int __udelay = (udelay); \
140 + INVAL_CACHE_AND_WAIT(map, chip, adr, 0, 0, &__udelay); })
143 static int do_point_onechip (struct map_info *map, struct flchip *chip, loff_t adr, size_t len)
144 @@ -1342,7 +1343,7 @@
146 ret = INVAL_CACHE_AND_WAIT(map, chip, adr,
147 adr, map_bankwidth(map),
148 - chip->word_write_time);
149 + &chip->word_write_time);
151 xip_enable(map, chip, adr);
152 printk(KERN_ERR "%s: word write error (status timeout)\n", map->name);
153 @@ -1579,7 +1580,7 @@
155 ret = INVAL_CACHE_AND_WAIT(map, chip, cmd_adr,
157 - chip->buffer_write_time);
158 + &chip->buffer_write_time);
160 map_write(map, CMD(0x70), cmd_adr);
161 chip->state = FL_STATUS;
162 @@ -1714,7 +1715,7 @@
164 ret = INVAL_CACHE_AND_WAIT(map, chip, adr,
167 + &chip->erase_time);
169 map_write(map, CMD(0x70), adr);
170 chip->state = FL_STATUS;