pmc.c 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981
  1. /*
  2. * drivers/soc/tegra/pmc.c
  3. *
  4. * Copyright (c) 2010 Google, Inc
  5. *
  6. * Author:
  7. * Colin Cross <ccross@google.com>
  8. *
  9. * This software is licensed under the terms of the GNU General Public
  10. * License version 2, as published by the Free Software Foundation, and
  11. * may be copied, distributed, and modified under those terms.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. */
  19. #define pr_fmt(fmt) "tegra-pmc: " fmt
  20. #include <linux/kernel.h>
  21. #include <linux/clk.h>
  22. #include <linux/clk/tegra.h>
  23. #include <linux/debugfs.h>
  24. #include <linux/delay.h>
  25. #include <linux/err.h>
  26. #include <linux/export.h>
  27. #include <linux/init.h>
  28. #include <linux/io.h>
  29. #include <linux/iopoll.h>
  30. #include <linux/of.h>
  31. #include <linux/of_address.h>
  32. #include <linux/of_platform.h>
  33. #include <linux/platform_device.h>
  34. #include <linux/pm_domain.h>
  35. #include <linux/reboot.h>
  36. #include <linux/reset.h>
  37. #include <linux/seq_file.h>
  38. #include <linux/slab.h>
  39. #include <linux/spinlock.h>
  40. #include <soc/tegra/common.h>
  41. #include <soc/tegra/fuse.h>
  42. #include <soc/tegra/pmc.h>
  43. #define PMC_CNTRL 0x0
  44. #define PMC_CNTRL_INTR_POLARITY BIT(17) /* inverts INTR polarity */
  45. #define PMC_CNTRL_CPU_PWRREQ_OE BIT(16) /* CPU pwr req enable */
  46. #define PMC_CNTRL_CPU_PWRREQ_POLARITY BIT(15) /* CPU pwr req polarity */
  47. #define PMC_CNTRL_SIDE_EFFECT_LP0 BIT(14) /* LP0 when CPU pwr gated */
  48. #define PMC_CNTRL_SYSCLK_OE BIT(11) /* system clock enable */
  49. #define PMC_CNTRL_SYSCLK_POLARITY BIT(10) /* sys clk polarity */
  50. #define PMC_CNTRL_MAIN_RST BIT(4)
  51. #define DPD_SAMPLE 0x020
  52. #define DPD_SAMPLE_ENABLE BIT(0)
  53. #define DPD_SAMPLE_DISABLE (0 << 0)
  54. #define PWRGATE_TOGGLE 0x30
  55. #define PWRGATE_TOGGLE_START BIT(8)
  56. #define REMOVE_CLAMPING 0x34
  57. #define PWRGATE_STATUS 0x38
  58. #define PMC_PWR_DET 0x48
  59. #define PMC_SCRATCH0_MODE_RECOVERY BIT(31)
  60. #define PMC_SCRATCH0_MODE_BOOTLOADER BIT(30)
  61. #define PMC_SCRATCH0_MODE_RCM BIT(1)
  62. #define PMC_SCRATCH0_MODE_MASK (PMC_SCRATCH0_MODE_RECOVERY | \
  63. PMC_SCRATCH0_MODE_BOOTLOADER | \
  64. PMC_SCRATCH0_MODE_RCM)
  65. #define PMC_CPUPWRGOOD_TIMER 0xc8
  66. #define PMC_CPUPWROFF_TIMER 0xcc
  67. #define PMC_PWR_DET_VALUE 0xe4
  68. #define PMC_SCRATCH41 0x140
  69. #define PMC_SENSOR_CTRL 0x1b0
  70. #define PMC_SENSOR_CTRL_SCRATCH_WRITE BIT(2)
  71. #define PMC_SENSOR_CTRL_ENABLE_RST BIT(1)
  72. #define PMC_RST_STATUS 0x1b4
  73. #define PMC_RST_STATUS_POR 0
  74. #define PMC_RST_STATUS_WATCHDOG 1
  75. #define PMC_RST_STATUS_SENSOR 2
  76. #define PMC_RST_STATUS_SW_MAIN 3
  77. #define PMC_RST_STATUS_LP0 4
  78. #define PMC_RST_STATUS_AOTAG 5
  79. #define IO_DPD_REQ 0x1b8
  80. #define IO_DPD_REQ_CODE_IDLE (0U << 30)
  81. #define IO_DPD_REQ_CODE_OFF (1U << 30)
  82. #define IO_DPD_REQ_CODE_ON (2U << 30)
  83. #define IO_DPD_REQ_CODE_MASK (3U << 30)
  84. #define IO_DPD_STATUS 0x1bc
  85. #define IO_DPD2_REQ 0x1c0
  86. #define IO_DPD2_STATUS 0x1c4
  87. #define SEL_DPD_TIM 0x1c8
  88. #define PMC_SCRATCH54 0x258
  89. #define PMC_SCRATCH54_DATA_SHIFT 8
  90. #define PMC_SCRATCH54_ADDR_SHIFT 0
  91. #define PMC_SCRATCH55 0x25c
  92. #define PMC_SCRATCH55_RESET_TEGRA BIT(31)
  93. #define PMC_SCRATCH55_CNTRL_ID_SHIFT 27
  94. #define PMC_SCRATCH55_PINMUX_SHIFT 24
  95. #define PMC_SCRATCH55_16BITOP BIT(15)
  96. #define PMC_SCRATCH55_CHECKSUM_SHIFT 16
  97. #define PMC_SCRATCH55_I2CSLV1_SHIFT 0
  98. #define GPU_RG_CNTRL 0x2d4
  99. /* Tegra186 and later */
  100. #define WAKE_AOWAKE_CTRL 0x4f4
  101. #define WAKE_AOWAKE_CTRL_INTR_POLARITY BIT(0)
  102. struct tegra_powergate {
  103. struct generic_pm_domain genpd;
  104. struct tegra_pmc *pmc;
  105. unsigned int id;
  106. struct clk **clks;
  107. unsigned int num_clks;
  108. struct reset_control *reset;
  109. };
  110. struct tegra_io_pad_soc {
  111. enum tegra_io_pad id;
  112. unsigned int dpd;
  113. unsigned int voltage;
  114. };
  115. struct tegra_pmc_regs {
  116. unsigned int scratch0;
  117. unsigned int dpd_req;
  118. unsigned int dpd_status;
  119. unsigned int dpd2_req;
  120. unsigned int dpd2_status;
  121. };
  122. struct tegra_pmc_soc {
  123. unsigned int num_powergates;
  124. const char *const *powergates;
  125. unsigned int num_cpu_powergates;
  126. const u8 *cpu_powergates;
  127. bool has_tsense_reset;
  128. bool has_gpu_clamps;
  129. bool needs_mbist_war;
  130. const struct tegra_io_pad_soc *io_pads;
  131. unsigned int num_io_pads;
  132. const struct tegra_pmc_regs *regs;
  133. void (*init)(struct tegra_pmc *pmc);
  134. void (*setup_irq_polarity)(struct tegra_pmc *pmc,
  135. struct device_node *np,
  136. bool invert);
  137. };
  138. /**
  139. * struct tegra_pmc - NVIDIA Tegra PMC
  140. * @dev: pointer to PMC device structure
  141. * @base: pointer to I/O remapped register region
  142. * @clk: pointer to pclk clock
  143. * @soc: pointer to SoC data structure
  144. * @debugfs: pointer to debugfs entry
  145. * @rate: currently configured rate of pclk
  146. * @suspend_mode: lowest suspend mode available
  147. * @cpu_good_time: CPU power good time (in microseconds)
  148. * @cpu_off_time: CPU power off time (in microsecends)
  149. * @core_osc_time: core power good OSC time (in microseconds)
  150. * @core_pmu_time: core power good PMU time (in microseconds)
  151. * @core_off_time: core power off time (in microseconds)
  152. * @corereq_high: core power request is active-high
  153. * @sysclkreq_high: system clock request is active-high
  154. * @combined_req: combined power request for CPU & core
  155. * @cpu_pwr_good_en: CPU power good signal is enabled
  156. * @lp0_vec_phys: physical base address of the LP0 warm boot code
  157. * @lp0_vec_size: size of the LP0 warm boot code
  158. * @powergates_available: Bitmap of available power gates
  159. * @powergates_lock: mutex for power gate register access
  160. */
  161. struct tegra_pmc {
  162. struct device *dev;
  163. void __iomem *base;
  164. void __iomem *wake;
  165. void __iomem *aotag;
  166. void __iomem *scratch;
  167. struct clk *clk;
  168. struct dentry *debugfs;
  169. const struct tegra_pmc_soc *soc;
  170. unsigned long rate;
  171. enum tegra_suspend_mode suspend_mode;
  172. u32 cpu_good_time;
  173. u32 cpu_off_time;
  174. u32 core_osc_time;
  175. u32 core_pmu_time;
  176. u32 core_off_time;
  177. bool corereq_high;
  178. bool sysclkreq_high;
  179. bool combined_req;
  180. bool cpu_pwr_good_en;
  181. u32 lp0_vec_phys;
  182. u32 lp0_vec_size;
  183. DECLARE_BITMAP(powergates_available, TEGRA_POWERGATE_MAX);
  184. struct mutex powergates_lock;
  185. };
  186. static struct tegra_pmc *pmc = &(struct tegra_pmc) {
  187. .base = NULL,
  188. .suspend_mode = TEGRA_SUSPEND_NONE,
  189. };
  190. static inline struct tegra_powergate *
  191. to_powergate(struct generic_pm_domain *domain)
  192. {
  193. return container_of(domain, struct tegra_powergate, genpd);
  194. }
  195. static u32 tegra_pmc_readl(unsigned long offset)
  196. {
  197. return readl(pmc->base + offset);
  198. }
  199. static void tegra_pmc_writel(u32 value, unsigned long offset)
  200. {
  201. writel(value, pmc->base + offset);
  202. }
  203. static inline bool tegra_powergate_state(int id)
  204. {
  205. if (id == TEGRA_POWERGATE_3D && pmc->soc->has_gpu_clamps)
  206. return (tegra_pmc_readl(GPU_RG_CNTRL) & 0x1) == 0;
  207. else
  208. return (tegra_pmc_readl(PWRGATE_STATUS) & BIT(id)) != 0;
  209. }
  210. static inline bool tegra_powergate_is_valid(int id)
  211. {
  212. return (pmc->soc && pmc->soc->powergates[id]);
  213. }
  214. static inline bool tegra_powergate_is_available(int id)
  215. {
  216. return test_bit(id, pmc->powergates_available);
  217. }
  218. static int tegra_powergate_lookup(struct tegra_pmc *pmc, const char *name)
  219. {
  220. unsigned int i;
  221. if (!pmc || !pmc->soc || !name)
  222. return -EINVAL;
  223. for (i = 0; i < pmc->soc->num_powergates; i++) {
  224. if (!tegra_powergate_is_valid(i))
  225. continue;
  226. if (!strcmp(name, pmc->soc->powergates[i]))
  227. return i;
  228. }
  229. return -ENODEV;
  230. }
  231. /**
  232. * tegra_powergate_set() - set the state of a partition
  233. * @id: partition ID
  234. * @new_state: new state of the partition
  235. */
  236. static int tegra_powergate_set(unsigned int id, bool new_state)
  237. {
  238. bool status;
  239. int err;
  240. if (id == TEGRA_POWERGATE_3D && pmc->soc->has_gpu_clamps)
  241. return -EINVAL;
  242. mutex_lock(&pmc->powergates_lock);
  243. if (tegra_powergate_state(id) == new_state) {
  244. mutex_unlock(&pmc->powergates_lock);
  245. return 0;
  246. }
  247. tegra_pmc_writel(PWRGATE_TOGGLE_START | id, PWRGATE_TOGGLE);
  248. err = readx_poll_timeout(tegra_powergate_state, id, status,
  249. status == new_state, 10, 100000);
  250. mutex_unlock(&pmc->powergates_lock);
  251. return err;
  252. }
  253. static int __tegra_powergate_remove_clamping(unsigned int id)
  254. {
  255. u32 mask;
  256. mutex_lock(&pmc->powergates_lock);
  257. /*
  258. * On Tegra124 and later, the clamps for the GPU are controlled by a
  259. * separate register (with different semantics).
  260. */
  261. if (id == TEGRA_POWERGATE_3D) {
  262. if (pmc->soc->has_gpu_clamps) {
  263. tegra_pmc_writel(0, GPU_RG_CNTRL);
  264. goto out;
  265. }
  266. }
  267. /*
  268. * Tegra 2 has a bug where PCIE and VDE clamping masks are
  269. * swapped relatively to the partition ids
  270. */
  271. if (id == TEGRA_POWERGATE_VDEC)
  272. mask = (1 << TEGRA_POWERGATE_PCIE);
  273. else if (id == TEGRA_POWERGATE_PCIE)
  274. mask = (1 << TEGRA_POWERGATE_VDEC);
  275. else
  276. mask = (1 << id);
  277. tegra_pmc_writel(mask, REMOVE_CLAMPING);
  278. out:
  279. mutex_unlock(&pmc->powergates_lock);
  280. return 0;
  281. }
  282. static void tegra_powergate_disable_clocks(struct tegra_powergate *pg)
  283. {
  284. unsigned int i;
  285. for (i = 0; i < pg->num_clks; i++)
  286. clk_disable_unprepare(pg->clks[i]);
  287. }
  288. static int tegra_powergate_enable_clocks(struct tegra_powergate *pg)
  289. {
  290. unsigned int i;
  291. int err;
  292. for (i = 0; i < pg->num_clks; i++) {
  293. err = clk_prepare_enable(pg->clks[i]);
  294. if (err)
  295. goto out;
  296. }
  297. return 0;
  298. out:
  299. while (i--)
  300. clk_disable_unprepare(pg->clks[i]);
  301. return err;
  302. }
  303. int __weak tegra210_clk_handle_mbist_war(unsigned int id)
  304. {
  305. return 0;
  306. }
  307. static int tegra_powergate_power_up(struct tegra_powergate *pg,
  308. bool disable_clocks)
  309. {
  310. int err;
  311. err = reset_control_assert(pg->reset);
  312. if (err)
  313. return err;
  314. usleep_range(10, 20);
  315. err = tegra_powergate_set(pg->id, true);
  316. if (err < 0)
  317. return err;
  318. usleep_range(10, 20);
  319. err = tegra_powergate_enable_clocks(pg);
  320. if (err)
  321. goto disable_clks;
  322. usleep_range(10, 20);
  323. err = __tegra_powergate_remove_clamping(pg->id);
  324. if (err)
  325. goto disable_clks;
  326. usleep_range(10, 20);
  327. err = reset_control_deassert(pg->reset);
  328. if (err)
  329. goto powergate_off;
  330. usleep_range(10, 20);
  331. if (pg->pmc->soc->needs_mbist_war)
  332. err = tegra210_clk_handle_mbist_war(pg->id);
  333. if (err)
  334. goto disable_clks;
  335. if (disable_clocks)
  336. tegra_powergate_disable_clocks(pg);
  337. return 0;
  338. disable_clks:
  339. tegra_powergate_disable_clocks(pg);
  340. usleep_range(10, 20);
  341. powergate_off:
  342. tegra_powergate_set(pg->id, false);
  343. return err;
  344. }
  345. static int tegra_powergate_power_down(struct tegra_powergate *pg)
  346. {
  347. int err;
  348. err = tegra_powergate_enable_clocks(pg);
  349. if (err)
  350. return err;
  351. usleep_range(10, 20);
  352. err = reset_control_assert(pg->reset);
  353. if (err)
  354. goto disable_clks;
  355. usleep_range(10, 20);
  356. tegra_powergate_disable_clocks(pg);
  357. usleep_range(10, 20);
  358. err = tegra_powergate_set(pg->id, false);
  359. if (err)
  360. goto assert_resets;
  361. return 0;
  362. assert_resets:
  363. tegra_powergate_enable_clocks(pg);
  364. usleep_range(10, 20);
  365. reset_control_deassert(pg->reset);
  366. usleep_range(10, 20);
  367. disable_clks:
  368. tegra_powergate_disable_clocks(pg);
  369. return err;
  370. }
  371. static int tegra_genpd_power_on(struct generic_pm_domain *domain)
  372. {
  373. struct tegra_powergate *pg = to_powergate(domain);
  374. int err;
  375. err = tegra_powergate_power_up(pg, true);
  376. if (err)
  377. pr_err("failed to turn on PM domain %s: %d\n", pg->genpd.name,
  378. err);
  379. return err;
  380. }
  381. static int tegra_genpd_power_off(struct generic_pm_domain *domain)
  382. {
  383. struct tegra_powergate *pg = to_powergate(domain);
  384. int err;
  385. err = tegra_powergate_power_down(pg);
  386. if (err)
  387. pr_err("failed to turn off PM domain %s: %d\n",
  388. pg->genpd.name, err);
  389. return err;
  390. }
  391. /**
  392. * tegra_powergate_power_on() - power on partition
  393. * @id: partition ID
  394. */
  395. int tegra_powergate_power_on(unsigned int id)
  396. {
  397. if (!tegra_powergate_is_available(id))
  398. return -EINVAL;
  399. return tegra_powergate_set(id, true);
  400. }
  401. /**
  402. * tegra_powergate_power_off() - power off partition
  403. * @id: partition ID
  404. */
  405. int tegra_powergate_power_off(unsigned int id)
  406. {
  407. if (!tegra_powergate_is_available(id))
  408. return -EINVAL;
  409. return tegra_powergate_set(id, false);
  410. }
  411. EXPORT_SYMBOL(tegra_powergate_power_off);
  412. /**
  413. * tegra_powergate_is_powered() - check if partition is powered
  414. * @id: partition ID
  415. */
  416. int tegra_powergate_is_powered(unsigned int id)
  417. {
  418. int status;
  419. if (!tegra_powergate_is_valid(id))
  420. return -EINVAL;
  421. mutex_lock(&pmc->powergates_lock);
  422. status = tegra_powergate_state(id);
  423. mutex_unlock(&pmc->powergates_lock);
  424. return status;
  425. }
  426. /**
  427. * tegra_powergate_remove_clamping() - remove power clamps for partition
  428. * @id: partition ID
  429. */
  430. int tegra_powergate_remove_clamping(unsigned int id)
  431. {
  432. if (!tegra_powergate_is_available(id))
  433. return -EINVAL;
  434. return __tegra_powergate_remove_clamping(id);
  435. }
  436. EXPORT_SYMBOL(tegra_powergate_remove_clamping);
  437. /**
  438. * tegra_powergate_sequence_power_up() - power up partition
  439. * @id: partition ID
  440. * @clk: clock for partition
  441. * @rst: reset for partition
  442. *
  443. * Must be called with clk disabled, and returns with clk enabled.
  444. */
  445. int tegra_powergate_sequence_power_up(unsigned int id, struct clk *clk,
  446. struct reset_control *rst)
  447. {
  448. struct tegra_powergate pg;
  449. int err;
  450. if (!tegra_powergate_is_available(id))
  451. return -EINVAL;
  452. pg.id = id;
  453. pg.clks = &clk;
  454. pg.num_clks = 1;
  455. pg.reset = rst;
  456. pg.pmc = pmc;
  457. err = tegra_powergate_power_up(&pg, false);
  458. if (err)
  459. pr_err("failed to turn on partition %d: %d\n", id, err);
  460. return err;
  461. }
  462. EXPORT_SYMBOL(tegra_powergate_sequence_power_up);
  463. #ifdef CONFIG_SMP
  464. /**
  465. * tegra_get_cpu_powergate_id() - convert from CPU ID to partition ID
  466. * @cpuid: CPU partition ID
  467. *
  468. * Returns the partition ID corresponding to the CPU partition ID or a
  469. * negative error code on failure.
  470. */
  471. static int tegra_get_cpu_powergate_id(unsigned int cpuid)
  472. {
  473. if (pmc->soc && cpuid < pmc->soc->num_cpu_powergates)
  474. return pmc->soc->cpu_powergates[cpuid];
  475. return -EINVAL;
  476. }
  477. /**
  478. * tegra_pmc_cpu_is_powered() - check if CPU partition is powered
  479. * @cpuid: CPU partition ID
  480. */
  481. bool tegra_pmc_cpu_is_powered(unsigned int cpuid)
  482. {
  483. int id;
  484. id = tegra_get_cpu_powergate_id(cpuid);
  485. if (id < 0)
  486. return false;
  487. return tegra_powergate_is_powered(id);
  488. }
  489. /**
  490. * tegra_pmc_cpu_power_on() - power on CPU partition
  491. * @cpuid: CPU partition ID
  492. */
  493. int tegra_pmc_cpu_power_on(unsigned int cpuid)
  494. {
  495. int id;
  496. id = tegra_get_cpu_powergate_id(cpuid);
  497. if (id < 0)
  498. return id;
  499. return tegra_powergate_set(id, true);
  500. }
  501. /**
  502. * tegra_pmc_cpu_remove_clamping() - remove power clamps for CPU partition
  503. * @cpuid: CPU partition ID
  504. */
  505. int tegra_pmc_cpu_remove_clamping(unsigned int cpuid)
  506. {
  507. int id;
  508. id = tegra_get_cpu_powergate_id(cpuid);
  509. if (id < 0)
  510. return id;
  511. return tegra_powergate_remove_clamping(id);
  512. }
  513. #endif /* CONFIG_SMP */
  514. static int tegra_pmc_restart_notify(struct notifier_block *this,
  515. unsigned long action, void *data)
  516. {
  517. const char *cmd = data;
  518. u32 value;
  519. value = readl(pmc->scratch + pmc->soc->regs->scratch0);
  520. value &= ~PMC_SCRATCH0_MODE_MASK;
  521. if (cmd) {
  522. if (strcmp(cmd, "recovery") == 0)
  523. value |= PMC_SCRATCH0_MODE_RECOVERY;
  524. if (strcmp(cmd, "bootloader") == 0)
  525. value |= PMC_SCRATCH0_MODE_BOOTLOADER;
  526. if (strcmp(cmd, "forced-recovery") == 0)
  527. value |= PMC_SCRATCH0_MODE_RCM;
  528. }
  529. writel(value, pmc->scratch + pmc->soc->regs->scratch0);
  530. /* reset everything but PMC_SCRATCH0 and PMC_RST_STATUS */
  531. value = tegra_pmc_readl(PMC_CNTRL);
  532. value |= PMC_CNTRL_MAIN_RST;
  533. tegra_pmc_writel(value, PMC_CNTRL);
  534. return NOTIFY_DONE;
  535. }
  536. static struct notifier_block tegra_pmc_restart_handler = {
  537. .notifier_call = tegra_pmc_restart_notify,
  538. .priority = 128,
  539. };
  540. static int powergate_show(struct seq_file *s, void *data)
  541. {
  542. unsigned int i;
  543. int status;
  544. seq_printf(s, " powergate powered\n");
  545. seq_printf(s, "------------------\n");
  546. for (i = 0; i < pmc->soc->num_powergates; i++) {
  547. status = tegra_powergate_is_powered(i);
  548. if (status < 0)
  549. continue;
  550. seq_printf(s, " %9s %7s\n", pmc->soc->powergates[i],
  551. status ? "yes" : "no");
  552. }
  553. return 0;
  554. }
  555. static int powergate_open(struct inode *inode, struct file *file)
  556. {
  557. return single_open(file, powergate_show, inode->i_private);
  558. }
  559. static const struct file_operations powergate_fops = {
  560. .open = powergate_open,
  561. .read = seq_read,
  562. .llseek = seq_lseek,
  563. .release = single_release,
  564. };
  565. static int tegra_powergate_debugfs_init(void)
  566. {
  567. pmc->debugfs = debugfs_create_file("powergate", S_IRUGO, NULL, NULL,
  568. &powergate_fops);
  569. if (!pmc->debugfs)
  570. return -ENOMEM;
  571. return 0;
  572. }
  573. static int tegra_powergate_of_get_clks(struct tegra_powergate *pg,
  574. struct device_node *np)
  575. {
  576. struct clk *clk;
  577. unsigned int i, count;
  578. int err;
  579. count = of_count_phandle_with_args(np, "clocks", "#clock-cells");
  580. if (count == 0)
  581. return -ENODEV;
  582. pg->clks = kcalloc(count, sizeof(clk), GFP_KERNEL);
  583. if (!pg->clks)
  584. return -ENOMEM;
  585. for (i = 0; i < count; i++) {
  586. pg->clks[i] = of_clk_get(np, i);
  587. if (IS_ERR(pg->clks[i])) {
  588. err = PTR_ERR(pg->clks[i]);
  589. goto err;
  590. }
  591. }
  592. pg->num_clks = count;
  593. return 0;
  594. err:
  595. while (i--)
  596. clk_put(pg->clks[i]);
  597. kfree(pg->clks);
  598. return err;
  599. }
  600. static int tegra_powergate_of_get_resets(struct tegra_powergate *pg,
  601. struct device_node *np, bool off)
  602. {
  603. int err;
  604. pg->reset = of_reset_control_array_get_exclusive(np);
  605. if (IS_ERR(pg->reset)) {
  606. err = PTR_ERR(pg->reset);
  607. pr_err("failed to get device resets: %d\n", err);
  608. return err;
  609. }
  610. if (off)
  611. err = reset_control_assert(pg->reset);
  612. else
  613. err = reset_control_deassert(pg->reset);
  614. if (err)
  615. reset_control_put(pg->reset);
  616. return err;
  617. }
  618. static void tegra_powergate_add(struct tegra_pmc *pmc, struct device_node *np)
  619. {
  620. struct tegra_powergate *pg;
  621. int id, err;
  622. bool off;
  623. pg = kzalloc(sizeof(*pg), GFP_KERNEL);
  624. if (!pg)
  625. return;
  626. id = tegra_powergate_lookup(pmc, np->name);
  627. if (id < 0) {
  628. pr_err("powergate lookup failed for %s: %d\n", np->name, id);
  629. goto free_mem;
  630. }
  631. /*
  632. * Clear the bit for this powergate so it cannot be managed
  633. * directly via the legacy APIs for controlling powergates.
  634. */
  635. clear_bit(id, pmc->powergates_available);
  636. pg->id = id;
  637. pg->genpd.name = np->name;
  638. pg->genpd.power_off = tegra_genpd_power_off;
  639. pg->genpd.power_on = tegra_genpd_power_on;
  640. pg->pmc = pmc;
  641. off = !tegra_powergate_is_powered(pg->id);
  642. err = tegra_powergate_of_get_clks(pg, np);
  643. if (err < 0) {
  644. pr_err("failed to get clocks for %s: %d\n", np->name, err);
  645. goto set_available;
  646. }
  647. err = tegra_powergate_of_get_resets(pg, np, off);
  648. if (err < 0) {
  649. pr_err("failed to get resets for %s: %d\n", np->name, err);
  650. goto remove_clks;
  651. }
  652. if (!IS_ENABLED(CONFIG_PM_GENERIC_DOMAINS)) {
  653. if (off)
  654. WARN_ON(tegra_powergate_power_up(pg, true));
  655. goto remove_resets;
  656. }
  657. /*
  658. * FIXME: If XHCI is enabled for Tegra, then power-up the XUSB
  659. * host and super-speed partitions. Once the XHCI driver
  660. * manages the partitions itself this code can be removed. Note
  661. * that we don't register these partitions with the genpd core
  662. * to avoid it from powering down the partitions as they appear
  663. * to be unused.
  664. */
  665. if (IS_ENABLED(CONFIG_USB_XHCI_TEGRA) &&
  666. (id == TEGRA_POWERGATE_XUSBA || id == TEGRA_POWERGATE_XUSBC)) {
  667. if (off)
  668. WARN_ON(tegra_powergate_power_up(pg, true));
  669. goto remove_resets;
  670. }
  671. err = pm_genpd_init(&pg->genpd, NULL, off);
  672. if (err < 0) {
  673. pr_err("failed to initialise PM domain %s: %d\n", np->name,
  674. err);
  675. goto remove_resets;
  676. }
  677. err = of_genpd_add_provider_simple(np, &pg->genpd);
  678. if (err < 0) {
  679. pr_err("failed to add PM domain provider for %s: %d\n",
  680. np->name, err);
  681. goto remove_genpd;
  682. }
  683. pr_debug("added PM domain %s\n", pg->genpd.name);
  684. return;
  685. remove_genpd:
  686. pm_genpd_remove(&pg->genpd);
  687. remove_resets:
  688. reset_control_put(pg->reset);
  689. remove_clks:
  690. while (pg->num_clks--)
  691. clk_put(pg->clks[pg->num_clks]);
  692. kfree(pg->clks);
  693. set_available:
  694. set_bit(id, pmc->powergates_available);
  695. free_mem:
  696. kfree(pg);
  697. }
  698. static void tegra_powergate_init(struct tegra_pmc *pmc,
  699. struct device_node *parent)
  700. {
  701. struct device_node *np, *child;
  702. unsigned int i;
  703. /* Create a bitmap of the available and valid partitions */
  704. for (i = 0; i < pmc->soc->num_powergates; i++)
  705. if (pmc->soc->powergates[i])
  706. set_bit(i, pmc->powergates_available);
  707. np = of_get_child_by_name(parent, "powergates");
  708. if (!np)
  709. return;
  710. for_each_child_of_node(np, child)
  711. tegra_powergate_add(pmc, child);
  712. of_node_put(np);
  713. }
  714. static const struct tegra_io_pad_soc *
  715. tegra_io_pad_find(struct tegra_pmc *pmc, enum tegra_io_pad id)
  716. {
  717. unsigned int i;
  718. for (i = 0; i < pmc->soc->num_io_pads; i++)
  719. if (pmc->soc->io_pads[i].id == id)
  720. return &pmc->soc->io_pads[i];
  721. return NULL;
  722. }
  723. static int tegra_io_pad_prepare(enum tegra_io_pad id, unsigned long *request,
  724. unsigned long *status, u32 *mask)
  725. {
  726. const struct tegra_io_pad_soc *pad;
  727. unsigned long rate, value;
  728. pad = tegra_io_pad_find(pmc, id);
  729. if (!pad) {
  730. pr_err("invalid I/O pad ID %u\n", id);
  731. return -ENOENT;
  732. }
  733. if (pad->dpd == UINT_MAX)
  734. return -ENOTSUPP;
  735. *mask = BIT(pad->dpd % 32);
  736. if (pad->dpd < 32) {
  737. *status = pmc->soc->regs->dpd_status;
  738. *request = pmc->soc->regs->dpd_req;
  739. } else {
  740. *status = pmc->soc->regs->dpd2_status;
  741. *request = pmc->soc->regs->dpd2_req;
  742. }
  743. if (pmc->clk) {
  744. rate = clk_get_rate(pmc->clk);
  745. if (!rate) {
  746. pr_err("failed to get clock rate\n");
  747. return -ENODEV;
  748. }
  749. tegra_pmc_writel(DPD_SAMPLE_ENABLE, DPD_SAMPLE);
  750. /* must be at least 200 ns, in APB (PCLK) clock cycles */
  751. value = DIV_ROUND_UP(1000000000, rate);
  752. value = DIV_ROUND_UP(200, value);
  753. tegra_pmc_writel(value, SEL_DPD_TIM);
  754. }
  755. return 0;
  756. }
  757. static int tegra_io_pad_poll(unsigned long offset, u32 mask,
  758. u32 val, unsigned long timeout)
  759. {
  760. u32 value;
  761. timeout = jiffies + msecs_to_jiffies(timeout);
  762. while (time_after(timeout, jiffies)) {
  763. value = tegra_pmc_readl(offset);
  764. if ((value & mask) == val)
  765. return 0;
  766. usleep_range(250, 1000);
  767. }
  768. return -ETIMEDOUT;
  769. }
  770. static void tegra_io_pad_unprepare(void)
  771. {
  772. if (pmc->clk)
  773. tegra_pmc_writel(DPD_SAMPLE_DISABLE, DPD_SAMPLE);
  774. }
  775. /**
  776. * tegra_io_pad_power_enable() - enable power to I/O pad
  777. * @id: Tegra I/O pad ID for which to enable power
  778. *
  779. * Returns: 0 on success or a negative error code on failure.
  780. */
  781. int tegra_io_pad_power_enable(enum tegra_io_pad id)
  782. {
  783. unsigned long request, status;
  784. u32 mask;
  785. int err;
  786. mutex_lock(&pmc->powergates_lock);
  787. err = tegra_io_pad_prepare(id, &request, &status, &mask);
  788. if (err < 0) {
  789. pr_err("failed to prepare I/O pad: %d\n", err);
  790. goto unlock;
  791. }
  792. tegra_pmc_writel(IO_DPD_REQ_CODE_OFF | mask, request);
  793. err = tegra_io_pad_poll(status, mask, 0, 250);
  794. if (err < 0) {
  795. pr_err("failed to enable I/O pad: %d\n", err);
  796. goto unlock;
  797. }
  798. tegra_io_pad_unprepare();
  799. unlock:
  800. mutex_unlock(&pmc->powergates_lock);
  801. return err;
  802. }
  803. EXPORT_SYMBOL(tegra_io_pad_power_enable);
  804. /**
  805. * tegra_io_pad_power_disable() - disable power to I/O pad
  806. * @id: Tegra I/O pad ID for which to disable power
  807. *
  808. * Returns: 0 on success or a negative error code on failure.
  809. */
  810. int tegra_io_pad_power_disable(enum tegra_io_pad id)
  811. {
  812. unsigned long request, status;
  813. u32 mask;
  814. int err;
  815. mutex_lock(&pmc->powergates_lock);
  816. err = tegra_io_pad_prepare(id, &request, &status, &mask);
  817. if (err < 0) {
  818. pr_err("failed to prepare I/O pad: %d\n", err);
  819. goto unlock;
  820. }
  821. tegra_pmc_writel(IO_DPD_REQ_CODE_ON | mask, request);
  822. err = tegra_io_pad_poll(status, mask, mask, 250);
  823. if (err < 0) {
  824. pr_err("failed to disable I/O pad: %d\n", err);
  825. goto unlock;
  826. }
  827. tegra_io_pad_unprepare();
  828. unlock:
  829. mutex_unlock(&pmc->powergates_lock);
  830. return err;
  831. }
  832. EXPORT_SYMBOL(tegra_io_pad_power_disable);
  833. int tegra_io_pad_set_voltage(enum tegra_io_pad id,
  834. enum tegra_io_pad_voltage voltage)
  835. {
  836. const struct tegra_io_pad_soc *pad;
  837. u32 value;
  838. pad = tegra_io_pad_find(pmc, id);
  839. if (!pad)
  840. return -ENOENT;
  841. if (pad->voltage == UINT_MAX)
  842. return -ENOTSUPP;
  843. mutex_lock(&pmc->powergates_lock);
  844. /* write-enable PMC_PWR_DET_VALUE[pad->voltage] */
  845. value = tegra_pmc_readl(PMC_PWR_DET);
  846. value |= BIT(pad->voltage);
  847. tegra_pmc_writel(value, PMC_PWR_DET);
  848. /* update I/O voltage */
  849. value = tegra_pmc_readl(PMC_PWR_DET_VALUE);
  850. if (voltage == TEGRA_IO_PAD_1800000UV)
  851. value &= ~BIT(pad->voltage);
  852. else
  853. value |= BIT(pad->voltage);
  854. tegra_pmc_writel(value, PMC_PWR_DET_VALUE);
  855. mutex_unlock(&pmc->powergates_lock);
  856. usleep_range(100, 250);
  857. return 0;
  858. }
  859. EXPORT_SYMBOL(tegra_io_pad_set_voltage);
  860. int tegra_io_pad_get_voltage(enum tegra_io_pad id)
  861. {
  862. const struct tegra_io_pad_soc *pad;
  863. u32 value;
  864. pad = tegra_io_pad_find(pmc, id);
  865. if (!pad)
  866. return -ENOENT;
  867. if (pad->voltage == UINT_MAX)
  868. return -ENOTSUPP;
  869. value = tegra_pmc_readl(PMC_PWR_DET_VALUE);
  870. if ((value & BIT(pad->voltage)) == 0)
  871. return TEGRA_IO_PAD_1800000UV;
  872. return TEGRA_IO_PAD_3300000UV;
  873. }
  874. EXPORT_SYMBOL(tegra_io_pad_get_voltage);
  875. /**
  876. * tegra_io_rail_power_on() - enable power to I/O rail
  877. * @id: Tegra I/O pad ID for which to enable power
  878. *
  879. * See also: tegra_io_pad_power_enable()
  880. */
  881. int tegra_io_rail_power_on(unsigned int id)
  882. {
  883. return tegra_io_pad_power_enable(id);
  884. }
  885. EXPORT_SYMBOL(tegra_io_rail_power_on);
  886. /**
  887. * tegra_io_rail_power_off() - disable power to I/O rail
  888. * @id: Tegra I/O pad ID for which to disable power
  889. *
  890. * See also: tegra_io_pad_power_disable()
  891. */
  892. int tegra_io_rail_power_off(unsigned int id)
  893. {
  894. return tegra_io_pad_power_disable(id);
  895. }
  896. EXPORT_SYMBOL(tegra_io_rail_power_off);
  897. #ifdef CONFIG_PM_SLEEP
  898. enum tegra_suspend_mode tegra_pmc_get_suspend_mode(void)
  899. {
  900. return pmc->suspend_mode;
  901. }
  902. void tegra_pmc_set_suspend_mode(enum tegra_suspend_mode mode)
  903. {
  904. if (mode < TEGRA_SUSPEND_NONE || mode >= TEGRA_MAX_SUSPEND_MODE)
  905. return;
  906. pmc->suspend_mode = mode;
  907. }
  908. void tegra_pmc_enter_suspend_mode(enum tegra_suspend_mode mode)
  909. {
  910. unsigned long long rate = 0;
  911. u32 value;
  912. switch (mode) {
  913. case TEGRA_SUSPEND_LP1:
  914. rate = 32768;
  915. break;
  916. case TEGRA_SUSPEND_LP2:
  917. rate = clk_get_rate(pmc->clk);
  918. break;
  919. default:
  920. break;
  921. }
  922. if (WARN_ON_ONCE(rate == 0))
  923. rate = 100000000;
  924. if (rate != pmc->rate) {
  925. u64 ticks;
  926. ticks = pmc->cpu_good_time * rate + USEC_PER_SEC - 1;
  927. do_div(ticks, USEC_PER_SEC);
  928. tegra_pmc_writel(ticks, PMC_CPUPWRGOOD_TIMER);
  929. ticks = pmc->cpu_off_time * rate + USEC_PER_SEC - 1;
  930. do_div(ticks, USEC_PER_SEC);
  931. tegra_pmc_writel(ticks, PMC_CPUPWROFF_TIMER);
  932. wmb();
  933. pmc->rate = rate;
  934. }
  935. value = tegra_pmc_readl(PMC_CNTRL);
  936. value &= ~PMC_CNTRL_SIDE_EFFECT_LP0;
  937. value |= PMC_CNTRL_CPU_PWRREQ_OE;
  938. tegra_pmc_writel(value, PMC_CNTRL);
  939. }
  940. #endif
  941. static int tegra_pmc_parse_dt(struct tegra_pmc *pmc, struct device_node *np)
  942. {
  943. u32 value, values[2];
  944. if (of_property_read_u32(np, "nvidia,suspend-mode", &value)) {
  945. } else {
  946. switch (value) {
  947. case 0:
  948. pmc->suspend_mode = TEGRA_SUSPEND_LP0;
  949. break;
  950. case 1:
  951. pmc->suspend_mode = TEGRA_SUSPEND_LP1;
  952. break;
  953. case 2:
  954. pmc->suspend_mode = TEGRA_SUSPEND_LP2;
  955. break;
  956. default:
  957. pmc->suspend_mode = TEGRA_SUSPEND_NONE;
  958. break;
  959. }
  960. }
  961. pmc->suspend_mode = tegra_pm_validate_suspend_mode(pmc->suspend_mode);
  962. if (of_property_read_u32(np, "nvidia,cpu-pwr-good-time", &value))
  963. pmc->suspend_mode = TEGRA_SUSPEND_NONE;
  964. pmc->cpu_good_time = value;
  965. if (of_property_read_u32(np, "nvidia,cpu-pwr-off-time", &value))
  966. pmc->suspend_mode = TEGRA_SUSPEND_NONE;
  967. pmc->cpu_off_time = value;
  968. if (of_property_read_u32_array(np, "nvidia,core-pwr-good-time",
  969. values, ARRAY_SIZE(values)))
  970. pmc->suspend_mode = TEGRA_SUSPEND_NONE;
  971. pmc->core_osc_time = values[0];
  972. pmc->core_pmu_time = values[1];
  973. if (of_property_read_u32(np, "nvidia,core-pwr-off-time", &value))
  974. pmc->suspend_mode = TEGRA_SUSPEND_NONE;
  975. pmc->core_off_time = value;
  976. pmc->corereq_high = of_property_read_bool(np,
  977. "nvidia,core-power-req-active-high");
  978. pmc->sysclkreq_high = of_property_read_bool(np,
  979. "nvidia,sys-clock-req-active-high");
  980. pmc->combined_req = of_property_read_bool(np,
  981. "nvidia,combined-power-req");
  982. pmc->cpu_pwr_good_en = of_property_read_bool(np,
  983. "nvidia,cpu-pwr-good-en");
  984. if (of_property_read_u32_array(np, "nvidia,lp0-vec", values,
  985. ARRAY_SIZE(values)))
  986. if (pmc->suspend_mode == TEGRA_SUSPEND_LP0)
  987. pmc->suspend_mode = TEGRA_SUSPEND_LP1;
  988. pmc->lp0_vec_phys = values[0];
  989. pmc->lp0_vec_size = values[1];
  990. return 0;
  991. }
  992. static void tegra_pmc_init(struct tegra_pmc *pmc)
  993. {
  994. if (pmc->soc->init)
  995. pmc->soc->init(pmc);
  996. }
  997. static void tegra_pmc_init_tsense_reset(struct tegra_pmc *pmc)
  998. {
  999. static const char disabled[] = "emergency thermal reset disabled";
  1000. u32 pmu_addr, ctrl_id, reg_addr, reg_data, pinmux;
  1001. struct device *dev = pmc->dev;
  1002. struct device_node *np;
  1003. u32 value, checksum;
  1004. if (!pmc->soc->has_tsense_reset)
  1005. return;
  1006. np = of_find_node_by_name(pmc->dev->of_node, "i2c-thermtrip");
  1007. if (!np) {
  1008. dev_warn(dev, "i2c-thermtrip node not found, %s.\n", disabled);
  1009. return;
  1010. }
  1011. if (of_property_read_u32(np, "nvidia,i2c-controller-id", &ctrl_id)) {
  1012. dev_err(dev, "I2C controller ID missing, %s.\n", disabled);
  1013. goto out;
  1014. }
  1015. if (of_property_read_u32(np, "nvidia,bus-addr", &pmu_addr)) {
  1016. dev_err(dev, "nvidia,bus-addr missing, %s.\n", disabled);
  1017. goto out;
  1018. }
  1019. if (of_property_read_u32(np, "nvidia,reg-addr", &reg_addr)) {
  1020. dev_err(dev, "nvidia,reg-addr missing, %s.\n", disabled);
  1021. goto out;
  1022. }
  1023. if (of_property_read_u32(np, "nvidia,reg-data", &reg_data)) {
  1024. dev_err(dev, "nvidia,reg-data missing, %s.\n", disabled);
  1025. goto out;
  1026. }
  1027. if (of_property_read_u32(np, "nvidia,pinmux-id", &pinmux))
  1028. pinmux = 0;
  1029. value = tegra_pmc_readl(PMC_SENSOR_CTRL);
  1030. value |= PMC_SENSOR_CTRL_SCRATCH_WRITE;
  1031. tegra_pmc_writel(value, PMC_SENSOR_CTRL);
  1032. value = (reg_data << PMC_SCRATCH54_DATA_SHIFT) |
  1033. (reg_addr << PMC_SCRATCH54_ADDR_SHIFT);
  1034. tegra_pmc_writel(value, PMC_SCRATCH54);
  1035. value = PMC_SCRATCH55_RESET_TEGRA;
  1036. value |= ctrl_id << PMC_SCRATCH55_CNTRL_ID_SHIFT;
  1037. value |= pinmux << PMC_SCRATCH55_PINMUX_SHIFT;
  1038. value |= pmu_addr << PMC_SCRATCH55_I2CSLV1_SHIFT;
  1039. /*
  1040. * Calculate checksum of SCRATCH54, SCRATCH55 fields. Bits 23:16 will
  1041. * contain the checksum and are currently zero, so they are not added.
  1042. */
  1043. checksum = reg_addr + reg_data + (value & 0xff) + ((value >> 8) & 0xff)
  1044. + ((value >> 24) & 0xff);
  1045. checksum &= 0xff;
  1046. checksum = 0x100 - checksum;
  1047. value |= checksum << PMC_SCRATCH55_CHECKSUM_SHIFT;
  1048. tegra_pmc_writel(value, PMC_SCRATCH55);
  1049. value = tegra_pmc_readl(PMC_SENSOR_CTRL);
  1050. value |= PMC_SENSOR_CTRL_ENABLE_RST;
  1051. tegra_pmc_writel(value, PMC_SENSOR_CTRL);
  1052. dev_info(pmc->dev, "emergency thermal reset enabled\n");
  1053. out:
  1054. of_node_put(np);
  1055. }
  1056. static int tegra_pmc_probe(struct platform_device *pdev)
  1057. {
  1058. void __iomem *base;
  1059. struct resource *res;
  1060. int err;
  1061. /*
  1062. * Early initialisation should have configured an initial
  1063. * register mapping and setup the soc data pointer. If these
  1064. * are not valid then something went badly wrong!
  1065. */
  1066. if (WARN_ON(!pmc->base || !pmc->soc))
  1067. return -ENODEV;
  1068. err = tegra_pmc_parse_dt(pmc, pdev->dev.of_node);
  1069. if (err < 0)
  1070. return err;
  1071. /* take over the memory region from the early initialization */
  1072. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1073. base = devm_ioremap_resource(&pdev->dev, res);
  1074. if (IS_ERR(base))
  1075. return PTR_ERR(base);
  1076. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "wake");
  1077. if (res) {
  1078. pmc->wake = devm_ioremap_resource(&pdev->dev, res);
  1079. if (IS_ERR(pmc->wake))
  1080. return PTR_ERR(pmc->wake);
  1081. } else {
  1082. pmc->wake = base;
  1083. }
  1084. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "aotag");
  1085. if (res) {
  1086. pmc->aotag = devm_ioremap_resource(&pdev->dev, res);
  1087. if (IS_ERR(pmc->aotag))
  1088. return PTR_ERR(pmc->aotag);
  1089. } else {
  1090. pmc->aotag = base;
  1091. }
  1092. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "scratch");
  1093. if (res) {
  1094. pmc->scratch = devm_ioremap_resource(&pdev->dev, res);
  1095. if (IS_ERR(pmc->scratch))
  1096. return PTR_ERR(pmc->scratch);
  1097. } else {
  1098. pmc->scratch = base;
  1099. }
  1100. pmc->clk = devm_clk_get(&pdev->dev, "pclk");
  1101. if (IS_ERR(pmc->clk)) {
  1102. err = PTR_ERR(pmc->clk);
  1103. if (err != -ENOENT) {
  1104. dev_err(&pdev->dev, "failed to get pclk: %d\n", err);
  1105. return err;
  1106. }
  1107. pmc->clk = NULL;
  1108. }
  1109. pmc->dev = &pdev->dev;
  1110. tegra_pmc_init(pmc);
  1111. tegra_pmc_init_tsense_reset(pmc);
  1112. if (IS_ENABLED(CONFIG_DEBUG_FS)) {
  1113. err = tegra_powergate_debugfs_init();
  1114. if (err < 0)
  1115. return err;
  1116. }
  1117. err = register_restart_handler(&tegra_pmc_restart_handler);
  1118. if (err) {
  1119. debugfs_remove(pmc->debugfs);
  1120. dev_err(&pdev->dev, "unable to register restart handler, %d\n",
  1121. err);
  1122. return err;
  1123. }
  1124. mutex_lock(&pmc->powergates_lock);
  1125. iounmap(pmc->base);
  1126. pmc->base = base;
  1127. mutex_unlock(&pmc->powergates_lock);
  1128. return 0;
  1129. }
  1130. #if defined(CONFIG_PM_SLEEP) && defined(CONFIG_ARM)
  1131. static int tegra_pmc_suspend(struct device *dev)
  1132. {
  1133. tegra_pmc_writel(virt_to_phys(tegra_resume), PMC_SCRATCH41);
  1134. return 0;
  1135. }
  1136. static int tegra_pmc_resume(struct device *dev)
  1137. {
  1138. tegra_pmc_writel(0x0, PMC_SCRATCH41);
  1139. return 0;
  1140. }
  1141. static SIMPLE_DEV_PM_OPS(tegra_pmc_pm_ops, tegra_pmc_suspend, tegra_pmc_resume);
  1142. #endif
  1143. static const char * const tegra20_powergates[] = {
  1144. [TEGRA_POWERGATE_CPU] = "cpu",
  1145. [TEGRA_POWERGATE_3D] = "3d",
  1146. [TEGRA_POWERGATE_VENC] = "venc",
  1147. [TEGRA_POWERGATE_VDEC] = "vdec",
  1148. [TEGRA_POWERGATE_PCIE] = "pcie",
  1149. [TEGRA_POWERGATE_L2] = "l2",
  1150. [TEGRA_POWERGATE_MPE] = "mpe",
  1151. };
  1152. static const struct tegra_pmc_regs tegra20_pmc_regs = {
  1153. .scratch0 = 0x50,
  1154. .dpd_req = 0x1b8,
  1155. .dpd_status = 0x1bc,
  1156. .dpd2_req = 0x1c0,
  1157. .dpd2_status = 0x1c4,
  1158. };
  1159. static void tegra20_pmc_init(struct tegra_pmc *pmc)
  1160. {
  1161. u32 value;
  1162. /* Always enable CPU power request */
  1163. value = tegra_pmc_readl(PMC_CNTRL);
  1164. value |= PMC_CNTRL_CPU_PWRREQ_OE;
  1165. tegra_pmc_writel(value, PMC_CNTRL);
  1166. value = tegra_pmc_readl(PMC_CNTRL);
  1167. if (pmc->sysclkreq_high)
  1168. value &= ~PMC_CNTRL_SYSCLK_POLARITY;
  1169. else
  1170. value |= PMC_CNTRL_SYSCLK_POLARITY;
  1171. /* configure the output polarity while the request is tristated */
  1172. tegra_pmc_writel(value, PMC_CNTRL);
  1173. /* now enable the request */
  1174. value = tegra_pmc_readl(PMC_CNTRL);
  1175. value |= PMC_CNTRL_SYSCLK_OE;
  1176. tegra_pmc_writel(value, PMC_CNTRL);
  1177. }
  1178. static void tegra20_pmc_setup_irq_polarity(struct tegra_pmc *pmc,
  1179. struct device_node *np,
  1180. bool invert)
  1181. {
  1182. u32 value;
  1183. value = tegra_pmc_readl(PMC_CNTRL);
  1184. if (invert)
  1185. value |= PMC_CNTRL_INTR_POLARITY;
  1186. else
  1187. value &= ~PMC_CNTRL_INTR_POLARITY;
  1188. tegra_pmc_writel(value, PMC_CNTRL);
  1189. }
  1190. static const struct tegra_pmc_soc tegra20_pmc_soc = {
  1191. .num_powergates = ARRAY_SIZE(tegra20_powergates),
  1192. .powergates = tegra20_powergates,
  1193. .num_cpu_powergates = 0,
  1194. .cpu_powergates = NULL,
  1195. .has_tsense_reset = false,
  1196. .has_gpu_clamps = false,
  1197. .num_io_pads = 0,
  1198. .io_pads = NULL,
  1199. .regs = &tegra20_pmc_regs,
  1200. .init = tegra20_pmc_init,
  1201. .setup_irq_polarity = tegra20_pmc_setup_irq_polarity,
  1202. };
  1203. static const char * const tegra30_powergates[] = {
  1204. [TEGRA_POWERGATE_CPU] = "cpu0",
  1205. [TEGRA_POWERGATE_3D] = "3d0",
  1206. [TEGRA_POWERGATE_VENC] = "venc",
  1207. [TEGRA_POWERGATE_VDEC] = "vdec",
  1208. [TEGRA_POWERGATE_PCIE] = "pcie",
  1209. [TEGRA_POWERGATE_L2] = "l2",
  1210. [TEGRA_POWERGATE_MPE] = "mpe",
  1211. [TEGRA_POWERGATE_HEG] = "heg",
  1212. [TEGRA_POWERGATE_SATA] = "sata",
  1213. [TEGRA_POWERGATE_CPU1] = "cpu1",
  1214. [TEGRA_POWERGATE_CPU2] = "cpu2",
  1215. [TEGRA_POWERGATE_CPU3] = "cpu3",
  1216. [TEGRA_POWERGATE_CELP] = "celp",
  1217. [TEGRA_POWERGATE_3D1] = "3d1",
  1218. };
  1219. static const u8 tegra30_cpu_powergates[] = {
  1220. TEGRA_POWERGATE_CPU,
  1221. TEGRA_POWERGATE_CPU1,
  1222. TEGRA_POWERGATE_CPU2,
  1223. TEGRA_POWERGATE_CPU3,
  1224. };
  1225. static const struct tegra_pmc_soc tegra30_pmc_soc = {
  1226. .num_powergates = ARRAY_SIZE(tegra30_powergates),
  1227. .powergates = tegra30_powergates,
  1228. .num_cpu_powergates = ARRAY_SIZE(tegra30_cpu_powergates),
  1229. .cpu_powergates = tegra30_cpu_powergates,
  1230. .has_tsense_reset = true,
  1231. .has_gpu_clamps = false,
  1232. .num_io_pads = 0,
  1233. .io_pads = NULL,
  1234. .regs = &tegra20_pmc_regs,
  1235. .init = tegra20_pmc_init,
  1236. .setup_irq_polarity = tegra20_pmc_setup_irq_polarity,
  1237. };
  1238. static const char * const tegra114_powergates[] = {
  1239. [TEGRA_POWERGATE_CPU] = "crail",
  1240. [TEGRA_POWERGATE_3D] = "3d",
  1241. [TEGRA_POWERGATE_VENC] = "venc",
  1242. [TEGRA_POWERGATE_VDEC] = "vdec",
  1243. [TEGRA_POWERGATE_MPE] = "mpe",
  1244. [TEGRA_POWERGATE_HEG] = "heg",
  1245. [TEGRA_POWERGATE_CPU1] = "cpu1",
  1246. [TEGRA_POWERGATE_CPU2] = "cpu2",
  1247. [TEGRA_POWERGATE_CPU3] = "cpu3",
  1248. [TEGRA_POWERGATE_CELP] = "celp",
  1249. [TEGRA_POWERGATE_CPU0] = "cpu0",
  1250. [TEGRA_POWERGATE_C0NC] = "c0nc",
  1251. [TEGRA_POWERGATE_C1NC] = "c1nc",
  1252. [TEGRA_POWERGATE_DIS] = "dis",
  1253. [TEGRA_POWERGATE_DISB] = "disb",
  1254. [TEGRA_POWERGATE_XUSBA] = "xusba",
  1255. [TEGRA_POWERGATE_XUSBB] = "xusbb",
  1256. [TEGRA_POWERGATE_XUSBC] = "xusbc",
  1257. };
  1258. static const u8 tegra114_cpu_powergates[] = {
  1259. TEGRA_POWERGATE_CPU0,
  1260. TEGRA_POWERGATE_CPU1,
  1261. TEGRA_POWERGATE_CPU2,
  1262. TEGRA_POWERGATE_CPU3,
  1263. };
  1264. static const struct tegra_pmc_soc tegra114_pmc_soc = {
  1265. .num_powergates = ARRAY_SIZE(tegra114_powergates),
  1266. .powergates = tegra114_powergates,
  1267. .num_cpu_powergates = ARRAY_SIZE(tegra114_cpu_powergates),
  1268. .cpu_powergates = tegra114_cpu_powergates,
  1269. .has_tsense_reset = true,
  1270. .has_gpu_clamps = false,
  1271. .num_io_pads = 0,
  1272. .io_pads = NULL,
  1273. .regs = &tegra20_pmc_regs,
  1274. .init = tegra20_pmc_init,
  1275. .setup_irq_polarity = tegra20_pmc_setup_irq_polarity,
  1276. };
  1277. static const char * const tegra124_powergates[] = {
  1278. [TEGRA_POWERGATE_CPU] = "crail",
  1279. [TEGRA_POWERGATE_3D] = "3d",
  1280. [TEGRA_POWERGATE_VENC] = "venc",
  1281. [TEGRA_POWERGATE_PCIE] = "pcie",
  1282. [TEGRA_POWERGATE_VDEC] = "vdec",
  1283. [TEGRA_POWERGATE_MPE] = "mpe",
  1284. [TEGRA_POWERGATE_HEG] = "heg",
  1285. [TEGRA_POWERGATE_SATA] = "sata",
  1286. [TEGRA_POWERGATE_CPU1] = "cpu1",
  1287. [TEGRA_POWERGATE_CPU2] = "cpu2",
  1288. [TEGRA_POWERGATE_CPU3] = "cpu3",
  1289. [TEGRA_POWERGATE_CELP] = "celp",
  1290. [TEGRA_POWERGATE_CPU0] = "cpu0",
  1291. [TEGRA_POWERGATE_C0NC] = "c0nc",
  1292. [TEGRA_POWERGATE_C1NC] = "c1nc",
  1293. [TEGRA_POWERGATE_SOR] = "sor",
  1294. [TEGRA_POWERGATE_DIS] = "dis",
  1295. [TEGRA_POWERGATE_DISB] = "disb",
  1296. [TEGRA_POWERGATE_XUSBA] = "xusba",
  1297. [TEGRA_POWERGATE_XUSBB] = "xusbb",
  1298. [TEGRA_POWERGATE_XUSBC] = "xusbc",
  1299. [TEGRA_POWERGATE_VIC] = "vic",
  1300. [TEGRA_POWERGATE_IRAM] = "iram",
  1301. };
  1302. static const u8 tegra124_cpu_powergates[] = {
  1303. TEGRA_POWERGATE_CPU0,
  1304. TEGRA_POWERGATE_CPU1,
  1305. TEGRA_POWERGATE_CPU2,
  1306. TEGRA_POWERGATE_CPU3,
  1307. };
  1308. static const struct tegra_io_pad_soc tegra124_io_pads[] = {
  1309. { .id = TEGRA_IO_PAD_AUDIO, .dpd = 17, .voltage = UINT_MAX },
  1310. { .id = TEGRA_IO_PAD_BB, .dpd = 15, .voltage = UINT_MAX },
  1311. { .id = TEGRA_IO_PAD_CAM, .dpd = 36, .voltage = UINT_MAX },
  1312. { .id = TEGRA_IO_PAD_COMP, .dpd = 22, .voltage = UINT_MAX },
  1313. { .id = TEGRA_IO_PAD_CSIA, .dpd = 0, .voltage = UINT_MAX },
  1314. { .id = TEGRA_IO_PAD_CSIB, .dpd = 1, .voltage = UINT_MAX },
  1315. { .id = TEGRA_IO_PAD_CSIE, .dpd = 44, .voltage = UINT_MAX },
  1316. { .id = TEGRA_IO_PAD_DSI, .dpd = 2, .voltage = UINT_MAX },
  1317. { .id = TEGRA_IO_PAD_DSIB, .dpd = 39, .voltage = UINT_MAX },
  1318. { .id = TEGRA_IO_PAD_DSIC, .dpd = 40, .voltage = UINT_MAX },
  1319. { .id = TEGRA_IO_PAD_DSID, .dpd = 41, .voltage = UINT_MAX },
  1320. { .id = TEGRA_IO_PAD_HDMI, .dpd = 28, .voltage = UINT_MAX },
  1321. { .id = TEGRA_IO_PAD_HSIC, .dpd = 19, .voltage = UINT_MAX },
  1322. { .id = TEGRA_IO_PAD_HV, .dpd = 38, .voltage = UINT_MAX },
  1323. { .id = TEGRA_IO_PAD_LVDS, .dpd = 57, .voltage = UINT_MAX },
  1324. { .id = TEGRA_IO_PAD_MIPI_BIAS, .dpd = 3, .voltage = UINT_MAX },
  1325. { .id = TEGRA_IO_PAD_NAND, .dpd = 13, .voltage = UINT_MAX },
  1326. { .id = TEGRA_IO_PAD_PEX_BIAS, .dpd = 4, .voltage = UINT_MAX },
  1327. { .id = TEGRA_IO_PAD_PEX_CLK1, .dpd = 5, .voltage = UINT_MAX },
  1328. { .id = TEGRA_IO_PAD_PEX_CLK2, .dpd = 6, .voltage = UINT_MAX },
  1329. { .id = TEGRA_IO_PAD_PEX_CNTRL, .dpd = 32, .voltage = UINT_MAX },
  1330. { .id = TEGRA_IO_PAD_SDMMC1, .dpd = 33, .voltage = UINT_MAX },
  1331. { .id = TEGRA_IO_PAD_SDMMC3, .dpd = 34, .voltage = UINT_MAX },
  1332. { .id = TEGRA_IO_PAD_SDMMC4, .dpd = 35, .voltage = UINT_MAX },
  1333. { .id = TEGRA_IO_PAD_SYS_DDC, .dpd = 58, .voltage = UINT_MAX },
  1334. { .id = TEGRA_IO_PAD_UART, .dpd = 14, .voltage = UINT_MAX },
  1335. { .id = TEGRA_IO_PAD_USB0, .dpd = 9, .voltage = UINT_MAX },
  1336. { .id = TEGRA_IO_PAD_USB1, .dpd = 10, .voltage = UINT_MAX },
  1337. { .id = TEGRA_IO_PAD_USB2, .dpd = 11, .voltage = UINT_MAX },
  1338. { .id = TEGRA_IO_PAD_USB_BIAS, .dpd = 12, .voltage = UINT_MAX },
  1339. };
  1340. static const struct tegra_pmc_soc tegra124_pmc_soc = {
  1341. .num_powergates = ARRAY_SIZE(tegra124_powergates),
  1342. .powergates = tegra124_powergates,
  1343. .num_cpu_powergates = ARRAY_SIZE(tegra124_cpu_powergates),
  1344. .cpu_powergates = tegra124_cpu_powergates,
  1345. .has_tsense_reset = true,
  1346. .has_gpu_clamps = true,
  1347. .num_io_pads = ARRAY_SIZE(tegra124_io_pads),
  1348. .io_pads = tegra124_io_pads,
  1349. .regs = &tegra20_pmc_regs,
  1350. .init = tegra20_pmc_init,
  1351. .setup_irq_polarity = tegra20_pmc_setup_irq_polarity,
  1352. };
  1353. static const char * const tegra210_powergates[] = {
  1354. [TEGRA_POWERGATE_CPU] = "crail",
  1355. [TEGRA_POWERGATE_3D] = "3d",
  1356. [TEGRA_POWERGATE_VENC] = "venc",
  1357. [TEGRA_POWERGATE_PCIE] = "pcie",
  1358. [TEGRA_POWERGATE_MPE] = "mpe",
  1359. [TEGRA_POWERGATE_SATA] = "sata",
  1360. [TEGRA_POWERGATE_CPU1] = "cpu1",
  1361. [TEGRA_POWERGATE_CPU2] = "cpu2",
  1362. [TEGRA_POWERGATE_CPU3] = "cpu3",
  1363. [TEGRA_POWERGATE_CPU0] = "cpu0",
  1364. [TEGRA_POWERGATE_C0NC] = "c0nc",
  1365. [TEGRA_POWERGATE_SOR] = "sor",
  1366. [TEGRA_POWERGATE_DIS] = "dis",
  1367. [TEGRA_POWERGATE_DISB] = "disb",
  1368. [TEGRA_POWERGATE_XUSBA] = "xusba",
  1369. [TEGRA_POWERGATE_XUSBB] = "xusbb",
  1370. [TEGRA_POWERGATE_XUSBC] = "xusbc",
  1371. [TEGRA_POWERGATE_VIC] = "vic",
  1372. [TEGRA_POWERGATE_IRAM] = "iram",
  1373. [TEGRA_POWERGATE_NVDEC] = "nvdec",
  1374. [TEGRA_POWERGATE_NVJPG] = "nvjpg",
  1375. [TEGRA_POWERGATE_AUD] = "aud",
  1376. [TEGRA_POWERGATE_DFD] = "dfd",
  1377. [TEGRA_POWERGATE_VE2] = "ve2",
  1378. };
  1379. static const u8 tegra210_cpu_powergates[] = {
  1380. TEGRA_POWERGATE_CPU0,
  1381. TEGRA_POWERGATE_CPU1,
  1382. TEGRA_POWERGATE_CPU2,
  1383. TEGRA_POWERGATE_CPU3,
  1384. };
  1385. static const struct tegra_io_pad_soc tegra210_io_pads[] = {
  1386. { .id = TEGRA_IO_PAD_AUDIO, .dpd = 17, .voltage = 5 },
  1387. { .id = TEGRA_IO_PAD_AUDIO_HV, .dpd = 61, .voltage = 18 },
  1388. { .id = TEGRA_IO_PAD_CAM, .dpd = 36, .voltage = 10 },
  1389. { .id = TEGRA_IO_PAD_CSIA, .dpd = 0, .voltage = UINT_MAX },
  1390. { .id = TEGRA_IO_PAD_CSIB, .dpd = 1, .voltage = UINT_MAX },
  1391. { .id = TEGRA_IO_PAD_CSIC, .dpd = 42, .voltage = UINT_MAX },
  1392. { .id = TEGRA_IO_PAD_CSID, .dpd = 43, .voltage = UINT_MAX },
  1393. { .id = TEGRA_IO_PAD_CSIE, .dpd = 44, .voltage = UINT_MAX },
  1394. { .id = TEGRA_IO_PAD_CSIF, .dpd = 45, .voltage = UINT_MAX },
  1395. { .id = TEGRA_IO_PAD_DBG, .dpd = 25, .voltage = 19 },
  1396. { .id = TEGRA_IO_PAD_DEBUG_NONAO, .dpd = 26, .voltage = UINT_MAX },
  1397. { .id = TEGRA_IO_PAD_DMIC, .dpd = 50, .voltage = 20 },
  1398. { .id = TEGRA_IO_PAD_DP, .dpd = 51, .voltage = UINT_MAX },
  1399. { .id = TEGRA_IO_PAD_DSI, .dpd = 2, .voltage = UINT_MAX },
  1400. { .id = TEGRA_IO_PAD_DSIB, .dpd = 39, .voltage = UINT_MAX },
  1401. { .id = TEGRA_IO_PAD_DSIC, .dpd = 40, .voltage = UINT_MAX },
  1402. { .id = TEGRA_IO_PAD_DSID, .dpd = 41, .voltage = UINT_MAX },
  1403. { .id = TEGRA_IO_PAD_EMMC, .dpd = 35, .voltage = UINT_MAX },
  1404. { .id = TEGRA_IO_PAD_EMMC2, .dpd = 37, .voltage = UINT_MAX },
  1405. { .id = TEGRA_IO_PAD_GPIO, .dpd = 27, .voltage = 21 },
  1406. { .id = TEGRA_IO_PAD_HDMI, .dpd = 28, .voltage = UINT_MAX },
  1407. { .id = TEGRA_IO_PAD_HSIC, .dpd = 19, .voltage = UINT_MAX },
  1408. { .id = TEGRA_IO_PAD_LVDS, .dpd = 57, .voltage = UINT_MAX },
  1409. { .id = TEGRA_IO_PAD_MIPI_BIAS, .dpd = 3, .voltage = UINT_MAX },
  1410. { .id = TEGRA_IO_PAD_PEX_BIAS, .dpd = 4, .voltage = UINT_MAX },
  1411. { .id = TEGRA_IO_PAD_PEX_CLK1, .dpd = 5, .voltage = UINT_MAX },
  1412. { .id = TEGRA_IO_PAD_PEX_CLK2, .dpd = 6, .voltage = UINT_MAX },
  1413. { .id = TEGRA_IO_PAD_PEX_CNTRL, .dpd = UINT_MAX, .voltage = 11 },
  1414. { .id = TEGRA_IO_PAD_SDMMC1, .dpd = 33, .voltage = 12 },
  1415. { .id = TEGRA_IO_PAD_SDMMC3, .dpd = 34, .voltage = 13 },
  1416. { .id = TEGRA_IO_PAD_SPI, .dpd = 46, .voltage = 22 },
  1417. { .id = TEGRA_IO_PAD_SPI_HV, .dpd = 47, .voltage = 23 },
  1418. { .id = TEGRA_IO_PAD_UART, .dpd = 14, .voltage = 2 },
  1419. { .id = TEGRA_IO_PAD_USB0, .dpd = 9, .voltage = UINT_MAX },
  1420. { .id = TEGRA_IO_PAD_USB1, .dpd = 10, .voltage = UINT_MAX },
  1421. { .id = TEGRA_IO_PAD_USB2, .dpd = 11, .voltage = UINT_MAX },
  1422. { .id = TEGRA_IO_PAD_USB3, .dpd = 18, .voltage = UINT_MAX },
  1423. { .id = TEGRA_IO_PAD_USB_BIAS, .dpd = 12, .voltage = UINT_MAX },
  1424. };
  1425. static const struct tegra_pmc_soc tegra210_pmc_soc = {
  1426. .num_powergates = ARRAY_SIZE(tegra210_powergates),
  1427. .powergates = tegra210_powergates,
  1428. .num_cpu_powergates = ARRAY_SIZE(tegra210_cpu_powergates),
  1429. .cpu_powergates = tegra210_cpu_powergates,
  1430. .has_tsense_reset = true,
  1431. .has_gpu_clamps = true,
  1432. .needs_mbist_war = true,
  1433. .num_io_pads = ARRAY_SIZE(tegra210_io_pads),
  1434. .io_pads = tegra210_io_pads,
  1435. .regs = &tegra20_pmc_regs,
  1436. .init = tegra20_pmc_init,
  1437. .setup_irq_polarity = tegra20_pmc_setup_irq_polarity,
  1438. };
  1439. static const struct tegra_io_pad_soc tegra186_io_pads[] = {
  1440. { .id = TEGRA_IO_PAD_CSIA, .dpd = 0, .voltage = UINT_MAX },
  1441. { .id = TEGRA_IO_PAD_CSIB, .dpd = 1, .voltage = UINT_MAX },
  1442. { .id = TEGRA_IO_PAD_DSI, .dpd = 2, .voltage = UINT_MAX },
  1443. { .id = TEGRA_IO_PAD_MIPI_BIAS, .dpd = 3, .voltage = UINT_MAX },
  1444. { .id = TEGRA_IO_PAD_PEX_CLK_BIAS, .dpd = 4, .voltage = UINT_MAX },
  1445. { .id = TEGRA_IO_PAD_PEX_CLK3, .dpd = 5, .voltage = UINT_MAX },
  1446. { .id = TEGRA_IO_PAD_PEX_CLK2, .dpd = 6, .voltage = UINT_MAX },
  1447. { .id = TEGRA_IO_PAD_PEX_CLK1, .dpd = 7, .voltage = UINT_MAX },
  1448. { .id = TEGRA_IO_PAD_USB0, .dpd = 9, .voltage = UINT_MAX },
  1449. { .id = TEGRA_IO_PAD_USB1, .dpd = 10, .voltage = UINT_MAX },
  1450. { .id = TEGRA_IO_PAD_USB2, .dpd = 11, .voltage = UINT_MAX },
  1451. { .id = TEGRA_IO_PAD_USB_BIAS, .dpd = 12, .voltage = UINT_MAX },
  1452. { .id = TEGRA_IO_PAD_UART, .dpd = 14, .voltage = UINT_MAX },
  1453. { .id = TEGRA_IO_PAD_AUDIO, .dpd = 17, .voltage = UINT_MAX },
  1454. { .id = TEGRA_IO_PAD_HSIC, .dpd = 19, .voltage = UINT_MAX },
  1455. { .id = TEGRA_IO_PAD_DBG, .dpd = 25, .voltage = UINT_MAX },
  1456. { .id = TEGRA_IO_PAD_HDMI_DP0, .dpd = 28, .voltage = UINT_MAX },
  1457. { .id = TEGRA_IO_PAD_HDMI_DP1, .dpd = 29, .voltage = UINT_MAX },
  1458. { .id = TEGRA_IO_PAD_PEX_CNTRL, .dpd = 32, .voltage = UINT_MAX },
  1459. { .id = TEGRA_IO_PAD_SDMMC2_HV, .dpd = 34, .voltage = UINT_MAX },
  1460. { .id = TEGRA_IO_PAD_SDMMC4, .dpd = 36, .voltage = UINT_MAX },
  1461. { .id = TEGRA_IO_PAD_CAM, .dpd = 38, .voltage = UINT_MAX },
  1462. { .id = TEGRA_IO_PAD_DSIB, .dpd = 40, .voltage = UINT_MAX },
  1463. { .id = TEGRA_IO_PAD_DSIC, .dpd = 41, .voltage = UINT_MAX },
  1464. { .id = TEGRA_IO_PAD_DSID, .dpd = 42, .voltage = UINT_MAX },
  1465. { .id = TEGRA_IO_PAD_CSIC, .dpd = 43, .voltage = UINT_MAX },
  1466. { .id = TEGRA_IO_PAD_CSID, .dpd = 44, .voltage = UINT_MAX },
  1467. { .id = TEGRA_IO_PAD_CSIE, .dpd = 45, .voltage = UINT_MAX },
  1468. { .id = TEGRA_IO_PAD_CSIF, .dpd = 46, .voltage = UINT_MAX },
  1469. { .id = TEGRA_IO_PAD_SPI, .dpd = 47, .voltage = UINT_MAX },
  1470. { .id = TEGRA_IO_PAD_UFS, .dpd = 49, .voltage = UINT_MAX },
  1471. { .id = TEGRA_IO_PAD_DMIC_HV, .dpd = 52, .voltage = UINT_MAX },
  1472. { .id = TEGRA_IO_PAD_EDP, .dpd = 53, .voltage = UINT_MAX },
  1473. { .id = TEGRA_IO_PAD_SDMMC1_HV, .dpd = 55, .voltage = UINT_MAX },
  1474. { .id = TEGRA_IO_PAD_SDMMC3_HV, .dpd = 56, .voltage = UINT_MAX },
  1475. { .id = TEGRA_IO_PAD_CONN, .dpd = 60, .voltage = UINT_MAX },
  1476. { .id = TEGRA_IO_PAD_AUDIO_HV, .dpd = 61, .voltage = UINT_MAX },
  1477. };
  1478. static const struct tegra_pmc_regs tegra186_pmc_regs = {
  1479. .scratch0 = 0x2000,
  1480. .dpd_req = 0x74,
  1481. .dpd_status = 0x78,
  1482. .dpd2_req = 0x7c,
  1483. .dpd2_status = 0x80,
  1484. };
  1485. static void tegra186_pmc_setup_irq_polarity(struct tegra_pmc *pmc,
  1486. struct device_node *np,
  1487. bool invert)
  1488. {
  1489. struct resource regs;
  1490. void __iomem *wake;
  1491. u32 value;
  1492. int index;
  1493. index = of_property_match_string(np, "reg-names", "wake");
  1494. if (index < 0) {
  1495. pr_err("failed to find PMC wake registers\n");
  1496. return;
  1497. }
  1498. of_address_to_resource(np, index, &regs);
  1499. wake = ioremap_nocache(regs.start, resource_size(&regs));
  1500. if (!wake) {
  1501. pr_err("failed to map PMC wake registers\n");
  1502. return;
  1503. }
  1504. value = readl(wake + WAKE_AOWAKE_CTRL);
  1505. if (invert)
  1506. value |= WAKE_AOWAKE_CTRL_INTR_POLARITY;
  1507. else
  1508. value &= ~WAKE_AOWAKE_CTRL_INTR_POLARITY;
  1509. writel(value, wake + WAKE_AOWAKE_CTRL);
  1510. iounmap(wake);
  1511. }
  1512. static const struct tegra_pmc_soc tegra186_pmc_soc = {
  1513. .num_powergates = 0,
  1514. .powergates = NULL,
  1515. .num_cpu_powergates = 0,
  1516. .cpu_powergates = NULL,
  1517. .has_tsense_reset = false,
  1518. .has_gpu_clamps = false,
  1519. .num_io_pads = ARRAY_SIZE(tegra186_io_pads),
  1520. .io_pads = tegra186_io_pads,
  1521. .regs = &tegra186_pmc_regs,
  1522. .init = NULL,
  1523. .setup_irq_polarity = tegra186_pmc_setup_irq_polarity,
  1524. };
  1525. static const struct of_device_id tegra_pmc_match[] = {
  1526. { .compatible = "nvidia,tegra194-pmc", .data = &tegra186_pmc_soc },
  1527. { .compatible = "nvidia,tegra186-pmc", .data = &tegra186_pmc_soc },
  1528. { .compatible = "nvidia,tegra210-pmc", .data = &tegra210_pmc_soc },
  1529. { .compatible = "nvidia,tegra132-pmc", .data = &tegra124_pmc_soc },
  1530. { .compatible = "nvidia,tegra124-pmc", .data = &tegra124_pmc_soc },
  1531. { .compatible = "nvidia,tegra114-pmc", .data = &tegra114_pmc_soc },
  1532. { .compatible = "nvidia,tegra30-pmc", .data = &tegra30_pmc_soc },
  1533. { .compatible = "nvidia,tegra20-pmc", .data = &tegra20_pmc_soc },
  1534. { }
  1535. };
  1536. static struct platform_driver tegra_pmc_driver = {
  1537. .driver = {
  1538. .name = "tegra-pmc",
  1539. .suppress_bind_attrs = true,
  1540. .of_match_table = tegra_pmc_match,
  1541. #if defined(CONFIG_PM_SLEEP) && defined(CONFIG_ARM)
  1542. .pm = &tegra_pmc_pm_ops,
  1543. #endif
  1544. },
  1545. .probe = tegra_pmc_probe,
  1546. };
  1547. builtin_platform_driver(tegra_pmc_driver);
  1548. /*
  1549. * Early initialization to allow access to registers in the very early boot
  1550. * process.
  1551. */
  1552. static int __init tegra_pmc_early_init(void)
  1553. {
  1554. const struct of_device_id *match;
  1555. struct device_node *np;
  1556. struct resource regs;
  1557. bool invert;
  1558. mutex_init(&pmc->powergates_lock);
  1559. np = of_find_matching_node_and_match(NULL, tegra_pmc_match, &match);
  1560. if (!np) {
  1561. /*
  1562. * Fall back to legacy initialization for 32-bit ARM only. All
  1563. * 64-bit ARM device tree files for Tegra are required to have
  1564. * a PMC node.
  1565. *
  1566. * This is for backwards-compatibility with old device trees
  1567. * that didn't contain a PMC node. Note that in this case the
  1568. * SoC data can't be matched and therefore powergating is
  1569. * disabled.
  1570. */
  1571. if (IS_ENABLED(CONFIG_ARM) && soc_is_tegra()) {
  1572. pr_warn("DT node not found, powergating disabled\n");
  1573. regs.start = 0x7000e400;
  1574. regs.end = 0x7000e7ff;
  1575. regs.flags = IORESOURCE_MEM;
  1576. pr_warn("Using memory region %pR\n", &regs);
  1577. } else {
  1578. /*
  1579. * At this point we're not running on Tegra, so play
  1580. * nice with multi-platform kernels.
  1581. */
  1582. return 0;
  1583. }
  1584. } else {
  1585. /*
  1586. * Extract information from the device tree if we've found a
  1587. * matching node.
  1588. */
  1589. if (of_address_to_resource(np, 0, &regs) < 0) {
  1590. pr_err("failed to get PMC registers\n");
  1591. of_node_put(np);
  1592. return -ENXIO;
  1593. }
  1594. }
  1595. pmc->base = ioremap_nocache(regs.start, resource_size(&regs));
  1596. if (!pmc->base) {
  1597. pr_err("failed to map PMC registers\n");
  1598. of_node_put(np);
  1599. return -ENXIO;
  1600. }
  1601. if (np) {
  1602. pmc->soc = match->data;
  1603. tegra_powergate_init(pmc, np);
  1604. /*
  1605. * Invert the interrupt polarity if a PMC device tree node
  1606. * exists and contains the nvidia,invert-interrupt property.
  1607. */
  1608. invert = of_property_read_bool(np, "nvidia,invert-interrupt");
  1609. pmc->soc->setup_irq_polarity(pmc, np, invert);
  1610. of_node_put(np);
  1611. }
  1612. return 0;
  1613. }
  1614. early_initcall(tegra_pmc_early_init);