pmc.c 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827
  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(np);
  729. }
  730. static const struct tegra_io_pad_soc *
  731. tegra_io_pad_find(struct tegra_pmc *pmc, enum tegra_io_pad id)
  732. {
  733. unsigned int i;
  734. for (i = 0; i < pmc->soc->num_io_pads; i++)
  735. if (pmc->soc->io_pads[i].id == id)
  736. return &pmc->soc->io_pads[i];
  737. return NULL;
  738. }
  739. static int tegra_io_pad_prepare(enum tegra_io_pad id, unsigned long *request,
  740. unsigned long *status, u32 *mask)
  741. {
  742. const struct tegra_io_pad_soc *pad;
  743. unsigned long rate, value;
  744. pad = tegra_io_pad_find(pmc, id);
  745. if (!pad) {
  746. pr_err("invalid I/O pad ID %u\n", id);
  747. return -ENOENT;
  748. }
  749. if (pad->dpd == UINT_MAX)
  750. return -ENOTSUPP;
  751. *mask = BIT(pad->dpd % 32);
  752. if (pad->dpd < 32) {
  753. *status = IO_DPD_STATUS;
  754. *request = IO_DPD_REQ;
  755. } else {
  756. *status = IO_DPD2_STATUS;
  757. *request = IO_DPD2_REQ;
  758. }
  759. rate = clk_get_rate(pmc->clk);
  760. if (!rate) {
  761. pr_err("failed to get clock rate\n");
  762. return -ENODEV;
  763. }
  764. tegra_pmc_writel(DPD_SAMPLE_ENABLE, DPD_SAMPLE);
  765. /* must be at least 200 ns, in APB (PCLK) clock cycles */
  766. value = DIV_ROUND_UP(1000000000, rate);
  767. value = DIV_ROUND_UP(200, value);
  768. tegra_pmc_writel(value, SEL_DPD_TIM);
  769. return 0;
  770. }
  771. static int tegra_io_pad_poll(unsigned long offset, u32 mask,
  772. u32 val, unsigned long timeout)
  773. {
  774. u32 value;
  775. timeout = jiffies + msecs_to_jiffies(timeout);
  776. while (time_after(timeout, jiffies)) {
  777. value = tegra_pmc_readl(offset);
  778. if ((value & mask) == val)
  779. return 0;
  780. usleep_range(250, 1000);
  781. }
  782. return -ETIMEDOUT;
  783. }
  784. static void tegra_io_pad_unprepare(void)
  785. {
  786. tegra_pmc_writel(DPD_SAMPLE_DISABLE, DPD_SAMPLE);
  787. }
  788. /**
  789. * tegra_io_pad_power_enable() - enable power to I/O pad
  790. * @id: Tegra I/O pad ID for which to enable power
  791. *
  792. * Returns: 0 on success or a negative error code on failure.
  793. */
  794. int tegra_io_pad_power_enable(enum tegra_io_pad id)
  795. {
  796. unsigned long request, status;
  797. u32 mask;
  798. int err;
  799. mutex_lock(&pmc->powergates_lock);
  800. err = tegra_io_pad_prepare(id, &request, &status, &mask);
  801. if (err < 0) {
  802. pr_err("failed to prepare I/O pad: %d\n", err);
  803. goto unlock;
  804. }
  805. tegra_pmc_writel(IO_DPD_REQ_CODE_OFF | mask, request);
  806. err = tegra_io_pad_poll(status, mask, 0, 250);
  807. if (err < 0) {
  808. pr_err("failed to enable I/O pad: %d\n", err);
  809. goto unlock;
  810. }
  811. tegra_io_pad_unprepare();
  812. unlock:
  813. mutex_unlock(&pmc->powergates_lock);
  814. return err;
  815. }
  816. EXPORT_SYMBOL(tegra_io_pad_power_enable);
  817. /**
  818. * tegra_io_pad_power_disable() - disable power to I/O pad
  819. * @id: Tegra I/O pad ID for which to disable power
  820. *
  821. * Returns: 0 on success or a negative error code on failure.
  822. */
  823. int tegra_io_pad_power_disable(enum tegra_io_pad id)
  824. {
  825. unsigned long request, status;
  826. u32 mask;
  827. int err;
  828. mutex_lock(&pmc->powergates_lock);
  829. err = tegra_io_pad_prepare(id, &request, &status, &mask);
  830. if (err < 0) {
  831. pr_err("failed to prepare I/O pad: %d\n", err);
  832. goto unlock;
  833. }
  834. tegra_pmc_writel(IO_DPD_REQ_CODE_ON | mask, request);
  835. err = tegra_io_pad_poll(status, mask, mask, 250);
  836. if (err < 0) {
  837. pr_err("failed to disable I/O pad: %d\n", err);
  838. goto unlock;
  839. }
  840. tegra_io_pad_unprepare();
  841. unlock:
  842. mutex_unlock(&pmc->powergates_lock);
  843. return err;
  844. }
  845. EXPORT_SYMBOL(tegra_io_pad_power_disable);
  846. int tegra_io_pad_set_voltage(enum tegra_io_pad id,
  847. enum tegra_io_pad_voltage voltage)
  848. {
  849. const struct tegra_io_pad_soc *pad;
  850. u32 value;
  851. pad = tegra_io_pad_find(pmc, id);
  852. if (!pad)
  853. return -ENOENT;
  854. if (pad->voltage == UINT_MAX)
  855. return -ENOTSUPP;
  856. mutex_lock(&pmc->powergates_lock);
  857. /* write-enable PMC_PWR_DET_VALUE[pad->voltage] */
  858. value = tegra_pmc_readl(PMC_PWR_DET);
  859. value |= BIT(pad->voltage);
  860. tegra_pmc_writel(value, PMC_PWR_DET);
  861. /* update I/O voltage */
  862. value = tegra_pmc_readl(PMC_PWR_DET_VALUE);
  863. if (voltage == TEGRA_IO_PAD_1800000UV)
  864. value &= ~BIT(pad->voltage);
  865. else
  866. value |= BIT(pad->voltage);
  867. tegra_pmc_writel(value, PMC_PWR_DET_VALUE);
  868. mutex_unlock(&pmc->powergates_lock);
  869. usleep_range(100, 250);
  870. return 0;
  871. }
  872. EXPORT_SYMBOL(tegra_io_pad_set_voltage);
  873. int tegra_io_pad_get_voltage(enum tegra_io_pad id)
  874. {
  875. const struct tegra_io_pad_soc *pad;
  876. u32 value;
  877. pad = tegra_io_pad_find(pmc, id);
  878. if (!pad)
  879. return -ENOENT;
  880. if (pad->voltage == UINT_MAX)
  881. return -ENOTSUPP;
  882. value = tegra_pmc_readl(PMC_PWR_DET_VALUE);
  883. if ((value & BIT(pad->voltage)) == 0)
  884. return TEGRA_IO_PAD_1800000UV;
  885. return TEGRA_IO_PAD_3300000UV;
  886. }
  887. EXPORT_SYMBOL(tegra_io_pad_get_voltage);
  888. /**
  889. * tegra_io_rail_power_on() - enable power to I/O rail
  890. * @id: Tegra I/O pad ID for which to enable power
  891. *
  892. * See also: tegra_io_pad_power_enable()
  893. */
  894. int tegra_io_rail_power_on(unsigned int id)
  895. {
  896. return tegra_io_pad_power_enable(id);
  897. }
  898. EXPORT_SYMBOL(tegra_io_rail_power_on);
  899. /**
  900. * tegra_io_rail_power_off() - disable power to I/O rail
  901. * @id: Tegra I/O pad ID for which to disable power
  902. *
  903. * See also: tegra_io_pad_power_disable()
  904. */
  905. int tegra_io_rail_power_off(unsigned int id)
  906. {
  907. return tegra_io_pad_power_disable(id);
  908. }
  909. EXPORT_SYMBOL(tegra_io_rail_power_off);
  910. #ifdef CONFIG_PM_SLEEP
  911. enum tegra_suspend_mode tegra_pmc_get_suspend_mode(void)
  912. {
  913. return pmc->suspend_mode;
  914. }
  915. void tegra_pmc_set_suspend_mode(enum tegra_suspend_mode mode)
  916. {
  917. if (mode < TEGRA_SUSPEND_NONE || mode >= TEGRA_MAX_SUSPEND_MODE)
  918. return;
  919. pmc->suspend_mode = mode;
  920. }
  921. void tegra_pmc_enter_suspend_mode(enum tegra_suspend_mode mode)
  922. {
  923. unsigned long long rate = 0;
  924. u32 value;
  925. switch (mode) {
  926. case TEGRA_SUSPEND_LP1:
  927. rate = 32768;
  928. break;
  929. case TEGRA_SUSPEND_LP2:
  930. rate = clk_get_rate(pmc->clk);
  931. break;
  932. default:
  933. break;
  934. }
  935. if (WARN_ON_ONCE(rate == 0))
  936. rate = 100000000;
  937. if (rate != pmc->rate) {
  938. u64 ticks;
  939. ticks = pmc->cpu_good_time * rate + USEC_PER_SEC - 1;
  940. do_div(ticks, USEC_PER_SEC);
  941. tegra_pmc_writel(ticks, PMC_CPUPWRGOOD_TIMER);
  942. ticks = pmc->cpu_off_time * rate + USEC_PER_SEC - 1;
  943. do_div(ticks, USEC_PER_SEC);
  944. tegra_pmc_writel(ticks, PMC_CPUPWROFF_TIMER);
  945. wmb();
  946. pmc->rate = rate;
  947. }
  948. value = tegra_pmc_readl(PMC_CNTRL);
  949. value &= ~PMC_CNTRL_SIDE_EFFECT_LP0;
  950. value |= PMC_CNTRL_CPU_PWRREQ_OE;
  951. tegra_pmc_writel(value, PMC_CNTRL);
  952. }
  953. #endif
  954. static int tegra_pmc_parse_dt(struct tegra_pmc *pmc, struct device_node *np)
  955. {
  956. u32 value, values[2];
  957. if (of_property_read_u32(np, "nvidia,suspend-mode", &value)) {
  958. } else {
  959. switch (value) {
  960. case 0:
  961. pmc->suspend_mode = TEGRA_SUSPEND_LP0;
  962. break;
  963. case 1:
  964. pmc->suspend_mode = TEGRA_SUSPEND_LP1;
  965. break;
  966. case 2:
  967. pmc->suspend_mode = TEGRA_SUSPEND_LP2;
  968. break;
  969. default:
  970. pmc->suspend_mode = TEGRA_SUSPEND_NONE;
  971. break;
  972. }
  973. }
  974. pmc->suspend_mode = tegra_pm_validate_suspend_mode(pmc->suspend_mode);
  975. if (of_property_read_u32(np, "nvidia,cpu-pwr-good-time", &value))
  976. pmc->suspend_mode = TEGRA_SUSPEND_NONE;
  977. pmc->cpu_good_time = value;
  978. if (of_property_read_u32(np, "nvidia,cpu-pwr-off-time", &value))
  979. pmc->suspend_mode = TEGRA_SUSPEND_NONE;
  980. pmc->cpu_off_time = value;
  981. if (of_property_read_u32_array(np, "nvidia,core-pwr-good-time",
  982. values, ARRAY_SIZE(values)))
  983. pmc->suspend_mode = TEGRA_SUSPEND_NONE;
  984. pmc->core_osc_time = values[0];
  985. pmc->core_pmu_time = values[1];
  986. if (of_property_read_u32(np, "nvidia,core-pwr-off-time", &value))
  987. pmc->suspend_mode = TEGRA_SUSPEND_NONE;
  988. pmc->core_off_time = value;
  989. pmc->corereq_high = of_property_read_bool(np,
  990. "nvidia,core-power-req-active-high");
  991. pmc->sysclkreq_high = of_property_read_bool(np,
  992. "nvidia,sys-clock-req-active-high");
  993. pmc->combined_req = of_property_read_bool(np,
  994. "nvidia,combined-power-req");
  995. pmc->cpu_pwr_good_en = of_property_read_bool(np,
  996. "nvidia,cpu-pwr-good-en");
  997. if (of_property_read_u32_array(np, "nvidia,lp0-vec", values,
  998. ARRAY_SIZE(values)))
  999. if (pmc->suspend_mode == TEGRA_SUSPEND_LP0)
  1000. pmc->suspend_mode = TEGRA_SUSPEND_LP1;
  1001. pmc->lp0_vec_phys = values[0];
  1002. pmc->lp0_vec_size = values[1];
  1003. return 0;
  1004. }
  1005. static void tegra_pmc_init(struct tegra_pmc *pmc)
  1006. {
  1007. u32 value;
  1008. /* Always enable CPU power request */
  1009. value = tegra_pmc_readl(PMC_CNTRL);
  1010. value |= PMC_CNTRL_CPU_PWRREQ_OE;
  1011. tegra_pmc_writel(value, PMC_CNTRL);
  1012. value = tegra_pmc_readl(PMC_CNTRL);
  1013. if (pmc->sysclkreq_high)
  1014. value &= ~PMC_CNTRL_SYSCLK_POLARITY;
  1015. else
  1016. value |= PMC_CNTRL_SYSCLK_POLARITY;
  1017. /* configure the output polarity while the request is tristated */
  1018. tegra_pmc_writel(value, PMC_CNTRL);
  1019. /* now enable the request */
  1020. value = tegra_pmc_readl(PMC_CNTRL);
  1021. value |= PMC_CNTRL_SYSCLK_OE;
  1022. tegra_pmc_writel(value, PMC_CNTRL);
  1023. }
  1024. static void tegra_pmc_init_tsense_reset(struct tegra_pmc *pmc)
  1025. {
  1026. static const char disabled[] = "emergency thermal reset disabled";
  1027. u32 pmu_addr, ctrl_id, reg_addr, reg_data, pinmux;
  1028. struct device *dev = pmc->dev;
  1029. struct device_node *np;
  1030. u32 value, checksum;
  1031. if (!pmc->soc->has_tsense_reset)
  1032. return;
  1033. np = of_find_node_by_name(pmc->dev->of_node, "i2c-thermtrip");
  1034. if (!np) {
  1035. dev_warn(dev, "i2c-thermtrip node not found, %s.\n", disabled);
  1036. return;
  1037. }
  1038. if (of_property_read_u32(np, "nvidia,i2c-controller-id", &ctrl_id)) {
  1039. dev_err(dev, "I2C controller ID missing, %s.\n", disabled);
  1040. goto out;
  1041. }
  1042. if (of_property_read_u32(np, "nvidia,bus-addr", &pmu_addr)) {
  1043. dev_err(dev, "nvidia,bus-addr missing, %s.\n", disabled);
  1044. goto out;
  1045. }
  1046. if (of_property_read_u32(np, "nvidia,reg-addr", &reg_addr)) {
  1047. dev_err(dev, "nvidia,reg-addr missing, %s.\n", disabled);
  1048. goto out;
  1049. }
  1050. if (of_property_read_u32(np, "nvidia,reg-data", &reg_data)) {
  1051. dev_err(dev, "nvidia,reg-data missing, %s.\n", disabled);
  1052. goto out;
  1053. }
  1054. if (of_property_read_u32(np, "nvidia,pinmux-id", &pinmux))
  1055. pinmux = 0;
  1056. value = tegra_pmc_readl(PMC_SENSOR_CTRL);
  1057. value |= PMC_SENSOR_CTRL_SCRATCH_WRITE;
  1058. tegra_pmc_writel(value, PMC_SENSOR_CTRL);
  1059. value = (reg_data << PMC_SCRATCH54_DATA_SHIFT) |
  1060. (reg_addr << PMC_SCRATCH54_ADDR_SHIFT);
  1061. tegra_pmc_writel(value, PMC_SCRATCH54);
  1062. value = PMC_SCRATCH55_RESET_TEGRA;
  1063. value |= ctrl_id << PMC_SCRATCH55_CNTRL_ID_SHIFT;
  1064. value |= pinmux << PMC_SCRATCH55_PINMUX_SHIFT;
  1065. value |= pmu_addr << PMC_SCRATCH55_I2CSLV1_SHIFT;
  1066. /*
  1067. * Calculate checksum of SCRATCH54, SCRATCH55 fields. Bits 23:16 will
  1068. * contain the checksum and are currently zero, so they are not added.
  1069. */
  1070. checksum = reg_addr + reg_data + (value & 0xff) + ((value >> 8) & 0xff)
  1071. + ((value >> 24) & 0xff);
  1072. checksum &= 0xff;
  1073. checksum = 0x100 - checksum;
  1074. value |= checksum << PMC_SCRATCH55_CHECKSUM_SHIFT;
  1075. tegra_pmc_writel(value, PMC_SCRATCH55);
  1076. value = tegra_pmc_readl(PMC_SENSOR_CTRL);
  1077. value |= PMC_SENSOR_CTRL_ENABLE_RST;
  1078. tegra_pmc_writel(value, PMC_SENSOR_CTRL);
  1079. dev_info(pmc->dev, "emergency thermal reset enabled\n");
  1080. out:
  1081. of_node_put(np);
  1082. }
  1083. static int tegra_pmc_probe(struct platform_device *pdev)
  1084. {
  1085. void __iomem *base;
  1086. struct resource *res;
  1087. int err;
  1088. /*
  1089. * Early initialisation should have configured an initial
  1090. * register mapping and setup the soc data pointer. If these
  1091. * are not valid then something went badly wrong!
  1092. */
  1093. if (WARN_ON(!pmc->base || !pmc->soc))
  1094. return -ENODEV;
  1095. err = tegra_pmc_parse_dt(pmc, pdev->dev.of_node);
  1096. if (err < 0)
  1097. return err;
  1098. /* take over the memory region from the early initialization */
  1099. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1100. base = devm_ioremap_resource(&pdev->dev, res);
  1101. if (IS_ERR(base))
  1102. return PTR_ERR(base);
  1103. pmc->clk = devm_clk_get(&pdev->dev, "pclk");
  1104. if (IS_ERR(pmc->clk)) {
  1105. err = PTR_ERR(pmc->clk);
  1106. dev_err(&pdev->dev, "failed to get pclk: %d\n", err);
  1107. return err;
  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_soc tegra20_pmc_soc = {
  1153. .num_powergates = ARRAY_SIZE(tegra20_powergates),
  1154. .powergates = tegra20_powergates,
  1155. .num_cpu_powergates = 0,
  1156. .cpu_powergates = NULL,
  1157. .has_tsense_reset = false,
  1158. .has_gpu_clamps = false,
  1159. };
  1160. static const char * const tegra30_powergates[] = {
  1161. [TEGRA_POWERGATE_CPU] = "cpu0",
  1162. [TEGRA_POWERGATE_3D] = "3d0",
  1163. [TEGRA_POWERGATE_VENC] = "venc",
  1164. [TEGRA_POWERGATE_VDEC] = "vdec",
  1165. [TEGRA_POWERGATE_PCIE] = "pcie",
  1166. [TEGRA_POWERGATE_L2] = "l2",
  1167. [TEGRA_POWERGATE_MPE] = "mpe",
  1168. [TEGRA_POWERGATE_HEG] = "heg",
  1169. [TEGRA_POWERGATE_SATA] = "sata",
  1170. [TEGRA_POWERGATE_CPU1] = "cpu1",
  1171. [TEGRA_POWERGATE_CPU2] = "cpu2",
  1172. [TEGRA_POWERGATE_CPU3] = "cpu3",
  1173. [TEGRA_POWERGATE_CELP] = "celp",
  1174. [TEGRA_POWERGATE_3D1] = "3d1",
  1175. };
  1176. static const u8 tegra30_cpu_powergates[] = {
  1177. TEGRA_POWERGATE_CPU,
  1178. TEGRA_POWERGATE_CPU1,
  1179. TEGRA_POWERGATE_CPU2,
  1180. TEGRA_POWERGATE_CPU3,
  1181. };
  1182. static const struct tegra_pmc_soc tegra30_pmc_soc = {
  1183. .num_powergates = ARRAY_SIZE(tegra30_powergates),
  1184. .powergates = tegra30_powergates,
  1185. .num_cpu_powergates = ARRAY_SIZE(tegra30_cpu_powergates),
  1186. .cpu_powergates = tegra30_cpu_powergates,
  1187. .has_tsense_reset = true,
  1188. .has_gpu_clamps = false,
  1189. };
  1190. static const char * const tegra114_powergates[] = {
  1191. [TEGRA_POWERGATE_CPU] = "crail",
  1192. [TEGRA_POWERGATE_3D] = "3d",
  1193. [TEGRA_POWERGATE_VENC] = "venc",
  1194. [TEGRA_POWERGATE_VDEC] = "vdec",
  1195. [TEGRA_POWERGATE_MPE] = "mpe",
  1196. [TEGRA_POWERGATE_HEG] = "heg",
  1197. [TEGRA_POWERGATE_CPU1] = "cpu1",
  1198. [TEGRA_POWERGATE_CPU2] = "cpu2",
  1199. [TEGRA_POWERGATE_CPU3] = "cpu3",
  1200. [TEGRA_POWERGATE_CELP] = "celp",
  1201. [TEGRA_POWERGATE_CPU0] = "cpu0",
  1202. [TEGRA_POWERGATE_C0NC] = "c0nc",
  1203. [TEGRA_POWERGATE_C1NC] = "c1nc",
  1204. [TEGRA_POWERGATE_DIS] = "dis",
  1205. [TEGRA_POWERGATE_DISB] = "disb",
  1206. [TEGRA_POWERGATE_XUSBA] = "xusba",
  1207. [TEGRA_POWERGATE_XUSBB] = "xusbb",
  1208. [TEGRA_POWERGATE_XUSBC] = "xusbc",
  1209. };
  1210. static const u8 tegra114_cpu_powergates[] = {
  1211. TEGRA_POWERGATE_CPU0,
  1212. TEGRA_POWERGATE_CPU1,
  1213. TEGRA_POWERGATE_CPU2,
  1214. TEGRA_POWERGATE_CPU3,
  1215. };
  1216. static const struct tegra_pmc_soc tegra114_pmc_soc = {
  1217. .num_powergates = ARRAY_SIZE(tegra114_powergates),
  1218. .powergates = tegra114_powergates,
  1219. .num_cpu_powergates = ARRAY_SIZE(tegra114_cpu_powergates),
  1220. .cpu_powergates = tegra114_cpu_powergates,
  1221. .has_tsense_reset = true,
  1222. .has_gpu_clamps = false,
  1223. };
  1224. static const char * const tegra124_powergates[] = {
  1225. [TEGRA_POWERGATE_CPU] = "crail",
  1226. [TEGRA_POWERGATE_3D] = "3d",
  1227. [TEGRA_POWERGATE_VENC] = "venc",
  1228. [TEGRA_POWERGATE_PCIE] = "pcie",
  1229. [TEGRA_POWERGATE_VDEC] = "vdec",
  1230. [TEGRA_POWERGATE_MPE] = "mpe",
  1231. [TEGRA_POWERGATE_HEG] = "heg",
  1232. [TEGRA_POWERGATE_SATA] = "sata",
  1233. [TEGRA_POWERGATE_CPU1] = "cpu1",
  1234. [TEGRA_POWERGATE_CPU2] = "cpu2",
  1235. [TEGRA_POWERGATE_CPU3] = "cpu3",
  1236. [TEGRA_POWERGATE_CELP] = "celp",
  1237. [TEGRA_POWERGATE_CPU0] = "cpu0",
  1238. [TEGRA_POWERGATE_C0NC] = "c0nc",
  1239. [TEGRA_POWERGATE_C1NC] = "c1nc",
  1240. [TEGRA_POWERGATE_SOR] = "sor",
  1241. [TEGRA_POWERGATE_DIS] = "dis",
  1242. [TEGRA_POWERGATE_DISB] = "disb",
  1243. [TEGRA_POWERGATE_XUSBA] = "xusba",
  1244. [TEGRA_POWERGATE_XUSBB] = "xusbb",
  1245. [TEGRA_POWERGATE_XUSBC] = "xusbc",
  1246. [TEGRA_POWERGATE_VIC] = "vic",
  1247. [TEGRA_POWERGATE_IRAM] = "iram",
  1248. };
  1249. static const u8 tegra124_cpu_powergates[] = {
  1250. TEGRA_POWERGATE_CPU0,
  1251. TEGRA_POWERGATE_CPU1,
  1252. TEGRA_POWERGATE_CPU2,
  1253. TEGRA_POWERGATE_CPU3,
  1254. };
  1255. static const struct tegra_io_pad_soc tegra124_io_pads[] = {
  1256. { .id = TEGRA_IO_PAD_AUDIO, .dpd = 17, .voltage = UINT_MAX },
  1257. { .id = TEGRA_IO_PAD_BB, .dpd = 15, .voltage = UINT_MAX },
  1258. { .id = TEGRA_IO_PAD_CAM, .dpd = 36, .voltage = UINT_MAX },
  1259. { .id = TEGRA_IO_PAD_COMP, .dpd = 22, .voltage = UINT_MAX },
  1260. { .id = TEGRA_IO_PAD_CSIA, .dpd = 0, .voltage = UINT_MAX },
  1261. { .id = TEGRA_IO_PAD_CSIB, .dpd = 1, .voltage = UINT_MAX },
  1262. { .id = TEGRA_IO_PAD_CSIE, .dpd = 44, .voltage = UINT_MAX },
  1263. { .id = TEGRA_IO_PAD_DSI, .dpd = 2, .voltage = UINT_MAX },
  1264. { .id = TEGRA_IO_PAD_DSIB, .dpd = 39, .voltage = UINT_MAX },
  1265. { .id = TEGRA_IO_PAD_DSIC, .dpd = 40, .voltage = UINT_MAX },
  1266. { .id = TEGRA_IO_PAD_DSID, .dpd = 41, .voltage = UINT_MAX },
  1267. { .id = TEGRA_IO_PAD_HDMI, .dpd = 28, .voltage = UINT_MAX },
  1268. { .id = TEGRA_IO_PAD_HSIC, .dpd = 19, .voltage = UINT_MAX },
  1269. { .id = TEGRA_IO_PAD_HV, .dpd = 38, .voltage = UINT_MAX },
  1270. { .id = TEGRA_IO_PAD_LVDS, .dpd = 57, .voltage = UINT_MAX },
  1271. { .id = TEGRA_IO_PAD_MIPI_BIAS, .dpd = 3, .voltage = UINT_MAX },
  1272. { .id = TEGRA_IO_PAD_NAND, .dpd = 13, .voltage = UINT_MAX },
  1273. { .id = TEGRA_IO_PAD_PEX_BIAS, .dpd = 4, .voltage = UINT_MAX },
  1274. { .id = TEGRA_IO_PAD_PEX_CLK1, .dpd = 5, .voltage = UINT_MAX },
  1275. { .id = TEGRA_IO_PAD_PEX_CLK2, .dpd = 6, .voltage = UINT_MAX },
  1276. { .id = TEGRA_IO_PAD_PEX_CNTRL, .dpd = 32, .voltage = UINT_MAX },
  1277. { .id = TEGRA_IO_PAD_SDMMC1, .dpd = 33, .voltage = UINT_MAX },
  1278. { .id = TEGRA_IO_PAD_SDMMC3, .dpd = 34, .voltage = UINT_MAX },
  1279. { .id = TEGRA_IO_PAD_SDMMC4, .dpd = 35, .voltage = UINT_MAX },
  1280. { .id = TEGRA_IO_PAD_SYS_DDC, .dpd = 58, .voltage = UINT_MAX },
  1281. { .id = TEGRA_IO_PAD_UART, .dpd = 14, .voltage = UINT_MAX },
  1282. { .id = TEGRA_IO_PAD_USB0, .dpd = 9, .voltage = UINT_MAX },
  1283. { .id = TEGRA_IO_PAD_USB1, .dpd = 10, .voltage = UINT_MAX },
  1284. { .id = TEGRA_IO_PAD_USB2, .dpd = 11, .voltage = UINT_MAX },
  1285. { .id = TEGRA_IO_PAD_USB_BIAS, .dpd = 12, .voltage = UINT_MAX },
  1286. };
  1287. static const struct tegra_pmc_soc tegra124_pmc_soc = {
  1288. .num_powergates = ARRAY_SIZE(tegra124_powergates),
  1289. .powergates = tegra124_powergates,
  1290. .num_cpu_powergates = ARRAY_SIZE(tegra124_cpu_powergates),
  1291. .cpu_powergates = tegra124_cpu_powergates,
  1292. .has_tsense_reset = true,
  1293. .has_gpu_clamps = true,
  1294. .num_io_pads = ARRAY_SIZE(tegra124_io_pads),
  1295. .io_pads = tegra124_io_pads,
  1296. };
  1297. static const char * const tegra210_powergates[] = {
  1298. [TEGRA_POWERGATE_CPU] = "crail",
  1299. [TEGRA_POWERGATE_3D] = "3d",
  1300. [TEGRA_POWERGATE_VENC] = "venc",
  1301. [TEGRA_POWERGATE_PCIE] = "pcie",
  1302. [TEGRA_POWERGATE_MPE] = "mpe",
  1303. [TEGRA_POWERGATE_SATA] = "sata",
  1304. [TEGRA_POWERGATE_CPU1] = "cpu1",
  1305. [TEGRA_POWERGATE_CPU2] = "cpu2",
  1306. [TEGRA_POWERGATE_CPU3] = "cpu3",
  1307. [TEGRA_POWERGATE_CPU0] = "cpu0",
  1308. [TEGRA_POWERGATE_C0NC] = "c0nc",
  1309. [TEGRA_POWERGATE_SOR] = "sor",
  1310. [TEGRA_POWERGATE_DIS] = "dis",
  1311. [TEGRA_POWERGATE_DISB] = "disb",
  1312. [TEGRA_POWERGATE_XUSBA] = "xusba",
  1313. [TEGRA_POWERGATE_XUSBB] = "xusbb",
  1314. [TEGRA_POWERGATE_XUSBC] = "xusbc",
  1315. [TEGRA_POWERGATE_VIC] = "vic",
  1316. [TEGRA_POWERGATE_IRAM] = "iram",
  1317. [TEGRA_POWERGATE_NVDEC] = "nvdec",
  1318. [TEGRA_POWERGATE_NVJPG] = "nvjpg",
  1319. [TEGRA_POWERGATE_AUD] = "aud",
  1320. [TEGRA_POWERGATE_DFD] = "dfd",
  1321. [TEGRA_POWERGATE_VE2] = "ve2",
  1322. };
  1323. static const u8 tegra210_cpu_powergates[] = {
  1324. TEGRA_POWERGATE_CPU0,
  1325. TEGRA_POWERGATE_CPU1,
  1326. TEGRA_POWERGATE_CPU2,
  1327. TEGRA_POWERGATE_CPU3,
  1328. };
  1329. static const struct tegra_io_pad_soc tegra210_io_pads[] = {
  1330. { .id = TEGRA_IO_PAD_AUDIO, .dpd = 17, .voltage = 5 },
  1331. { .id = TEGRA_IO_PAD_AUDIO_HV, .dpd = 61, .voltage = 18 },
  1332. { .id = TEGRA_IO_PAD_CAM, .dpd = 36, .voltage = 10 },
  1333. { .id = TEGRA_IO_PAD_CSIA, .dpd = 0, .voltage = UINT_MAX },
  1334. { .id = TEGRA_IO_PAD_CSIB, .dpd = 1, .voltage = UINT_MAX },
  1335. { .id = TEGRA_IO_PAD_CSIC, .dpd = 42, .voltage = UINT_MAX },
  1336. { .id = TEGRA_IO_PAD_CSID, .dpd = 43, .voltage = UINT_MAX },
  1337. { .id = TEGRA_IO_PAD_CSIE, .dpd = 44, .voltage = UINT_MAX },
  1338. { .id = TEGRA_IO_PAD_CSIF, .dpd = 45, .voltage = UINT_MAX },
  1339. { .id = TEGRA_IO_PAD_DBG, .dpd = 25, .voltage = 19 },
  1340. { .id = TEGRA_IO_PAD_DEBUG_NONAO, .dpd = 26, .voltage = UINT_MAX },
  1341. { .id = TEGRA_IO_PAD_DMIC, .dpd = 50, .voltage = 20 },
  1342. { .id = TEGRA_IO_PAD_DP, .dpd = 51, .voltage = UINT_MAX },
  1343. { .id = TEGRA_IO_PAD_DSI, .dpd = 2, .voltage = UINT_MAX },
  1344. { .id = TEGRA_IO_PAD_DSIB, .dpd = 39, .voltage = UINT_MAX },
  1345. { .id = TEGRA_IO_PAD_DSIC, .dpd = 40, .voltage = UINT_MAX },
  1346. { .id = TEGRA_IO_PAD_DSID, .dpd = 41, .voltage = UINT_MAX },
  1347. { .id = TEGRA_IO_PAD_EMMC, .dpd = 35, .voltage = UINT_MAX },
  1348. { .id = TEGRA_IO_PAD_EMMC2, .dpd = 37, .voltage = UINT_MAX },
  1349. { .id = TEGRA_IO_PAD_GPIO, .dpd = 27, .voltage = 21 },
  1350. { .id = TEGRA_IO_PAD_HDMI, .dpd = 28, .voltage = UINT_MAX },
  1351. { .id = TEGRA_IO_PAD_HSIC, .dpd = 19, .voltage = UINT_MAX },
  1352. { .id = TEGRA_IO_PAD_LVDS, .dpd = 57, .voltage = UINT_MAX },
  1353. { .id = TEGRA_IO_PAD_MIPI_BIAS, .dpd = 3, .voltage = UINT_MAX },
  1354. { .id = TEGRA_IO_PAD_PEX_BIAS, .dpd = 4, .voltage = UINT_MAX },
  1355. { .id = TEGRA_IO_PAD_PEX_CLK1, .dpd = 5, .voltage = UINT_MAX },
  1356. { .id = TEGRA_IO_PAD_PEX_CLK2, .dpd = 6, .voltage = UINT_MAX },
  1357. { .id = TEGRA_IO_PAD_PEX_CNTRL, .dpd = UINT_MAX, .voltage = 11 },
  1358. { .id = TEGRA_IO_PAD_SDMMC1, .dpd = 33, .voltage = 12 },
  1359. { .id = TEGRA_IO_PAD_SDMMC3, .dpd = 34, .voltage = 13 },
  1360. { .id = TEGRA_IO_PAD_SPI, .dpd = 46, .voltage = 22 },
  1361. { .id = TEGRA_IO_PAD_SPI_HV, .dpd = 47, .voltage = 23 },
  1362. { .id = TEGRA_IO_PAD_UART, .dpd = 14, .voltage = 2 },
  1363. { .id = TEGRA_IO_PAD_USB0, .dpd = 9, .voltage = UINT_MAX },
  1364. { .id = TEGRA_IO_PAD_USB1, .dpd = 10, .voltage = UINT_MAX },
  1365. { .id = TEGRA_IO_PAD_USB2, .dpd = 11, .voltage = UINT_MAX },
  1366. { .id = TEGRA_IO_PAD_USB3, .dpd = 18, .voltage = UINT_MAX },
  1367. { .id = TEGRA_IO_PAD_USB_BIAS, .dpd = 12, .voltage = UINT_MAX },
  1368. };
  1369. static const struct tegra_pmc_soc tegra210_pmc_soc = {
  1370. .num_powergates = ARRAY_SIZE(tegra210_powergates),
  1371. .powergates = tegra210_powergates,
  1372. .num_cpu_powergates = ARRAY_SIZE(tegra210_cpu_powergates),
  1373. .cpu_powergates = tegra210_cpu_powergates,
  1374. .has_tsense_reset = true,
  1375. .has_gpu_clamps = true,
  1376. .num_io_pads = ARRAY_SIZE(tegra210_io_pads),
  1377. .io_pads = tegra210_io_pads,
  1378. };
  1379. static const struct of_device_id tegra_pmc_match[] = {
  1380. { .compatible = "nvidia,tegra210-pmc", .data = &tegra210_pmc_soc },
  1381. { .compatible = "nvidia,tegra132-pmc", .data = &tegra124_pmc_soc },
  1382. { .compatible = "nvidia,tegra124-pmc", .data = &tegra124_pmc_soc },
  1383. { .compatible = "nvidia,tegra114-pmc", .data = &tegra114_pmc_soc },
  1384. { .compatible = "nvidia,tegra30-pmc", .data = &tegra30_pmc_soc },
  1385. { .compatible = "nvidia,tegra20-pmc", .data = &tegra20_pmc_soc },
  1386. { }
  1387. };
  1388. static struct platform_driver tegra_pmc_driver = {
  1389. .driver = {
  1390. .name = "tegra-pmc",
  1391. .suppress_bind_attrs = true,
  1392. .of_match_table = tegra_pmc_match,
  1393. #if defined(CONFIG_PM_SLEEP) && defined(CONFIG_ARM)
  1394. .pm = &tegra_pmc_pm_ops,
  1395. #endif
  1396. },
  1397. .probe = tegra_pmc_probe,
  1398. };
  1399. builtin_platform_driver(tegra_pmc_driver);
  1400. /*
  1401. * Early initialization to allow access to registers in the very early boot
  1402. * process.
  1403. */
  1404. static int __init tegra_pmc_early_init(void)
  1405. {
  1406. const struct of_device_id *match;
  1407. struct device_node *np;
  1408. struct resource regs;
  1409. bool invert;
  1410. u32 value;
  1411. mutex_init(&pmc->powergates_lock);
  1412. np = of_find_matching_node_and_match(NULL, tegra_pmc_match, &match);
  1413. if (!np) {
  1414. /*
  1415. * Fall back to legacy initialization for 32-bit ARM only. All
  1416. * 64-bit ARM device tree files for Tegra are required to have
  1417. * a PMC node.
  1418. *
  1419. * This is for backwards-compatibility with old device trees
  1420. * that didn't contain a PMC node. Note that in this case the
  1421. * SoC data can't be matched and therefore powergating is
  1422. * disabled.
  1423. */
  1424. if (IS_ENABLED(CONFIG_ARM) && soc_is_tegra()) {
  1425. pr_warn("DT node not found, powergating disabled\n");
  1426. regs.start = 0x7000e400;
  1427. regs.end = 0x7000e7ff;
  1428. regs.flags = IORESOURCE_MEM;
  1429. pr_warn("Using memory region %pR\n", &regs);
  1430. } else {
  1431. /*
  1432. * At this point we're not running on Tegra, so play
  1433. * nice with multi-platform kernels.
  1434. */
  1435. return 0;
  1436. }
  1437. } else {
  1438. /*
  1439. * Extract information from the device tree if we've found a
  1440. * matching node.
  1441. */
  1442. if (of_address_to_resource(np, 0, &regs) < 0) {
  1443. pr_err("failed to get PMC registers\n");
  1444. of_node_put(np);
  1445. return -ENXIO;
  1446. }
  1447. }
  1448. pmc->base = ioremap_nocache(regs.start, resource_size(&regs));
  1449. if (!pmc->base) {
  1450. pr_err("failed to map PMC registers\n");
  1451. of_node_put(np);
  1452. return -ENXIO;
  1453. }
  1454. if (np) {
  1455. pmc->soc = match->data;
  1456. tegra_powergate_init(pmc, np);
  1457. /*
  1458. * Invert the interrupt polarity if a PMC device tree node
  1459. * exists and contains the nvidia,invert-interrupt property.
  1460. */
  1461. invert = of_property_read_bool(np, "nvidia,invert-interrupt");
  1462. value = tegra_pmc_readl(PMC_CNTRL);
  1463. if (invert)
  1464. value |= PMC_CNTRL_INTR_POLARITY;
  1465. else
  1466. value &= ~PMC_CNTRL_INTR_POLARITY;
  1467. tegra_pmc_writel(value, PMC_CNTRL);
  1468. of_node_put(np);
  1469. }
  1470. return 0;
  1471. }
  1472. early_initcall(tegra_pmc_early_init);