emif.c 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670
  1. /*
  2. * EMIF driver
  3. *
  4. * Copyright (C) 2012 Texas Instruments, Inc.
  5. *
  6. * Aneesh V <aneesh@ti.com>
  7. * Santosh Shilimkar <santosh.shilimkar@ti.com>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. */
  13. #include <linux/kernel.h>
  14. #include <linux/reboot.h>
  15. #include <linux/platform_data/emif_plat.h>
  16. #include <linux/io.h>
  17. #include <linux/device.h>
  18. #include <linux/platform_device.h>
  19. #include <linux/interrupt.h>
  20. #include <linux/slab.h>
  21. #include <linux/debugfs.h>
  22. #include <linux/seq_file.h>
  23. #include <linux/module.h>
  24. #include <linux/list.h>
  25. #include <linux/spinlock.h>
  26. #include <memory/jedec_ddr.h>
  27. #include "emif.h"
  28. /**
  29. * struct emif_data - Per device static data for driver's use
  30. * @duplicate: Whether the DDR devices attached to this EMIF
  31. * instance are exactly same as that on EMIF1. In
  32. * this case we can save some memory and processing
  33. * @temperature_level: Maximum temperature of LPDDR2 devices attached
  34. * to this EMIF - read from MR4 register. If there
  35. * are two devices attached to this EMIF, this
  36. * value is the maximum of the two temperature
  37. * levels.
  38. * @node: node in the device list
  39. * @base: base address of memory-mapped IO registers.
  40. * @dev: device pointer.
  41. * @addressing table with addressing information from the spec
  42. * @regs_cache: An array of 'struct emif_regs' that stores
  43. * calculated register values for different
  44. * frequencies, to avoid re-calculating them on
  45. * each DVFS transition.
  46. * @curr_regs: The set of register values used in the last
  47. * frequency change (i.e. corresponding to the
  48. * frequency in effect at the moment)
  49. * @plat_data: Pointer to saved platform data.
  50. * @debugfs_root: dentry to the root folder for EMIF in debugfs
  51. */
  52. struct emif_data {
  53. u8 duplicate;
  54. u8 temperature_level;
  55. u8 lpmode;
  56. struct list_head node;
  57. unsigned long irq_state;
  58. void __iomem *base;
  59. struct device *dev;
  60. const struct lpddr2_addressing *addressing;
  61. struct emif_regs *regs_cache[EMIF_MAX_NUM_FREQUENCIES];
  62. struct emif_regs *curr_regs;
  63. struct emif_platform_data *plat_data;
  64. struct dentry *debugfs_root;
  65. };
  66. static struct emif_data *emif1;
  67. static spinlock_t emif_lock;
  68. static unsigned long irq_state;
  69. static u32 t_ck; /* DDR clock period in ps */
  70. static LIST_HEAD(device_list);
  71. static void do_emif_regdump_show(struct seq_file *s, struct emif_data *emif,
  72. struct emif_regs *regs)
  73. {
  74. u32 type = emif->plat_data->device_info->type;
  75. u32 ip_rev = emif->plat_data->ip_rev;
  76. seq_printf(s, "EMIF register cache dump for %dMHz\n",
  77. regs->freq/1000000);
  78. seq_printf(s, "ref_ctrl_shdw\t: 0x%08x\n", regs->ref_ctrl_shdw);
  79. seq_printf(s, "sdram_tim1_shdw\t: 0x%08x\n", regs->sdram_tim1_shdw);
  80. seq_printf(s, "sdram_tim2_shdw\t: 0x%08x\n", regs->sdram_tim2_shdw);
  81. seq_printf(s, "sdram_tim3_shdw\t: 0x%08x\n", regs->sdram_tim3_shdw);
  82. if (ip_rev == EMIF_4D) {
  83. seq_printf(s, "read_idle_ctrl_shdw_normal\t: 0x%08x\n",
  84. regs->read_idle_ctrl_shdw_normal);
  85. seq_printf(s, "read_idle_ctrl_shdw_volt_ramp\t: 0x%08x\n",
  86. regs->read_idle_ctrl_shdw_volt_ramp);
  87. } else if (ip_rev == EMIF_4D5) {
  88. seq_printf(s, "dll_calib_ctrl_shdw_normal\t: 0x%08x\n",
  89. regs->dll_calib_ctrl_shdw_normal);
  90. seq_printf(s, "dll_calib_ctrl_shdw_volt_ramp\t: 0x%08x\n",
  91. regs->dll_calib_ctrl_shdw_volt_ramp);
  92. }
  93. if (type == DDR_TYPE_LPDDR2_S2 || type == DDR_TYPE_LPDDR2_S4) {
  94. seq_printf(s, "ref_ctrl_shdw_derated\t: 0x%08x\n",
  95. regs->ref_ctrl_shdw_derated);
  96. seq_printf(s, "sdram_tim1_shdw_derated\t: 0x%08x\n",
  97. regs->sdram_tim1_shdw_derated);
  98. seq_printf(s, "sdram_tim3_shdw_derated\t: 0x%08x\n",
  99. regs->sdram_tim3_shdw_derated);
  100. }
  101. }
  102. static int emif_regdump_show(struct seq_file *s, void *unused)
  103. {
  104. struct emif_data *emif = s->private;
  105. struct emif_regs **regs_cache;
  106. int i;
  107. if (emif->duplicate)
  108. regs_cache = emif1->regs_cache;
  109. else
  110. regs_cache = emif->regs_cache;
  111. for (i = 0; i < EMIF_MAX_NUM_FREQUENCIES && regs_cache[i]; i++) {
  112. do_emif_regdump_show(s, emif, regs_cache[i]);
  113. seq_printf(s, "\n");
  114. }
  115. return 0;
  116. }
  117. static int emif_regdump_open(struct inode *inode, struct file *file)
  118. {
  119. return single_open(file, emif_regdump_show, inode->i_private);
  120. }
  121. static const struct file_operations emif_regdump_fops = {
  122. .open = emif_regdump_open,
  123. .read = seq_read,
  124. .release = single_release,
  125. };
  126. static int emif_mr4_show(struct seq_file *s, void *unused)
  127. {
  128. struct emif_data *emif = s->private;
  129. seq_printf(s, "MR4=%d\n", emif->temperature_level);
  130. return 0;
  131. }
  132. static int emif_mr4_open(struct inode *inode, struct file *file)
  133. {
  134. return single_open(file, emif_mr4_show, inode->i_private);
  135. }
  136. static const struct file_operations emif_mr4_fops = {
  137. .open = emif_mr4_open,
  138. .read = seq_read,
  139. .release = single_release,
  140. };
  141. static int __init_or_module emif_debugfs_init(struct emif_data *emif)
  142. {
  143. struct dentry *dentry;
  144. int ret;
  145. dentry = debugfs_create_dir(dev_name(emif->dev), NULL);
  146. if (IS_ERR(dentry)) {
  147. ret = PTR_ERR(dentry);
  148. goto err0;
  149. }
  150. emif->debugfs_root = dentry;
  151. dentry = debugfs_create_file("regcache_dump", S_IRUGO,
  152. emif->debugfs_root, emif, &emif_regdump_fops);
  153. if (IS_ERR(dentry)) {
  154. ret = PTR_ERR(dentry);
  155. goto err1;
  156. }
  157. dentry = debugfs_create_file("mr4", S_IRUGO,
  158. emif->debugfs_root, emif, &emif_mr4_fops);
  159. if (IS_ERR(dentry)) {
  160. ret = PTR_ERR(dentry);
  161. goto err1;
  162. }
  163. return 0;
  164. err1:
  165. debugfs_remove_recursive(emif->debugfs_root);
  166. err0:
  167. return ret;
  168. }
  169. static void __exit emif_debugfs_exit(struct emif_data *emif)
  170. {
  171. debugfs_remove_recursive(emif->debugfs_root);
  172. emif->debugfs_root = NULL;
  173. }
  174. /*
  175. * Calculate the period of DDR clock from frequency value
  176. */
  177. static void set_ddr_clk_period(u32 freq)
  178. {
  179. /* Divide 10^12 by frequency to get period in ps */
  180. t_ck = (u32)DIV_ROUND_UP_ULL(1000000000000ull, freq);
  181. }
  182. /*
  183. * Get bus width used by EMIF. Note that this may be different from the
  184. * bus width of the DDR devices used. For instance two 16-bit DDR devices
  185. * may be connected to a given CS of EMIF. In this case bus width as far
  186. * as EMIF is concerned is 32, where as the DDR bus width is 16 bits.
  187. */
  188. static u32 get_emif_bus_width(struct emif_data *emif)
  189. {
  190. u32 width;
  191. void __iomem *base = emif->base;
  192. width = (readl(base + EMIF_SDRAM_CONFIG) & NARROW_MODE_MASK)
  193. >> NARROW_MODE_SHIFT;
  194. width = width == 0 ? 32 : 16;
  195. return width;
  196. }
  197. /*
  198. * Get the CL from SDRAM_CONFIG register
  199. */
  200. static u32 get_cl(struct emif_data *emif)
  201. {
  202. u32 cl;
  203. void __iomem *base = emif->base;
  204. cl = (readl(base + EMIF_SDRAM_CONFIG) & CL_MASK) >> CL_SHIFT;
  205. return cl;
  206. }
  207. static void set_lpmode(struct emif_data *emif, u8 lpmode)
  208. {
  209. u32 temp;
  210. void __iomem *base = emif->base;
  211. temp = readl(base + EMIF_POWER_MANAGEMENT_CONTROL);
  212. temp &= ~LP_MODE_MASK;
  213. temp |= (lpmode << LP_MODE_SHIFT);
  214. writel(temp, base + EMIF_POWER_MANAGEMENT_CONTROL);
  215. }
  216. static void do_freq_update(void)
  217. {
  218. struct emif_data *emif;
  219. /*
  220. * Workaround for errata i728: Disable LPMODE during FREQ_UPDATE
  221. *
  222. * i728 DESCRIPTION:
  223. * The EMIF automatically puts the SDRAM into self-refresh mode
  224. * after the EMIF has not performed accesses during
  225. * EMIF_PWR_MGMT_CTRL[7:4] REG_SR_TIM number of DDR clock cycles
  226. * and the EMIF_PWR_MGMT_CTRL[10:8] REG_LP_MODE bit field is set
  227. * to 0x2. If during a small window the following three events
  228. * occur:
  229. * - The SR_TIMING counter expires
  230. * - And frequency change is requested
  231. * - And OCP access is requested
  232. * Then it causes instable clock on the DDR interface.
  233. *
  234. * WORKAROUND
  235. * To avoid the occurrence of the three events, the workaround
  236. * is to disable the self-refresh when requesting a frequency
  237. * change. Before requesting a frequency change the software must
  238. * program EMIF_PWR_MGMT_CTRL[10:8] REG_LP_MODE to 0x0. When the
  239. * frequency change has been done, the software can reprogram
  240. * EMIF_PWR_MGMT_CTRL[10:8] REG_LP_MODE to 0x2
  241. */
  242. list_for_each_entry(emif, &device_list, node) {
  243. if (emif->lpmode == EMIF_LP_MODE_SELF_REFRESH)
  244. set_lpmode(emif, EMIF_LP_MODE_DISABLE);
  245. }
  246. /*
  247. * TODO: Do FREQ_UPDATE here when an API
  248. * is available for this as part of the new
  249. * clock framework
  250. */
  251. list_for_each_entry(emif, &device_list, node) {
  252. if (emif->lpmode == EMIF_LP_MODE_SELF_REFRESH)
  253. set_lpmode(emif, EMIF_LP_MODE_SELF_REFRESH);
  254. }
  255. }
  256. /* Find addressing table entry based on the device's type and density */
  257. static const struct lpddr2_addressing *get_addressing_table(
  258. const struct ddr_device_info *device_info)
  259. {
  260. u32 index, type, density;
  261. type = device_info->type;
  262. density = device_info->density;
  263. switch (type) {
  264. case DDR_TYPE_LPDDR2_S4:
  265. index = density - 1;
  266. break;
  267. case DDR_TYPE_LPDDR2_S2:
  268. switch (density) {
  269. case DDR_DENSITY_1Gb:
  270. case DDR_DENSITY_2Gb:
  271. index = density + 3;
  272. break;
  273. default:
  274. index = density - 1;
  275. }
  276. break;
  277. default:
  278. return NULL;
  279. }
  280. return &lpddr2_jedec_addressing_table[index];
  281. }
  282. /*
  283. * Find the the right timing table from the array of timing
  284. * tables of the device using DDR clock frequency
  285. */
  286. static const struct lpddr2_timings *get_timings_table(struct emif_data *emif,
  287. u32 freq)
  288. {
  289. u32 i, min, max, freq_nearest;
  290. const struct lpddr2_timings *timings = NULL;
  291. const struct lpddr2_timings *timings_arr = emif->plat_data->timings;
  292. struct device *dev = emif->dev;
  293. /* Start with a very high frequency - 1GHz */
  294. freq_nearest = 1000000000;
  295. /*
  296. * Find the timings table such that:
  297. * 1. the frequency range covers the required frequency(safe) AND
  298. * 2. the max_freq is closest to the required frequency(optimal)
  299. */
  300. for (i = 0; i < emif->plat_data->timings_arr_size; i++) {
  301. max = timings_arr[i].max_freq;
  302. min = timings_arr[i].min_freq;
  303. if ((freq >= min) && (freq <= max) && (max < freq_nearest)) {
  304. freq_nearest = max;
  305. timings = &timings_arr[i];
  306. }
  307. }
  308. if (!timings)
  309. dev_err(dev, "%s: couldn't find timings for - %dHz\n",
  310. __func__, freq);
  311. dev_dbg(dev, "%s: timings table: freq %d, speed bin freq %d\n",
  312. __func__, freq, freq_nearest);
  313. return timings;
  314. }
  315. static u32 get_sdram_ref_ctrl_shdw(u32 freq,
  316. const struct lpddr2_addressing *addressing)
  317. {
  318. u32 ref_ctrl_shdw = 0, val = 0, freq_khz, t_refi;
  319. /* Scale down frequency and t_refi to avoid overflow */
  320. freq_khz = freq / 1000;
  321. t_refi = addressing->tREFI_ns / 100;
  322. /*
  323. * refresh rate to be set is 'tREFI(in us) * freq in MHz
  324. * division by 10000 to account for change in units
  325. */
  326. val = t_refi * freq_khz / 10000;
  327. ref_ctrl_shdw |= val << REFRESH_RATE_SHIFT;
  328. return ref_ctrl_shdw;
  329. }
  330. static u32 get_sdram_tim_1_shdw(const struct lpddr2_timings *timings,
  331. const struct lpddr2_min_tck *min_tck,
  332. const struct lpddr2_addressing *addressing)
  333. {
  334. u32 tim1 = 0, val = 0;
  335. val = max(min_tck->tWTR, DIV_ROUND_UP(timings->tWTR, t_ck)) - 1;
  336. tim1 |= val << T_WTR_SHIFT;
  337. if (addressing->num_banks == B8)
  338. val = DIV_ROUND_UP(timings->tFAW, t_ck*4);
  339. else
  340. val = max(min_tck->tRRD, DIV_ROUND_UP(timings->tRRD, t_ck));
  341. tim1 |= (val - 1) << T_RRD_SHIFT;
  342. val = DIV_ROUND_UP(timings->tRAS_min + timings->tRPab, t_ck) - 1;
  343. tim1 |= val << T_RC_SHIFT;
  344. val = max(min_tck->tRASmin, DIV_ROUND_UP(timings->tRAS_min, t_ck));
  345. tim1 |= (val - 1) << T_RAS_SHIFT;
  346. val = max(min_tck->tWR, DIV_ROUND_UP(timings->tWR, t_ck)) - 1;
  347. tim1 |= val << T_WR_SHIFT;
  348. val = max(min_tck->tRCD, DIV_ROUND_UP(timings->tRCD, t_ck)) - 1;
  349. tim1 |= val << T_RCD_SHIFT;
  350. val = max(min_tck->tRPab, DIV_ROUND_UP(timings->tRPab, t_ck)) - 1;
  351. tim1 |= val << T_RP_SHIFT;
  352. return tim1;
  353. }
  354. static u32 get_sdram_tim_1_shdw_derated(const struct lpddr2_timings *timings,
  355. const struct lpddr2_min_tck *min_tck,
  356. const struct lpddr2_addressing *addressing)
  357. {
  358. u32 tim1 = 0, val = 0;
  359. val = max(min_tck->tWTR, DIV_ROUND_UP(timings->tWTR, t_ck)) - 1;
  360. tim1 = val << T_WTR_SHIFT;
  361. /*
  362. * tFAW is approximately 4 times tRRD. So add 1875*4 = 7500ps
  363. * to tFAW for de-rating
  364. */
  365. if (addressing->num_banks == B8) {
  366. val = DIV_ROUND_UP(timings->tFAW + 7500, 4 * t_ck) - 1;
  367. } else {
  368. val = DIV_ROUND_UP(timings->tRRD + 1875, t_ck);
  369. val = max(min_tck->tRRD, val) - 1;
  370. }
  371. tim1 |= val << T_RRD_SHIFT;
  372. val = DIV_ROUND_UP(timings->tRAS_min + timings->tRPab + 1875, t_ck);
  373. tim1 |= (val - 1) << T_RC_SHIFT;
  374. val = DIV_ROUND_UP(timings->tRAS_min + 1875, t_ck);
  375. val = max(min_tck->tRASmin, val) - 1;
  376. tim1 |= val << T_RAS_SHIFT;
  377. val = max(min_tck->tWR, DIV_ROUND_UP(timings->tWR, t_ck)) - 1;
  378. tim1 |= val << T_WR_SHIFT;
  379. val = max(min_tck->tRCD, DIV_ROUND_UP(timings->tRCD + 1875, t_ck));
  380. tim1 |= (val - 1) << T_RCD_SHIFT;
  381. val = max(min_tck->tRPab, DIV_ROUND_UP(timings->tRPab + 1875, t_ck));
  382. tim1 |= (val - 1) << T_RP_SHIFT;
  383. return tim1;
  384. }
  385. static u32 get_sdram_tim_2_shdw(const struct lpddr2_timings *timings,
  386. const struct lpddr2_min_tck *min_tck,
  387. const struct lpddr2_addressing *addressing,
  388. u32 type)
  389. {
  390. u32 tim2 = 0, val = 0;
  391. val = min_tck->tCKE - 1;
  392. tim2 |= val << T_CKE_SHIFT;
  393. val = max(min_tck->tRTP, DIV_ROUND_UP(timings->tRTP, t_ck)) - 1;
  394. tim2 |= val << T_RTP_SHIFT;
  395. /* tXSNR = tRFCab_ps + 10 ns(tRFCab_ps for LPDDR2). */
  396. val = DIV_ROUND_UP(addressing->tRFCab_ps + 10000, t_ck) - 1;
  397. tim2 |= val << T_XSNR_SHIFT;
  398. /* XSRD same as XSNR for LPDDR2 */
  399. tim2 |= val << T_XSRD_SHIFT;
  400. val = max(min_tck->tXP, DIV_ROUND_UP(timings->tXP, t_ck)) - 1;
  401. tim2 |= val << T_XP_SHIFT;
  402. return tim2;
  403. }
  404. static u32 get_sdram_tim_3_shdw(const struct lpddr2_timings *timings,
  405. const struct lpddr2_min_tck *min_tck,
  406. const struct lpddr2_addressing *addressing,
  407. u32 type, u32 ip_rev, u32 derated)
  408. {
  409. u32 tim3 = 0, val = 0, t_dqsck;
  410. val = timings->tRAS_max_ns / addressing->tREFI_ns - 1;
  411. val = val > 0xF ? 0xF : val;
  412. tim3 |= val << T_RAS_MAX_SHIFT;
  413. val = DIV_ROUND_UP(addressing->tRFCab_ps, t_ck) - 1;
  414. tim3 |= val << T_RFC_SHIFT;
  415. t_dqsck = (derated == EMIF_DERATED_TIMINGS) ?
  416. timings->tDQSCK_max_derated : timings->tDQSCK_max;
  417. if (ip_rev == EMIF_4D5)
  418. val = DIV_ROUND_UP(t_dqsck + 1000, t_ck) - 1;
  419. else
  420. val = DIV_ROUND_UP(t_dqsck, t_ck) - 1;
  421. tim3 |= val << T_TDQSCKMAX_SHIFT;
  422. val = DIV_ROUND_UP(timings->tZQCS, t_ck) - 1;
  423. tim3 |= val << ZQ_ZQCS_SHIFT;
  424. val = DIV_ROUND_UP(timings->tCKESR, t_ck);
  425. val = max(min_tck->tCKESR, val) - 1;
  426. tim3 |= val << T_CKESR_SHIFT;
  427. if (ip_rev == EMIF_4D5) {
  428. tim3 |= (EMIF_T_CSTA - 1) << T_CSTA_SHIFT;
  429. val = DIV_ROUND_UP(EMIF_T_PDLL_UL, 128) - 1;
  430. tim3 |= val << T_PDLL_UL_SHIFT;
  431. }
  432. return tim3;
  433. }
  434. static u32 get_zq_config_reg(const struct lpddr2_addressing *addressing,
  435. bool cs1_used, bool cal_resistors_per_cs)
  436. {
  437. u32 zq = 0, val = 0;
  438. val = EMIF_ZQCS_INTERVAL_US * 1000 / addressing->tREFI_ns;
  439. zq |= val << ZQ_REFINTERVAL_SHIFT;
  440. val = DIV_ROUND_UP(T_ZQCL_DEFAULT_NS, T_ZQCS_DEFAULT_NS) - 1;
  441. zq |= val << ZQ_ZQCL_MULT_SHIFT;
  442. val = DIV_ROUND_UP(T_ZQINIT_DEFAULT_NS, T_ZQCL_DEFAULT_NS) - 1;
  443. zq |= val << ZQ_ZQINIT_MULT_SHIFT;
  444. zq |= ZQ_SFEXITEN_ENABLE << ZQ_SFEXITEN_SHIFT;
  445. if (cal_resistors_per_cs)
  446. zq |= ZQ_DUALCALEN_ENABLE << ZQ_DUALCALEN_SHIFT;
  447. else
  448. zq |= ZQ_DUALCALEN_DISABLE << ZQ_DUALCALEN_SHIFT;
  449. zq |= ZQ_CS0EN_MASK; /* CS0 is used for sure */
  450. val = cs1_used ? 1 : 0;
  451. zq |= val << ZQ_CS1EN_SHIFT;
  452. return zq;
  453. }
  454. static u32 get_temp_alert_config(const struct lpddr2_addressing *addressing,
  455. const struct emif_custom_configs *custom_configs, bool cs1_used,
  456. u32 sdram_io_width, u32 emif_bus_width)
  457. {
  458. u32 alert = 0, interval, devcnt;
  459. if (custom_configs && (custom_configs->mask &
  460. EMIF_CUSTOM_CONFIG_TEMP_ALERT_POLL_INTERVAL))
  461. interval = custom_configs->temp_alert_poll_interval_ms;
  462. else
  463. interval = TEMP_ALERT_POLL_INTERVAL_DEFAULT_MS;
  464. interval *= 1000000; /* Convert to ns */
  465. interval /= addressing->tREFI_ns; /* Convert to refresh cycles */
  466. alert |= (interval << TA_REFINTERVAL_SHIFT);
  467. /*
  468. * sdram_io_width is in 'log2(x) - 1' form. Convert emif_bus_width
  469. * also to this form and subtract to get TA_DEVCNT, which is
  470. * in log2(x) form.
  471. */
  472. emif_bus_width = __fls(emif_bus_width) - 1;
  473. devcnt = emif_bus_width - sdram_io_width;
  474. alert |= devcnt << TA_DEVCNT_SHIFT;
  475. /* DEVWDT is in 'log2(x) - 3' form */
  476. alert |= (sdram_io_width - 2) << TA_DEVWDT_SHIFT;
  477. alert |= 1 << TA_SFEXITEN_SHIFT;
  478. alert |= 1 << TA_CS0EN_SHIFT;
  479. alert |= (cs1_used ? 1 : 0) << TA_CS1EN_SHIFT;
  480. return alert;
  481. }
  482. static u32 get_read_idle_ctrl_shdw(u8 volt_ramp)
  483. {
  484. u32 idle = 0, val = 0;
  485. /*
  486. * Maximum value in normal conditions and increased frequency
  487. * when voltage is ramping
  488. */
  489. if (volt_ramp)
  490. val = READ_IDLE_INTERVAL_DVFS / t_ck / 64 - 1;
  491. else
  492. val = 0x1FF;
  493. /*
  494. * READ_IDLE_CTRL register in EMIF4D has same offset and fields
  495. * as DLL_CALIB_CTRL in EMIF4D5, so use the same shifts
  496. */
  497. idle |= val << DLL_CALIB_INTERVAL_SHIFT;
  498. idle |= EMIF_READ_IDLE_LEN_VAL << ACK_WAIT_SHIFT;
  499. return idle;
  500. }
  501. static u32 get_dll_calib_ctrl_shdw(u8 volt_ramp)
  502. {
  503. u32 calib = 0, val = 0;
  504. if (volt_ramp == DDR_VOLTAGE_RAMPING)
  505. val = DLL_CALIB_INTERVAL_DVFS / t_ck / 16 - 1;
  506. else
  507. val = 0; /* Disabled when voltage is stable */
  508. calib |= val << DLL_CALIB_INTERVAL_SHIFT;
  509. calib |= DLL_CALIB_ACK_WAIT_VAL << ACK_WAIT_SHIFT;
  510. return calib;
  511. }
  512. static u32 get_ddr_phy_ctrl_1_attilaphy_4d(const struct lpddr2_timings *timings,
  513. u32 freq, u8 RL)
  514. {
  515. u32 phy = EMIF_DDR_PHY_CTRL_1_BASE_VAL_ATTILAPHY, val = 0;
  516. val = RL + DIV_ROUND_UP(timings->tDQSCK_max, t_ck) - 1;
  517. phy |= val << READ_LATENCY_SHIFT_4D;
  518. if (freq <= 100000000)
  519. val = EMIF_DLL_SLAVE_DLY_CTRL_100_MHZ_AND_LESS_ATTILAPHY;
  520. else if (freq <= 200000000)
  521. val = EMIF_DLL_SLAVE_DLY_CTRL_200_MHZ_ATTILAPHY;
  522. else
  523. val = EMIF_DLL_SLAVE_DLY_CTRL_400_MHZ_ATTILAPHY;
  524. phy |= val << DLL_SLAVE_DLY_CTRL_SHIFT_4D;
  525. return phy;
  526. }
  527. static u32 get_phy_ctrl_1_intelliphy_4d5(u32 freq, u8 cl)
  528. {
  529. u32 phy = EMIF_DDR_PHY_CTRL_1_BASE_VAL_INTELLIPHY, half_delay;
  530. /*
  531. * DLL operates at 266 MHz. If DDR frequency is near 266 MHz,
  532. * half-delay is not needed else set half-delay
  533. */
  534. if (freq >= 265000000 && freq < 267000000)
  535. half_delay = 0;
  536. else
  537. half_delay = 1;
  538. phy |= half_delay << DLL_HALF_DELAY_SHIFT_4D5;
  539. phy |= ((cl + DIV_ROUND_UP(EMIF_PHY_TOTAL_READ_LATENCY_INTELLIPHY_PS,
  540. t_ck) - 1) << READ_LATENCY_SHIFT_4D5);
  541. return phy;
  542. }
  543. static u32 get_ext_phy_ctrl_2_intelliphy_4d5(void)
  544. {
  545. u32 fifo_we_slave_ratio;
  546. fifo_we_slave_ratio = DIV_ROUND_CLOSEST(
  547. EMIF_INTELLI_PHY_DQS_GATE_OPENING_DELAY_PS * 256 , t_ck);
  548. return fifo_we_slave_ratio | fifo_we_slave_ratio << 11 |
  549. fifo_we_slave_ratio << 22;
  550. }
  551. static u32 get_ext_phy_ctrl_3_intelliphy_4d5(void)
  552. {
  553. u32 fifo_we_slave_ratio;
  554. fifo_we_slave_ratio = DIV_ROUND_CLOSEST(
  555. EMIF_INTELLI_PHY_DQS_GATE_OPENING_DELAY_PS * 256 , t_ck);
  556. return fifo_we_slave_ratio >> 10 | fifo_we_slave_ratio << 1 |
  557. fifo_we_slave_ratio << 12 | fifo_we_slave_ratio << 23;
  558. }
  559. static u32 get_ext_phy_ctrl_4_intelliphy_4d5(void)
  560. {
  561. u32 fifo_we_slave_ratio;
  562. fifo_we_slave_ratio = DIV_ROUND_CLOSEST(
  563. EMIF_INTELLI_PHY_DQS_GATE_OPENING_DELAY_PS * 256 , t_ck);
  564. return fifo_we_slave_ratio >> 9 | fifo_we_slave_ratio << 2 |
  565. fifo_we_slave_ratio << 13;
  566. }
  567. static u32 get_pwr_mgmt_ctrl(u32 freq, struct emif_data *emif, u32 ip_rev)
  568. {
  569. u32 pwr_mgmt_ctrl = 0, timeout;
  570. u32 lpmode = EMIF_LP_MODE_SELF_REFRESH;
  571. u32 timeout_perf = EMIF_LP_MODE_TIMEOUT_PERFORMANCE;
  572. u32 timeout_pwr = EMIF_LP_MODE_TIMEOUT_POWER;
  573. u32 freq_threshold = EMIF_LP_MODE_FREQ_THRESHOLD;
  574. struct emif_custom_configs *cust_cfgs = emif->plat_data->custom_configs;
  575. if (cust_cfgs && (cust_cfgs->mask & EMIF_CUSTOM_CONFIG_LPMODE)) {
  576. lpmode = cust_cfgs->lpmode;
  577. timeout_perf = cust_cfgs->lpmode_timeout_performance;
  578. timeout_pwr = cust_cfgs->lpmode_timeout_power;
  579. freq_threshold = cust_cfgs->lpmode_freq_threshold;
  580. }
  581. /* Timeout based on DDR frequency */
  582. timeout = freq >= freq_threshold ? timeout_perf : timeout_pwr;
  583. /* The value to be set in register is "log2(timeout) - 3" */
  584. if (timeout < 16) {
  585. timeout = 0;
  586. } else {
  587. timeout = __fls(timeout) - 3;
  588. if (timeout & (timeout - 1))
  589. timeout++;
  590. }
  591. switch (lpmode) {
  592. case EMIF_LP_MODE_CLOCK_STOP:
  593. pwr_mgmt_ctrl = (timeout << CS_TIM_SHIFT) |
  594. SR_TIM_MASK | PD_TIM_MASK;
  595. break;
  596. case EMIF_LP_MODE_SELF_REFRESH:
  597. /* Workaround for errata i735 */
  598. if (timeout < 6)
  599. timeout = 6;
  600. pwr_mgmt_ctrl = (timeout << SR_TIM_SHIFT) |
  601. CS_TIM_MASK | PD_TIM_MASK;
  602. break;
  603. case EMIF_LP_MODE_PWR_DN:
  604. pwr_mgmt_ctrl = (timeout << PD_TIM_SHIFT) |
  605. CS_TIM_MASK | SR_TIM_MASK;
  606. break;
  607. case EMIF_LP_MODE_DISABLE:
  608. default:
  609. pwr_mgmt_ctrl = CS_TIM_MASK |
  610. PD_TIM_MASK | SR_TIM_MASK;
  611. }
  612. /* No CS_TIM in EMIF_4D5 */
  613. if (ip_rev == EMIF_4D5)
  614. pwr_mgmt_ctrl &= ~CS_TIM_MASK;
  615. pwr_mgmt_ctrl |= lpmode << LP_MODE_SHIFT;
  616. return pwr_mgmt_ctrl;
  617. }
  618. /*
  619. * Get the temperature level of the EMIF instance:
  620. * Reads the MR4 register of attached SDRAM parts to find out the temperature
  621. * level. If there are two parts attached(one on each CS), then the temperature
  622. * level for the EMIF instance is the higher of the two temperatures.
  623. */
  624. static void get_temperature_level(struct emif_data *emif)
  625. {
  626. u32 temp, temperature_level;
  627. void __iomem *base;
  628. base = emif->base;
  629. /* Read mode register 4 */
  630. writel(DDR_MR4, base + EMIF_LPDDR2_MODE_REG_CONFIG);
  631. temperature_level = readl(base + EMIF_LPDDR2_MODE_REG_DATA);
  632. temperature_level = (temperature_level & MR4_SDRAM_REF_RATE_MASK) >>
  633. MR4_SDRAM_REF_RATE_SHIFT;
  634. if (emif->plat_data->device_info->cs1_used) {
  635. writel(DDR_MR4 | CS_MASK, base + EMIF_LPDDR2_MODE_REG_CONFIG);
  636. temp = readl(base + EMIF_LPDDR2_MODE_REG_DATA);
  637. temp = (temp & MR4_SDRAM_REF_RATE_MASK)
  638. >> MR4_SDRAM_REF_RATE_SHIFT;
  639. temperature_level = max(temp, temperature_level);
  640. }
  641. /* treat everything less than nominal(3) in MR4 as nominal */
  642. if (unlikely(temperature_level < SDRAM_TEMP_NOMINAL))
  643. temperature_level = SDRAM_TEMP_NOMINAL;
  644. /* if we get reserved value in MR4 persist with the existing value */
  645. if (likely(temperature_level != SDRAM_TEMP_RESERVED_4))
  646. emif->temperature_level = temperature_level;
  647. }
  648. /*
  649. * Program EMIF shadow registers that are not dependent on temperature
  650. * or voltage
  651. */
  652. static void setup_registers(struct emif_data *emif, struct emif_regs *regs)
  653. {
  654. void __iomem *base = emif->base;
  655. writel(regs->sdram_tim2_shdw, base + EMIF_SDRAM_TIMING_2_SHDW);
  656. writel(regs->phy_ctrl_1_shdw, base + EMIF_DDR_PHY_CTRL_1_SHDW);
  657. /* Settings specific for EMIF4D5 */
  658. if (emif->plat_data->ip_rev != EMIF_4D5)
  659. return;
  660. writel(regs->ext_phy_ctrl_2_shdw, base + EMIF_EXT_PHY_CTRL_2_SHDW);
  661. writel(regs->ext_phy_ctrl_3_shdw, base + EMIF_EXT_PHY_CTRL_3_SHDW);
  662. writel(regs->ext_phy_ctrl_4_shdw, base + EMIF_EXT_PHY_CTRL_4_SHDW);
  663. }
  664. /*
  665. * When voltage ramps dll calibration and forced read idle should
  666. * happen more often
  667. */
  668. static void setup_volt_sensitive_regs(struct emif_data *emif,
  669. struct emif_regs *regs, u32 volt_state)
  670. {
  671. u32 calib_ctrl;
  672. void __iomem *base = emif->base;
  673. /*
  674. * EMIF_READ_IDLE_CTRL in EMIF4D refers to the same register as
  675. * EMIF_DLL_CALIB_CTRL in EMIF4D5 and dll_calib_ctrl_shadow_*
  676. * is an alias of the respective read_idle_ctrl_shdw_* (members of
  677. * a union). So, the below code takes care of both cases
  678. */
  679. if (volt_state == DDR_VOLTAGE_RAMPING)
  680. calib_ctrl = regs->dll_calib_ctrl_shdw_volt_ramp;
  681. else
  682. calib_ctrl = regs->dll_calib_ctrl_shdw_normal;
  683. writel(calib_ctrl, base + EMIF_DLL_CALIB_CTRL_SHDW);
  684. }
  685. /*
  686. * setup_temperature_sensitive_regs() - set the timings for temperature
  687. * sensitive registers. This happens once at initialisation time based
  688. * on the temperature at boot time and subsequently based on the temperature
  689. * alert interrupt. Temperature alert can happen when the temperature
  690. * increases or drops. So this function can have the effect of either
  691. * derating the timings or going back to nominal values.
  692. */
  693. static void setup_temperature_sensitive_regs(struct emif_data *emif,
  694. struct emif_regs *regs)
  695. {
  696. u32 tim1, tim3, ref_ctrl, type;
  697. void __iomem *base = emif->base;
  698. u32 temperature;
  699. type = emif->plat_data->device_info->type;
  700. tim1 = regs->sdram_tim1_shdw;
  701. tim3 = regs->sdram_tim3_shdw;
  702. ref_ctrl = regs->ref_ctrl_shdw;
  703. /* No de-rating for non-lpddr2 devices */
  704. if (type != DDR_TYPE_LPDDR2_S2 && type != DDR_TYPE_LPDDR2_S4)
  705. goto out;
  706. temperature = emif->temperature_level;
  707. if (temperature == SDRAM_TEMP_HIGH_DERATE_REFRESH) {
  708. ref_ctrl = regs->ref_ctrl_shdw_derated;
  709. } else if (temperature == SDRAM_TEMP_HIGH_DERATE_REFRESH_AND_TIMINGS) {
  710. tim1 = regs->sdram_tim1_shdw_derated;
  711. tim3 = regs->sdram_tim3_shdw_derated;
  712. ref_ctrl = regs->ref_ctrl_shdw_derated;
  713. }
  714. out:
  715. writel(tim1, base + EMIF_SDRAM_TIMING_1_SHDW);
  716. writel(tim3, base + EMIF_SDRAM_TIMING_3_SHDW);
  717. writel(ref_ctrl, base + EMIF_SDRAM_REFRESH_CTRL_SHDW);
  718. }
  719. static irqreturn_t handle_temp_alert(void __iomem *base, struct emif_data *emif)
  720. {
  721. u32 old_temp_level;
  722. irqreturn_t ret = IRQ_HANDLED;
  723. spin_lock_irqsave(&emif_lock, irq_state);
  724. old_temp_level = emif->temperature_level;
  725. get_temperature_level(emif);
  726. if (unlikely(emif->temperature_level == old_temp_level)) {
  727. goto out;
  728. } else if (!emif->curr_regs) {
  729. dev_err(emif->dev, "temperature alert before registers are calculated, not de-rating timings\n");
  730. goto out;
  731. }
  732. if (emif->temperature_level < old_temp_level ||
  733. emif->temperature_level == SDRAM_TEMP_VERY_HIGH_SHUTDOWN) {
  734. /*
  735. * Temperature coming down - defer handling to thread OR
  736. * Temperature far too high - do kernel_power_off() from
  737. * thread context
  738. */
  739. ret = IRQ_WAKE_THREAD;
  740. } else {
  741. /* Temperature is going up - handle immediately */
  742. setup_temperature_sensitive_regs(emif, emif->curr_regs);
  743. do_freq_update();
  744. }
  745. out:
  746. spin_unlock_irqrestore(&emif_lock, irq_state);
  747. return ret;
  748. }
  749. static irqreturn_t emif_interrupt_handler(int irq, void *dev_id)
  750. {
  751. u32 interrupts;
  752. struct emif_data *emif = dev_id;
  753. void __iomem *base = emif->base;
  754. struct device *dev = emif->dev;
  755. irqreturn_t ret = IRQ_HANDLED;
  756. /* Save the status and clear it */
  757. interrupts = readl(base + EMIF_SYSTEM_OCP_INTERRUPT_STATUS);
  758. writel(interrupts, base + EMIF_SYSTEM_OCP_INTERRUPT_STATUS);
  759. /*
  760. * Handle temperature alert
  761. * Temperature alert should be same for all ports
  762. * So, it's enough to process it only for one of the ports
  763. */
  764. if (interrupts & TA_SYS_MASK)
  765. ret = handle_temp_alert(base, emif);
  766. if (interrupts & ERR_SYS_MASK)
  767. dev_err(dev, "Access error from SYS port - %x\n", interrupts);
  768. if (emif->plat_data->hw_caps & EMIF_HW_CAPS_LL_INTERFACE) {
  769. /* Save the status and clear it */
  770. interrupts = readl(base + EMIF_LL_OCP_INTERRUPT_STATUS);
  771. writel(interrupts, base + EMIF_LL_OCP_INTERRUPT_STATUS);
  772. if (interrupts & ERR_LL_MASK)
  773. dev_err(dev, "Access error from LL port - %x\n",
  774. interrupts);
  775. }
  776. return ret;
  777. }
  778. static irqreturn_t emif_threaded_isr(int irq, void *dev_id)
  779. {
  780. struct emif_data *emif = dev_id;
  781. if (emif->temperature_level == SDRAM_TEMP_VERY_HIGH_SHUTDOWN) {
  782. dev_emerg(emif->dev, "SDRAM temperature exceeds operating limit.. Needs shut down!!!\n");
  783. kernel_power_off();
  784. return IRQ_HANDLED;
  785. }
  786. spin_lock_irqsave(&emif_lock, irq_state);
  787. if (emif->curr_regs) {
  788. setup_temperature_sensitive_regs(emif, emif->curr_regs);
  789. do_freq_update();
  790. } else {
  791. dev_err(emif->dev, "temperature alert before registers are calculated, not de-rating timings\n");
  792. }
  793. spin_unlock_irqrestore(&emif_lock, irq_state);
  794. return IRQ_HANDLED;
  795. }
  796. static void clear_all_interrupts(struct emif_data *emif)
  797. {
  798. void __iomem *base = emif->base;
  799. writel(readl(base + EMIF_SYSTEM_OCP_INTERRUPT_STATUS),
  800. base + EMIF_SYSTEM_OCP_INTERRUPT_STATUS);
  801. if (emif->plat_data->hw_caps & EMIF_HW_CAPS_LL_INTERFACE)
  802. writel(readl(base + EMIF_LL_OCP_INTERRUPT_STATUS),
  803. base + EMIF_LL_OCP_INTERRUPT_STATUS);
  804. }
  805. static void disable_and_clear_all_interrupts(struct emif_data *emif)
  806. {
  807. void __iomem *base = emif->base;
  808. /* Disable all interrupts */
  809. writel(readl(base + EMIF_SYSTEM_OCP_INTERRUPT_ENABLE_SET),
  810. base + EMIF_SYSTEM_OCP_INTERRUPT_ENABLE_CLEAR);
  811. if (emif->plat_data->hw_caps & EMIF_HW_CAPS_LL_INTERFACE)
  812. writel(readl(base + EMIF_LL_OCP_INTERRUPT_ENABLE_SET),
  813. base + EMIF_LL_OCP_INTERRUPT_ENABLE_CLEAR);
  814. /* Clear all interrupts */
  815. clear_all_interrupts(emif);
  816. }
  817. static int __init_or_module setup_interrupts(struct emif_data *emif, u32 irq)
  818. {
  819. u32 interrupts, type;
  820. void __iomem *base = emif->base;
  821. type = emif->plat_data->device_info->type;
  822. clear_all_interrupts(emif);
  823. /* Enable interrupts for SYS interface */
  824. interrupts = EN_ERR_SYS_MASK;
  825. if (type == DDR_TYPE_LPDDR2_S2 || type == DDR_TYPE_LPDDR2_S4)
  826. interrupts |= EN_TA_SYS_MASK;
  827. writel(interrupts, base + EMIF_SYSTEM_OCP_INTERRUPT_ENABLE_SET);
  828. /* Enable interrupts for LL interface */
  829. if (emif->plat_data->hw_caps & EMIF_HW_CAPS_LL_INTERFACE) {
  830. /* TA need not be enabled for LL */
  831. interrupts = EN_ERR_LL_MASK;
  832. writel(interrupts, base + EMIF_LL_OCP_INTERRUPT_ENABLE_SET);
  833. }
  834. /* setup IRQ handlers */
  835. return devm_request_threaded_irq(emif->dev, irq,
  836. emif_interrupt_handler,
  837. emif_threaded_isr,
  838. 0, dev_name(emif->dev),
  839. emif);
  840. }
  841. static void __init_or_module emif_onetime_settings(struct emif_data *emif)
  842. {
  843. u32 pwr_mgmt_ctrl, zq, temp_alert_cfg;
  844. void __iomem *base = emif->base;
  845. const struct lpddr2_addressing *addressing;
  846. const struct ddr_device_info *device_info;
  847. device_info = emif->plat_data->device_info;
  848. addressing = get_addressing_table(device_info);
  849. /*
  850. * Init power management settings
  851. * We don't know the frequency yet. Use a high frequency
  852. * value for a conservative timeout setting
  853. */
  854. pwr_mgmt_ctrl = get_pwr_mgmt_ctrl(1000000000, emif,
  855. emif->plat_data->ip_rev);
  856. emif->lpmode = (pwr_mgmt_ctrl & LP_MODE_MASK) >> LP_MODE_SHIFT;
  857. writel(pwr_mgmt_ctrl, base + EMIF_POWER_MANAGEMENT_CONTROL);
  858. /* Init ZQ calibration settings */
  859. zq = get_zq_config_reg(addressing, device_info->cs1_used,
  860. device_info->cal_resistors_per_cs);
  861. writel(zq, base + EMIF_SDRAM_OUTPUT_IMPEDANCE_CALIBRATION_CONFIG);
  862. /* Check temperature level temperature level*/
  863. get_temperature_level(emif);
  864. if (emif->temperature_level == SDRAM_TEMP_VERY_HIGH_SHUTDOWN)
  865. dev_emerg(emif->dev, "SDRAM temperature exceeds operating limit.. Needs shut down!!!\n");
  866. /* Init temperature polling */
  867. temp_alert_cfg = get_temp_alert_config(addressing,
  868. emif->plat_data->custom_configs, device_info->cs1_used,
  869. device_info->io_width, get_emif_bus_width(emif));
  870. writel(temp_alert_cfg, base + EMIF_TEMPERATURE_ALERT_CONFIG);
  871. /*
  872. * Program external PHY control registers that are not frequency
  873. * dependent
  874. */
  875. if (emif->plat_data->phy_type != EMIF_PHY_TYPE_INTELLIPHY)
  876. return;
  877. writel(EMIF_EXT_PHY_CTRL_1_VAL, base + EMIF_EXT_PHY_CTRL_1_SHDW);
  878. writel(EMIF_EXT_PHY_CTRL_5_VAL, base + EMIF_EXT_PHY_CTRL_5_SHDW);
  879. writel(EMIF_EXT_PHY_CTRL_6_VAL, base + EMIF_EXT_PHY_CTRL_6_SHDW);
  880. writel(EMIF_EXT_PHY_CTRL_7_VAL, base + EMIF_EXT_PHY_CTRL_7_SHDW);
  881. writel(EMIF_EXT_PHY_CTRL_8_VAL, base + EMIF_EXT_PHY_CTRL_8_SHDW);
  882. writel(EMIF_EXT_PHY_CTRL_9_VAL, base + EMIF_EXT_PHY_CTRL_9_SHDW);
  883. writel(EMIF_EXT_PHY_CTRL_10_VAL, base + EMIF_EXT_PHY_CTRL_10_SHDW);
  884. writel(EMIF_EXT_PHY_CTRL_11_VAL, base + EMIF_EXT_PHY_CTRL_11_SHDW);
  885. writel(EMIF_EXT_PHY_CTRL_12_VAL, base + EMIF_EXT_PHY_CTRL_12_SHDW);
  886. writel(EMIF_EXT_PHY_CTRL_13_VAL, base + EMIF_EXT_PHY_CTRL_13_SHDW);
  887. writel(EMIF_EXT_PHY_CTRL_14_VAL, base + EMIF_EXT_PHY_CTRL_14_SHDW);
  888. writel(EMIF_EXT_PHY_CTRL_15_VAL, base + EMIF_EXT_PHY_CTRL_15_SHDW);
  889. writel(EMIF_EXT_PHY_CTRL_16_VAL, base + EMIF_EXT_PHY_CTRL_16_SHDW);
  890. writel(EMIF_EXT_PHY_CTRL_17_VAL, base + EMIF_EXT_PHY_CTRL_17_SHDW);
  891. writel(EMIF_EXT_PHY_CTRL_18_VAL, base + EMIF_EXT_PHY_CTRL_18_SHDW);
  892. writel(EMIF_EXT_PHY_CTRL_19_VAL, base + EMIF_EXT_PHY_CTRL_19_SHDW);
  893. writel(EMIF_EXT_PHY_CTRL_20_VAL, base + EMIF_EXT_PHY_CTRL_20_SHDW);
  894. writel(EMIF_EXT_PHY_CTRL_21_VAL, base + EMIF_EXT_PHY_CTRL_21_SHDW);
  895. writel(EMIF_EXT_PHY_CTRL_22_VAL, base + EMIF_EXT_PHY_CTRL_22_SHDW);
  896. writel(EMIF_EXT_PHY_CTRL_23_VAL, base + EMIF_EXT_PHY_CTRL_23_SHDW);
  897. writel(EMIF_EXT_PHY_CTRL_24_VAL, base + EMIF_EXT_PHY_CTRL_24_SHDW);
  898. }
  899. static void get_default_timings(struct emif_data *emif)
  900. {
  901. struct emif_platform_data *pd = emif->plat_data;
  902. pd->timings = lpddr2_jedec_timings;
  903. pd->timings_arr_size = ARRAY_SIZE(lpddr2_jedec_timings);
  904. dev_warn(emif->dev, "%s: using default timings\n", __func__);
  905. }
  906. static int is_dev_data_valid(u32 type, u32 density, u32 io_width, u32 phy_type,
  907. u32 ip_rev, struct device *dev)
  908. {
  909. int valid;
  910. valid = (type == DDR_TYPE_LPDDR2_S4 ||
  911. type == DDR_TYPE_LPDDR2_S2)
  912. && (density >= DDR_DENSITY_64Mb
  913. && density <= DDR_DENSITY_8Gb)
  914. && (io_width >= DDR_IO_WIDTH_8
  915. && io_width <= DDR_IO_WIDTH_32);
  916. /* Combinations of EMIF and PHY revisions that we support today */
  917. switch (ip_rev) {
  918. case EMIF_4D:
  919. valid = valid && (phy_type == EMIF_PHY_TYPE_ATTILAPHY);
  920. break;
  921. case EMIF_4D5:
  922. valid = valid && (phy_type == EMIF_PHY_TYPE_INTELLIPHY);
  923. break;
  924. default:
  925. valid = 0;
  926. }
  927. if (!valid)
  928. dev_err(dev, "%s: invalid DDR details\n", __func__);
  929. return valid;
  930. }
  931. static int is_custom_config_valid(struct emif_custom_configs *cust_cfgs,
  932. struct device *dev)
  933. {
  934. int valid = 1;
  935. if ((cust_cfgs->mask & EMIF_CUSTOM_CONFIG_LPMODE) &&
  936. (cust_cfgs->lpmode != EMIF_LP_MODE_DISABLE))
  937. valid = cust_cfgs->lpmode_freq_threshold &&
  938. cust_cfgs->lpmode_timeout_performance &&
  939. cust_cfgs->lpmode_timeout_power;
  940. if (cust_cfgs->mask & EMIF_CUSTOM_CONFIG_TEMP_ALERT_POLL_INTERVAL)
  941. valid = valid && cust_cfgs->temp_alert_poll_interval_ms;
  942. if (!valid)
  943. dev_warn(dev, "%s: invalid custom configs\n", __func__);
  944. return valid;
  945. }
  946. static struct emif_data *__init_or_module get_device_details(
  947. struct platform_device *pdev)
  948. {
  949. u32 size;
  950. struct emif_data *emif = NULL;
  951. struct ddr_device_info *dev_info;
  952. struct emif_custom_configs *cust_cfgs;
  953. struct emif_platform_data *pd;
  954. struct device *dev;
  955. void *temp;
  956. pd = pdev->dev.platform_data;
  957. dev = &pdev->dev;
  958. if (!(pd && pd->device_info && is_dev_data_valid(pd->device_info->type,
  959. pd->device_info->density, pd->device_info->io_width,
  960. pd->phy_type, pd->ip_rev, dev))) {
  961. dev_err(dev, "%s: invalid device data\n", __func__);
  962. goto error;
  963. }
  964. emif = devm_kzalloc(dev, sizeof(*emif), GFP_KERNEL);
  965. temp = devm_kzalloc(dev, sizeof(*pd), GFP_KERNEL);
  966. dev_info = devm_kzalloc(dev, sizeof(*dev_info), GFP_KERNEL);
  967. if (!emif || !pd || !dev_info) {
  968. dev_err(dev, "%s:%d: allocation error\n", __func__, __LINE__);
  969. goto error;
  970. }
  971. memcpy(temp, pd, sizeof(*pd));
  972. pd = temp;
  973. memcpy(dev_info, pd->device_info, sizeof(*dev_info));
  974. pd->device_info = dev_info;
  975. emif->plat_data = pd;
  976. emif->dev = dev;
  977. emif->temperature_level = SDRAM_TEMP_NOMINAL;
  978. /*
  979. * For EMIF instances other than EMIF1 see if the devices connected
  980. * are exactly same as on EMIF1(which is typically the case). If so,
  981. * mark it as a duplicate of EMIF1 and skip copying timings data.
  982. * This will save some memory and some computation later.
  983. */
  984. emif->duplicate = emif1 && (memcmp(dev_info,
  985. emif1->plat_data->device_info,
  986. sizeof(struct ddr_device_info)) == 0);
  987. if (emif->duplicate) {
  988. pd->timings = NULL;
  989. pd->min_tck = NULL;
  990. goto out;
  991. } else if (emif1) {
  992. dev_warn(emif->dev, "%s: Non-symmetric DDR geometry\n",
  993. __func__);
  994. }
  995. /*
  996. * Copy custom configs - ignore allocation error, if any, as
  997. * custom_configs is not very critical
  998. */
  999. cust_cfgs = pd->custom_configs;
  1000. if (cust_cfgs && is_custom_config_valid(cust_cfgs, dev)) {
  1001. temp = devm_kzalloc(dev, sizeof(*cust_cfgs), GFP_KERNEL);
  1002. if (temp)
  1003. memcpy(temp, cust_cfgs, sizeof(*cust_cfgs));
  1004. else
  1005. dev_warn(dev, "%s:%d: allocation error\n", __func__,
  1006. __LINE__);
  1007. pd->custom_configs = temp;
  1008. }
  1009. /*
  1010. * Copy timings and min-tck values from platform data. If it is not
  1011. * available or if memory allocation fails, use JEDEC defaults
  1012. */
  1013. size = sizeof(struct lpddr2_timings) * pd->timings_arr_size;
  1014. if (pd->timings) {
  1015. temp = devm_kzalloc(dev, size, GFP_KERNEL);
  1016. if (temp) {
  1017. memcpy(temp, pd->timings, sizeof(*pd->timings));
  1018. pd->timings = temp;
  1019. } else {
  1020. dev_warn(dev, "%s:%d: allocation error\n", __func__,
  1021. __LINE__);
  1022. get_default_timings(emif);
  1023. }
  1024. } else {
  1025. get_default_timings(emif);
  1026. }
  1027. if (pd->min_tck) {
  1028. temp = devm_kzalloc(dev, sizeof(*pd->min_tck), GFP_KERNEL);
  1029. if (temp) {
  1030. memcpy(temp, pd->min_tck, sizeof(*pd->min_tck));
  1031. pd->min_tck = temp;
  1032. } else {
  1033. dev_warn(dev, "%s:%d: allocation error\n", __func__,
  1034. __LINE__);
  1035. pd->min_tck = &lpddr2_jedec_min_tck;
  1036. }
  1037. } else {
  1038. pd->min_tck = &lpddr2_jedec_min_tck;
  1039. }
  1040. out:
  1041. return emif;
  1042. error:
  1043. return NULL;
  1044. }
  1045. static int __init_or_module emif_probe(struct platform_device *pdev)
  1046. {
  1047. struct emif_data *emif;
  1048. struct resource *res;
  1049. int irq;
  1050. emif = get_device_details(pdev);
  1051. if (!emif) {
  1052. pr_err("%s: error getting device data\n", __func__);
  1053. goto error;
  1054. }
  1055. list_add(&emif->node, &device_list);
  1056. emif->addressing = get_addressing_table(emif->plat_data->device_info);
  1057. /* Save pointers to each other in emif and device structures */
  1058. emif->dev = &pdev->dev;
  1059. platform_set_drvdata(pdev, emif);
  1060. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1061. if (!res) {
  1062. dev_err(emif->dev, "%s: error getting memory resource\n",
  1063. __func__);
  1064. goto error;
  1065. }
  1066. emif->base = devm_request_and_ioremap(emif->dev, res);
  1067. if (!emif->base) {
  1068. dev_err(emif->dev, "%s: devm_request_and_ioremap() failed\n",
  1069. __func__);
  1070. goto error;
  1071. }
  1072. irq = platform_get_irq(pdev, 0);
  1073. if (irq < 0) {
  1074. dev_err(emif->dev, "%s: error getting IRQ resource - %d\n",
  1075. __func__, irq);
  1076. goto error;
  1077. }
  1078. emif_onetime_settings(emif);
  1079. emif_debugfs_init(emif);
  1080. disable_and_clear_all_interrupts(emif);
  1081. setup_interrupts(emif, irq);
  1082. /* One-time actions taken on probing the first device */
  1083. if (!emif1) {
  1084. emif1 = emif;
  1085. spin_lock_init(&emif_lock);
  1086. /*
  1087. * TODO: register notifiers for frequency and voltage
  1088. * change here once the respective frameworks are
  1089. * available
  1090. */
  1091. }
  1092. dev_info(&pdev->dev, "%s: device configured with addr = %p and IRQ%d\n",
  1093. __func__, emif->base, irq);
  1094. return 0;
  1095. error:
  1096. return -ENODEV;
  1097. }
  1098. static int __exit emif_remove(struct platform_device *pdev)
  1099. {
  1100. struct emif_data *emif = platform_get_drvdata(pdev);
  1101. emif_debugfs_exit(emif);
  1102. return 0;
  1103. }
  1104. static void emif_shutdown(struct platform_device *pdev)
  1105. {
  1106. struct emif_data *emif = platform_get_drvdata(pdev);
  1107. disable_and_clear_all_interrupts(emif);
  1108. }
  1109. static int get_emif_reg_values(struct emif_data *emif, u32 freq,
  1110. struct emif_regs *regs)
  1111. {
  1112. u32 cs1_used, ip_rev, phy_type;
  1113. u32 cl, type;
  1114. const struct lpddr2_timings *timings;
  1115. const struct lpddr2_min_tck *min_tck;
  1116. const struct ddr_device_info *device_info;
  1117. const struct lpddr2_addressing *addressing;
  1118. struct emif_data *emif_for_calc;
  1119. struct device *dev;
  1120. const struct emif_custom_configs *custom_configs;
  1121. dev = emif->dev;
  1122. /*
  1123. * If the devices on this EMIF instance is duplicate of EMIF1,
  1124. * use EMIF1 details for the calculation
  1125. */
  1126. emif_for_calc = emif->duplicate ? emif1 : emif;
  1127. timings = get_timings_table(emif_for_calc, freq);
  1128. addressing = emif_for_calc->addressing;
  1129. if (!timings || !addressing) {
  1130. dev_err(dev, "%s: not enough data available for %dHz",
  1131. __func__, freq);
  1132. return -1;
  1133. }
  1134. device_info = emif_for_calc->plat_data->device_info;
  1135. type = device_info->type;
  1136. cs1_used = device_info->cs1_used;
  1137. ip_rev = emif_for_calc->plat_data->ip_rev;
  1138. phy_type = emif_for_calc->plat_data->phy_type;
  1139. min_tck = emif_for_calc->plat_data->min_tck;
  1140. custom_configs = emif_for_calc->plat_data->custom_configs;
  1141. set_ddr_clk_period(freq);
  1142. regs->ref_ctrl_shdw = get_sdram_ref_ctrl_shdw(freq, addressing);
  1143. regs->sdram_tim1_shdw = get_sdram_tim_1_shdw(timings, min_tck,
  1144. addressing);
  1145. regs->sdram_tim2_shdw = get_sdram_tim_2_shdw(timings, min_tck,
  1146. addressing, type);
  1147. regs->sdram_tim3_shdw = get_sdram_tim_3_shdw(timings, min_tck,
  1148. addressing, type, ip_rev, EMIF_NORMAL_TIMINGS);
  1149. cl = get_cl(emif);
  1150. if (phy_type == EMIF_PHY_TYPE_ATTILAPHY && ip_rev == EMIF_4D) {
  1151. regs->phy_ctrl_1_shdw = get_ddr_phy_ctrl_1_attilaphy_4d(
  1152. timings, freq, cl);
  1153. } else if (phy_type == EMIF_PHY_TYPE_INTELLIPHY && ip_rev == EMIF_4D5) {
  1154. regs->phy_ctrl_1_shdw = get_phy_ctrl_1_intelliphy_4d5(freq, cl);
  1155. regs->ext_phy_ctrl_2_shdw = get_ext_phy_ctrl_2_intelliphy_4d5();
  1156. regs->ext_phy_ctrl_3_shdw = get_ext_phy_ctrl_3_intelliphy_4d5();
  1157. regs->ext_phy_ctrl_4_shdw = get_ext_phy_ctrl_4_intelliphy_4d5();
  1158. } else {
  1159. return -1;
  1160. }
  1161. /* Only timeout values in pwr_mgmt_ctrl_shdw register */
  1162. regs->pwr_mgmt_ctrl_shdw =
  1163. get_pwr_mgmt_ctrl(freq, emif_for_calc, ip_rev) &
  1164. (CS_TIM_MASK | SR_TIM_MASK | PD_TIM_MASK);
  1165. if (ip_rev & EMIF_4D) {
  1166. regs->read_idle_ctrl_shdw_normal =
  1167. get_read_idle_ctrl_shdw(DDR_VOLTAGE_STABLE);
  1168. regs->read_idle_ctrl_shdw_volt_ramp =
  1169. get_read_idle_ctrl_shdw(DDR_VOLTAGE_RAMPING);
  1170. } else if (ip_rev & EMIF_4D5) {
  1171. regs->dll_calib_ctrl_shdw_normal =
  1172. get_dll_calib_ctrl_shdw(DDR_VOLTAGE_STABLE);
  1173. regs->dll_calib_ctrl_shdw_volt_ramp =
  1174. get_dll_calib_ctrl_shdw(DDR_VOLTAGE_RAMPING);
  1175. }
  1176. if (type == DDR_TYPE_LPDDR2_S2 || type == DDR_TYPE_LPDDR2_S4) {
  1177. regs->ref_ctrl_shdw_derated = get_sdram_ref_ctrl_shdw(freq / 4,
  1178. addressing);
  1179. regs->sdram_tim1_shdw_derated =
  1180. get_sdram_tim_1_shdw_derated(timings, min_tck,
  1181. addressing);
  1182. regs->sdram_tim3_shdw_derated = get_sdram_tim_3_shdw(timings,
  1183. min_tck, addressing, type, ip_rev,
  1184. EMIF_DERATED_TIMINGS);
  1185. }
  1186. regs->freq = freq;
  1187. return 0;
  1188. }
  1189. /*
  1190. * get_regs() - gets the cached emif_regs structure for a given EMIF instance
  1191. * given frequency(freq):
  1192. *
  1193. * As an optimisation, every EMIF instance other than EMIF1 shares the
  1194. * register cache with EMIF1 if the devices connected on this instance
  1195. * are same as that on EMIF1(indicated by the duplicate flag)
  1196. *
  1197. * If we do not have an entry corresponding to the frequency given, we
  1198. * allocate a new entry and calculate the values
  1199. *
  1200. * Upon finding the right reg dump, save it in curr_regs. It can be
  1201. * directly used for thermal de-rating and voltage ramping changes.
  1202. */
  1203. static struct emif_regs *get_regs(struct emif_data *emif, u32 freq)
  1204. {
  1205. int i;
  1206. struct emif_regs **regs_cache;
  1207. struct emif_regs *regs = NULL;
  1208. struct device *dev;
  1209. dev = emif->dev;
  1210. if (emif->curr_regs && emif->curr_regs->freq == freq) {
  1211. dev_dbg(dev, "%s: using curr_regs - %u Hz", __func__, freq);
  1212. return emif->curr_regs;
  1213. }
  1214. if (emif->duplicate)
  1215. regs_cache = emif1->regs_cache;
  1216. else
  1217. regs_cache = emif->regs_cache;
  1218. for (i = 0; i < EMIF_MAX_NUM_FREQUENCIES && regs_cache[i]; i++) {
  1219. if (regs_cache[i]->freq == freq) {
  1220. regs = regs_cache[i];
  1221. dev_dbg(dev,
  1222. "%s: reg dump found in reg cache for %u Hz\n",
  1223. __func__, freq);
  1224. break;
  1225. }
  1226. }
  1227. /*
  1228. * If we don't have an entry for this frequency in the cache create one
  1229. * and calculate the values
  1230. */
  1231. if (!regs) {
  1232. regs = devm_kzalloc(emif->dev, sizeof(*regs), GFP_ATOMIC);
  1233. if (!regs)
  1234. return NULL;
  1235. if (get_emif_reg_values(emif, freq, regs)) {
  1236. devm_kfree(emif->dev, regs);
  1237. return NULL;
  1238. }
  1239. /*
  1240. * Now look for an un-used entry in the cache and save the
  1241. * newly created struct. If there are no free entries
  1242. * over-write the last entry
  1243. */
  1244. for (i = 0; i < EMIF_MAX_NUM_FREQUENCIES && regs_cache[i]; i++)
  1245. ;
  1246. if (i >= EMIF_MAX_NUM_FREQUENCIES) {
  1247. dev_warn(dev, "%s: regs_cache full - reusing a slot!!\n",
  1248. __func__);
  1249. i = EMIF_MAX_NUM_FREQUENCIES - 1;
  1250. devm_kfree(emif->dev, regs_cache[i]);
  1251. }
  1252. regs_cache[i] = regs;
  1253. }
  1254. return regs;
  1255. }
  1256. static void do_volt_notify_handling(struct emif_data *emif, u32 volt_state)
  1257. {
  1258. dev_dbg(emif->dev, "%s: voltage notification : %d", __func__,
  1259. volt_state);
  1260. if (!emif->curr_regs) {
  1261. dev_err(emif->dev,
  1262. "%s: volt-notify before registers are ready: %d\n",
  1263. __func__, volt_state);
  1264. return;
  1265. }
  1266. setup_volt_sensitive_regs(emif, emif->curr_regs, volt_state);
  1267. }
  1268. /*
  1269. * TODO: voltage notify handling should be hooked up to
  1270. * regulator framework as soon as the necessary support
  1271. * is available in mainline kernel. This function is un-used
  1272. * right now.
  1273. */
  1274. static void __attribute__((unused)) volt_notify_handling(u32 volt_state)
  1275. {
  1276. struct emif_data *emif;
  1277. spin_lock_irqsave(&emif_lock, irq_state);
  1278. list_for_each_entry(emif, &device_list, node)
  1279. do_volt_notify_handling(emif, volt_state);
  1280. do_freq_update();
  1281. spin_unlock_irqrestore(&emif_lock, irq_state);
  1282. }
  1283. static void do_freq_pre_notify_handling(struct emif_data *emif, u32 new_freq)
  1284. {
  1285. struct emif_regs *regs;
  1286. regs = get_regs(emif, new_freq);
  1287. if (!regs)
  1288. return;
  1289. emif->curr_regs = regs;
  1290. /*
  1291. * Update the shadow registers:
  1292. * Temperature and voltage-ramp sensitive settings are also configured
  1293. * in terms of DDR cycles. So, we need to update them too when there
  1294. * is a freq change
  1295. */
  1296. dev_dbg(emif->dev, "%s: setting up shadow registers for %uHz",
  1297. __func__, new_freq);
  1298. setup_registers(emif, regs);
  1299. setup_temperature_sensitive_regs(emif, regs);
  1300. setup_volt_sensitive_regs(emif, regs, DDR_VOLTAGE_STABLE);
  1301. /*
  1302. * Part of workaround for errata i728. See do_freq_update()
  1303. * for more details
  1304. */
  1305. if (emif->lpmode == EMIF_LP_MODE_SELF_REFRESH)
  1306. set_lpmode(emif, EMIF_LP_MODE_DISABLE);
  1307. }
  1308. /*
  1309. * TODO: frequency notify handling should be hooked up to
  1310. * clock framework as soon as the necessary support is
  1311. * available in mainline kernel. This function is un-used
  1312. * right now.
  1313. */
  1314. static void __attribute__((unused)) freq_pre_notify_handling(u32 new_freq)
  1315. {
  1316. struct emif_data *emif;
  1317. /*
  1318. * NOTE: we are taking the spin-lock here and releases it
  1319. * only in post-notifier. This doesn't look good and
  1320. * Sparse complains about it, but this seems to be
  1321. * un-avoidable. We need to lock a sequence of events
  1322. * that is split between EMIF and clock framework.
  1323. *
  1324. * 1. EMIF driver updates EMIF timings in shadow registers in the
  1325. * frequency pre-notify callback from clock framework
  1326. * 2. clock framework sets up the registers for the new frequency
  1327. * 3. clock framework initiates a hw-sequence that updates
  1328. * the frequency EMIF timings synchronously.
  1329. *
  1330. * All these 3 steps should be performed as an atomic operation
  1331. * vis-a-vis similar sequence in the EMIF interrupt handler
  1332. * for temperature events. Otherwise, there could be race
  1333. * conditions that could result in incorrect EMIF timings for
  1334. * a given frequency
  1335. */
  1336. spin_lock_irqsave(&emif_lock, irq_state);
  1337. list_for_each_entry(emif, &device_list, node)
  1338. do_freq_pre_notify_handling(emif, new_freq);
  1339. }
  1340. static void do_freq_post_notify_handling(struct emif_data *emif)
  1341. {
  1342. /*
  1343. * Part of workaround for errata i728. See do_freq_update()
  1344. * for more details
  1345. */
  1346. if (emif->lpmode == EMIF_LP_MODE_SELF_REFRESH)
  1347. set_lpmode(emif, EMIF_LP_MODE_SELF_REFRESH);
  1348. }
  1349. /*
  1350. * TODO: frequency notify handling should be hooked up to
  1351. * clock framework as soon as the necessary support is
  1352. * available in mainline kernel. This function is un-used
  1353. * right now.
  1354. */
  1355. static void __attribute__((unused)) freq_post_notify_handling(void)
  1356. {
  1357. struct emif_data *emif;
  1358. list_for_each_entry(emif, &device_list, node)
  1359. do_freq_post_notify_handling(emif);
  1360. /*
  1361. * Lock is done in pre-notify handler. See freq_pre_notify_handling()
  1362. * for more details
  1363. */
  1364. spin_unlock_irqrestore(&emif_lock, irq_state);
  1365. }
  1366. static struct platform_driver emif_driver = {
  1367. .remove = __exit_p(emif_remove),
  1368. .shutdown = emif_shutdown,
  1369. .driver = {
  1370. .name = "emif",
  1371. },
  1372. };
  1373. static int __init_or_module emif_register(void)
  1374. {
  1375. return platform_driver_probe(&emif_driver, emif_probe);
  1376. }
  1377. static void __exit emif_unregister(void)
  1378. {
  1379. platform_driver_unregister(&emif_driver);
  1380. }
  1381. module_init(emif_register);
  1382. module_exit(emif_unregister);
  1383. MODULE_DESCRIPTION("TI EMIF SDRAM Controller Driver");
  1384. MODULE_LICENSE("GPL");
  1385. MODULE_ALIAS("platform:emif");
  1386. MODULE_AUTHOR("Texas Instruments Inc");