cfi_cmdset_0001.c 65 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380
  1. /*
  2. * Common Flash Interface support:
  3. * Intel Extended Vendor Command Set (ID 0x0001)
  4. *
  5. * (C) 2000 Red Hat. GPL'd
  6. *
  7. * $Id: cfi_cmdset_0001.c,v 1.178 2005/05/19 17:05:43 nico Exp $
  8. *
  9. *
  10. * 10/10/2000 Nicolas Pitre <nico@cam.org>
  11. * - completely revamped method functions so they are aware and
  12. * independent of the flash geometry (buswidth, interleave, etc.)
  13. * - scalability vs code size is completely set at compile-time
  14. * (see include/linux/mtd/cfi.h for selection)
  15. * - optimized write buffer method
  16. * 02/05/2002 Christopher Hoover <ch@hpl.hp.com>/<ch@murgatroid.com>
  17. * - reworked lock/unlock/erase support for var size flash
  18. */
  19. #include <linux/module.h>
  20. #include <linux/types.h>
  21. #include <linux/kernel.h>
  22. #include <linux/sched.h>
  23. #include <linux/init.h>
  24. #include <asm/io.h>
  25. #include <asm/byteorder.h>
  26. #include <linux/errno.h>
  27. #include <linux/slab.h>
  28. #include <linux/delay.h>
  29. #include <linux/interrupt.h>
  30. #include <linux/reboot.h>
  31. #include <linux/mtd/xip.h>
  32. #include <linux/mtd/map.h>
  33. #include <linux/mtd/mtd.h>
  34. #include <linux/mtd/compatmac.h>
  35. #include <linux/mtd/cfi.h>
  36. /* #define CMDSET0001_DISABLE_ERASE_SUSPEND_ON_WRITE */
  37. /* #define CMDSET0001_DISABLE_WRITE_SUSPEND */
  38. // debugging, turns off buffer write mode if set to 1
  39. #define FORCE_WORD_WRITE 0
  40. #define MANUFACTURER_INTEL 0x0089
  41. #define I82802AB 0x00ad
  42. #define I82802AC 0x00ac
  43. #define MANUFACTURER_ST 0x0020
  44. #define M50LPW080 0x002F
  45. static int cfi_intelext_read (struct mtd_info *, loff_t, size_t, size_t *, u_char *);
  46. static int cfi_intelext_write_words(struct mtd_info *, loff_t, size_t, size_t *, const u_char *);
  47. static int cfi_intelext_write_buffers(struct mtd_info *, loff_t, size_t, size_t *, const u_char *);
  48. static int cfi_intelext_erase_varsize(struct mtd_info *, struct erase_info *);
  49. static void cfi_intelext_sync (struct mtd_info *);
  50. static int cfi_intelext_lock(struct mtd_info *mtd, loff_t ofs, size_t len);
  51. static int cfi_intelext_unlock(struct mtd_info *mtd, loff_t ofs, size_t len);
  52. #ifdef CONFIG_MTD_OTP
  53. static int cfi_intelext_read_fact_prot_reg (struct mtd_info *, loff_t, size_t, size_t *, u_char *);
  54. static int cfi_intelext_read_user_prot_reg (struct mtd_info *, loff_t, size_t, size_t *, u_char *);
  55. static int cfi_intelext_write_user_prot_reg (struct mtd_info *, loff_t, size_t, size_t *, u_char *);
  56. static int cfi_intelext_lock_user_prot_reg (struct mtd_info *, loff_t, size_t);
  57. static int cfi_intelext_get_fact_prot_info (struct mtd_info *,
  58. struct otp_info *, size_t);
  59. static int cfi_intelext_get_user_prot_info (struct mtd_info *,
  60. struct otp_info *, size_t);
  61. #endif
  62. static int cfi_intelext_suspend (struct mtd_info *);
  63. static void cfi_intelext_resume (struct mtd_info *);
  64. static int cfi_intelext_reboot (struct notifier_block *, unsigned long, void *);
  65. static void cfi_intelext_destroy(struct mtd_info *);
  66. struct mtd_info *cfi_cmdset_0001(struct map_info *, int);
  67. static struct mtd_info *cfi_intelext_setup (struct mtd_info *);
  68. static int cfi_intelext_partition_fixup(struct mtd_info *, struct cfi_private **);
  69. static int cfi_intelext_point (struct mtd_info *mtd, loff_t from, size_t len,
  70. size_t *retlen, u_char **mtdbuf);
  71. static void cfi_intelext_unpoint (struct mtd_info *mtd, u_char *addr, loff_t from,
  72. size_t len);
  73. static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr, int mode);
  74. static void put_chip(struct map_info *map, struct flchip *chip, unsigned long adr);
  75. #include "fwh_lock.h"
  76. /*
  77. * *********** SETUP AND PROBE BITS ***********
  78. */
  79. static struct mtd_chip_driver cfi_intelext_chipdrv = {
  80. .probe = NULL, /* Not usable directly */
  81. .destroy = cfi_intelext_destroy,
  82. .name = "cfi_cmdset_0001",
  83. .module = THIS_MODULE
  84. };
  85. /* #define DEBUG_LOCK_BITS */
  86. /* #define DEBUG_CFI_FEATURES */
  87. #ifdef DEBUG_CFI_FEATURES
  88. static void cfi_tell_features(struct cfi_pri_intelext *extp)
  89. {
  90. int i;
  91. printk(" Feature/Command Support: %4.4X\n", extp->FeatureSupport);
  92. printk(" - Chip Erase: %s\n", extp->FeatureSupport&1?"supported":"unsupported");
  93. printk(" - Suspend Erase: %s\n", extp->FeatureSupport&2?"supported":"unsupported");
  94. printk(" - Suspend Program: %s\n", extp->FeatureSupport&4?"supported":"unsupported");
  95. printk(" - Legacy Lock/Unlock: %s\n", extp->FeatureSupport&8?"supported":"unsupported");
  96. printk(" - Queued Erase: %s\n", extp->FeatureSupport&16?"supported":"unsupported");
  97. printk(" - Instant block lock: %s\n", extp->FeatureSupport&32?"supported":"unsupported");
  98. printk(" - Protection Bits: %s\n", extp->FeatureSupport&64?"supported":"unsupported");
  99. printk(" - Page-mode read: %s\n", extp->FeatureSupport&128?"supported":"unsupported");
  100. printk(" - Synchronous read: %s\n", extp->FeatureSupport&256?"supported":"unsupported");
  101. printk(" - Simultaneous operations: %s\n", extp->FeatureSupport&512?"supported":"unsupported");
  102. for (i=10; i<32; i++) {
  103. if (extp->FeatureSupport & (1<<i))
  104. printk(" - Unknown Bit %X: supported\n", i);
  105. }
  106. printk(" Supported functions after Suspend: %2.2X\n", extp->SuspendCmdSupport);
  107. printk(" - Program after Erase Suspend: %s\n", extp->SuspendCmdSupport&1?"supported":"unsupported");
  108. for (i=1; i<8; i++) {
  109. if (extp->SuspendCmdSupport & (1<<i))
  110. printk(" - Unknown Bit %X: supported\n", i);
  111. }
  112. printk(" Block Status Register Mask: %4.4X\n", extp->BlkStatusRegMask);
  113. printk(" - Lock Bit Active: %s\n", extp->BlkStatusRegMask&1?"yes":"no");
  114. printk(" - Valid Bit Active: %s\n", extp->BlkStatusRegMask&2?"yes":"no");
  115. for (i=2; i<16; i++) {
  116. if (extp->BlkStatusRegMask & (1<<i))
  117. printk(" - Unknown Bit %X Active: yes\n",i);
  118. }
  119. printk(" Vcc Logic Supply Optimum Program/Erase Voltage: %d.%d V\n",
  120. extp->VccOptimal >> 4, extp->VccOptimal & 0xf);
  121. if (extp->VppOptimal)
  122. printk(" Vpp Programming Supply Optimum Program/Erase Voltage: %d.%d V\n",
  123. extp->VppOptimal >> 4, extp->VppOptimal & 0xf);
  124. }
  125. #endif
  126. #ifdef CMDSET0001_DISABLE_ERASE_SUSPEND_ON_WRITE
  127. /* Some Intel Strata Flash prior to FPO revision C has bugs in this area */
  128. static void fixup_intel_strataflash(struct mtd_info *mtd, void* param)
  129. {
  130. struct map_info *map = mtd->priv;
  131. struct cfi_private *cfi = map->fldrv_priv;
  132. struct cfi_pri_amdstd *extp = cfi->cmdset_priv;
  133. printk(KERN_WARNING "cfi_cmdset_0001: Suspend "
  134. "erase on write disabled.\n");
  135. extp->SuspendCmdSupport &= ~1;
  136. }
  137. #endif
  138. #ifdef CMDSET0001_DISABLE_WRITE_SUSPEND
  139. static void fixup_no_write_suspend(struct mtd_info *mtd, void* param)
  140. {
  141. struct map_info *map = mtd->priv;
  142. struct cfi_private *cfi = map->fldrv_priv;
  143. struct cfi_pri_intelext *cfip = cfi->cmdset_priv;
  144. if (cfip && (cfip->FeatureSupport&4)) {
  145. cfip->FeatureSupport &= ~4;
  146. printk(KERN_WARNING "cfi_cmdset_0001: write suspend disabled\n");
  147. }
  148. }
  149. #endif
  150. static void fixup_st_m28w320ct(struct mtd_info *mtd, void* param)
  151. {
  152. struct map_info *map = mtd->priv;
  153. struct cfi_private *cfi = map->fldrv_priv;
  154. cfi->cfiq->BufWriteTimeoutTyp = 0; /* Not supported */
  155. cfi->cfiq->BufWriteTimeoutMax = 0; /* Not supported */
  156. }
  157. static void fixup_st_m28w320cb(struct mtd_info *mtd, void* param)
  158. {
  159. struct map_info *map = mtd->priv;
  160. struct cfi_private *cfi = map->fldrv_priv;
  161. /* Note this is done after the region info is endian swapped */
  162. cfi->cfiq->EraseRegionInfo[1] =
  163. (cfi->cfiq->EraseRegionInfo[1] & 0xffff0000) | 0x3e;
  164. };
  165. static void fixup_use_point(struct mtd_info *mtd, void *param)
  166. {
  167. struct map_info *map = mtd->priv;
  168. if (!mtd->point && map_is_linear(map)) {
  169. mtd->point = cfi_intelext_point;
  170. mtd->unpoint = cfi_intelext_unpoint;
  171. }
  172. }
  173. static void fixup_use_write_buffers(struct mtd_info *mtd, void *param)
  174. {
  175. struct map_info *map = mtd->priv;
  176. struct cfi_private *cfi = map->fldrv_priv;
  177. if (cfi->cfiq->BufWriteTimeoutTyp) {
  178. printk(KERN_INFO "Using buffer write method\n" );
  179. mtd->write = cfi_intelext_write_buffers;
  180. }
  181. }
  182. static struct cfi_fixup cfi_fixup_table[] = {
  183. #ifdef CMDSET0001_DISABLE_ERASE_SUSPEND_ON_WRITE
  184. { CFI_MFR_ANY, CFI_ID_ANY, fixup_intel_strataflash, NULL },
  185. #endif
  186. #ifdef CMDSET0001_DISABLE_WRITE_SUSPEND
  187. { CFI_MFR_ANY, CFI_ID_ANY, fixup_no_write_suspend, NULL },
  188. #endif
  189. #if !FORCE_WORD_WRITE
  190. { CFI_MFR_ANY, CFI_ID_ANY, fixup_use_write_buffers, NULL },
  191. #endif
  192. { CFI_MFR_ST, 0x00ba, /* M28W320CT */ fixup_st_m28w320ct, NULL },
  193. { CFI_MFR_ST, 0x00bb, /* M28W320CB */ fixup_st_m28w320cb, NULL },
  194. { 0, 0, NULL, NULL }
  195. };
  196. static struct cfi_fixup jedec_fixup_table[] = {
  197. { MANUFACTURER_INTEL, I82802AB, fixup_use_fwh_lock, NULL, },
  198. { MANUFACTURER_INTEL, I82802AC, fixup_use_fwh_lock, NULL, },
  199. { MANUFACTURER_ST, M50LPW080, fixup_use_fwh_lock, NULL, },
  200. { 0, 0, NULL, NULL }
  201. };
  202. static struct cfi_fixup fixup_table[] = {
  203. /* The CFI vendor ids and the JEDEC vendor IDs appear
  204. * to be common. It is like the devices id's are as
  205. * well. This table is to pick all cases where
  206. * we know that is the case.
  207. */
  208. { CFI_MFR_ANY, CFI_ID_ANY, fixup_use_point, NULL },
  209. { 0, 0, NULL, NULL }
  210. };
  211. static inline struct cfi_pri_intelext *
  212. read_pri_intelext(struct map_info *map, __u16 adr)
  213. {
  214. struct cfi_pri_intelext *extp;
  215. unsigned int extp_size = sizeof(*extp);
  216. again:
  217. extp = (struct cfi_pri_intelext *)cfi_read_pri(map, adr, extp_size, "Intel/Sharp");
  218. if (!extp)
  219. return NULL;
  220. /* Do some byteswapping if necessary */
  221. extp->FeatureSupport = le32_to_cpu(extp->FeatureSupport);
  222. extp->BlkStatusRegMask = le16_to_cpu(extp->BlkStatusRegMask);
  223. extp->ProtRegAddr = le16_to_cpu(extp->ProtRegAddr);
  224. if (extp->MajorVersion == '1' && extp->MinorVersion == '3') {
  225. unsigned int extra_size = 0;
  226. int nb_parts, i;
  227. /* Protection Register info */
  228. extra_size += (extp->NumProtectionFields - 1) *
  229. sizeof(struct cfi_intelext_otpinfo);
  230. /* Burst Read info */
  231. extra_size += 6;
  232. /* Number of hardware-partitions */
  233. extra_size += 1;
  234. if (extp_size < sizeof(*extp) + extra_size)
  235. goto need_more;
  236. nb_parts = extp->extra[extra_size - 1];
  237. for (i = 0; i < nb_parts; i++) {
  238. struct cfi_intelext_regioninfo *rinfo;
  239. rinfo = (struct cfi_intelext_regioninfo *)&extp->extra[extra_size];
  240. extra_size += sizeof(*rinfo);
  241. if (extp_size < sizeof(*extp) + extra_size)
  242. goto need_more;
  243. rinfo->NumIdentPartitions=le16_to_cpu(rinfo->NumIdentPartitions);
  244. extra_size += (rinfo->NumBlockTypes - 1)
  245. * sizeof(struct cfi_intelext_blockinfo);
  246. }
  247. if (extp_size < sizeof(*extp) + extra_size) {
  248. need_more:
  249. extp_size = sizeof(*extp) + extra_size;
  250. kfree(extp);
  251. if (extp_size > 4096) {
  252. printk(KERN_ERR
  253. "%s: cfi_pri_intelext is too fat\n",
  254. __FUNCTION__);
  255. return NULL;
  256. }
  257. goto again;
  258. }
  259. }
  260. return extp;
  261. }
  262. /* This routine is made available to other mtd code via
  263. * inter_module_register. It must only be accessed through
  264. * inter_module_get which will bump the use count of this module. The
  265. * addresses passed back in cfi are valid as long as the use count of
  266. * this module is non-zero, i.e. between inter_module_get and
  267. * inter_module_put. Keith Owens <kaos@ocs.com.au> 29 Oct 2000.
  268. */
  269. struct mtd_info *cfi_cmdset_0001(struct map_info *map, int primary)
  270. {
  271. struct cfi_private *cfi = map->fldrv_priv;
  272. struct mtd_info *mtd;
  273. int i;
  274. mtd = kmalloc(sizeof(*mtd), GFP_KERNEL);
  275. if (!mtd) {
  276. printk(KERN_ERR "Failed to allocate memory for MTD device\n");
  277. return NULL;
  278. }
  279. memset(mtd, 0, sizeof(*mtd));
  280. mtd->priv = map;
  281. mtd->type = MTD_NORFLASH;
  282. /* Fill in the default mtd operations */
  283. mtd->erase = cfi_intelext_erase_varsize;
  284. mtd->read = cfi_intelext_read;
  285. mtd->write = cfi_intelext_write_words;
  286. mtd->sync = cfi_intelext_sync;
  287. mtd->lock = cfi_intelext_lock;
  288. mtd->unlock = cfi_intelext_unlock;
  289. mtd->suspend = cfi_intelext_suspend;
  290. mtd->resume = cfi_intelext_resume;
  291. mtd->flags = MTD_CAP_NORFLASH;
  292. mtd->name = map->name;
  293. mtd->reboot_notifier.notifier_call = cfi_intelext_reboot;
  294. if (cfi->cfi_mode == CFI_MODE_CFI) {
  295. /*
  296. * It's a real CFI chip, not one for which the probe
  297. * routine faked a CFI structure. So we read the feature
  298. * table from it.
  299. */
  300. __u16 adr = primary?cfi->cfiq->P_ADR:cfi->cfiq->A_ADR;
  301. struct cfi_pri_intelext *extp;
  302. extp = read_pri_intelext(map, adr);
  303. if (!extp) {
  304. kfree(mtd);
  305. return NULL;
  306. }
  307. /* Install our own private info structure */
  308. cfi->cmdset_priv = extp;
  309. cfi_fixup(mtd, cfi_fixup_table);
  310. #ifdef DEBUG_CFI_FEATURES
  311. /* Tell the user about it in lots of lovely detail */
  312. cfi_tell_features(extp);
  313. #endif
  314. if(extp->SuspendCmdSupport & 1) {
  315. printk(KERN_NOTICE "cfi_cmdset_0001: Erase suspend on write enabled\n");
  316. }
  317. }
  318. else if (cfi->cfi_mode == CFI_MODE_JEDEC) {
  319. /* Apply jedec specific fixups */
  320. cfi_fixup(mtd, jedec_fixup_table);
  321. }
  322. /* Apply generic fixups */
  323. cfi_fixup(mtd, fixup_table);
  324. for (i=0; i< cfi->numchips; i++) {
  325. cfi->chips[i].word_write_time = 1<<cfi->cfiq->WordWriteTimeoutTyp;
  326. cfi->chips[i].buffer_write_time = 1<<cfi->cfiq->BufWriteTimeoutTyp;
  327. cfi->chips[i].erase_time = 1<<cfi->cfiq->BlockEraseTimeoutTyp;
  328. cfi->chips[i].ref_point_counter = 0;
  329. }
  330. map->fldrv = &cfi_intelext_chipdrv;
  331. return cfi_intelext_setup(mtd);
  332. }
  333. static struct mtd_info *cfi_intelext_setup(struct mtd_info *mtd)
  334. {
  335. struct map_info *map = mtd->priv;
  336. struct cfi_private *cfi = map->fldrv_priv;
  337. unsigned long offset = 0;
  338. int i,j;
  339. unsigned long devsize = (1<<cfi->cfiq->DevSize) * cfi->interleave;
  340. //printk(KERN_DEBUG "number of CFI chips: %d\n", cfi->numchips);
  341. mtd->size = devsize * cfi->numchips;
  342. mtd->numeraseregions = cfi->cfiq->NumEraseRegions * cfi->numchips;
  343. mtd->eraseregions = kmalloc(sizeof(struct mtd_erase_region_info)
  344. * mtd->numeraseregions, GFP_KERNEL);
  345. if (!mtd->eraseregions) {
  346. printk(KERN_ERR "Failed to allocate memory for MTD erase region info\n");
  347. goto setup_err;
  348. }
  349. for (i=0; i<cfi->cfiq->NumEraseRegions; i++) {
  350. unsigned long ernum, ersize;
  351. ersize = ((cfi->cfiq->EraseRegionInfo[i] >> 8) & ~0xff) * cfi->interleave;
  352. ernum = (cfi->cfiq->EraseRegionInfo[i] & 0xffff) + 1;
  353. if (mtd->erasesize < ersize) {
  354. mtd->erasesize = ersize;
  355. }
  356. for (j=0; j<cfi->numchips; j++) {
  357. mtd->eraseregions[(j*cfi->cfiq->NumEraseRegions)+i].offset = (j*devsize)+offset;
  358. mtd->eraseregions[(j*cfi->cfiq->NumEraseRegions)+i].erasesize = ersize;
  359. mtd->eraseregions[(j*cfi->cfiq->NumEraseRegions)+i].numblocks = ernum;
  360. }
  361. offset += (ersize * ernum);
  362. }
  363. if (offset != devsize) {
  364. /* Argh */
  365. printk(KERN_WARNING "Sum of regions (%lx) != total size of set of interleaved chips (%lx)\n", offset, devsize);
  366. goto setup_err;
  367. }
  368. for (i=0; i<mtd->numeraseregions;i++){
  369. printk(KERN_DEBUG "%d: offset=0x%x,size=0x%x,blocks=%d\n",
  370. i,mtd->eraseregions[i].offset,
  371. mtd->eraseregions[i].erasesize,
  372. mtd->eraseregions[i].numblocks);
  373. }
  374. #ifdef CONFIG_MTD_OTP
  375. mtd->read_fact_prot_reg = cfi_intelext_read_fact_prot_reg;
  376. mtd->read_user_prot_reg = cfi_intelext_read_user_prot_reg;
  377. mtd->write_user_prot_reg = cfi_intelext_write_user_prot_reg;
  378. mtd->lock_user_prot_reg = cfi_intelext_lock_user_prot_reg;
  379. mtd->get_fact_prot_info = cfi_intelext_get_fact_prot_info;
  380. mtd->get_user_prot_info = cfi_intelext_get_user_prot_info;
  381. #endif
  382. /* This function has the potential to distort the reality
  383. a bit and therefore should be called last. */
  384. if (cfi_intelext_partition_fixup(mtd, &cfi) != 0)
  385. goto setup_err;
  386. __module_get(THIS_MODULE);
  387. register_reboot_notifier(&mtd->reboot_notifier);
  388. return mtd;
  389. setup_err:
  390. if(mtd) {
  391. if(mtd->eraseregions)
  392. kfree(mtd->eraseregions);
  393. kfree(mtd);
  394. }
  395. kfree(cfi->cmdset_priv);
  396. return NULL;
  397. }
  398. static int cfi_intelext_partition_fixup(struct mtd_info *mtd,
  399. struct cfi_private **pcfi)
  400. {
  401. struct map_info *map = mtd->priv;
  402. struct cfi_private *cfi = *pcfi;
  403. struct cfi_pri_intelext *extp = cfi->cmdset_priv;
  404. /*
  405. * Probing of multi-partition flash ships.
  406. *
  407. * To support multiple partitions when available, we simply arrange
  408. * for each of them to have their own flchip structure even if they
  409. * are on the same physical chip. This means completely recreating
  410. * a new cfi_private structure right here which is a blatent code
  411. * layering violation, but this is still the least intrusive
  412. * arrangement at this point. This can be rearranged in the future
  413. * if someone feels motivated enough. --nico
  414. */
  415. if (extp && extp->MajorVersion == '1' && extp->MinorVersion == '3'
  416. && extp->FeatureSupport & (1 << 9)) {
  417. struct cfi_private *newcfi;
  418. struct flchip *chip;
  419. struct flchip_shared *shared;
  420. int offs, numregions, numparts, partshift, numvirtchips, i, j;
  421. /* Protection Register info */
  422. offs = (extp->NumProtectionFields - 1) *
  423. sizeof(struct cfi_intelext_otpinfo);
  424. /* Burst Read info */
  425. offs += 6;
  426. /* Number of partition regions */
  427. numregions = extp->extra[offs];
  428. offs += 1;
  429. /* Number of hardware partitions */
  430. numparts = 0;
  431. for (i = 0; i < numregions; i++) {
  432. struct cfi_intelext_regioninfo *rinfo;
  433. rinfo = (struct cfi_intelext_regioninfo *)&extp->extra[offs];
  434. numparts += rinfo->NumIdentPartitions;
  435. offs += sizeof(*rinfo)
  436. + (rinfo->NumBlockTypes - 1) *
  437. sizeof(struct cfi_intelext_blockinfo);
  438. }
  439. /*
  440. * All functions below currently rely on all chips having
  441. * the same geometry so we'll just assume that all hardware
  442. * partitions are of the same size too.
  443. */
  444. partshift = cfi->chipshift - __ffs(numparts);
  445. if ((1 << partshift) < mtd->erasesize) {
  446. printk( KERN_ERR
  447. "%s: bad number of hw partitions (%d)\n",
  448. __FUNCTION__, numparts);
  449. return -EINVAL;
  450. }
  451. numvirtchips = cfi->numchips * numparts;
  452. newcfi = kmalloc(sizeof(struct cfi_private) + numvirtchips * sizeof(struct flchip), GFP_KERNEL);
  453. if (!newcfi)
  454. return -ENOMEM;
  455. shared = kmalloc(sizeof(struct flchip_shared) * cfi->numchips, GFP_KERNEL);
  456. if (!shared) {
  457. kfree(newcfi);
  458. return -ENOMEM;
  459. }
  460. memcpy(newcfi, cfi, sizeof(struct cfi_private));
  461. newcfi->numchips = numvirtchips;
  462. newcfi->chipshift = partshift;
  463. chip = &newcfi->chips[0];
  464. for (i = 0; i < cfi->numchips; i++) {
  465. shared[i].writing = shared[i].erasing = NULL;
  466. spin_lock_init(&shared[i].lock);
  467. for (j = 0; j < numparts; j++) {
  468. *chip = cfi->chips[i];
  469. chip->start += j << partshift;
  470. chip->priv = &shared[i];
  471. /* those should be reset too since
  472. they create memory references. */
  473. init_waitqueue_head(&chip->wq);
  474. spin_lock_init(&chip->_spinlock);
  475. chip->mutex = &chip->_spinlock;
  476. chip++;
  477. }
  478. }
  479. printk(KERN_DEBUG "%s: %d set(s) of %d interleaved chips "
  480. "--> %d partitions of %d KiB\n",
  481. map->name, cfi->numchips, cfi->interleave,
  482. newcfi->numchips, 1<<(newcfi->chipshift-10));
  483. map->fldrv_priv = newcfi;
  484. *pcfi = newcfi;
  485. kfree(cfi);
  486. }
  487. return 0;
  488. }
  489. /*
  490. * *********** CHIP ACCESS FUNCTIONS ***********
  491. */
  492. static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr, int mode)
  493. {
  494. DECLARE_WAITQUEUE(wait, current);
  495. struct cfi_private *cfi = map->fldrv_priv;
  496. map_word status, status_OK = CMD(0x80), status_PWS = CMD(0x01);
  497. unsigned long timeo;
  498. struct cfi_pri_intelext *cfip = cfi->cmdset_priv;
  499. resettime:
  500. timeo = jiffies + HZ;
  501. retry:
  502. if (chip->priv && (mode == FL_WRITING || mode == FL_ERASING || mode == FL_OTP_WRITE)) {
  503. /*
  504. * OK. We have possibility for contension on the write/erase
  505. * operations which are global to the real chip and not per
  506. * partition. So let's fight it over in the partition which
  507. * currently has authority on the operation.
  508. *
  509. * The rules are as follows:
  510. *
  511. * - any write operation must own shared->writing.
  512. *
  513. * - any erase operation must own _both_ shared->writing and
  514. * shared->erasing.
  515. *
  516. * - contension arbitration is handled in the owner's context.
  517. *
  518. * The 'shared' struct can be read when its lock is taken.
  519. * However any writes to it can only be made when the current
  520. * owner's lock is also held.
  521. */
  522. struct flchip_shared *shared = chip->priv;
  523. struct flchip *contender;
  524. spin_lock(&shared->lock);
  525. contender = shared->writing;
  526. if (contender && contender != chip) {
  527. /*
  528. * The engine to perform desired operation on this
  529. * partition is already in use by someone else.
  530. * Let's fight over it in the context of the chip
  531. * currently using it. If it is possible to suspend,
  532. * that other partition will do just that, otherwise
  533. * it'll happily send us to sleep. In any case, when
  534. * get_chip returns success we're clear to go ahead.
  535. */
  536. int ret = spin_trylock(contender->mutex);
  537. spin_unlock(&shared->lock);
  538. if (!ret)
  539. goto retry;
  540. spin_unlock(chip->mutex);
  541. ret = get_chip(map, contender, contender->start, mode);
  542. spin_lock(chip->mutex);
  543. if (ret) {
  544. spin_unlock(contender->mutex);
  545. return ret;
  546. }
  547. timeo = jiffies + HZ;
  548. spin_lock(&shared->lock);
  549. }
  550. /* We now own it */
  551. shared->writing = chip;
  552. if (mode == FL_ERASING)
  553. shared->erasing = chip;
  554. if (contender && contender != chip)
  555. spin_unlock(contender->mutex);
  556. spin_unlock(&shared->lock);
  557. }
  558. switch (chip->state) {
  559. case FL_STATUS:
  560. for (;;) {
  561. status = map_read(map, adr);
  562. if (map_word_andequal(map, status, status_OK, status_OK))
  563. break;
  564. /* At this point we're fine with write operations
  565. in other partitions as they don't conflict. */
  566. if (chip->priv && map_word_andequal(map, status, status_PWS, status_PWS))
  567. break;
  568. if (time_after(jiffies, timeo)) {
  569. printk(KERN_ERR "Waiting for chip to be ready timed out. Status %lx\n",
  570. status.x[0]);
  571. return -EIO;
  572. }
  573. spin_unlock(chip->mutex);
  574. cfi_udelay(1);
  575. spin_lock(chip->mutex);
  576. /* Someone else might have been playing with it. */
  577. goto retry;
  578. }
  579. case FL_READY:
  580. case FL_CFI_QUERY:
  581. case FL_JEDEC_QUERY:
  582. return 0;
  583. case FL_ERASING:
  584. if (!cfip ||
  585. !(cfip->FeatureSupport & 2) ||
  586. !(mode == FL_READY || mode == FL_POINT ||
  587. (mode == FL_WRITING && (cfip->SuspendCmdSupport & 1))))
  588. goto sleep;
  589. /* Erase suspend */
  590. map_write(map, CMD(0xB0), adr);
  591. /* If the flash has finished erasing, then 'erase suspend'
  592. * appears to make some (28F320) flash devices switch to
  593. * 'read' mode. Make sure that we switch to 'read status'
  594. * mode so we get the right data. --rmk
  595. */
  596. map_write(map, CMD(0x70), adr);
  597. chip->oldstate = FL_ERASING;
  598. chip->state = FL_ERASE_SUSPENDING;
  599. chip->erase_suspended = 1;
  600. for (;;) {
  601. status = map_read(map, adr);
  602. if (map_word_andequal(map, status, status_OK, status_OK))
  603. break;
  604. if (time_after(jiffies, timeo)) {
  605. /* Urgh. Resume and pretend we weren't here. */
  606. map_write(map, CMD(0xd0), adr);
  607. /* Make sure we're in 'read status' mode if it had finished */
  608. map_write(map, CMD(0x70), adr);
  609. chip->state = FL_ERASING;
  610. chip->oldstate = FL_READY;
  611. printk(KERN_ERR "Chip not ready after erase "
  612. "suspended: status = 0x%lx\n", status.x[0]);
  613. return -EIO;
  614. }
  615. spin_unlock(chip->mutex);
  616. cfi_udelay(1);
  617. spin_lock(chip->mutex);
  618. /* Nobody will touch it while it's in state FL_ERASE_SUSPENDING.
  619. So we can just loop here. */
  620. }
  621. chip->state = FL_STATUS;
  622. return 0;
  623. case FL_XIP_WHILE_ERASING:
  624. if (mode != FL_READY && mode != FL_POINT &&
  625. (mode != FL_WRITING || !cfip || !(cfip->SuspendCmdSupport&1)))
  626. goto sleep;
  627. chip->oldstate = chip->state;
  628. chip->state = FL_READY;
  629. return 0;
  630. case FL_POINT:
  631. /* Only if there's no operation suspended... */
  632. if (mode == FL_READY && chip->oldstate == FL_READY)
  633. return 0;
  634. default:
  635. sleep:
  636. set_current_state(TASK_UNINTERRUPTIBLE);
  637. add_wait_queue(&chip->wq, &wait);
  638. spin_unlock(chip->mutex);
  639. schedule();
  640. remove_wait_queue(&chip->wq, &wait);
  641. spin_lock(chip->mutex);
  642. goto resettime;
  643. }
  644. }
  645. static void put_chip(struct map_info *map, struct flchip *chip, unsigned long adr)
  646. {
  647. struct cfi_private *cfi = map->fldrv_priv;
  648. if (chip->priv) {
  649. struct flchip_shared *shared = chip->priv;
  650. spin_lock(&shared->lock);
  651. if (shared->writing == chip && chip->oldstate == FL_READY) {
  652. /* We own the ability to write, but we're done */
  653. shared->writing = shared->erasing;
  654. if (shared->writing && shared->writing != chip) {
  655. /* give back ownership to who we loaned it from */
  656. struct flchip *loaner = shared->writing;
  657. spin_lock(loaner->mutex);
  658. spin_unlock(&shared->lock);
  659. spin_unlock(chip->mutex);
  660. put_chip(map, loaner, loaner->start);
  661. spin_lock(chip->mutex);
  662. spin_unlock(loaner->mutex);
  663. wake_up(&chip->wq);
  664. return;
  665. }
  666. shared->erasing = NULL;
  667. shared->writing = NULL;
  668. } else if (shared->erasing == chip && shared->writing != chip) {
  669. /*
  670. * We own the ability to erase without the ability
  671. * to write, which means the erase was suspended
  672. * and some other partition is currently writing.
  673. * Don't let the switch below mess things up since
  674. * we don't have ownership to resume anything.
  675. */
  676. spin_unlock(&shared->lock);
  677. wake_up(&chip->wq);
  678. return;
  679. }
  680. spin_unlock(&shared->lock);
  681. }
  682. switch(chip->oldstate) {
  683. case FL_ERASING:
  684. chip->state = chip->oldstate;
  685. /* What if one interleaved chip has finished and the
  686. other hasn't? The old code would leave the finished
  687. one in READY mode. That's bad, and caused -EROFS
  688. errors to be returned from do_erase_oneblock because
  689. that's the only bit it checked for at the time.
  690. As the state machine appears to explicitly allow
  691. sending the 0x70 (Read Status) command to an erasing
  692. chip and expecting it to be ignored, that's what we
  693. do. */
  694. map_write(map, CMD(0xd0), adr);
  695. map_write(map, CMD(0x70), adr);
  696. chip->oldstate = FL_READY;
  697. chip->state = FL_ERASING;
  698. break;
  699. case FL_XIP_WHILE_ERASING:
  700. chip->state = chip->oldstate;
  701. chip->oldstate = FL_READY;
  702. break;
  703. case FL_READY:
  704. case FL_STATUS:
  705. case FL_JEDEC_QUERY:
  706. /* We should really make set_vpp() count, rather than doing this */
  707. DISABLE_VPP(map);
  708. break;
  709. default:
  710. printk(KERN_ERR "put_chip() called with oldstate %d!!\n", chip->oldstate);
  711. }
  712. wake_up(&chip->wq);
  713. }
  714. #ifdef CONFIG_MTD_XIP
  715. /*
  716. * No interrupt what so ever can be serviced while the flash isn't in array
  717. * mode. This is ensured by the xip_disable() and xip_enable() functions
  718. * enclosing any code path where the flash is known not to be in array mode.
  719. * And within a XIP disabled code path, only functions marked with __xipram
  720. * may be called and nothing else (it's a good thing to inspect generated
  721. * assembly to make sure inline functions were actually inlined and that gcc
  722. * didn't emit calls to its own support functions). Also configuring MTD CFI
  723. * support to a single buswidth and a single interleave is also recommended.
  724. */
  725. static void xip_disable(struct map_info *map, struct flchip *chip,
  726. unsigned long adr)
  727. {
  728. /* TODO: chips with no XIP use should ignore and return */
  729. (void) map_read(map, adr); /* ensure mmu mapping is up to date */
  730. local_irq_disable();
  731. }
  732. static void __xipram xip_enable(struct map_info *map, struct flchip *chip,
  733. unsigned long adr)
  734. {
  735. struct cfi_private *cfi = map->fldrv_priv;
  736. if (chip->state != FL_POINT && chip->state != FL_READY) {
  737. map_write(map, CMD(0xff), adr);
  738. chip->state = FL_READY;
  739. }
  740. (void) map_read(map, adr);
  741. xip_iprefetch();
  742. local_irq_enable();
  743. }
  744. /*
  745. * When a delay is required for the flash operation to complete, the
  746. * xip_udelay() function is polling for both the given timeout and pending
  747. * (but still masked) hardware interrupts. Whenever there is an interrupt
  748. * pending then the flash erase or write operation is suspended, array mode
  749. * restored and interrupts unmasked. Task scheduling might also happen at that
  750. * point. The CPU eventually returns from the interrupt or the call to
  751. * schedule() and the suspended flash operation is resumed for the remaining
  752. * of the delay period.
  753. *
  754. * Warning: this function _will_ fool interrupt latency tracing tools.
  755. */
  756. static void __xipram xip_udelay(struct map_info *map, struct flchip *chip,
  757. unsigned long adr, int usec)
  758. {
  759. struct cfi_private *cfi = map->fldrv_priv;
  760. struct cfi_pri_intelext *cfip = cfi->cmdset_priv;
  761. map_word status, OK = CMD(0x80);
  762. unsigned long suspended, start = xip_currtime();
  763. flstate_t oldstate, newstate;
  764. do {
  765. cpu_relax();
  766. if (xip_irqpending() && cfip &&
  767. ((chip->state == FL_ERASING && (cfip->FeatureSupport&2)) ||
  768. (chip->state == FL_WRITING && (cfip->FeatureSupport&4))) &&
  769. (cfi_interleave_is_1(cfi) || chip->oldstate == FL_READY)) {
  770. /*
  771. * Let's suspend the erase or write operation when
  772. * supported. Note that we currently don't try to
  773. * suspend interleaved chips if there is already
  774. * another operation suspended (imagine what happens
  775. * when one chip was already done with the current
  776. * operation while another chip suspended it, then
  777. * we resume the whole thing at once). Yes, it
  778. * can happen!
  779. */
  780. map_write(map, CMD(0xb0), adr);
  781. map_write(map, CMD(0x70), adr);
  782. usec -= xip_elapsed_since(start);
  783. suspended = xip_currtime();
  784. do {
  785. if (xip_elapsed_since(suspended) > 100000) {
  786. /*
  787. * The chip doesn't want to suspend
  788. * after waiting for 100 msecs.
  789. * This is a critical error but there
  790. * is not much we can do here.
  791. */
  792. return;
  793. }
  794. status = map_read(map, adr);
  795. } while (!map_word_andequal(map, status, OK, OK));
  796. /* Suspend succeeded */
  797. oldstate = chip->state;
  798. if (oldstate == FL_ERASING) {
  799. if (!map_word_bitsset(map, status, CMD(0x40)))
  800. break;
  801. newstate = FL_XIP_WHILE_ERASING;
  802. chip->erase_suspended = 1;
  803. } else {
  804. if (!map_word_bitsset(map, status, CMD(0x04)))
  805. break;
  806. newstate = FL_XIP_WHILE_WRITING;
  807. chip->write_suspended = 1;
  808. }
  809. chip->state = newstate;
  810. map_write(map, CMD(0xff), adr);
  811. (void) map_read(map, adr);
  812. asm volatile (".rep 8; nop; .endr");
  813. local_irq_enable();
  814. spin_unlock(chip->mutex);
  815. asm volatile (".rep 8; nop; .endr");
  816. cond_resched();
  817. /*
  818. * We're back. However someone else might have
  819. * decided to go write to the chip if we are in
  820. * a suspended erase state. If so let's wait
  821. * until it's done.
  822. */
  823. spin_lock(chip->mutex);
  824. while (chip->state != newstate) {
  825. DECLARE_WAITQUEUE(wait, current);
  826. set_current_state(TASK_UNINTERRUPTIBLE);
  827. add_wait_queue(&chip->wq, &wait);
  828. spin_unlock(chip->mutex);
  829. schedule();
  830. remove_wait_queue(&chip->wq, &wait);
  831. spin_lock(chip->mutex);
  832. }
  833. /* Disallow XIP again */
  834. local_irq_disable();
  835. /* Resume the write or erase operation */
  836. map_write(map, CMD(0xd0), adr);
  837. map_write(map, CMD(0x70), adr);
  838. chip->state = oldstate;
  839. start = xip_currtime();
  840. } else if (usec >= 1000000/HZ) {
  841. /*
  842. * Try to save on CPU power when waiting delay
  843. * is at least a system timer tick period.
  844. * No need to be extremely accurate here.
  845. */
  846. xip_cpu_idle();
  847. }
  848. status = map_read(map, adr);
  849. } while (!map_word_andequal(map, status, OK, OK)
  850. && xip_elapsed_since(start) < usec);
  851. }
  852. #define UDELAY(map, chip, adr, usec) xip_udelay(map, chip, adr, usec)
  853. /*
  854. * The INVALIDATE_CACHED_RANGE() macro is normally used in parallel while
  855. * the flash is actively programming or erasing since we have to poll for
  856. * the operation to complete anyway. We can't do that in a generic way with
  857. * a XIP setup so do it before the actual flash operation in this case
  858. * and stub it out from INVALIDATE_CACHE_UDELAY.
  859. */
  860. #define XIP_INVAL_CACHED_RANGE(map, from, size) \
  861. INVALIDATE_CACHED_RANGE(map, from, size)
  862. #define INVALIDATE_CACHE_UDELAY(map, chip, adr, len, usec) \
  863. UDELAY(map, chip, adr, usec)
  864. /*
  865. * Extra notes:
  866. *
  867. * Activating this XIP support changes the way the code works a bit. For
  868. * example the code to suspend the current process when concurrent access
  869. * happens is never executed because xip_udelay() will always return with the
  870. * same chip state as it was entered with. This is why there is no care for
  871. * the presence of add_wait_queue() or schedule() calls from within a couple
  872. * xip_disable()'d areas of code, like in do_erase_oneblock for example.
  873. * The queueing and scheduling are always happening within xip_udelay().
  874. *
  875. * Similarly, get_chip() and put_chip() just happen to always be executed
  876. * with chip->state set to FL_READY (or FL_XIP_WHILE_*) where flash state
  877. * is in array mode, therefore never executing many cases therein and not
  878. * causing any problem with XIP.
  879. */
  880. #else
  881. #define xip_disable(map, chip, adr)
  882. #define xip_enable(map, chip, adr)
  883. #define XIP_INVAL_CACHED_RANGE(x...)
  884. #define UDELAY(map, chip, adr, usec) \
  885. do { \
  886. spin_unlock(chip->mutex); \
  887. cfi_udelay(usec); \
  888. spin_lock(chip->mutex); \
  889. } while (0)
  890. #define INVALIDATE_CACHE_UDELAY(map, chip, adr, len, usec) \
  891. do { \
  892. spin_unlock(chip->mutex); \
  893. INVALIDATE_CACHED_RANGE(map, adr, len); \
  894. cfi_udelay(usec); \
  895. spin_lock(chip->mutex); \
  896. } while (0)
  897. #endif
  898. static int do_point_onechip (struct map_info *map, struct flchip *chip, loff_t adr, size_t len)
  899. {
  900. unsigned long cmd_addr;
  901. struct cfi_private *cfi = map->fldrv_priv;
  902. int ret = 0;
  903. adr += chip->start;
  904. /* Ensure cmd read/writes are aligned. */
  905. cmd_addr = adr & ~(map_bankwidth(map)-1);
  906. spin_lock(chip->mutex);
  907. ret = get_chip(map, chip, cmd_addr, FL_POINT);
  908. if (!ret) {
  909. if (chip->state != FL_POINT && chip->state != FL_READY)
  910. map_write(map, CMD(0xff), cmd_addr);
  911. chip->state = FL_POINT;
  912. chip->ref_point_counter++;
  913. }
  914. spin_unlock(chip->mutex);
  915. return ret;
  916. }
  917. static int cfi_intelext_point (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char **mtdbuf)
  918. {
  919. struct map_info *map = mtd->priv;
  920. struct cfi_private *cfi = map->fldrv_priv;
  921. unsigned long ofs;
  922. int chipnum;
  923. int ret = 0;
  924. if (!map->virt || (from + len > mtd->size))
  925. return -EINVAL;
  926. *mtdbuf = (void *)map->virt + from;
  927. *retlen = 0;
  928. /* Now lock the chip(s) to POINT state */
  929. /* ofs: offset within the first chip that the first read should start */
  930. chipnum = (from >> cfi->chipshift);
  931. ofs = from - (chipnum << cfi->chipshift);
  932. while (len) {
  933. unsigned long thislen;
  934. if (chipnum >= cfi->numchips)
  935. break;
  936. if ((len + ofs -1) >> cfi->chipshift)
  937. thislen = (1<<cfi->chipshift) - ofs;
  938. else
  939. thislen = len;
  940. ret = do_point_onechip(map, &cfi->chips[chipnum], ofs, thislen);
  941. if (ret)
  942. break;
  943. *retlen += thislen;
  944. len -= thislen;
  945. ofs = 0;
  946. chipnum++;
  947. }
  948. return 0;
  949. }
  950. static void cfi_intelext_unpoint (struct mtd_info *mtd, u_char *addr, loff_t from, size_t len)
  951. {
  952. struct map_info *map = mtd->priv;
  953. struct cfi_private *cfi = map->fldrv_priv;
  954. unsigned long ofs;
  955. int chipnum;
  956. /* Now unlock the chip(s) POINT state */
  957. /* ofs: offset within the first chip that the first read should start */
  958. chipnum = (from >> cfi->chipshift);
  959. ofs = from - (chipnum << cfi->chipshift);
  960. while (len) {
  961. unsigned long thislen;
  962. struct flchip *chip;
  963. chip = &cfi->chips[chipnum];
  964. if (chipnum >= cfi->numchips)
  965. break;
  966. if ((len + ofs -1) >> cfi->chipshift)
  967. thislen = (1<<cfi->chipshift) - ofs;
  968. else
  969. thislen = len;
  970. spin_lock(chip->mutex);
  971. if (chip->state == FL_POINT) {
  972. chip->ref_point_counter--;
  973. if(chip->ref_point_counter == 0)
  974. chip->state = FL_READY;
  975. } else
  976. printk(KERN_ERR "Warning: unpoint called on non pointed region\n"); /* Should this give an error? */
  977. put_chip(map, chip, chip->start);
  978. spin_unlock(chip->mutex);
  979. len -= thislen;
  980. ofs = 0;
  981. chipnum++;
  982. }
  983. }
  984. static inline int do_read_onechip(struct map_info *map, struct flchip *chip, loff_t adr, size_t len, u_char *buf)
  985. {
  986. unsigned long cmd_addr;
  987. struct cfi_private *cfi = map->fldrv_priv;
  988. int ret;
  989. adr += chip->start;
  990. /* Ensure cmd read/writes are aligned. */
  991. cmd_addr = adr & ~(map_bankwidth(map)-1);
  992. spin_lock(chip->mutex);
  993. ret = get_chip(map, chip, cmd_addr, FL_READY);
  994. if (ret) {
  995. spin_unlock(chip->mutex);
  996. return ret;
  997. }
  998. if (chip->state != FL_POINT && chip->state != FL_READY) {
  999. map_write(map, CMD(0xff), cmd_addr);
  1000. chip->state = FL_READY;
  1001. }
  1002. map_copy_from(map, buf, adr, len);
  1003. put_chip(map, chip, cmd_addr);
  1004. spin_unlock(chip->mutex);
  1005. return 0;
  1006. }
  1007. static int cfi_intelext_read (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf)
  1008. {
  1009. struct map_info *map = mtd->priv;
  1010. struct cfi_private *cfi = map->fldrv_priv;
  1011. unsigned long ofs;
  1012. int chipnum;
  1013. int ret = 0;
  1014. /* ofs: offset within the first chip that the first read should start */
  1015. chipnum = (from >> cfi->chipshift);
  1016. ofs = from - (chipnum << cfi->chipshift);
  1017. *retlen = 0;
  1018. while (len) {
  1019. unsigned long thislen;
  1020. if (chipnum >= cfi->numchips)
  1021. break;
  1022. if ((len + ofs -1) >> cfi->chipshift)
  1023. thislen = (1<<cfi->chipshift) - ofs;
  1024. else
  1025. thislen = len;
  1026. ret = do_read_onechip(map, &cfi->chips[chipnum], ofs, thislen, buf);
  1027. if (ret)
  1028. break;
  1029. *retlen += thislen;
  1030. len -= thislen;
  1031. buf += thislen;
  1032. ofs = 0;
  1033. chipnum++;
  1034. }
  1035. return ret;
  1036. }
  1037. static int __xipram do_write_oneword(struct map_info *map, struct flchip *chip,
  1038. unsigned long adr, map_word datum, int mode)
  1039. {
  1040. struct cfi_private *cfi = map->fldrv_priv;
  1041. map_word status, status_OK, write_cmd;
  1042. unsigned long timeo;
  1043. int z, ret=0;
  1044. adr += chip->start;
  1045. /* Let's determine this according to the interleave only once */
  1046. status_OK = CMD(0x80);
  1047. switch (mode) {
  1048. case FL_WRITING: write_cmd = CMD(0x40); break;
  1049. case FL_OTP_WRITE: write_cmd = CMD(0xc0); break;
  1050. default: return -EINVAL;
  1051. }
  1052. spin_lock(chip->mutex);
  1053. ret = get_chip(map, chip, adr, mode);
  1054. if (ret) {
  1055. spin_unlock(chip->mutex);
  1056. return ret;
  1057. }
  1058. XIP_INVAL_CACHED_RANGE(map, adr, map_bankwidth(map));
  1059. ENABLE_VPP(map);
  1060. xip_disable(map, chip, adr);
  1061. map_write(map, write_cmd, adr);
  1062. map_write(map, datum, adr);
  1063. chip->state = mode;
  1064. INVALIDATE_CACHE_UDELAY(map, chip,
  1065. adr, map_bankwidth(map),
  1066. chip->word_write_time);
  1067. timeo = jiffies + (HZ/2);
  1068. z = 0;
  1069. for (;;) {
  1070. if (chip->state != mode) {
  1071. /* Someone's suspended the write. Sleep */
  1072. DECLARE_WAITQUEUE(wait, current);
  1073. set_current_state(TASK_UNINTERRUPTIBLE);
  1074. add_wait_queue(&chip->wq, &wait);
  1075. spin_unlock(chip->mutex);
  1076. schedule();
  1077. remove_wait_queue(&chip->wq, &wait);
  1078. timeo = jiffies + (HZ / 2); /* FIXME */
  1079. spin_lock(chip->mutex);
  1080. continue;
  1081. }
  1082. status = map_read(map, adr);
  1083. if (map_word_andequal(map, status, status_OK, status_OK))
  1084. break;
  1085. /* OK Still waiting */
  1086. if (time_after(jiffies, timeo)) {
  1087. chip->state = FL_STATUS;
  1088. xip_enable(map, chip, adr);
  1089. printk(KERN_ERR "waiting for chip to be ready timed out in word write\n");
  1090. ret = -EIO;
  1091. goto out;
  1092. }
  1093. /* Latency issues. Drop the lock, wait a while and retry */
  1094. z++;
  1095. UDELAY(map, chip, adr, 1);
  1096. }
  1097. if (!z) {
  1098. chip->word_write_time--;
  1099. if (!chip->word_write_time)
  1100. chip->word_write_time++;
  1101. }
  1102. if (z > 1)
  1103. chip->word_write_time++;
  1104. /* Done and happy. */
  1105. chip->state = FL_STATUS;
  1106. /* check for lock bit */
  1107. if (map_word_bitsset(map, status, CMD(0x02))) {
  1108. /* clear status */
  1109. map_write(map, CMD(0x50), adr);
  1110. /* put back into read status register mode */
  1111. map_write(map, CMD(0x70), adr);
  1112. ret = -EROFS;
  1113. }
  1114. xip_enable(map, chip, adr);
  1115. out: put_chip(map, chip, adr);
  1116. spin_unlock(chip->mutex);
  1117. return ret;
  1118. }
  1119. static int cfi_intelext_write_words (struct mtd_info *mtd, loff_t to , size_t len, size_t *retlen, const u_char *buf)
  1120. {
  1121. struct map_info *map = mtd->priv;
  1122. struct cfi_private *cfi = map->fldrv_priv;
  1123. int ret = 0;
  1124. int chipnum;
  1125. unsigned long ofs;
  1126. *retlen = 0;
  1127. if (!len)
  1128. return 0;
  1129. chipnum = to >> cfi->chipshift;
  1130. ofs = to - (chipnum << cfi->chipshift);
  1131. /* If it's not bus-aligned, do the first byte write */
  1132. if (ofs & (map_bankwidth(map)-1)) {
  1133. unsigned long bus_ofs = ofs & ~(map_bankwidth(map)-1);
  1134. int gap = ofs - bus_ofs;
  1135. int n;
  1136. map_word datum;
  1137. n = min_t(int, len, map_bankwidth(map)-gap);
  1138. datum = map_word_ff(map);
  1139. datum = map_word_load_partial(map, datum, buf, gap, n);
  1140. ret = do_write_oneword(map, &cfi->chips[chipnum],
  1141. bus_ofs, datum, FL_WRITING);
  1142. if (ret)
  1143. return ret;
  1144. len -= n;
  1145. ofs += n;
  1146. buf += n;
  1147. (*retlen) += n;
  1148. if (ofs >> cfi->chipshift) {
  1149. chipnum ++;
  1150. ofs = 0;
  1151. if (chipnum == cfi->numchips)
  1152. return 0;
  1153. }
  1154. }
  1155. while(len >= map_bankwidth(map)) {
  1156. map_word datum = map_word_load(map, buf);
  1157. ret = do_write_oneword(map, &cfi->chips[chipnum],
  1158. ofs, datum, FL_WRITING);
  1159. if (ret)
  1160. return ret;
  1161. ofs += map_bankwidth(map);
  1162. buf += map_bankwidth(map);
  1163. (*retlen) += map_bankwidth(map);
  1164. len -= map_bankwidth(map);
  1165. if (ofs >> cfi->chipshift) {
  1166. chipnum ++;
  1167. ofs = 0;
  1168. if (chipnum == cfi->numchips)
  1169. return 0;
  1170. }
  1171. }
  1172. if (len & (map_bankwidth(map)-1)) {
  1173. map_word datum;
  1174. datum = map_word_ff(map);
  1175. datum = map_word_load_partial(map, datum, buf, 0, len);
  1176. ret = do_write_oneword(map, &cfi->chips[chipnum],
  1177. ofs, datum, FL_WRITING);
  1178. if (ret)
  1179. return ret;
  1180. (*retlen) += len;
  1181. }
  1182. return 0;
  1183. }
  1184. static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip,
  1185. unsigned long adr, const u_char *buf, int len)
  1186. {
  1187. struct cfi_private *cfi = map->fldrv_priv;
  1188. map_word status, status_OK;
  1189. unsigned long cmd_adr, timeo;
  1190. int wbufsize, z, ret=0, bytes, words;
  1191. wbufsize = cfi_interleave(cfi) << cfi->cfiq->MaxBufWriteSize;
  1192. adr += chip->start;
  1193. cmd_adr = adr & ~(wbufsize-1);
  1194. /* Let's determine this according to the interleave only once */
  1195. status_OK = CMD(0x80);
  1196. spin_lock(chip->mutex);
  1197. ret = get_chip(map, chip, cmd_adr, FL_WRITING);
  1198. if (ret) {
  1199. spin_unlock(chip->mutex);
  1200. return ret;
  1201. }
  1202. XIP_INVAL_CACHED_RANGE(map, adr, len);
  1203. ENABLE_VPP(map);
  1204. xip_disable(map, chip, cmd_adr);
  1205. /* §4.8 of the 28FxxxJ3A datasheet says "Any time SR.4 and/or SR.5 is set
  1206. [...], the device will not accept any more Write to Buffer commands".
  1207. So we must check here and reset those bits if they're set. Otherwise
  1208. we're just pissing in the wind */
  1209. if (chip->state != FL_STATUS)
  1210. map_write(map, CMD(0x70), cmd_adr);
  1211. status = map_read(map, cmd_adr);
  1212. if (map_word_bitsset(map, status, CMD(0x30))) {
  1213. xip_enable(map, chip, cmd_adr);
  1214. printk(KERN_WARNING "SR.4 or SR.5 bits set in buffer write (status %lx). Clearing.\n", status.x[0]);
  1215. xip_disable(map, chip, cmd_adr);
  1216. map_write(map, CMD(0x50), cmd_adr);
  1217. map_write(map, CMD(0x70), cmd_adr);
  1218. }
  1219. chip->state = FL_WRITING_TO_BUFFER;
  1220. z = 0;
  1221. for (;;) {
  1222. map_write(map, CMD(0xe8), cmd_adr);
  1223. status = map_read(map, cmd_adr);
  1224. if (map_word_andequal(map, status, status_OK, status_OK))
  1225. break;
  1226. UDELAY(map, chip, cmd_adr, 1);
  1227. if (++z > 20) {
  1228. /* Argh. Not ready for write to buffer */
  1229. map_word Xstatus;
  1230. map_write(map, CMD(0x70), cmd_adr);
  1231. chip->state = FL_STATUS;
  1232. Xstatus = map_read(map, cmd_adr);
  1233. /* Odd. Clear status bits */
  1234. map_write(map, CMD(0x50), cmd_adr);
  1235. map_write(map, CMD(0x70), cmd_adr);
  1236. xip_enable(map, chip, cmd_adr);
  1237. printk(KERN_ERR "Chip not ready for buffer write. status = %lx, Xstatus = %lx\n",
  1238. status.x[0], Xstatus.x[0]);
  1239. ret = -EIO;
  1240. goto out;
  1241. }
  1242. }
  1243. /* Write length of data to come */
  1244. bytes = len & (map_bankwidth(map)-1);
  1245. words = len / map_bankwidth(map);
  1246. map_write(map, CMD(words - !bytes), cmd_adr );
  1247. /* Write data */
  1248. z = 0;
  1249. while(z < words * map_bankwidth(map)) {
  1250. map_word datum = map_word_load(map, buf);
  1251. map_write(map, datum, adr+z);
  1252. z += map_bankwidth(map);
  1253. buf += map_bankwidth(map);
  1254. }
  1255. if (bytes) {
  1256. map_word datum;
  1257. datum = map_word_ff(map);
  1258. datum = map_word_load_partial(map, datum, buf, 0, bytes);
  1259. map_write(map, datum, adr+z);
  1260. }
  1261. /* GO GO GO */
  1262. map_write(map, CMD(0xd0), cmd_adr);
  1263. chip->state = FL_WRITING;
  1264. INVALIDATE_CACHE_UDELAY(map, chip,
  1265. cmd_adr, len,
  1266. chip->buffer_write_time);
  1267. timeo = jiffies + (HZ/2);
  1268. z = 0;
  1269. for (;;) {
  1270. if (chip->state != FL_WRITING) {
  1271. /* Someone's suspended the write. Sleep */
  1272. DECLARE_WAITQUEUE(wait, current);
  1273. set_current_state(TASK_UNINTERRUPTIBLE);
  1274. add_wait_queue(&chip->wq, &wait);
  1275. spin_unlock(chip->mutex);
  1276. schedule();
  1277. remove_wait_queue(&chip->wq, &wait);
  1278. timeo = jiffies + (HZ / 2); /* FIXME */
  1279. spin_lock(chip->mutex);
  1280. continue;
  1281. }
  1282. status = map_read(map, cmd_adr);
  1283. if (map_word_andequal(map, status, status_OK, status_OK))
  1284. break;
  1285. /* OK Still waiting */
  1286. if (time_after(jiffies, timeo)) {
  1287. chip->state = FL_STATUS;
  1288. xip_enable(map, chip, cmd_adr);
  1289. printk(KERN_ERR "waiting for chip to be ready timed out in bufwrite\n");
  1290. ret = -EIO;
  1291. goto out;
  1292. }
  1293. /* Latency issues. Drop the lock, wait a while and retry */
  1294. z++;
  1295. UDELAY(map, chip, cmd_adr, 1);
  1296. }
  1297. if (!z) {
  1298. chip->buffer_write_time--;
  1299. if (!chip->buffer_write_time)
  1300. chip->buffer_write_time++;
  1301. }
  1302. if (z > 1)
  1303. chip->buffer_write_time++;
  1304. /* Done and happy. */
  1305. chip->state = FL_STATUS;
  1306. /* check for lock bit */
  1307. if (map_word_bitsset(map, status, CMD(0x02))) {
  1308. /* clear status */
  1309. map_write(map, CMD(0x50), cmd_adr);
  1310. /* put back into read status register mode */
  1311. map_write(map, CMD(0x70), adr);
  1312. ret = -EROFS;
  1313. }
  1314. xip_enable(map, chip, cmd_adr);
  1315. out: put_chip(map, chip, cmd_adr);
  1316. spin_unlock(chip->mutex);
  1317. return ret;
  1318. }
  1319. static int cfi_intelext_write_buffers (struct mtd_info *mtd, loff_t to,
  1320. size_t len, size_t *retlen, const u_char *buf)
  1321. {
  1322. struct map_info *map = mtd->priv;
  1323. struct cfi_private *cfi = map->fldrv_priv;
  1324. int wbufsize = cfi_interleave(cfi) << cfi->cfiq->MaxBufWriteSize;
  1325. int ret = 0;
  1326. int chipnum;
  1327. unsigned long ofs;
  1328. *retlen = 0;
  1329. if (!len)
  1330. return 0;
  1331. chipnum = to >> cfi->chipshift;
  1332. ofs = to - (chipnum << cfi->chipshift);
  1333. /* If it's not bus-aligned, do the first word write */
  1334. if (ofs & (map_bankwidth(map)-1)) {
  1335. size_t local_len = (-ofs)&(map_bankwidth(map)-1);
  1336. if (local_len > len)
  1337. local_len = len;
  1338. ret = cfi_intelext_write_words(mtd, to, local_len,
  1339. retlen, buf);
  1340. if (ret)
  1341. return ret;
  1342. ofs += local_len;
  1343. buf += local_len;
  1344. len -= local_len;
  1345. if (ofs >> cfi->chipshift) {
  1346. chipnum ++;
  1347. ofs = 0;
  1348. if (chipnum == cfi->numchips)
  1349. return 0;
  1350. }
  1351. }
  1352. while(len) {
  1353. /* We must not cross write block boundaries */
  1354. int size = wbufsize - (ofs & (wbufsize-1));
  1355. if (size > len)
  1356. size = len;
  1357. ret = do_write_buffer(map, &cfi->chips[chipnum],
  1358. ofs, buf, size);
  1359. if (ret)
  1360. return ret;
  1361. ofs += size;
  1362. buf += size;
  1363. (*retlen) += size;
  1364. len -= size;
  1365. if (ofs >> cfi->chipshift) {
  1366. chipnum ++;
  1367. ofs = 0;
  1368. if (chipnum == cfi->numchips)
  1369. return 0;
  1370. }
  1371. }
  1372. return 0;
  1373. }
  1374. static int __xipram do_erase_oneblock(struct map_info *map, struct flchip *chip,
  1375. unsigned long adr, int len, void *thunk)
  1376. {
  1377. struct cfi_private *cfi = map->fldrv_priv;
  1378. map_word status, status_OK;
  1379. unsigned long timeo;
  1380. int retries = 3;
  1381. DECLARE_WAITQUEUE(wait, current);
  1382. int ret = 0;
  1383. adr += chip->start;
  1384. /* Let's determine this according to the interleave only once */
  1385. status_OK = CMD(0x80);
  1386. retry:
  1387. spin_lock(chip->mutex);
  1388. ret = get_chip(map, chip, adr, FL_ERASING);
  1389. if (ret) {
  1390. spin_unlock(chip->mutex);
  1391. return ret;
  1392. }
  1393. XIP_INVAL_CACHED_RANGE(map, adr, len);
  1394. ENABLE_VPP(map);
  1395. xip_disable(map, chip, adr);
  1396. /* Clear the status register first */
  1397. map_write(map, CMD(0x50), adr);
  1398. /* Now erase */
  1399. map_write(map, CMD(0x20), adr);
  1400. map_write(map, CMD(0xD0), adr);
  1401. chip->state = FL_ERASING;
  1402. chip->erase_suspended = 0;
  1403. INVALIDATE_CACHE_UDELAY(map, chip,
  1404. adr, len,
  1405. chip->erase_time*1000/2);
  1406. /* FIXME. Use a timer to check this, and return immediately. */
  1407. /* Once the state machine's known to be working I'll do that */
  1408. timeo = jiffies + (HZ*20);
  1409. for (;;) {
  1410. if (chip->state != FL_ERASING) {
  1411. /* Someone's suspended the erase. Sleep */
  1412. set_current_state(TASK_UNINTERRUPTIBLE);
  1413. add_wait_queue(&chip->wq, &wait);
  1414. spin_unlock(chip->mutex);
  1415. schedule();
  1416. remove_wait_queue(&chip->wq, &wait);
  1417. spin_lock(chip->mutex);
  1418. continue;
  1419. }
  1420. if (chip->erase_suspended) {
  1421. /* This erase was suspended and resumed.
  1422. Adjust the timeout */
  1423. timeo = jiffies + (HZ*20); /* FIXME */
  1424. chip->erase_suspended = 0;
  1425. }
  1426. status = map_read(map, adr);
  1427. if (map_word_andequal(map, status, status_OK, status_OK))
  1428. break;
  1429. /* OK Still waiting */
  1430. if (time_after(jiffies, timeo)) {
  1431. map_word Xstatus;
  1432. map_write(map, CMD(0x70), adr);
  1433. chip->state = FL_STATUS;
  1434. Xstatus = map_read(map, adr);
  1435. /* Clear status bits */
  1436. map_write(map, CMD(0x50), adr);
  1437. map_write(map, CMD(0x70), adr);
  1438. xip_enable(map, chip, adr);
  1439. printk(KERN_ERR "waiting for erase at %08lx to complete timed out. status = %lx, Xstatus = %lx.\n",
  1440. adr, status.x[0], Xstatus.x[0]);
  1441. ret = -EIO;
  1442. goto out;
  1443. }
  1444. /* Latency issues. Drop the lock, wait a while and retry */
  1445. UDELAY(map, chip, adr, 1000000/HZ);
  1446. }
  1447. /* We've broken this before. It doesn't hurt to be safe */
  1448. map_write(map, CMD(0x70), adr);
  1449. chip->state = FL_STATUS;
  1450. status = map_read(map, adr);
  1451. /* check for lock bit */
  1452. if (map_word_bitsset(map, status, CMD(0x3a))) {
  1453. unsigned long chipstatus;
  1454. /* Reset the error bits */
  1455. map_write(map, CMD(0x50), adr);
  1456. map_write(map, CMD(0x70), adr);
  1457. xip_enable(map, chip, adr);
  1458. chipstatus = MERGESTATUS(status);
  1459. if ((chipstatus & 0x30) == 0x30) {
  1460. printk(KERN_NOTICE "Chip reports improper command sequence: status 0x%lx\n", chipstatus);
  1461. ret = -EIO;
  1462. } else if (chipstatus & 0x02) {
  1463. /* Protection bit set */
  1464. ret = -EROFS;
  1465. } else if (chipstatus & 0x8) {
  1466. /* Voltage */
  1467. printk(KERN_WARNING "Chip reports voltage low on erase: status 0x%lx\n", chipstatus);
  1468. ret = -EIO;
  1469. } else if (chipstatus & 0x20) {
  1470. if (retries--) {
  1471. printk(KERN_DEBUG "Chip erase failed at 0x%08lx: status 0x%lx. Retrying...\n", adr, chipstatus);
  1472. timeo = jiffies + HZ;
  1473. put_chip(map, chip, adr);
  1474. spin_unlock(chip->mutex);
  1475. goto retry;
  1476. }
  1477. printk(KERN_DEBUG "Chip erase failed at 0x%08lx: status 0x%lx\n", adr, chipstatus);
  1478. ret = -EIO;
  1479. }
  1480. } else {
  1481. xip_enable(map, chip, adr);
  1482. ret = 0;
  1483. }
  1484. out: put_chip(map, chip, adr);
  1485. spin_unlock(chip->mutex);
  1486. return ret;
  1487. }
  1488. int cfi_intelext_erase_varsize(struct mtd_info *mtd, struct erase_info *instr)
  1489. {
  1490. unsigned long ofs, len;
  1491. int ret;
  1492. ofs = instr->addr;
  1493. len = instr->len;
  1494. ret = cfi_varsize_frob(mtd, do_erase_oneblock, ofs, len, NULL);
  1495. if (ret)
  1496. return ret;
  1497. instr->state = MTD_ERASE_DONE;
  1498. mtd_erase_callback(instr);
  1499. return 0;
  1500. }
  1501. static void cfi_intelext_sync (struct mtd_info *mtd)
  1502. {
  1503. struct map_info *map = mtd->priv;
  1504. struct cfi_private *cfi = map->fldrv_priv;
  1505. int i;
  1506. struct flchip *chip;
  1507. int ret = 0;
  1508. for (i=0; !ret && i<cfi->numchips; i++) {
  1509. chip = &cfi->chips[i];
  1510. spin_lock(chip->mutex);
  1511. ret = get_chip(map, chip, chip->start, FL_SYNCING);
  1512. if (!ret) {
  1513. chip->oldstate = chip->state;
  1514. chip->state = FL_SYNCING;
  1515. /* No need to wake_up() on this state change -
  1516. * as the whole point is that nobody can do anything
  1517. * with the chip now anyway.
  1518. */
  1519. }
  1520. spin_unlock(chip->mutex);
  1521. }
  1522. /* Unlock the chips again */
  1523. for (i--; i >=0; i--) {
  1524. chip = &cfi->chips[i];
  1525. spin_lock(chip->mutex);
  1526. if (chip->state == FL_SYNCING) {
  1527. chip->state = chip->oldstate;
  1528. chip->oldstate = FL_READY;
  1529. wake_up(&chip->wq);
  1530. }
  1531. spin_unlock(chip->mutex);
  1532. }
  1533. }
  1534. #ifdef DEBUG_LOCK_BITS
  1535. static int __xipram do_printlockstatus_oneblock(struct map_info *map,
  1536. struct flchip *chip,
  1537. unsigned long adr,
  1538. int len, void *thunk)
  1539. {
  1540. struct cfi_private *cfi = map->fldrv_priv;
  1541. int status, ofs_factor = cfi->interleave * cfi->device_type;
  1542. adr += chip->start;
  1543. xip_disable(map, chip, adr+(2*ofs_factor));
  1544. map_write(map, CMD(0x90), adr+(2*ofs_factor));
  1545. chip->state = FL_JEDEC_QUERY;
  1546. status = cfi_read_query(map, adr+(2*ofs_factor));
  1547. xip_enable(map, chip, 0);
  1548. printk(KERN_DEBUG "block status register for 0x%08lx is %x\n",
  1549. adr, status);
  1550. return 0;
  1551. }
  1552. #endif
  1553. #define DO_XXLOCK_ONEBLOCK_LOCK ((void *) 1)
  1554. #define DO_XXLOCK_ONEBLOCK_UNLOCK ((void *) 2)
  1555. static int __xipram do_xxlock_oneblock(struct map_info *map, struct flchip *chip,
  1556. unsigned long adr, int len, void *thunk)
  1557. {
  1558. struct cfi_private *cfi = map->fldrv_priv;
  1559. struct cfi_pri_intelext *extp = cfi->cmdset_priv;
  1560. map_word status, status_OK;
  1561. unsigned long timeo = jiffies + HZ;
  1562. int ret;
  1563. adr += chip->start;
  1564. /* Let's determine this according to the interleave only once */
  1565. status_OK = CMD(0x80);
  1566. spin_lock(chip->mutex);
  1567. ret = get_chip(map, chip, adr, FL_LOCKING);
  1568. if (ret) {
  1569. spin_unlock(chip->mutex);
  1570. return ret;
  1571. }
  1572. ENABLE_VPP(map);
  1573. xip_disable(map, chip, adr);
  1574. map_write(map, CMD(0x60), adr);
  1575. if (thunk == DO_XXLOCK_ONEBLOCK_LOCK) {
  1576. map_write(map, CMD(0x01), adr);
  1577. chip->state = FL_LOCKING;
  1578. } else if (thunk == DO_XXLOCK_ONEBLOCK_UNLOCK) {
  1579. map_write(map, CMD(0xD0), adr);
  1580. chip->state = FL_UNLOCKING;
  1581. } else
  1582. BUG();
  1583. /*
  1584. * If Instant Individual Block Locking supported then no need
  1585. * to delay.
  1586. */
  1587. if (!extp || !(extp->FeatureSupport & (1 << 5)))
  1588. UDELAY(map, chip, adr, 1000000/HZ);
  1589. /* FIXME. Use a timer to check this, and return immediately. */
  1590. /* Once the state machine's known to be working I'll do that */
  1591. timeo = jiffies + (HZ*20);
  1592. for (;;) {
  1593. status = map_read(map, adr);
  1594. if (map_word_andequal(map, status, status_OK, status_OK))
  1595. break;
  1596. /* OK Still waiting */
  1597. if (time_after(jiffies, timeo)) {
  1598. map_word Xstatus;
  1599. map_write(map, CMD(0x70), adr);
  1600. chip->state = FL_STATUS;
  1601. Xstatus = map_read(map, adr);
  1602. xip_enable(map, chip, adr);
  1603. printk(KERN_ERR "waiting for unlock to complete timed out. status = %lx, Xstatus = %lx.\n",
  1604. status.x[0], Xstatus.x[0]);
  1605. put_chip(map, chip, adr);
  1606. spin_unlock(chip->mutex);
  1607. return -EIO;
  1608. }
  1609. /* Latency issues. Drop the lock, wait a while and retry */
  1610. UDELAY(map, chip, adr, 1);
  1611. }
  1612. /* Done and happy. */
  1613. chip->state = FL_STATUS;
  1614. xip_enable(map, chip, adr);
  1615. put_chip(map, chip, adr);
  1616. spin_unlock(chip->mutex);
  1617. return 0;
  1618. }
  1619. static int cfi_intelext_lock(struct mtd_info *mtd, loff_t ofs, size_t len)
  1620. {
  1621. int ret;
  1622. #ifdef DEBUG_LOCK_BITS
  1623. printk(KERN_DEBUG "%s: lock status before, ofs=0x%08llx, len=0x%08X\n",
  1624. __FUNCTION__, ofs, len);
  1625. cfi_varsize_frob(mtd, do_printlockstatus_oneblock,
  1626. ofs, len, 0);
  1627. #endif
  1628. ret = cfi_varsize_frob(mtd, do_xxlock_oneblock,
  1629. ofs, len, DO_XXLOCK_ONEBLOCK_LOCK);
  1630. #ifdef DEBUG_LOCK_BITS
  1631. printk(KERN_DEBUG "%s: lock status after, ret=%d\n",
  1632. __FUNCTION__, ret);
  1633. cfi_varsize_frob(mtd, do_printlockstatus_oneblock,
  1634. ofs, len, 0);
  1635. #endif
  1636. return ret;
  1637. }
  1638. static int cfi_intelext_unlock(struct mtd_info *mtd, loff_t ofs, size_t len)
  1639. {
  1640. int ret;
  1641. #ifdef DEBUG_LOCK_BITS
  1642. printk(KERN_DEBUG "%s: lock status before, ofs=0x%08llx, len=0x%08X\n",
  1643. __FUNCTION__, ofs, len);
  1644. cfi_varsize_frob(mtd, do_printlockstatus_oneblock,
  1645. ofs, len, 0);
  1646. #endif
  1647. ret = cfi_varsize_frob(mtd, do_xxlock_oneblock,
  1648. ofs, len, DO_XXLOCK_ONEBLOCK_UNLOCK);
  1649. #ifdef DEBUG_LOCK_BITS
  1650. printk(KERN_DEBUG "%s: lock status after, ret=%d\n",
  1651. __FUNCTION__, ret);
  1652. cfi_varsize_frob(mtd, do_printlockstatus_oneblock,
  1653. ofs, len, 0);
  1654. #endif
  1655. return ret;
  1656. }
  1657. #ifdef CONFIG_MTD_OTP
  1658. typedef int (*otp_op_t)(struct map_info *map, struct flchip *chip,
  1659. u_long data_offset, u_char *buf, u_int size,
  1660. u_long prot_offset, u_int groupno, u_int groupsize);
  1661. static int __xipram
  1662. do_otp_read(struct map_info *map, struct flchip *chip, u_long offset,
  1663. u_char *buf, u_int size, u_long prot, u_int grpno, u_int grpsz)
  1664. {
  1665. struct cfi_private *cfi = map->fldrv_priv;
  1666. int ret;
  1667. spin_lock(chip->mutex);
  1668. ret = get_chip(map, chip, chip->start, FL_JEDEC_QUERY);
  1669. if (ret) {
  1670. spin_unlock(chip->mutex);
  1671. return ret;
  1672. }
  1673. /* let's ensure we're not reading back cached data from array mode */
  1674. INVALIDATE_CACHED_RANGE(map, chip->start + offset, size);
  1675. xip_disable(map, chip, chip->start);
  1676. if (chip->state != FL_JEDEC_QUERY) {
  1677. map_write(map, CMD(0x90), chip->start);
  1678. chip->state = FL_JEDEC_QUERY;
  1679. }
  1680. map_copy_from(map, buf, chip->start + offset, size);
  1681. xip_enable(map, chip, chip->start);
  1682. /* then ensure we don't keep OTP data in the cache */
  1683. INVALIDATE_CACHED_RANGE(map, chip->start + offset, size);
  1684. put_chip(map, chip, chip->start);
  1685. spin_unlock(chip->mutex);
  1686. return 0;
  1687. }
  1688. static int
  1689. do_otp_write(struct map_info *map, struct flchip *chip, u_long offset,
  1690. u_char *buf, u_int size, u_long prot, u_int grpno, u_int grpsz)
  1691. {
  1692. int ret;
  1693. while (size) {
  1694. unsigned long bus_ofs = offset & ~(map_bankwidth(map)-1);
  1695. int gap = offset - bus_ofs;
  1696. int n = min_t(int, size, map_bankwidth(map)-gap);
  1697. map_word datum = map_word_ff(map);
  1698. datum = map_word_load_partial(map, datum, buf, gap, n);
  1699. ret = do_write_oneword(map, chip, bus_ofs, datum, FL_OTP_WRITE);
  1700. if (ret)
  1701. return ret;
  1702. offset += n;
  1703. buf += n;
  1704. size -= n;
  1705. }
  1706. return 0;
  1707. }
  1708. static int
  1709. do_otp_lock(struct map_info *map, struct flchip *chip, u_long offset,
  1710. u_char *buf, u_int size, u_long prot, u_int grpno, u_int grpsz)
  1711. {
  1712. struct cfi_private *cfi = map->fldrv_priv;
  1713. map_word datum;
  1714. /* make sure area matches group boundaries */
  1715. if (size != grpsz)
  1716. return -EXDEV;
  1717. datum = map_word_ff(map);
  1718. datum = map_word_clr(map, datum, CMD(1 << grpno));
  1719. return do_write_oneword(map, chip, prot, datum, FL_OTP_WRITE);
  1720. }
  1721. static int cfi_intelext_otp_walk(struct mtd_info *mtd, loff_t from, size_t len,
  1722. size_t *retlen, u_char *buf,
  1723. otp_op_t action, int user_regs)
  1724. {
  1725. struct map_info *map = mtd->priv;
  1726. struct cfi_private *cfi = map->fldrv_priv;
  1727. struct cfi_pri_intelext *extp = cfi->cmdset_priv;
  1728. struct flchip *chip;
  1729. struct cfi_intelext_otpinfo *otp;
  1730. u_long devsize, reg_prot_offset, data_offset;
  1731. u_int chip_num, chip_step, field, reg_fact_size, reg_user_size;
  1732. u_int groups, groupno, groupsize, reg_fact_groups, reg_user_groups;
  1733. int ret;
  1734. *retlen = 0;
  1735. /* Check that we actually have some OTP registers */
  1736. if (!extp || !(extp->FeatureSupport & 64) || !extp->NumProtectionFields)
  1737. return -ENODATA;
  1738. /* we need real chips here not virtual ones */
  1739. devsize = (1 << cfi->cfiq->DevSize) * cfi->interleave;
  1740. chip_step = devsize >> cfi->chipshift;
  1741. chip_num = 0;
  1742. /* Some chips have OTP located in the _top_ partition only.
  1743. For example: Intel 28F256L18T (T means top-parameter device) */
  1744. if (cfi->mfr == MANUFACTURER_INTEL) {
  1745. switch (cfi->id) {
  1746. case 0x880b:
  1747. case 0x880c:
  1748. case 0x880d:
  1749. chip_num = chip_step - 1;
  1750. }
  1751. }
  1752. for ( ; chip_num < cfi->numchips; chip_num += chip_step) {
  1753. chip = &cfi->chips[chip_num];
  1754. otp = (struct cfi_intelext_otpinfo *)&extp->extra[0];
  1755. /* first OTP region */
  1756. field = 0;
  1757. reg_prot_offset = extp->ProtRegAddr;
  1758. reg_fact_groups = 1;
  1759. reg_fact_size = 1 << extp->FactProtRegSize;
  1760. reg_user_groups = 1;
  1761. reg_user_size = 1 << extp->UserProtRegSize;
  1762. while (len > 0) {
  1763. /* flash geometry fixup */
  1764. data_offset = reg_prot_offset + 1;
  1765. data_offset *= cfi->interleave * cfi->device_type;
  1766. reg_prot_offset *= cfi->interleave * cfi->device_type;
  1767. reg_fact_size *= cfi->interleave;
  1768. reg_user_size *= cfi->interleave;
  1769. if (user_regs) {
  1770. groups = reg_user_groups;
  1771. groupsize = reg_user_size;
  1772. /* skip over factory reg area */
  1773. groupno = reg_fact_groups;
  1774. data_offset += reg_fact_groups * reg_fact_size;
  1775. } else {
  1776. groups = reg_fact_groups;
  1777. groupsize = reg_fact_size;
  1778. groupno = 0;
  1779. }
  1780. while (len > 0 && groups > 0) {
  1781. if (!action) {
  1782. /*
  1783. * Special case: if action is NULL
  1784. * we fill buf with otp_info records.
  1785. */
  1786. struct otp_info *otpinfo;
  1787. map_word lockword;
  1788. len -= sizeof(struct otp_info);
  1789. if (len <= 0)
  1790. return -ENOSPC;
  1791. ret = do_otp_read(map, chip,
  1792. reg_prot_offset,
  1793. (u_char *)&lockword,
  1794. map_bankwidth(map),
  1795. 0, 0, 0);
  1796. if (ret)
  1797. return ret;
  1798. otpinfo = (struct otp_info *)buf;
  1799. otpinfo->start = from;
  1800. otpinfo->length = groupsize;
  1801. otpinfo->locked =
  1802. !map_word_bitsset(map, lockword,
  1803. CMD(1 << groupno));
  1804. from += groupsize;
  1805. buf += sizeof(*otpinfo);
  1806. *retlen += sizeof(*otpinfo);
  1807. } else if (from >= groupsize) {
  1808. from -= groupsize;
  1809. data_offset += groupsize;
  1810. } else {
  1811. int size = groupsize;
  1812. data_offset += from;
  1813. size -= from;
  1814. from = 0;
  1815. if (size > len)
  1816. size = len;
  1817. ret = action(map, chip, data_offset,
  1818. buf, size, reg_prot_offset,
  1819. groupno, groupsize);
  1820. if (ret < 0)
  1821. return ret;
  1822. buf += size;
  1823. len -= size;
  1824. *retlen += size;
  1825. data_offset += size;
  1826. }
  1827. groupno++;
  1828. groups--;
  1829. }
  1830. /* next OTP region */
  1831. if (++field == extp->NumProtectionFields)
  1832. break;
  1833. reg_prot_offset = otp->ProtRegAddr;
  1834. reg_fact_groups = otp->FactGroups;
  1835. reg_fact_size = 1 << otp->FactProtRegSize;
  1836. reg_user_groups = otp->UserGroups;
  1837. reg_user_size = 1 << otp->UserProtRegSize;
  1838. otp++;
  1839. }
  1840. }
  1841. return 0;
  1842. }
  1843. static int cfi_intelext_read_fact_prot_reg(struct mtd_info *mtd, loff_t from,
  1844. size_t len, size_t *retlen,
  1845. u_char *buf)
  1846. {
  1847. return cfi_intelext_otp_walk(mtd, from, len, retlen,
  1848. buf, do_otp_read, 0);
  1849. }
  1850. static int cfi_intelext_read_user_prot_reg(struct mtd_info *mtd, loff_t from,
  1851. size_t len, size_t *retlen,
  1852. u_char *buf)
  1853. {
  1854. return cfi_intelext_otp_walk(mtd, from, len, retlen,
  1855. buf, do_otp_read, 1);
  1856. }
  1857. static int cfi_intelext_write_user_prot_reg(struct mtd_info *mtd, loff_t from,
  1858. size_t len, size_t *retlen,
  1859. u_char *buf)
  1860. {
  1861. return cfi_intelext_otp_walk(mtd, from, len, retlen,
  1862. buf, do_otp_write, 1);
  1863. }
  1864. static int cfi_intelext_lock_user_prot_reg(struct mtd_info *mtd,
  1865. loff_t from, size_t len)
  1866. {
  1867. size_t retlen;
  1868. return cfi_intelext_otp_walk(mtd, from, len, &retlen,
  1869. NULL, do_otp_lock, 1);
  1870. }
  1871. static int cfi_intelext_get_fact_prot_info(struct mtd_info *mtd,
  1872. struct otp_info *buf, size_t len)
  1873. {
  1874. size_t retlen;
  1875. int ret;
  1876. ret = cfi_intelext_otp_walk(mtd, 0, len, &retlen, (u_char *)buf, NULL, 0);
  1877. return ret ? : retlen;
  1878. }
  1879. static int cfi_intelext_get_user_prot_info(struct mtd_info *mtd,
  1880. struct otp_info *buf, size_t len)
  1881. {
  1882. size_t retlen;
  1883. int ret;
  1884. ret = cfi_intelext_otp_walk(mtd, 0, len, &retlen, (u_char *)buf, NULL, 1);
  1885. return ret ? : retlen;
  1886. }
  1887. #endif
  1888. static int cfi_intelext_suspend(struct mtd_info *mtd)
  1889. {
  1890. struct map_info *map = mtd->priv;
  1891. struct cfi_private *cfi = map->fldrv_priv;
  1892. int i;
  1893. struct flchip *chip;
  1894. int ret = 0;
  1895. for (i=0; !ret && i<cfi->numchips; i++) {
  1896. chip = &cfi->chips[i];
  1897. spin_lock(chip->mutex);
  1898. switch (chip->state) {
  1899. case FL_READY:
  1900. case FL_STATUS:
  1901. case FL_CFI_QUERY:
  1902. case FL_JEDEC_QUERY:
  1903. if (chip->oldstate == FL_READY) {
  1904. chip->oldstate = chip->state;
  1905. chip->state = FL_PM_SUSPENDED;
  1906. /* No need to wake_up() on this state change -
  1907. * as the whole point is that nobody can do anything
  1908. * with the chip now anyway.
  1909. */
  1910. } else {
  1911. /* There seems to be an operation pending. We must wait for it. */
  1912. printk(KERN_NOTICE "Flash device refused suspend due to pending operation (oldstate %d)\n", chip->oldstate);
  1913. ret = -EAGAIN;
  1914. }
  1915. break;
  1916. default:
  1917. /* Should we actually wait? Once upon a time these routines weren't
  1918. allowed to. Or should we return -EAGAIN, because the upper layers
  1919. ought to have already shut down anything which was using the device
  1920. anyway? The latter for now. */
  1921. printk(KERN_NOTICE "Flash device refused suspend due to active operation (state %d)\n", chip->oldstate);
  1922. ret = -EAGAIN;
  1923. case FL_PM_SUSPENDED:
  1924. break;
  1925. }
  1926. spin_unlock(chip->mutex);
  1927. }
  1928. /* Unlock the chips again */
  1929. if (ret) {
  1930. for (i--; i >=0; i--) {
  1931. chip = &cfi->chips[i];
  1932. spin_lock(chip->mutex);
  1933. if (chip->state == FL_PM_SUSPENDED) {
  1934. /* No need to force it into a known state here,
  1935. because we're returning failure, and it didn't
  1936. get power cycled */
  1937. chip->state = chip->oldstate;
  1938. chip->oldstate = FL_READY;
  1939. wake_up(&chip->wq);
  1940. }
  1941. spin_unlock(chip->mutex);
  1942. }
  1943. }
  1944. return ret;
  1945. }
  1946. static void cfi_intelext_resume(struct mtd_info *mtd)
  1947. {
  1948. struct map_info *map = mtd->priv;
  1949. struct cfi_private *cfi = map->fldrv_priv;
  1950. int i;
  1951. struct flchip *chip;
  1952. for (i=0; i<cfi->numchips; i++) {
  1953. chip = &cfi->chips[i];
  1954. spin_lock(chip->mutex);
  1955. /* Go to known state. Chip may have been power cycled */
  1956. if (chip->state == FL_PM_SUSPENDED) {
  1957. map_write(map, CMD(0xFF), cfi->chips[i].start);
  1958. chip->oldstate = chip->state = FL_READY;
  1959. wake_up(&chip->wq);
  1960. }
  1961. spin_unlock(chip->mutex);
  1962. }
  1963. }
  1964. static int cfi_intelext_reset(struct mtd_info *mtd)
  1965. {
  1966. struct map_info *map = mtd->priv;
  1967. struct cfi_private *cfi = map->fldrv_priv;
  1968. int i, ret;
  1969. for (i=0; i < cfi->numchips; i++) {
  1970. struct flchip *chip = &cfi->chips[i];
  1971. /* force the completion of any ongoing operation
  1972. and switch to array mode so any bootloader in
  1973. flash is accessible for soft reboot. */
  1974. spin_lock(chip->mutex);
  1975. ret = get_chip(map, chip, chip->start, FL_SYNCING);
  1976. if (!ret) {
  1977. map_write(map, CMD(0xff), chip->start);
  1978. chip->state = FL_READY;
  1979. }
  1980. spin_unlock(chip->mutex);
  1981. }
  1982. return 0;
  1983. }
  1984. static int cfi_intelext_reboot(struct notifier_block *nb, unsigned long val,
  1985. void *v)
  1986. {
  1987. struct mtd_info *mtd;
  1988. mtd = container_of(nb, struct mtd_info, reboot_notifier);
  1989. cfi_intelext_reset(mtd);
  1990. return NOTIFY_DONE;
  1991. }
  1992. static void cfi_intelext_destroy(struct mtd_info *mtd)
  1993. {
  1994. struct map_info *map = mtd->priv;
  1995. struct cfi_private *cfi = map->fldrv_priv;
  1996. cfi_intelext_reset(mtd);
  1997. unregister_reboot_notifier(&mtd->reboot_notifier);
  1998. kfree(cfi->cmdset_priv);
  1999. kfree(cfi->cfiq);
  2000. kfree(cfi->chips[0].priv);
  2001. kfree(cfi);
  2002. kfree(mtd->eraseregions);
  2003. }
  2004. static char im_name_1[]="cfi_cmdset_0001";
  2005. static char im_name_3[]="cfi_cmdset_0003";
  2006. static int __init cfi_intelext_init(void)
  2007. {
  2008. inter_module_register(im_name_1, THIS_MODULE, &cfi_cmdset_0001);
  2009. inter_module_register(im_name_3, THIS_MODULE, &cfi_cmdset_0001);
  2010. return 0;
  2011. }
  2012. static void __exit cfi_intelext_exit(void)
  2013. {
  2014. inter_module_unregister(im_name_1);
  2015. inter_module_unregister(im_name_3);
  2016. }
  2017. module_init(cfi_intelext_init);
  2018. module_exit(cfi_intelext_exit);
  2019. MODULE_LICENSE("GPL");
  2020. MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org> et al.");
  2021. MODULE_DESCRIPTION("MTD chip driver for Intel/Sharp flash chips");