omap-gpmc.c 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091
  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_address.h>
  29. #include <linux/of_mtd.h>
  30. #include <linux/of_device.h>
  31. #include <linux/omap-gpmc.h>
  32. #include <linux/mtd/nand.h>
  33. #include <linux/pm_runtime.h>
  34. #include <linux/platform_data/mtd-nand-omap2.h>
  35. #include <linux/platform_data/mtd-onenand-omap2.h>
  36. #include <asm/mach-types.h>
  37. #define DEVICE_NAME "omap-gpmc"
  38. /* GPMC register offsets */
  39. #define GPMC_REVISION 0x00
  40. #define GPMC_SYSCONFIG 0x10
  41. #define GPMC_SYSSTATUS 0x14
  42. #define GPMC_IRQSTATUS 0x18
  43. #define GPMC_IRQENABLE 0x1c
  44. #define GPMC_TIMEOUT_CONTROL 0x40
  45. #define GPMC_ERR_ADDRESS 0x44
  46. #define GPMC_ERR_TYPE 0x48
  47. #define GPMC_CONFIG 0x50
  48. #define GPMC_STATUS 0x54
  49. #define GPMC_PREFETCH_CONFIG1 0x1e0
  50. #define GPMC_PREFETCH_CONFIG2 0x1e4
  51. #define GPMC_PREFETCH_CONTROL 0x1ec
  52. #define GPMC_PREFETCH_STATUS 0x1f0
  53. #define GPMC_ECC_CONFIG 0x1f4
  54. #define GPMC_ECC_CONTROL 0x1f8
  55. #define GPMC_ECC_SIZE_CONFIG 0x1fc
  56. #define GPMC_ECC1_RESULT 0x200
  57. #define GPMC_ECC_BCH_RESULT_0 0x240 /* not available on OMAP2 */
  58. #define GPMC_ECC_BCH_RESULT_1 0x244 /* not available on OMAP2 */
  59. #define GPMC_ECC_BCH_RESULT_2 0x248 /* not available on OMAP2 */
  60. #define GPMC_ECC_BCH_RESULT_3 0x24c /* not available on OMAP2 */
  61. #define GPMC_ECC_BCH_RESULT_4 0x300 /* not available on OMAP2 */
  62. #define GPMC_ECC_BCH_RESULT_5 0x304 /* not available on OMAP2 */
  63. #define GPMC_ECC_BCH_RESULT_6 0x308 /* not available on OMAP2 */
  64. /* GPMC ECC control settings */
  65. #define GPMC_ECC_CTRL_ECCCLEAR 0x100
  66. #define GPMC_ECC_CTRL_ECCDISABLE 0x000
  67. #define GPMC_ECC_CTRL_ECCREG1 0x001
  68. #define GPMC_ECC_CTRL_ECCREG2 0x002
  69. #define GPMC_ECC_CTRL_ECCREG3 0x003
  70. #define GPMC_ECC_CTRL_ECCREG4 0x004
  71. #define GPMC_ECC_CTRL_ECCREG5 0x005
  72. #define GPMC_ECC_CTRL_ECCREG6 0x006
  73. #define GPMC_ECC_CTRL_ECCREG7 0x007
  74. #define GPMC_ECC_CTRL_ECCREG8 0x008
  75. #define GPMC_ECC_CTRL_ECCREG9 0x009
  76. #define GPMC_CONFIG_LIMITEDADDRESS BIT(1)
  77. #define GPMC_CONFIG2_CSEXTRADELAY BIT(7)
  78. #define GPMC_CONFIG3_ADVEXTRADELAY BIT(7)
  79. #define GPMC_CONFIG4_OEEXTRADELAY BIT(7)
  80. #define GPMC_CONFIG4_WEEXTRADELAY BIT(23)
  81. #define GPMC_CONFIG6_CYCLE2CYCLEDIFFCSEN BIT(6)
  82. #define GPMC_CONFIG6_CYCLE2CYCLESAMECSEN BIT(7)
  83. #define GPMC_CS0_OFFSET 0x60
  84. #define GPMC_CS_SIZE 0x30
  85. #define GPMC_BCH_SIZE 0x10
  86. #define GPMC_MEM_END 0x3FFFFFFF
  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. #define GPMC_CS_CONFIG1 0x00
  99. #define GPMC_CS_CONFIG2 0x04
  100. #define GPMC_CS_CONFIG3 0x08
  101. #define GPMC_CS_CONFIG4 0x0c
  102. #define GPMC_CS_CONFIG5 0x10
  103. #define GPMC_CS_CONFIG6 0x14
  104. #define GPMC_CS_CONFIG7 0x18
  105. #define GPMC_CS_NAND_COMMAND 0x1c
  106. #define GPMC_CS_NAND_ADDRESS 0x20
  107. #define GPMC_CS_NAND_DATA 0x24
  108. /* Control Commands */
  109. #define GPMC_CONFIG_RDY_BSY 0x00000001
  110. #define GPMC_CONFIG_DEV_SIZE 0x00000002
  111. #define GPMC_CONFIG_DEV_TYPE 0x00000003
  112. #define GPMC_SET_IRQ_STATUS 0x00000004
  113. #define GPMC_CONFIG1_WRAPBURST_SUPP (1 << 31)
  114. #define GPMC_CONFIG1_READMULTIPLE_SUPP (1 << 30)
  115. #define GPMC_CONFIG1_READTYPE_ASYNC (0 << 29)
  116. #define GPMC_CONFIG1_READTYPE_SYNC (1 << 29)
  117. #define GPMC_CONFIG1_WRITEMULTIPLE_SUPP (1 << 28)
  118. #define GPMC_CONFIG1_WRITETYPE_ASYNC (0 << 27)
  119. #define GPMC_CONFIG1_WRITETYPE_SYNC (1 << 27)
  120. #define GPMC_CONFIG1_CLKACTIVATIONTIME(val) ((val & 3) << 25)
  121. #define GPMC_CONFIG1_PAGE_LEN(val) ((val & 3) << 23)
  122. #define GPMC_CONFIG1_WAIT_READ_MON (1 << 22)
  123. #define GPMC_CONFIG1_WAIT_WRITE_MON (1 << 21)
  124. #define GPMC_CONFIG1_WAIT_MON_IIME(val) ((val & 3) << 18)
  125. #define GPMC_CONFIG1_WAIT_PIN_SEL(val) ((val & 3) << 16)
  126. #define GPMC_CONFIG1_DEVICESIZE(val) ((val & 3) << 12)
  127. #define GPMC_CONFIG1_DEVICESIZE_16 GPMC_CONFIG1_DEVICESIZE(1)
  128. #define GPMC_CONFIG1_DEVICETYPE(val) ((val & 3) << 10)
  129. #define GPMC_CONFIG1_DEVICETYPE_NOR GPMC_CONFIG1_DEVICETYPE(0)
  130. #define GPMC_CONFIG1_MUXTYPE(val) ((val & 3) << 8)
  131. #define GPMC_CONFIG1_TIME_PARA_GRAN (1 << 4)
  132. #define GPMC_CONFIG1_FCLK_DIV(val) (val & 3)
  133. #define GPMC_CONFIG1_FCLK_DIV2 (GPMC_CONFIG1_FCLK_DIV(1))
  134. #define GPMC_CONFIG1_FCLK_DIV3 (GPMC_CONFIG1_FCLK_DIV(2))
  135. #define GPMC_CONFIG1_FCLK_DIV4 (GPMC_CONFIG1_FCLK_DIV(3))
  136. #define GPMC_CONFIG7_CSVALID (1 << 6)
  137. #define GPMC_DEVICETYPE_NOR 0
  138. #define GPMC_DEVICETYPE_NAND 2
  139. #define GPMC_CONFIG_WRITEPROTECT 0x00000010
  140. #define WR_RD_PIN_MONITORING 0x00600000
  141. #define GPMC_ENABLE_IRQ 0x0000000d
  142. /* ECC commands */
  143. #define GPMC_ECC_READ 0 /* Reset Hardware ECC for read */
  144. #define GPMC_ECC_WRITE 1 /* Reset Hardware ECC for write */
  145. #define GPMC_ECC_READSYN 2 /* Reset before syndrom is read back */
  146. /* XXX: Only NAND irq has been considered,currently these are the only ones used
  147. */
  148. #define GPMC_NR_IRQ 2
  149. struct gpmc_cs_data {
  150. const char *name;
  151. #define GPMC_CS_RESERVED (1 << 0)
  152. u32 flags;
  153. struct resource mem;
  154. };
  155. struct gpmc_client_irq {
  156. unsigned irq;
  157. u32 bitmask;
  158. };
  159. /* Structure to save gpmc cs context */
  160. struct gpmc_cs_config {
  161. u32 config1;
  162. u32 config2;
  163. u32 config3;
  164. u32 config4;
  165. u32 config5;
  166. u32 config6;
  167. u32 config7;
  168. int is_valid;
  169. };
  170. /*
  171. * Structure to save/restore gpmc context
  172. * to support core off on OMAP3
  173. */
  174. struct omap3_gpmc_regs {
  175. u32 sysconfig;
  176. u32 irqenable;
  177. u32 timeout_ctrl;
  178. u32 config;
  179. u32 prefetch_config1;
  180. u32 prefetch_config2;
  181. u32 prefetch_control;
  182. struct gpmc_cs_config cs_context[GPMC_CS_NUM];
  183. };
  184. static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
  185. static struct irq_chip gpmc_irq_chip;
  186. static int gpmc_irq_start;
  187. static struct resource gpmc_mem_root;
  188. static struct gpmc_cs_data gpmc_cs[GPMC_CS_NUM];
  189. static DEFINE_SPINLOCK(gpmc_mem_lock);
  190. /* Define chip-selects as reserved by default until probe completes */
  191. static unsigned int gpmc_cs_num = GPMC_CS_NUM;
  192. static unsigned int gpmc_nr_waitpins;
  193. static struct device *gpmc_dev;
  194. static int gpmc_irq;
  195. static resource_size_t phys_base, mem_size;
  196. static unsigned gpmc_capability;
  197. static void __iomem *gpmc_base;
  198. static struct clk *gpmc_l3_clk;
  199. static irqreturn_t gpmc_handle_irq(int irq, void *dev);
  200. static void gpmc_write_reg(int idx, u32 val)
  201. {
  202. writel_relaxed(val, gpmc_base + idx);
  203. }
  204. static u32 gpmc_read_reg(int idx)
  205. {
  206. return readl_relaxed(gpmc_base + idx);
  207. }
  208. void gpmc_cs_write_reg(int cs, int idx, u32 val)
  209. {
  210. void __iomem *reg_addr;
  211. reg_addr = gpmc_base + GPMC_CS0_OFFSET + (cs * GPMC_CS_SIZE) + idx;
  212. writel_relaxed(val, reg_addr);
  213. }
  214. static u32 gpmc_cs_read_reg(int cs, int idx)
  215. {
  216. void __iomem *reg_addr;
  217. reg_addr = gpmc_base + GPMC_CS0_OFFSET + (cs * GPMC_CS_SIZE) + idx;
  218. return readl_relaxed(reg_addr);
  219. }
  220. /* TODO: Add support for gpmc_fck to clock framework and use it */
  221. static unsigned long gpmc_get_fclk_period(void)
  222. {
  223. unsigned long rate = clk_get_rate(gpmc_l3_clk);
  224. rate /= 1000;
  225. rate = 1000000000 / rate; /* In picoseconds */
  226. return rate;
  227. }
  228. static unsigned int gpmc_ns_to_ticks(unsigned int time_ns)
  229. {
  230. unsigned long tick_ps;
  231. /* Calculate in picosecs to yield more exact results */
  232. tick_ps = gpmc_get_fclk_period();
  233. return (time_ns * 1000 + tick_ps - 1) / tick_ps;
  234. }
  235. static unsigned int gpmc_ps_to_ticks(unsigned int time_ps)
  236. {
  237. unsigned long tick_ps;
  238. /* Calculate in picosecs to yield more exact results */
  239. tick_ps = gpmc_get_fclk_period();
  240. return (time_ps + tick_ps - 1) / tick_ps;
  241. }
  242. unsigned int gpmc_ticks_to_ns(unsigned int ticks)
  243. {
  244. return ticks * gpmc_get_fclk_period() / 1000;
  245. }
  246. static unsigned int gpmc_ticks_to_ps(unsigned int ticks)
  247. {
  248. return ticks * gpmc_get_fclk_period();
  249. }
  250. static unsigned int gpmc_round_ps_to_ticks(unsigned int time_ps)
  251. {
  252. unsigned long ticks = gpmc_ps_to_ticks(time_ps);
  253. return ticks * gpmc_get_fclk_period();
  254. }
  255. static inline void gpmc_cs_modify_reg(int cs, int reg, u32 mask, bool value)
  256. {
  257. u32 l;
  258. l = gpmc_cs_read_reg(cs, reg);
  259. if (value)
  260. l |= mask;
  261. else
  262. l &= ~mask;
  263. gpmc_cs_write_reg(cs, reg, l);
  264. }
  265. static void gpmc_cs_bool_timings(int cs, const struct gpmc_bool_timings *p)
  266. {
  267. gpmc_cs_modify_reg(cs, GPMC_CS_CONFIG1,
  268. GPMC_CONFIG1_TIME_PARA_GRAN,
  269. p->time_para_granularity);
  270. gpmc_cs_modify_reg(cs, GPMC_CS_CONFIG2,
  271. GPMC_CONFIG2_CSEXTRADELAY, p->cs_extra_delay);
  272. gpmc_cs_modify_reg(cs, GPMC_CS_CONFIG3,
  273. GPMC_CONFIG3_ADVEXTRADELAY, p->adv_extra_delay);
  274. gpmc_cs_modify_reg(cs, GPMC_CS_CONFIG4,
  275. GPMC_CONFIG4_OEEXTRADELAY, p->oe_extra_delay);
  276. gpmc_cs_modify_reg(cs, GPMC_CS_CONFIG4,
  277. GPMC_CONFIG4_OEEXTRADELAY, p->we_extra_delay);
  278. gpmc_cs_modify_reg(cs, GPMC_CS_CONFIG6,
  279. GPMC_CONFIG6_CYCLE2CYCLESAMECSEN,
  280. p->cycle2cyclesamecsen);
  281. gpmc_cs_modify_reg(cs, GPMC_CS_CONFIG6,
  282. GPMC_CONFIG6_CYCLE2CYCLEDIFFCSEN,
  283. p->cycle2cyclediffcsen);
  284. }
  285. #ifdef DEBUG
  286. static int get_gpmc_timing_reg(int cs, int reg, int st_bit, int end_bit,
  287. bool raw, bool noval, int shift,
  288. const char *name)
  289. {
  290. u32 l;
  291. int nr_bits, max_value, mask;
  292. l = gpmc_cs_read_reg(cs, reg);
  293. nr_bits = end_bit - st_bit + 1;
  294. max_value = (1 << nr_bits) - 1;
  295. mask = max_value << st_bit;
  296. l = (l & mask) >> st_bit;
  297. if (shift)
  298. l = (shift << l);
  299. if (noval && (l == 0))
  300. return 0;
  301. if (!raw) {
  302. unsigned int time_ns_min, time_ns, time_ns_max;
  303. time_ns_min = gpmc_ticks_to_ns(l ? l - 1 : 0);
  304. time_ns = gpmc_ticks_to_ns(l);
  305. time_ns_max = gpmc_ticks_to_ns(l + 1 > max_value ?
  306. max_value : l + 1);
  307. pr_info("gpmc,%s = <%u> (%u - %u ns, %i ticks)\n",
  308. name, time_ns, time_ns_min, time_ns_max, l);
  309. } else {
  310. pr_info("gpmc,%s = <%u>\n", name, l);
  311. }
  312. return l;
  313. }
  314. #define GPMC_PRINT_CONFIG(cs, config) \
  315. pr_info("cs%i %s: 0x%08x\n", cs, #config, \
  316. gpmc_cs_read_reg(cs, config))
  317. #define GPMC_GET_RAW(reg, st, end, field) \
  318. get_gpmc_timing_reg(cs, (reg), (st), (end), 1, 0, 0, field)
  319. #define GPMC_GET_RAW_BOOL(reg, st, end, field) \
  320. get_gpmc_timing_reg(cs, (reg), (st), (end), 1, 1, 0, field)
  321. #define GPMC_GET_RAW_SHIFT(reg, st, end, shift, field) \
  322. get_gpmc_timing_reg(cs, (reg), (st), (end), 1, 1, (shift), field)
  323. #define GPMC_GET_TICKS(reg, st, end, field) \
  324. get_gpmc_timing_reg(cs, (reg), (st), (end), 0, 0, 0, field)
  325. static void gpmc_show_regs(int cs, const char *desc)
  326. {
  327. pr_info("gpmc cs%i %s:\n", cs, desc);
  328. GPMC_PRINT_CONFIG(cs, GPMC_CS_CONFIG1);
  329. GPMC_PRINT_CONFIG(cs, GPMC_CS_CONFIG2);
  330. GPMC_PRINT_CONFIG(cs, GPMC_CS_CONFIG3);
  331. GPMC_PRINT_CONFIG(cs, GPMC_CS_CONFIG4);
  332. GPMC_PRINT_CONFIG(cs, GPMC_CS_CONFIG5);
  333. GPMC_PRINT_CONFIG(cs, GPMC_CS_CONFIG6);
  334. }
  335. /*
  336. * Note that gpmc,wait-pin handing wrongly assumes bit 8 is available,
  337. * see commit c9fb809.
  338. */
  339. static void gpmc_cs_show_timings(int cs, const char *desc)
  340. {
  341. gpmc_show_regs(cs, desc);
  342. pr_info("gpmc cs%i access configuration:\n", cs);
  343. GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG1, 4, 4, "time-para-granularity");
  344. GPMC_GET_RAW(GPMC_CS_CONFIG1, 8, 9, "mux-add-data");
  345. GPMC_GET_RAW(GPMC_CS_CONFIG1, 12, 13, "device-width");
  346. GPMC_GET_RAW(GPMC_CS_CONFIG1, 16, 17, "wait-pin");
  347. GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG1, 21, 21, "wait-on-write");
  348. GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG1, 22, 22, "wait-on-read");
  349. GPMC_GET_RAW_SHIFT(GPMC_CS_CONFIG1, 23, 24, 4, "burst-length");
  350. GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG1, 27, 27, "sync-write");
  351. GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG1, 28, 28, "burst-write");
  352. GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG1, 29, 29, "gpmc,sync-read");
  353. GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG1, 30, 30, "burst-read");
  354. GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG1, 31, 31, "burst-wrap");
  355. GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG2, 7, 7, "cs-extra-delay");
  356. GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG3, 7, 7, "adv-extra-delay");
  357. GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG4, 23, 23, "we-extra-delay");
  358. GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG4, 7, 7, "oe-extra-delay");
  359. GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG6, 7, 7, "cycle2cycle-samecsen");
  360. GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG6, 6, 6, "cycle2cycle-diffcsen");
  361. pr_info("gpmc cs%i timings configuration:\n", cs);
  362. GPMC_GET_TICKS(GPMC_CS_CONFIG2, 0, 3, "cs-on-ns");
  363. GPMC_GET_TICKS(GPMC_CS_CONFIG2, 8, 12, "cs-rd-off-ns");
  364. GPMC_GET_TICKS(GPMC_CS_CONFIG2, 16, 20, "cs-wr-off-ns");
  365. GPMC_GET_TICKS(GPMC_CS_CONFIG3, 0, 3, "adv-on-ns");
  366. GPMC_GET_TICKS(GPMC_CS_CONFIG3, 8, 12, "adv-rd-off-ns");
  367. GPMC_GET_TICKS(GPMC_CS_CONFIG3, 16, 20, "adv-wr-off-ns");
  368. GPMC_GET_TICKS(GPMC_CS_CONFIG4, 0, 3, "oe-on-ns");
  369. GPMC_GET_TICKS(GPMC_CS_CONFIG4, 8, 12, "oe-off-ns");
  370. GPMC_GET_TICKS(GPMC_CS_CONFIG4, 16, 19, "we-on-ns");
  371. GPMC_GET_TICKS(GPMC_CS_CONFIG4, 24, 28, "we-off-ns");
  372. GPMC_GET_TICKS(GPMC_CS_CONFIG5, 0, 4, "rd-cycle-ns");
  373. GPMC_GET_TICKS(GPMC_CS_CONFIG5, 8, 12, "wr-cycle-ns");
  374. GPMC_GET_TICKS(GPMC_CS_CONFIG5, 16, 20, "access-ns");
  375. GPMC_GET_TICKS(GPMC_CS_CONFIG5, 24, 27, "page-burst-access-ns");
  376. GPMC_GET_TICKS(GPMC_CS_CONFIG6, 0, 3, "bus-turnaround-ns");
  377. GPMC_GET_TICKS(GPMC_CS_CONFIG6, 8, 11, "cycle2cycle-delay-ns");
  378. GPMC_GET_TICKS(GPMC_CS_CONFIG1, 18, 19, "wait-monitoring-ns");
  379. GPMC_GET_TICKS(GPMC_CS_CONFIG1, 25, 26, "clk-activation-ns");
  380. GPMC_GET_TICKS(GPMC_CS_CONFIG6, 16, 19, "wr-data-mux-bus-ns");
  381. GPMC_GET_TICKS(GPMC_CS_CONFIG6, 24, 28, "wr-access-ns");
  382. }
  383. #else
  384. static inline void gpmc_cs_show_timings(int cs, const char *desc)
  385. {
  386. }
  387. #endif
  388. static int set_gpmc_timing_reg(int cs, int reg, int st_bit, int end_bit,
  389. int time, const char *name)
  390. {
  391. u32 l;
  392. int ticks, mask, nr_bits;
  393. if (time == 0)
  394. ticks = 0;
  395. else
  396. ticks = gpmc_ns_to_ticks(time);
  397. nr_bits = end_bit - st_bit + 1;
  398. mask = (1 << nr_bits) - 1;
  399. if (ticks > mask) {
  400. pr_err("%s: GPMC error! CS%d: %s: %d ns, %d ticks > %d\n",
  401. __func__, cs, name, time, ticks, mask);
  402. return -1;
  403. }
  404. l = gpmc_cs_read_reg(cs, reg);
  405. #ifdef DEBUG
  406. printk(KERN_INFO
  407. "GPMC CS%d: %-10s: %3d ticks, %3lu ns (was %3i ticks) %3d ns\n",
  408. cs, name, ticks, gpmc_get_fclk_period() * ticks / 1000,
  409. (l >> st_bit) & mask, time);
  410. #endif
  411. l &= ~(mask << st_bit);
  412. l |= ticks << st_bit;
  413. gpmc_cs_write_reg(cs, reg, l);
  414. return 0;
  415. }
  416. #define GPMC_SET_ONE(reg, st, end, field) \
  417. if (set_gpmc_timing_reg(cs, (reg), (st), (end), \
  418. t->field, #field) < 0) \
  419. return -1
  420. int gpmc_calc_divider(unsigned int sync_clk)
  421. {
  422. int div;
  423. u32 l;
  424. l = sync_clk + (gpmc_get_fclk_period() - 1);
  425. div = l / gpmc_get_fclk_period();
  426. if (div > 4)
  427. return -1;
  428. if (div <= 0)
  429. div = 1;
  430. return div;
  431. }
  432. int gpmc_cs_set_timings(int cs, const struct gpmc_timings *t)
  433. {
  434. int div;
  435. u32 l;
  436. gpmc_cs_show_timings(cs, "before gpmc_cs_set_timings");
  437. div = gpmc_calc_divider(t->sync_clk);
  438. if (div < 0)
  439. return div;
  440. GPMC_SET_ONE(GPMC_CS_CONFIG2, 0, 3, cs_on);
  441. GPMC_SET_ONE(GPMC_CS_CONFIG2, 8, 12, cs_rd_off);
  442. GPMC_SET_ONE(GPMC_CS_CONFIG2, 16, 20, cs_wr_off);
  443. GPMC_SET_ONE(GPMC_CS_CONFIG3, 0, 3, adv_on);
  444. GPMC_SET_ONE(GPMC_CS_CONFIG3, 8, 12, adv_rd_off);
  445. GPMC_SET_ONE(GPMC_CS_CONFIG3, 16, 20, adv_wr_off);
  446. GPMC_SET_ONE(GPMC_CS_CONFIG4, 0, 3, oe_on);
  447. GPMC_SET_ONE(GPMC_CS_CONFIG4, 8, 12, oe_off);
  448. GPMC_SET_ONE(GPMC_CS_CONFIG4, 16, 19, we_on);
  449. GPMC_SET_ONE(GPMC_CS_CONFIG4, 24, 28, we_off);
  450. GPMC_SET_ONE(GPMC_CS_CONFIG5, 0, 4, rd_cycle);
  451. GPMC_SET_ONE(GPMC_CS_CONFIG5, 8, 12, wr_cycle);
  452. GPMC_SET_ONE(GPMC_CS_CONFIG5, 16, 20, access);
  453. GPMC_SET_ONE(GPMC_CS_CONFIG5, 24, 27, page_burst_access);
  454. GPMC_SET_ONE(GPMC_CS_CONFIG6, 0, 3, bus_turnaround);
  455. GPMC_SET_ONE(GPMC_CS_CONFIG6, 8, 11, cycle2cycle_delay);
  456. GPMC_SET_ONE(GPMC_CS_CONFIG1, 18, 19, wait_monitoring);
  457. GPMC_SET_ONE(GPMC_CS_CONFIG1, 25, 26, clk_activation);
  458. if (gpmc_capability & GPMC_HAS_WR_DATA_MUX_BUS)
  459. GPMC_SET_ONE(GPMC_CS_CONFIG6, 16, 19, wr_data_mux_bus);
  460. if (gpmc_capability & GPMC_HAS_WR_ACCESS)
  461. GPMC_SET_ONE(GPMC_CS_CONFIG6, 24, 28, wr_access);
  462. /* caller is expected to have initialized CONFIG1 to cover
  463. * at least sync vs async
  464. */
  465. l = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG1);
  466. if (l & (GPMC_CONFIG1_READTYPE_SYNC | GPMC_CONFIG1_WRITETYPE_SYNC)) {
  467. #ifdef DEBUG
  468. printk(KERN_INFO "GPMC CS%d CLK period is %lu ns (div %d)\n",
  469. cs, (div * gpmc_get_fclk_period()) / 1000, div);
  470. #endif
  471. l &= ~0x03;
  472. l |= (div - 1);
  473. gpmc_cs_write_reg(cs, GPMC_CS_CONFIG1, l);
  474. }
  475. gpmc_cs_bool_timings(cs, &t->bool_timings);
  476. gpmc_cs_show_timings(cs, "after gpmc_cs_set_timings");
  477. return 0;
  478. }
  479. static int gpmc_cs_set_memconf(int cs, u32 base, u32 size)
  480. {
  481. u32 l;
  482. u32 mask;
  483. /*
  484. * Ensure that base address is aligned on a
  485. * boundary equal to or greater than size.
  486. */
  487. if (base & (size - 1))
  488. return -EINVAL;
  489. mask = (1 << GPMC_SECTION_SHIFT) - size;
  490. l = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG7);
  491. l &= ~0x3f;
  492. l = (base >> GPMC_CHUNK_SHIFT) & 0x3f;
  493. l &= ~(0x0f << 8);
  494. l |= ((mask >> GPMC_CHUNK_SHIFT) & 0x0f) << 8;
  495. l |= GPMC_CONFIG7_CSVALID;
  496. gpmc_cs_write_reg(cs, GPMC_CS_CONFIG7, l);
  497. return 0;
  498. }
  499. static void gpmc_cs_enable_mem(int cs)
  500. {
  501. u32 l;
  502. l = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG7);
  503. l |= GPMC_CONFIG7_CSVALID;
  504. gpmc_cs_write_reg(cs, GPMC_CS_CONFIG7, l);
  505. }
  506. static void gpmc_cs_disable_mem(int cs)
  507. {
  508. u32 l;
  509. l = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG7);
  510. l &= ~GPMC_CONFIG7_CSVALID;
  511. gpmc_cs_write_reg(cs, GPMC_CS_CONFIG7, l);
  512. }
  513. static void gpmc_cs_get_memconf(int cs, u32 *base, u32 *size)
  514. {
  515. u32 l;
  516. u32 mask;
  517. l = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG7);
  518. *base = (l & 0x3f) << GPMC_CHUNK_SHIFT;
  519. mask = (l >> 8) & 0x0f;
  520. *size = (1 << GPMC_SECTION_SHIFT) - (mask << GPMC_CHUNK_SHIFT);
  521. }
  522. static int gpmc_cs_mem_enabled(int cs)
  523. {
  524. u32 l;
  525. l = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG7);
  526. return l & GPMC_CONFIG7_CSVALID;
  527. }
  528. static void gpmc_cs_set_reserved(int cs, int reserved)
  529. {
  530. struct gpmc_cs_data *gpmc = &gpmc_cs[cs];
  531. gpmc->flags |= GPMC_CS_RESERVED;
  532. }
  533. static bool gpmc_cs_reserved(int cs)
  534. {
  535. struct gpmc_cs_data *gpmc = &gpmc_cs[cs];
  536. return gpmc->flags & GPMC_CS_RESERVED;
  537. }
  538. static void gpmc_cs_set_name(int cs, const char *name)
  539. {
  540. struct gpmc_cs_data *gpmc = &gpmc_cs[cs];
  541. gpmc->name = name;
  542. }
  543. const char *gpmc_cs_get_name(int cs)
  544. {
  545. struct gpmc_cs_data *gpmc = &gpmc_cs[cs];
  546. return gpmc->name;
  547. }
  548. static unsigned long gpmc_mem_align(unsigned long size)
  549. {
  550. int order;
  551. size = (size - 1) >> (GPMC_CHUNK_SHIFT - 1);
  552. order = GPMC_CHUNK_SHIFT - 1;
  553. do {
  554. size >>= 1;
  555. order++;
  556. } while (size);
  557. size = 1 << order;
  558. return size;
  559. }
  560. static int gpmc_cs_insert_mem(int cs, unsigned long base, unsigned long size)
  561. {
  562. struct gpmc_cs_data *gpmc = &gpmc_cs[cs];
  563. struct resource *res = &gpmc->mem;
  564. int r;
  565. size = gpmc_mem_align(size);
  566. spin_lock(&gpmc_mem_lock);
  567. res->start = base;
  568. res->end = base + size - 1;
  569. r = request_resource(&gpmc_mem_root, res);
  570. spin_unlock(&gpmc_mem_lock);
  571. return r;
  572. }
  573. static int gpmc_cs_delete_mem(int cs)
  574. {
  575. struct gpmc_cs_data *gpmc = &gpmc_cs[cs];
  576. struct resource *res = &gpmc->mem;
  577. int r;
  578. spin_lock(&gpmc_mem_lock);
  579. r = release_resource(res);
  580. res->start = 0;
  581. res->end = 0;
  582. spin_unlock(&gpmc_mem_lock);
  583. return r;
  584. }
  585. /**
  586. * gpmc_cs_remap - remaps a chip-select physical base address
  587. * @cs: chip-select to remap
  588. * @base: physical base address to re-map chip-select to
  589. *
  590. * Re-maps a chip-select to a new physical base address specified by
  591. * "base". Returns 0 on success and appropriate negative error code
  592. * on failure.
  593. */
  594. static int gpmc_cs_remap(int cs, u32 base)
  595. {
  596. int ret;
  597. u32 old_base, size;
  598. if (cs > gpmc_cs_num) {
  599. pr_err("%s: requested chip-select is disabled\n", __func__);
  600. return -ENODEV;
  601. }
  602. /*
  603. * Make sure we ignore any device offsets from the GPMC partition
  604. * allocated for the chip select and that the new base confirms
  605. * to the GPMC 16MB minimum granularity.
  606. */
  607. base &= ~(SZ_16M - 1);
  608. gpmc_cs_get_memconf(cs, &old_base, &size);
  609. if (base == old_base)
  610. return 0;
  611. ret = gpmc_cs_delete_mem(cs);
  612. if (ret < 0)
  613. return ret;
  614. ret = gpmc_cs_insert_mem(cs, base, size);
  615. if (ret < 0)
  616. return ret;
  617. ret = gpmc_cs_set_memconf(cs, base, size);
  618. return ret;
  619. }
  620. int gpmc_cs_request(int cs, unsigned long size, unsigned long *base)
  621. {
  622. struct gpmc_cs_data *gpmc = &gpmc_cs[cs];
  623. struct resource *res = &gpmc->mem;
  624. int r = -1;
  625. if (cs > gpmc_cs_num) {
  626. pr_err("%s: requested chip-select is disabled\n", __func__);
  627. return -ENODEV;
  628. }
  629. size = gpmc_mem_align(size);
  630. if (size > (1 << GPMC_SECTION_SHIFT))
  631. return -ENOMEM;
  632. spin_lock(&gpmc_mem_lock);
  633. if (gpmc_cs_reserved(cs)) {
  634. r = -EBUSY;
  635. goto out;
  636. }
  637. if (gpmc_cs_mem_enabled(cs))
  638. r = adjust_resource(res, res->start & ~(size - 1), size);
  639. if (r < 0)
  640. r = allocate_resource(&gpmc_mem_root, res, size, 0, ~0,
  641. size, NULL, NULL);
  642. if (r < 0)
  643. goto out;
  644. /* Disable CS while changing base address and size mask */
  645. gpmc_cs_disable_mem(cs);
  646. r = gpmc_cs_set_memconf(cs, res->start, resource_size(res));
  647. if (r < 0) {
  648. release_resource(res);
  649. goto out;
  650. }
  651. /* Enable CS */
  652. gpmc_cs_enable_mem(cs);
  653. *base = res->start;
  654. gpmc_cs_set_reserved(cs, 1);
  655. out:
  656. spin_unlock(&gpmc_mem_lock);
  657. return r;
  658. }
  659. EXPORT_SYMBOL(gpmc_cs_request);
  660. void gpmc_cs_free(int cs)
  661. {
  662. struct gpmc_cs_data *gpmc = &gpmc_cs[cs];
  663. struct resource *res = &gpmc->mem;
  664. spin_lock(&gpmc_mem_lock);
  665. if (cs >= gpmc_cs_num || cs < 0 || !gpmc_cs_reserved(cs)) {
  666. printk(KERN_ERR "Trying to free non-reserved GPMC CS%d\n", cs);
  667. BUG();
  668. spin_unlock(&gpmc_mem_lock);
  669. return;
  670. }
  671. gpmc_cs_disable_mem(cs);
  672. if (res->flags)
  673. release_resource(res);
  674. gpmc_cs_set_reserved(cs, 0);
  675. spin_unlock(&gpmc_mem_lock);
  676. }
  677. EXPORT_SYMBOL(gpmc_cs_free);
  678. /**
  679. * gpmc_configure - write request to configure gpmc
  680. * @cmd: command type
  681. * @wval: value to write
  682. * @return status of the operation
  683. */
  684. int gpmc_configure(int cmd, int wval)
  685. {
  686. u32 regval;
  687. switch (cmd) {
  688. case GPMC_ENABLE_IRQ:
  689. gpmc_write_reg(GPMC_IRQENABLE, wval);
  690. break;
  691. case GPMC_SET_IRQ_STATUS:
  692. gpmc_write_reg(GPMC_IRQSTATUS, wval);
  693. break;
  694. case GPMC_CONFIG_WP:
  695. regval = gpmc_read_reg(GPMC_CONFIG);
  696. if (wval)
  697. regval &= ~GPMC_CONFIG_WRITEPROTECT; /* WP is ON */
  698. else
  699. regval |= GPMC_CONFIG_WRITEPROTECT; /* WP is OFF */
  700. gpmc_write_reg(GPMC_CONFIG, regval);
  701. break;
  702. default:
  703. pr_err("%s: command not supported\n", __func__);
  704. return -EINVAL;
  705. }
  706. return 0;
  707. }
  708. EXPORT_SYMBOL(gpmc_configure);
  709. void gpmc_update_nand_reg(struct gpmc_nand_regs *reg, int cs)
  710. {
  711. int i;
  712. reg->gpmc_status = gpmc_base + GPMC_STATUS;
  713. reg->gpmc_nand_command = gpmc_base + GPMC_CS0_OFFSET +
  714. GPMC_CS_NAND_COMMAND + GPMC_CS_SIZE * cs;
  715. reg->gpmc_nand_address = gpmc_base + GPMC_CS0_OFFSET +
  716. GPMC_CS_NAND_ADDRESS + GPMC_CS_SIZE * cs;
  717. reg->gpmc_nand_data = gpmc_base + GPMC_CS0_OFFSET +
  718. GPMC_CS_NAND_DATA + GPMC_CS_SIZE * cs;
  719. reg->gpmc_prefetch_config1 = gpmc_base + GPMC_PREFETCH_CONFIG1;
  720. reg->gpmc_prefetch_config2 = gpmc_base + GPMC_PREFETCH_CONFIG2;
  721. reg->gpmc_prefetch_control = gpmc_base + GPMC_PREFETCH_CONTROL;
  722. reg->gpmc_prefetch_status = gpmc_base + GPMC_PREFETCH_STATUS;
  723. reg->gpmc_ecc_config = gpmc_base + GPMC_ECC_CONFIG;
  724. reg->gpmc_ecc_control = gpmc_base + GPMC_ECC_CONTROL;
  725. reg->gpmc_ecc_size_config = gpmc_base + GPMC_ECC_SIZE_CONFIG;
  726. reg->gpmc_ecc1_result = gpmc_base + GPMC_ECC1_RESULT;
  727. for (i = 0; i < GPMC_BCH_NUM_REMAINDER; i++) {
  728. reg->gpmc_bch_result0[i] = gpmc_base + GPMC_ECC_BCH_RESULT_0 +
  729. GPMC_BCH_SIZE * i;
  730. reg->gpmc_bch_result1[i] = gpmc_base + GPMC_ECC_BCH_RESULT_1 +
  731. GPMC_BCH_SIZE * i;
  732. reg->gpmc_bch_result2[i] = gpmc_base + GPMC_ECC_BCH_RESULT_2 +
  733. GPMC_BCH_SIZE * i;
  734. reg->gpmc_bch_result3[i] = gpmc_base + GPMC_ECC_BCH_RESULT_3 +
  735. GPMC_BCH_SIZE * i;
  736. reg->gpmc_bch_result4[i] = gpmc_base + GPMC_ECC_BCH_RESULT_4 +
  737. i * GPMC_BCH_SIZE;
  738. reg->gpmc_bch_result5[i] = gpmc_base + GPMC_ECC_BCH_RESULT_5 +
  739. i * GPMC_BCH_SIZE;
  740. reg->gpmc_bch_result6[i] = gpmc_base + GPMC_ECC_BCH_RESULT_6 +
  741. i * GPMC_BCH_SIZE;
  742. }
  743. }
  744. int gpmc_get_client_irq(unsigned irq_config)
  745. {
  746. int i;
  747. if (hweight32(irq_config) > 1)
  748. return 0;
  749. for (i = 0; i < GPMC_NR_IRQ; i++)
  750. if (gpmc_client_irq[i].bitmask & irq_config)
  751. return gpmc_client_irq[i].irq;
  752. return 0;
  753. }
  754. static int gpmc_irq_endis(unsigned irq, bool endis)
  755. {
  756. int i;
  757. u32 regval;
  758. for (i = 0; i < GPMC_NR_IRQ; i++)
  759. if (irq == gpmc_client_irq[i].irq) {
  760. regval = gpmc_read_reg(GPMC_IRQENABLE);
  761. if (endis)
  762. regval |= gpmc_client_irq[i].bitmask;
  763. else
  764. regval &= ~gpmc_client_irq[i].bitmask;
  765. gpmc_write_reg(GPMC_IRQENABLE, regval);
  766. break;
  767. }
  768. return 0;
  769. }
  770. static void gpmc_irq_disable(struct irq_data *p)
  771. {
  772. gpmc_irq_endis(p->irq, false);
  773. }
  774. static void gpmc_irq_enable(struct irq_data *p)
  775. {
  776. gpmc_irq_endis(p->irq, true);
  777. }
  778. static void gpmc_irq_noop(struct irq_data *data) { }
  779. static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
  780. static int gpmc_setup_irq(void)
  781. {
  782. int i;
  783. u32 regval;
  784. if (!gpmc_irq)
  785. return -EINVAL;
  786. gpmc_irq_start = irq_alloc_descs(-1, 0, GPMC_NR_IRQ, 0);
  787. if (gpmc_irq_start < 0) {
  788. pr_err("irq_alloc_descs failed\n");
  789. return gpmc_irq_start;
  790. }
  791. gpmc_irq_chip.name = "gpmc";
  792. gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
  793. gpmc_irq_chip.irq_enable = gpmc_irq_enable;
  794. gpmc_irq_chip.irq_disable = gpmc_irq_disable;
  795. gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
  796. gpmc_irq_chip.irq_ack = gpmc_irq_noop;
  797. gpmc_irq_chip.irq_mask = gpmc_irq_noop;
  798. gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
  799. gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
  800. gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
  801. for (i = 0; i < GPMC_NR_IRQ; i++) {
  802. gpmc_client_irq[i].irq = gpmc_irq_start + i;
  803. irq_set_chip_and_handler(gpmc_client_irq[i].irq,
  804. &gpmc_irq_chip, handle_simple_irq);
  805. set_irq_flags(gpmc_client_irq[i].irq,
  806. IRQF_VALID | IRQF_NOAUTOEN);
  807. }
  808. /* Disable interrupts */
  809. gpmc_write_reg(GPMC_IRQENABLE, 0);
  810. /* clear interrupts */
  811. regval = gpmc_read_reg(GPMC_IRQSTATUS);
  812. gpmc_write_reg(GPMC_IRQSTATUS, regval);
  813. return request_irq(gpmc_irq, gpmc_handle_irq, 0, "gpmc", NULL);
  814. }
  815. static int gpmc_free_irq(void)
  816. {
  817. int i;
  818. if (gpmc_irq)
  819. free_irq(gpmc_irq, NULL);
  820. for (i = 0; i < GPMC_NR_IRQ; i++) {
  821. irq_set_handler(gpmc_client_irq[i].irq, NULL);
  822. irq_set_chip(gpmc_client_irq[i].irq, &no_irq_chip);
  823. irq_modify_status(gpmc_client_irq[i].irq, 0, 0);
  824. }
  825. irq_free_descs(gpmc_irq_start, GPMC_NR_IRQ);
  826. return 0;
  827. }
  828. static void gpmc_mem_exit(void)
  829. {
  830. int cs;
  831. for (cs = 0; cs < gpmc_cs_num; cs++) {
  832. if (!gpmc_cs_mem_enabled(cs))
  833. continue;
  834. gpmc_cs_delete_mem(cs);
  835. }
  836. }
  837. static void gpmc_mem_init(void)
  838. {
  839. int cs;
  840. /*
  841. * The first 1MB of GPMC address space is typically mapped to
  842. * the internal ROM. Never allocate the first page, to
  843. * facilitate bug detection; even if we didn't boot from ROM.
  844. */
  845. gpmc_mem_root.start = SZ_1M;
  846. gpmc_mem_root.end = GPMC_MEM_END;
  847. /* Reserve all regions that has been set up by bootloader */
  848. for (cs = 0; cs < gpmc_cs_num; cs++) {
  849. u32 base, size;
  850. if (!gpmc_cs_mem_enabled(cs))
  851. continue;
  852. gpmc_cs_get_memconf(cs, &base, &size);
  853. if (gpmc_cs_insert_mem(cs, base, size)) {
  854. pr_warn("%s: disabling cs %d mapped at 0x%x-0x%x\n",
  855. __func__, cs, base, base + size);
  856. gpmc_cs_disable_mem(cs);
  857. }
  858. }
  859. }
  860. static u32 gpmc_round_ps_to_sync_clk(u32 time_ps, u32 sync_clk)
  861. {
  862. u32 temp;
  863. int div;
  864. div = gpmc_calc_divider(sync_clk);
  865. temp = gpmc_ps_to_ticks(time_ps);
  866. temp = (temp + div - 1) / div;
  867. return gpmc_ticks_to_ps(temp * div);
  868. }
  869. /* XXX: can the cycles be avoided ? */
  870. static int gpmc_calc_sync_read_timings(struct gpmc_timings *gpmc_t,
  871. struct gpmc_device_timings *dev_t,
  872. bool mux)
  873. {
  874. u32 temp;
  875. /* adv_rd_off */
  876. temp = dev_t->t_avdp_r;
  877. /* XXX: mux check required ? */
  878. if (mux) {
  879. /* XXX: t_avdp not to be required for sync, only added for tusb
  880. * this indirectly necessitates requirement of t_avdp_r and
  881. * t_avdp_w instead of having a single t_avdp
  882. */
  883. temp = max_t(u32, temp, gpmc_t->clk_activation + dev_t->t_avdh);
  884. temp = max_t(u32, gpmc_t->adv_on + gpmc_ticks_to_ps(1), temp);
  885. }
  886. gpmc_t->adv_rd_off = gpmc_round_ps_to_ticks(temp);
  887. /* oe_on */
  888. temp = dev_t->t_oeasu; /* XXX: remove this ? */
  889. if (mux) {
  890. temp = max_t(u32, temp, gpmc_t->clk_activation + dev_t->t_ach);
  891. temp = max_t(u32, temp, gpmc_t->adv_rd_off +
  892. gpmc_ticks_to_ps(dev_t->cyc_aavdh_oe));
  893. }
  894. gpmc_t->oe_on = gpmc_round_ps_to_ticks(temp);
  895. /* access */
  896. /* XXX: any scope for improvement ?, by combining oe_on
  897. * and clk_activation, need to check whether
  898. * access = clk_activation + round to sync clk ?
  899. */
  900. temp = max_t(u32, dev_t->t_iaa, dev_t->cyc_iaa * gpmc_t->sync_clk);
  901. temp += gpmc_t->clk_activation;
  902. if (dev_t->cyc_oe)
  903. temp = max_t(u32, temp, gpmc_t->oe_on +
  904. gpmc_ticks_to_ps(dev_t->cyc_oe));
  905. gpmc_t->access = gpmc_round_ps_to_ticks(temp);
  906. gpmc_t->oe_off = gpmc_t->access + gpmc_ticks_to_ps(1);
  907. gpmc_t->cs_rd_off = gpmc_t->oe_off;
  908. /* rd_cycle */
  909. temp = max_t(u32, dev_t->t_cez_r, dev_t->t_oez);
  910. temp = gpmc_round_ps_to_sync_clk(temp, gpmc_t->sync_clk) +
  911. gpmc_t->access;
  912. /* XXX: barter t_ce_rdyz with t_cez_r ? */
  913. if (dev_t->t_ce_rdyz)
  914. temp = max_t(u32, temp, gpmc_t->cs_rd_off + dev_t->t_ce_rdyz);
  915. gpmc_t->rd_cycle = gpmc_round_ps_to_ticks(temp);
  916. return 0;
  917. }
  918. static int gpmc_calc_sync_write_timings(struct gpmc_timings *gpmc_t,
  919. struct gpmc_device_timings *dev_t,
  920. bool mux)
  921. {
  922. u32 temp;
  923. /* adv_wr_off */
  924. temp = dev_t->t_avdp_w;
  925. if (mux) {
  926. temp = max_t(u32, temp,
  927. gpmc_t->clk_activation + dev_t->t_avdh);
  928. temp = max_t(u32, gpmc_t->adv_on + gpmc_ticks_to_ps(1), temp);
  929. }
  930. gpmc_t->adv_wr_off = gpmc_round_ps_to_ticks(temp);
  931. /* wr_data_mux_bus */
  932. temp = max_t(u32, dev_t->t_weasu,
  933. gpmc_t->clk_activation + dev_t->t_rdyo);
  934. /* XXX: shouldn't mux be kept as a whole for wr_data_mux_bus ?,
  935. * and in that case remember to handle we_on properly
  936. */
  937. if (mux) {
  938. temp = max_t(u32, temp,
  939. gpmc_t->adv_wr_off + dev_t->t_aavdh);
  940. temp = max_t(u32, temp, gpmc_t->adv_wr_off +
  941. gpmc_ticks_to_ps(dev_t->cyc_aavdh_we));
  942. }
  943. gpmc_t->wr_data_mux_bus = gpmc_round_ps_to_ticks(temp);
  944. /* we_on */
  945. if (gpmc_capability & GPMC_HAS_WR_DATA_MUX_BUS)
  946. gpmc_t->we_on = gpmc_round_ps_to_ticks(dev_t->t_weasu);
  947. else
  948. gpmc_t->we_on = gpmc_t->wr_data_mux_bus;
  949. /* wr_access */
  950. /* XXX: gpmc_capability check reqd ? , even if not, will not harm */
  951. gpmc_t->wr_access = gpmc_t->access;
  952. /* we_off */
  953. temp = gpmc_t->we_on + dev_t->t_wpl;
  954. temp = max_t(u32, temp,
  955. gpmc_t->wr_access + gpmc_ticks_to_ps(1));
  956. temp = max_t(u32, temp,
  957. gpmc_t->we_on + gpmc_ticks_to_ps(dev_t->cyc_wpl));
  958. gpmc_t->we_off = gpmc_round_ps_to_ticks(temp);
  959. gpmc_t->cs_wr_off = gpmc_round_ps_to_ticks(gpmc_t->we_off +
  960. dev_t->t_wph);
  961. /* wr_cycle */
  962. temp = gpmc_round_ps_to_sync_clk(dev_t->t_cez_w, gpmc_t->sync_clk);
  963. temp += gpmc_t->wr_access;
  964. /* XXX: barter t_ce_rdyz with t_cez_w ? */
  965. if (dev_t->t_ce_rdyz)
  966. temp = max_t(u32, temp,
  967. gpmc_t->cs_wr_off + dev_t->t_ce_rdyz);
  968. gpmc_t->wr_cycle = gpmc_round_ps_to_ticks(temp);
  969. return 0;
  970. }
  971. static int gpmc_calc_async_read_timings(struct gpmc_timings *gpmc_t,
  972. struct gpmc_device_timings *dev_t,
  973. bool mux)
  974. {
  975. u32 temp;
  976. /* adv_rd_off */
  977. temp = dev_t->t_avdp_r;
  978. if (mux)
  979. temp = max_t(u32, gpmc_t->adv_on + gpmc_ticks_to_ps(1), temp);
  980. gpmc_t->adv_rd_off = gpmc_round_ps_to_ticks(temp);
  981. /* oe_on */
  982. temp = dev_t->t_oeasu;
  983. if (mux)
  984. temp = max_t(u32, temp,
  985. gpmc_t->adv_rd_off + dev_t->t_aavdh);
  986. gpmc_t->oe_on = gpmc_round_ps_to_ticks(temp);
  987. /* access */
  988. temp = max_t(u32, dev_t->t_iaa, /* XXX: remove t_iaa in async ? */
  989. gpmc_t->oe_on + dev_t->t_oe);
  990. temp = max_t(u32, temp,
  991. gpmc_t->cs_on + dev_t->t_ce);
  992. temp = max_t(u32, temp,
  993. gpmc_t->adv_on + dev_t->t_aa);
  994. gpmc_t->access = gpmc_round_ps_to_ticks(temp);
  995. gpmc_t->oe_off = gpmc_t->access + gpmc_ticks_to_ps(1);
  996. gpmc_t->cs_rd_off = gpmc_t->oe_off;
  997. /* rd_cycle */
  998. temp = max_t(u32, dev_t->t_rd_cycle,
  999. gpmc_t->cs_rd_off + dev_t->t_cez_r);
  1000. temp = max_t(u32, temp, gpmc_t->oe_off + dev_t->t_oez);
  1001. gpmc_t->rd_cycle = gpmc_round_ps_to_ticks(temp);
  1002. return 0;
  1003. }
  1004. static int gpmc_calc_async_write_timings(struct gpmc_timings *gpmc_t,
  1005. struct gpmc_device_timings *dev_t,
  1006. bool mux)
  1007. {
  1008. u32 temp;
  1009. /* adv_wr_off */
  1010. temp = dev_t->t_avdp_w;
  1011. if (mux)
  1012. temp = max_t(u32, gpmc_t->adv_on + gpmc_ticks_to_ps(1), temp);
  1013. gpmc_t->adv_wr_off = gpmc_round_ps_to_ticks(temp);
  1014. /* wr_data_mux_bus */
  1015. temp = dev_t->t_weasu;
  1016. if (mux) {
  1017. temp = max_t(u32, temp, gpmc_t->adv_wr_off + dev_t->t_aavdh);
  1018. temp = max_t(u32, temp, gpmc_t->adv_wr_off +
  1019. gpmc_ticks_to_ps(dev_t->cyc_aavdh_we));
  1020. }
  1021. gpmc_t->wr_data_mux_bus = gpmc_round_ps_to_ticks(temp);
  1022. /* we_on */
  1023. if (gpmc_capability & GPMC_HAS_WR_DATA_MUX_BUS)
  1024. gpmc_t->we_on = gpmc_round_ps_to_ticks(dev_t->t_weasu);
  1025. else
  1026. gpmc_t->we_on = gpmc_t->wr_data_mux_bus;
  1027. /* we_off */
  1028. temp = gpmc_t->we_on + dev_t->t_wpl;
  1029. gpmc_t->we_off = gpmc_round_ps_to_ticks(temp);
  1030. gpmc_t->cs_wr_off = gpmc_round_ps_to_ticks(gpmc_t->we_off +
  1031. dev_t->t_wph);
  1032. /* wr_cycle */
  1033. temp = max_t(u32, dev_t->t_wr_cycle,
  1034. gpmc_t->cs_wr_off + dev_t->t_cez_w);
  1035. gpmc_t->wr_cycle = gpmc_round_ps_to_ticks(temp);
  1036. return 0;
  1037. }
  1038. static int gpmc_calc_sync_common_timings(struct gpmc_timings *gpmc_t,
  1039. struct gpmc_device_timings *dev_t)
  1040. {
  1041. u32 temp;
  1042. gpmc_t->sync_clk = gpmc_calc_divider(dev_t->clk) *
  1043. gpmc_get_fclk_period();
  1044. gpmc_t->page_burst_access = gpmc_round_ps_to_sync_clk(
  1045. dev_t->t_bacc,
  1046. gpmc_t->sync_clk);
  1047. temp = max_t(u32, dev_t->t_ces, dev_t->t_avds);
  1048. gpmc_t->clk_activation = gpmc_round_ps_to_ticks(temp);
  1049. if (gpmc_calc_divider(gpmc_t->sync_clk) != 1)
  1050. return 0;
  1051. if (dev_t->ce_xdelay)
  1052. gpmc_t->bool_timings.cs_extra_delay = true;
  1053. if (dev_t->avd_xdelay)
  1054. gpmc_t->bool_timings.adv_extra_delay = true;
  1055. if (dev_t->oe_xdelay)
  1056. gpmc_t->bool_timings.oe_extra_delay = true;
  1057. if (dev_t->we_xdelay)
  1058. gpmc_t->bool_timings.we_extra_delay = true;
  1059. return 0;
  1060. }
  1061. static int gpmc_calc_common_timings(struct gpmc_timings *gpmc_t,
  1062. struct gpmc_device_timings *dev_t,
  1063. bool sync)
  1064. {
  1065. u32 temp;
  1066. /* cs_on */
  1067. gpmc_t->cs_on = gpmc_round_ps_to_ticks(dev_t->t_ceasu);
  1068. /* adv_on */
  1069. temp = dev_t->t_avdasu;
  1070. if (dev_t->t_ce_avd)
  1071. temp = max_t(u32, temp,
  1072. gpmc_t->cs_on + dev_t->t_ce_avd);
  1073. gpmc_t->adv_on = gpmc_round_ps_to_ticks(temp);
  1074. if (sync)
  1075. gpmc_calc_sync_common_timings(gpmc_t, dev_t);
  1076. return 0;
  1077. }
  1078. /* TODO: remove this function once all peripherals are confirmed to
  1079. * work with generic timing. Simultaneously gpmc_cs_set_timings()
  1080. * has to be modified to handle timings in ps instead of ns
  1081. */
  1082. static void gpmc_convert_ps_to_ns(struct gpmc_timings *t)
  1083. {
  1084. t->cs_on /= 1000;
  1085. t->cs_rd_off /= 1000;
  1086. t->cs_wr_off /= 1000;
  1087. t->adv_on /= 1000;
  1088. t->adv_rd_off /= 1000;
  1089. t->adv_wr_off /= 1000;
  1090. t->we_on /= 1000;
  1091. t->we_off /= 1000;
  1092. t->oe_on /= 1000;
  1093. t->oe_off /= 1000;
  1094. t->page_burst_access /= 1000;
  1095. t->access /= 1000;
  1096. t->rd_cycle /= 1000;
  1097. t->wr_cycle /= 1000;
  1098. t->bus_turnaround /= 1000;
  1099. t->cycle2cycle_delay /= 1000;
  1100. t->wait_monitoring /= 1000;
  1101. t->clk_activation /= 1000;
  1102. t->wr_access /= 1000;
  1103. t->wr_data_mux_bus /= 1000;
  1104. }
  1105. int gpmc_calc_timings(struct gpmc_timings *gpmc_t,
  1106. struct gpmc_settings *gpmc_s,
  1107. struct gpmc_device_timings *dev_t)
  1108. {
  1109. bool mux = false, sync = false;
  1110. if (gpmc_s) {
  1111. mux = gpmc_s->mux_add_data ? true : false;
  1112. sync = (gpmc_s->sync_read || gpmc_s->sync_write);
  1113. }
  1114. memset(gpmc_t, 0, sizeof(*gpmc_t));
  1115. gpmc_calc_common_timings(gpmc_t, dev_t, sync);
  1116. if (gpmc_s && gpmc_s->sync_read)
  1117. gpmc_calc_sync_read_timings(gpmc_t, dev_t, mux);
  1118. else
  1119. gpmc_calc_async_read_timings(gpmc_t, dev_t, mux);
  1120. if (gpmc_s && gpmc_s->sync_write)
  1121. gpmc_calc_sync_write_timings(gpmc_t, dev_t, mux);
  1122. else
  1123. gpmc_calc_async_write_timings(gpmc_t, dev_t, mux);
  1124. /* TODO: remove, see function definition */
  1125. gpmc_convert_ps_to_ns(gpmc_t);
  1126. return 0;
  1127. }
  1128. /**
  1129. * gpmc_cs_program_settings - programs non-timing related settings
  1130. * @cs: GPMC chip-select to program
  1131. * @p: pointer to GPMC settings structure
  1132. *
  1133. * Programs non-timing related settings for a GPMC chip-select, such as
  1134. * bus-width, burst configuration, etc. Function should be called once
  1135. * for each chip-select that is being used and must be called before
  1136. * calling gpmc_cs_set_timings() as timing parameters in the CONFIG1
  1137. * register will be initialised to zero by this function. Returns 0 on
  1138. * success and appropriate negative error code on failure.
  1139. */
  1140. int gpmc_cs_program_settings(int cs, struct gpmc_settings *p)
  1141. {
  1142. u32 config1;
  1143. if ((!p->device_width) || (p->device_width > GPMC_DEVWIDTH_16BIT)) {
  1144. pr_err("%s: invalid width %d!", __func__, p->device_width);
  1145. return -EINVAL;
  1146. }
  1147. /* Address-data multiplexing not supported for NAND devices */
  1148. if (p->device_nand && p->mux_add_data) {
  1149. pr_err("%s: invalid configuration!\n", __func__);
  1150. return -EINVAL;
  1151. }
  1152. if ((p->mux_add_data > GPMC_MUX_AD) ||
  1153. ((p->mux_add_data == GPMC_MUX_AAD) &&
  1154. !(gpmc_capability & GPMC_HAS_MUX_AAD))) {
  1155. pr_err("%s: invalid multiplex configuration!\n", __func__);
  1156. return -EINVAL;
  1157. }
  1158. /* Page/burst mode supports lengths of 4, 8 and 16 bytes */
  1159. if (p->burst_read || p->burst_write) {
  1160. switch (p->burst_len) {
  1161. case GPMC_BURST_4:
  1162. case GPMC_BURST_8:
  1163. case GPMC_BURST_16:
  1164. break;
  1165. default:
  1166. pr_err("%s: invalid page/burst-length (%d)\n",
  1167. __func__, p->burst_len);
  1168. return -EINVAL;
  1169. }
  1170. }
  1171. if (p->wait_pin > gpmc_nr_waitpins) {
  1172. pr_err("%s: invalid wait-pin (%d)\n", __func__, p->wait_pin);
  1173. return -EINVAL;
  1174. }
  1175. config1 = GPMC_CONFIG1_DEVICESIZE((p->device_width - 1));
  1176. if (p->sync_read)
  1177. config1 |= GPMC_CONFIG1_READTYPE_SYNC;
  1178. if (p->sync_write)
  1179. config1 |= GPMC_CONFIG1_WRITETYPE_SYNC;
  1180. if (p->wait_on_read)
  1181. config1 |= GPMC_CONFIG1_WAIT_READ_MON;
  1182. if (p->wait_on_write)
  1183. config1 |= GPMC_CONFIG1_WAIT_WRITE_MON;
  1184. if (p->wait_on_read || p->wait_on_write)
  1185. config1 |= GPMC_CONFIG1_WAIT_PIN_SEL(p->wait_pin);
  1186. if (p->device_nand)
  1187. config1 |= GPMC_CONFIG1_DEVICETYPE(GPMC_DEVICETYPE_NAND);
  1188. if (p->mux_add_data)
  1189. config1 |= GPMC_CONFIG1_MUXTYPE(p->mux_add_data);
  1190. if (p->burst_read)
  1191. config1 |= GPMC_CONFIG1_READMULTIPLE_SUPP;
  1192. if (p->burst_write)
  1193. config1 |= GPMC_CONFIG1_WRITEMULTIPLE_SUPP;
  1194. if (p->burst_read || p->burst_write) {
  1195. config1 |= GPMC_CONFIG1_PAGE_LEN(p->burst_len >> 3);
  1196. config1 |= p->burst_wrap ? GPMC_CONFIG1_WRAPBURST_SUPP : 0;
  1197. }
  1198. gpmc_cs_write_reg(cs, GPMC_CS_CONFIG1, config1);
  1199. return 0;
  1200. }
  1201. #ifdef CONFIG_OF
  1202. static const struct of_device_id gpmc_dt_ids[] = {
  1203. { .compatible = "ti,omap2420-gpmc" },
  1204. { .compatible = "ti,omap2430-gpmc" },
  1205. { .compatible = "ti,omap3430-gpmc" }, /* omap3430 & omap3630 */
  1206. { .compatible = "ti,omap4430-gpmc" }, /* omap4430 & omap4460 & omap543x */
  1207. { .compatible = "ti,am3352-gpmc" }, /* am335x devices */
  1208. { }
  1209. };
  1210. MODULE_DEVICE_TABLE(of, gpmc_dt_ids);
  1211. /**
  1212. * gpmc_read_settings_dt - read gpmc settings from device-tree
  1213. * @np: pointer to device-tree node for a gpmc child device
  1214. * @p: pointer to gpmc settings structure
  1215. *
  1216. * Reads the GPMC settings for a GPMC child device from device-tree and
  1217. * stores them in the GPMC settings structure passed. The GPMC settings
  1218. * structure is initialised to zero by this function and so any
  1219. * previously stored settings will be cleared.
  1220. */
  1221. void gpmc_read_settings_dt(struct device_node *np, struct gpmc_settings *p)
  1222. {
  1223. memset(p, 0, sizeof(struct gpmc_settings));
  1224. p->sync_read = of_property_read_bool(np, "gpmc,sync-read");
  1225. p->sync_write = of_property_read_bool(np, "gpmc,sync-write");
  1226. of_property_read_u32(np, "gpmc,device-width", &p->device_width);
  1227. of_property_read_u32(np, "gpmc,mux-add-data", &p->mux_add_data);
  1228. if (!of_property_read_u32(np, "gpmc,burst-length", &p->burst_len)) {
  1229. p->burst_wrap = of_property_read_bool(np, "gpmc,burst-wrap");
  1230. p->burst_read = of_property_read_bool(np, "gpmc,burst-read");
  1231. p->burst_write = of_property_read_bool(np, "gpmc,burst-write");
  1232. if (!p->burst_read && !p->burst_write)
  1233. pr_warn("%s: page/burst-length set but not used!\n",
  1234. __func__);
  1235. }
  1236. if (!of_property_read_u32(np, "gpmc,wait-pin", &p->wait_pin)) {
  1237. p->wait_on_read = of_property_read_bool(np,
  1238. "gpmc,wait-on-read");
  1239. p->wait_on_write = of_property_read_bool(np,
  1240. "gpmc,wait-on-write");
  1241. if (!p->wait_on_read && !p->wait_on_write)
  1242. pr_debug("%s: rd/wr wait monitoring not enabled!\n",
  1243. __func__);
  1244. }
  1245. }
  1246. static void __maybe_unused gpmc_read_timings_dt(struct device_node *np,
  1247. struct gpmc_timings *gpmc_t)
  1248. {
  1249. struct gpmc_bool_timings *p;
  1250. if (!np || !gpmc_t)
  1251. return;
  1252. memset(gpmc_t, 0, sizeof(*gpmc_t));
  1253. /* minimum clock period for syncronous mode */
  1254. of_property_read_u32(np, "gpmc,sync-clk-ps", &gpmc_t->sync_clk);
  1255. /* chip select timtings */
  1256. of_property_read_u32(np, "gpmc,cs-on-ns", &gpmc_t->cs_on);
  1257. of_property_read_u32(np, "gpmc,cs-rd-off-ns", &gpmc_t->cs_rd_off);
  1258. of_property_read_u32(np, "gpmc,cs-wr-off-ns", &gpmc_t->cs_wr_off);
  1259. /* ADV signal timings */
  1260. of_property_read_u32(np, "gpmc,adv-on-ns", &gpmc_t->adv_on);
  1261. of_property_read_u32(np, "gpmc,adv-rd-off-ns", &gpmc_t->adv_rd_off);
  1262. of_property_read_u32(np, "gpmc,adv-wr-off-ns", &gpmc_t->adv_wr_off);
  1263. /* WE signal timings */
  1264. of_property_read_u32(np, "gpmc,we-on-ns", &gpmc_t->we_on);
  1265. of_property_read_u32(np, "gpmc,we-off-ns", &gpmc_t->we_off);
  1266. /* OE signal timings */
  1267. of_property_read_u32(np, "gpmc,oe-on-ns", &gpmc_t->oe_on);
  1268. of_property_read_u32(np, "gpmc,oe-off-ns", &gpmc_t->oe_off);
  1269. /* access and cycle timings */
  1270. of_property_read_u32(np, "gpmc,page-burst-access-ns",
  1271. &gpmc_t->page_burst_access);
  1272. of_property_read_u32(np, "gpmc,access-ns", &gpmc_t->access);
  1273. of_property_read_u32(np, "gpmc,rd-cycle-ns", &gpmc_t->rd_cycle);
  1274. of_property_read_u32(np, "gpmc,wr-cycle-ns", &gpmc_t->wr_cycle);
  1275. of_property_read_u32(np, "gpmc,bus-turnaround-ns",
  1276. &gpmc_t->bus_turnaround);
  1277. of_property_read_u32(np, "gpmc,cycle2cycle-delay-ns",
  1278. &gpmc_t->cycle2cycle_delay);
  1279. of_property_read_u32(np, "gpmc,wait-monitoring-ns",
  1280. &gpmc_t->wait_monitoring);
  1281. of_property_read_u32(np, "gpmc,clk-activation-ns",
  1282. &gpmc_t->clk_activation);
  1283. /* only applicable to OMAP3+ */
  1284. of_property_read_u32(np, "gpmc,wr-access-ns", &gpmc_t->wr_access);
  1285. of_property_read_u32(np, "gpmc,wr-data-mux-bus-ns",
  1286. &gpmc_t->wr_data_mux_bus);
  1287. /* bool timing parameters */
  1288. p = &gpmc_t->bool_timings;
  1289. p->cycle2cyclediffcsen =
  1290. of_property_read_bool(np, "gpmc,cycle2cycle-diffcsen");
  1291. p->cycle2cyclesamecsen =
  1292. of_property_read_bool(np, "gpmc,cycle2cycle-samecsen");
  1293. p->we_extra_delay = of_property_read_bool(np, "gpmc,we-extra-delay");
  1294. p->oe_extra_delay = of_property_read_bool(np, "gpmc,oe-extra-delay");
  1295. p->adv_extra_delay = of_property_read_bool(np, "gpmc,adv-extra-delay");
  1296. p->cs_extra_delay = of_property_read_bool(np, "gpmc,cs-extra-delay");
  1297. p->time_para_granularity =
  1298. of_property_read_bool(np, "gpmc,time-para-granularity");
  1299. }
  1300. #if IS_ENABLED(CONFIG_MTD_NAND)
  1301. static const char * const nand_xfer_types[] = {
  1302. [NAND_OMAP_PREFETCH_POLLED] = "prefetch-polled",
  1303. [NAND_OMAP_POLLED] = "polled",
  1304. [NAND_OMAP_PREFETCH_DMA] = "prefetch-dma",
  1305. [NAND_OMAP_PREFETCH_IRQ] = "prefetch-irq",
  1306. };
  1307. static int gpmc_probe_nand_child(struct platform_device *pdev,
  1308. struct device_node *child)
  1309. {
  1310. u32 val;
  1311. const char *s;
  1312. struct gpmc_timings gpmc_t;
  1313. struct omap_nand_platform_data *gpmc_nand_data;
  1314. if (of_property_read_u32(child, "reg", &val) < 0) {
  1315. dev_err(&pdev->dev, "%s has no 'reg' property\n",
  1316. child->full_name);
  1317. return -ENODEV;
  1318. }
  1319. gpmc_nand_data = devm_kzalloc(&pdev->dev, sizeof(*gpmc_nand_data),
  1320. GFP_KERNEL);
  1321. if (!gpmc_nand_data)
  1322. return -ENOMEM;
  1323. gpmc_nand_data->cs = val;
  1324. gpmc_nand_data->of_node = child;
  1325. /* Detect availability of ELM module */
  1326. gpmc_nand_data->elm_of_node = of_parse_phandle(child, "ti,elm-id", 0);
  1327. if (gpmc_nand_data->elm_of_node == NULL)
  1328. gpmc_nand_data->elm_of_node =
  1329. of_parse_phandle(child, "elm_id", 0);
  1330. /* select ecc-scheme for NAND */
  1331. if (of_property_read_string(child, "ti,nand-ecc-opt", &s)) {
  1332. pr_err("%s: ti,nand-ecc-opt not found\n", __func__);
  1333. return -ENODEV;
  1334. }
  1335. if (!strcmp(s, "sw"))
  1336. gpmc_nand_data->ecc_opt = OMAP_ECC_HAM1_CODE_SW;
  1337. else if (!strcmp(s, "ham1") ||
  1338. !strcmp(s, "hw") || !strcmp(s, "hw-romcode"))
  1339. gpmc_nand_data->ecc_opt =
  1340. OMAP_ECC_HAM1_CODE_HW;
  1341. else if (!strcmp(s, "bch4"))
  1342. if (gpmc_nand_data->elm_of_node)
  1343. gpmc_nand_data->ecc_opt =
  1344. OMAP_ECC_BCH4_CODE_HW;
  1345. else
  1346. gpmc_nand_data->ecc_opt =
  1347. OMAP_ECC_BCH4_CODE_HW_DETECTION_SW;
  1348. else if (!strcmp(s, "bch8"))
  1349. if (gpmc_nand_data->elm_of_node)
  1350. gpmc_nand_data->ecc_opt =
  1351. OMAP_ECC_BCH8_CODE_HW;
  1352. else
  1353. gpmc_nand_data->ecc_opt =
  1354. OMAP_ECC_BCH8_CODE_HW_DETECTION_SW;
  1355. else if (!strcmp(s, "bch16"))
  1356. if (gpmc_nand_data->elm_of_node)
  1357. gpmc_nand_data->ecc_opt =
  1358. OMAP_ECC_BCH16_CODE_HW;
  1359. else
  1360. pr_err("%s: BCH16 requires ELM support\n", __func__);
  1361. else
  1362. pr_err("%s: ti,nand-ecc-opt invalid value\n", __func__);
  1363. /* select data transfer mode for NAND controller */
  1364. if (!of_property_read_string(child, "ti,nand-xfer-type", &s))
  1365. for (val = 0; val < ARRAY_SIZE(nand_xfer_types); val++)
  1366. if (!strcasecmp(s, nand_xfer_types[val])) {
  1367. gpmc_nand_data->xfer_type = val;
  1368. break;
  1369. }
  1370. gpmc_nand_data->flash_bbt = of_get_nand_on_flash_bbt(child);
  1371. val = of_get_nand_bus_width(child);
  1372. if (val == 16)
  1373. gpmc_nand_data->devsize = NAND_BUSWIDTH_16;
  1374. gpmc_read_timings_dt(child, &gpmc_t);
  1375. gpmc_nand_init(gpmc_nand_data, &gpmc_t);
  1376. return 0;
  1377. }
  1378. #else
  1379. static int gpmc_probe_nand_child(struct platform_device *pdev,
  1380. struct device_node *child)
  1381. {
  1382. return 0;
  1383. }
  1384. #endif
  1385. #if IS_ENABLED(CONFIG_MTD_ONENAND)
  1386. static int gpmc_probe_onenand_child(struct platform_device *pdev,
  1387. struct device_node *child)
  1388. {
  1389. u32 val;
  1390. struct omap_onenand_platform_data *gpmc_onenand_data;
  1391. if (of_property_read_u32(child, "reg", &val) < 0) {
  1392. dev_err(&pdev->dev, "%s has no 'reg' property\n",
  1393. child->full_name);
  1394. return -ENODEV;
  1395. }
  1396. gpmc_onenand_data = devm_kzalloc(&pdev->dev, sizeof(*gpmc_onenand_data),
  1397. GFP_KERNEL);
  1398. if (!gpmc_onenand_data)
  1399. return -ENOMEM;
  1400. gpmc_onenand_data->cs = val;
  1401. gpmc_onenand_data->of_node = child;
  1402. gpmc_onenand_data->dma_channel = -1;
  1403. if (!of_property_read_u32(child, "dma-channel", &val))
  1404. gpmc_onenand_data->dma_channel = val;
  1405. gpmc_onenand_init(gpmc_onenand_data);
  1406. return 0;
  1407. }
  1408. #else
  1409. static int gpmc_probe_onenand_child(struct platform_device *pdev,
  1410. struct device_node *child)
  1411. {
  1412. return 0;
  1413. }
  1414. #endif
  1415. /**
  1416. * gpmc_probe_generic_child - configures the gpmc for a child device
  1417. * @pdev: pointer to gpmc platform device
  1418. * @child: pointer to device-tree node for child device
  1419. *
  1420. * Allocates and configures a GPMC chip-select for a child device.
  1421. * Returns 0 on success and appropriate negative error code on failure.
  1422. */
  1423. static int gpmc_probe_generic_child(struct platform_device *pdev,
  1424. struct device_node *child)
  1425. {
  1426. struct gpmc_settings gpmc_s;
  1427. struct gpmc_timings gpmc_t;
  1428. struct resource res;
  1429. unsigned long base;
  1430. const char *name;
  1431. int ret, cs;
  1432. u32 val;
  1433. if (of_property_read_u32(child, "reg", &cs) < 0) {
  1434. dev_err(&pdev->dev, "%s has no 'reg' property\n",
  1435. child->full_name);
  1436. return -ENODEV;
  1437. }
  1438. if (of_address_to_resource(child, 0, &res) < 0) {
  1439. dev_err(&pdev->dev, "%s has malformed 'reg' property\n",
  1440. child->full_name);
  1441. return -ENODEV;
  1442. }
  1443. /*
  1444. * Check if we have multiple instances of the same device
  1445. * on a single chip select. If so, use the already initialized
  1446. * timings.
  1447. */
  1448. name = gpmc_cs_get_name(cs);
  1449. if (name && child->name && of_node_cmp(child->name, name) == 0)
  1450. goto no_timings;
  1451. ret = gpmc_cs_request(cs, resource_size(&res), &base);
  1452. if (ret < 0) {
  1453. dev_err(&pdev->dev, "cannot request GPMC CS %d\n", cs);
  1454. return ret;
  1455. }
  1456. gpmc_cs_set_name(cs, child->name);
  1457. gpmc_read_settings_dt(child, &gpmc_s);
  1458. gpmc_read_timings_dt(child, &gpmc_t);
  1459. /*
  1460. * For some GPMC devices we still need to rely on the bootloader
  1461. * timings because the devices can be connected via FPGA.
  1462. * REVISIT: Add timing support from slls644g.pdf.
  1463. */
  1464. if (!gpmc_t.cs_rd_off) {
  1465. WARN(1, "enable GPMC debug to configure .dts timings for CS%i\n",
  1466. cs);
  1467. gpmc_cs_show_timings(cs,
  1468. "please add GPMC bootloader timings to .dts");
  1469. goto no_timings;
  1470. }
  1471. /* CS must be disabled while making changes to gpmc configuration */
  1472. gpmc_cs_disable_mem(cs);
  1473. /*
  1474. * FIXME: gpmc_cs_request() will map the CS to an arbitary
  1475. * location in the gpmc address space. When booting with
  1476. * device-tree we want the NOR flash to be mapped to the
  1477. * location specified in the device-tree blob. So remap the
  1478. * CS to this location. Once DT migration is complete should
  1479. * just make gpmc_cs_request() map a specific address.
  1480. */
  1481. ret = gpmc_cs_remap(cs, res.start);
  1482. if (ret < 0) {
  1483. dev_err(&pdev->dev, "cannot remap GPMC CS %d to %pa\n",
  1484. cs, &res.start);
  1485. goto err;
  1486. }
  1487. ret = of_property_read_u32(child, "bank-width", &gpmc_s.device_width);
  1488. if (ret < 0)
  1489. goto err;
  1490. ret = gpmc_cs_program_settings(cs, &gpmc_s);
  1491. if (ret < 0)
  1492. goto err;
  1493. ret = gpmc_cs_set_timings(cs, &gpmc_t);
  1494. if (ret) {
  1495. dev_err(&pdev->dev, "failed to set gpmc timings for: %s\n",
  1496. child->name);
  1497. goto err;
  1498. }
  1499. /* Clear limited address i.e. enable A26-A11 */
  1500. val = gpmc_read_reg(GPMC_CONFIG);
  1501. val &= ~GPMC_CONFIG_LIMITEDADDRESS;
  1502. gpmc_write_reg(GPMC_CONFIG, val);
  1503. /* Enable CS region */
  1504. gpmc_cs_enable_mem(cs);
  1505. no_timings:
  1506. if (of_platform_device_create(child, NULL, &pdev->dev))
  1507. return 0;
  1508. dev_err(&pdev->dev, "failed to create gpmc child %s\n", child->name);
  1509. ret = -ENODEV;
  1510. err:
  1511. gpmc_cs_free(cs);
  1512. return ret;
  1513. }
  1514. static int gpmc_probe_dt(struct platform_device *pdev)
  1515. {
  1516. int ret;
  1517. struct device_node *child;
  1518. const struct of_device_id *of_id =
  1519. of_match_device(gpmc_dt_ids, &pdev->dev);
  1520. if (!of_id)
  1521. return 0;
  1522. ret = of_property_read_u32(pdev->dev.of_node, "gpmc,num-cs",
  1523. &gpmc_cs_num);
  1524. if (ret < 0) {
  1525. pr_err("%s: number of chip-selects not defined\n", __func__);
  1526. return ret;
  1527. } else if (gpmc_cs_num < 1) {
  1528. pr_err("%s: all chip-selects are disabled\n", __func__);
  1529. return -EINVAL;
  1530. } else if (gpmc_cs_num > GPMC_CS_NUM) {
  1531. pr_err("%s: number of supported chip-selects cannot be > %d\n",
  1532. __func__, GPMC_CS_NUM);
  1533. return -EINVAL;
  1534. }
  1535. ret = of_property_read_u32(pdev->dev.of_node, "gpmc,num-waitpins",
  1536. &gpmc_nr_waitpins);
  1537. if (ret < 0) {
  1538. pr_err("%s: number of wait pins not found!\n", __func__);
  1539. return ret;
  1540. }
  1541. for_each_available_child_of_node(pdev->dev.of_node, child) {
  1542. if (!child->name)
  1543. continue;
  1544. if (of_node_cmp(child->name, "nand") == 0)
  1545. ret = gpmc_probe_nand_child(pdev, child);
  1546. else if (of_node_cmp(child->name, "onenand") == 0)
  1547. ret = gpmc_probe_onenand_child(pdev, child);
  1548. else if (of_node_cmp(child->name, "ethernet") == 0 ||
  1549. of_node_cmp(child->name, "nor") == 0 ||
  1550. of_node_cmp(child->name, "uart") == 0)
  1551. ret = gpmc_probe_generic_child(pdev, child);
  1552. if (WARN(ret < 0, "%s: probing gpmc child %s failed\n",
  1553. __func__, child->full_name))
  1554. of_node_put(child);
  1555. }
  1556. return 0;
  1557. }
  1558. #else
  1559. static int gpmc_probe_dt(struct platform_device *pdev)
  1560. {
  1561. return 0;
  1562. }
  1563. #endif
  1564. static int gpmc_probe(struct platform_device *pdev)
  1565. {
  1566. int rc;
  1567. u32 l;
  1568. struct resource *res;
  1569. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1570. if (res == NULL)
  1571. return -ENOENT;
  1572. phys_base = res->start;
  1573. mem_size = resource_size(res);
  1574. gpmc_base = devm_ioremap_resource(&pdev->dev, res);
  1575. if (IS_ERR(gpmc_base))
  1576. return PTR_ERR(gpmc_base);
  1577. res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  1578. if (res == NULL)
  1579. dev_warn(&pdev->dev, "Failed to get resource: irq\n");
  1580. else
  1581. gpmc_irq = res->start;
  1582. gpmc_l3_clk = devm_clk_get(&pdev->dev, "fck");
  1583. if (IS_ERR(gpmc_l3_clk)) {
  1584. dev_err(&pdev->dev, "Failed to get GPMC fck\n");
  1585. gpmc_irq = 0;
  1586. return PTR_ERR(gpmc_l3_clk);
  1587. }
  1588. if (!clk_get_rate(gpmc_l3_clk)) {
  1589. dev_err(&pdev->dev, "Invalid GPMC fck clock rate\n");
  1590. return -EINVAL;
  1591. }
  1592. pm_runtime_enable(&pdev->dev);
  1593. pm_runtime_get_sync(&pdev->dev);
  1594. gpmc_dev = &pdev->dev;
  1595. l = gpmc_read_reg(GPMC_REVISION);
  1596. /*
  1597. * FIXME: Once device-tree migration is complete the below flags
  1598. * should be populated based upon the device-tree compatible
  1599. * string. For now just use the IP revision. OMAP3+ devices have
  1600. * the wr_access and wr_data_mux_bus register fields. OMAP4+
  1601. * devices support the addr-addr-data multiplex protocol.
  1602. *
  1603. * GPMC IP revisions:
  1604. * - OMAP24xx = 2.0
  1605. * - OMAP3xxx = 5.0
  1606. * - OMAP44xx/54xx/AM335x = 6.0
  1607. */
  1608. if (GPMC_REVISION_MAJOR(l) > 0x4)
  1609. gpmc_capability = GPMC_HAS_WR_ACCESS | GPMC_HAS_WR_DATA_MUX_BUS;
  1610. if (GPMC_REVISION_MAJOR(l) > 0x5)
  1611. gpmc_capability |= GPMC_HAS_MUX_AAD;
  1612. dev_info(gpmc_dev, "GPMC revision %d.%d\n", GPMC_REVISION_MAJOR(l),
  1613. GPMC_REVISION_MINOR(l));
  1614. gpmc_mem_init();
  1615. if (gpmc_setup_irq() < 0)
  1616. dev_warn(gpmc_dev, "gpmc_setup_irq failed\n");
  1617. if (!pdev->dev.of_node) {
  1618. gpmc_cs_num = GPMC_CS_NUM;
  1619. gpmc_nr_waitpins = GPMC_NR_WAITPINS;
  1620. }
  1621. rc = gpmc_probe_dt(pdev);
  1622. if (rc < 0) {
  1623. pm_runtime_put_sync(&pdev->dev);
  1624. dev_err(gpmc_dev, "failed to probe DT parameters\n");
  1625. return rc;
  1626. }
  1627. return 0;
  1628. }
  1629. static int gpmc_remove(struct platform_device *pdev)
  1630. {
  1631. gpmc_free_irq();
  1632. gpmc_mem_exit();
  1633. pm_runtime_put_sync(&pdev->dev);
  1634. pm_runtime_disable(&pdev->dev);
  1635. gpmc_dev = NULL;
  1636. return 0;
  1637. }
  1638. #ifdef CONFIG_PM_SLEEP
  1639. static int gpmc_suspend(struct device *dev)
  1640. {
  1641. omap3_gpmc_save_context();
  1642. pm_runtime_put_sync(dev);
  1643. return 0;
  1644. }
  1645. static int gpmc_resume(struct device *dev)
  1646. {
  1647. pm_runtime_get_sync(dev);
  1648. omap3_gpmc_restore_context();
  1649. return 0;
  1650. }
  1651. #endif
  1652. static SIMPLE_DEV_PM_OPS(gpmc_pm_ops, gpmc_suspend, gpmc_resume);
  1653. static struct platform_driver gpmc_driver = {
  1654. .probe = gpmc_probe,
  1655. .remove = gpmc_remove,
  1656. .driver = {
  1657. .name = DEVICE_NAME,
  1658. .of_match_table = of_match_ptr(gpmc_dt_ids),
  1659. .pm = &gpmc_pm_ops,
  1660. },
  1661. };
  1662. static __init int gpmc_init(void)
  1663. {
  1664. return platform_driver_register(&gpmc_driver);
  1665. }
  1666. static __exit void gpmc_exit(void)
  1667. {
  1668. platform_driver_unregister(&gpmc_driver);
  1669. }
  1670. postcore_initcall(gpmc_init);
  1671. module_exit(gpmc_exit);
  1672. static irqreturn_t gpmc_handle_irq(int irq, void *dev)
  1673. {
  1674. int i;
  1675. u32 regval;
  1676. regval = gpmc_read_reg(GPMC_IRQSTATUS);
  1677. if (!regval)
  1678. return IRQ_NONE;
  1679. for (i = 0; i < GPMC_NR_IRQ; i++)
  1680. if (regval & gpmc_client_irq[i].bitmask)
  1681. generic_handle_irq(gpmc_client_irq[i].irq);
  1682. gpmc_write_reg(GPMC_IRQSTATUS, regval);
  1683. return IRQ_HANDLED;
  1684. }
  1685. static struct omap3_gpmc_regs gpmc_context;
  1686. void omap3_gpmc_save_context(void)
  1687. {
  1688. int i;
  1689. gpmc_context.sysconfig = gpmc_read_reg(GPMC_SYSCONFIG);
  1690. gpmc_context.irqenable = gpmc_read_reg(GPMC_IRQENABLE);
  1691. gpmc_context.timeout_ctrl = gpmc_read_reg(GPMC_TIMEOUT_CONTROL);
  1692. gpmc_context.config = gpmc_read_reg(GPMC_CONFIG);
  1693. gpmc_context.prefetch_config1 = gpmc_read_reg(GPMC_PREFETCH_CONFIG1);
  1694. gpmc_context.prefetch_config2 = gpmc_read_reg(GPMC_PREFETCH_CONFIG2);
  1695. gpmc_context.prefetch_control = gpmc_read_reg(GPMC_PREFETCH_CONTROL);
  1696. for (i = 0; i < gpmc_cs_num; i++) {
  1697. gpmc_context.cs_context[i].is_valid = gpmc_cs_mem_enabled(i);
  1698. if (gpmc_context.cs_context[i].is_valid) {
  1699. gpmc_context.cs_context[i].config1 =
  1700. gpmc_cs_read_reg(i, GPMC_CS_CONFIG1);
  1701. gpmc_context.cs_context[i].config2 =
  1702. gpmc_cs_read_reg(i, GPMC_CS_CONFIG2);
  1703. gpmc_context.cs_context[i].config3 =
  1704. gpmc_cs_read_reg(i, GPMC_CS_CONFIG3);
  1705. gpmc_context.cs_context[i].config4 =
  1706. gpmc_cs_read_reg(i, GPMC_CS_CONFIG4);
  1707. gpmc_context.cs_context[i].config5 =
  1708. gpmc_cs_read_reg(i, GPMC_CS_CONFIG5);
  1709. gpmc_context.cs_context[i].config6 =
  1710. gpmc_cs_read_reg(i, GPMC_CS_CONFIG6);
  1711. gpmc_context.cs_context[i].config7 =
  1712. gpmc_cs_read_reg(i, GPMC_CS_CONFIG7);
  1713. }
  1714. }
  1715. }
  1716. void omap3_gpmc_restore_context(void)
  1717. {
  1718. int i;
  1719. gpmc_write_reg(GPMC_SYSCONFIG, gpmc_context.sysconfig);
  1720. gpmc_write_reg(GPMC_IRQENABLE, gpmc_context.irqenable);
  1721. gpmc_write_reg(GPMC_TIMEOUT_CONTROL, gpmc_context.timeout_ctrl);
  1722. gpmc_write_reg(GPMC_CONFIG, gpmc_context.config);
  1723. gpmc_write_reg(GPMC_PREFETCH_CONFIG1, gpmc_context.prefetch_config1);
  1724. gpmc_write_reg(GPMC_PREFETCH_CONFIG2, gpmc_context.prefetch_config2);
  1725. gpmc_write_reg(GPMC_PREFETCH_CONTROL, gpmc_context.prefetch_control);
  1726. for (i = 0; i < gpmc_cs_num; i++) {
  1727. if (gpmc_context.cs_context[i].is_valid) {
  1728. gpmc_cs_write_reg(i, GPMC_CS_CONFIG1,
  1729. gpmc_context.cs_context[i].config1);
  1730. gpmc_cs_write_reg(i, GPMC_CS_CONFIG2,
  1731. gpmc_context.cs_context[i].config2);
  1732. gpmc_cs_write_reg(i, GPMC_CS_CONFIG3,
  1733. gpmc_context.cs_context[i].config3);
  1734. gpmc_cs_write_reg(i, GPMC_CS_CONFIG4,
  1735. gpmc_context.cs_context[i].config4);
  1736. gpmc_cs_write_reg(i, GPMC_CS_CONFIG5,
  1737. gpmc_context.cs_context[i].config5);
  1738. gpmc_cs_write_reg(i, GPMC_CS_CONFIG6,
  1739. gpmc_context.cs_context[i].config6);
  1740. gpmc_cs_write_reg(i, GPMC_CS_CONFIG7,
  1741. gpmc_context.cs_context[i].config7);
  1742. }
  1743. }
  1744. }