pmc.c 50 KB

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