pm.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133
  1. /*
  2. * Meson Power Management Routines
  3. *
  4. * Copyright (C) 2010 Amlogic, Inc. http://www.amlogic.com/
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #include <linux/pm.h>
  11. #include <linux/suspend.h>
  12. #include <linux/module.h>
  13. #include <linux/platform_device.h>
  14. #include <linux/clk.h>
  15. #include <linux/spinlock.h>
  16. #include <linux/clk.h>
  17. #include <linux/fs.h>
  18. #include <asm/cacheflush.h>
  19. #include <asm/delay.h>
  20. #include <asm/uaccess.h>
  21. #include <mach/pm.h>
  22. #include <mach/am_regs.h>
  23. #include <mach/sram.h>
  24. #include <mach/power_gate.h>
  25. #include <mach/gpio.h>
  26. #include <mach/pctl.h>
  27. #include <mach/clock.h>
  28. #ifdef CONFIG_WAKELOCK
  29. #include <linux/wakelock.h>
  30. #endif
  31. #ifdef CONFIG_HAS_EARLYSUSPEND
  32. #include <linux/earlysuspend.h>
  33. static struct early_suspend early_suspend;
  34. static int early_suspend_flag = 0;
  35. #endif
  36. #define ON 1
  37. #define OFF 0
  38. #include "sleep.h"
  39. #ifndef CONFIG_BT
  40. #define EARLY_SUSPEND_USE_XTAL
  41. #endif
  42. #if (defined CONFIG_MACH_MESON_8726M_REFC03)||(defined CONFIG_MACH_MESON_8726M_REFC06)
  43. #define ETHERNET_ALWAYS
  44. #endif
  45. static void (*meson_sram_suspend) (struct meson_pm_config *);
  46. static struct meson_pm_config *pdata;
  47. static int mask_save[4];
  48. static void meson_sram_push(void *dest, void *src, unsigned int size)
  49. {
  50. int res = 0;
  51. memcpy(dest, src, size);
  52. flush_icache_range((unsigned long)dest, (unsigned long)(dest + size));
  53. res = memcmp(dest, src, size);
  54. printk("compare code in sram addr = 0x%x, size = 0x%x, result = %d",
  55. (unsigned)dest, size, res);
  56. }
  57. #define GATE_OFF(_MOD) do {power_gate_flag[GCLK_IDX_##_MOD] = IS_CLK_GATE_ON(_MOD);CLK_GATE_OFF(_MOD);} while(0)
  58. #define GATE_ON(_MOD) do {if (power_gate_flag[GCLK_IDX_##_MOD]) CLK_GATE_ON(_MOD);} while(0)
  59. #define GATE_SWITCH(flag, _MOD) do {if (flag) GATE_ON(_MOD); else GATE_OFF(_MOD);} while(0)
  60. static int power_gate_flag[GCLK_IDX_MAX];
  61. void power_gate_init(void)
  62. {
  63. GATE_INIT(AHB_BRIDGE);
  64. GATE_INIT(AHB_SRAM);
  65. GATE_INIT(AIU_ADC);
  66. GATE_INIT(AIU_MIXER_REG);
  67. GATE_INIT(AIU_AUD_MIXER);
  68. GATE_INIT(AIU_AIFIFO2);
  69. GATE_INIT(AIU_AMCLK_MEASURE);
  70. GATE_INIT(AIU_I2S_OUT);
  71. GATE_INIT(AIU_IEC958);
  72. GATE_INIT(AIU_AI_TOP_GLUE);
  73. GATE_INIT(AIU_AUD_DAC);
  74. GATE_INIT(AIU_ICE958_AMCLK);
  75. GATE_INIT(AIU_I2S_DAC_AMCLK);
  76. GATE_INIT(AIU_I2S_SLOW);
  77. GATE_INIT(AIU_AUD_DAC_CLK);
  78. GATE_INIT(ASSIST_MISC);
  79. GATE_INIT(AMRISC);
  80. GATE_INIT(AUD_BUF);
  81. GATE_INIT(AUD_IN);
  82. GATE_INIT(BLK_MOV);
  83. GATE_INIT(BT656_IN);
  84. GATE_INIT(DEMUX);
  85. GATE_INIT(MMC_DDR);
  86. GATE_INIT(DDR);
  87. GATE_INIT(ETHERNET);
  88. GATE_INIT(GE2D);
  89. GATE_INIT(HDMI_MPEG_DOMAIN);
  90. GATE_INIT(HIU_PARSER_TOP);
  91. GATE_INIT(HIU_PARSER);
  92. GATE_INIT(ISA);
  93. GATE_INIT(MEDIA_CPU);
  94. GATE_INIT(MISC_USB0_TO_DDR);
  95. GATE_INIT(MISC_USB1_TO_DDR);
  96. GATE_INIT(MISC_SATA_TO_DDR);
  97. GATE_INIT(AHB_CONTROL_BUS);
  98. GATE_INIT(AHB_DATA_BUS);
  99. GATE_INIT(AXI_BUS);
  100. GATE_INIT(ROM_CLK);
  101. GATE_INIT(EFUSE);
  102. GATE_INIT(AHB_ARB0);
  103. GATE_INIT(RESET);
  104. GATE_INIT(MDEC_CLK_PIC_DC);
  105. GATE_INIT(MDEC_CLK_DBLK);
  106. GATE_INIT(MDEC_CLK_PSC);
  107. GATE_INIT(MDEC_CLK_ASSIST);
  108. GATE_INIT(MC_CLK);
  109. GATE_INIT(IQIDCT_CLK);
  110. GATE_INIT(VLD_CLK);
  111. GATE_INIT(NAND);
  112. GATE_INIT(RESERVED0);
  113. GATE_INIT(VGHL_PWM);
  114. GATE_INIT(LED_PWM);
  115. GATE_INIT(UART1);
  116. GATE_INIT(SDIO);
  117. GATE_INIT(ASYNC_FIFO);
  118. GATE_INIT(STREAM);
  119. GATE_INIT(RTC);
  120. GATE_INIT(UART0);
  121. GATE_INIT(RANDOM_NUM_GEN);
  122. GATE_INIT(SMART_CARD_MPEG_DOMAIN);
  123. GATE_INIT(SMART_CARD);
  124. GATE_INIT(SAR_ADC);
  125. GATE_INIT(I2C);
  126. GATE_INIT(IR_REMOTE);
  127. GATE_INIT(_1200XXX);
  128. GATE_INIT(SATA);
  129. GATE_INIT(SPI1);
  130. GATE_INIT(SPI2);
  131. GATE_INIT(USB1);
  132. GATE_INIT(USB0);
  133. GATE_INIT(VI_CORE);
  134. GATE_INIT(LCD);
  135. GATE_INIT(ENC480P_MPEG_DOMAIN);
  136. GATE_INIT(ENC480I);
  137. GATE_INIT(VENC_MISC);
  138. GATE_INIT(ENC480P);
  139. GATE_INIT(HDMI);
  140. GATE_INIT(VCLK3_DAC);
  141. GATE_INIT(VCLK3_MISC);
  142. GATE_INIT(VCLK3_DVI);
  143. GATE_INIT(VCLK2_VIU);
  144. GATE_INIT(VCLK2_VENC_DVI);
  145. GATE_INIT(VCLK2_VENC_ENC480P);
  146. GATE_INIT(VCLK2_VENC_BIST);
  147. GATE_INIT(VCLK1_VENC_656);
  148. GATE_INIT(VCLK1_VENC_DVI);
  149. GATE_INIT(VCLK1_VENC_ENCI);
  150. GATE_INIT(VCLK1_VENC_BIST);
  151. GATE_INIT(VIDEO_IN);
  152. GATE_INIT(WIFI);
  153. }
  154. void power_init_off(void)
  155. {
  156. GATE_OFF(BT656_IN);
  157. GATE_OFF(VIDEO_IN);
  158. GATE_OFF(GE2D);
  159. GATE_OFF(DEMUX);
  160. GATE_OFF(ETHERNET);
  161. GATE_OFF(WIFI);
  162. CLEAR_CBUS_REG_MASK(HHI_DEMOD_CLK_CNTL, (1 << 8));
  163. CLEAR_CBUS_REG_MASK(HHI_SATA_CLK_CNTL, (1 << 8));
  164. CLEAR_CBUS_REG_MASK(HHI_ETH_CLK_CNTL, (1 << 8));
  165. CLEAR_CBUS_REG_MASK(HHI_WIFI_CLK_CNTL, (1 << 0));
  166. SET_CBUS_REG_MASK(HHI_DEMOD_PLL_CNTL, (1 << 15));
  167. }
  168. void power_gate_switch(int flag)
  169. {
  170. #ifndef ADJUST_CORE_VOLTAGE
  171. GATE_SWITCH(flag, LED_PWM);
  172. #endif
  173. GATE_SWITCH(flag, VGHL_PWM);
  174. GATE_SWITCH(flag, VI_CORE);
  175. GATE_SWITCH(flag, MDEC_CLK_PIC_DC);
  176. GATE_SWITCH(flag, MDEC_CLK_DBLK);
  177. GATE_SWITCH(flag, MDEC_CLK_PSC);
  178. GATE_SWITCH(flag, MDEC_CLK_ASSIST);
  179. GATE_SWITCH(flag, MC_CLK);
  180. GATE_SWITCH(flag, IQIDCT_CLK);
  181. GATE_SWITCH(flag, VLD_CLK);
  182. //GATE_SWITCH(flag, AHB_BRIDGE);
  183. //GATE_SWITCH(flag, AHB_SRAM);
  184. GATE_SWITCH(flag, AIU_ADC);
  185. GATE_SWITCH(flag, AIU_MIXER_REG);
  186. GATE_SWITCH(flag, AIU_AUD_MIXER);
  187. GATE_SWITCH(flag, AIU_AIFIFO2);
  188. GATE_SWITCH(flag, AIU_AMCLK_MEASURE);
  189. GATE_SWITCH(flag, AIU_I2S_OUT);
  190. GATE_SWITCH(flag, AIU_IEC958);
  191. GATE_SWITCH(flag, AIU_AI_TOP_GLUE);
  192. GATE_SWITCH(flag, AIU_AUD_DAC);
  193. GATE_SWITCH(flag, AIU_ICE958_AMCLK);
  194. GATE_SWITCH(flag, AIU_I2S_DAC_AMCLK);
  195. GATE_SWITCH(flag, AIU_I2S_SLOW);
  196. GATE_SWITCH(flag, AIU_AUD_DAC_CLK);
  197. //GATE_SWITCH(flag, ASSIST_MISC);
  198. GATE_SWITCH(flag, AUD_BUF);
  199. GATE_SWITCH(flag, BLK_MOV);
  200. GATE_SWITCH(flag, DEMUX);
  201. //GATE_SWITCH(flag, MMC_DDR);
  202. //GATE_SWITCH(flag, DDR);
  203. #ifndef ETHERNET_ALWAYS
  204. GATE_SWITCH(flag, ETHERNET);
  205. #endif
  206. GATE_SWITCH(flag, HDMI_MPEG_DOMAIN);
  207. //GATE_SWITCH(flag, HIU_PARSER);
  208. GATE_SWITCH(flag, HIU_PARSER_TOP);
  209. //GATE_SWITCH(flag, ISA);
  210. GATE_SWITCH(flag, MEDIA_CPU);
  211. GATE_SWITCH(flag, MISC_USB0_TO_DDR);
  212. GATE_SWITCH(flag, MISC_USB1_TO_DDR);
  213. GATE_SWITCH(flag, MISC_SATA_TO_DDR);
  214. //GATE_SWITCH(flag, AHB_CONTROL_BUS);
  215. //GATE_SWITCH(flag, AHB_DATA_BUS);
  216. //GATE_SWITCH(flag, AXI_BUS);
  217. //GATE_SWITCH(flag, AHB_ARB0);
  218. //GATE_SWITCH(flag, RESET);
  219. GATE_SWITCH(flag, NAND);
  220. GATE_SWITCH(flag, RESERVED0);
  221. //GATE_SWITCH(flag, UART1);
  222. GATE_SWITCH(flag, SDIO);
  223. GATE_SWITCH(flag, ASYNC_FIFO);
  224. GATE_SWITCH(flag, STREAM);
  225. #if (defined CONFIG_MACH_MESON_8726M_REFC03)
  226. GATE_SWITCH(flag, RTC);
  227. #endif
  228. //GATE_SWITCH(flag, UART0);
  229. GATE_SWITCH(flag, RANDOM_NUM_GEN);
  230. GATE_SWITCH(flag, SMART_CARD_MPEG_DOMAIN);
  231. GATE_SWITCH(flag, SMART_CARD);
  232. GATE_SWITCH(flag, SAR_ADC);
  233. GATE_SWITCH(flag, I2C);
  234. #if (!defined CONFIG_MACH_MESON_8726M_REFC03)&&(!defined CONFIG_MACH_MESON_8726M_REFC06)
  235. GATE_SWITCH(flag, IR_REMOTE);
  236. #endif
  237. //GATE_SWITCH(flag, _1200XXX);
  238. GATE_SWITCH(flag, SATA);
  239. GATE_SWITCH(flag, SPI1);
  240. GATE_SWITCH(flag, SPI2);
  241. GATE_SWITCH(flag, USB1);
  242. GATE_SWITCH(flag, USB0);
  243. GATE_SWITCH(flag, WIFI);
  244. }
  245. EXPORT_SYMBOL(power_gate_switch);
  246. void early_power_gate_switch(int flag)
  247. {
  248. GATE_SWITCH(flag, AMRISC);
  249. GATE_SWITCH(flag, AUD_IN);
  250. GATE_SWITCH(flag, BLK_MOV);
  251. GATE_SWITCH(flag, BT656_IN);
  252. GATE_SWITCH(flag, GE2D);
  253. GATE_SWITCH(flag, ROM_CLK);
  254. GATE_SWITCH(flag, EFUSE);
  255. GATE_SWITCH(flag, RESERVED0);
  256. GATE_SWITCH(flag, LCD);
  257. GATE_SWITCH(flag, ENC480P_MPEG_DOMAIN);
  258. GATE_SWITCH(flag, ENC480I);
  259. GATE_SWITCH(flag, VENC_MISC);
  260. GATE_SWITCH(flag, ENC480P);
  261. GATE_SWITCH(flag, HDMI);
  262. GATE_SWITCH(flag, VCLK3_DAC);
  263. GATE_SWITCH(flag, VCLK3_MISC);
  264. GATE_SWITCH(flag, VCLK3_DVI);
  265. GATE_SWITCH(flag, VCLK2_VIU);
  266. GATE_SWITCH(flag, VCLK2_VENC_DVI);
  267. GATE_SWITCH(flag, VCLK2_VENC_ENC480P);
  268. GATE_SWITCH(flag, VCLK2_VENC_BIST);
  269. GATE_SWITCH(flag, VCLK1_VENC_656);
  270. GATE_SWITCH(flag, VCLK1_VENC_DVI);
  271. GATE_SWITCH(flag, VCLK1_VENC_ENCI);
  272. GATE_SWITCH(flag, VCLK1_VENC_BIST);
  273. GATE_SWITCH(flag, VIDEO_IN);
  274. }
  275. EXPORT_SYMBOL(early_power_gate_switch);
  276. #ifndef ETHERNET_ALWAYS
  277. #define CLK_COUNT 9
  278. #else
  279. #define CLK_COUNT 8
  280. #endif
  281. static char clk_flag[CLK_COUNT];
  282. static unsigned clks[CLK_COUNT] = {
  283. HHI_DEMOD_CLK_CNTL,
  284. HHI_SATA_CLK_CNTL,
  285. #ifndef ETHERNET_ALWAYS
  286. HHI_ETH_CLK_CNTL,
  287. #endif
  288. HHI_WIFI_CLK_CNTL,
  289. HHI_VID_CLK_CNTL,
  290. HHI_AUD_CLK_CNTL,
  291. HHI_MALI_CLK_CNTL,
  292. HHI_HDMI_CLK_CNTL,
  293. HHI_MPEG_CLK_CNTL,
  294. };
  295. static char clks_name[CLK_COUNT][32] = {
  296. "HHI_DEMOD_CLK_CNTL",
  297. "HHI_SATA_CLK_CNTL",
  298. #ifndef ETHERNET_ALWAYS
  299. "HHI_ETH_CLK_CNTL",
  300. #endif
  301. "HHI_WIFI_CLK_CNTL",
  302. "HHI_VID_CLK_CNTL",
  303. "HHI_AUD_CLK_CNTL",
  304. "HHI_MALI_CLK_CNTL",
  305. "HHI_HDMI_CLK_CNTL",
  306. "HHI_MPEG_CLK_CNTL",
  307. };
  308. #ifdef EARLY_SUSPEND_USE_XTAL
  309. #ifndef ETHERNET_ALWAYS
  310. #define EARLY_CLK_COUNT 6
  311. #else
  312. #define EARLY_CLK_COUNT 5
  313. #endif
  314. #else
  315. #ifndef ETHERNET_ALWAYS
  316. #define EARLY_CLK_COUNT 5
  317. #else
  318. #define EARLY_CLK_COUNT 4
  319. #endif
  320. #endif
  321. static char early_clk_flag[EARLY_CLK_COUNT];
  322. static unsigned early_clks[EARLY_CLK_COUNT] = {
  323. HHI_DEMOD_CLK_CNTL,
  324. HHI_SATA_CLK_CNTL,
  325. #ifndef ETHERNET_ALWAYS
  326. HHI_ETH_CLK_CNTL,
  327. #endif
  328. HHI_WIFI_CLK_CNTL,
  329. HHI_VID_CLK_CNTL,
  330. #ifdef EARLY_SUSPEND_USE_XTAL
  331. HHI_MPEG_CLK_CNTL,
  332. #endif
  333. };
  334. static char early_clks_name[EARLY_CLK_COUNT][32] = {
  335. "HHI_DEMOD_CLK_CNTL",
  336. "HHI_SATA_CLK_CNTL",
  337. #ifndef ETHERNET_ALWAYS
  338. "HHI_ETH_CLK_CNTL",
  339. #endif
  340. "HHI_WIFI_CLK_CNTL",
  341. "HHI_VID_CLK_CNTL",
  342. #ifdef EARLY_SUSPEND_USE_XTAL
  343. "HHI_MPEG_CLK_CNTL",
  344. #endif
  345. };
  346. static unsigned uart_rate_backup;
  347. static unsigned xtal_uart_rate_backup;
  348. void clk_switch(int flag)
  349. {
  350. int i;
  351. if (flag) {
  352. for (i = CLK_COUNT - 1; i >= 0; i--) {
  353. if (clk_flag[i]) {
  354. if ((clks[i] == HHI_VID_CLK_CNTL)
  355. || (clks[i] == HHI_WIFI_CLK_CNTL)) {
  356. SET_CBUS_REG_MASK(clks[i], 1);
  357. } else if (clks[i] == HHI_MPEG_CLK_CNTL) {
  358. udelay(1000);
  359. SET_CBUS_REG_MASK(clks[i], (1 << 8)); // normal
  360. CLEAR_CBUS_REG_MASK(UART0_CONTROL,
  361. (1 << 19) | 0xFFF);
  362. SET_CBUS_REG_MASK(UART0_CONTROL,
  363. (((uart_rate_backup /
  364. (115200 * 4)) -
  365. 1) & 0xfff));
  366. CLEAR_CBUS_REG_MASK(UART1_CONTROL,
  367. (1 << 19) | 0xFFF);
  368. SET_CBUS_REG_MASK(UART1_CONTROL,
  369. (((uart_rate_backup /
  370. (115200 * 4)) -
  371. 1) & 0xfff));
  372. } else {
  373. SET_CBUS_REG_MASK(clks[i], (1 << 8));
  374. }
  375. clk_flag[i] = 0;
  376. printk(KERN_INFO "clk %s(%x) on\n",
  377. clks_name[i], clks[i]);
  378. }
  379. }
  380. } else {
  381. for (i = 0; i < CLK_COUNT; i++) {
  382. if ((clks[i] == HHI_VID_CLK_CNTL)
  383. || (clks[i] == HHI_WIFI_CLK_CNTL)) {
  384. clk_flag[i] = READ_CBUS_REG_BITS(clks[i], 0, 1);
  385. if (clk_flag[i]) {
  386. CLEAR_CBUS_REG_MASK(clks[i], 1);
  387. }
  388. } else if (clks[i] == HHI_MPEG_CLK_CNTL) {
  389. if (READ_CBUS_REG(clks[i]) & (1 << 8)) {
  390. clk_flag[i] = 1;
  391. udelay(1000);
  392. CLEAR_CBUS_REG_MASK(clks[i], (1 << 8)); // 24M
  393. CLEAR_CBUS_REG_MASK(UART0_CONTROL,
  394. (1 << 19) | 0xFFF);
  395. SET_CBUS_REG_MASK(UART0_CONTROL,
  396. (((xtal_uart_rate_backup / (115200 * 4)) - 1) & 0xfff));
  397. CLEAR_CBUS_REG_MASK(UART1_CONTROL,
  398. (1 << 19) | 0xFFF);
  399. SET_CBUS_REG_MASK(UART1_CONTROL,
  400. (((xtal_uart_rate_backup / (115200 * 4)) - 1) & 0xfff));
  401. }
  402. } else {
  403. clk_flag[i] =
  404. READ_CBUS_REG_BITS(clks[i], 8, 1) ? 1 : 0;
  405. if (clk_flag[i])
  406. CLEAR_CBUS_REG_MASK(clks[i], (1 << 8));
  407. }
  408. if (clk_flag[i])
  409. printk(KERN_INFO "clk %s(%x) off\n",
  410. clks_name[i], clks[i]);
  411. }
  412. }
  413. }
  414. EXPORT_SYMBOL(clk_switch);
  415. void early_clk_switch(int flag)
  416. {
  417. int i;
  418. struct clk *sys_clk;
  419. if (flag) {
  420. for (i = EARLY_CLK_COUNT - 1; i >= 0; i--) {
  421. if (early_clk_flag[i]) {
  422. if ((early_clks[i] == HHI_VID_CLK_CNTL)
  423. || (early_clks[i] == HHI_WIFI_CLK_CNTL)) {
  424. SET_CBUS_REG_MASK(early_clks[i], 1);
  425. } else if (early_clks[i] == HHI_MPEG_CLK_CNTL) {
  426. udelay(1000);
  427. SET_CBUS_REG_MASK(early_clks[i], (1 << 8)); // clk81 back to normal
  428. CLEAR_CBUS_REG_MASK(UART0_CONTROL,
  429. (1 << 19) | 0xFFF);
  430. SET_CBUS_REG_MASK(UART0_CONTROL,
  431. (((uart_rate_backup /
  432. (115200 * 4)) -
  433. 1) & 0xfff));
  434. CLEAR_CBUS_REG_MASK(UART1_CONTROL,
  435. (1 << 19) | 0xFFF);
  436. SET_CBUS_REG_MASK(UART1_CONTROL,
  437. (((uart_rate_backup /
  438. (115200 * 4)) -
  439. 1) & 0xfff));
  440. } else {
  441. SET_CBUS_REG_MASK(early_clks[i],
  442. (1 << 8));
  443. }
  444. printk(KERN_INFO "late clk %s(%x) on\n",
  445. early_clks_name[i], early_clks[i]);
  446. early_clk_flag[i] = 0;
  447. }
  448. }
  449. } else {
  450. sys_clk = clk_get_sys("clk81", NULL);
  451. uart_rate_backup = sys_clk->rate;
  452. sys_clk = clk_get_sys("clk_xtal", NULL);
  453. xtal_uart_rate_backup = sys_clk->rate;
  454. for (i = 0; i < EARLY_CLK_COUNT; i++) {
  455. if ((early_clks[i] == HHI_VID_CLK_CNTL)
  456. || (early_clks[i] == HHI_WIFI_CLK_CNTL)) {
  457. early_clk_flag[i] =
  458. READ_CBUS_REG_BITS(early_clks[i], 0, 1);
  459. if (early_clk_flag[i]) {
  460. CLEAR_CBUS_REG_MASK(early_clks[i], 1);
  461. }
  462. } else if (early_clks[i] == HHI_MPEG_CLK_CNTL) {
  463. early_clk_flag[i] = 1;
  464. udelay(1000);
  465. CLEAR_CBUS_REG_MASK(early_clks[i], (1 << 8)); // 24M
  466. CLEAR_CBUS_REG_MASK(UART0_CONTROL,
  467. (1 << 19) | 0xFFF);
  468. SET_CBUS_REG_MASK(UART0_CONTROL,
  469. (((xtal_uart_rate_backup /
  470. (115200 * 4)) -
  471. 1) & 0xfff));
  472. CLEAR_CBUS_REG_MASK(UART1_CONTROL,
  473. (1 << 19) | 0xFFF);
  474. SET_CBUS_REG_MASK(UART1_CONTROL,
  475. (((xtal_uart_rate_backup /
  476. (115200 * 4)) -
  477. 1) & 0xfff));
  478. } else {
  479. early_clk_flag[i] =
  480. READ_CBUS_REG_BITS(early_clks[i], 8,
  481. 1) ? 1 : 0;
  482. if (early_clk_flag[i]) {
  483. CLEAR_CBUS_REG_MASK(early_clks[i],
  484. (1 << 8));
  485. }
  486. }
  487. if (early_clk_flag[i])
  488. printk(KERN_INFO "early clk %s(%x) off\n",
  489. early_clks_name[i], early_clks[i]);
  490. }
  491. }
  492. }
  493. EXPORT_SYMBOL(early_clk_switch);
  494. #define PLL_COUNT 4
  495. static char pll_flag[PLL_COUNT];
  496. static unsigned plls[PLL_COUNT] = {
  497. HHI_DEMOD_PLL_CNTL,
  498. HHI_VID_PLL_CNTL,
  499. HHI_AUD_PLL_CNTL,
  500. HHI_OTHER_PLL_CNTL,
  501. };
  502. static char plls_name[PLL_COUNT][32] = {
  503. "HHI_DEMOD_PLL_CNTL",
  504. "HHI_VID_PLL_CNTL",
  505. "HHI_AUD_PLL_CNTL",
  506. "HHI_OTHER_PLL_CNTL",
  507. };
  508. #define EARLY_PLL_COUNT 2
  509. static char early_pll_flag[EARLY_PLL_COUNT];
  510. static unsigned early_plls[EARLY_PLL_COUNT] = {
  511. HHI_DEMOD_PLL_CNTL,
  512. HHI_VID_PLL_CNTL,
  513. };
  514. static char early_plls_name[EARLY_PLL_COUNT][32] = {
  515. "HHI_DEMOD_PLL_CNTL",
  516. "HHI_VID_PLL_CNTL",
  517. };
  518. void pll_switch(int flag)
  519. {
  520. int i;
  521. if (flag) {
  522. for (i = PLL_COUNT - 1; i >= 0; i--) {
  523. if (pll_flag[i]) {
  524. CLEAR_CBUS_REG_MASK(plls[i], (1<<15));
  525. pll_flag[i] = 0;
  526. printk(KERN_INFO "pll %s(%x) on\n", plls_name[i], plls[i]);
  527. }
  528. }
  529. udelay(1000);
  530. }
  531. else{
  532. for (i=0;i<PLL_COUNT;i++){
  533. pll_flag[i] = READ_CBUS_REG_BITS(plls[i], 15, 1) ? 0 : 1;
  534. if (pll_flag[i]){
  535. printk(KERN_INFO "pll %s(%x) off\n", plls_name[i], plls[i]);
  536. SET_CBUS_REG_MASK(plls[i], (1<<15));
  537. }
  538. }
  539. }
  540. }
  541. EXPORT_SYMBOL(pll_switch);
  542. void early_pll_switch(int flag)
  543. {
  544. int i;
  545. if (flag) {
  546. for (i = EARLY_PLL_COUNT - 1; i >= 0; i--) {
  547. if (early_pll_flag[i]) {
  548. CLEAR_CBUS_REG_MASK(early_plls[i], (1 << 15));
  549. early_pll_flag[i] = 0;
  550. printk(KERN_INFO "late pll %s(%x) on\n", early_plls_name[i], early_plls[i]);
  551. }
  552. }
  553. udelay(1000);
  554. }
  555. else{
  556. for (i=0;i<EARLY_PLL_COUNT;i++){
  557. early_pll_flag[i] = READ_CBUS_REG_BITS(early_plls[i], 15, 1) ? 0 : 1;
  558. if (early_pll_flag[i]){
  559. printk(KERN_INFO "early pll %s(%x) off\n", early_plls_name[i], early_plls[i]);
  560. SET_CBUS_REG_MASK(early_plls[i], (1<<15));
  561. }
  562. }
  563. }
  564. }
  565. EXPORT_SYMBOL(early_pll_switch);
  566. typedef struct {
  567. char name[32];
  568. unsigned reg_addr;
  569. unsigned set_bits;
  570. unsigned clear_bits;
  571. unsigned reg_value;
  572. unsigned enable; // 1:cbus 2:apb 3:ahb 0:disable
  573. } analog_t;
  574. #if (!defined CONFIG_MACH_MESON_8726M_REFC03)&&(!defined CONFIG_MACH_MESON_8726M_REFC06)
  575. #define ANALOG_COUNT 8
  576. #else
  577. #define ANALOG_COUNT 5
  578. #endif
  579. static analog_t analog_regs[ANALOG_COUNT] = {
  580. {"SAR_ADC", SAR_ADC_REG3, 1<<28, (1<<30)|(1<<21), 0, 1},
  581. {"LED_PWM_REG0", LED_PWM_REG0, 1<<13, 1<<12, 0, 0}, // needed for core voltage adjustment, so not off
  582. {"VGHL_PWM_REG0", VGHL_PWM_REG0, 1<<13, 1<<12, 0, 1},
  583. {"WIFI_ADC_SAMPLING", WIFI_ADC_SAMPLING, 0, 1<<18, 0, 1},
  584. {"ADC_EN_ADC", ADC_EN_ADC, 0, 1<<31, 0, 2},
  585. #if (!defined CONFIG_MACH_MESON_8726M_REFC03)&&(!defined CONFIG_MACH_MESON_8726M_REFC06)
  586. {"WIFI_ADC_DAC", WIFI_ADC_DAC, (3<<10)|0xff, 0, 0, 3},
  587. {"ADC_EN_CMLGEN_RES", ADC_EN_CMLGEN_RES, 0, (1<<26)|(1<<25), 0, 3},
  588. {"WIFI_SARADC", WIFI_SARADC, 0, 1<<2, 0, 3},
  589. #endif
  590. };
  591. void analog_switch(int flag)
  592. {
  593. int i;
  594. unsigned reg_value = 0;
  595. if (flag) {
  596. printk(KERN_INFO "analog on\n");
  597. SET_CBUS_REG_MASK(AM_ANALOG_TOP_REG0, 1 << 1); // set 0x206e bit[1] 1 to power on top analog
  598. for (i = 0; i < ANALOG_COUNT; i++) {
  599. if (analog_regs[i].enable
  600. && (analog_regs[i].set_bits
  601. || analog_regs[i].clear_bits)) {
  602. if (analog_regs[i].enable == 1)
  603. WRITE_CBUS_REG(analog_regs[i].reg_addr,
  604. analog_regs[i].
  605. reg_value);
  606. else if (analog_regs[i].enable == 2)
  607. WRITE_APB_REG(analog_regs[i].reg_addr,
  608. analog_regs[i].reg_value);
  609. else if (analog_regs[i].enable == 3)
  610. WRITE_AHB_REG(analog_regs[i].reg_addr,
  611. analog_regs[i].reg_value);
  612. }
  613. }
  614. } else {
  615. printk(KERN_INFO "analog off\n");
  616. for (i = 0; i < ANALOG_COUNT; i++) {
  617. if (analog_regs[i].enable
  618. && (analog_regs[i].set_bits
  619. || analog_regs[i].clear_bits)) {
  620. if (analog_regs[i].enable == 1) {
  621. analog_regs[i].reg_value =
  622. READ_CBUS_REG(analog_regs[i].
  623. reg_addr);
  624. printk("%s(0x%x):0x%x",
  625. analog_regs[i].name,
  626. CBUS_REG_ADDR(analog_regs[i].
  627. reg_addr),
  628. analog_regs[i].reg_value);
  629. if (analog_regs[i].clear_bits) {
  630. CLEAR_CBUS_REG_MASK(analog_regs
  631. [i].
  632. reg_addr,
  633. analog_regs
  634. [i].
  635. clear_bits);
  636. printk(" & ~0x%x",
  637. analog_regs[i].
  638. clear_bits);
  639. }
  640. if (analog_regs[i].set_bits) {
  641. SET_CBUS_REG_MASK(analog_regs
  642. [i].reg_addr,
  643. analog_regs
  644. [i].set_bits);
  645. printk(" | 0x%x",
  646. analog_regs[i].set_bits);
  647. }
  648. reg_value =
  649. READ_CBUS_REG(analog_regs[i].
  650. reg_addr);
  651. printk(" = 0x%x\n", reg_value);
  652. } else if (analog_regs[i].enable == 2) {
  653. analog_regs[i].reg_value =
  654. READ_APB_REG(analog_regs[i].
  655. reg_addr);
  656. printk("%s(0x%x):0x%x",
  657. analog_regs[i].name,
  658. APB_REG_ADDR(analog_regs[i].
  659. reg_addr),
  660. analog_regs[i].reg_value);
  661. if (analog_regs[i].clear_bits) {
  662. CLEAR_APB_REG_MASK(analog_regs
  663. [i].reg_addr,
  664. analog_regs
  665. [i].
  666. clear_bits);
  667. printk(" & ~0x%x",
  668. analog_regs[i].
  669. clear_bits);
  670. }
  671. if (analog_regs[i].set_bits) {
  672. SET_APB_REG_MASK(analog_regs[i].
  673. reg_addr,
  674. analog_regs[i].
  675. set_bits);
  676. printk(" | 0x%x",
  677. analog_regs[i].set_bits);
  678. }
  679. reg_value =
  680. READ_APB_REG(analog_regs[i].
  681. reg_addr);
  682. printk(" = 0x%x\n", reg_value);
  683. } else if (analog_regs[i].enable == 3) {
  684. analog_regs[i].reg_value =
  685. READ_AHB_REG(analog_regs[i].
  686. reg_addr);
  687. printk("%s(0x%x):0x%x",
  688. analog_regs[i].name,
  689. AHB_REG_ADDR(analog_regs[i].
  690. reg_addr),
  691. analog_regs[i].reg_value);
  692. if (analog_regs[i].clear_bits) {
  693. CLEAR_AHB_REG_MASK(analog_regs
  694. [i].reg_addr,
  695. analog_regs
  696. [i].
  697. clear_bits);
  698. printk(" & ~0x%x",
  699. analog_regs[i].
  700. clear_bits);
  701. }
  702. if (analog_regs[i].set_bits) {
  703. SET_AHB_REG_MASK(analog_regs[i].
  704. reg_addr,
  705. analog_regs[i].
  706. set_bits);
  707. printk(" | 0x%x",
  708. analog_regs[i].set_bits);
  709. }
  710. reg_value =
  711. READ_AHB_REG(analog_regs[i].
  712. reg_addr);
  713. printk(" = 0x%x\n", reg_value);
  714. }
  715. }
  716. }
  717. CLEAR_CBUS_REG_MASK(AM_ANALOG_TOP_REG0, 1 << 1); // set 0x206e bit[1] 0 to shutdown top analog
  718. }
  719. }
  720. void usb_switch(int is_on, int ctrl)
  721. {
  722. int index, por;
  723. if (ctrl == 0)
  724. index = USB_CTL_INDEX_A;
  725. else
  726. index = USB_CTL_INDEX_B;
  727. if (is_on)
  728. por = USB_CTL_POR_ON;
  729. else
  730. por = USB_CTL_POR_OFF;
  731. set_usb_ctl_por(index, por);
  732. }
  733. #if defined(CONFIG_SUSPEND)
  734. extern void set_standby_led(char is_standby);
  735. #endif
  736. #ifdef CONFIG_HAS_EARLYSUSPEND
  737. static void meson_system_early_suspend(struct early_suspend *h)
  738. {
  739. if (!early_suspend_flag) {
  740. printk(KERN_INFO "sys_suspend\n");
  741. if (pdata->set_exgpio_early_suspend) {
  742. pdata->set_exgpio_early_suspend(OFF);
  743. }
  744. early_power_gate_switch(OFF);
  745. early_clk_switch(OFF);
  746. early_pll_switch(OFF);
  747. early_suspend_flag = 1;
  748. #if (defined(CONFIG_SUSPEND))&&(defined(CONFIG_MACH_MESON_8726M_REFC06))
  749. set_standby_led(1);
  750. #endif
  751. }
  752. }
  753. static void meson_system_late_resume(struct early_suspend *h)
  754. {
  755. if (early_suspend_flag) {
  756. early_pll_switch(ON);
  757. early_clk_switch(ON);
  758. early_power_gate_switch(ON);
  759. early_suspend_flag = 0;
  760. if (pdata->set_exgpio_early_suspend) {
  761. pdata->set_exgpio_early_suspend(ON);
  762. }
  763. printk(KERN_INFO "sys_resume\n");
  764. #if (defined(CONFIG_SUSPEND))&&(defined(CONFIG_MACH_MESON_8726M_REFC06))
  765. set_standby_led(0);
  766. #endif
  767. }
  768. }
  769. #endif
  770. #define MODE_DELAYED_WAKE 0
  771. #define MODE_IRQ_DELAYED_WAKE 1
  772. #define MODE_IRQ_ONLY_WAKE 2
  773. static void auto_clk_gating_setup(unsigned long sleep_dly_tb,
  774. unsigned long mode, unsigned long clear_fiq,
  775. unsigned long clear_irq,
  776. unsigned long start_delay,
  777. unsigned long clock_gate_dly,
  778. unsigned long sleep_time,
  779. unsigned long enable_delay)
  780. {
  781. WRITE_CBUS_REG(HHI_A9_AUTO_CLK0, (sleep_dly_tb << 24) | // sleep timebase
  782. (sleep_time << 16) | // sleep time
  783. (clear_irq << 5) | // clear IRQ
  784. (clear_fiq << 4) | // clear FIQ
  785. (mode << 2)); // mode
  786. WRITE_CBUS_REG(HHI_A9_AUTO_CLK1, (0 << 20) | // start delay timebase
  787. (enable_delay << 12) | // enable delay
  788. (clock_gate_dly << 8) | // clock gate delay
  789. (start_delay << 0)); // start delay
  790. SET_CBUS_REG_MASK(HHI_A9_AUTO_CLK0, 1 << 0);
  791. }
  792. static void meson_pm_suspend(void)
  793. {
  794. #ifdef SAVE_DDR_REGS
  795. int *p = pdata->ddr_reg_backup;
  796. int i;
  797. #endif
  798. unsigned ddr_clk_N;
  799. unsigned mpeg_clk_backup;
  800. printk(KERN_INFO "enter meson_pm_suspend!\n");
  801. pdata->ddr_clk = READ_CBUS_REG(HHI_DDR_PLL_CNTL);
  802. ddr_clk_N = (pdata->ddr_clk >> 9) & 0x1f;
  803. ddr_clk_N = ddr_clk_N * 4; // N*4
  804. if (ddr_clk_N > 0x1f)
  805. ddr_clk_N = 0x1f;
  806. pdata->ddr_clk &= ~(0x1f << 9);
  807. pdata->ddr_clk |= ddr_clk_N << 9;
  808. printk(KERN_INFO "target ddr clock 0x%x!\n", pdata->ddr_clk);
  809. analog_switch(OFF);
  810. usb_switch(OFF, 0);
  811. usb_switch(OFF, 1);
  812. if (pdata->set_vccx2) {
  813. pdata->set_vccx2(OFF);
  814. }
  815. power_gate_switch(OFF);
  816. #ifdef SAVE_DDR_REGS
  817. printk("PCTL_TOGCNT1U_ADDR %x\n", READ_APB_REG(PCTL_TOGCNT1U_ADDR));
  818. printk("PCTL_TOGCNT100N_ADDR %x\n", READ_APB_REG(PCTL_TOGCNT100N_ADDR));
  819. printk("PCTL_TREFI_ADDR %x\n", READ_APB_REG(PCTL_TREFI_ADDR));
  820. printk("PCTL_ZQCR_ADDR %x\n", READ_APB_REG(PCTL_ZQCR_ADDR));
  821. printk("PCTL_ODTCFG_ADDR %x\n", READ_APB_REG(PCTL_ODTCFG_ADDR));
  822. printk("PCTL_TMRD_ADDR %x\n", READ_APB_REG(PCTL_TMRD_ADDR));
  823. printk("PCTL_TRFC_ADDR %x\n", READ_APB_REG(PCTL_TRFC_ADDR));
  824. printk("PCTL_TRP_ADDR %x\n", READ_APB_REG(PCTL_TRP_ADDR));
  825. printk("PCTL_TAL_ADDR %x\n", READ_APB_REG(PCTL_TAL_ADDR));
  826. printk("PCTL_TCWL_ADDR %x\n", READ_APB_REG(PCTL_TCWL_ADDR));
  827. printk("PCTL_TCL_ADDR %x\n", READ_APB_REG(PCTL_TCL_ADDR));
  828. printk("PCTL_TRAS_ADDR %x\n", READ_APB_REG(PCTL_TRAS_ADDR));
  829. printk("PCTL_TRC_ADDR %x\n", READ_APB_REG(PCTL_TRC_ADDR));
  830. printk("PCTL_TRCD_ADDR %x\n", READ_APB_REG(PCTL_TRCD_ADDR));
  831. printk("PCTL_TRRD_ADDR %x\n", READ_APB_REG(PCTL_TRRD_ADDR));
  832. printk("PCTL_TRTP_ADDR %x\n", READ_APB_REG(PCTL_TRTP_ADDR));
  833. printk("PCTL_TWR_ADDR %x\n", READ_APB_REG(PCTL_TWR_ADDR));
  834. printk("PCTL_TWTR_ADDR %x\n", READ_APB_REG(PCTL_TWTR_ADDR));
  835. printk("PCTL_TEXSR_ADDR %x\n", READ_APB_REG(PCTL_TEXSR_ADDR));
  836. printk("PCTL_TXP_ADDR %x\n", READ_APB_REG(PCTL_TXP_ADDR));
  837. printk("PCTL_TDQS_ADDR %x\n", READ_APB_REG(PCTL_TDQS_ADDR));
  838. printk("PCTL_MCFG_ADDR %x\n", READ_APB_REG(PCTL_MCFG_ADDR));
  839. printk("PCTL_RSLR0_ADDR %x\n", READ_APB_REG(PCTL_RSLR0_ADDR));
  840. printk("PCTL_RDGR0_ADDR %x\n", READ_APB_REG(PCTL_RDGR0_ADDR));
  841. printk("MMC_DDR_CTRL %x\n", READ_APB_REG(MMC_DDR_CTRL));
  842. #endif
  843. clk_switch(OFF);
  844. pll_switch(OFF);
  845. printk("meson_sram_suspend params 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x\n",
  846. (unsigned)pdata->pctl_reg_base, (unsigned)pdata->mmc_reg_base,
  847. (unsigned)pdata->hiu_reg_base, (unsigned)pdata->power_key,
  848. (unsigned)pdata->ddr_clk, (unsigned)pdata->ddr_reg_backup);
  849. meson_sram_push(meson_sram_suspend, meson_cpu_suspend,
  850. meson_cpu_suspend_sz);
  851. printk(KERN_INFO "sleep ...\n");
  852. mpeg_clk_backup = READ_CBUS_REG(HHI_MPEG_CLK_CNTL); // save clk81 ctrl
  853. #ifdef SYSTEM_16K
  854. if (READ_CBUS_REG(HHI_MPEG_CLK_CNTL) & (1 << 8))
  855. CLEAR_CBUS_REG_MASK(HHI_MPEG_CLK_CNTL, (1 << 8)); // clk81 = xtal
  856. SET_CBUS_REG_MASK(HHI_MPEG_CLK_CNTL, (1 << 9)); // xtal_rtc = rtc
  857. WRITE_CBUS_REG_BITS(HHI_MPEG_CLK_CNTL, 0x1, 0, 6); // devider = 2
  858. WRITE_CBUS_REG_BITS(HHI_MPEG_CLK_CNTL, 0, 12, 2); // clk81 src -> xtal_rtc
  859. SET_CBUS_REG_MASK(HHI_MPEG_CLK_CNTL, (1 << 8)); // clk81 = xtal_rtc / devider
  860. #else
  861. if (READ_CBUS_REG(HHI_MPEG_CLK_CNTL) & (1 << 8))
  862. CLEAR_CBUS_REG_MASK(HHI_MPEG_CLK_CNTL, (1 << 8)); // clk81 = xtal
  863. #if (!defined CONFIG_MACH_MESON_8726M_REFC03)&&(!defined CONFIG_MACH_MESON_8726M_REFC06)
  864. WRITE_CBUS_REG_BITS(HHI_MPEG_CLK_CNTL, 0x7f, 0, 6); // devider = 128
  865. #else
  866. WRITE_CBUS_REG_BITS(HHI_MPEG_CLK_CNTL, 0x1e, 0, 6); // devider = 30
  867. #endif
  868. WRITE_CBUS_REG_BITS(HHI_MPEG_CLK_CNTL, 0, 12, 2); // clk81 src -> xtal_rtc
  869. SET_CBUS_REG_MASK(HHI_MPEG_CLK_CNTL, (1 << 8)); // clk81 = xtal_rtc / devider
  870. #endif
  871. CLEAR_CBUS_REG_MASK(HHI_A9_CLK_CNTL, (1 << 7)); // clka9 = xtal_rtc / 2
  872. #ifdef SYSTEM_16K
  873. SET_CBUS_REG_MASK(PREG_CTLREG0_ADDR, 1);
  874. #endif
  875. auto_clk_gating_setup(2, // select 100uS timebase
  876. MODE_IRQ_ONLY_WAKE, // Set interrupt wakeup only
  877. 0, // don't clear the FIQ global mask
  878. 0, // don't clear the IRQ global mask
  879. 1, // 1us start delay
  880. 1, // 1uS gate delay
  881. 1, // Set the delay wakeup time (1mS)
  882. 1); // 1uS enable delay
  883. SET_CBUS_REG_MASK(HHI_SYS_PLL_CNTL, (1 << 15)); // turn off sys pll
  884. #if (defined CONFIG_MACH_MESON_8726M_REFC01) || (defined CONFIG_MACH_MESON_8726M_REFC03)
  885. WRITE_CBUS_REG(A9_0_IRQ_IN0_INTR_MASK, pdata->power_key); // enable remote interrupt only
  886. #elif (defined CONFIG_MACH_MESON_8726M_REFC06)
  887. WRITE_CBUS_REG(A9_0_IRQ_IN0_INTR_MASK, pdata->power_key); // enable remote interrupt only
  888. WRITE_CBUS_REG(A9_0_IRQ_IN2_INTR_MASK, 1);
  889. #else
  890. WRITE_CBUS_REG(A9_0_IRQ_IN2_INTR_MASK, pdata->power_key); // enable rtc interrupt only
  891. #endif
  892. #if (defined CONFIG_MACH_MESON_8726M_REFC03)||(defined CONFIG_MACH_MESON_8726M_REFC06)
  893. int tmp_data = 0;
  894. tmp_data = READ_CBUS_REG(PREG_CTLREG0_ADDR);
  895. WRITE_CBUS_REG(PREG_CTLREG0_ADDR, tmp_data | 0x1);
  896. tmp_data = READ_CBUS_REG(IR_DEC_REG0);
  897. WRITE_CBUS_REG(IR_DEC_REG0, tmp_data & 0xFFFFFF00);
  898. tmp_data = READ_CBUS_REG(IR_DEC_REG1);
  899. WRITE_CBUS_REG(IR_DEC_REG1, tmp_data | 0x00000001);
  900. WRITE_CBUS_REG(IR_DEC_REG1, tmp_data & 0xFFFFFFFE);
  901. #endif
  902. meson_sram_suspend(pdata);
  903. CLEAR_CBUS_REG_MASK(HHI_SYS_PLL_CNTL, (1 << 15)); // turn on sys pll
  904. udelay(10);
  905. #ifdef SYSTEM_16K
  906. CLEAR_CBUS_REG_MASK(PREG_CTLREG0_ADDR, 1);
  907. #endif
  908. SET_CBUS_REG_MASK(HHI_A9_CLK_CNTL, (1 << 7)); // clka9 = sys pll / devider
  909. CLEAR_CBUS_REG_MASK(HHI_MPEG_CLK_CNTL, (1 << 8)); // clk81 = xtal
  910. #ifdef SYSTEM_16K
  911. CLEAR_CBUS_REG_MASK(HHI_MPEG_CLK_CNTL, (1 << 9)); // xtal_rtc = xtal
  912. #endif
  913. WRITE_CBUS_REG(HHI_MPEG_CLK_CNTL, mpeg_clk_backup); // restore clk81 ctrl
  914. #if (defined CONFIG_MACH_MESON_8726M_REFC03)||(defined CONFIG_MACH_MESON_8726M_REFC06)
  915. tmp_data = READ_CBUS_REG(PREG_CTLREG0_ADDR);
  916. WRITE_CBUS_REG(PREG_CTLREG0_ADDR, tmp_data & 0xFFFFFFFE);
  917. tmp_data = READ_CBUS_REG(IR_DEC_REG0);
  918. WRITE_CBUS_REG(IR_DEC_REG0, tmp_data | 0x00000013);
  919. tmp_data = READ_CBUS_REG(IR_DEC_REG1);
  920. WRITE_CBUS_REG(IR_DEC_REG1, tmp_data | 0x00000001);
  921. WRITE_CBUS_REG(IR_DEC_REG1, tmp_data & 0xFFFFFFFE);
  922. #endif
  923. printk(KERN_INFO "... wake up\n");
  924. if (pdata->set_vccx2) {
  925. pdata->set_vccx2(ON);
  926. }
  927. pll_switch(ON);
  928. clk_switch(ON);
  929. #ifdef SAVE_DDR_REGS
  930. for (i = 0; i < 100 / 4; i++)
  931. printk("%x\n", p[i]);
  932. #endif
  933. power_gate_switch(ON);
  934. usb_switch(ON, 0);
  935. usb_switch(ON, 1);
  936. analog_switch(ON);
  937. }
  938. static int meson_pm_prepare(void)
  939. {
  940. printk(KERN_INFO "enter meson_pm_prepare!\n");
  941. mask_save[0] = READ_CBUS_REG(A9_0_IRQ_IN0_INTR_MASK);
  942. mask_save[1] = READ_CBUS_REG(A9_0_IRQ_IN1_INTR_MASK);
  943. mask_save[2] = READ_CBUS_REG(A9_0_IRQ_IN2_INTR_MASK);
  944. mask_save[3] = READ_CBUS_REG(A9_0_IRQ_IN3_INTR_MASK);
  945. WRITE_CBUS_REG(A9_0_IRQ_IN0_INTR_MASK, 0x0);
  946. WRITE_CBUS_REG(A9_0_IRQ_IN1_INTR_MASK, 0x0);
  947. WRITE_CBUS_REG(A9_0_IRQ_IN2_INTR_MASK, 0x0);
  948. WRITE_CBUS_REG(A9_0_IRQ_IN3_INTR_MASK, 0x0);
  949. meson_sram_push(meson_sram_suspend, meson_cpu_suspend,
  950. meson_cpu_suspend_sz);
  951. return 0;
  952. }
  953. static int meson_pm_enter(suspend_state_t state)
  954. {
  955. int ret = 0;
  956. switch (state) {
  957. case PM_SUSPEND_STANDBY:
  958. case PM_SUSPEND_MEM:
  959. meson_pm_suspend();
  960. break;
  961. default:
  962. ret = -EINVAL;
  963. }
  964. return ret;
  965. }
  966. static void meson_pm_finish(void)
  967. {
  968. printk(KERN_INFO "enter meson_pm_finish!\n");
  969. WRITE_CBUS_REG(A9_0_IRQ_IN0_INTR_MASK, mask_save[0]);
  970. WRITE_CBUS_REG(A9_0_IRQ_IN1_INTR_MASK, mask_save[1]);
  971. WRITE_CBUS_REG(A9_0_IRQ_IN2_INTR_MASK, mask_save[2]);
  972. WRITE_CBUS_REG(A9_0_IRQ_IN3_INTR_MASK, mask_save[3]);
  973. }
  974. static struct platform_suspend_ops meson_pm_ops = {
  975. .enter = meson_pm_enter,
  976. .prepare = meson_pm_prepare,
  977. .finish = meson_pm_finish,
  978. .valid = suspend_valid_only_mem,
  979. };
  980. static int __init meson_pm_probe(struct platform_device *pdev)
  981. {
  982. printk(KERN_INFO "enter meson_pm_probe!\n");
  983. #if (!defined CONFIG_MACH_MESON_8726M_REFC03)&&(!defined CONFIG_MACH_MESON_8726M_REFC06)&&(!defined CONFIG_MACH_MESON_8726M_REFC08)
  984. power_init_off();
  985. #endif
  986. power_gate_init();
  987. #ifdef CONFIG_HAS_EARLYSUSPEND
  988. early_suspend.level = EARLY_SUSPEND_LEVEL_DISABLE_FB;
  989. early_suspend.suspend = meson_system_early_suspend;
  990. early_suspend.resume = meson_system_late_resume;
  991. //early_suspend.param = pdev;
  992. register_early_suspend(&early_suspend);
  993. #endif
  994. pdata = pdev->dev.platform_data;
  995. if (!pdata) {
  996. dev_err(&pdev->dev, "cannot get platform data\n");
  997. return -ENOENT;
  998. }
  999. pdata->ddr_reg_backup = sram_alloc(32 * 4);
  1000. if (!pdata->ddr_reg_backup) {
  1001. dev_err(&pdev->dev, "cannot allocate SRAM memory\n");
  1002. return -ENOMEM;
  1003. }
  1004. meson_sram_suspend = sram_alloc(meson_cpu_suspend_sz);
  1005. if (!meson_sram_suspend) {
  1006. dev_err(&pdev->dev, "cannot allocate SRAM memory\n");
  1007. return -ENOMEM;
  1008. }
  1009. meson_sram_push(meson_sram_suspend, meson_cpu_suspend,
  1010. meson_cpu_suspend_sz);
  1011. suspend_set_ops(&meson_pm_ops);
  1012. printk(KERN_INFO "meson_pm_probe done 0x%x %d!\n",
  1013. (unsigned)meson_sram_suspend, meson_cpu_suspend_sz);
  1014. return 0;
  1015. }
  1016. static int __exit meson_pm_remove(struct platform_device *pdev)
  1017. {
  1018. #ifdef CONFIG_HAS_EARLYSUSPEND
  1019. unregister_early_suspend(&early_suspend);
  1020. #endif
  1021. return 0;
  1022. }
  1023. static struct platform_driver meson_pm_driver = {
  1024. .driver = {
  1025. .name = "pm-meson",
  1026. .owner = THIS_MODULE,
  1027. },
  1028. .remove = __exit_p(meson_pm_remove),
  1029. };
  1030. static int __init meson_pm_init(void)
  1031. {
  1032. return platform_driver_probe(&meson_pm_driver, meson_pm_probe);
  1033. }
  1034. late_initcall(meson_pm_init);