aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Riesch <christian.riesch@omicron.at>2013-04-26 15:10:28 -0400
committerBrian Norris <computersforpeace@gmail.com>2014-07-11 22:44:24 -0400
commitfeb8677935d4319c6d22b017fefac1532cd80529 (patch)
treef067645bb0cad175f786c59edbb6362552efb05a
parentdc7e9ecdd6a41edbd57b80e5ed837a06debd14ae (diff)
mtd: cfi_cmdset_0002: Invalidate cache after entering/exiting OTP memory
When the one time programmable (OTP) memory region is entered by issuing the 0xaa/0x55/0x88 command, the OTP memory occupies the addresses which are normally used by the first sector of the regular flash memory. This patch therefore invalidates cache for this addresses after entering/exiting OTP memory. This patch also moves the code into separate functions. Signed-off-by: Christian Riesch <christian.riesch@omicron.at> Signed-off-by: Brian Norris <computersforpeace@gmail.com>
-rw-r--r--drivers/mtd/chips/cfi_cmdset_0002.c44
1 files changed, 34 insertions, 10 deletions
diff --git a/drivers/mtd/chips/cfi_cmdset_0002.c b/drivers/mtd/chips/cfi_cmdset_0002.c
index 54825083fd14..612eb3d6902c 100644
--- a/drivers/mtd/chips/cfi_cmdset_0002.c
+++ b/drivers/mtd/chips/cfi_cmdset_0002.c
@@ -1152,11 +1152,42 @@ static int cfi_amdstd_read (struct mtd_info *mtd, loff_t from, size_t len, size_
1152typedef int (*otp_op_t)(struct map_info *map, struct flchip *chip, 1152typedef int (*otp_op_t)(struct map_info *map, struct flchip *chip,
1153 loff_t adr, size_t len, u_char *buf); 1153 loff_t adr, size_t len, u_char *buf);
1154 1154
1155static inline void otp_enter(struct map_info *map, struct flchip *chip,
1156 loff_t adr, size_t len)
1157{
1158 struct cfi_private *cfi = map->fldrv_priv;
1159
1160 cfi_send_gen_cmd(0xAA, cfi->addr_unlock1, chip->start, map, cfi,
1161 cfi->device_type, NULL);
1162 cfi_send_gen_cmd(0x55, cfi->addr_unlock2, chip->start, map, cfi,
1163 cfi->device_type, NULL);
1164 cfi_send_gen_cmd(0x88, cfi->addr_unlock1, chip->start, map, cfi,
1165 cfi->device_type, NULL);
1166
1167 INVALIDATE_CACHED_RANGE(map, chip->start + adr, len);
1168}
1169
1170static inline void otp_exit(struct map_info *map, struct flchip *chip,
1171 loff_t adr, size_t len)
1172{
1173 struct cfi_private *cfi = map->fldrv_priv;
1174
1175 cfi_send_gen_cmd(0xAA, cfi->addr_unlock1, chip->start, map, cfi,
1176 cfi->device_type, NULL);
1177 cfi_send_gen_cmd(0x55, cfi->addr_unlock2, chip->start, map, cfi,
1178 cfi->device_type, NULL);
1179 cfi_send_gen_cmd(0x90, cfi->addr_unlock1, chip->start, map, cfi,
1180 cfi->device_type, NULL);
1181 cfi_send_gen_cmd(0x00, cfi->addr_unlock1, chip->start, map, cfi,
1182 cfi->device_type, NULL);
1183
1184 INVALIDATE_CACHED_RANGE(map, chip->start + adr, len);
1185}
1186
1155static inline int do_read_secsi_onechip(struct map_info *map, struct flchip *chip, loff_t adr, size_t len, u_char *buf) 1187static inline int do_read_secsi_onechip(struct map_info *map, struct flchip *chip, loff_t adr, size_t len, u_char *buf)
1156{ 1188{
1157 DECLARE_WAITQUEUE(wait, current); 1189 DECLARE_WAITQUEUE(wait, current);
1158 unsigned long timeo = jiffies + HZ; 1190 unsigned long timeo = jiffies + HZ;
1159 struct cfi_private *cfi = map->fldrv_priv;
1160 1191
1161 retry: 1192 retry:
1162 mutex_lock(&chip->mutex); 1193 mutex_lock(&chip->mutex);
@@ -1178,16 +1209,9 @@ static inline int do_read_secsi_onechip(struct map_info *map, struct flchip *chi
1178 1209
1179 chip->state = FL_READY; 1210 chip->state = FL_READY;
1180 1211
1181 cfi_send_gen_cmd(0xAA, cfi->addr_unlock1, chip->start, map, cfi, cfi->device_type, NULL); 1212 otp_enter(map, chip, adr, len);
1182 cfi_send_gen_cmd(0x55, cfi->addr_unlock2, chip->start, map, cfi, cfi->device_type, NULL);
1183 cfi_send_gen_cmd(0x88, cfi->addr_unlock1, chip->start, map, cfi, cfi->device_type, NULL);
1184
1185 map_copy_from(map, buf, adr, len); 1213 map_copy_from(map, buf, adr, len);
1186 1214 otp_exit(map, chip, adr, len);
1187 cfi_send_gen_cmd(0xAA, cfi->addr_unlock1, chip->start, map, cfi, cfi->device_type, NULL);
1188 cfi_send_gen_cmd(0x55, cfi->addr_unlock2, chip->start, map, cfi, cfi->device_type, NULL);
1189 cfi_send_gen_cmd(0x90, cfi->addr_unlock1, chip->start, map, cfi, cfi->device_type, NULL);
1190 cfi_send_gen_cmd(0x00, cfi->addr_unlock1, chip->start, map, cfi, cfi->device_type, NULL);
1191 1215
1192 wake_up(&chip->wq); 1216 wake_up(&chip->wq);
1193 mutex_unlock(&chip->mutex); 1217 mutex_unlock(&chip->mutex);