pm.c 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * arch/arm/mach-at91/pm.c
  4. * AT91 Power Management
  5. *
  6. * Copyright (C) 2005 David Brownell
  7. */
  8. #include <linux/genalloc.h>
  9. #include <linux/io.h>
  10. #include <linux/of_address.h>
  11. #include <linux/of.h>
  12. #include <linux/of_fdt.h>
  13. #include <linux/of_platform.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/parser.h>
  16. #include <linux/suspend.h>
  17. #include <linux/clk.h>
  18. #include <linux/clk/at91_pmc.h>
  19. #include <linux/platform_data/atmel.h>
  20. #include <asm/cacheflush.h>
  21. #include <asm/fncpy.h>
  22. #include <asm/system_misc.h>
  23. #include <asm/suspend.h>
  24. #include "generic.h"
  25. #include "pm.h"
  26. #include "sam_secure.h"
  27. #define BACKUP_DDR_PHY_CALIBRATION (9)
  28. /**
  29. * struct at91_pm_bu - AT91 power management backup unit data structure
  30. * @suspended: true if suspended to backup mode
  31. * @reserved: reserved
  32. * @canary: canary data for memory checking after exit from backup mode
  33. * @resume: resume API
  34. * @ddr_phy_calibration: DDR PHY calibration data: ZQ0CR0, first 8 words
  35. * of the memory
  36. */
  37. struct at91_pm_bu {
  38. int suspended;
  39. unsigned long reserved;
  40. phys_addr_t canary;
  41. phys_addr_t resume;
  42. unsigned long ddr_phy_calibration[BACKUP_DDR_PHY_CALIBRATION];
  43. };
  44. /**
  45. * struct at91_pm_sfrbu_regs - registers mapping for SFRBU
  46. * @pswbu: power switch BU control registers
  47. */
  48. struct at91_pm_sfrbu_regs {
  49. struct {
  50. u32 key;
  51. u32 ctrl;
  52. u32 state;
  53. u32 softsw;
  54. } pswbu;
  55. };
  56. /**
  57. * enum at91_pm_eth_clk - Ethernet clock indexes
  58. * @AT91_PM_ETH_PCLK: pclk index
  59. * @AT91_PM_ETH_HCLK: hclk index
  60. * @AT91_PM_ETH_MAX_CLK: max index
  61. */
  62. enum at91_pm_eth_clk {
  63. AT91_PM_ETH_PCLK,
  64. AT91_PM_ETH_HCLK,
  65. AT91_PM_ETH_MAX_CLK,
  66. };
  67. /**
  68. * enum at91_pm_eth - Ethernet controller indexes
  69. * @AT91_PM_G_ETH: gigabit Ethernet controller index
  70. * @AT91_PM_E_ETH: megabit Ethernet controller index
  71. * @AT91_PM_MAX_ETH: max index
  72. */
  73. enum at91_pm_eth {
  74. AT91_PM_G_ETH,
  75. AT91_PM_E_ETH,
  76. AT91_PM_MAX_ETH,
  77. };
  78. /**
  79. * struct at91_pm_quirk_eth - AT91 PM Ethernet quirks
  80. * @dev: Ethernet device
  81. * @np: Ethernet device node
  82. * @clks: Ethernet clocks
  83. * @modes: power management mode that this quirk applies to
  84. * @dns_modes: do not suspend modes: stop suspending if Ethernet is configured
  85. * as wakeup source but buggy and no other wakeup source is
  86. * available
  87. */
  88. struct at91_pm_quirk_eth {
  89. struct device *dev;
  90. struct device_node *np;
  91. struct clk_bulk_data clks[AT91_PM_ETH_MAX_CLK];
  92. u32 modes;
  93. u32 dns_modes;
  94. };
  95. /**
  96. * struct at91_pm_quirks - AT91 PM quirks
  97. * @eth: Ethernet quirks
  98. */
  99. struct at91_pm_quirks {
  100. struct at91_pm_quirk_eth eth[AT91_PM_MAX_ETH];
  101. };
  102. /**
  103. * struct at91_soc_pm - AT91 SoC power management data structure
  104. * @config_shdwc_ws: wakeup sources configuration function for SHDWC
  105. * @config_pmc_ws: wakeup srouces configuration function for PMC
  106. * @ws_ids: wakup sources of_device_id array
  107. * @bu: backup unit mapped data (for backup mode)
  108. * @quirks: PM quirks
  109. * @data: PM data to be used on last phase of suspend
  110. * @sfrbu_regs: SFRBU registers mapping
  111. * @memcs: memory chip select
  112. */
  113. struct at91_soc_pm {
  114. int (*config_shdwc_ws)(void __iomem *shdwc, u32 *mode, u32 *polarity);
  115. int (*config_pmc_ws)(void __iomem *pmc, u32 mode, u32 polarity);
  116. const struct of_device_id *ws_ids;
  117. struct at91_pm_bu *bu;
  118. struct at91_pm_quirks quirks;
  119. struct at91_pm_data data;
  120. struct at91_pm_sfrbu_regs sfrbu_regs;
  121. void *memcs;
  122. };
  123. /**
  124. * enum at91_pm_iomaps - IOs that needs to be mapped for different PM modes
  125. * @AT91_PM_IOMAP_SHDWC: SHDWC controller
  126. * @AT91_PM_IOMAP_SFRBU: SFRBU controller
  127. * @AT91_PM_IOMAP_ETHC: Ethernet controller
  128. */
  129. enum at91_pm_iomaps {
  130. AT91_PM_IOMAP_SHDWC,
  131. AT91_PM_IOMAP_SFRBU,
  132. AT91_PM_IOMAP_ETHC,
  133. };
  134. #define AT91_PM_IOMAP(name) BIT(AT91_PM_IOMAP_##name)
  135. static struct at91_soc_pm soc_pm = {
  136. .data = {
  137. .standby_mode = AT91_PM_STANDBY,
  138. .suspend_mode = AT91_PM_ULP0,
  139. },
  140. };
  141. static const match_table_t pm_modes __initconst = {
  142. { AT91_PM_STANDBY, "standby" },
  143. { AT91_PM_ULP0, "ulp0" },
  144. { AT91_PM_ULP0_FAST, "ulp0-fast" },
  145. { AT91_PM_ULP1, "ulp1" },
  146. { AT91_PM_BACKUP, "backup" },
  147. { -1, NULL },
  148. };
  149. #define at91_ramc_read(id, field) \
  150. __raw_readl(soc_pm.data.ramc[id] + field)
  151. #define at91_ramc_write(id, field, value) \
  152. __raw_writel(value, soc_pm.data.ramc[id] + field)
  153. static int at91_pm_valid_state(suspend_state_t state)
  154. {
  155. switch (state) {
  156. case PM_SUSPEND_ON:
  157. case PM_SUSPEND_STANDBY:
  158. case PM_SUSPEND_MEM:
  159. return 1;
  160. default:
  161. return 0;
  162. }
  163. }
  164. static int canary = 0xA5A5A5A5;
  165. struct wakeup_source_info {
  166. unsigned int pmc_fsmr_bit;
  167. unsigned int shdwc_mr_bit;
  168. bool set_polarity;
  169. };
  170. static const struct wakeup_source_info ws_info[] = {
  171. { .pmc_fsmr_bit = AT91_PMC_FSTT(10), .set_polarity = true },
  172. { .pmc_fsmr_bit = AT91_PMC_RTCAL, .shdwc_mr_bit = BIT(17) },
  173. { .pmc_fsmr_bit = AT91_PMC_USBAL },
  174. { .pmc_fsmr_bit = AT91_PMC_SDMMC_CD },
  175. { .pmc_fsmr_bit = AT91_PMC_RTTAL },
  176. { .pmc_fsmr_bit = AT91_PMC_RXLP_MCE },
  177. };
  178. static const struct of_device_id sama5d2_ws_ids[] = {
  179. { .compatible = "atmel,sama5d2-gem", .data = &ws_info[0] },
  180. { .compatible = "atmel,sama5d2-rtc", .data = &ws_info[1] },
  181. { .compatible = "atmel,sama5d3-udc", .data = &ws_info[2] },
  182. { .compatible = "atmel,at91rm9200-ohci", .data = &ws_info[2] },
  183. { .compatible = "usb-ohci", .data = &ws_info[2] },
  184. { .compatible = "atmel,at91sam9g45-ehci", .data = &ws_info[2] },
  185. { .compatible = "usb-ehci", .data = &ws_info[2] },
  186. { .compatible = "atmel,sama5d2-sdhci", .data = &ws_info[3] },
  187. { /* sentinel */ }
  188. };
  189. static const struct of_device_id sam9x60_ws_ids[] = {
  190. { .compatible = "microchip,sam9x60-rtc", .data = &ws_info[1] },
  191. { .compatible = "atmel,at91rm9200-ohci", .data = &ws_info[2] },
  192. { .compatible = "usb-ohci", .data = &ws_info[2] },
  193. { .compatible = "atmel,at91sam9g45-ehci", .data = &ws_info[2] },
  194. { .compatible = "usb-ehci", .data = &ws_info[2] },
  195. { .compatible = "microchip,sam9x60-rtt", .data = &ws_info[4] },
  196. { .compatible = "cdns,sam9x60-macb", .data = &ws_info[5] },
  197. { /* sentinel */ }
  198. };
  199. static const struct of_device_id sama7_ws_ids[] = {
  200. { .compatible = "microchip,sama7d65-rtc", .data = &ws_info[1] },
  201. { .compatible = "microchip,sama7g5-rtc", .data = &ws_info[1] },
  202. { .compatible = "microchip,sama7g5-ohci", .data = &ws_info[2] },
  203. { .compatible = "usb-ohci", .data = &ws_info[2] },
  204. { .compatible = "atmel,at91sam9g45-ehci", .data = &ws_info[2] },
  205. { .compatible = "usb-ehci", .data = &ws_info[2] },
  206. { .compatible = "microchip,sama7d65-sdhci", .data = &ws_info[3] },
  207. { .compatible = "microchip,sama7g5-sdhci", .data = &ws_info[3] },
  208. { .compatible = "microchip,sama7d65-rtt", .data = &ws_info[4] },
  209. { .compatible = "microchip,sama7g5-rtt", .data = &ws_info[4] },
  210. { /* sentinel */ }
  211. };
  212. static const struct of_device_id sam9x7_ws_ids[] = {
  213. { .compatible = "microchip,sam9x7-rtc", .data = &ws_info[1] },
  214. { .compatible = "microchip,sam9x7-rtt", .data = &ws_info[4] },
  215. { .compatible = "microchip,sam9x7-gem", .data = &ws_info[5] },
  216. { /* sentinel */ }
  217. };
  218. static int at91_pm_config_ws(unsigned int pm_mode, bool set)
  219. {
  220. const struct wakeup_source_info *wsi;
  221. const struct of_device_id *match;
  222. struct platform_device *pdev;
  223. struct device_node *np;
  224. unsigned int mode = 0, polarity = 0, val = 0;
  225. if (pm_mode != AT91_PM_ULP1)
  226. return 0;
  227. if (!soc_pm.data.pmc || !soc_pm.data.shdwc || !soc_pm.ws_ids)
  228. return -EPERM;
  229. if (!set) {
  230. writel(mode, soc_pm.data.pmc + AT91_PMC_FSMR);
  231. return 0;
  232. }
  233. if (soc_pm.config_shdwc_ws)
  234. soc_pm.config_shdwc_ws(soc_pm.data.shdwc, &mode, &polarity);
  235. /* SHDWC.MR */
  236. val = readl(soc_pm.data.shdwc + 0x04);
  237. /* Loop through defined wakeup sources. */
  238. for_each_matching_node_and_match(np, soc_pm.ws_ids, &match) {
  239. pdev = of_find_device_by_node(np);
  240. if (!pdev)
  241. continue;
  242. if (device_may_wakeup(&pdev->dev)) {
  243. wsi = match->data;
  244. /* Check if enabled on SHDWC. */
  245. if (wsi->shdwc_mr_bit && !(val & wsi->shdwc_mr_bit))
  246. goto put_device;
  247. mode |= wsi->pmc_fsmr_bit;
  248. if (wsi->set_polarity)
  249. polarity |= wsi->pmc_fsmr_bit;
  250. }
  251. put_device:
  252. put_device(&pdev->dev);
  253. }
  254. if (mode) {
  255. if (soc_pm.config_pmc_ws)
  256. soc_pm.config_pmc_ws(soc_pm.data.pmc, mode, polarity);
  257. } else {
  258. pr_err("AT91: PM: no ULP1 wakeup sources found!");
  259. }
  260. return mode ? 0 : -EPERM;
  261. }
  262. static int at91_sama5d2_config_shdwc_ws(void __iomem *shdwc, u32 *mode,
  263. u32 *polarity)
  264. {
  265. u32 val;
  266. /* SHDWC.WUIR */
  267. val = readl(shdwc + 0x0c);
  268. *mode |= (val & 0x3ff);
  269. *polarity |= ((val >> 16) & 0x3ff);
  270. return 0;
  271. }
  272. static int at91_sama5d2_config_pmc_ws(void __iomem *pmc, u32 mode, u32 polarity)
  273. {
  274. writel(mode, pmc + AT91_PMC_FSMR);
  275. writel(polarity, pmc + AT91_PMC_FSPR);
  276. return 0;
  277. }
  278. static int at91_sam9x60_config_pmc_ws(void __iomem *pmc, u32 mode, u32 polarity)
  279. {
  280. writel(mode, pmc + AT91_PMC_FSMR);
  281. return 0;
  282. }
  283. static bool at91_pm_eth_quirk_is_valid(struct at91_pm_quirk_eth *eth)
  284. {
  285. struct platform_device *pdev;
  286. /* Interface NA in DT. */
  287. if (!eth->np)
  288. return false;
  289. /* No quirks for this interface and current suspend mode. */
  290. if (!(eth->modes & BIT(soc_pm.data.mode)))
  291. return false;
  292. if (!eth->dev) {
  293. /* Driver not probed. */
  294. pdev = of_find_device_by_node(eth->np);
  295. if (!pdev)
  296. return false;
  297. /* put_device(eth->dev) is called at the end of suspend. */
  298. eth->dev = &pdev->dev;
  299. }
  300. /* No quirks if device isn't a wakeup source. */
  301. if (!device_may_wakeup(eth->dev))
  302. return false;
  303. return true;
  304. }
  305. static int at91_pm_config_quirks(bool suspend)
  306. {
  307. struct at91_pm_quirk_eth *eth;
  308. int i, j, ret, tmp;
  309. /*
  310. * Ethernet IPs who's device_node pointers are stored into
  311. * soc_pm.quirks.eth[].np cannot handle WoL packets while in ULP0, ULP1
  312. * or both due to a hardware bug. If they receive WoL packets while in
  313. * ULP0 or ULP1 IPs could stop working or the whole system could stop
  314. * working. We cannot handle this scenario in the ethernet driver itself
  315. * as the driver is common to multiple vendors and also we only know
  316. * here, in this file, if we suspend to ULP0 or ULP1 mode. Thus handle
  317. * these scenarios here, as quirks.
  318. */
  319. for (i = 0; i < AT91_PM_MAX_ETH; i++) {
  320. eth = &soc_pm.quirks.eth[i];
  321. if (!at91_pm_eth_quirk_is_valid(eth))
  322. continue;
  323. /*
  324. * For modes in dns_modes mask the system blocks if quirk is not
  325. * applied but if applied the interface doesn't act at WoL
  326. * events. Thus take care to avoid suspending if this interface
  327. * is the only configured wakeup source.
  328. */
  329. if (suspend && eth->dns_modes & BIT(soc_pm.data.mode)) {
  330. int ws_count = 0;
  331. #ifdef CONFIG_PM_SLEEP
  332. struct wakeup_source *ws;
  333. for_each_wakeup_source(ws) {
  334. if (ws->dev == eth->dev)
  335. continue;
  336. ws_count++;
  337. break;
  338. }
  339. #endif
  340. /*
  341. * Checking !ws is good for all platforms with issues
  342. * even when both G_ETH and E_ETH are available as dns_modes
  343. * is populated only on G_ETH interface.
  344. */
  345. if (!ws_count) {
  346. pr_err("AT91: PM: Ethernet cannot resume from WoL!");
  347. ret = -EPERM;
  348. put_device(eth->dev);
  349. eth->dev = NULL;
  350. /* No need to revert clock settings for this eth. */
  351. i--;
  352. goto clk_unconfigure;
  353. }
  354. }
  355. if (suspend) {
  356. clk_bulk_disable_unprepare(AT91_PM_ETH_MAX_CLK, eth->clks);
  357. } else {
  358. ret = clk_bulk_prepare_enable(AT91_PM_ETH_MAX_CLK,
  359. eth->clks);
  360. if (ret)
  361. goto clk_unconfigure;
  362. /*
  363. * Release the reference to eth->dev taken in
  364. * at91_pm_eth_quirk_is_valid().
  365. */
  366. put_device(eth->dev);
  367. eth->dev = NULL;
  368. }
  369. }
  370. return 0;
  371. clk_unconfigure:
  372. /*
  373. * In case of resume we reach this point if clk_prepare_enable() failed.
  374. * we don't want to revert the previous clk_prepare_enable() for the
  375. * other IP.
  376. */
  377. for (j = i; j >= 0; j--) {
  378. eth = &soc_pm.quirks.eth[j];
  379. if (suspend) {
  380. if (!at91_pm_eth_quirk_is_valid(eth))
  381. continue;
  382. tmp = clk_bulk_prepare_enable(AT91_PM_ETH_MAX_CLK, eth->clks);
  383. if (tmp) {
  384. pr_err("AT91: PM: failed to enable %s clocks\n",
  385. j == AT91_PM_G_ETH ? "geth" : "eth");
  386. }
  387. }
  388. /*
  389. * Release the reference to eth->dev taken in
  390. * at91_pm_eth_quirk_is_valid().
  391. */
  392. put_device(eth->dev);
  393. eth->dev = NULL;
  394. }
  395. return ret;
  396. }
  397. /*
  398. * Called after processes are frozen, but before we shutdown devices.
  399. */
  400. static int at91_pm_begin(suspend_state_t state)
  401. {
  402. int ret;
  403. switch (state) {
  404. case PM_SUSPEND_MEM:
  405. soc_pm.data.mode = soc_pm.data.suspend_mode;
  406. break;
  407. case PM_SUSPEND_STANDBY:
  408. soc_pm.data.mode = soc_pm.data.standby_mode;
  409. break;
  410. default:
  411. soc_pm.data.mode = -1;
  412. }
  413. ret = at91_pm_config_ws(soc_pm.data.mode, true);
  414. if (ret)
  415. return ret;
  416. if (soc_pm.data.mode == AT91_PM_BACKUP)
  417. soc_pm.bu->suspended = 1;
  418. else if (soc_pm.bu)
  419. soc_pm.bu->suspended = 0;
  420. return 0;
  421. }
  422. /*
  423. * Verify that all the clocks are correct before entering
  424. * slow-clock mode.
  425. */
  426. static int at91_pm_verify_clocks(void)
  427. {
  428. unsigned long scsr;
  429. int i;
  430. scsr = readl(soc_pm.data.pmc + AT91_PMC_SCSR);
  431. /* USB must not be using PLLB */
  432. if ((scsr & soc_pm.data.uhp_udp_mask) != 0) {
  433. pr_err("AT91: PM - Suspend-to-RAM with USB still active\n");
  434. return 0;
  435. }
  436. /* PCK0..PCK3 must be disabled, or configured to use clk32k */
  437. for (i = 0; i < 4; i++) {
  438. u32 css;
  439. if ((scsr & (AT91_PMC_PCK0 << i)) == 0)
  440. continue;
  441. css = readl(soc_pm.data.pmc + AT91_PMC_PCKR(i)) & AT91_PMC_CSS;
  442. if (css != AT91_PMC_CSS_SLOW) {
  443. pr_err("AT91: PM - Suspend-to-RAM with PCK%d src %d\n", i, css);
  444. return 0;
  445. }
  446. }
  447. return 1;
  448. }
  449. /*
  450. * Call this from platform driver suspend() to see how deeply to suspend.
  451. * For example, some controllers (like OHCI) need one of the PLL clocks
  452. * in order to act as a wakeup source, and those are not available when
  453. * going into slow clock mode.
  454. *
  455. * REVISIT: generalize as clk_will_be_available(clk)? Other platforms have
  456. * the very same problem (but not using at91 main_clk), and it'd be better
  457. * to add one generic API rather than lots of platform-specific ones.
  458. */
  459. int at91_suspend_entering_slow_clock(void)
  460. {
  461. return (soc_pm.data.mode >= AT91_PM_ULP0);
  462. }
  463. EXPORT_SYMBOL(at91_suspend_entering_slow_clock);
  464. static void (*at91_suspend_sram_fn)(struct at91_pm_data *);
  465. extern void at91_pm_suspend_in_sram(struct at91_pm_data *pm_data);
  466. extern u32 at91_pm_suspend_in_sram_sz;
  467. static int at91_suspend_finish(unsigned long val)
  468. {
  469. /* SYNOPSYS workaround to fix a bug in the calibration logic */
  470. unsigned char modified_fix_code[] = {
  471. 0x00, 0x01, 0x01, 0x06, 0x07, 0x0c, 0x06, 0x07, 0x0b, 0x18,
  472. 0x0a, 0x0b, 0x0c, 0x0d, 0x0d, 0x0a, 0x13, 0x13, 0x12, 0x13,
  473. 0x14, 0x15, 0x15, 0x12, 0x18, 0x19, 0x19, 0x1e, 0x1f, 0x14,
  474. 0x1e, 0x1f,
  475. };
  476. unsigned int tmp, index;
  477. int i;
  478. if (soc_pm.data.mode == AT91_PM_BACKUP && soc_pm.data.ramc_phy) {
  479. /*
  480. * Bootloader will perform DDR recalibration and will try to
  481. * restore the ZQ0SR0 with the value saved here. But the
  482. * calibration is buggy and restoring some values from ZQ0SR0
  483. * is forbidden and risky thus we need to provide processed
  484. * values for these.
  485. */
  486. tmp = readl(soc_pm.data.ramc_phy + DDR3PHY_ZQ0SR0);
  487. /* Store pull-down output impedance select. */
  488. index = (tmp >> DDR3PHY_ZQ0SR0_PDO_OFF) & 0x1f;
  489. soc_pm.bu->ddr_phy_calibration[0] = modified_fix_code[index] << DDR3PHY_ZQ0SR0_PDO_OFF;
  490. /* Store pull-up output impedance select. */
  491. index = (tmp >> DDR3PHY_ZQ0SR0_PUO_OFF) & 0x1f;
  492. soc_pm.bu->ddr_phy_calibration[0] |= modified_fix_code[index] << DDR3PHY_ZQ0SR0_PUO_OFF;
  493. /* Store pull-down on-die termination impedance select. */
  494. index = (tmp >> DDR3PHY_ZQ0SR0_PDODT_OFF) & 0x1f;
  495. soc_pm.bu->ddr_phy_calibration[0] |= modified_fix_code[index] << DDR3PHY_ZQ0SR0_PDODT_OFF;
  496. /* Store pull-up on-die termination impedance select. */
  497. index = (tmp >> DDR3PHY_ZQ0SRO_PUODT_OFF) & 0x1f;
  498. soc_pm.bu->ddr_phy_calibration[0] |= modified_fix_code[index] << DDR3PHY_ZQ0SRO_PUODT_OFF;
  499. /*
  500. * The 1st 8 words of memory might get corrupted in the process
  501. * of DDR PHY recalibration; it is saved here in securam and it
  502. * will be restored later, after recalibration, by bootloader
  503. */
  504. for (i = 1; i < BACKUP_DDR_PHY_CALIBRATION; i++)
  505. soc_pm.bu->ddr_phy_calibration[i] =
  506. *((unsigned int *)soc_pm.memcs + (i - 1));
  507. }
  508. flush_cache_all();
  509. outer_disable();
  510. at91_suspend_sram_fn(&soc_pm.data);
  511. return 0;
  512. }
  513. /**
  514. * at91_pm_switch_ba_to_auto() - Configure Backup Unit Power Switch
  515. * to automatic/hardware mode.
  516. *
  517. * The Backup Unit Power Switch can be managed either by software or hardware.
  518. * Enabling hardware mode allows the automatic transition of power between
  519. * VDDANA (or VDDIN33) and VDDBU (or VBAT, respectively), based on the
  520. * availability of these power sources.
  521. *
  522. * If the Backup Unit Power Switch is already in automatic mode, no action is
  523. * required. If it is in software-controlled mode, it is switched to automatic
  524. * mode to enhance safety and eliminate the need for toggling between power
  525. * sources.
  526. */
  527. static void at91_pm_switch_ba_to_auto(void)
  528. {
  529. unsigned int offset = offsetof(struct at91_pm_sfrbu_regs, pswbu);
  530. unsigned int val;
  531. /* Just for safety. */
  532. if (!soc_pm.data.sfrbu)
  533. return;
  534. val = readl(soc_pm.data.sfrbu + offset);
  535. /* Already on auto/hardware. */
  536. if (!(val & soc_pm.sfrbu_regs.pswbu.ctrl))
  537. return;
  538. val &= ~soc_pm.sfrbu_regs.pswbu.ctrl;
  539. val |= soc_pm.sfrbu_regs.pswbu.key;
  540. writel(val, soc_pm.data.sfrbu + offset);
  541. }
  542. static void at91_pm_suspend(suspend_state_t state)
  543. {
  544. if (soc_pm.data.mode == AT91_PM_BACKUP) {
  545. at91_pm_switch_ba_to_auto();
  546. cpu_suspend(0, at91_suspend_finish);
  547. /* The SRAM is lost between suspend cycles */
  548. at91_suspend_sram_fn = fncpy(at91_suspend_sram_fn,
  549. &at91_pm_suspend_in_sram,
  550. at91_pm_suspend_in_sram_sz);
  551. if (IS_ENABLED(CONFIG_SOC_SAMA7D65)) {
  552. /* SHDWC.SR */
  553. readl(soc_pm.data.shdwc + 0x08);
  554. }
  555. } else {
  556. at91_suspend_finish(0);
  557. }
  558. outer_resume();
  559. }
  560. /*
  561. * STANDBY mode has *all* drivers suspended; ignores irqs not marked as 'wakeup'
  562. * event sources; and reduces DRAM power. But otherwise it's identical to
  563. * PM_SUSPEND_ON: cpu idle, and nothing fancy done with main or cpu clocks.
  564. *
  565. * AT91_PM_ULP0 is like STANDBY plus slow clock mode, so drivers must
  566. * suspend more deeply, the master clock switches to the clk32k and turns off
  567. * the main oscillator
  568. *
  569. * AT91_PM_BACKUP turns off the whole SoC after placing the DDR in self refresh
  570. */
  571. static int at91_pm_enter(suspend_state_t state)
  572. {
  573. int ret;
  574. ret = at91_pm_config_quirks(true);
  575. if (ret)
  576. return ret;
  577. switch (state) {
  578. case PM_SUSPEND_MEM:
  579. case PM_SUSPEND_STANDBY:
  580. /*
  581. * Ensure that clocks are in a valid state.
  582. */
  583. if (soc_pm.data.mode >= AT91_PM_ULP0 &&
  584. !at91_pm_verify_clocks())
  585. goto error;
  586. at91_pm_suspend(state);
  587. break;
  588. case PM_SUSPEND_ON:
  589. cpu_do_idle();
  590. break;
  591. default:
  592. pr_debug("AT91: PM - bogus suspend state %d\n", state);
  593. goto error;
  594. }
  595. error:
  596. at91_pm_config_quirks(false);
  597. return 0;
  598. }
  599. /*
  600. * Called right prior to thawing processes.
  601. */
  602. static void at91_pm_end(void)
  603. {
  604. at91_pm_config_ws(soc_pm.data.mode, false);
  605. }
  606. static const struct platform_suspend_ops at91_pm_ops = {
  607. .valid = at91_pm_valid_state,
  608. .begin = at91_pm_begin,
  609. .enter = at91_pm_enter,
  610. .end = at91_pm_end,
  611. };
  612. static struct platform_device at91_cpuidle_device = {
  613. .name = "cpuidle-at91",
  614. };
  615. /*
  616. * The AT91RM9200 goes into self-refresh mode with this command, and will
  617. * terminate self-refresh automatically on the next SDRAM access.
  618. *
  619. * Self-refresh mode is exited as soon as a memory access is made, but we don't
  620. * know for sure when that happens. However, we need to restore the low-power
  621. * mode if it was enabled before going idle. Restoring low-power mode while
  622. * still in self-refresh is "not recommended", but seems to work.
  623. */
  624. static void at91rm9200_standby(void)
  625. {
  626. asm volatile(
  627. "b 1f\n\t"
  628. ".align 5\n\t"
  629. "1: mcr p15, 0, %0, c7, c10, 4\n\t"
  630. " str %2, [%1, %3]\n\t"
  631. " mcr p15, 0, %0, c7, c0, 4\n\t"
  632. :
  633. : "r" (0), "r" (soc_pm.data.ramc[0]),
  634. "r" (1), "r" (AT91_MC_SDRAMC_SRR));
  635. }
  636. /* We manage both DDRAM/SDRAM controllers, we need more than one value to
  637. * remember.
  638. */
  639. static void at91_ddr_standby(void)
  640. {
  641. /* Those two values allow us to delay self-refresh activation
  642. * to the maximum. */
  643. u32 lpr0, lpr1 = 0;
  644. u32 mdr, saved_mdr0, saved_mdr1 = 0;
  645. u32 saved_lpr0, saved_lpr1 = 0;
  646. /* LPDDR1 --> force DDR2 mode during self-refresh */
  647. saved_mdr0 = at91_ramc_read(0, AT91_DDRSDRC_MDR);
  648. if ((saved_mdr0 & AT91_DDRSDRC_MD) == AT91_DDRSDRC_MD_LOW_POWER_DDR) {
  649. mdr = saved_mdr0 & ~AT91_DDRSDRC_MD;
  650. mdr |= AT91_DDRSDRC_MD_DDR2;
  651. at91_ramc_write(0, AT91_DDRSDRC_MDR, mdr);
  652. }
  653. if (soc_pm.data.ramc[1]) {
  654. saved_lpr1 = at91_ramc_read(1, AT91_DDRSDRC_LPR);
  655. lpr1 = saved_lpr1 & ~AT91_DDRSDRC_LPCB;
  656. lpr1 |= AT91_DDRSDRC_LPCB_SELF_REFRESH;
  657. saved_mdr1 = at91_ramc_read(1, AT91_DDRSDRC_MDR);
  658. if ((saved_mdr1 & AT91_DDRSDRC_MD) == AT91_DDRSDRC_MD_LOW_POWER_DDR) {
  659. mdr = saved_mdr1 & ~AT91_DDRSDRC_MD;
  660. mdr |= AT91_DDRSDRC_MD_DDR2;
  661. at91_ramc_write(1, AT91_DDRSDRC_MDR, mdr);
  662. }
  663. }
  664. saved_lpr0 = at91_ramc_read(0, AT91_DDRSDRC_LPR);
  665. lpr0 = saved_lpr0 & ~AT91_DDRSDRC_LPCB;
  666. lpr0 |= AT91_DDRSDRC_LPCB_SELF_REFRESH;
  667. /* self-refresh mode now */
  668. at91_ramc_write(0, AT91_DDRSDRC_LPR, lpr0);
  669. if (soc_pm.data.ramc[1])
  670. at91_ramc_write(1, AT91_DDRSDRC_LPR, lpr1);
  671. cpu_do_idle();
  672. at91_ramc_write(0, AT91_DDRSDRC_MDR, saved_mdr0);
  673. at91_ramc_write(0, AT91_DDRSDRC_LPR, saved_lpr0);
  674. if (soc_pm.data.ramc[1]) {
  675. at91_ramc_write(0, AT91_DDRSDRC_MDR, saved_mdr1);
  676. at91_ramc_write(1, AT91_DDRSDRC_LPR, saved_lpr1);
  677. }
  678. }
  679. static void sama5d3_ddr_standby(void)
  680. {
  681. u32 lpr0;
  682. u32 saved_lpr0;
  683. saved_lpr0 = at91_ramc_read(0, AT91_DDRSDRC_LPR);
  684. lpr0 = saved_lpr0 & ~AT91_DDRSDRC_LPCB;
  685. lpr0 |= AT91_DDRSDRC_LPCB_POWER_DOWN;
  686. at91_ramc_write(0, AT91_DDRSDRC_LPR, lpr0);
  687. cpu_do_idle();
  688. at91_ramc_write(0, AT91_DDRSDRC_LPR, saved_lpr0);
  689. }
  690. /* We manage both DDRAM/SDRAM controllers, we need more than one value to
  691. * remember.
  692. */
  693. static void at91sam9_sdram_standby(void)
  694. {
  695. u32 lpr0, lpr1 = 0;
  696. u32 saved_lpr0, saved_lpr1 = 0;
  697. if (soc_pm.data.ramc[1]) {
  698. saved_lpr1 = at91_ramc_read(1, AT91_SDRAMC_LPR);
  699. lpr1 = saved_lpr1 & ~AT91_SDRAMC_LPCB;
  700. lpr1 |= AT91_SDRAMC_LPCB_SELF_REFRESH;
  701. }
  702. saved_lpr0 = at91_ramc_read(0, AT91_SDRAMC_LPR);
  703. lpr0 = saved_lpr0 & ~AT91_SDRAMC_LPCB;
  704. lpr0 |= AT91_SDRAMC_LPCB_SELF_REFRESH;
  705. /* self-refresh mode now */
  706. at91_ramc_write(0, AT91_SDRAMC_LPR, lpr0);
  707. if (soc_pm.data.ramc[1])
  708. at91_ramc_write(1, AT91_SDRAMC_LPR, lpr1);
  709. cpu_do_idle();
  710. at91_ramc_write(0, AT91_SDRAMC_LPR, saved_lpr0);
  711. if (soc_pm.data.ramc[1])
  712. at91_ramc_write(1, AT91_SDRAMC_LPR, saved_lpr1);
  713. }
  714. static void sama7g5_standby(void)
  715. {
  716. int pwrtmg, ratio;
  717. pwrtmg = readl(soc_pm.data.ramc[0] + UDDRC_PWRCTL);
  718. ratio = readl(soc_pm.data.pmc + AT91_PMC_RATIO);
  719. /*
  720. * Place RAM into self-refresh after a maximum idle clocks. The maximum
  721. * idle clocks is configured by bootloader in
  722. * UDDRC_PWRMGT.SELFREF_TO_X32.
  723. */
  724. writel(pwrtmg | UDDRC_PWRCTL_SELFREF_EN,
  725. soc_pm.data.ramc[0] + UDDRC_PWRCTL);
  726. /* Divide CPU clock by 16. */
  727. writel(ratio & ~AT91_PMC_RATIO_RATIO, soc_pm.data.pmc + AT91_PMC_RATIO);
  728. cpu_do_idle();
  729. /* Restore previous configuration. */
  730. writel(ratio, soc_pm.data.pmc + AT91_PMC_RATIO);
  731. writel(pwrtmg, soc_pm.data.ramc[0] + UDDRC_PWRCTL);
  732. }
  733. struct ramc_info {
  734. void (*idle)(void);
  735. unsigned int memctrl;
  736. };
  737. static const struct ramc_info ramc_infos[] __initconst = {
  738. { .idle = at91rm9200_standby, .memctrl = AT91_MEMCTRL_MC},
  739. { .idle = at91sam9_sdram_standby, .memctrl = AT91_MEMCTRL_SDRAMC},
  740. { .idle = at91_ddr_standby, .memctrl = AT91_MEMCTRL_DDRSDR},
  741. { .idle = sama5d3_ddr_standby, .memctrl = AT91_MEMCTRL_DDRSDR},
  742. { .idle = sama7g5_standby, },
  743. };
  744. static const struct of_device_id ramc_ids[] __initconst = {
  745. { .compatible = "atmel,at91rm9200-sdramc", .data = &ramc_infos[0] },
  746. { .compatible = "atmel,at91sam9260-sdramc", .data = &ramc_infos[1] },
  747. { .compatible = "atmel,at91sam9g45-ddramc", .data = &ramc_infos[2] },
  748. { .compatible = "atmel,sama5d3-ddramc", .data = &ramc_infos[3] },
  749. { .compatible = "microchip,sama7g5-uddrc", .data = &ramc_infos[4], },
  750. { /*sentinel*/ }
  751. };
  752. static const struct of_device_id ramc_phy_ids[] __initconst = {
  753. { .compatible = "microchip,sama7g5-ddr3phy", },
  754. { /* Sentinel. */ },
  755. };
  756. static __init int at91_dt_ramc(bool phy_mandatory)
  757. {
  758. struct device_node *np;
  759. const struct of_device_id *of_id;
  760. int idx = 0;
  761. void *standby = NULL;
  762. const struct ramc_info *ramc;
  763. int ret;
  764. for_each_matching_node_and_match(np, ramc_ids, &of_id) {
  765. soc_pm.data.ramc[idx] = of_iomap(np, 0);
  766. if (!soc_pm.data.ramc[idx]) {
  767. pr_err("unable to map ramc[%d] cpu registers\n", idx);
  768. ret = -ENOMEM;
  769. of_node_put(np);
  770. goto unmap_ramc;
  771. }
  772. ramc = of_id->data;
  773. if (ramc) {
  774. if (!standby)
  775. standby = ramc->idle;
  776. soc_pm.data.memctrl = ramc->memctrl;
  777. }
  778. idx++;
  779. }
  780. if (!idx) {
  781. pr_err("unable to find compatible ram controller node in dtb\n");
  782. ret = -ENODEV;
  783. goto unmap_ramc;
  784. }
  785. /* Lookup for DDR PHY node, if any. */
  786. for_each_matching_node_and_match(np, ramc_phy_ids, &of_id) {
  787. soc_pm.data.ramc_phy = of_iomap(np, 0);
  788. if (!soc_pm.data.ramc_phy) {
  789. pr_err("unable to map ramc phy cpu registers\n");
  790. ret = -ENOMEM;
  791. of_node_put(np);
  792. goto unmap_ramc;
  793. }
  794. }
  795. if (phy_mandatory && !soc_pm.data.ramc_phy) {
  796. pr_err("DDR PHY is mandatory!\n");
  797. ret = -ENODEV;
  798. goto unmap_ramc;
  799. }
  800. if (!standby) {
  801. pr_warn("ramc no standby function available\n");
  802. return 0;
  803. }
  804. at91_cpuidle_device.dev.platform_data = standby;
  805. return 0;
  806. unmap_ramc:
  807. while (idx)
  808. iounmap(soc_pm.data.ramc[--idx]);
  809. return ret;
  810. }
  811. static void at91rm9200_idle(void)
  812. {
  813. /*
  814. * Disable the processor clock. The processor will be automatically
  815. * re-enabled by an interrupt or by a reset.
  816. */
  817. writel(AT91_PMC_PCK, soc_pm.data.pmc + AT91_PMC_SCDR);
  818. }
  819. static void at91sam9_idle(void)
  820. {
  821. writel(AT91_PMC_PCK, soc_pm.data.pmc + AT91_PMC_SCDR);
  822. cpu_do_idle();
  823. }
  824. static void __init at91_pm_sram_init(void)
  825. {
  826. struct gen_pool *sram_pool;
  827. phys_addr_t sram_pbase;
  828. unsigned long sram_base;
  829. struct platform_device *pdev = NULL;
  830. for_each_compatible_node_scoped(node, NULL, "mmio-sram") {
  831. pdev = of_find_device_by_node(node);
  832. if (pdev)
  833. break;
  834. }
  835. if (!pdev) {
  836. pr_warn("%s: failed to find sram device!\n", __func__);
  837. return;
  838. }
  839. sram_pool = gen_pool_get(&pdev->dev, NULL);
  840. if (!sram_pool) {
  841. pr_warn("%s: sram pool unavailable!\n", __func__);
  842. goto out_put_device;
  843. }
  844. sram_base = gen_pool_alloc(sram_pool, at91_pm_suspend_in_sram_sz);
  845. if (!sram_base) {
  846. pr_warn("%s: unable to alloc sram!\n", __func__);
  847. goto out_put_device;
  848. }
  849. sram_pbase = gen_pool_virt_to_phys(sram_pool, sram_base);
  850. at91_suspend_sram_fn = __arm_ioremap_exec(sram_pbase,
  851. at91_pm_suspend_in_sram_sz, false);
  852. if (!at91_suspend_sram_fn) {
  853. pr_warn("SRAM: Could not map\n");
  854. goto out_put_device;
  855. }
  856. /* Copy the pm suspend handler to SRAM */
  857. at91_suspend_sram_fn = fncpy(at91_suspend_sram_fn,
  858. &at91_pm_suspend_in_sram, at91_pm_suspend_in_sram_sz);
  859. return;
  860. out_put_device:
  861. put_device(&pdev->dev);
  862. return;
  863. }
  864. static bool __init at91_is_pm_mode_active(int pm_mode)
  865. {
  866. return (soc_pm.data.standby_mode == pm_mode ||
  867. soc_pm.data.suspend_mode == pm_mode);
  868. }
  869. static int __init at91_pm_backup_scan_memcs(unsigned long node,
  870. const char *uname, int depth,
  871. void *data)
  872. {
  873. const char *type;
  874. const __be32 *reg;
  875. int *located = data;
  876. int size;
  877. /* Memory node already located. */
  878. if (*located)
  879. return 0;
  880. type = of_get_flat_dt_prop(node, "device_type", NULL);
  881. /* We are scanning "memory" nodes only. */
  882. if (!type || strcmp(type, "memory"))
  883. return 0;
  884. reg = of_get_flat_dt_prop(node, "reg", &size);
  885. if (reg) {
  886. soc_pm.memcs = __va((phys_addr_t)be32_to_cpu(*reg));
  887. *located = 1;
  888. }
  889. return 0;
  890. }
  891. static int __init at91_pm_backup_init(void)
  892. {
  893. struct gen_pool *sram_pool;
  894. struct device_node *np;
  895. struct platform_device *pdev;
  896. int ret = -ENODEV, located = 0;
  897. if (!IS_ENABLED(CONFIG_SOC_SAMA5D2) &&
  898. !IS_ENABLED(CONFIG_SOC_SAMA7G5) &&
  899. !IS_ENABLED(CONFIG_SOC_SAMA7D65))
  900. return -EPERM;
  901. if (!at91_is_pm_mode_active(AT91_PM_BACKUP))
  902. return 0;
  903. np = of_find_compatible_node(NULL, NULL, "atmel,sama5d2-securam");
  904. if (!np)
  905. return ret;
  906. pdev = of_find_device_by_node(np);
  907. of_node_put(np);
  908. if (!pdev) {
  909. pr_warn("%s: failed to find securam device!\n", __func__);
  910. return ret;
  911. }
  912. sram_pool = gen_pool_get(&pdev->dev, NULL);
  913. if (!sram_pool) {
  914. pr_warn("%s: securam pool unavailable!\n", __func__);
  915. goto securam_fail;
  916. }
  917. soc_pm.bu = (void *)gen_pool_alloc(sram_pool, sizeof(struct at91_pm_bu));
  918. if (!soc_pm.bu) {
  919. pr_warn("%s: unable to alloc securam!\n", __func__);
  920. ret = -ENOMEM;
  921. goto securam_fail;
  922. }
  923. soc_pm.bu->suspended = 0;
  924. soc_pm.bu->canary = __pa_symbol(&canary);
  925. soc_pm.bu->resume = __pa_symbol(cpu_resume);
  926. if (soc_pm.data.ramc_phy) {
  927. of_scan_flat_dt(at91_pm_backup_scan_memcs, &located);
  928. if (!located)
  929. goto securam_fail;
  930. }
  931. return 0;
  932. securam_fail:
  933. put_device(&pdev->dev);
  934. return ret;
  935. }
  936. static void __init at91_pm_secure_init(void)
  937. {
  938. int suspend_mode;
  939. struct arm_smccc_res res;
  940. suspend_mode = soc_pm.data.suspend_mode;
  941. res = sam_smccc_call(SAMA5_SMC_SIP_SET_SUSPEND_MODE,
  942. suspend_mode, 0);
  943. if (res.a0 == 0) {
  944. pr_info("AT91: Secure PM: suspend mode set to %s\n",
  945. pm_modes[suspend_mode].pattern);
  946. soc_pm.data.mode = suspend_mode;
  947. return;
  948. }
  949. pr_warn("AT91: Secure PM: %s mode not supported !\n",
  950. pm_modes[suspend_mode].pattern);
  951. res = sam_smccc_call(SAMA5_SMC_SIP_GET_SUSPEND_MODE, 0, 0);
  952. if (res.a0 == 0) {
  953. pr_warn("AT91: Secure PM: failed to get default mode\n");
  954. soc_pm.data.mode = -1;
  955. return;
  956. }
  957. pr_info("AT91: Secure PM: using default suspend mode %s\n",
  958. pm_modes[suspend_mode].pattern);
  959. soc_pm.data.suspend_mode = res.a1;
  960. soc_pm.data.mode = soc_pm.data.suspend_mode;
  961. }
  962. static const struct of_device_id atmel_shdwc_ids[] = {
  963. { .compatible = "atmel,sama5d2-shdwc" },
  964. { .compatible = "microchip,sam9x60-shdwc" },
  965. { .compatible = "microchip,sama7g5-shdwc" },
  966. { /* sentinel. */ }
  967. };
  968. static const struct of_device_id gmac_ids[] __initconst = {
  969. { .compatible = "atmel,sama5d3-gem" },
  970. { .compatible = "atmel,sama5d2-gem" },
  971. { .compatible = "atmel,sama5d29-gem" },
  972. { .compatible = "microchip,sama7g5-gem" },
  973. { },
  974. };
  975. static const struct of_device_id emac_ids[] __initconst = {
  976. { .compatible = "atmel,sama5d3-macb" },
  977. { .compatible = "microchip,sama7g5-emac" },
  978. { },
  979. };
  980. /*
  981. * Replaces _mode_to_replace with a supported mode that doesn't depend
  982. * on controller pointed by _map_bitmask
  983. * @_maps: u32 array containing AT91_PM_IOMAP() flags and indexed by AT91
  984. * PM mode
  985. * @_map_bitmask: AT91_PM_IOMAP() bitmask; if _mode_to_replace depends on
  986. * controller represented by _map_bitmask, _mode_to_replace needs to be
  987. * updated
  988. * @_mode_to_replace: standby_mode or suspend_mode that need to be
  989. * updated
  990. * @_mode_to_check: standby_mode or suspend_mode; this is needed here
  991. * to avoid having standby_mode and suspend_mode set with the same AT91
  992. * PM mode
  993. */
  994. #define AT91_PM_REPLACE_MODE(_maps, _map_bitmask, _mode_to_replace, \
  995. _mode_to_check) \
  996. do { \
  997. if (((_maps)[(_mode_to_replace)]) & (_map_bitmask)) { \
  998. int _mode_to_use, _mode_complementary; \
  999. /* Use ULP0 if it doesn't need _map_bitmask. */ \
  1000. if (!((_maps)[AT91_PM_ULP0] & (_map_bitmask))) {\
  1001. _mode_to_use = AT91_PM_ULP0; \
  1002. _mode_complementary = AT91_PM_STANDBY; \
  1003. } else { \
  1004. _mode_to_use = AT91_PM_STANDBY; \
  1005. _mode_complementary = AT91_PM_STANDBY; \
  1006. } \
  1007. \
  1008. if ((_mode_to_check) != _mode_to_use) \
  1009. (_mode_to_replace) = _mode_to_use; \
  1010. else \
  1011. (_mode_to_replace) = _mode_complementary;\
  1012. } \
  1013. } while (0)
  1014. /*
  1015. * Replaces standby and suspend modes with default supported modes:
  1016. * ULP0 and STANDBY.
  1017. * @_maps: u32 array indexed by AT91 PM mode containing AT91_PM_IOMAP()
  1018. * flags
  1019. * @_map: controller specific name; standby and suspend mode need to be
  1020. * replaced in order to not depend on this controller
  1021. */
  1022. #define AT91_PM_REPLACE_MODES(_maps, _map) \
  1023. do { \
  1024. AT91_PM_REPLACE_MODE((_maps), BIT(AT91_PM_IOMAP_##_map),\
  1025. (soc_pm.data.standby_mode), \
  1026. (soc_pm.data.suspend_mode)); \
  1027. AT91_PM_REPLACE_MODE((_maps), BIT(AT91_PM_IOMAP_##_map),\
  1028. (soc_pm.data.suspend_mode), \
  1029. (soc_pm.data.standby_mode)); \
  1030. } while (0)
  1031. static int __init at91_pm_get_eth_clks(struct device_node *np,
  1032. struct clk_bulk_data *clks)
  1033. {
  1034. clks[AT91_PM_ETH_PCLK].clk = of_clk_get_by_name(np, "pclk");
  1035. if (IS_ERR(clks[AT91_PM_ETH_PCLK].clk))
  1036. return PTR_ERR(clks[AT91_PM_ETH_PCLK].clk);
  1037. clks[AT91_PM_ETH_HCLK].clk = of_clk_get_by_name(np, "hclk");
  1038. if (IS_ERR(clks[AT91_PM_ETH_HCLK].clk))
  1039. return PTR_ERR(clks[AT91_PM_ETH_HCLK].clk);
  1040. return 0;
  1041. }
  1042. static int __init at91_pm_eth_clks_empty(struct clk_bulk_data *clks)
  1043. {
  1044. return IS_ERR(clks[AT91_PM_ETH_PCLK].clk) ||
  1045. IS_ERR(clks[AT91_PM_ETH_HCLK].clk);
  1046. }
  1047. static void __init at91_pm_modes_init(const u32 *maps, int len)
  1048. {
  1049. struct at91_pm_quirk_eth *gmac = &soc_pm.quirks.eth[AT91_PM_G_ETH];
  1050. struct at91_pm_quirk_eth *emac = &soc_pm.quirks.eth[AT91_PM_E_ETH];
  1051. struct device_node *np;
  1052. int ret;
  1053. ret = at91_pm_backup_init();
  1054. if (ret) {
  1055. if (soc_pm.data.standby_mode == AT91_PM_BACKUP)
  1056. soc_pm.data.standby_mode = AT91_PM_ULP0;
  1057. if (soc_pm.data.suspend_mode == AT91_PM_BACKUP)
  1058. soc_pm.data.suspend_mode = AT91_PM_ULP0;
  1059. }
  1060. if (maps[soc_pm.data.standby_mode] & AT91_PM_IOMAP(SHDWC) ||
  1061. maps[soc_pm.data.suspend_mode] & AT91_PM_IOMAP(SHDWC)) {
  1062. np = of_find_matching_node(NULL, atmel_shdwc_ids);
  1063. if (!np) {
  1064. pr_warn("%s: failed to find shdwc!\n", __func__);
  1065. AT91_PM_REPLACE_MODES(maps, SHDWC);
  1066. } else {
  1067. soc_pm.data.shdwc = of_iomap(np, 0);
  1068. of_node_put(np);
  1069. }
  1070. }
  1071. if (maps[soc_pm.data.standby_mode] & AT91_PM_IOMAP(SFRBU) ||
  1072. maps[soc_pm.data.suspend_mode] & AT91_PM_IOMAP(SFRBU)) {
  1073. np = of_find_compatible_node(NULL, NULL, "atmel,sama5d2-sfrbu");
  1074. if (!np) {
  1075. pr_warn("%s: failed to find sfrbu!\n", __func__);
  1076. AT91_PM_REPLACE_MODES(maps, SFRBU);
  1077. } else {
  1078. soc_pm.data.sfrbu = of_iomap(np, 0);
  1079. of_node_put(np);
  1080. }
  1081. }
  1082. if ((at91_is_pm_mode_active(AT91_PM_ULP1) ||
  1083. at91_is_pm_mode_active(AT91_PM_ULP0) ||
  1084. at91_is_pm_mode_active(AT91_PM_ULP0_FAST)) &&
  1085. (maps[soc_pm.data.standby_mode] & AT91_PM_IOMAP(ETHC) ||
  1086. maps[soc_pm.data.suspend_mode] & AT91_PM_IOMAP(ETHC))) {
  1087. np = of_find_matching_node(NULL, gmac_ids);
  1088. if (!np) {
  1089. np = of_find_matching_node(NULL, emac_ids);
  1090. if (np)
  1091. goto get_emac_clks;
  1092. AT91_PM_REPLACE_MODES(maps, ETHC);
  1093. goto unmap_unused_nodes;
  1094. } else {
  1095. gmac->np = np;
  1096. at91_pm_get_eth_clks(np, gmac->clks);
  1097. }
  1098. np = of_find_matching_node(NULL, emac_ids);
  1099. if (!np) {
  1100. if (at91_pm_eth_clks_empty(gmac->clks))
  1101. AT91_PM_REPLACE_MODES(maps, ETHC);
  1102. } else {
  1103. get_emac_clks:
  1104. emac->np = np;
  1105. ret = at91_pm_get_eth_clks(np, emac->clks);
  1106. if (ret && at91_pm_eth_clks_empty(gmac->clks)) {
  1107. of_node_put(gmac->np);
  1108. of_node_put(emac->np);
  1109. gmac->np = NULL;
  1110. emac->np = NULL;
  1111. }
  1112. }
  1113. }
  1114. unmap_unused_nodes:
  1115. /* Unmap all unnecessary. */
  1116. if (soc_pm.data.shdwc &&
  1117. !(maps[soc_pm.data.standby_mode] & AT91_PM_IOMAP(SHDWC) ||
  1118. maps[soc_pm.data.suspend_mode] & AT91_PM_IOMAP(SHDWC))) {
  1119. iounmap(soc_pm.data.shdwc);
  1120. soc_pm.data.shdwc = NULL;
  1121. }
  1122. if (soc_pm.data.sfrbu &&
  1123. !(maps[soc_pm.data.standby_mode] & AT91_PM_IOMAP(SFRBU) ||
  1124. maps[soc_pm.data.suspend_mode] & AT91_PM_IOMAP(SFRBU))) {
  1125. iounmap(soc_pm.data.sfrbu);
  1126. soc_pm.data.sfrbu = NULL;
  1127. }
  1128. return;
  1129. }
  1130. struct pmc_info {
  1131. unsigned long uhp_udp_mask;
  1132. unsigned long mckr;
  1133. unsigned long version;
  1134. unsigned long mcks;
  1135. };
  1136. static const struct pmc_info pmc_infos[] __initconst = {
  1137. {
  1138. .uhp_udp_mask = AT91RM9200_PMC_UHP | AT91RM9200_PMC_UDP,
  1139. .mckr = 0x30,
  1140. .version = AT91_PMC_V1,
  1141. },
  1142. {
  1143. .uhp_udp_mask = AT91SAM926x_PMC_UHP | AT91SAM926x_PMC_UDP,
  1144. .mckr = 0x30,
  1145. .version = AT91_PMC_V1,
  1146. },
  1147. {
  1148. .uhp_udp_mask = AT91SAM926x_PMC_UHP,
  1149. .mckr = 0x30,
  1150. .version = AT91_PMC_V1,
  1151. },
  1152. { .uhp_udp_mask = 0,
  1153. .mckr = 0x30,
  1154. .version = AT91_PMC_V1,
  1155. },
  1156. {
  1157. .uhp_udp_mask = AT91SAM926x_PMC_UHP,
  1158. .mckr = 0x28,
  1159. .version = AT91_PMC_V2,
  1160. },
  1161. {
  1162. .mckr = 0x28,
  1163. .version = AT91_PMC_V2,
  1164. .mcks = 4,
  1165. },
  1166. {
  1167. .uhp_udp_mask = AT91SAM926x_PMC_UHP,
  1168. .mckr = 0x28,
  1169. .version = AT91_PMC_V2,
  1170. .mcks = 9,
  1171. },
  1172. };
  1173. static const struct of_device_id atmel_pmc_ids[] __initconst = {
  1174. { .compatible = "atmel,at91rm9200-pmc", .data = &pmc_infos[0] },
  1175. { .compatible = "atmel,at91sam9260-pmc", .data = &pmc_infos[1] },
  1176. { .compatible = "atmel,at91sam9261-pmc", .data = &pmc_infos[1] },
  1177. { .compatible = "atmel,at91sam9263-pmc", .data = &pmc_infos[1] },
  1178. { .compatible = "atmel,at91sam9g45-pmc", .data = &pmc_infos[2] },
  1179. { .compatible = "atmel,at91sam9n12-pmc", .data = &pmc_infos[1] },
  1180. { .compatible = "atmel,at91sam9rl-pmc", .data = &pmc_infos[3] },
  1181. { .compatible = "atmel,at91sam9x5-pmc", .data = &pmc_infos[1] },
  1182. { .compatible = "atmel,sama5d3-pmc", .data = &pmc_infos[1] },
  1183. { .compatible = "atmel,sama5d4-pmc", .data = &pmc_infos[1] },
  1184. { .compatible = "atmel,sama5d2-pmc", .data = &pmc_infos[1] },
  1185. { .compatible = "microchip,sam9x60-pmc", .data = &pmc_infos[4] },
  1186. { .compatible = "microchip,sam9x7-pmc", .data = &pmc_infos[4] },
  1187. { .compatible = "microchip,sama7d65-pmc", .data = &pmc_infos[6] },
  1188. { .compatible = "microchip,sama7g5-pmc", .data = &pmc_infos[5] },
  1189. { /* sentinel */ },
  1190. };
  1191. static void __init at91_pm_modes_validate(const int *modes, int len)
  1192. {
  1193. u8 i, standby = 0, suspend = 0;
  1194. int mode;
  1195. for (i = 0; i < len; i++) {
  1196. if (standby && suspend)
  1197. break;
  1198. if (modes[i] == soc_pm.data.standby_mode && !standby) {
  1199. standby = 1;
  1200. continue;
  1201. }
  1202. if (modes[i] == soc_pm.data.suspend_mode && !suspend) {
  1203. suspend = 1;
  1204. continue;
  1205. }
  1206. }
  1207. if (!standby) {
  1208. if (soc_pm.data.suspend_mode == AT91_PM_STANDBY)
  1209. mode = AT91_PM_ULP0;
  1210. else
  1211. mode = AT91_PM_STANDBY;
  1212. pr_warn("AT91: PM: %s mode not supported! Using %s.\n",
  1213. pm_modes[soc_pm.data.standby_mode].pattern,
  1214. pm_modes[mode].pattern);
  1215. soc_pm.data.standby_mode = mode;
  1216. }
  1217. if (!suspend) {
  1218. if (soc_pm.data.standby_mode == AT91_PM_ULP0)
  1219. mode = AT91_PM_STANDBY;
  1220. else
  1221. mode = AT91_PM_ULP0;
  1222. pr_warn("AT91: PM: %s mode not supported! Using %s.\n",
  1223. pm_modes[soc_pm.data.suspend_mode].pattern,
  1224. pm_modes[mode].pattern);
  1225. soc_pm.data.suspend_mode = mode;
  1226. }
  1227. }
  1228. static void __init at91_pm_init(void (*pm_idle)(void))
  1229. {
  1230. struct device_node *pmc_np;
  1231. const struct of_device_id *of_id;
  1232. const struct pmc_info *pmc;
  1233. if (at91_cpuidle_device.dev.platform_data)
  1234. platform_device_register(&at91_cpuidle_device);
  1235. pmc_np = of_find_matching_node_and_match(NULL, atmel_pmc_ids, &of_id);
  1236. soc_pm.data.pmc = of_iomap(pmc_np, 0);
  1237. of_node_put(pmc_np);
  1238. if (!soc_pm.data.pmc) {
  1239. pr_err("AT91: PM not supported, PMC not found\n");
  1240. return;
  1241. }
  1242. pmc = of_id->data;
  1243. soc_pm.data.uhp_udp_mask = pmc->uhp_udp_mask;
  1244. soc_pm.data.pmc_mckr_offset = pmc->mckr;
  1245. soc_pm.data.pmc_version = pmc->version;
  1246. soc_pm.data.pmc_mcks = pmc->mcks;
  1247. if (pm_idle)
  1248. arm_pm_idle = pm_idle;
  1249. at91_pm_sram_init();
  1250. if (at91_suspend_sram_fn) {
  1251. suspend_set_ops(&at91_pm_ops);
  1252. pr_info("AT91: PM: standby: %s, suspend: %s\n",
  1253. pm_modes[soc_pm.data.standby_mode].pattern,
  1254. pm_modes[soc_pm.data.suspend_mode].pattern);
  1255. } else {
  1256. pr_info("AT91: PM not supported, due to no SRAM allocated\n");
  1257. }
  1258. }
  1259. void __init at91rm9200_pm_init(void)
  1260. {
  1261. int ret;
  1262. if (!IS_ENABLED(CONFIG_SOC_AT91RM9200))
  1263. return;
  1264. /*
  1265. * Force STANDBY and ULP0 mode to avoid calling
  1266. * at91_pm_modes_validate() which may increase booting time.
  1267. * Platform supports anyway only STANDBY and ULP0 modes.
  1268. */
  1269. soc_pm.data.standby_mode = AT91_PM_STANDBY;
  1270. soc_pm.data.suspend_mode = AT91_PM_ULP0;
  1271. ret = at91_dt_ramc(false);
  1272. if (ret)
  1273. return;
  1274. /*
  1275. * AT91RM9200 SDRAM low-power mode cannot be used with self-refresh.
  1276. */
  1277. at91_ramc_write(0, AT91_MC_SDRAMC_LPR, 0);
  1278. at91_pm_init(at91rm9200_idle);
  1279. }
  1280. void __init sam9x60_pm_init(void)
  1281. {
  1282. static const int modes[] __initconst = {
  1283. AT91_PM_STANDBY, AT91_PM_ULP0, AT91_PM_ULP0_FAST, AT91_PM_ULP1,
  1284. };
  1285. static const int iomaps[] __initconst = {
  1286. [AT91_PM_ULP1] = AT91_PM_IOMAP(SHDWC),
  1287. };
  1288. int ret;
  1289. if (!IS_ENABLED(CONFIG_SOC_SAM9X60))
  1290. return;
  1291. at91_pm_modes_validate(modes, ARRAY_SIZE(modes));
  1292. at91_pm_modes_init(iomaps, ARRAY_SIZE(iomaps));
  1293. ret = at91_dt_ramc(false);
  1294. if (ret)
  1295. return;
  1296. at91_pm_init(NULL);
  1297. soc_pm.ws_ids = sam9x60_ws_ids;
  1298. soc_pm.config_pmc_ws = at91_sam9x60_config_pmc_ws;
  1299. }
  1300. void __init sam9x7_pm_init(void)
  1301. {
  1302. static const int modes[] __initconst = {
  1303. AT91_PM_STANDBY, AT91_PM_ULP0,
  1304. };
  1305. int ret;
  1306. if (!IS_ENABLED(CONFIG_SOC_SAM9X7))
  1307. return;
  1308. at91_pm_modes_validate(modes, ARRAY_SIZE(modes));
  1309. ret = at91_dt_ramc(false);
  1310. if (ret)
  1311. return;
  1312. at91_pm_init(NULL);
  1313. soc_pm.ws_ids = sam9x7_ws_ids;
  1314. soc_pm.config_pmc_ws = at91_sam9x60_config_pmc_ws;
  1315. }
  1316. void __init at91sam9_pm_init(void)
  1317. {
  1318. int ret;
  1319. if (!IS_ENABLED(CONFIG_SOC_AT91SAM9))
  1320. return;
  1321. /*
  1322. * Force STANDBY and ULP0 mode to avoid calling
  1323. * at91_pm_modes_validate() which may increase booting time.
  1324. * Platform supports anyway only STANDBY and ULP0 modes.
  1325. */
  1326. soc_pm.data.standby_mode = AT91_PM_STANDBY;
  1327. soc_pm.data.suspend_mode = AT91_PM_ULP0;
  1328. ret = at91_dt_ramc(false);
  1329. if (ret)
  1330. return;
  1331. at91_pm_init(at91sam9_idle);
  1332. }
  1333. void __init sama5_pm_init(void)
  1334. {
  1335. static const int modes[] __initconst = {
  1336. AT91_PM_STANDBY, AT91_PM_ULP0, AT91_PM_ULP0_FAST,
  1337. };
  1338. static const u32 iomaps[] __initconst = {
  1339. [AT91_PM_ULP0] = AT91_PM_IOMAP(ETHC),
  1340. [AT91_PM_ULP0_FAST] = AT91_PM_IOMAP(ETHC),
  1341. };
  1342. int ret;
  1343. if (!IS_ENABLED(CONFIG_SOC_SAMA5))
  1344. return;
  1345. at91_pm_modes_validate(modes, ARRAY_SIZE(modes));
  1346. at91_pm_modes_init(iomaps, ARRAY_SIZE(iomaps));
  1347. ret = at91_dt_ramc(false);
  1348. if (ret)
  1349. return;
  1350. at91_pm_init(NULL);
  1351. /* Quirks applies to ULP0, ULP0 fast and ULP1 modes. */
  1352. soc_pm.quirks.eth[AT91_PM_G_ETH].modes = BIT(AT91_PM_ULP0) |
  1353. BIT(AT91_PM_ULP0_FAST) |
  1354. BIT(AT91_PM_ULP1);
  1355. /* Do not suspend in ULP0, ULP0 fast if GETH is the only wakeup source. */
  1356. soc_pm.quirks.eth[AT91_PM_G_ETH].dns_modes = BIT(AT91_PM_ULP0) |
  1357. BIT(AT91_PM_ULP0_FAST);
  1358. }
  1359. void __init sama5d2_pm_init(void)
  1360. {
  1361. static const int modes[] __initconst = {
  1362. AT91_PM_STANDBY, AT91_PM_ULP0, AT91_PM_ULP0_FAST, AT91_PM_ULP1,
  1363. AT91_PM_BACKUP,
  1364. };
  1365. static const u32 iomaps[] __initconst = {
  1366. [AT91_PM_ULP0] = AT91_PM_IOMAP(ETHC),
  1367. [AT91_PM_ULP0_FAST] = AT91_PM_IOMAP(ETHC),
  1368. [AT91_PM_ULP1] = AT91_PM_IOMAP(SHDWC) |
  1369. AT91_PM_IOMAP(ETHC),
  1370. [AT91_PM_BACKUP] = AT91_PM_IOMAP(SHDWC) |
  1371. AT91_PM_IOMAP(SFRBU),
  1372. };
  1373. int ret;
  1374. if (!IS_ENABLED(CONFIG_SOC_SAMA5D2))
  1375. return;
  1376. if (IS_ENABLED(CONFIG_ATMEL_SECURE_PM)) {
  1377. pr_warn("AT91: Secure PM: ignoring standby mode\n");
  1378. at91_pm_secure_init();
  1379. return;
  1380. }
  1381. at91_pm_modes_validate(modes, ARRAY_SIZE(modes));
  1382. at91_pm_modes_init(iomaps, ARRAY_SIZE(iomaps));
  1383. ret = at91_dt_ramc(false);
  1384. if (ret)
  1385. return;
  1386. at91_pm_init(NULL);
  1387. soc_pm.ws_ids = sama5d2_ws_ids;
  1388. soc_pm.config_shdwc_ws = at91_sama5d2_config_shdwc_ws;
  1389. soc_pm.config_pmc_ws = at91_sama5d2_config_pmc_ws;
  1390. soc_pm.sfrbu_regs.pswbu.key = (0x4BD20C << 8);
  1391. soc_pm.sfrbu_regs.pswbu.ctrl = BIT(0);
  1392. soc_pm.sfrbu_regs.pswbu.softsw = BIT(1);
  1393. soc_pm.sfrbu_regs.pswbu.state = BIT(3);
  1394. /* Quirk applies to ULP0, ULP0 fast and ULP1 modes. */
  1395. soc_pm.quirks.eth[AT91_PM_G_ETH].modes = BIT(AT91_PM_ULP0) |
  1396. BIT(AT91_PM_ULP0_FAST) |
  1397. BIT(AT91_PM_ULP1);
  1398. /*
  1399. * Do not suspend in ULP0, ULP0 fast if GETH is the only wakeup
  1400. * source.
  1401. */
  1402. soc_pm.quirks.eth[AT91_PM_G_ETH].dns_modes = BIT(AT91_PM_ULP0) |
  1403. BIT(AT91_PM_ULP0_FAST);
  1404. }
  1405. void __init sama7_pm_init(void)
  1406. {
  1407. static const int modes[] __initconst = {
  1408. AT91_PM_STANDBY, AT91_PM_ULP0, AT91_PM_ULP1, AT91_PM_BACKUP,
  1409. };
  1410. static const u32 iomaps[] __initconst = {
  1411. [AT91_PM_ULP0] = AT91_PM_IOMAP(SFRBU),
  1412. [AT91_PM_ULP1] = AT91_PM_IOMAP(SFRBU) |
  1413. AT91_PM_IOMAP(SHDWC) |
  1414. AT91_PM_IOMAP(ETHC),
  1415. [AT91_PM_BACKUP] = AT91_PM_IOMAP(SFRBU) |
  1416. AT91_PM_IOMAP(SHDWC),
  1417. };
  1418. int ret;
  1419. if (!IS_ENABLED(CONFIG_SOC_SAMA7))
  1420. return;
  1421. at91_pm_modes_validate(modes, ARRAY_SIZE(modes));
  1422. ret = at91_dt_ramc(true);
  1423. if (ret)
  1424. return;
  1425. at91_pm_modes_init(iomaps, ARRAY_SIZE(iomaps));
  1426. at91_pm_init(NULL);
  1427. soc_pm.ws_ids = sama7_ws_ids;
  1428. soc_pm.config_pmc_ws = at91_sam9x60_config_pmc_ws;
  1429. soc_pm.sfrbu_regs.pswbu.key = (0x4BD20C << 8);
  1430. soc_pm.sfrbu_regs.pswbu.ctrl = BIT(0);
  1431. soc_pm.sfrbu_regs.pswbu.softsw = BIT(1);
  1432. soc_pm.sfrbu_regs.pswbu.state = BIT(2);
  1433. /* Quirks applies to ULP1 for both Ethernet interfaces. */
  1434. soc_pm.quirks.eth[AT91_PM_E_ETH].modes = BIT(AT91_PM_ULP1);
  1435. soc_pm.quirks.eth[AT91_PM_G_ETH].modes = BIT(AT91_PM_ULP1);
  1436. }
  1437. static int __init at91_pm_modes_select(char *str)
  1438. {
  1439. char *s;
  1440. substring_t args[MAX_OPT_ARGS];
  1441. int standby, suspend;
  1442. if (!str)
  1443. return 0;
  1444. s = strsep(&str, ",");
  1445. standby = match_token(s, pm_modes, args);
  1446. if (standby < 0)
  1447. return 0;
  1448. suspend = match_token(str, pm_modes, args);
  1449. if (suspend < 0)
  1450. return 0;
  1451. soc_pm.data.standby_mode = standby;
  1452. soc_pm.data.suspend_mode = suspend;
  1453. return 0;
  1454. }
  1455. early_param("atmel.pm_modes", at91_pm_modes_select);