gpmc.c 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655
  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_configure - write request to configure gpmc
  462. * @cmd: command type
  463. * @wval: value to write
  464. * @return status of the operation
  465. */
  466. int gpmc_configure(int cmd, int wval)
  467. {
  468. u32 regval;
  469. switch (cmd) {
  470. case GPMC_ENABLE_IRQ:
  471. gpmc_write_reg(GPMC_IRQENABLE, wval);
  472. break;
  473. case GPMC_SET_IRQ_STATUS:
  474. gpmc_write_reg(GPMC_IRQSTATUS, wval);
  475. break;
  476. case GPMC_CONFIG_WP:
  477. regval = gpmc_read_reg(GPMC_CONFIG);
  478. if (wval)
  479. regval &= ~GPMC_CONFIG_WRITEPROTECT; /* WP is ON */
  480. else
  481. regval |= GPMC_CONFIG_WRITEPROTECT; /* WP is OFF */
  482. gpmc_write_reg(GPMC_CONFIG, regval);
  483. break;
  484. default:
  485. pr_err("%s: command not supported\n", __func__);
  486. return -EINVAL;
  487. }
  488. return 0;
  489. }
  490. EXPORT_SYMBOL(gpmc_configure);
  491. void gpmc_update_nand_reg(struct gpmc_nand_regs *reg, int cs)
  492. {
  493. int i;
  494. reg->gpmc_status = gpmc_base + GPMC_STATUS;
  495. reg->gpmc_nand_command = gpmc_base + GPMC_CS0_OFFSET +
  496. GPMC_CS_NAND_COMMAND + GPMC_CS_SIZE * cs;
  497. reg->gpmc_nand_address = gpmc_base + GPMC_CS0_OFFSET +
  498. GPMC_CS_NAND_ADDRESS + GPMC_CS_SIZE * cs;
  499. reg->gpmc_nand_data = gpmc_base + GPMC_CS0_OFFSET +
  500. GPMC_CS_NAND_DATA + GPMC_CS_SIZE * cs;
  501. reg->gpmc_prefetch_config1 = gpmc_base + GPMC_PREFETCH_CONFIG1;
  502. reg->gpmc_prefetch_config2 = gpmc_base + GPMC_PREFETCH_CONFIG2;
  503. reg->gpmc_prefetch_control = gpmc_base + GPMC_PREFETCH_CONTROL;
  504. reg->gpmc_prefetch_status = gpmc_base + GPMC_PREFETCH_STATUS;
  505. reg->gpmc_ecc_config = gpmc_base + GPMC_ECC_CONFIG;
  506. reg->gpmc_ecc_control = gpmc_base + GPMC_ECC_CONTROL;
  507. reg->gpmc_ecc_size_config = gpmc_base + GPMC_ECC_SIZE_CONFIG;
  508. reg->gpmc_ecc1_result = gpmc_base + GPMC_ECC1_RESULT;
  509. for (i = 0; i < GPMC_BCH_NUM_REMAINDER; i++) {
  510. reg->gpmc_bch_result0[i] = gpmc_base + GPMC_ECC_BCH_RESULT_0 +
  511. GPMC_BCH_SIZE * i;
  512. reg->gpmc_bch_result1[i] = gpmc_base + GPMC_ECC_BCH_RESULT_1 +
  513. GPMC_BCH_SIZE * i;
  514. reg->gpmc_bch_result2[i] = gpmc_base + GPMC_ECC_BCH_RESULT_2 +
  515. GPMC_BCH_SIZE * i;
  516. reg->gpmc_bch_result3[i] = gpmc_base + GPMC_ECC_BCH_RESULT_3 +
  517. GPMC_BCH_SIZE * i;
  518. }
  519. }
  520. int gpmc_get_client_irq(unsigned irq_config)
  521. {
  522. int i;
  523. if (hweight32(irq_config) > 1)
  524. return 0;
  525. for (i = 0; i < GPMC_NR_IRQ; i++)
  526. if (gpmc_client_irq[i].bitmask & irq_config)
  527. return gpmc_client_irq[i].irq;
  528. return 0;
  529. }
  530. static int gpmc_irq_endis(unsigned irq, bool endis)
  531. {
  532. int i;
  533. u32 regval;
  534. for (i = 0; i < GPMC_NR_IRQ; i++)
  535. if (irq == gpmc_client_irq[i].irq) {
  536. regval = gpmc_read_reg(GPMC_IRQENABLE);
  537. if (endis)
  538. regval |= gpmc_client_irq[i].bitmask;
  539. else
  540. regval &= ~gpmc_client_irq[i].bitmask;
  541. gpmc_write_reg(GPMC_IRQENABLE, regval);
  542. break;
  543. }
  544. return 0;
  545. }
  546. static void gpmc_irq_disable(struct irq_data *p)
  547. {
  548. gpmc_irq_endis(p->irq, false);
  549. }
  550. static void gpmc_irq_enable(struct irq_data *p)
  551. {
  552. gpmc_irq_endis(p->irq, true);
  553. }
  554. static void gpmc_irq_noop(struct irq_data *data) { }
  555. static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
  556. static int gpmc_setup_irq(void)
  557. {
  558. int i;
  559. u32 regval;
  560. if (!gpmc_irq)
  561. return -EINVAL;
  562. gpmc_irq_start = irq_alloc_descs(-1, 0, GPMC_NR_IRQ, 0);
  563. if (gpmc_irq_start < 0) {
  564. pr_err("irq_alloc_descs failed\n");
  565. return gpmc_irq_start;
  566. }
  567. gpmc_irq_chip.name = "gpmc";
  568. gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
  569. gpmc_irq_chip.irq_enable = gpmc_irq_enable;
  570. gpmc_irq_chip.irq_disable = gpmc_irq_disable;
  571. gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
  572. gpmc_irq_chip.irq_ack = gpmc_irq_noop;
  573. gpmc_irq_chip.irq_mask = gpmc_irq_noop;
  574. gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
  575. gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
  576. gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
  577. for (i = 0; i < GPMC_NR_IRQ; i++) {
  578. gpmc_client_irq[i].irq = gpmc_irq_start + i;
  579. irq_set_chip_and_handler(gpmc_client_irq[i].irq,
  580. &gpmc_irq_chip, handle_simple_irq);
  581. set_irq_flags(gpmc_client_irq[i].irq,
  582. IRQF_VALID | IRQF_NOAUTOEN);
  583. }
  584. /* Disable interrupts */
  585. gpmc_write_reg(GPMC_IRQENABLE, 0);
  586. /* clear interrupts */
  587. regval = gpmc_read_reg(GPMC_IRQSTATUS);
  588. gpmc_write_reg(GPMC_IRQSTATUS, regval);
  589. return request_irq(gpmc_irq, gpmc_handle_irq, 0, "gpmc", NULL);
  590. }
  591. static int gpmc_free_irq(void)
  592. {
  593. int i;
  594. if (gpmc_irq)
  595. free_irq(gpmc_irq, NULL);
  596. for (i = 0; i < GPMC_NR_IRQ; i++) {
  597. irq_set_handler(gpmc_client_irq[i].irq, NULL);
  598. irq_set_chip(gpmc_client_irq[i].irq, &no_irq_chip);
  599. irq_modify_status(gpmc_client_irq[i].irq, 0, 0);
  600. }
  601. irq_free_descs(gpmc_irq_start, GPMC_NR_IRQ);
  602. return 0;
  603. }
  604. static void gpmc_mem_exit(void)
  605. {
  606. int cs;
  607. for (cs = 0; cs < GPMC_CS_NUM; cs++) {
  608. if (!gpmc_cs_mem_enabled(cs))
  609. continue;
  610. gpmc_cs_delete_mem(cs);
  611. }
  612. }
  613. static int gpmc_mem_init(void)
  614. {
  615. int cs, rc;
  616. unsigned long boot_rom_space = 0;
  617. /* never allocate the first page, to facilitate bug detection;
  618. * even if we didn't boot from ROM.
  619. */
  620. boot_rom_space = BOOT_ROM_SPACE;
  621. gpmc_mem_root.start = GPMC_MEM_START + boot_rom_space;
  622. gpmc_mem_root.end = GPMC_MEM_END;
  623. /* Reserve all regions that has been set up by bootloader */
  624. for (cs = 0; cs < GPMC_CS_NUM; cs++) {
  625. u32 base, size;
  626. if (!gpmc_cs_mem_enabled(cs))
  627. continue;
  628. gpmc_cs_get_memconf(cs, &base, &size);
  629. rc = gpmc_cs_insert_mem(cs, base, size);
  630. if (rc < 0) {
  631. while (--cs >= 0)
  632. if (gpmc_cs_mem_enabled(cs))
  633. gpmc_cs_delete_mem(cs);
  634. return rc;
  635. }
  636. }
  637. return 0;
  638. }
  639. static u32 gpmc_round_ps_to_sync_clk(u32 time_ps, u32 sync_clk)
  640. {
  641. u32 temp;
  642. int div;
  643. div = gpmc_calc_divider(sync_clk);
  644. temp = gpmc_ps_to_ticks(time_ps);
  645. temp = (temp + div - 1) / div;
  646. return gpmc_ticks_to_ps(temp * div);
  647. }
  648. /* XXX: can the cycles be avoided ? */
  649. static int gpmc_calc_sync_read_timings(struct gpmc_timings *gpmc_t,
  650. struct gpmc_device_timings *dev_t,
  651. bool mux)
  652. {
  653. u32 temp;
  654. /* adv_rd_off */
  655. temp = dev_t->t_avdp_r;
  656. /* XXX: mux check required ? */
  657. if (mux) {
  658. /* XXX: t_avdp not to be required for sync, only added for tusb
  659. * this indirectly necessitates requirement of t_avdp_r and
  660. * t_avdp_w instead of having a single t_avdp
  661. */
  662. temp = max_t(u32, temp, gpmc_t->clk_activation + dev_t->t_avdh);
  663. temp = max_t(u32, gpmc_t->adv_on + gpmc_ticks_to_ps(1), temp);
  664. }
  665. gpmc_t->adv_rd_off = gpmc_round_ps_to_ticks(temp);
  666. /* oe_on */
  667. temp = dev_t->t_oeasu; /* XXX: remove this ? */
  668. if (mux) {
  669. temp = max_t(u32, temp, gpmc_t->clk_activation + dev_t->t_ach);
  670. temp = max_t(u32, temp, gpmc_t->adv_rd_off +
  671. gpmc_ticks_to_ps(dev_t->cyc_aavdh_oe));
  672. }
  673. gpmc_t->oe_on = gpmc_round_ps_to_ticks(temp);
  674. /* access */
  675. /* XXX: any scope for improvement ?, by combining oe_on
  676. * and clk_activation, need to check whether
  677. * access = clk_activation + round to sync clk ?
  678. */
  679. temp = max_t(u32, dev_t->t_iaa, dev_t->cyc_iaa * gpmc_t->sync_clk);
  680. temp += gpmc_t->clk_activation;
  681. if (dev_t->cyc_oe)
  682. temp = max_t(u32, temp, gpmc_t->oe_on +
  683. gpmc_ticks_to_ps(dev_t->cyc_oe));
  684. gpmc_t->access = gpmc_round_ps_to_ticks(temp);
  685. gpmc_t->oe_off = gpmc_t->access + gpmc_ticks_to_ps(1);
  686. gpmc_t->cs_rd_off = gpmc_t->oe_off;
  687. /* rd_cycle */
  688. temp = max_t(u32, dev_t->t_cez_r, dev_t->t_oez);
  689. temp = gpmc_round_ps_to_sync_clk(temp, gpmc_t->sync_clk) +
  690. gpmc_t->access;
  691. /* XXX: barter t_ce_rdyz with t_cez_r ? */
  692. if (dev_t->t_ce_rdyz)
  693. temp = max_t(u32, temp, gpmc_t->cs_rd_off + dev_t->t_ce_rdyz);
  694. gpmc_t->rd_cycle = gpmc_round_ps_to_ticks(temp);
  695. return 0;
  696. }
  697. static int gpmc_calc_sync_write_timings(struct gpmc_timings *gpmc_t,
  698. struct gpmc_device_timings *dev_t,
  699. bool mux)
  700. {
  701. u32 temp;
  702. /* adv_wr_off */
  703. temp = dev_t->t_avdp_w;
  704. if (mux) {
  705. temp = max_t(u32, temp,
  706. gpmc_t->clk_activation + dev_t->t_avdh);
  707. temp = max_t(u32, gpmc_t->adv_on + gpmc_ticks_to_ps(1), temp);
  708. }
  709. gpmc_t->adv_wr_off = gpmc_round_ps_to_ticks(temp);
  710. /* wr_data_mux_bus */
  711. temp = max_t(u32, dev_t->t_weasu,
  712. gpmc_t->clk_activation + dev_t->t_rdyo);
  713. /* XXX: shouldn't mux be kept as a whole for wr_data_mux_bus ?,
  714. * and in that case remember to handle we_on properly
  715. */
  716. if (mux) {
  717. temp = max_t(u32, temp,
  718. gpmc_t->adv_wr_off + dev_t->t_aavdh);
  719. temp = max_t(u32, temp, gpmc_t->adv_wr_off +
  720. gpmc_ticks_to_ps(dev_t->cyc_aavdh_we));
  721. }
  722. gpmc_t->wr_data_mux_bus = gpmc_round_ps_to_ticks(temp);
  723. /* we_on */
  724. if (gpmc_capability & GPMC_HAS_WR_DATA_MUX_BUS)
  725. gpmc_t->we_on = gpmc_round_ps_to_ticks(dev_t->t_weasu);
  726. else
  727. gpmc_t->we_on = gpmc_t->wr_data_mux_bus;
  728. /* wr_access */
  729. /* XXX: gpmc_capability check reqd ? , even if not, will not harm */
  730. gpmc_t->wr_access = gpmc_t->access;
  731. /* we_off */
  732. temp = gpmc_t->we_on + dev_t->t_wpl;
  733. temp = max_t(u32, temp,
  734. gpmc_t->wr_access + gpmc_ticks_to_ps(1));
  735. temp = max_t(u32, temp,
  736. gpmc_t->we_on + gpmc_ticks_to_ps(dev_t->cyc_wpl));
  737. gpmc_t->we_off = gpmc_round_ps_to_ticks(temp);
  738. gpmc_t->cs_wr_off = gpmc_round_ps_to_ticks(gpmc_t->we_off +
  739. dev_t->t_wph);
  740. /* wr_cycle */
  741. temp = gpmc_round_ps_to_sync_clk(dev_t->t_cez_w, gpmc_t->sync_clk);
  742. temp += gpmc_t->wr_access;
  743. /* XXX: barter t_ce_rdyz with t_cez_w ? */
  744. if (dev_t->t_ce_rdyz)
  745. temp = max_t(u32, temp,
  746. gpmc_t->cs_wr_off + dev_t->t_ce_rdyz);
  747. gpmc_t->wr_cycle = gpmc_round_ps_to_ticks(temp);
  748. return 0;
  749. }
  750. static int gpmc_calc_async_read_timings(struct gpmc_timings *gpmc_t,
  751. struct gpmc_device_timings *dev_t,
  752. bool mux)
  753. {
  754. u32 temp;
  755. /* adv_rd_off */
  756. temp = dev_t->t_avdp_r;
  757. if (mux)
  758. temp = max_t(u32, gpmc_t->adv_on + gpmc_ticks_to_ps(1), temp);
  759. gpmc_t->adv_rd_off = gpmc_round_ps_to_ticks(temp);
  760. /* oe_on */
  761. temp = dev_t->t_oeasu;
  762. if (mux)
  763. temp = max_t(u32, temp,
  764. gpmc_t->adv_rd_off + dev_t->t_aavdh);
  765. gpmc_t->oe_on = gpmc_round_ps_to_ticks(temp);
  766. /* access */
  767. temp = max_t(u32, dev_t->t_iaa, /* XXX: remove t_iaa in async ? */
  768. gpmc_t->oe_on + dev_t->t_oe);
  769. temp = max_t(u32, temp,
  770. gpmc_t->cs_on + dev_t->t_ce);
  771. temp = max_t(u32, temp,
  772. gpmc_t->adv_on + dev_t->t_aa);
  773. gpmc_t->access = gpmc_round_ps_to_ticks(temp);
  774. gpmc_t->oe_off = gpmc_t->access + gpmc_ticks_to_ps(1);
  775. gpmc_t->cs_rd_off = gpmc_t->oe_off;
  776. /* rd_cycle */
  777. temp = max_t(u32, dev_t->t_rd_cycle,
  778. gpmc_t->cs_rd_off + dev_t->t_cez_r);
  779. temp = max_t(u32, temp, gpmc_t->oe_off + dev_t->t_oez);
  780. gpmc_t->rd_cycle = gpmc_round_ps_to_ticks(temp);
  781. return 0;
  782. }
  783. static int gpmc_calc_async_write_timings(struct gpmc_timings *gpmc_t,
  784. struct gpmc_device_timings *dev_t,
  785. bool mux)
  786. {
  787. u32 temp;
  788. /* adv_wr_off */
  789. temp = dev_t->t_avdp_w;
  790. if (mux)
  791. temp = max_t(u32, gpmc_t->adv_on + gpmc_ticks_to_ps(1), temp);
  792. gpmc_t->adv_wr_off = gpmc_round_ps_to_ticks(temp);
  793. /* wr_data_mux_bus */
  794. temp = dev_t->t_weasu;
  795. if (mux) {
  796. temp = max_t(u32, temp, gpmc_t->adv_wr_off + dev_t->t_aavdh);
  797. temp = max_t(u32, temp, gpmc_t->adv_wr_off +
  798. gpmc_ticks_to_ps(dev_t->cyc_aavdh_we));
  799. }
  800. gpmc_t->wr_data_mux_bus = gpmc_round_ps_to_ticks(temp);
  801. /* we_on */
  802. if (gpmc_capability & GPMC_HAS_WR_DATA_MUX_BUS)
  803. gpmc_t->we_on = gpmc_round_ps_to_ticks(dev_t->t_weasu);
  804. else
  805. gpmc_t->we_on = gpmc_t->wr_data_mux_bus;
  806. /* we_off */
  807. temp = gpmc_t->we_on + dev_t->t_wpl;
  808. gpmc_t->we_off = gpmc_round_ps_to_ticks(temp);
  809. gpmc_t->cs_wr_off = gpmc_round_ps_to_ticks(gpmc_t->we_off +
  810. dev_t->t_wph);
  811. /* wr_cycle */
  812. temp = max_t(u32, dev_t->t_wr_cycle,
  813. gpmc_t->cs_wr_off + dev_t->t_cez_w);
  814. gpmc_t->wr_cycle = gpmc_round_ps_to_ticks(temp);
  815. return 0;
  816. }
  817. static int gpmc_calc_sync_common_timings(struct gpmc_timings *gpmc_t,
  818. struct gpmc_device_timings *dev_t)
  819. {
  820. u32 temp;
  821. gpmc_t->sync_clk = gpmc_calc_divider(dev_t->clk) *
  822. gpmc_get_fclk_period();
  823. gpmc_t->page_burst_access = gpmc_round_ps_to_sync_clk(
  824. dev_t->t_bacc,
  825. gpmc_t->sync_clk);
  826. temp = max_t(u32, dev_t->t_ces, dev_t->t_avds);
  827. gpmc_t->clk_activation = gpmc_round_ps_to_ticks(temp);
  828. if (gpmc_calc_divider(gpmc_t->sync_clk) != 1)
  829. return 0;
  830. if (dev_t->ce_xdelay)
  831. gpmc_t->bool_timings.cs_extra_delay = true;
  832. if (dev_t->avd_xdelay)
  833. gpmc_t->bool_timings.adv_extra_delay = true;
  834. if (dev_t->oe_xdelay)
  835. gpmc_t->bool_timings.oe_extra_delay = true;
  836. if (dev_t->we_xdelay)
  837. gpmc_t->bool_timings.we_extra_delay = true;
  838. return 0;
  839. }
  840. static int gpmc_calc_common_timings(struct gpmc_timings *gpmc_t,
  841. struct gpmc_device_timings *dev_t,
  842. bool sync)
  843. {
  844. u32 temp;
  845. /* cs_on */
  846. gpmc_t->cs_on = gpmc_round_ps_to_ticks(dev_t->t_ceasu);
  847. /* adv_on */
  848. temp = dev_t->t_avdasu;
  849. if (dev_t->t_ce_avd)
  850. temp = max_t(u32, temp,
  851. gpmc_t->cs_on + dev_t->t_ce_avd);
  852. gpmc_t->adv_on = gpmc_round_ps_to_ticks(temp);
  853. if (sync)
  854. gpmc_calc_sync_common_timings(gpmc_t, dev_t);
  855. return 0;
  856. }
  857. /* TODO: remove this function once all peripherals are confirmed to
  858. * work with generic timing. Simultaneously gpmc_cs_set_timings()
  859. * has to be modified to handle timings in ps instead of ns
  860. */
  861. static void gpmc_convert_ps_to_ns(struct gpmc_timings *t)
  862. {
  863. t->cs_on /= 1000;
  864. t->cs_rd_off /= 1000;
  865. t->cs_wr_off /= 1000;
  866. t->adv_on /= 1000;
  867. t->adv_rd_off /= 1000;
  868. t->adv_wr_off /= 1000;
  869. t->we_on /= 1000;
  870. t->we_off /= 1000;
  871. t->oe_on /= 1000;
  872. t->oe_off /= 1000;
  873. t->page_burst_access /= 1000;
  874. t->access /= 1000;
  875. t->rd_cycle /= 1000;
  876. t->wr_cycle /= 1000;
  877. t->bus_turnaround /= 1000;
  878. t->cycle2cycle_delay /= 1000;
  879. t->wait_monitoring /= 1000;
  880. t->clk_activation /= 1000;
  881. t->wr_access /= 1000;
  882. t->wr_data_mux_bus /= 1000;
  883. }
  884. int gpmc_calc_timings(struct gpmc_timings *gpmc_t,
  885. struct gpmc_settings *gpmc_s,
  886. struct gpmc_device_timings *dev_t)
  887. {
  888. bool mux = false, sync = false;
  889. if (gpmc_s) {
  890. mux = gpmc_s->mux_add_data ? true : false;
  891. sync = (gpmc_s->sync_read || gpmc_s->sync_write);
  892. }
  893. memset(gpmc_t, 0, sizeof(*gpmc_t));
  894. gpmc_calc_common_timings(gpmc_t, dev_t, sync);
  895. if (gpmc_s && gpmc_s->sync_read)
  896. gpmc_calc_sync_read_timings(gpmc_t, dev_t, mux);
  897. else
  898. gpmc_calc_async_read_timings(gpmc_t, dev_t, mux);
  899. if (gpmc_s && gpmc_s->sync_write)
  900. gpmc_calc_sync_write_timings(gpmc_t, dev_t, mux);
  901. else
  902. gpmc_calc_async_write_timings(gpmc_t, dev_t, mux);
  903. /* TODO: remove, see function definition */
  904. gpmc_convert_ps_to_ns(gpmc_t);
  905. return 0;
  906. }
  907. /**
  908. * gpmc_cs_program_settings - programs non-timing related settings
  909. * @cs: GPMC chip-select to program
  910. * @p: pointer to GPMC settings structure
  911. *
  912. * Programs non-timing related settings for a GPMC chip-select, such as
  913. * bus-width, burst configuration, etc. Function should be called once
  914. * for each chip-select that is being used and must be called before
  915. * calling gpmc_cs_set_timings() as timing parameters in the CONFIG1
  916. * register will be initialised to zero by this function. Returns 0 on
  917. * success and appropriate negative error code on failure.
  918. */
  919. int gpmc_cs_program_settings(int cs, struct gpmc_settings *p)
  920. {
  921. u32 config1;
  922. if ((!p->device_width) || (p->device_width > GPMC_DEVWIDTH_16BIT)) {
  923. pr_err("%s: invalid width %d!", __func__, p->device_width);
  924. return -EINVAL;
  925. }
  926. /* Address-data multiplexing not supported for NAND devices */
  927. if (p->device_nand && p->mux_add_data) {
  928. pr_err("%s: invalid configuration!\n", __func__);
  929. return -EINVAL;
  930. }
  931. if ((p->mux_add_data > GPMC_MUX_AD) ||
  932. ((p->mux_add_data == GPMC_MUX_AAD) &&
  933. !(gpmc_capability & GPMC_HAS_MUX_AAD))) {
  934. pr_err("%s: invalid multiplex configuration!\n", __func__);
  935. return -EINVAL;
  936. }
  937. /* Page/burst mode supports lengths of 4, 8 and 16 bytes */
  938. if (p->burst_read || p->burst_write) {
  939. switch (p->burst_len) {
  940. case GPMC_BURST_4:
  941. case GPMC_BURST_8:
  942. case GPMC_BURST_16:
  943. break;
  944. default:
  945. pr_err("%s: invalid page/burst-length (%d)\n",
  946. __func__, p->burst_len);
  947. return -EINVAL;
  948. }
  949. }
  950. if ((p->wait_on_read || p->wait_on_write) &&
  951. (p->wait_pin > gpmc_nr_waitpins)) {
  952. pr_err("%s: invalid wait-pin (%d)\n", __func__, p->wait_pin);
  953. return -EINVAL;
  954. }
  955. config1 = GPMC_CONFIG1_DEVICESIZE((p->device_width - 1));
  956. if (p->sync_read)
  957. config1 |= GPMC_CONFIG1_READTYPE_SYNC;
  958. if (p->sync_write)
  959. config1 |= GPMC_CONFIG1_WRITETYPE_SYNC;
  960. if (p->wait_on_read)
  961. config1 |= GPMC_CONFIG1_WAIT_READ_MON;
  962. if (p->wait_on_write)
  963. config1 |= GPMC_CONFIG1_WAIT_WRITE_MON;
  964. if (p->wait_on_read || p->wait_on_write)
  965. config1 |= GPMC_CONFIG1_WAIT_PIN_SEL(p->wait_pin);
  966. if (p->device_nand)
  967. config1 |= GPMC_CONFIG1_DEVICETYPE(GPMC_DEVICETYPE_NAND);
  968. if (p->mux_add_data)
  969. config1 |= GPMC_CONFIG1_MUXTYPE(p->mux_add_data);
  970. if (p->burst_read)
  971. config1 |= GPMC_CONFIG1_READMULTIPLE_SUPP;
  972. if (p->burst_write)
  973. config1 |= GPMC_CONFIG1_WRITEMULTIPLE_SUPP;
  974. if (p->burst_read || p->burst_write) {
  975. config1 |= GPMC_CONFIG1_PAGE_LEN(p->burst_len >> 3);
  976. config1 |= p->burst_wrap ? GPMC_CONFIG1_WRAPBURST_SUPP : 0;
  977. }
  978. gpmc_cs_write_reg(cs, GPMC_CS_CONFIG1, config1);
  979. return 0;
  980. }
  981. #ifdef CONFIG_OF
  982. static struct of_device_id gpmc_dt_ids[] = {
  983. { .compatible = "ti,omap2420-gpmc" },
  984. { .compatible = "ti,omap2430-gpmc" },
  985. { .compatible = "ti,omap3430-gpmc" }, /* omap3430 & omap3630 */
  986. { .compatible = "ti,omap4430-gpmc" }, /* omap4430 & omap4460 & omap543x */
  987. { .compatible = "ti,am3352-gpmc" }, /* am335x devices */
  988. { }
  989. };
  990. MODULE_DEVICE_TABLE(of, gpmc_dt_ids);
  991. /**
  992. * gpmc_read_settings_dt - read gpmc settings from device-tree
  993. * @np: pointer to device-tree node for a gpmc child device
  994. * @p: pointer to gpmc settings structure
  995. *
  996. * Reads the GPMC settings for a GPMC child device from device-tree and
  997. * stores them in the GPMC settings structure passed. The GPMC settings
  998. * structure is initialised to zero by this function and so any
  999. * previously stored settings will be cleared.
  1000. */
  1001. void gpmc_read_settings_dt(struct device_node *np, struct gpmc_settings *p)
  1002. {
  1003. memset(p, 0, sizeof(struct gpmc_settings));
  1004. p->sync_read = of_property_read_bool(np, "gpmc,sync-read");
  1005. p->sync_write = of_property_read_bool(np, "gpmc,sync-write");
  1006. p->device_nand = of_property_read_bool(np, "gpmc,device-nand");
  1007. of_property_read_u32(np, "gpmc,device-width", &p->device_width);
  1008. of_property_read_u32(np, "gpmc,mux-add-data", &p->mux_add_data);
  1009. if (!of_property_read_u32(np, "gpmc,burst-length", &p->burst_len)) {
  1010. p->burst_wrap = of_property_read_bool(np, "gpmc,burst-wrap");
  1011. p->burst_read = of_property_read_bool(np, "gpmc,burst-read");
  1012. p->burst_write = of_property_read_bool(np, "gpmc,burst-write");
  1013. if (!p->burst_read && !p->burst_write)
  1014. pr_warn("%s: page/burst-length set but not used!\n",
  1015. __func__);
  1016. }
  1017. if (!of_property_read_u32(np, "gpmc,wait-pin", &p->wait_pin)) {
  1018. p->wait_on_read = of_property_read_bool(np,
  1019. "gpmc,wait-on-read");
  1020. p->wait_on_write = of_property_read_bool(np,
  1021. "gpmc,wait-on-write");
  1022. if (!p->wait_on_read && !p->wait_on_write)
  1023. pr_warn("%s: read/write wait monitoring not enabled!\n",
  1024. __func__);
  1025. }
  1026. }
  1027. static void __maybe_unused gpmc_read_timings_dt(struct device_node *np,
  1028. struct gpmc_timings *gpmc_t)
  1029. {
  1030. struct gpmc_bool_timings *p;
  1031. if (!np || !gpmc_t)
  1032. return;
  1033. memset(gpmc_t, 0, sizeof(*gpmc_t));
  1034. /* minimum clock period for syncronous mode */
  1035. of_property_read_u32(np, "gpmc,sync-clk-ps", &gpmc_t->sync_clk);
  1036. /* chip select timtings */
  1037. of_property_read_u32(np, "gpmc,cs-on-ns", &gpmc_t->cs_on);
  1038. of_property_read_u32(np, "gpmc,cs-rd-off-ns", &gpmc_t->cs_rd_off);
  1039. of_property_read_u32(np, "gpmc,cs-wr-off-ns", &gpmc_t->cs_wr_off);
  1040. /* ADV signal timings */
  1041. of_property_read_u32(np, "gpmc,adv-on-ns", &gpmc_t->adv_on);
  1042. of_property_read_u32(np, "gpmc,adv-rd-off-ns", &gpmc_t->adv_rd_off);
  1043. of_property_read_u32(np, "gpmc,adv-wr-off-ns", &gpmc_t->adv_wr_off);
  1044. /* WE signal timings */
  1045. of_property_read_u32(np, "gpmc,we-on-ns", &gpmc_t->we_on);
  1046. of_property_read_u32(np, "gpmc,we-off-ns", &gpmc_t->we_off);
  1047. /* OE signal timings */
  1048. of_property_read_u32(np, "gpmc,oe-on-ns", &gpmc_t->oe_on);
  1049. of_property_read_u32(np, "gpmc,oe-off-ns", &gpmc_t->oe_off);
  1050. /* access and cycle timings */
  1051. of_property_read_u32(np, "gpmc,page-burst-access-ns",
  1052. &gpmc_t->page_burst_access);
  1053. of_property_read_u32(np, "gpmc,access-ns", &gpmc_t->access);
  1054. of_property_read_u32(np, "gpmc,rd-cycle-ns", &gpmc_t->rd_cycle);
  1055. of_property_read_u32(np, "gpmc,wr-cycle-ns", &gpmc_t->wr_cycle);
  1056. of_property_read_u32(np, "gpmc,bus-turnaround-ns",
  1057. &gpmc_t->bus_turnaround);
  1058. of_property_read_u32(np, "gpmc,cycle2cycle-delay-ns",
  1059. &gpmc_t->cycle2cycle_delay);
  1060. of_property_read_u32(np, "gpmc,wait-monitoring-ns",
  1061. &gpmc_t->wait_monitoring);
  1062. of_property_read_u32(np, "gpmc,clk-activation-ns",
  1063. &gpmc_t->clk_activation);
  1064. /* only applicable to OMAP3+ */
  1065. of_property_read_u32(np, "gpmc,wr-access-ns", &gpmc_t->wr_access);
  1066. of_property_read_u32(np, "gpmc,wr-data-mux-bus-ns",
  1067. &gpmc_t->wr_data_mux_bus);
  1068. /* bool timing parameters */
  1069. p = &gpmc_t->bool_timings;
  1070. p->cycle2cyclediffcsen =
  1071. of_property_read_bool(np, "gpmc,cycle2cycle-diffcsen");
  1072. p->cycle2cyclesamecsen =
  1073. of_property_read_bool(np, "gpmc,cycle2cycle-samecsen");
  1074. p->we_extra_delay = of_property_read_bool(np, "gpmc,we-extra-delay");
  1075. p->oe_extra_delay = of_property_read_bool(np, "gpmc,oe-extra-delay");
  1076. p->adv_extra_delay = of_property_read_bool(np, "gpmc,adv-extra-delay");
  1077. p->cs_extra_delay = of_property_read_bool(np, "gpmc,cs-extra-delay");
  1078. p->time_para_granularity =
  1079. of_property_read_bool(np, "gpmc,time-para-granularity");
  1080. }
  1081. #ifdef CONFIG_MTD_NAND
  1082. static const char * const nand_ecc_opts[] = {
  1083. [OMAP_ECC_HAMMING_CODE_DEFAULT] = "sw",
  1084. [OMAP_ECC_HAMMING_CODE_HW] = "hw",
  1085. [OMAP_ECC_HAMMING_CODE_HW_ROMCODE] = "hw-romcode",
  1086. [OMAP_ECC_BCH4_CODE_HW] = "bch4",
  1087. [OMAP_ECC_BCH8_CODE_HW] = "bch8",
  1088. };
  1089. static int gpmc_probe_nand_child(struct platform_device *pdev,
  1090. struct device_node *child)
  1091. {
  1092. u32 val;
  1093. const char *s;
  1094. struct gpmc_timings gpmc_t;
  1095. struct omap_nand_platform_data *gpmc_nand_data;
  1096. if (of_property_read_u32(child, "reg", &val) < 0) {
  1097. dev_err(&pdev->dev, "%s has no 'reg' property\n",
  1098. child->full_name);
  1099. return -ENODEV;
  1100. }
  1101. gpmc_nand_data = devm_kzalloc(&pdev->dev, sizeof(*gpmc_nand_data),
  1102. GFP_KERNEL);
  1103. if (!gpmc_nand_data)
  1104. return -ENOMEM;
  1105. gpmc_nand_data->cs = val;
  1106. gpmc_nand_data->of_node = child;
  1107. if (!of_property_read_string(child, "ti,nand-ecc-opt", &s))
  1108. for (val = 0; val < ARRAY_SIZE(nand_ecc_opts); val++)
  1109. if (!strcasecmp(s, nand_ecc_opts[val])) {
  1110. gpmc_nand_data->ecc_opt = val;
  1111. break;
  1112. }
  1113. val = of_get_nand_bus_width(child);
  1114. if (val == 16)
  1115. gpmc_nand_data->devsize = NAND_BUSWIDTH_16;
  1116. gpmc_read_timings_dt(child, &gpmc_t);
  1117. gpmc_nand_init(gpmc_nand_data, &gpmc_t);
  1118. return 0;
  1119. }
  1120. #else
  1121. static int gpmc_probe_nand_child(struct platform_device *pdev,
  1122. struct device_node *child)
  1123. {
  1124. return 0;
  1125. }
  1126. #endif
  1127. #ifdef CONFIG_MTD_ONENAND
  1128. static int gpmc_probe_onenand_child(struct platform_device *pdev,
  1129. struct device_node *child)
  1130. {
  1131. u32 val;
  1132. struct omap_onenand_platform_data *gpmc_onenand_data;
  1133. if (of_property_read_u32(child, "reg", &val) < 0) {
  1134. dev_err(&pdev->dev, "%s has no 'reg' property\n",
  1135. child->full_name);
  1136. return -ENODEV;
  1137. }
  1138. gpmc_onenand_data = devm_kzalloc(&pdev->dev, sizeof(*gpmc_onenand_data),
  1139. GFP_KERNEL);
  1140. if (!gpmc_onenand_data)
  1141. return -ENOMEM;
  1142. gpmc_onenand_data->cs = val;
  1143. gpmc_onenand_data->of_node = child;
  1144. gpmc_onenand_data->dma_channel = -1;
  1145. if (!of_property_read_u32(child, "dma-channel", &val))
  1146. gpmc_onenand_data->dma_channel = val;
  1147. gpmc_onenand_init(gpmc_onenand_data);
  1148. return 0;
  1149. }
  1150. #else
  1151. static int gpmc_probe_onenand_child(struct platform_device *pdev,
  1152. struct device_node *child)
  1153. {
  1154. return 0;
  1155. }
  1156. #endif
  1157. static int gpmc_probe_dt(struct platform_device *pdev)
  1158. {
  1159. int ret;
  1160. struct device_node *child;
  1161. const struct of_device_id *of_id =
  1162. of_match_device(gpmc_dt_ids, &pdev->dev);
  1163. if (!of_id)
  1164. return 0;
  1165. ret = of_property_read_u32(pdev->dev.of_node, "gpmc,num-waitpins",
  1166. &gpmc_nr_waitpins);
  1167. if (ret < 0) {
  1168. pr_err("%s: number of wait pins not found!\n", __func__);
  1169. return ret;
  1170. }
  1171. for_each_node_by_name(child, "nand") {
  1172. ret = gpmc_probe_nand_child(pdev, child);
  1173. if (ret < 0) {
  1174. of_node_put(child);
  1175. return ret;
  1176. }
  1177. }
  1178. for_each_node_by_name(child, "onenand") {
  1179. ret = gpmc_probe_onenand_child(pdev, child);
  1180. if (ret < 0) {
  1181. of_node_put(child);
  1182. return ret;
  1183. }
  1184. }
  1185. return 0;
  1186. }
  1187. #else
  1188. static int gpmc_probe_dt(struct platform_device *pdev)
  1189. {
  1190. return 0;
  1191. }
  1192. #endif
  1193. static int gpmc_probe(struct platform_device *pdev)
  1194. {
  1195. int rc;
  1196. u32 l;
  1197. struct resource *res;
  1198. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1199. if (res == NULL)
  1200. return -ENOENT;
  1201. phys_base = res->start;
  1202. mem_size = resource_size(res);
  1203. gpmc_base = devm_ioremap_resource(&pdev->dev, res);
  1204. if (IS_ERR(gpmc_base))
  1205. return PTR_ERR(gpmc_base);
  1206. res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  1207. if (res == NULL)
  1208. dev_warn(&pdev->dev, "Failed to get resource: irq\n");
  1209. else
  1210. gpmc_irq = res->start;
  1211. gpmc_l3_clk = clk_get(&pdev->dev, "fck");
  1212. if (IS_ERR(gpmc_l3_clk)) {
  1213. dev_err(&pdev->dev, "error: clk_get\n");
  1214. gpmc_irq = 0;
  1215. return PTR_ERR(gpmc_l3_clk);
  1216. }
  1217. clk_prepare_enable(gpmc_l3_clk);
  1218. gpmc_dev = &pdev->dev;
  1219. l = gpmc_read_reg(GPMC_REVISION);
  1220. /*
  1221. * FIXME: Once device-tree migration is complete the below flags
  1222. * should be populated based upon the device-tree compatible
  1223. * string. For now just use the IP revision. OMAP3+ devices have
  1224. * the wr_access and wr_data_mux_bus register fields. OMAP4+
  1225. * devices support the addr-addr-data multiplex protocol.
  1226. *
  1227. * GPMC IP revisions:
  1228. * - OMAP24xx = 2.0
  1229. * - OMAP3xxx = 5.0
  1230. * - OMAP44xx/54xx/AM335x = 6.0
  1231. */
  1232. if (GPMC_REVISION_MAJOR(l) > 0x4)
  1233. gpmc_capability = GPMC_HAS_WR_ACCESS | GPMC_HAS_WR_DATA_MUX_BUS;
  1234. if (GPMC_REVISION_MAJOR(l) > 0x5)
  1235. gpmc_capability |= GPMC_HAS_MUX_AAD;
  1236. dev_info(gpmc_dev, "GPMC revision %d.%d\n", GPMC_REVISION_MAJOR(l),
  1237. GPMC_REVISION_MINOR(l));
  1238. rc = gpmc_mem_init();
  1239. if (rc < 0) {
  1240. clk_disable_unprepare(gpmc_l3_clk);
  1241. clk_put(gpmc_l3_clk);
  1242. dev_err(gpmc_dev, "failed to reserve memory\n");
  1243. return rc;
  1244. }
  1245. if (gpmc_setup_irq() < 0)
  1246. dev_warn(gpmc_dev, "gpmc_setup_irq failed\n");
  1247. /* Now the GPMC is initialised, unreserve the chip-selects */
  1248. gpmc_cs_map = 0;
  1249. if (!pdev->dev.of_node)
  1250. gpmc_nr_waitpins = GPMC_NR_WAITPINS;
  1251. rc = gpmc_probe_dt(pdev);
  1252. if (rc < 0) {
  1253. clk_disable_unprepare(gpmc_l3_clk);
  1254. clk_put(gpmc_l3_clk);
  1255. dev_err(gpmc_dev, "failed to probe DT parameters\n");
  1256. return rc;
  1257. }
  1258. return 0;
  1259. }
  1260. static int gpmc_remove(struct platform_device *pdev)
  1261. {
  1262. gpmc_free_irq();
  1263. gpmc_mem_exit();
  1264. gpmc_dev = NULL;
  1265. return 0;
  1266. }
  1267. static struct platform_driver gpmc_driver = {
  1268. .probe = gpmc_probe,
  1269. .remove = gpmc_remove,
  1270. .driver = {
  1271. .name = DEVICE_NAME,
  1272. .owner = THIS_MODULE,
  1273. .of_match_table = of_match_ptr(gpmc_dt_ids),
  1274. },
  1275. };
  1276. static __init int gpmc_init(void)
  1277. {
  1278. return platform_driver_register(&gpmc_driver);
  1279. }
  1280. static __exit void gpmc_exit(void)
  1281. {
  1282. platform_driver_unregister(&gpmc_driver);
  1283. }
  1284. omap_postcore_initcall(gpmc_init);
  1285. module_exit(gpmc_exit);
  1286. static int __init omap_gpmc_init(void)
  1287. {
  1288. struct omap_hwmod *oh;
  1289. struct platform_device *pdev;
  1290. char *oh_name = "gpmc";
  1291. /*
  1292. * if the board boots up with a populated DT, do not
  1293. * manually add the device from this initcall
  1294. */
  1295. if (of_have_populated_dt())
  1296. return -ENODEV;
  1297. oh = omap_hwmod_lookup(oh_name);
  1298. if (!oh) {
  1299. pr_err("Could not look up %s\n", oh_name);
  1300. return -ENODEV;
  1301. }
  1302. pdev = omap_device_build(DEVICE_NAME, -1, oh, NULL, 0);
  1303. WARN(IS_ERR(pdev), "could not build omap_device for %s\n", oh_name);
  1304. return IS_ERR(pdev) ? PTR_ERR(pdev) : 0;
  1305. }
  1306. omap_postcore_initcall(omap_gpmc_init);
  1307. static irqreturn_t gpmc_handle_irq(int irq, void *dev)
  1308. {
  1309. int i;
  1310. u32 regval;
  1311. regval = gpmc_read_reg(GPMC_IRQSTATUS);
  1312. if (!regval)
  1313. return IRQ_NONE;
  1314. for (i = 0; i < GPMC_NR_IRQ; i++)
  1315. if (regval & gpmc_client_irq[i].bitmask)
  1316. generic_handle_irq(gpmc_client_irq[i].irq);
  1317. gpmc_write_reg(GPMC_IRQSTATUS, regval);
  1318. return IRQ_HANDLED;
  1319. }
  1320. #ifdef CONFIG_ARCH_OMAP3
  1321. static struct omap3_gpmc_regs gpmc_context;
  1322. void omap3_gpmc_save_context(void)
  1323. {
  1324. int i;
  1325. gpmc_context.sysconfig = gpmc_read_reg(GPMC_SYSCONFIG);
  1326. gpmc_context.irqenable = gpmc_read_reg(GPMC_IRQENABLE);
  1327. gpmc_context.timeout_ctrl = gpmc_read_reg(GPMC_TIMEOUT_CONTROL);
  1328. gpmc_context.config = gpmc_read_reg(GPMC_CONFIG);
  1329. gpmc_context.prefetch_config1 = gpmc_read_reg(GPMC_PREFETCH_CONFIG1);
  1330. gpmc_context.prefetch_config2 = gpmc_read_reg(GPMC_PREFETCH_CONFIG2);
  1331. gpmc_context.prefetch_control = gpmc_read_reg(GPMC_PREFETCH_CONTROL);
  1332. for (i = 0; i < GPMC_CS_NUM; i++) {
  1333. gpmc_context.cs_context[i].is_valid = gpmc_cs_mem_enabled(i);
  1334. if (gpmc_context.cs_context[i].is_valid) {
  1335. gpmc_context.cs_context[i].config1 =
  1336. gpmc_cs_read_reg(i, GPMC_CS_CONFIG1);
  1337. gpmc_context.cs_context[i].config2 =
  1338. gpmc_cs_read_reg(i, GPMC_CS_CONFIG2);
  1339. gpmc_context.cs_context[i].config3 =
  1340. gpmc_cs_read_reg(i, GPMC_CS_CONFIG3);
  1341. gpmc_context.cs_context[i].config4 =
  1342. gpmc_cs_read_reg(i, GPMC_CS_CONFIG4);
  1343. gpmc_context.cs_context[i].config5 =
  1344. gpmc_cs_read_reg(i, GPMC_CS_CONFIG5);
  1345. gpmc_context.cs_context[i].config6 =
  1346. gpmc_cs_read_reg(i, GPMC_CS_CONFIG6);
  1347. gpmc_context.cs_context[i].config7 =
  1348. gpmc_cs_read_reg(i, GPMC_CS_CONFIG7);
  1349. }
  1350. }
  1351. }
  1352. void omap3_gpmc_restore_context(void)
  1353. {
  1354. int i;
  1355. gpmc_write_reg(GPMC_SYSCONFIG, gpmc_context.sysconfig);
  1356. gpmc_write_reg(GPMC_IRQENABLE, gpmc_context.irqenable);
  1357. gpmc_write_reg(GPMC_TIMEOUT_CONTROL, gpmc_context.timeout_ctrl);
  1358. gpmc_write_reg(GPMC_CONFIG, gpmc_context.config);
  1359. gpmc_write_reg(GPMC_PREFETCH_CONFIG1, gpmc_context.prefetch_config1);
  1360. gpmc_write_reg(GPMC_PREFETCH_CONFIG2, gpmc_context.prefetch_config2);
  1361. gpmc_write_reg(GPMC_PREFETCH_CONTROL, gpmc_context.prefetch_control);
  1362. for (i = 0; i < GPMC_CS_NUM; i++) {
  1363. if (gpmc_context.cs_context[i].is_valid) {
  1364. gpmc_cs_write_reg(i, GPMC_CS_CONFIG1,
  1365. gpmc_context.cs_context[i].config1);
  1366. gpmc_cs_write_reg(i, GPMC_CS_CONFIG2,
  1367. gpmc_context.cs_context[i].config2);
  1368. gpmc_cs_write_reg(i, GPMC_CS_CONFIG3,
  1369. gpmc_context.cs_context[i].config3);
  1370. gpmc_cs_write_reg(i, GPMC_CS_CONFIG4,
  1371. gpmc_context.cs_context[i].config4);
  1372. gpmc_cs_write_reg(i, GPMC_CS_CONFIG5,
  1373. gpmc_context.cs_context[i].config5);
  1374. gpmc_cs_write_reg(i, GPMC_CS_CONFIG6,
  1375. gpmc_context.cs_context[i].config6);
  1376. gpmc_cs_write_reg(i, GPMC_CS_CONFIG7,
  1377. gpmc_context.cs_context[i].config7);
  1378. }
  1379. }
  1380. }
  1381. #endif /* CONFIG_ARCH_OMAP3 */