pmc.c 44 KB

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