gpmc.c 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650
  1. /*
  2. * GPMC support functions
  3. *
  4. * Copyright (C) 2005-2006 Nokia Corporation
  5. *
  6. * Author: Juha Yrjola
  7. *
  8. * Copyright (C) 2009 Texas Instruments
  9. * Added OMAP4 support - Santosh Shilimkar <santosh.shilimkar@ti.com>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License version 2 as
  13. * published by the Free Software Foundation.
  14. */
  15. #undef DEBUG
  16. #include <linux/irq.h>
  17. #include <linux/kernel.h>
  18. #include <linux/init.h>
  19. #include <linux/err.h>
  20. #include <linux/clk.h>
  21. #include <linux/ioport.h>
  22. #include <linux/spinlock.h>
  23. #include <linux/io.h>
  24. #include <linux/module.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/platform_device.h>
  27. #include <linux/of.h>
  28. #include <linux/of_mtd.h>
  29. #include <linux/of_device.h>
  30. #include <linux/mtd/nand.h>
  31. #include <linux/platform_data/mtd-nand-omap2.h>
  32. #include <asm/mach-types.h>
  33. #include "soc.h"
  34. #include "common.h"
  35. #include "omap_device.h"
  36. #include "gpmc.h"
  37. #include "gpmc-nand.h"
  38. #include "gpmc-onenand.h"
  39. #define DEVICE_NAME "omap-gpmc"
  40. /* GPMC register offsets */
  41. #define GPMC_REVISION 0x00
  42. #define GPMC_SYSCONFIG 0x10
  43. #define GPMC_SYSSTATUS 0x14
  44. #define GPMC_IRQSTATUS 0x18
  45. #define GPMC_IRQENABLE 0x1c
  46. #define GPMC_TIMEOUT_CONTROL 0x40
  47. #define GPMC_ERR_ADDRESS 0x44
  48. #define GPMC_ERR_TYPE 0x48
  49. #define GPMC_CONFIG 0x50
  50. #define GPMC_STATUS 0x54
  51. #define GPMC_PREFETCH_CONFIG1 0x1e0
  52. #define GPMC_PREFETCH_CONFIG2 0x1e4
  53. #define GPMC_PREFETCH_CONTROL 0x1ec
  54. #define GPMC_PREFETCH_STATUS 0x1f0
  55. #define GPMC_ECC_CONFIG 0x1f4
  56. #define GPMC_ECC_CONTROL 0x1f8
  57. #define GPMC_ECC_SIZE_CONFIG 0x1fc
  58. #define GPMC_ECC1_RESULT 0x200
  59. #define GPMC_ECC_BCH_RESULT_0 0x240 /* not available on OMAP2 */
  60. #define GPMC_ECC_BCH_RESULT_1 0x244 /* not available on OMAP2 */
  61. #define GPMC_ECC_BCH_RESULT_2 0x248 /* not available on OMAP2 */
  62. #define GPMC_ECC_BCH_RESULT_3 0x24c /* not available on OMAP2 */
  63. /* GPMC ECC control settings */
  64. #define GPMC_ECC_CTRL_ECCCLEAR 0x100
  65. #define GPMC_ECC_CTRL_ECCDISABLE 0x000
  66. #define GPMC_ECC_CTRL_ECCREG1 0x001
  67. #define GPMC_ECC_CTRL_ECCREG2 0x002
  68. #define GPMC_ECC_CTRL_ECCREG3 0x003
  69. #define GPMC_ECC_CTRL_ECCREG4 0x004
  70. #define GPMC_ECC_CTRL_ECCREG5 0x005
  71. #define GPMC_ECC_CTRL_ECCREG6 0x006
  72. #define GPMC_ECC_CTRL_ECCREG7 0x007
  73. #define GPMC_ECC_CTRL_ECCREG8 0x008
  74. #define GPMC_ECC_CTRL_ECCREG9 0x009
  75. #define GPMC_CONFIG2_CSEXTRADELAY BIT(7)
  76. #define GPMC_CONFIG3_ADVEXTRADELAY BIT(7)
  77. #define GPMC_CONFIG4_OEEXTRADELAY BIT(7)
  78. #define GPMC_CONFIG4_WEEXTRADELAY BIT(23)
  79. #define GPMC_CONFIG6_CYCLE2CYCLEDIFFCSEN BIT(6)
  80. #define GPMC_CONFIG6_CYCLE2CYCLESAMECSEN BIT(7)
  81. #define GPMC_CS0_OFFSET 0x60
  82. #define GPMC_CS_SIZE 0x30
  83. #define GPMC_BCH_SIZE 0x10
  84. #define GPMC_MEM_START 0x00000000
  85. #define GPMC_MEM_END 0x3FFFFFFF
  86. #define BOOT_ROM_SPACE 0x100000 /* 1MB */
  87. #define GPMC_CHUNK_SHIFT 24 /* 16 MB */
  88. #define GPMC_SECTION_SHIFT 28 /* 128 MB */
  89. #define CS_NUM_SHIFT 24
  90. #define ENABLE_PREFETCH (0x1 << 7)
  91. #define DMA_MPU_MODE 2
  92. #define GPMC_REVISION_MAJOR(l) ((l >> 4) & 0xf)
  93. #define GPMC_REVISION_MINOR(l) (l & 0xf)
  94. #define GPMC_HAS_WR_ACCESS 0x1
  95. #define GPMC_HAS_WR_DATA_MUX_BUS 0x2
  96. #define GPMC_HAS_MUX_AAD 0x4
  97. #define GPMC_NR_WAITPINS 4
  98. /* XXX: Only NAND irq has been considered,currently these are the only ones used
  99. */
  100. #define GPMC_NR_IRQ 2
  101. struct gpmc_client_irq {
  102. unsigned irq;
  103. u32 bitmask;
  104. };
  105. /* Structure to save gpmc cs context */
  106. struct gpmc_cs_config {
  107. u32 config1;
  108. u32 config2;
  109. u32 config3;
  110. u32 config4;
  111. u32 config5;
  112. u32 config6;
  113. u32 config7;
  114. int is_valid;
  115. };
  116. /*
  117. * Structure to save/restore gpmc context
  118. * to support core off on OMAP3
  119. */
  120. struct omap3_gpmc_regs {
  121. u32 sysconfig;
  122. u32 irqenable;
  123. u32 timeout_ctrl;
  124. u32 config;
  125. u32 prefetch_config1;
  126. u32 prefetch_config2;
  127. u32 prefetch_control;
  128. struct gpmc_cs_config cs_context[GPMC_CS_NUM];
  129. };
  130. static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
  131. static struct irq_chip gpmc_irq_chip;
  132. static unsigned gpmc_irq_start;
  133. static struct resource gpmc_mem_root;
  134. static struct resource gpmc_cs_mem[GPMC_CS_NUM];
  135. static DEFINE_SPINLOCK(gpmc_mem_lock);
  136. /* Define chip-selects as reserved by default until probe completes */
  137. static unsigned int gpmc_cs_map = ((1 << GPMC_CS_NUM) - 1);
  138. static unsigned int gpmc_nr_waitpins;
  139. static struct device *gpmc_dev;
  140. static int gpmc_irq;
  141. static resource_size_t phys_base, mem_size;
  142. static unsigned gpmc_capability;
  143. static void __iomem *gpmc_base;
  144. static struct clk *gpmc_l3_clk;
  145. static irqreturn_t gpmc_handle_irq(int irq, void *dev);
  146. static void gpmc_write_reg(int idx, u32 val)
  147. {
  148. __raw_writel(val, gpmc_base + idx);
  149. }
  150. static u32 gpmc_read_reg(int idx)
  151. {
  152. return __raw_readl(gpmc_base + idx);
  153. }
  154. void gpmc_cs_write_reg(int cs, int idx, u32 val)
  155. {
  156. void __iomem *reg_addr;
  157. reg_addr = gpmc_base + GPMC_CS0_OFFSET + (cs * GPMC_CS_SIZE) + idx;
  158. __raw_writel(val, reg_addr);
  159. }
  160. static u32 gpmc_cs_read_reg(int cs, int idx)
  161. {
  162. void __iomem *reg_addr;
  163. reg_addr = gpmc_base + GPMC_CS0_OFFSET + (cs * GPMC_CS_SIZE) + idx;
  164. return __raw_readl(reg_addr);
  165. }
  166. /* TODO: Add support for gpmc_fck to clock framework and use it */
  167. static unsigned long gpmc_get_fclk_period(void)
  168. {
  169. unsigned long rate = clk_get_rate(gpmc_l3_clk);
  170. if (rate == 0) {
  171. printk(KERN_WARNING "gpmc_l3_clk not enabled\n");
  172. return 0;
  173. }
  174. rate /= 1000;
  175. rate = 1000000000 / rate; /* In picoseconds */
  176. return rate;
  177. }
  178. static unsigned int gpmc_ns_to_ticks(unsigned int time_ns)
  179. {
  180. unsigned long tick_ps;
  181. /* Calculate in picosecs to yield more exact results */
  182. tick_ps = gpmc_get_fclk_period();
  183. return (time_ns * 1000 + tick_ps - 1) / tick_ps;
  184. }
  185. static unsigned int gpmc_ps_to_ticks(unsigned int time_ps)
  186. {
  187. unsigned long tick_ps;
  188. /* Calculate in picosecs to yield more exact results */
  189. tick_ps = gpmc_get_fclk_period();
  190. return (time_ps + tick_ps - 1) / tick_ps;
  191. }
  192. unsigned int gpmc_ticks_to_ns(unsigned int ticks)
  193. {
  194. return ticks * gpmc_get_fclk_period() / 1000;
  195. }
  196. static unsigned int gpmc_ticks_to_ps(unsigned int ticks)
  197. {
  198. return ticks * gpmc_get_fclk_period();
  199. }
  200. static unsigned int gpmc_round_ps_to_ticks(unsigned int time_ps)
  201. {
  202. unsigned long ticks = gpmc_ps_to_ticks(time_ps);
  203. return ticks * gpmc_get_fclk_period();
  204. }
  205. static inline void gpmc_cs_modify_reg(int cs, int reg, u32 mask, bool value)
  206. {
  207. u32 l;
  208. l = gpmc_cs_read_reg(cs, reg);
  209. if (value)
  210. l |= mask;
  211. else
  212. l &= ~mask;
  213. gpmc_cs_write_reg(cs, reg, l);
  214. }
  215. static void gpmc_cs_bool_timings(int cs, const struct gpmc_bool_timings *p)
  216. {
  217. gpmc_cs_modify_reg(cs, GPMC_CS_CONFIG1,
  218. GPMC_CONFIG1_TIME_PARA_GRAN,
  219. p->time_para_granularity);
  220. gpmc_cs_modify_reg(cs, GPMC_CS_CONFIG2,
  221. GPMC_CONFIG2_CSEXTRADELAY, p->cs_extra_delay);
  222. gpmc_cs_modify_reg(cs, GPMC_CS_CONFIG3,
  223. GPMC_CONFIG3_ADVEXTRADELAY, p->adv_extra_delay);
  224. gpmc_cs_modify_reg(cs, GPMC_CS_CONFIG4,
  225. GPMC_CONFIG4_OEEXTRADELAY, p->oe_extra_delay);
  226. gpmc_cs_modify_reg(cs, GPMC_CS_CONFIG4,
  227. GPMC_CONFIG4_OEEXTRADELAY, p->we_extra_delay);
  228. gpmc_cs_modify_reg(cs, GPMC_CS_CONFIG6,
  229. GPMC_CONFIG6_CYCLE2CYCLESAMECSEN,
  230. p->cycle2cyclesamecsen);
  231. gpmc_cs_modify_reg(cs, GPMC_CS_CONFIG6,
  232. GPMC_CONFIG6_CYCLE2CYCLEDIFFCSEN,
  233. p->cycle2cyclediffcsen);
  234. }
  235. #ifdef DEBUG
  236. static int set_gpmc_timing_reg(int cs, int reg, int st_bit, int end_bit,
  237. int time, const char *name)
  238. #else
  239. static int set_gpmc_timing_reg(int cs, int reg, int st_bit, int end_bit,
  240. int time)
  241. #endif
  242. {
  243. u32 l;
  244. int ticks, mask, nr_bits;
  245. if (time == 0)
  246. ticks = 0;
  247. else
  248. ticks = gpmc_ns_to_ticks(time);
  249. nr_bits = end_bit - st_bit + 1;
  250. if (ticks >= 1 << nr_bits) {
  251. #ifdef DEBUG
  252. printk(KERN_INFO "GPMC CS%d: %-10s* %3d ns, %3d ticks >= %d\n",
  253. cs, name, time, ticks, 1 << nr_bits);
  254. #endif
  255. return -1;
  256. }
  257. mask = (1 << nr_bits) - 1;
  258. l = gpmc_cs_read_reg(cs, reg);
  259. #ifdef DEBUG
  260. printk(KERN_INFO
  261. "GPMC CS%d: %-10s: %3d ticks, %3lu ns (was %3i ticks) %3d ns\n",
  262. cs, name, ticks, gpmc_get_fclk_period() * ticks / 1000,
  263. (l >> st_bit) & mask, time);
  264. #endif
  265. l &= ~(mask << st_bit);
  266. l |= ticks << st_bit;
  267. gpmc_cs_write_reg(cs, reg, l);
  268. return 0;
  269. }
  270. #ifdef DEBUG
  271. #define GPMC_SET_ONE(reg, st, end, field) \
  272. if (set_gpmc_timing_reg(cs, (reg), (st), (end), \
  273. t->field, #field) < 0) \
  274. return -1
  275. #else
  276. #define GPMC_SET_ONE(reg, st, end, field) \
  277. if (set_gpmc_timing_reg(cs, (reg), (st), (end), t->field) < 0) \
  278. return -1
  279. #endif
  280. int gpmc_calc_divider(unsigned int sync_clk)
  281. {
  282. int div;
  283. u32 l;
  284. l = sync_clk + (gpmc_get_fclk_period() - 1);
  285. div = l / gpmc_get_fclk_period();
  286. if (div > 4)
  287. return -1;
  288. if (div <= 0)
  289. div = 1;
  290. return div;
  291. }
  292. int gpmc_cs_set_timings(int cs, const struct gpmc_timings *t)
  293. {
  294. int div;
  295. u32 l;
  296. div = gpmc_calc_divider(t->sync_clk);
  297. if (div < 0)
  298. return div;
  299. GPMC_SET_ONE(GPMC_CS_CONFIG2, 0, 3, cs_on);
  300. GPMC_SET_ONE(GPMC_CS_CONFIG2, 8, 12, cs_rd_off);
  301. GPMC_SET_ONE(GPMC_CS_CONFIG2, 16, 20, cs_wr_off);
  302. GPMC_SET_ONE(GPMC_CS_CONFIG3, 0, 3, adv_on);
  303. GPMC_SET_ONE(GPMC_CS_CONFIG3, 8, 12, adv_rd_off);
  304. GPMC_SET_ONE(GPMC_CS_CONFIG3, 16, 20, adv_wr_off);
  305. GPMC_SET_ONE(GPMC_CS_CONFIG4, 0, 3, oe_on);
  306. GPMC_SET_ONE(GPMC_CS_CONFIG4, 8, 12, oe_off);
  307. GPMC_SET_ONE(GPMC_CS_CONFIG4, 16, 19, we_on);
  308. GPMC_SET_ONE(GPMC_CS_CONFIG4, 24, 28, we_off);
  309. GPMC_SET_ONE(GPMC_CS_CONFIG5, 0, 4, rd_cycle);
  310. GPMC_SET_ONE(GPMC_CS_CONFIG5, 8, 12, wr_cycle);
  311. GPMC_SET_ONE(GPMC_CS_CONFIG5, 16, 20, access);
  312. GPMC_SET_ONE(GPMC_CS_CONFIG5, 24, 27, page_burst_access);
  313. GPMC_SET_ONE(GPMC_CS_CONFIG6, 0, 3, bus_turnaround);
  314. GPMC_SET_ONE(GPMC_CS_CONFIG6, 8, 11, cycle2cycle_delay);
  315. GPMC_SET_ONE(GPMC_CS_CONFIG1, 18, 19, wait_monitoring);
  316. GPMC_SET_ONE(GPMC_CS_CONFIG1, 25, 26, clk_activation);
  317. if (gpmc_capability & GPMC_HAS_WR_DATA_MUX_BUS)
  318. GPMC_SET_ONE(GPMC_CS_CONFIG6, 16, 19, wr_data_mux_bus);
  319. if (gpmc_capability & GPMC_HAS_WR_ACCESS)
  320. GPMC_SET_ONE(GPMC_CS_CONFIG6, 24, 28, wr_access);
  321. /* caller is expected to have initialized CONFIG1 to cover
  322. * at least sync vs async
  323. */
  324. l = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG1);
  325. if (l & (GPMC_CONFIG1_READTYPE_SYNC | GPMC_CONFIG1_WRITETYPE_SYNC)) {
  326. #ifdef DEBUG
  327. printk(KERN_INFO "GPMC CS%d CLK period is %lu ns (div %d)\n",
  328. cs, (div * gpmc_get_fclk_period()) / 1000, div);
  329. #endif
  330. l &= ~0x03;
  331. l |= (div - 1);
  332. gpmc_cs_write_reg(cs, GPMC_CS_CONFIG1, l);
  333. }
  334. gpmc_cs_bool_timings(cs, &t->bool_timings);
  335. return 0;
  336. }
  337. static void gpmc_cs_enable_mem(int cs, u32 base, u32 size)
  338. {
  339. u32 l;
  340. u32 mask;
  341. mask = (1 << GPMC_SECTION_SHIFT) - size;
  342. l = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG7);
  343. l &= ~0x3f;
  344. l = (base >> GPMC_CHUNK_SHIFT) & 0x3f;
  345. l &= ~(0x0f << 8);
  346. l |= ((mask >> GPMC_CHUNK_SHIFT) & 0x0f) << 8;
  347. l |= GPMC_CONFIG7_CSVALID;
  348. gpmc_cs_write_reg(cs, GPMC_CS_CONFIG7, l);
  349. }
  350. static void gpmc_cs_disable_mem(int cs)
  351. {
  352. u32 l;
  353. l = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG7);
  354. l &= ~GPMC_CONFIG7_CSVALID;
  355. gpmc_cs_write_reg(cs, GPMC_CS_CONFIG7, l);
  356. }
  357. static void gpmc_cs_get_memconf(int cs, u32 *base, u32 *size)
  358. {
  359. u32 l;
  360. u32 mask;
  361. l = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG7);
  362. *base = (l & 0x3f) << GPMC_CHUNK_SHIFT;
  363. mask = (l >> 8) & 0x0f;
  364. *size = (1 << GPMC_SECTION_SHIFT) - (mask << GPMC_CHUNK_SHIFT);
  365. }
  366. static int gpmc_cs_mem_enabled(int cs)
  367. {
  368. u32 l;
  369. l = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG7);
  370. return l & GPMC_CONFIG7_CSVALID;
  371. }
  372. static void gpmc_cs_set_reserved(int cs, int reserved)
  373. {
  374. gpmc_cs_map &= ~(1 << cs);
  375. gpmc_cs_map |= (reserved ? 1 : 0) << cs;
  376. }
  377. static bool gpmc_cs_reserved(int cs)
  378. {
  379. return gpmc_cs_map & (1 << cs);
  380. }
  381. static unsigned long gpmc_mem_align(unsigned long size)
  382. {
  383. int order;
  384. size = (size - 1) >> (GPMC_CHUNK_SHIFT - 1);
  385. order = GPMC_CHUNK_SHIFT - 1;
  386. do {
  387. size >>= 1;
  388. order++;
  389. } while (size);
  390. size = 1 << order;
  391. return size;
  392. }
  393. static int gpmc_cs_insert_mem(int cs, unsigned long base, unsigned long size)
  394. {
  395. struct resource *res = &gpmc_cs_mem[cs];
  396. int r;
  397. size = gpmc_mem_align(size);
  398. spin_lock(&gpmc_mem_lock);
  399. res->start = base;
  400. res->end = base + size - 1;
  401. r = request_resource(&gpmc_mem_root, res);
  402. spin_unlock(&gpmc_mem_lock);
  403. return r;
  404. }
  405. static int gpmc_cs_delete_mem(int cs)
  406. {
  407. struct resource *res = &gpmc_cs_mem[cs];
  408. int r;
  409. spin_lock(&gpmc_mem_lock);
  410. r = release_resource(&gpmc_cs_mem[cs]);
  411. res->start = 0;
  412. res->end = 0;
  413. spin_unlock(&gpmc_mem_lock);
  414. return r;
  415. }
  416. int gpmc_cs_request(int cs, unsigned long size, unsigned long *base)
  417. {
  418. struct resource *res = &gpmc_cs_mem[cs];
  419. int r = -1;
  420. if (cs > GPMC_CS_NUM)
  421. return -ENODEV;
  422. size = gpmc_mem_align(size);
  423. if (size > (1 << GPMC_SECTION_SHIFT))
  424. return -ENOMEM;
  425. spin_lock(&gpmc_mem_lock);
  426. if (gpmc_cs_reserved(cs)) {
  427. r = -EBUSY;
  428. goto out;
  429. }
  430. if (gpmc_cs_mem_enabled(cs))
  431. r = adjust_resource(res, res->start & ~(size - 1), size);
  432. if (r < 0)
  433. r = allocate_resource(&gpmc_mem_root, res, size, 0, ~0,
  434. size, NULL, NULL);
  435. if (r < 0)
  436. goto out;
  437. gpmc_cs_enable_mem(cs, res->start, resource_size(res));
  438. *base = res->start;
  439. gpmc_cs_set_reserved(cs, 1);
  440. out:
  441. spin_unlock(&gpmc_mem_lock);
  442. return r;
  443. }
  444. EXPORT_SYMBOL(gpmc_cs_request);
  445. void gpmc_cs_free(int cs)
  446. {
  447. spin_lock(&gpmc_mem_lock);
  448. if (cs >= GPMC_CS_NUM || cs < 0 || !gpmc_cs_reserved(cs)) {
  449. printk(KERN_ERR "Trying to free non-reserved GPMC CS%d\n", cs);
  450. BUG();
  451. spin_unlock(&gpmc_mem_lock);
  452. return;
  453. }
  454. gpmc_cs_disable_mem(cs);
  455. release_resource(&gpmc_cs_mem[cs]);
  456. gpmc_cs_set_reserved(cs, 0);
  457. spin_unlock(&gpmc_mem_lock);
  458. }
  459. EXPORT_SYMBOL(gpmc_cs_free);
  460. /**
  461. * gpmc_cs_configure - write request to configure gpmc
  462. * @cs: chip select number
  463. * @cmd: command type
  464. * @wval: value to write
  465. * @return status of the operation
  466. */
  467. int gpmc_cs_configure(int cs, int cmd, int wval)
  468. {
  469. int err = 0;
  470. u32 regval = 0;
  471. switch (cmd) {
  472. case GPMC_ENABLE_IRQ:
  473. gpmc_write_reg(GPMC_IRQENABLE, wval);
  474. break;
  475. case GPMC_SET_IRQ_STATUS:
  476. gpmc_write_reg(GPMC_IRQSTATUS, wval);
  477. break;
  478. case GPMC_CONFIG_WP:
  479. regval = gpmc_read_reg(GPMC_CONFIG);
  480. if (wval)
  481. regval &= ~GPMC_CONFIG_WRITEPROTECT; /* WP is ON */
  482. else
  483. regval |= GPMC_CONFIG_WRITEPROTECT; /* WP is OFF */
  484. gpmc_write_reg(GPMC_CONFIG, regval);
  485. break;
  486. case GPMC_CONFIG_RDY_BSY:
  487. regval = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG1);
  488. if (wval)
  489. regval |= WR_RD_PIN_MONITORING;
  490. else
  491. regval &= ~WR_RD_PIN_MONITORING;
  492. gpmc_cs_write_reg(cs, GPMC_CS_CONFIG1, regval);
  493. break;
  494. case GPMC_CONFIG_DEV_SIZE:
  495. regval = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG1);
  496. /* clear 2 target bits */
  497. regval &= ~GPMC_CONFIG1_DEVICESIZE(3);
  498. /* set the proper value */
  499. regval |= GPMC_CONFIG1_DEVICESIZE(wval);
  500. gpmc_cs_write_reg(cs, GPMC_CS_CONFIG1, regval);
  501. break;
  502. case GPMC_CONFIG_DEV_TYPE:
  503. regval = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG1);
  504. /* clear 4 target bits */
  505. regval &= ~(GPMC_CONFIG1_DEVICETYPE(3) |
  506. GPMC_CONFIG1_MUXTYPE(3));
  507. /* set the proper value */
  508. regval |= GPMC_CONFIG1_DEVICETYPE(wval);
  509. if (wval == GPMC_DEVICETYPE_NOR)
  510. regval |= GPMC_CONFIG1_MUXADDDATA;
  511. gpmc_cs_write_reg(cs, GPMC_CS_CONFIG1, regval);
  512. break;
  513. default:
  514. printk(KERN_ERR "gpmc_configure_cs: Not supported\n");
  515. err = -EINVAL;
  516. }
  517. return err;
  518. }
  519. EXPORT_SYMBOL(gpmc_cs_configure);
  520. void gpmc_update_nand_reg(struct gpmc_nand_regs *reg, int cs)
  521. {
  522. int i;
  523. reg->gpmc_status = gpmc_base + GPMC_STATUS;
  524. reg->gpmc_nand_command = gpmc_base + GPMC_CS0_OFFSET +
  525. GPMC_CS_NAND_COMMAND + GPMC_CS_SIZE * cs;
  526. reg->gpmc_nand_address = gpmc_base + GPMC_CS0_OFFSET +
  527. GPMC_CS_NAND_ADDRESS + GPMC_CS_SIZE * cs;
  528. reg->gpmc_nand_data = gpmc_base + GPMC_CS0_OFFSET +
  529. GPMC_CS_NAND_DATA + GPMC_CS_SIZE * cs;
  530. reg->gpmc_prefetch_config1 = gpmc_base + GPMC_PREFETCH_CONFIG1;
  531. reg->gpmc_prefetch_config2 = gpmc_base + GPMC_PREFETCH_CONFIG2;
  532. reg->gpmc_prefetch_control = gpmc_base + GPMC_PREFETCH_CONTROL;
  533. reg->gpmc_prefetch_status = gpmc_base + GPMC_PREFETCH_STATUS;
  534. reg->gpmc_ecc_config = gpmc_base + GPMC_ECC_CONFIG;
  535. reg->gpmc_ecc_control = gpmc_base + GPMC_ECC_CONTROL;
  536. reg->gpmc_ecc_size_config = gpmc_base + GPMC_ECC_SIZE_CONFIG;
  537. reg->gpmc_ecc1_result = gpmc_base + GPMC_ECC1_RESULT;
  538. for (i = 0; i < GPMC_BCH_NUM_REMAINDER; i++) {
  539. reg->gpmc_bch_result0[i] = gpmc_base + GPMC_ECC_BCH_RESULT_0 +
  540. GPMC_BCH_SIZE * i;
  541. reg->gpmc_bch_result1[i] = gpmc_base + GPMC_ECC_BCH_RESULT_1 +
  542. GPMC_BCH_SIZE * i;
  543. reg->gpmc_bch_result2[i] = gpmc_base + GPMC_ECC_BCH_RESULT_2 +
  544. GPMC_BCH_SIZE * i;
  545. reg->gpmc_bch_result3[i] = gpmc_base + GPMC_ECC_BCH_RESULT_3 +
  546. GPMC_BCH_SIZE * i;
  547. }
  548. }
  549. int gpmc_get_client_irq(unsigned irq_config)
  550. {
  551. int i;
  552. if (hweight32(irq_config) > 1)
  553. return 0;
  554. for (i = 0; i < GPMC_NR_IRQ; i++)
  555. if (gpmc_client_irq[i].bitmask & irq_config)
  556. return gpmc_client_irq[i].irq;
  557. return 0;
  558. }
  559. static int gpmc_irq_endis(unsigned irq, bool endis)
  560. {
  561. int i;
  562. u32 regval;
  563. for (i = 0; i < GPMC_NR_IRQ; i++)
  564. if (irq == gpmc_client_irq[i].irq) {
  565. regval = gpmc_read_reg(GPMC_IRQENABLE);
  566. if (endis)
  567. regval |= gpmc_client_irq[i].bitmask;
  568. else
  569. regval &= ~gpmc_client_irq[i].bitmask;
  570. gpmc_write_reg(GPMC_IRQENABLE, regval);
  571. break;
  572. }
  573. return 0;
  574. }
  575. static void gpmc_irq_disable(struct irq_data *p)
  576. {
  577. gpmc_irq_endis(p->irq, false);
  578. }
  579. static void gpmc_irq_enable(struct irq_data *p)
  580. {
  581. gpmc_irq_endis(p->irq, true);
  582. }
  583. static void gpmc_irq_noop(struct irq_data *data) { }
  584. static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
  585. static int gpmc_setup_irq(void)
  586. {
  587. int i;
  588. u32 regval;
  589. if (!gpmc_irq)
  590. return -EINVAL;
  591. gpmc_irq_start = irq_alloc_descs(-1, 0, GPMC_NR_IRQ, 0);
  592. if (gpmc_irq_start < 0) {
  593. pr_err("irq_alloc_descs failed\n");
  594. return gpmc_irq_start;
  595. }
  596. gpmc_irq_chip.name = "gpmc";
  597. gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
  598. gpmc_irq_chip.irq_enable = gpmc_irq_enable;
  599. gpmc_irq_chip.irq_disable = gpmc_irq_disable;
  600. gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
  601. gpmc_irq_chip.irq_ack = gpmc_irq_noop;
  602. gpmc_irq_chip.irq_mask = gpmc_irq_noop;
  603. gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
  604. gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
  605. gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
  606. for (i = 0; i < GPMC_NR_IRQ; i++) {
  607. gpmc_client_irq[i].irq = gpmc_irq_start + i;
  608. irq_set_chip_and_handler(gpmc_client_irq[i].irq,
  609. &gpmc_irq_chip, handle_simple_irq);
  610. set_irq_flags(gpmc_client_irq[i].irq,
  611. IRQF_VALID | IRQF_NOAUTOEN);
  612. }
  613. /* Disable interrupts */
  614. gpmc_write_reg(GPMC_IRQENABLE, 0);
  615. /* clear interrupts */
  616. regval = gpmc_read_reg(GPMC_IRQSTATUS);
  617. gpmc_write_reg(GPMC_IRQSTATUS, regval);
  618. return request_irq(gpmc_irq, gpmc_handle_irq, 0, "gpmc", NULL);
  619. }
  620. static int gpmc_free_irq(void)
  621. {
  622. int i;
  623. if (gpmc_irq)
  624. free_irq(gpmc_irq, NULL);
  625. for (i = 0; i < GPMC_NR_IRQ; i++) {
  626. irq_set_handler(gpmc_client_irq[i].irq, NULL);
  627. irq_set_chip(gpmc_client_irq[i].irq, &no_irq_chip);
  628. irq_modify_status(gpmc_client_irq[i].irq, 0, 0);
  629. }
  630. irq_free_descs(gpmc_irq_start, GPMC_NR_IRQ);
  631. return 0;
  632. }
  633. static void gpmc_mem_exit(void)
  634. {
  635. int cs;
  636. for (cs = 0; cs < GPMC_CS_NUM; cs++) {
  637. if (!gpmc_cs_mem_enabled(cs))
  638. continue;
  639. gpmc_cs_delete_mem(cs);
  640. }
  641. }
  642. static int gpmc_mem_init(void)
  643. {
  644. int cs, rc;
  645. unsigned long boot_rom_space = 0;
  646. /* never allocate the first page, to facilitate bug detection;
  647. * even if we didn't boot from ROM.
  648. */
  649. boot_rom_space = BOOT_ROM_SPACE;
  650. gpmc_mem_root.start = GPMC_MEM_START + boot_rom_space;
  651. gpmc_mem_root.end = GPMC_MEM_END;
  652. /* Reserve all regions that has been set up by bootloader */
  653. for (cs = 0; cs < GPMC_CS_NUM; cs++) {
  654. u32 base, size;
  655. if (!gpmc_cs_mem_enabled(cs))
  656. continue;
  657. gpmc_cs_get_memconf(cs, &base, &size);
  658. rc = gpmc_cs_insert_mem(cs, base, size);
  659. if (rc < 0) {
  660. while (--cs >= 0)
  661. if (gpmc_cs_mem_enabled(cs))
  662. gpmc_cs_delete_mem(cs);
  663. return rc;
  664. }
  665. }
  666. return 0;
  667. }
  668. static u32 gpmc_round_ps_to_sync_clk(u32 time_ps, u32 sync_clk)
  669. {
  670. u32 temp;
  671. int div;
  672. div = gpmc_calc_divider(sync_clk);
  673. temp = gpmc_ps_to_ticks(time_ps);
  674. temp = (temp + div - 1) / div;
  675. return gpmc_ticks_to_ps(temp * div);
  676. }
  677. /* XXX: can the cycles be avoided ? */
  678. static int gpmc_calc_sync_read_timings(struct gpmc_timings *gpmc_t,
  679. struct gpmc_device_timings *dev_t,
  680. bool mux)
  681. {
  682. u32 temp;
  683. /* adv_rd_off */
  684. temp = dev_t->t_avdp_r;
  685. /* XXX: mux check required ? */
  686. if (mux) {
  687. /* XXX: t_avdp not to be required for sync, only added for tusb
  688. * this indirectly necessitates requirement of t_avdp_r and
  689. * t_avdp_w instead of having a single t_avdp
  690. */
  691. temp = max_t(u32, temp, gpmc_t->clk_activation + dev_t->t_avdh);
  692. temp = max_t(u32, gpmc_t->adv_on + gpmc_ticks_to_ps(1), temp);
  693. }
  694. gpmc_t->adv_rd_off = gpmc_round_ps_to_ticks(temp);
  695. /* oe_on */
  696. temp = dev_t->t_oeasu; /* XXX: remove this ? */
  697. if (mux) {
  698. temp = max_t(u32, temp, gpmc_t->clk_activation + dev_t->t_ach);
  699. temp = max_t(u32, temp, gpmc_t->adv_rd_off +
  700. gpmc_ticks_to_ps(dev_t->cyc_aavdh_oe));
  701. }
  702. gpmc_t->oe_on = gpmc_round_ps_to_ticks(temp);
  703. /* access */
  704. /* XXX: any scope for improvement ?, by combining oe_on
  705. * and clk_activation, need to check whether
  706. * access = clk_activation + round to sync clk ?
  707. */
  708. temp = max_t(u32, dev_t->t_iaa, dev_t->cyc_iaa * gpmc_t->sync_clk);
  709. temp += gpmc_t->clk_activation;
  710. if (dev_t->cyc_oe)
  711. temp = max_t(u32, temp, gpmc_t->oe_on +
  712. gpmc_ticks_to_ps(dev_t->cyc_oe));
  713. gpmc_t->access = gpmc_round_ps_to_ticks(temp);
  714. gpmc_t->oe_off = gpmc_t->access + gpmc_ticks_to_ps(1);
  715. gpmc_t->cs_rd_off = gpmc_t->oe_off;
  716. /* rd_cycle */
  717. temp = max_t(u32, dev_t->t_cez_r, dev_t->t_oez);
  718. temp = gpmc_round_ps_to_sync_clk(temp, gpmc_t->sync_clk) +
  719. gpmc_t->access;
  720. /* XXX: barter t_ce_rdyz with t_cez_r ? */
  721. if (dev_t->t_ce_rdyz)
  722. temp = max_t(u32, temp, gpmc_t->cs_rd_off + dev_t->t_ce_rdyz);
  723. gpmc_t->rd_cycle = gpmc_round_ps_to_ticks(temp);
  724. return 0;
  725. }
  726. static int gpmc_calc_sync_write_timings(struct gpmc_timings *gpmc_t,
  727. struct gpmc_device_timings *dev_t,
  728. bool mux)
  729. {
  730. u32 temp;
  731. /* adv_wr_off */
  732. temp = dev_t->t_avdp_w;
  733. if (mux) {
  734. temp = max_t(u32, temp,
  735. gpmc_t->clk_activation + dev_t->t_avdh);
  736. temp = max_t(u32, gpmc_t->adv_on + gpmc_ticks_to_ps(1), temp);
  737. }
  738. gpmc_t->adv_wr_off = gpmc_round_ps_to_ticks(temp);
  739. /* wr_data_mux_bus */
  740. temp = max_t(u32, dev_t->t_weasu,
  741. gpmc_t->clk_activation + dev_t->t_rdyo);
  742. /* XXX: shouldn't mux be kept as a whole for wr_data_mux_bus ?,
  743. * and in that case remember to handle we_on properly
  744. */
  745. if (mux) {
  746. temp = max_t(u32, temp,
  747. gpmc_t->adv_wr_off + dev_t->t_aavdh);
  748. temp = max_t(u32, temp, gpmc_t->adv_wr_off +
  749. gpmc_ticks_to_ps(dev_t->cyc_aavdh_we));
  750. }
  751. gpmc_t->wr_data_mux_bus = gpmc_round_ps_to_ticks(temp);
  752. /* we_on */
  753. if (gpmc_capability & GPMC_HAS_WR_DATA_MUX_BUS)
  754. gpmc_t->we_on = gpmc_round_ps_to_ticks(dev_t->t_weasu);
  755. else
  756. gpmc_t->we_on = gpmc_t->wr_data_mux_bus;
  757. /* wr_access */
  758. /* XXX: gpmc_capability check reqd ? , even if not, will not harm */
  759. gpmc_t->wr_access = gpmc_t->access;
  760. /* we_off */
  761. temp = gpmc_t->we_on + dev_t->t_wpl;
  762. temp = max_t(u32, temp,
  763. gpmc_t->wr_access + gpmc_ticks_to_ps(1));
  764. temp = max_t(u32, temp,
  765. gpmc_t->we_on + gpmc_ticks_to_ps(dev_t->cyc_wpl));
  766. gpmc_t->we_off = gpmc_round_ps_to_ticks(temp);
  767. gpmc_t->cs_wr_off = gpmc_round_ps_to_ticks(gpmc_t->we_off +
  768. dev_t->t_wph);
  769. /* wr_cycle */
  770. temp = gpmc_round_ps_to_sync_clk(dev_t->t_cez_w, gpmc_t->sync_clk);
  771. temp += gpmc_t->wr_access;
  772. /* XXX: barter t_ce_rdyz with t_cez_w ? */
  773. if (dev_t->t_ce_rdyz)
  774. temp = max_t(u32, temp,
  775. gpmc_t->cs_wr_off + dev_t->t_ce_rdyz);
  776. gpmc_t->wr_cycle = gpmc_round_ps_to_ticks(temp);
  777. return 0;
  778. }
  779. static int gpmc_calc_async_read_timings(struct gpmc_timings *gpmc_t,
  780. struct gpmc_device_timings *dev_t,
  781. bool mux)
  782. {
  783. u32 temp;
  784. /* adv_rd_off */
  785. temp = dev_t->t_avdp_r;
  786. if (mux)
  787. temp = max_t(u32, gpmc_t->adv_on + gpmc_ticks_to_ps(1), temp);
  788. gpmc_t->adv_rd_off = gpmc_round_ps_to_ticks(temp);
  789. /* oe_on */
  790. temp = dev_t->t_oeasu;
  791. if (mux)
  792. temp = max_t(u32, temp,
  793. gpmc_t->adv_rd_off + dev_t->t_aavdh);
  794. gpmc_t->oe_on = gpmc_round_ps_to_ticks(temp);
  795. /* access */
  796. temp = max_t(u32, dev_t->t_iaa, /* XXX: remove t_iaa in async ? */
  797. gpmc_t->oe_on + dev_t->t_oe);
  798. temp = max_t(u32, temp,
  799. gpmc_t->cs_on + dev_t->t_ce);
  800. temp = max_t(u32, temp,
  801. gpmc_t->adv_on + dev_t->t_aa);
  802. gpmc_t->access = gpmc_round_ps_to_ticks(temp);
  803. gpmc_t->oe_off = gpmc_t->access + gpmc_ticks_to_ps(1);
  804. gpmc_t->cs_rd_off = gpmc_t->oe_off;
  805. /* rd_cycle */
  806. temp = max_t(u32, dev_t->t_rd_cycle,
  807. gpmc_t->cs_rd_off + dev_t->t_cez_r);
  808. temp = max_t(u32, temp, gpmc_t->oe_off + dev_t->t_oez);
  809. gpmc_t->rd_cycle = gpmc_round_ps_to_ticks(temp);
  810. return 0;
  811. }
  812. static int gpmc_calc_async_write_timings(struct gpmc_timings *gpmc_t,
  813. struct gpmc_device_timings *dev_t,
  814. bool mux)
  815. {
  816. u32 temp;
  817. /* adv_wr_off */
  818. temp = dev_t->t_avdp_w;
  819. if (mux)
  820. temp = max_t(u32, gpmc_t->adv_on + gpmc_ticks_to_ps(1), temp);
  821. gpmc_t->adv_wr_off = gpmc_round_ps_to_ticks(temp);
  822. /* wr_data_mux_bus */
  823. temp = dev_t->t_weasu;
  824. if (mux) {
  825. temp = max_t(u32, temp, gpmc_t->adv_wr_off + dev_t->t_aavdh);
  826. temp = max_t(u32, temp, gpmc_t->adv_wr_off +
  827. gpmc_ticks_to_ps(dev_t->cyc_aavdh_we));
  828. }
  829. gpmc_t->wr_data_mux_bus = gpmc_round_ps_to_ticks(temp);
  830. /* we_on */
  831. if (gpmc_capability & GPMC_HAS_WR_DATA_MUX_BUS)
  832. gpmc_t->we_on = gpmc_round_ps_to_ticks(dev_t->t_weasu);
  833. else
  834. gpmc_t->we_on = gpmc_t->wr_data_mux_bus;
  835. /* we_off */
  836. temp = gpmc_t->we_on + dev_t->t_wpl;
  837. gpmc_t->we_off = gpmc_round_ps_to_ticks(temp);
  838. gpmc_t->cs_wr_off = gpmc_round_ps_to_ticks(gpmc_t->we_off +
  839. dev_t->t_wph);
  840. /* wr_cycle */
  841. temp = max_t(u32, dev_t->t_wr_cycle,
  842. gpmc_t->cs_wr_off + dev_t->t_cez_w);
  843. gpmc_t->wr_cycle = gpmc_round_ps_to_ticks(temp);
  844. return 0;
  845. }
  846. static int gpmc_calc_sync_common_timings(struct gpmc_timings *gpmc_t,
  847. struct gpmc_device_timings *dev_t)
  848. {
  849. u32 temp;
  850. gpmc_t->sync_clk = gpmc_calc_divider(dev_t->clk) *
  851. gpmc_get_fclk_period();
  852. gpmc_t->page_burst_access = gpmc_round_ps_to_sync_clk(
  853. dev_t->t_bacc,
  854. gpmc_t->sync_clk);
  855. temp = max_t(u32, dev_t->t_ces, dev_t->t_avds);
  856. gpmc_t->clk_activation = gpmc_round_ps_to_ticks(temp);
  857. if (gpmc_calc_divider(gpmc_t->sync_clk) != 1)
  858. return 0;
  859. if (dev_t->ce_xdelay)
  860. gpmc_t->bool_timings.cs_extra_delay = true;
  861. if (dev_t->avd_xdelay)
  862. gpmc_t->bool_timings.adv_extra_delay = true;
  863. if (dev_t->oe_xdelay)
  864. gpmc_t->bool_timings.oe_extra_delay = true;
  865. if (dev_t->we_xdelay)
  866. gpmc_t->bool_timings.we_extra_delay = true;
  867. return 0;
  868. }
  869. static int gpmc_calc_common_timings(struct gpmc_timings *gpmc_t,
  870. struct gpmc_device_timings *dev_t,
  871. bool sync)
  872. {
  873. u32 temp;
  874. /* cs_on */
  875. gpmc_t->cs_on = gpmc_round_ps_to_ticks(dev_t->t_ceasu);
  876. /* adv_on */
  877. temp = dev_t->t_avdasu;
  878. if (dev_t->t_ce_avd)
  879. temp = max_t(u32, temp,
  880. gpmc_t->cs_on + dev_t->t_ce_avd);
  881. gpmc_t->adv_on = gpmc_round_ps_to_ticks(temp);
  882. if (sync)
  883. gpmc_calc_sync_common_timings(gpmc_t, dev_t);
  884. return 0;
  885. }
  886. /* TODO: remove this function once all peripherals are confirmed to
  887. * work with generic timing. Simultaneously gpmc_cs_set_timings()
  888. * has to be modified to handle timings in ps instead of ns
  889. */
  890. static void gpmc_convert_ps_to_ns(struct gpmc_timings *t)
  891. {
  892. t->cs_on /= 1000;
  893. t->cs_rd_off /= 1000;
  894. t->cs_wr_off /= 1000;
  895. t->adv_on /= 1000;
  896. t->adv_rd_off /= 1000;
  897. t->adv_wr_off /= 1000;
  898. t->we_on /= 1000;
  899. t->we_off /= 1000;
  900. t->oe_on /= 1000;
  901. t->oe_off /= 1000;
  902. t->page_burst_access /= 1000;
  903. t->access /= 1000;
  904. t->rd_cycle /= 1000;
  905. t->wr_cycle /= 1000;
  906. t->bus_turnaround /= 1000;
  907. t->cycle2cycle_delay /= 1000;
  908. t->wait_monitoring /= 1000;
  909. t->clk_activation /= 1000;
  910. t->wr_access /= 1000;
  911. t->wr_data_mux_bus /= 1000;
  912. }
  913. int gpmc_calc_timings(struct gpmc_timings *gpmc_t,
  914. struct gpmc_settings *gpmc_s,
  915. struct gpmc_device_timings *dev_t)
  916. {
  917. bool mux = false, sync = false;
  918. if (gpmc_s) {
  919. mux = gpmc_s->mux_add_data ? true : false;
  920. sync = (gpmc_s->sync_read || gpmc_s->sync_write);
  921. }
  922. memset(gpmc_t, 0, sizeof(*gpmc_t));
  923. gpmc_calc_common_timings(gpmc_t, dev_t, sync);
  924. if (gpmc_s && gpmc_s->sync_read)
  925. gpmc_calc_sync_read_timings(gpmc_t, dev_t, mux);
  926. else
  927. gpmc_calc_async_read_timings(gpmc_t, dev_t, mux);
  928. if (gpmc_s && gpmc_s->sync_write)
  929. gpmc_calc_sync_write_timings(gpmc_t, dev_t, mux);
  930. else
  931. gpmc_calc_async_write_timings(gpmc_t, dev_t, mux);
  932. /* TODO: remove, see function definition */
  933. gpmc_convert_ps_to_ns(gpmc_t);
  934. return 0;
  935. }
  936. /**
  937. * gpmc_cs_program_settings - programs non-timing related settings
  938. * @cs: GPMC chip-select to program
  939. * @p: pointer to GPMC settings structure
  940. *
  941. * Programs non-timing related settings for a GPMC chip-select, such as
  942. * bus-width, burst configuration, etc. Function should be called once
  943. * for each chip-select that is being used and must be called before
  944. * calling gpmc_cs_set_timings() as timing parameters in the CONFIG1
  945. * register will be initialised to zero by this function. Returns 0 on
  946. * success and appropriate negative error code on failure.
  947. */
  948. int gpmc_cs_program_settings(int cs, struct gpmc_settings *p)
  949. {
  950. u32 config1;
  951. if ((!p->device_width) || (p->device_width > GPMC_DEVWIDTH_16BIT)) {
  952. pr_err("%s: invalid width %d!", __func__, p->device_width);
  953. return -EINVAL;
  954. }
  955. /* Address-data multiplexing not supported for NAND devices */
  956. if (p->device_nand && p->mux_add_data) {
  957. pr_err("%s: invalid configuration!\n", __func__);
  958. return -EINVAL;
  959. }
  960. if ((p->mux_add_data > GPMC_MUX_AD) ||
  961. ((p->mux_add_data == GPMC_MUX_AAD) &&
  962. !(gpmc_capability & GPMC_HAS_MUX_AAD))) {
  963. pr_err("%s: invalid multiplex configuration!\n", __func__);
  964. return -EINVAL;
  965. }
  966. /* Page/burst mode supports lengths of 4, 8 and 16 bytes */
  967. if (p->burst_read || p->burst_write) {
  968. switch (p->burst_len) {
  969. case GPMC_BURST_4:
  970. case GPMC_BURST_8:
  971. case GPMC_BURST_16:
  972. break;
  973. default:
  974. pr_err("%s: invalid page/burst-length (%d)\n",
  975. __func__, p->burst_len);
  976. return -EINVAL;
  977. }
  978. }
  979. if ((p->wait_on_read || p->wait_on_write) &&
  980. (p->wait_pin > gpmc_nr_waitpins)) {
  981. pr_err("%s: invalid wait-pin (%d)\n", __func__, p->wait_pin);
  982. return -EINVAL;
  983. }
  984. config1 = GPMC_CONFIG1_DEVICESIZE((p->device_width - 1));
  985. if (p->sync_read)
  986. config1 |= GPMC_CONFIG1_READTYPE_SYNC;
  987. if (p->sync_write)
  988. config1 |= GPMC_CONFIG1_WRITETYPE_SYNC;
  989. if (p->wait_on_read)
  990. config1 |= GPMC_CONFIG1_WAIT_READ_MON;
  991. if (p->wait_on_write)
  992. config1 |= GPMC_CONFIG1_WAIT_WRITE_MON;
  993. if (p->wait_on_read || p->wait_on_write)
  994. config1 |= GPMC_CONFIG1_WAIT_PIN_SEL(p->wait_pin);
  995. if (p->device_nand)
  996. config1 |= GPMC_CONFIG1_DEVICETYPE(GPMC_DEVICETYPE_NAND);
  997. if (p->mux_add_data)
  998. config1 |= GPMC_CONFIG1_MUXTYPE(p->mux_add_data);
  999. if (p->burst_read)
  1000. config1 |= GPMC_CONFIG1_READMULTIPLE_SUPP;
  1001. if (p->burst_write)
  1002. config1 |= GPMC_CONFIG1_WRITEMULTIPLE_SUPP;
  1003. if (p->burst_read || p->burst_write) {
  1004. config1 |= GPMC_CONFIG1_PAGE_LEN(p->burst_len >> 3);
  1005. config1 |= p->burst_wrap ? GPMC_CONFIG1_WRAPBURST_SUPP : 0;
  1006. }
  1007. gpmc_cs_write_reg(cs, GPMC_CS_CONFIG1, config1);
  1008. return 0;
  1009. }
  1010. #ifdef CONFIG_OF
  1011. static struct of_device_id gpmc_dt_ids[] = {
  1012. { .compatible = "ti,omap2420-gpmc" },
  1013. { .compatible = "ti,omap2430-gpmc" },
  1014. { .compatible = "ti,omap3430-gpmc" }, /* omap3430 & omap3630 */
  1015. { .compatible = "ti,omap4430-gpmc" }, /* omap4430 & omap4460 & omap543x */
  1016. { .compatible = "ti,am3352-gpmc" }, /* am335x devices */
  1017. { }
  1018. };
  1019. MODULE_DEVICE_TABLE(of, gpmc_dt_ids);
  1020. static void __maybe_unused gpmc_read_timings_dt(struct device_node *np,
  1021. struct gpmc_timings *gpmc_t)
  1022. {
  1023. u32 val;
  1024. memset(gpmc_t, 0, sizeof(*gpmc_t));
  1025. /* minimum clock period for syncronous mode */
  1026. if (!of_property_read_u32(np, "gpmc,sync-clk", &val))
  1027. gpmc_t->sync_clk = val;
  1028. /* chip select timtings */
  1029. if (!of_property_read_u32(np, "gpmc,cs-on", &val))
  1030. gpmc_t->cs_on = val;
  1031. if (!of_property_read_u32(np, "gpmc,cs-rd-off", &val))
  1032. gpmc_t->cs_rd_off = val;
  1033. if (!of_property_read_u32(np, "gpmc,cs-wr-off", &val))
  1034. gpmc_t->cs_wr_off = val;
  1035. /* ADV signal timings */
  1036. if (!of_property_read_u32(np, "gpmc,adv-on", &val))
  1037. gpmc_t->adv_on = val;
  1038. if (!of_property_read_u32(np, "gpmc,adv-rd-off", &val))
  1039. gpmc_t->adv_rd_off = val;
  1040. if (!of_property_read_u32(np, "gpmc,adv-wr-off", &val))
  1041. gpmc_t->adv_wr_off = val;
  1042. /* WE signal timings */
  1043. if (!of_property_read_u32(np, "gpmc,we-on", &val))
  1044. gpmc_t->we_on = val;
  1045. if (!of_property_read_u32(np, "gpmc,we-off", &val))
  1046. gpmc_t->we_off = val;
  1047. /* OE signal timings */
  1048. if (!of_property_read_u32(np, "gpmc,oe-on", &val))
  1049. gpmc_t->oe_on = val;
  1050. if (!of_property_read_u32(np, "gpmc,oe-off", &val))
  1051. gpmc_t->oe_off = val;
  1052. /* access and cycle timings */
  1053. if (!of_property_read_u32(np, "gpmc,page-burst-access", &val))
  1054. gpmc_t->page_burst_access = val;
  1055. if (!of_property_read_u32(np, "gpmc,access", &val))
  1056. gpmc_t->access = val;
  1057. if (!of_property_read_u32(np, "gpmc,rd-cycle", &val))
  1058. gpmc_t->rd_cycle = val;
  1059. if (!of_property_read_u32(np, "gpmc,wr-cycle", &val))
  1060. gpmc_t->wr_cycle = val;
  1061. /* only for OMAP3430 */
  1062. if (!of_property_read_u32(np, "gpmc,wr-access", &val))
  1063. gpmc_t->wr_access = val;
  1064. if (!of_property_read_u32(np, "gpmc,wr-data-mux-bus", &val))
  1065. gpmc_t->wr_data_mux_bus = val;
  1066. }
  1067. #ifdef CONFIG_MTD_NAND
  1068. static const char * const nand_ecc_opts[] = {
  1069. [OMAP_ECC_HAMMING_CODE_DEFAULT] = "sw",
  1070. [OMAP_ECC_HAMMING_CODE_HW] = "hw",
  1071. [OMAP_ECC_HAMMING_CODE_HW_ROMCODE] = "hw-romcode",
  1072. [OMAP_ECC_BCH4_CODE_HW] = "bch4",
  1073. [OMAP_ECC_BCH8_CODE_HW] = "bch8",
  1074. };
  1075. static int gpmc_probe_nand_child(struct platform_device *pdev,
  1076. struct device_node *child)
  1077. {
  1078. u32 val;
  1079. const char *s;
  1080. struct gpmc_timings gpmc_t;
  1081. struct omap_nand_platform_data *gpmc_nand_data;
  1082. if (of_property_read_u32(child, "reg", &val) < 0) {
  1083. dev_err(&pdev->dev, "%s has no 'reg' property\n",
  1084. child->full_name);
  1085. return -ENODEV;
  1086. }
  1087. gpmc_nand_data = devm_kzalloc(&pdev->dev, sizeof(*gpmc_nand_data),
  1088. GFP_KERNEL);
  1089. if (!gpmc_nand_data)
  1090. return -ENOMEM;
  1091. gpmc_nand_data->cs = val;
  1092. gpmc_nand_data->of_node = child;
  1093. if (!of_property_read_string(child, "ti,nand-ecc-opt", &s))
  1094. for (val = 0; val < ARRAY_SIZE(nand_ecc_opts); val++)
  1095. if (!strcasecmp(s, nand_ecc_opts[val])) {
  1096. gpmc_nand_data->ecc_opt = val;
  1097. break;
  1098. }
  1099. val = of_get_nand_bus_width(child);
  1100. if (val == 16)
  1101. gpmc_nand_data->devsize = NAND_BUSWIDTH_16;
  1102. gpmc_read_timings_dt(child, &gpmc_t);
  1103. gpmc_nand_init(gpmc_nand_data, &gpmc_t);
  1104. return 0;
  1105. }
  1106. #else
  1107. static int gpmc_probe_nand_child(struct platform_device *pdev,
  1108. struct device_node *child)
  1109. {
  1110. return 0;
  1111. }
  1112. #endif
  1113. #ifdef CONFIG_MTD_ONENAND
  1114. static int gpmc_probe_onenand_child(struct platform_device *pdev,
  1115. struct device_node *child)
  1116. {
  1117. u32 val;
  1118. struct omap_onenand_platform_data *gpmc_onenand_data;
  1119. if (of_property_read_u32(child, "reg", &val) < 0) {
  1120. dev_err(&pdev->dev, "%s has no 'reg' property\n",
  1121. child->full_name);
  1122. return -ENODEV;
  1123. }
  1124. gpmc_onenand_data = devm_kzalloc(&pdev->dev, sizeof(*gpmc_onenand_data),
  1125. GFP_KERNEL);
  1126. if (!gpmc_onenand_data)
  1127. return -ENOMEM;
  1128. gpmc_onenand_data->cs = val;
  1129. gpmc_onenand_data->of_node = child;
  1130. gpmc_onenand_data->dma_channel = -1;
  1131. if (!of_property_read_u32(child, "dma-channel", &val))
  1132. gpmc_onenand_data->dma_channel = val;
  1133. gpmc_onenand_init(gpmc_onenand_data);
  1134. return 0;
  1135. }
  1136. #else
  1137. static int gpmc_probe_onenand_child(struct platform_device *pdev,
  1138. struct device_node *child)
  1139. {
  1140. return 0;
  1141. }
  1142. #endif
  1143. static int gpmc_probe_dt(struct platform_device *pdev)
  1144. {
  1145. int ret;
  1146. struct device_node *child;
  1147. const struct of_device_id *of_id =
  1148. of_match_device(gpmc_dt_ids, &pdev->dev);
  1149. if (!of_id)
  1150. return 0;
  1151. ret = of_property_read_u32(pdev->dev.of_node, "gpmc,num-waitpins",
  1152. &gpmc_nr_waitpins);
  1153. if (ret < 0) {
  1154. pr_err("%s: number of wait pins not found!\n", __func__);
  1155. return ret;
  1156. }
  1157. for_each_node_by_name(child, "nand") {
  1158. ret = gpmc_probe_nand_child(pdev, child);
  1159. if (ret < 0) {
  1160. of_node_put(child);
  1161. return ret;
  1162. }
  1163. }
  1164. for_each_node_by_name(child, "onenand") {
  1165. ret = gpmc_probe_onenand_child(pdev, child);
  1166. if (ret < 0) {
  1167. of_node_put(child);
  1168. return ret;
  1169. }
  1170. }
  1171. return 0;
  1172. }
  1173. #else
  1174. static int gpmc_probe_dt(struct platform_device *pdev)
  1175. {
  1176. return 0;
  1177. }
  1178. #endif
  1179. static int gpmc_probe(struct platform_device *pdev)
  1180. {
  1181. int rc;
  1182. u32 l;
  1183. struct resource *res;
  1184. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1185. if (res == NULL)
  1186. return -ENOENT;
  1187. phys_base = res->start;
  1188. mem_size = resource_size(res);
  1189. gpmc_base = devm_ioremap_resource(&pdev->dev, res);
  1190. if (IS_ERR(gpmc_base))
  1191. return PTR_ERR(gpmc_base);
  1192. res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  1193. if (res == NULL)
  1194. dev_warn(&pdev->dev, "Failed to get resource: irq\n");
  1195. else
  1196. gpmc_irq = res->start;
  1197. gpmc_l3_clk = clk_get(&pdev->dev, "fck");
  1198. if (IS_ERR(gpmc_l3_clk)) {
  1199. dev_err(&pdev->dev, "error: clk_get\n");
  1200. gpmc_irq = 0;
  1201. return PTR_ERR(gpmc_l3_clk);
  1202. }
  1203. clk_prepare_enable(gpmc_l3_clk);
  1204. gpmc_dev = &pdev->dev;
  1205. l = gpmc_read_reg(GPMC_REVISION);
  1206. /*
  1207. * FIXME: Once device-tree migration is complete the below flags
  1208. * should be populated based upon the device-tree compatible
  1209. * string. For now just use the IP revision. OMAP3+ devices have
  1210. * the wr_access and wr_data_mux_bus register fields. OMAP4+
  1211. * devices support the addr-addr-data multiplex protocol.
  1212. *
  1213. * GPMC IP revisions:
  1214. * - OMAP24xx = 2.0
  1215. * - OMAP3xxx = 5.0
  1216. * - OMAP44xx/54xx/AM335x = 6.0
  1217. */
  1218. if (GPMC_REVISION_MAJOR(l) > 0x4)
  1219. gpmc_capability = GPMC_HAS_WR_ACCESS | GPMC_HAS_WR_DATA_MUX_BUS;
  1220. if (GPMC_REVISION_MAJOR(l) > 0x5)
  1221. gpmc_capability |= GPMC_HAS_MUX_AAD;
  1222. dev_info(gpmc_dev, "GPMC revision %d.%d\n", GPMC_REVISION_MAJOR(l),
  1223. GPMC_REVISION_MINOR(l));
  1224. rc = gpmc_mem_init();
  1225. if (rc < 0) {
  1226. clk_disable_unprepare(gpmc_l3_clk);
  1227. clk_put(gpmc_l3_clk);
  1228. dev_err(gpmc_dev, "failed to reserve memory\n");
  1229. return rc;
  1230. }
  1231. if (gpmc_setup_irq() < 0)
  1232. dev_warn(gpmc_dev, "gpmc_setup_irq failed\n");
  1233. /* Now the GPMC is initialised, unreserve the chip-selects */
  1234. gpmc_cs_map = 0;
  1235. if (!pdev->dev.of_node)
  1236. gpmc_nr_waitpins = GPMC_NR_WAITPINS;
  1237. rc = gpmc_probe_dt(pdev);
  1238. if (rc < 0) {
  1239. clk_disable_unprepare(gpmc_l3_clk);
  1240. clk_put(gpmc_l3_clk);
  1241. dev_err(gpmc_dev, "failed to probe DT parameters\n");
  1242. return rc;
  1243. }
  1244. return 0;
  1245. }
  1246. static int gpmc_remove(struct platform_device *pdev)
  1247. {
  1248. gpmc_free_irq();
  1249. gpmc_mem_exit();
  1250. gpmc_dev = NULL;
  1251. return 0;
  1252. }
  1253. static struct platform_driver gpmc_driver = {
  1254. .probe = gpmc_probe,
  1255. .remove = gpmc_remove,
  1256. .driver = {
  1257. .name = DEVICE_NAME,
  1258. .owner = THIS_MODULE,
  1259. .of_match_table = of_match_ptr(gpmc_dt_ids),
  1260. },
  1261. };
  1262. static __init int gpmc_init(void)
  1263. {
  1264. return platform_driver_register(&gpmc_driver);
  1265. }
  1266. static __exit void gpmc_exit(void)
  1267. {
  1268. platform_driver_unregister(&gpmc_driver);
  1269. }
  1270. omap_postcore_initcall(gpmc_init);
  1271. module_exit(gpmc_exit);
  1272. static int __init omap_gpmc_init(void)
  1273. {
  1274. struct omap_hwmod *oh;
  1275. struct platform_device *pdev;
  1276. char *oh_name = "gpmc";
  1277. /*
  1278. * if the board boots up with a populated DT, do not
  1279. * manually add the device from this initcall
  1280. */
  1281. if (of_have_populated_dt())
  1282. return -ENODEV;
  1283. oh = omap_hwmod_lookup(oh_name);
  1284. if (!oh) {
  1285. pr_err("Could not look up %s\n", oh_name);
  1286. return -ENODEV;
  1287. }
  1288. pdev = omap_device_build(DEVICE_NAME, -1, oh, NULL, 0);
  1289. WARN(IS_ERR(pdev), "could not build omap_device for %s\n", oh_name);
  1290. return IS_ERR(pdev) ? PTR_ERR(pdev) : 0;
  1291. }
  1292. omap_postcore_initcall(omap_gpmc_init);
  1293. static irqreturn_t gpmc_handle_irq(int irq, void *dev)
  1294. {
  1295. int i;
  1296. u32 regval;
  1297. regval = gpmc_read_reg(GPMC_IRQSTATUS);
  1298. if (!regval)
  1299. return IRQ_NONE;
  1300. for (i = 0; i < GPMC_NR_IRQ; i++)
  1301. if (regval & gpmc_client_irq[i].bitmask)
  1302. generic_handle_irq(gpmc_client_irq[i].irq);
  1303. gpmc_write_reg(GPMC_IRQSTATUS, regval);
  1304. return IRQ_HANDLED;
  1305. }
  1306. #ifdef CONFIG_ARCH_OMAP3
  1307. static struct omap3_gpmc_regs gpmc_context;
  1308. void omap3_gpmc_save_context(void)
  1309. {
  1310. int i;
  1311. gpmc_context.sysconfig = gpmc_read_reg(GPMC_SYSCONFIG);
  1312. gpmc_context.irqenable = gpmc_read_reg(GPMC_IRQENABLE);
  1313. gpmc_context.timeout_ctrl = gpmc_read_reg(GPMC_TIMEOUT_CONTROL);
  1314. gpmc_context.config = gpmc_read_reg(GPMC_CONFIG);
  1315. gpmc_context.prefetch_config1 = gpmc_read_reg(GPMC_PREFETCH_CONFIG1);
  1316. gpmc_context.prefetch_config2 = gpmc_read_reg(GPMC_PREFETCH_CONFIG2);
  1317. gpmc_context.prefetch_control = gpmc_read_reg(GPMC_PREFETCH_CONTROL);
  1318. for (i = 0; i < GPMC_CS_NUM; i++) {
  1319. gpmc_context.cs_context[i].is_valid = gpmc_cs_mem_enabled(i);
  1320. if (gpmc_context.cs_context[i].is_valid) {
  1321. gpmc_context.cs_context[i].config1 =
  1322. gpmc_cs_read_reg(i, GPMC_CS_CONFIG1);
  1323. gpmc_context.cs_context[i].config2 =
  1324. gpmc_cs_read_reg(i, GPMC_CS_CONFIG2);
  1325. gpmc_context.cs_context[i].config3 =
  1326. gpmc_cs_read_reg(i, GPMC_CS_CONFIG3);
  1327. gpmc_context.cs_context[i].config4 =
  1328. gpmc_cs_read_reg(i, GPMC_CS_CONFIG4);
  1329. gpmc_context.cs_context[i].config5 =
  1330. gpmc_cs_read_reg(i, GPMC_CS_CONFIG5);
  1331. gpmc_context.cs_context[i].config6 =
  1332. gpmc_cs_read_reg(i, GPMC_CS_CONFIG6);
  1333. gpmc_context.cs_context[i].config7 =
  1334. gpmc_cs_read_reg(i, GPMC_CS_CONFIG7);
  1335. }
  1336. }
  1337. }
  1338. void omap3_gpmc_restore_context(void)
  1339. {
  1340. int i;
  1341. gpmc_write_reg(GPMC_SYSCONFIG, gpmc_context.sysconfig);
  1342. gpmc_write_reg(GPMC_IRQENABLE, gpmc_context.irqenable);
  1343. gpmc_write_reg(GPMC_TIMEOUT_CONTROL, gpmc_context.timeout_ctrl);
  1344. gpmc_write_reg(GPMC_CONFIG, gpmc_context.config);
  1345. gpmc_write_reg(GPMC_PREFETCH_CONFIG1, gpmc_context.prefetch_config1);
  1346. gpmc_write_reg(GPMC_PREFETCH_CONFIG2, gpmc_context.prefetch_config2);
  1347. gpmc_write_reg(GPMC_PREFETCH_CONTROL, gpmc_context.prefetch_control);
  1348. for (i = 0; i < GPMC_CS_NUM; i++) {
  1349. if (gpmc_context.cs_context[i].is_valid) {
  1350. gpmc_cs_write_reg(i, GPMC_CS_CONFIG1,
  1351. gpmc_context.cs_context[i].config1);
  1352. gpmc_cs_write_reg(i, GPMC_CS_CONFIG2,
  1353. gpmc_context.cs_context[i].config2);
  1354. gpmc_cs_write_reg(i, GPMC_CS_CONFIG3,
  1355. gpmc_context.cs_context[i].config3);
  1356. gpmc_cs_write_reg(i, GPMC_CS_CONFIG4,
  1357. gpmc_context.cs_context[i].config4);
  1358. gpmc_cs_write_reg(i, GPMC_CS_CONFIG5,
  1359. gpmc_context.cs_context[i].config5);
  1360. gpmc_cs_write_reg(i, GPMC_CS_CONFIG6,
  1361. gpmc_context.cs_context[i].config6);
  1362. gpmc_cs_write_reg(i, GPMC_CS_CONFIG7,
  1363. gpmc_context.cs_context[i].config7);
  1364. }
  1365. }
  1366. }
  1367. #endif /* CONFIG_ARCH_OMAP3 */