clk-dfll.c 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738
  1. /*
  2. * clk-dfll.c - Tegra DFLL clock source common code
  3. *
  4. * Copyright (C) 2012-2014 NVIDIA Corporation. All rights reserved.
  5. *
  6. * Aleksandr Frid <afrid@nvidia.com>
  7. * Paul Walmsley <pwalmsley@nvidia.com>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful, but WITHOUT
  14. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  15. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  16. * more details.
  17. *
  18. * This library is for the DVCO and DFLL IP blocks on the Tegra124
  19. * SoC. These IP blocks together are also known at NVIDIA as
  20. * "CL-DVFS". To try to avoid confusion, this code refers to them
  21. * collectively as the "DFLL."
  22. *
  23. * The DFLL is a root clocksource which tolerates some amount of
  24. * supply voltage noise. Tegra124 uses it to clock the fast CPU
  25. * complex when the target CPU speed is above a particular rate. The
  26. * DFLL can be operated in either open-loop mode or closed-loop mode.
  27. * In open-loop mode, the DFLL generates an output clock appropriate
  28. * to the supply voltage. In closed-loop mode, when configured with a
  29. * target frequency, the DFLL minimizes supply voltage while
  30. * delivering an average frequency equal to the target.
  31. *
  32. * Devices clocked by the DFLL must be able to tolerate frequency
  33. * variation. In the case of the CPU, it's important to note that the
  34. * CPU cycle time will vary. This has implications for
  35. * performance-measurement code and any code that relies on the CPU
  36. * cycle time to delay for a certain length of time.
  37. *
  38. */
  39. #include <linux/clk.h>
  40. #include <linux/clk-provider.h>
  41. #include <linux/debugfs.h>
  42. #include <linux/device.h>
  43. #include <linux/err.h>
  44. #include <linux/i2c.h>
  45. #include <linux/io.h>
  46. #include <linux/kernel.h>
  47. #include <linux/module.h>
  48. #include <linux/of.h>
  49. #include <linux/pm_opp.h>
  50. #include <linux/pm_runtime.h>
  51. #include <linux/regmap.h>
  52. #include <linux/regulator/consumer.h>
  53. #include <linux/reset.h>
  54. #include <linux/seq_file.h>
  55. #include "clk-dfll.h"
  56. #include "cvb.h"
  57. /*
  58. * DFLL control registers - access via dfll_{readl,writel}
  59. */
  60. /* DFLL_CTRL: DFLL control register */
  61. #define DFLL_CTRL 0x00
  62. #define DFLL_CTRL_MODE_MASK 0x03
  63. /* DFLL_CONFIG: DFLL sample rate control */
  64. #define DFLL_CONFIG 0x04
  65. #define DFLL_CONFIG_DIV_MASK 0xff
  66. #define DFLL_CONFIG_DIV_PRESCALE 32
  67. /* DFLL_PARAMS: tuning coefficients for closed loop integrator */
  68. #define DFLL_PARAMS 0x08
  69. #define DFLL_PARAMS_CG_SCALE (0x1 << 24)
  70. #define DFLL_PARAMS_FORCE_MODE_SHIFT 22
  71. #define DFLL_PARAMS_FORCE_MODE_MASK (0x3 << DFLL_PARAMS_FORCE_MODE_SHIFT)
  72. #define DFLL_PARAMS_CF_PARAM_SHIFT 16
  73. #define DFLL_PARAMS_CF_PARAM_MASK (0x3f << DFLL_PARAMS_CF_PARAM_SHIFT)
  74. #define DFLL_PARAMS_CI_PARAM_SHIFT 8
  75. #define DFLL_PARAMS_CI_PARAM_MASK (0x7 << DFLL_PARAMS_CI_PARAM_SHIFT)
  76. #define DFLL_PARAMS_CG_PARAM_SHIFT 0
  77. #define DFLL_PARAMS_CG_PARAM_MASK (0xff << DFLL_PARAMS_CG_PARAM_SHIFT)
  78. /* DFLL_TUNE0: delay line configuration register 0 */
  79. #define DFLL_TUNE0 0x0c
  80. /* DFLL_TUNE1: delay line configuration register 1 */
  81. #define DFLL_TUNE1 0x10
  82. /* DFLL_FREQ_REQ: target DFLL frequency control */
  83. #define DFLL_FREQ_REQ 0x14
  84. #define DFLL_FREQ_REQ_FORCE_ENABLE (0x1 << 28)
  85. #define DFLL_FREQ_REQ_FORCE_SHIFT 16
  86. #define DFLL_FREQ_REQ_FORCE_MASK (0xfff << DFLL_FREQ_REQ_FORCE_SHIFT)
  87. #define FORCE_MAX 2047
  88. #define FORCE_MIN -2048
  89. #define DFLL_FREQ_REQ_SCALE_SHIFT 8
  90. #define DFLL_FREQ_REQ_SCALE_MASK (0xff << DFLL_FREQ_REQ_SCALE_SHIFT)
  91. #define DFLL_FREQ_REQ_SCALE_MAX 256
  92. #define DFLL_FREQ_REQ_FREQ_VALID (0x1 << 7)
  93. #define DFLL_FREQ_REQ_MULT_SHIFT 0
  94. #define DFLL_FREQ_REG_MULT_MASK (0x7f << DFLL_FREQ_REQ_MULT_SHIFT)
  95. #define FREQ_MAX 127
  96. /* DFLL_DROOP_CTRL: droop prevention control */
  97. #define DFLL_DROOP_CTRL 0x1c
  98. /* DFLL_OUTPUT_CFG: closed loop mode control registers */
  99. /* NOTE: access via dfll_i2c_{readl,writel} */
  100. #define DFLL_OUTPUT_CFG 0x20
  101. #define DFLL_OUTPUT_CFG_I2C_ENABLE (0x1 << 30)
  102. #define OUT_MASK 0x3f
  103. #define DFLL_OUTPUT_CFG_SAFE_SHIFT 24
  104. #define DFLL_OUTPUT_CFG_SAFE_MASK \
  105. (OUT_MASK << DFLL_OUTPUT_CFG_SAFE_SHIFT)
  106. #define DFLL_OUTPUT_CFG_MAX_SHIFT 16
  107. #define DFLL_OUTPUT_CFG_MAX_MASK \
  108. (OUT_MASK << DFLL_OUTPUT_CFG_MAX_SHIFT)
  109. #define DFLL_OUTPUT_CFG_MIN_SHIFT 8
  110. #define DFLL_OUTPUT_CFG_MIN_MASK \
  111. (OUT_MASK << DFLL_OUTPUT_CFG_MIN_SHIFT)
  112. #define DFLL_OUTPUT_CFG_PWM_DELTA (0x1 << 7)
  113. #define DFLL_OUTPUT_CFG_PWM_ENABLE (0x1 << 6)
  114. #define DFLL_OUTPUT_CFG_PWM_DIV_SHIFT 0
  115. #define DFLL_OUTPUT_CFG_PWM_DIV_MASK \
  116. (OUT_MASK << DFLL_OUTPUT_CFG_PWM_DIV_SHIFT)
  117. /* DFLL_OUTPUT_FORCE: closed loop mode voltage forcing control */
  118. #define DFLL_OUTPUT_FORCE 0x24
  119. #define DFLL_OUTPUT_FORCE_ENABLE (0x1 << 6)
  120. #define DFLL_OUTPUT_FORCE_VALUE_SHIFT 0
  121. #define DFLL_OUTPUT_FORCE_VALUE_MASK \
  122. (OUT_MASK << DFLL_OUTPUT_FORCE_VALUE_SHIFT)
  123. /* DFLL_MONITOR_CTRL: internal monitor data source control */
  124. #define DFLL_MONITOR_CTRL 0x28
  125. #define DFLL_MONITOR_CTRL_FREQ 6
  126. /* DFLL_MONITOR_DATA: internal monitor data output */
  127. #define DFLL_MONITOR_DATA 0x2c
  128. #define DFLL_MONITOR_DATA_NEW_MASK (0x1 << 16)
  129. #define DFLL_MONITOR_DATA_VAL_SHIFT 0
  130. #define DFLL_MONITOR_DATA_VAL_MASK (0xFFFF << DFLL_MONITOR_DATA_VAL_SHIFT)
  131. /*
  132. * I2C output control registers - access via dfll_i2c_{readl,writel}
  133. */
  134. /* DFLL_I2C_CFG: I2C controller configuration register */
  135. #define DFLL_I2C_CFG 0x40
  136. #define DFLL_I2C_CFG_ARB_ENABLE (0x1 << 20)
  137. #define DFLL_I2C_CFG_HS_CODE_SHIFT 16
  138. #define DFLL_I2C_CFG_HS_CODE_MASK (0x7 << DFLL_I2C_CFG_HS_CODE_SHIFT)
  139. #define DFLL_I2C_CFG_PACKET_ENABLE (0x1 << 15)
  140. #define DFLL_I2C_CFG_SIZE_SHIFT 12
  141. #define DFLL_I2C_CFG_SIZE_MASK (0x7 << DFLL_I2C_CFG_SIZE_SHIFT)
  142. #define DFLL_I2C_CFG_SLAVE_ADDR_10 (0x1 << 10)
  143. #define DFLL_I2C_CFG_SLAVE_ADDR_SHIFT_7BIT 1
  144. #define DFLL_I2C_CFG_SLAVE_ADDR_SHIFT_10BIT 0
  145. /* DFLL_I2C_VDD_REG_ADDR: PMIC I2C address for closed loop mode */
  146. #define DFLL_I2C_VDD_REG_ADDR 0x44
  147. /* DFLL_I2C_STS: I2C controller status */
  148. #define DFLL_I2C_STS 0x48
  149. #define DFLL_I2C_STS_I2C_LAST_SHIFT 1
  150. #define DFLL_I2C_STS_I2C_REQ_PENDING 0x1
  151. /* DFLL_INTR_STS: DFLL interrupt status register */
  152. #define DFLL_INTR_STS 0x5c
  153. /* DFLL_INTR_EN: DFLL interrupt enable register */
  154. #define DFLL_INTR_EN 0x60
  155. #define DFLL_INTR_MIN_MASK 0x1
  156. #define DFLL_INTR_MAX_MASK 0x2
  157. /*
  158. * Integrated I2C controller registers - relative to td->i2c_controller_base
  159. */
  160. /* DFLL_I2C_CLK_DIVISOR: I2C controller clock divisor */
  161. #define DFLL_I2C_CLK_DIVISOR 0x6c
  162. #define DFLL_I2C_CLK_DIVISOR_MASK 0xffff
  163. #define DFLL_I2C_CLK_DIVISOR_FS_SHIFT 16
  164. #define DFLL_I2C_CLK_DIVISOR_HS_SHIFT 0
  165. #define DFLL_I2C_CLK_DIVISOR_PREDIV 8
  166. #define DFLL_I2C_CLK_DIVISOR_HSMODE_PREDIV 12
  167. /*
  168. * Other constants
  169. */
  170. /* MAX_DFLL_VOLTAGES: number of LUT entries in the DFLL IP block */
  171. #define MAX_DFLL_VOLTAGES 33
  172. /*
  173. * REF_CLK_CYC_PER_DVCO_SAMPLE: the number of ref_clk cycles that the hardware
  174. * integrates the DVCO counter over - used for debug rate monitoring and
  175. * droop control
  176. */
  177. #define REF_CLK_CYC_PER_DVCO_SAMPLE 4
  178. /*
  179. * REF_CLOCK_RATE: the DFLL reference clock rate currently supported by this
  180. * driver, in Hz
  181. */
  182. #define REF_CLOCK_RATE 51000000UL
  183. #define DVCO_RATE_TO_MULT(rate, ref_rate) ((rate) / ((ref_rate) / 2))
  184. #define MULT_TO_DVCO_RATE(mult, ref_rate) ((mult) * ((ref_rate) / 2))
  185. /**
  186. * enum dfll_ctrl_mode - DFLL hardware operating mode
  187. * @DFLL_UNINITIALIZED: (uninitialized state - not in hardware bitfield)
  188. * @DFLL_DISABLED: DFLL not generating an output clock
  189. * @DFLL_OPEN_LOOP: DVCO running, but DFLL not adjusting voltage
  190. * @DFLL_CLOSED_LOOP: DVCO running, and DFLL adjusting voltage to match
  191. * the requested rate
  192. *
  193. * The integer corresponding to the last two states, minus one, is
  194. * written to the DFLL hardware to change operating modes.
  195. */
  196. enum dfll_ctrl_mode {
  197. DFLL_UNINITIALIZED = 0,
  198. DFLL_DISABLED = 1,
  199. DFLL_OPEN_LOOP = 2,
  200. DFLL_CLOSED_LOOP = 3,
  201. };
  202. /**
  203. * enum dfll_tune_range - voltage range that the driver believes it's in
  204. * @DFLL_TUNE_UNINITIALIZED: DFLL tuning not yet programmed
  205. * @DFLL_TUNE_LOW: DFLL in the low-voltage range (or open-loop mode)
  206. *
  207. * Some DFLL tuning parameters may need to change depending on the
  208. * DVCO's voltage; these states represent the ranges that the driver
  209. * supports. These are software states; these values are never
  210. * written into registers.
  211. */
  212. enum dfll_tune_range {
  213. DFLL_TUNE_UNINITIALIZED = 0,
  214. DFLL_TUNE_LOW = 1,
  215. };
  216. /**
  217. * struct dfll_rate_req - target DFLL rate request data
  218. * @rate: target frequency, after the postscaling
  219. * @dvco_target_rate: target frequency, after the postscaling
  220. * @lut_index: LUT index at which voltage the dvco_target_rate will be reached
  221. * @mult_bits: value to program to the MULT bits of the DFLL_FREQ_REQ register
  222. * @scale_bits: value to program to the SCALE bits of the DFLL_FREQ_REQ register
  223. */
  224. struct dfll_rate_req {
  225. unsigned long rate;
  226. unsigned long dvco_target_rate;
  227. int lut_index;
  228. u8 mult_bits;
  229. u8 scale_bits;
  230. };
  231. struct tegra_dfll {
  232. struct device *dev;
  233. struct tegra_dfll_soc_data *soc;
  234. void __iomem *base;
  235. void __iomem *i2c_base;
  236. void __iomem *i2c_controller_base;
  237. void __iomem *lut_base;
  238. struct regulator *vdd_reg;
  239. struct clk *soc_clk;
  240. struct clk *ref_clk;
  241. struct clk *i2c_clk;
  242. struct clk *dfll_clk;
  243. struct reset_control *dvco_rst;
  244. unsigned long ref_rate;
  245. unsigned long i2c_clk_rate;
  246. unsigned long dvco_rate_min;
  247. enum dfll_ctrl_mode mode;
  248. enum dfll_tune_range tune_range;
  249. struct dentry *debugfs_dir;
  250. struct clk_hw dfll_clk_hw;
  251. const char *output_clock_name;
  252. struct dfll_rate_req last_req;
  253. unsigned long last_unrounded_rate;
  254. /* Parameters from DT */
  255. u32 droop_ctrl;
  256. u32 sample_rate;
  257. u32 force_mode;
  258. u32 cf;
  259. u32 ci;
  260. u32 cg;
  261. bool cg_scale;
  262. /* I2C interface parameters */
  263. u32 i2c_fs_rate;
  264. u32 i2c_reg;
  265. u32 i2c_slave_addr;
  266. /* i2c_lut array entries are regulator framework selectors */
  267. unsigned i2c_lut[MAX_DFLL_VOLTAGES];
  268. int i2c_lut_size;
  269. u8 lut_min, lut_max, lut_safe;
  270. };
  271. #define clk_hw_to_dfll(_hw) container_of(_hw, struct tegra_dfll, dfll_clk_hw)
  272. /* mode_name: map numeric DFLL modes to names for friendly console messages */
  273. static const char * const mode_name[] = {
  274. [DFLL_UNINITIALIZED] = "uninitialized",
  275. [DFLL_DISABLED] = "disabled",
  276. [DFLL_OPEN_LOOP] = "open_loop",
  277. [DFLL_CLOSED_LOOP] = "closed_loop",
  278. };
  279. /*
  280. * Register accessors
  281. */
  282. static inline u32 dfll_readl(struct tegra_dfll *td, u32 offs)
  283. {
  284. return __raw_readl(td->base + offs);
  285. }
  286. static inline void dfll_writel(struct tegra_dfll *td, u32 val, u32 offs)
  287. {
  288. WARN_ON(offs >= DFLL_I2C_CFG);
  289. __raw_writel(val, td->base + offs);
  290. }
  291. static inline void dfll_wmb(struct tegra_dfll *td)
  292. {
  293. dfll_readl(td, DFLL_CTRL);
  294. }
  295. /* I2C output control registers - for addresses above DFLL_I2C_CFG */
  296. static inline u32 dfll_i2c_readl(struct tegra_dfll *td, u32 offs)
  297. {
  298. return __raw_readl(td->i2c_base + offs);
  299. }
  300. static inline void dfll_i2c_writel(struct tegra_dfll *td, u32 val, u32 offs)
  301. {
  302. __raw_writel(val, td->i2c_base + offs);
  303. }
  304. static inline void dfll_i2c_wmb(struct tegra_dfll *td)
  305. {
  306. dfll_i2c_readl(td, DFLL_I2C_CFG);
  307. }
  308. /**
  309. * dfll_is_running - is the DFLL currently generating a clock?
  310. * @td: DFLL instance
  311. *
  312. * If the DFLL is currently generating an output clock signal, return
  313. * true; otherwise return false.
  314. */
  315. static bool dfll_is_running(struct tegra_dfll *td)
  316. {
  317. return td->mode >= DFLL_OPEN_LOOP;
  318. }
  319. /*
  320. * Runtime PM suspend/resume callbacks
  321. */
  322. /**
  323. * tegra_dfll_runtime_resume - enable all clocks needed by the DFLL
  324. * @dev: DFLL device *
  325. *
  326. * Enable all clocks needed by the DFLL. Assumes that clk_prepare()
  327. * has already been called on all the clocks.
  328. *
  329. * XXX Should also handle context restore when returning from off.
  330. */
  331. int tegra_dfll_runtime_resume(struct device *dev)
  332. {
  333. struct tegra_dfll *td = dev_get_drvdata(dev);
  334. int ret;
  335. ret = clk_enable(td->ref_clk);
  336. if (ret) {
  337. dev_err(dev, "could not enable ref clock: %d\n", ret);
  338. return ret;
  339. }
  340. ret = clk_enable(td->soc_clk);
  341. if (ret) {
  342. dev_err(dev, "could not enable register clock: %d\n", ret);
  343. clk_disable(td->ref_clk);
  344. return ret;
  345. }
  346. ret = clk_enable(td->i2c_clk);
  347. if (ret) {
  348. dev_err(dev, "could not enable i2c clock: %d\n", ret);
  349. clk_disable(td->soc_clk);
  350. clk_disable(td->ref_clk);
  351. return ret;
  352. }
  353. return 0;
  354. }
  355. EXPORT_SYMBOL(tegra_dfll_runtime_resume);
  356. /**
  357. * tegra_dfll_runtime_suspend - disable all clocks needed by the DFLL
  358. * @dev: DFLL device *
  359. *
  360. * Disable all clocks needed by the DFLL. Assumes that other code
  361. * will later call clk_unprepare().
  362. */
  363. int tegra_dfll_runtime_suspend(struct device *dev)
  364. {
  365. struct tegra_dfll *td = dev_get_drvdata(dev);
  366. clk_disable(td->ref_clk);
  367. clk_disable(td->soc_clk);
  368. clk_disable(td->i2c_clk);
  369. return 0;
  370. }
  371. EXPORT_SYMBOL(tegra_dfll_runtime_suspend);
  372. /*
  373. * DFLL tuning operations (per-voltage-range tuning settings)
  374. */
  375. /**
  376. * dfll_tune_low - tune to DFLL and CPU settings valid for any voltage
  377. * @td: DFLL instance
  378. *
  379. * Tune the DFLL oscillator parameters and the CPU clock shaper for
  380. * the low-voltage range. These settings are valid for any voltage,
  381. * but may not be optimal.
  382. */
  383. static void dfll_tune_low(struct tegra_dfll *td)
  384. {
  385. td->tune_range = DFLL_TUNE_LOW;
  386. dfll_writel(td, td->soc->cvb->cpu_dfll_data.tune0_low, DFLL_TUNE0);
  387. dfll_writel(td, td->soc->cvb->cpu_dfll_data.tune1, DFLL_TUNE1);
  388. dfll_wmb(td);
  389. if (td->soc->set_clock_trimmers_low)
  390. td->soc->set_clock_trimmers_low();
  391. }
  392. /*
  393. * Output clock scaler helpers
  394. */
  395. /**
  396. * dfll_scale_dvco_rate - calculate scaled rate from the DVCO rate
  397. * @scale_bits: clock scaler value (bits in the DFLL_FREQ_REQ_SCALE field)
  398. * @dvco_rate: the DVCO rate
  399. *
  400. * Apply the same scaling formula that the DFLL hardware uses to scale
  401. * the DVCO rate.
  402. */
  403. static unsigned long dfll_scale_dvco_rate(int scale_bits,
  404. unsigned long dvco_rate)
  405. {
  406. return (u64)dvco_rate * (scale_bits + 1) / DFLL_FREQ_REQ_SCALE_MAX;
  407. }
  408. /*
  409. * DFLL mode switching
  410. */
  411. /**
  412. * dfll_set_mode - change the DFLL control mode
  413. * @td: DFLL instance
  414. * @mode: DFLL control mode (see enum dfll_ctrl_mode)
  415. *
  416. * Change the DFLL's operating mode between disabled, open-loop mode,
  417. * and closed-loop mode, or vice versa.
  418. */
  419. static void dfll_set_mode(struct tegra_dfll *td,
  420. enum dfll_ctrl_mode mode)
  421. {
  422. td->mode = mode;
  423. dfll_writel(td, mode - 1, DFLL_CTRL);
  424. dfll_wmb(td);
  425. }
  426. /*
  427. * DFLL-to-I2C controller interface
  428. */
  429. /**
  430. * dfll_i2c_set_output_enabled - enable/disable I2C PMIC voltage requests
  431. * @td: DFLL instance
  432. * @enable: whether to enable or disable the I2C voltage requests
  433. *
  434. * Set the master enable control for I2C control value updates. If disabled,
  435. * then I2C control messages are inhibited, regardless of the DFLL mode.
  436. */
  437. static int dfll_i2c_set_output_enabled(struct tegra_dfll *td, bool enable)
  438. {
  439. u32 val;
  440. val = dfll_i2c_readl(td, DFLL_OUTPUT_CFG);
  441. if (enable)
  442. val |= DFLL_OUTPUT_CFG_I2C_ENABLE;
  443. else
  444. val &= ~DFLL_OUTPUT_CFG_I2C_ENABLE;
  445. dfll_i2c_writel(td, val, DFLL_OUTPUT_CFG);
  446. dfll_i2c_wmb(td);
  447. return 0;
  448. }
  449. /**
  450. * dfll_load_lut - load the voltage lookup table
  451. * @td: struct tegra_dfll *
  452. *
  453. * Load the voltage-to-PMIC register value lookup table into the DFLL
  454. * IP block memory. Look-up tables can be loaded at any time.
  455. */
  456. static void dfll_load_i2c_lut(struct tegra_dfll *td)
  457. {
  458. int i, lut_index;
  459. u32 val;
  460. for (i = 0; i < MAX_DFLL_VOLTAGES; i++) {
  461. if (i < td->lut_min)
  462. lut_index = td->lut_min;
  463. else if (i > td->lut_max)
  464. lut_index = td->lut_max;
  465. else
  466. lut_index = i;
  467. val = regulator_list_hardware_vsel(td->vdd_reg,
  468. td->i2c_lut[lut_index]);
  469. __raw_writel(val, td->lut_base + i * 4);
  470. }
  471. dfll_i2c_wmb(td);
  472. }
  473. /**
  474. * dfll_init_i2c_if - set up the DFLL's DFLL-I2C interface
  475. * @td: DFLL instance
  476. *
  477. * During DFLL driver initialization, program the DFLL-I2C interface
  478. * with the PMU slave address, vdd register offset, and transfer mode.
  479. * This data is used by the DFLL to automatically construct I2C
  480. * voltage-set commands, which are then passed to the DFLL's internal
  481. * I2C controller.
  482. */
  483. static void dfll_init_i2c_if(struct tegra_dfll *td)
  484. {
  485. u32 val;
  486. if (td->i2c_slave_addr > 0x7f) {
  487. val = td->i2c_slave_addr << DFLL_I2C_CFG_SLAVE_ADDR_SHIFT_10BIT;
  488. val |= DFLL_I2C_CFG_SLAVE_ADDR_10;
  489. } else {
  490. val = td->i2c_slave_addr << DFLL_I2C_CFG_SLAVE_ADDR_SHIFT_7BIT;
  491. }
  492. val |= DFLL_I2C_CFG_SIZE_MASK;
  493. val |= DFLL_I2C_CFG_ARB_ENABLE;
  494. dfll_i2c_writel(td, val, DFLL_I2C_CFG);
  495. dfll_i2c_writel(td, td->i2c_reg, DFLL_I2C_VDD_REG_ADDR);
  496. val = DIV_ROUND_UP(td->i2c_clk_rate, td->i2c_fs_rate * 8);
  497. BUG_ON(!val || (val > DFLL_I2C_CLK_DIVISOR_MASK));
  498. val = (val - 1) << DFLL_I2C_CLK_DIVISOR_FS_SHIFT;
  499. /* default hs divisor just in case */
  500. val |= 1 << DFLL_I2C_CLK_DIVISOR_HS_SHIFT;
  501. __raw_writel(val, td->i2c_controller_base + DFLL_I2C_CLK_DIVISOR);
  502. dfll_i2c_wmb(td);
  503. }
  504. /**
  505. * dfll_init_out_if - prepare DFLL-to-PMIC interface
  506. * @td: DFLL instance
  507. *
  508. * During DFLL driver initialization or resume from context loss,
  509. * disable the I2C command output to the PMIC, set safe voltage and
  510. * output limits, and disable and clear limit interrupts.
  511. */
  512. static void dfll_init_out_if(struct tegra_dfll *td)
  513. {
  514. u32 val;
  515. td->lut_min = 0;
  516. td->lut_max = td->i2c_lut_size - 1;
  517. td->lut_safe = td->lut_min + 1;
  518. dfll_i2c_writel(td, 0, DFLL_OUTPUT_CFG);
  519. val = (td->lut_safe << DFLL_OUTPUT_CFG_SAFE_SHIFT) |
  520. (td->lut_max << DFLL_OUTPUT_CFG_MAX_SHIFT) |
  521. (td->lut_min << DFLL_OUTPUT_CFG_MIN_SHIFT);
  522. dfll_i2c_writel(td, val, DFLL_OUTPUT_CFG);
  523. dfll_i2c_wmb(td);
  524. dfll_writel(td, 0, DFLL_OUTPUT_FORCE);
  525. dfll_i2c_writel(td, 0, DFLL_INTR_EN);
  526. dfll_i2c_writel(td, DFLL_INTR_MAX_MASK | DFLL_INTR_MIN_MASK,
  527. DFLL_INTR_STS);
  528. dfll_load_i2c_lut(td);
  529. dfll_init_i2c_if(td);
  530. }
  531. /*
  532. * Set/get the DFLL's targeted output clock rate
  533. */
  534. /**
  535. * find_lut_index_for_rate - determine I2C LUT index for given DFLL rate
  536. * @td: DFLL instance
  537. * @rate: clock rate
  538. *
  539. * Determines the index of a I2C LUT entry for a voltage that approximately
  540. * produces the given DFLL clock rate. This is used when forcing a value
  541. * to the integrator during rate changes. Returns -ENOENT if a suitable
  542. * LUT index is not found.
  543. */
  544. static int find_lut_index_for_rate(struct tegra_dfll *td, unsigned long rate)
  545. {
  546. struct dev_pm_opp *opp;
  547. int i, uv;
  548. opp = dev_pm_opp_find_freq_ceil(td->soc->dev, &rate);
  549. if (IS_ERR(opp))
  550. return PTR_ERR(opp);
  551. uv = dev_pm_opp_get_voltage(opp);
  552. dev_pm_opp_put(opp);
  553. for (i = 0; i < td->i2c_lut_size; i++) {
  554. if (regulator_list_voltage(td->vdd_reg, td->i2c_lut[i]) == uv)
  555. return i;
  556. }
  557. return -ENOENT;
  558. }
  559. /**
  560. * dfll_calculate_rate_request - calculate DFLL parameters for a given rate
  561. * @td: DFLL instance
  562. * @req: DFLL-rate-request structure
  563. * @rate: the desired DFLL rate
  564. *
  565. * Populate the DFLL-rate-request record @req fields with the scale_bits
  566. * and mult_bits fields, based on the target input rate. Returns 0 upon
  567. * success, or -EINVAL if the requested rate in req->rate is too high
  568. * or low for the DFLL to generate.
  569. */
  570. static int dfll_calculate_rate_request(struct tegra_dfll *td,
  571. struct dfll_rate_req *req,
  572. unsigned long rate)
  573. {
  574. u32 val;
  575. /*
  576. * If requested rate is below the minimum DVCO rate, active the scaler.
  577. * In the future the DVCO minimum voltage should be selected based on
  578. * chip temperature and the actual minimum rate should be calibrated
  579. * at runtime.
  580. */
  581. req->scale_bits = DFLL_FREQ_REQ_SCALE_MAX - 1;
  582. if (rate < td->dvco_rate_min) {
  583. int scale;
  584. scale = DIV_ROUND_CLOSEST(rate / 1000 * DFLL_FREQ_REQ_SCALE_MAX,
  585. td->dvco_rate_min / 1000);
  586. if (!scale) {
  587. dev_err(td->dev, "%s: Rate %lu is too low\n",
  588. __func__, rate);
  589. return -EINVAL;
  590. }
  591. req->scale_bits = scale - 1;
  592. rate = td->dvco_rate_min;
  593. }
  594. /* Convert requested rate into frequency request and scale settings */
  595. val = DVCO_RATE_TO_MULT(rate, td->ref_rate);
  596. if (val > FREQ_MAX) {
  597. dev_err(td->dev, "%s: Rate %lu is above dfll range\n",
  598. __func__, rate);
  599. return -EINVAL;
  600. }
  601. req->mult_bits = val;
  602. req->dvco_target_rate = MULT_TO_DVCO_RATE(req->mult_bits, td->ref_rate);
  603. req->rate = dfll_scale_dvco_rate(req->scale_bits,
  604. req->dvco_target_rate);
  605. req->lut_index = find_lut_index_for_rate(td, req->dvco_target_rate);
  606. if (req->lut_index < 0)
  607. return req->lut_index;
  608. return 0;
  609. }
  610. /**
  611. * dfll_set_frequency_request - start the frequency change operation
  612. * @td: DFLL instance
  613. * @req: rate request structure
  614. *
  615. * Tell the DFLL to try to change its output frequency to the
  616. * frequency represented by @req. DFLL must be in closed-loop mode.
  617. */
  618. static void dfll_set_frequency_request(struct tegra_dfll *td,
  619. struct dfll_rate_req *req)
  620. {
  621. u32 val = 0;
  622. int force_val;
  623. int coef = 128; /* FIXME: td->cg_scale? */;
  624. force_val = (req->lut_index - td->lut_safe) * coef / td->cg;
  625. force_val = clamp(force_val, FORCE_MIN, FORCE_MAX);
  626. val |= req->mult_bits << DFLL_FREQ_REQ_MULT_SHIFT;
  627. val |= req->scale_bits << DFLL_FREQ_REQ_SCALE_SHIFT;
  628. val |= ((u32)force_val << DFLL_FREQ_REQ_FORCE_SHIFT) &
  629. DFLL_FREQ_REQ_FORCE_MASK;
  630. val |= DFLL_FREQ_REQ_FREQ_VALID | DFLL_FREQ_REQ_FORCE_ENABLE;
  631. dfll_writel(td, val, DFLL_FREQ_REQ);
  632. dfll_wmb(td);
  633. }
  634. /**
  635. * tegra_dfll_request_rate - set the next rate for the DFLL to tune to
  636. * @td: DFLL instance
  637. * @rate: clock rate to target
  638. *
  639. * Convert the requested clock rate @rate into the DFLL control logic
  640. * settings. In closed-loop mode, update new settings immediately to
  641. * adjust DFLL output rate accordingly. Otherwise, just save them
  642. * until the next switch to closed loop. Returns 0 upon success,
  643. * -EPERM if the DFLL driver has not yet been initialized, or -EINVAL
  644. * if @rate is outside the DFLL's tunable range.
  645. */
  646. static int dfll_request_rate(struct tegra_dfll *td, unsigned long rate)
  647. {
  648. int ret;
  649. struct dfll_rate_req req;
  650. if (td->mode == DFLL_UNINITIALIZED) {
  651. dev_err(td->dev, "%s: Cannot set DFLL rate in %s mode\n",
  652. __func__, mode_name[td->mode]);
  653. return -EPERM;
  654. }
  655. ret = dfll_calculate_rate_request(td, &req, rate);
  656. if (ret)
  657. return ret;
  658. td->last_unrounded_rate = rate;
  659. td->last_req = req;
  660. if (td->mode == DFLL_CLOSED_LOOP)
  661. dfll_set_frequency_request(td, &td->last_req);
  662. return 0;
  663. }
  664. /*
  665. * DFLL enable/disable & open-loop <-> closed-loop transitions
  666. */
  667. /**
  668. * dfll_disable - switch from open-loop mode to disabled mode
  669. * @td: DFLL instance
  670. *
  671. * Switch from OPEN_LOOP state to DISABLED state. Returns 0 upon success
  672. * or -EPERM if the DFLL is not currently in open-loop mode.
  673. */
  674. static int dfll_disable(struct tegra_dfll *td)
  675. {
  676. if (td->mode != DFLL_OPEN_LOOP) {
  677. dev_err(td->dev, "cannot disable DFLL in %s mode\n",
  678. mode_name[td->mode]);
  679. return -EINVAL;
  680. }
  681. dfll_set_mode(td, DFLL_DISABLED);
  682. pm_runtime_put_sync(td->dev);
  683. return 0;
  684. }
  685. /**
  686. * dfll_enable - switch a disabled DFLL to open-loop mode
  687. * @td: DFLL instance
  688. *
  689. * Switch from DISABLED state to OPEN_LOOP state. Returns 0 upon success
  690. * or -EPERM if the DFLL is not currently disabled.
  691. */
  692. static int dfll_enable(struct tegra_dfll *td)
  693. {
  694. if (td->mode != DFLL_DISABLED) {
  695. dev_err(td->dev, "cannot enable DFLL in %s mode\n",
  696. mode_name[td->mode]);
  697. return -EPERM;
  698. }
  699. pm_runtime_get_sync(td->dev);
  700. dfll_set_mode(td, DFLL_OPEN_LOOP);
  701. return 0;
  702. }
  703. /**
  704. * dfll_set_open_loop_config - prepare to switch to open-loop mode
  705. * @td: DFLL instance
  706. *
  707. * Prepare to switch the DFLL to open-loop mode. This switches the
  708. * DFLL to the low-voltage tuning range, ensures that I2C output
  709. * forcing is disabled, and disables the output clock rate scaler.
  710. * The DFLL's low-voltage tuning range parameters must be
  711. * characterized to keep the downstream device stable at any DVCO
  712. * input voltage. No return value.
  713. */
  714. static void dfll_set_open_loop_config(struct tegra_dfll *td)
  715. {
  716. u32 val;
  717. /* always tune low (safe) in open loop */
  718. if (td->tune_range != DFLL_TUNE_LOW)
  719. dfll_tune_low(td);
  720. val = dfll_readl(td, DFLL_FREQ_REQ);
  721. val |= DFLL_FREQ_REQ_SCALE_MASK;
  722. val &= ~DFLL_FREQ_REQ_FORCE_ENABLE;
  723. dfll_writel(td, val, DFLL_FREQ_REQ);
  724. dfll_wmb(td);
  725. }
  726. /**
  727. * tegra_dfll_lock - switch from open-loop to closed-loop mode
  728. * @td: DFLL instance
  729. *
  730. * Switch from OPEN_LOOP state to CLOSED_LOOP state. Returns 0 upon success,
  731. * -EINVAL if the DFLL's target rate hasn't been set yet, or -EPERM if the
  732. * DFLL is not currently in open-loop mode.
  733. */
  734. static int dfll_lock(struct tegra_dfll *td)
  735. {
  736. struct dfll_rate_req *req = &td->last_req;
  737. switch (td->mode) {
  738. case DFLL_CLOSED_LOOP:
  739. return 0;
  740. case DFLL_OPEN_LOOP:
  741. if (req->rate == 0) {
  742. dev_err(td->dev, "%s: Cannot lock DFLL at rate 0\n",
  743. __func__);
  744. return -EINVAL;
  745. }
  746. dfll_i2c_set_output_enabled(td, true);
  747. dfll_set_mode(td, DFLL_CLOSED_LOOP);
  748. dfll_set_frequency_request(td, req);
  749. return 0;
  750. default:
  751. BUG_ON(td->mode > DFLL_CLOSED_LOOP);
  752. dev_err(td->dev, "%s: Cannot lock DFLL in %s mode\n",
  753. __func__, mode_name[td->mode]);
  754. return -EPERM;
  755. }
  756. }
  757. /**
  758. * tegra_dfll_unlock - switch from closed-loop to open-loop mode
  759. * @td: DFLL instance
  760. *
  761. * Switch from CLOSED_LOOP state to OPEN_LOOP state. Returns 0 upon success,
  762. * or -EPERM if the DFLL is not currently in open-loop mode.
  763. */
  764. static int dfll_unlock(struct tegra_dfll *td)
  765. {
  766. switch (td->mode) {
  767. case DFLL_CLOSED_LOOP:
  768. dfll_set_open_loop_config(td);
  769. dfll_set_mode(td, DFLL_OPEN_LOOP);
  770. dfll_i2c_set_output_enabled(td, false);
  771. return 0;
  772. case DFLL_OPEN_LOOP:
  773. return 0;
  774. default:
  775. BUG_ON(td->mode > DFLL_CLOSED_LOOP);
  776. dev_err(td->dev, "%s: Cannot unlock DFLL in %s mode\n",
  777. __func__, mode_name[td->mode]);
  778. return -EPERM;
  779. }
  780. }
  781. /*
  782. * Clock framework integration
  783. *
  784. * When the DFLL is being controlled by the CCF, always enter closed loop
  785. * mode when the clk is enabled. This requires that a DFLL rate request
  786. * has been set beforehand, which implies that a clk_set_rate() call is
  787. * always required before a clk_enable().
  788. */
  789. static int dfll_clk_is_enabled(struct clk_hw *hw)
  790. {
  791. struct tegra_dfll *td = clk_hw_to_dfll(hw);
  792. return dfll_is_running(td);
  793. }
  794. static int dfll_clk_enable(struct clk_hw *hw)
  795. {
  796. struct tegra_dfll *td = clk_hw_to_dfll(hw);
  797. int ret;
  798. ret = dfll_enable(td);
  799. if (ret)
  800. return ret;
  801. ret = dfll_lock(td);
  802. if (ret)
  803. dfll_disable(td);
  804. return ret;
  805. }
  806. static void dfll_clk_disable(struct clk_hw *hw)
  807. {
  808. struct tegra_dfll *td = clk_hw_to_dfll(hw);
  809. int ret;
  810. ret = dfll_unlock(td);
  811. if (!ret)
  812. dfll_disable(td);
  813. }
  814. static unsigned long dfll_clk_recalc_rate(struct clk_hw *hw,
  815. unsigned long parent_rate)
  816. {
  817. struct tegra_dfll *td = clk_hw_to_dfll(hw);
  818. return td->last_unrounded_rate;
  819. }
  820. /* Must use determine_rate since it allows for rates exceeding 2^31-1 */
  821. static int dfll_clk_determine_rate(struct clk_hw *hw,
  822. struct clk_rate_request *clk_req)
  823. {
  824. struct tegra_dfll *td = clk_hw_to_dfll(hw);
  825. struct dfll_rate_req req;
  826. int ret;
  827. ret = dfll_calculate_rate_request(td, &req, clk_req->rate);
  828. if (ret)
  829. return ret;
  830. /*
  831. * Don't set the rounded rate, since it doesn't really matter as
  832. * the output rate will be voltage controlled anyway, and cpufreq
  833. * freaks out if any rounding happens.
  834. */
  835. return 0;
  836. }
  837. static int dfll_clk_set_rate(struct clk_hw *hw, unsigned long rate,
  838. unsigned long parent_rate)
  839. {
  840. struct tegra_dfll *td = clk_hw_to_dfll(hw);
  841. return dfll_request_rate(td, rate);
  842. }
  843. static const struct clk_ops dfll_clk_ops = {
  844. .is_enabled = dfll_clk_is_enabled,
  845. .enable = dfll_clk_enable,
  846. .disable = dfll_clk_disable,
  847. .recalc_rate = dfll_clk_recalc_rate,
  848. .determine_rate = dfll_clk_determine_rate,
  849. .set_rate = dfll_clk_set_rate,
  850. };
  851. static struct clk_init_data dfll_clk_init_data = {
  852. .ops = &dfll_clk_ops,
  853. .num_parents = 0,
  854. };
  855. /**
  856. * dfll_register_clk - register the DFLL output clock with the clock framework
  857. * @td: DFLL instance
  858. *
  859. * Register the DFLL's output clock with the Linux clock framework and register
  860. * the DFLL driver as an OF clock provider. Returns 0 upon success or -EINVAL
  861. * or -ENOMEM upon failure.
  862. */
  863. static int dfll_register_clk(struct tegra_dfll *td)
  864. {
  865. int ret;
  866. dfll_clk_init_data.name = td->output_clock_name;
  867. td->dfll_clk_hw.init = &dfll_clk_init_data;
  868. td->dfll_clk = clk_register(td->dev, &td->dfll_clk_hw);
  869. if (IS_ERR(td->dfll_clk)) {
  870. dev_err(td->dev, "DFLL clock registration error\n");
  871. return -EINVAL;
  872. }
  873. ret = of_clk_add_provider(td->dev->of_node, of_clk_src_simple_get,
  874. td->dfll_clk);
  875. if (ret) {
  876. dev_err(td->dev, "of_clk_add_provider() failed\n");
  877. clk_unregister(td->dfll_clk);
  878. return ret;
  879. }
  880. return 0;
  881. }
  882. /**
  883. * dfll_unregister_clk - unregister the DFLL output clock
  884. * @td: DFLL instance
  885. *
  886. * Unregister the DFLL's output clock from the Linux clock framework
  887. * and from clkdev. No return value.
  888. */
  889. static void dfll_unregister_clk(struct tegra_dfll *td)
  890. {
  891. of_clk_del_provider(td->dev->of_node);
  892. clk_unregister(td->dfll_clk);
  893. td->dfll_clk = NULL;
  894. }
  895. /*
  896. * Debugfs interface
  897. */
  898. #ifdef CONFIG_DEBUG_FS
  899. /*
  900. * Monitor control
  901. */
  902. /**
  903. * dfll_calc_monitored_rate - convert DFLL_MONITOR_DATA_VAL rate into real freq
  904. * @monitor_data: value read from the DFLL_MONITOR_DATA_VAL bitfield
  905. * @ref_rate: DFLL reference clock rate
  906. *
  907. * Convert @monitor_data from DFLL_MONITOR_DATA_VAL units into cycles
  908. * per second. Returns the converted value.
  909. */
  910. static u64 dfll_calc_monitored_rate(u32 monitor_data,
  911. unsigned long ref_rate)
  912. {
  913. return monitor_data * (ref_rate / REF_CLK_CYC_PER_DVCO_SAMPLE);
  914. }
  915. /**
  916. * dfll_read_monitor_rate - return the DFLL's output rate from internal monitor
  917. * @td: DFLL instance
  918. *
  919. * If the DFLL is enabled, return the last rate reported by the DFLL's
  920. * internal monitoring hardware. This works in both open-loop and
  921. * closed-loop mode, and takes the output scaler setting into account.
  922. * Assumes that the monitor was programmed to monitor frequency before
  923. * the sample period started. If the driver believes that the DFLL is
  924. * currently uninitialized or disabled, it will return 0, since
  925. * otherwise the DFLL monitor data register will return the last
  926. * measured rate from when the DFLL was active.
  927. */
  928. static u64 dfll_read_monitor_rate(struct tegra_dfll *td)
  929. {
  930. u32 v, s;
  931. u64 pre_scaler_rate, post_scaler_rate;
  932. if (!dfll_is_running(td))
  933. return 0;
  934. v = dfll_readl(td, DFLL_MONITOR_DATA);
  935. v = (v & DFLL_MONITOR_DATA_VAL_MASK) >> DFLL_MONITOR_DATA_VAL_SHIFT;
  936. pre_scaler_rate = dfll_calc_monitored_rate(v, td->ref_rate);
  937. s = dfll_readl(td, DFLL_FREQ_REQ);
  938. s = (s & DFLL_FREQ_REQ_SCALE_MASK) >> DFLL_FREQ_REQ_SCALE_SHIFT;
  939. post_scaler_rate = dfll_scale_dvco_rate(s, pre_scaler_rate);
  940. return post_scaler_rate;
  941. }
  942. static int attr_enable_get(void *data, u64 *val)
  943. {
  944. struct tegra_dfll *td = data;
  945. *val = dfll_is_running(td);
  946. return 0;
  947. }
  948. static int attr_enable_set(void *data, u64 val)
  949. {
  950. struct tegra_dfll *td = data;
  951. return val ? dfll_enable(td) : dfll_disable(td);
  952. }
  953. DEFINE_SIMPLE_ATTRIBUTE(enable_fops, attr_enable_get, attr_enable_set,
  954. "%llu\n");
  955. static int attr_lock_get(void *data, u64 *val)
  956. {
  957. struct tegra_dfll *td = data;
  958. *val = (td->mode == DFLL_CLOSED_LOOP);
  959. return 0;
  960. }
  961. static int attr_lock_set(void *data, u64 val)
  962. {
  963. struct tegra_dfll *td = data;
  964. return val ? dfll_lock(td) : dfll_unlock(td);
  965. }
  966. DEFINE_SIMPLE_ATTRIBUTE(lock_fops, attr_lock_get, attr_lock_set,
  967. "%llu\n");
  968. static int attr_rate_get(void *data, u64 *val)
  969. {
  970. struct tegra_dfll *td = data;
  971. *val = dfll_read_monitor_rate(td);
  972. return 0;
  973. }
  974. static int attr_rate_set(void *data, u64 val)
  975. {
  976. struct tegra_dfll *td = data;
  977. return dfll_request_rate(td, val);
  978. }
  979. DEFINE_SIMPLE_ATTRIBUTE(rate_fops, attr_rate_get, attr_rate_set, "%llu\n");
  980. static int attr_registers_show(struct seq_file *s, void *data)
  981. {
  982. u32 val, offs;
  983. struct tegra_dfll *td = s->private;
  984. seq_puts(s, "CONTROL REGISTERS:\n");
  985. for (offs = 0; offs <= DFLL_MONITOR_DATA; offs += 4) {
  986. if (offs == DFLL_OUTPUT_CFG)
  987. val = dfll_i2c_readl(td, offs);
  988. else
  989. val = dfll_readl(td, offs);
  990. seq_printf(s, "[0x%02x] = 0x%08x\n", offs, val);
  991. }
  992. seq_puts(s, "\nI2C and INTR REGISTERS:\n");
  993. for (offs = DFLL_I2C_CFG; offs <= DFLL_I2C_STS; offs += 4)
  994. seq_printf(s, "[0x%02x] = 0x%08x\n", offs,
  995. dfll_i2c_readl(td, offs));
  996. for (offs = DFLL_INTR_STS; offs <= DFLL_INTR_EN; offs += 4)
  997. seq_printf(s, "[0x%02x] = 0x%08x\n", offs,
  998. dfll_i2c_readl(td, offs));
  999. seq_puts(s, "\nINTEGRATED I2C CONTROLLER REGISTERS:\n");
  1000. offs = DFLL_I2C_CLK_DIVISOR;
  1001. seq_printf(s, "[0x%02x] = 0x%08x\n", offs,
  1002. __raw_readl(td->i2c_controller_base + offs));
  1003. seq_puts(s, "\nLUT:\n");
  1004. for (offs = 0; offs < 4 * MAX_DFLL_VOLTAGES; offs += 4)
  1005. seq_printf(s, "[0x%02x] = 0x%08x\n", offs,
  1006. __raw_readl(td->lut_base + offs));
  1007. return 0;
  1008. }
  1009. static int attr_registers_open(struct inode *inode, struct file *file)
  1010. {
  1011. return single_open(file, attr_registers_show, inode->i_private);
  1012. }
  1013. static const struct file_operations attr_registers_fops = {
  1014. .open = attr_registers_open,
  1015. .read = seq_read,
  1016. .llseek = seq_lseek,
  1017. .release = single_release,
  1018. };
  1019. static void dfll_debug_init(struct tegra_dfll *td)
  1020. {
  1021. struct dentry *root;
  1022. if (!td || (td->mode == DFLL_UNINITIALIZED))
  1023. return;
  1024. root = debugfs_create_dir("tegra_dfll_fcpu", NULL);
  1025. td->debugfs_dir = root;
  1026. debugfs_create_file("enable", S_IRUGO | S_IWUSR, root, td, &enable_fops);
  1027. debugfs_create_file("lock", S_IRUGO, root, td, &lock_fops);
  1028. debugfs_create_file("rate", S_IRUGO, root, td, &rate_fops);
  1029. debugfs_create_file("registers", S_IRUGO, root, td, &attr_registers_fops);
  1030. }
  1031. #else
  1032. static void inline dfll_debug_init(struct tegra_dfll *td) { }
  1033. #endif /* CONFIG_DEBUG_FS */
  1034. /*
  1035. * DFLL initialization
  1036. */
  1037. /**
  1038. * dfll_set_default_params - program non-output related DFLL parameters
  1039. * @td: DFLL instance
  1040. *
  1041. * During DFLL driver initialization or resume from context loss,
  1042. * program parameters for the closed loop integrator, DVCO tuning,
  1043. * voltage droop control and monitor control.
  1044. */
  1045. static void dfll_set_default_params(struct tegra_dfll *td)
  1046. {
  1047. u32 val;
  1048. val = DIV_ROUND_UP(td->ref_rate, td->sample_rate * 32);
  1049. BUG_ON(val > DFLL_CONFIG_DIV_MASK);
  1050. dfll_writel(td, val, DFLL_CONFIG);
  1051. val = (td->force_mode << DFLL_PARAMS_FORCE_MODE_SHIFT) |
  1052. (td->cf << DFLL_PARAMS_CF_PARAM_SHIFT) |
  1053. (td->ci << DFLL_PARAMS_CI_PARAM_SHIFT) |
  1054. (td->cg << DFLL_PARAMS_CG_PARAM_SHIFT) |
  1055. (td->cg_scale ? DFLL_PARAMS_CG_SCALE : 0);
  1056. dfll_writel(td, val, DFLL_PARAMS);
  1057. dfll_tune_low(td);
  1058. dfll_writel(td, td->droop_ctrl, DFLL_DROOP_CTRL);
  1059. dfll_writel(td, DFLL_MONITOR_CTRL_FREQ, DFLL_MONITOR_CTRL);
  1060. }
  1061. /**
  1062. * dfll_init_clks - clk_get() the DFLL source clocks
  1063. * @td: DFLL instance
  1064. *
  1065. * Call clk_get() on the DFLL source clocks and save the pointers for later
  1066. * use. Returns 0 upon success or error (see devm_clk_get) if one or more
  1067. * of the clocks couldn't be looked up.
  1068. */
  1069. static int dfll_init_clks(struct tegra_dfll *td)
  1070. {
  1071. td->ref_clk = devm_clk_get(td->dev, "ref");
  1072. if (IS_ERR(td->ref_clk)) {
  1073. dev_err(td->dev, "missing ref clock\n");
  1074. return PTR_ERR(td->ref_clk);
  1075. }
  1076. td->soc_clk = devm_clk_get(td->dev, "soc");
  1077. if (IS_ERR(td->soc_clk)) {
  1078. dev_err(td->dev, "missing soc clock\n");
  1079. return PTR_ERR(td->soc_clk);
  1080. }
  1081. td->i2c_clk = devm_clk_get(td->dev, "i2c");
  1082. if (IS_ERR(td->i2c_clk)) {
  1083. dev_err(td->dev, "missing i2c clock\n");
  1084. return PTR_ERR(td->i2c_clk);
  1085. }
  1086. td->i2c_clk_rate = clk_get_rate(td->i2c_clk);
  1087. return 0;
  1088. }
  1089. /**
  1090. * dfll_init - Prepare the DFLL IP block for use
  1091. * @td: DFLL instance
  1092. *
  1093. * Do everything necessary to prepare the DFLL IP block for use. The
  1094. * DFLL will be left in DISABLED state. Called by dfll_probe().
  1095. * Returns 0 upon success, or passes along the error from whatever
  1096. * function returned it.
  1097. */
  1098. static int dfll_init(struct tegra_dfll *td)
  1099. {
  1100. int ret;
  1101. td->ref_rate = clk_get_rate(td->ref_clk);
  1102. if (td->ref_rate != REF_CLOCK_RATE) {
  1103. dev_err(td->dev, "unexpected ref clk rate %lu, expecting %lu",
  1104. td->ref_rate, REF_CLOCK_RATE);
  1105. return -EINVAL;
  1106. }
  1107. reset_control_deassert(td->dvco_rst);
  1108. ret = clk_prepare(td->ref_clk);
  1109. if (ret) {
  1110. dev_err(td->dev, "failed to prepare ref_clk\n");
  1111. return ret;
  1112. }
  1113. ret = clk_prepare(td->soc_clk);
  1114. if (ret) {
  1115. dev_err(td->dev, "failed to prepare soc_clk\n");
  1116. goto di_err1;
  1117. }
  1118. ret = clk_prepare(td->i2c_clk);
  1119. if (ret) {
  1120. dev_err(td->dev, "failed to prepare i2c_clk\n");
  1121. goto di_err2;
  1122. }
  1123. td->last_unrounded_rate = 0;
  1124. pm_runtime_enable(td->dev);
  1125. pm_runtime_get_sync(td->dev);
  1126. dfll_set_mode(td, DFLL_DISABLED);
  1127. dfll_set_default_params(td);
  1128. if (td->soc->init_clock_trimmers)
  1129. td->soc->init_clock_trimmers();
  1130. dfll_set_open_loop_config(td);
  1131. dfll_init_out_if(td);
  1132. pm_runtime_put_sync(td->dev);
  1133. return 0;
  1134. di_err2:
  1135. clk_unprepare(td->soc_clk);
  1136. di_err1:
  1137. clk_unprepare(td->ref_clk);
  1138. reset_control_assert(td->dvco_rst);
  1139. return ret;
  1140. }
  1141. /*
  1142. * DT data fetch
  1143. */
  1144. /*
  1145. * Find a PMIC voltage register-to-voltage mapping for the given voltage.
  1146. * An exact voltage match is required.
  1147. */
  1148. static int find_vdd_map_entry_exact(struct tegra_dfll *td, int uV)
  1149. {
  1150. int i, n_voltages, reg_uV;
  1151. n_voltages = regulator_count_voltages(td->vdd_reg);
  1152. for (i = 0; i < n_voltages; i++) {
  1153. reg_uV = regulator_list_voltage(td->vdd_reg, i);
  1154. if (reg_uV < 0)
  1155. break;
  1156. if (uV == reg_uV)
  1157. return i;
  1158. }
  1159. dev_err(td->dev, "no voltage map entry for %d uV\n", uV);
  1160. return -EINVAL;
  1161. }
  1162. /*
  1163. * Find a PMIC voltage register-to-voltage mapping for the given voltage,
  1164. * rounding up to the closest supported voltage.
  1165. * */
  1166. static int find_vdd_map_entry_min(struct tegra_dfll *td, int uV)
  1167. {
  1168. int i, n_voltages, reg_uV;
  1169. n_voltages = regulator_count_voltages(td->vdd_reg);
  1170. for (i = 0; i < n_voltages; i++) {
  1171. reg_uV = regulator_list_voltage(td->vdd_reg, i);
  1172. if (reg_uV < 0)
  1173. break;
  1174. if (uV <= reg_uV)
  1175. return i;
  1176. }
  1177. dev_err(td->dev, "no voltage map entry rounding to %d uV\n", uV);
  1178. return -EINVAL;
  1179. }
  1180. /**
  1181. * dfll_build_i2c_lut - build the I2C voltage register lookup table
  1182. * @td: DFLL instance
  1183. *
  1184. * The DFLL hardware has 33 bytes of look-up table RAM that must be filled with
  1185. * PMIC voltage register values that span the entire DFLL operating range.
  1186. * This function builds the look-up table based on the OPP table provided by
  1187. * the soc-specific platform driver (td->soc->opp_dev) and the PMIC
  1188. * register-to-voltage mapping queried from the regulator framework.
  1189. *
  1190. * On success, fills in td->i2c_lut and returns 0, or -err on failure.
  1191. */
  1192. static int dfll_build_i2c_lut(struct tegra_dfll *td)
  1193. {
  1194. int ret = -EINVAL;
  1195. int j, v, v_max, v_opp;
  1196. int selector;
  1197. unsigned long rate;
  1198. struct dev_pm_opp *opp;
  1199. int lut;
  1200. rate = ULONG_MAX;
  1201. opp = dev_pm_opp_find_freq_floor(td->soc->dev, &rate);
  1202. if (IS_ERR(opp)) {
  1203. dev_err(td->dev, "couldn't get vmax opp, empty opp table?\n");
  1204. goto out;
  1205. }
  1206. v_max = dev_pm_opp_get_voltage(opp);
  1207. dev_pm_opp_put(opp);
  1208. v = td->soc->cvb->min_millivolts * 1000;
  1209. lut = find_vdd_map_entry_exact(td, v);
  1210. if (lut < 0)
  1211. goto out;
  1212. td->i2c_lut[0] = lut;
  1213. for (j = 1, rate = 0; ; rate++) {
  1214. opp = dev_pm_opp_find_freq_ceil(td->soc->dev, &rate);
  1215. if (IS_ERR(opp))
  1216. break;
  1217. v_opp = dev_pm_opp_get_voltage(opp);
  1218. if (v_opp <= td->soc->cvb->min_millivolts * 1000)
  1219. td->dvco_rate_min = dev_pm_opp_get_freq(opp);
  1220. dev_pm_opp_put(opp);
  1221. for (;;) {
  1222. v += max(1, (v_max - v) / (MAX_DFLL_VOLTAGES - j));
  1223. if (v >= v_opp)
  1224. break;
  1225. selector = find_vdd_map_entry_min(td, v);
  1226. if (selector < 0)
  1227. goto out;
  1228. if (selector != td->i2c_lut[j - 1])
  1229. td->i2c_lut[j++] = selector;
  1230. }
  1231. v = (j == MAX_DFLL_VOLTAGES - 1) ? v_max : v_opp;
  1232. selector = find_vdd_map_entry_exact(td, v);
  1233. if (selector < 0)
  1234. goto out;
  1235. if (selector != td->i2c_lut[j - 1])
  1236. td->i2c_lut[j++] = selector;
  1237. if (v >= v_max)
  1238. break;
  1239. }
  1240. td->i2c_lut_size = j;
  1241. if (!td->dvco_rate_min)
  1242. dev_err(td->dev, "no opp above DFLL minimum voltage %d mV\n",
  1243. td->soc->cvb->min_millivolts);
  1244. else
  1245. ret = 0;
  1246. out:
  1247. return ret;
  1248. }
  1249. /**
  1250. * read_dt_param - helper function for reading required parameters from the DT
  1251. * @td: DFLL instance
  1252. * @param: DT property name
  1253. * @dest: output pointer for the value read
  1254. *
  1255. * Read a required numeric parameter from the DFLL device node, or complain
  1256. * if the property doesn't exist. Returns a boolean indicating success for
  1257. * easy chaining of multiple calls to this function.
  1258. */
  1259. static bool read_dt_param(struct tegra_dfll *td, const char *param, u32 *dest)
  1260. {
  1261. int err = of_property_read_u32(td->dev->of_node, param, dest);
  1262. if (err < 0) {
  1263. dev_err(td->dev, "failed to read DT parameter %s: %d\n",
  1264. param, err);
  1265. return false;
  1266. }
  1267. return true;
  1268. }
  1269. /**
  1270. * dfll_fetch_i2c_params - query PMIC I2C params from DT & regulator subsystem
  1271. * @td: DFLL instance
  1272. *
  1273. * Read all the parameters required for operation in I2C mode. The parameters
  1274. * can originate from the device tree or the regulator subsystem.
  1275. * Returns 0 on success or -err on failure.
  1276. */
  1277. static int dfll_fetch_i2c_params(struct tegra_dfll *td)
  1278. {
  1279. struct regmap *regmap;
  1280. struct device *i2c_dev;
  1281. struct i2c_client *i2c_client;
  1282. int vsel_reg, vsel_mask;
  1283. int ret;
  1284. if (!read_dt_param(td, "nvidia,i2c-fs-rate", &td->i2c_fs_rate))
  1285. return -EINVAL;
  1286. regmap = regulator_get_regmap(td->vdd_reg);
  1287. i2c_dev = regmap_get_device(regmap);
  1288. i2c_client = to_i2c_client(i2c_dev);
  1289. td->i2c_slave_addr = i2c_client->addr;
  1290. ret = regulator_get_hardware_vsel_register(td->vdd_reg,
  1291. &vsel_reg,
  1292. &vsel_mask);
  1293. if (ret < 0) {
  1294. dev_err(td->dev,
  1295. "regulator unsuitable for DFLL I2C operation\n");
  1296. return -EINVAL;
  1297. }
  1298. td->i2c_reg = vsel_reg;
  1299. ret = dfll_build_i2c_lut(td);
  1300. if (ret) {
  1301. dev_err(td->dev, "couldn't build I2C LUT\n");
  1302. return ret;
  1303. }
  1304. return 0;
  1305. }
  1306. /**
  1307. * dfll_fetch_common_params - read DFLL parameters from the device tree
  1308. * @td: DFLL instance
  1309. *
  1310. * Read all the DT parameters that are common to both I2C and PWM operation.
  1311. * Returns 0 on success or -EINVAL on any failure.
  1312. */
  1313. static int dfll_fetch_common_params(struct tegra_dfll *td)
  1314. {
  1315. bool ok = true;
  1316. ok &= read_dt_param(td, "nvidia,droop-ctrl", &td->droop_ctrl);
  1317. ok &= read_dt_param(td, "nvidia,sample-rate", &td->sample_rate);
  1318. ok &= read_dt_param(td, "nvidia,force-mode", &td->force_mode);
  1319. ok &= read_dt_param(td, "nvidia,cf", &td->cf);
  1320. ok &= read_dt_param(td, "nvidia,ci", &td->ci);
  1321. ok &= read_dt_param(td, "nvidia,cg", &td->cg);
  1322. td->cg_scale = of_property_read_bool(td->dev->of_node,
  1323. "nvidia,cg-scale");
  1324. if (of_property_read_string(td->dev->of_node, "clock-output-names",
  1325. &td->output_clock_name)) {
  1326. dev_err(td->dev, "missing clock-output-names property\n");
  1327. ok = false;
  1328. }
  1329. return ok ? 0 : -EINVAL;
  1330. }
  1331. /*
  1332. * API exported to per-SoC platform drivers
  1333. */
  1334. /**
  1335. * tegra_dfll_register - probe a Tegra DFLL device
  1336. * @pdev: DFLL platform_device *
  1337. * @soc: Per-SoC integration and characterization data for this DFLL instance
  1338. *
  1339. * Probe and initialize a DFLL device instance. Intended to be called
  1340. * by a SoC-specific shim driver that passes in per-SoC integration
  1341. * and configuration data via @soc. Returns 0 on success or -err on failure.
  1342. */
  1343. int tegra_dfll_register(struct platform_device *pdev,
  1344. struct tegra_dfll_soc_data *soc)
  1345. {
  1346. struct resource *mem;
  1347. struct tegra_dfll *td;
  1348. int ret;
  1349. if (!soc) {
  1350. dev_err(&pdev->dev, "no tegra_dfll_soc_data provided\n");
  1351. return -EINVAL;
  1352. }
  1353. td = devm_kzalloc(&pdev->dev, sizeof(*td), GFP_KERNEL);
  1354. if (!td)
  1355. return -ENOMEM;
  1356. td->dev = &pdev->dev;
  1357. platform_set_drvdata(pdev, td);
  1358. td->soc = soc;
  1359. td->vdd_reg = devm_regulator_get(td->dev, "vdd-cpu");
  1360. if (IS_ERR(td->vdd_reg)) {
  1361. dev_err(td->dev, "couldn't get vdd_cpu regulator\n");
  1362. return PTR_ERR(td->vdd_reg);
  1363. }
  1364. td->dvco_rst = devm_reset_control_get(td->dev, "dvco");
  1365. if (IS_ERR(td->dvco_rst)) {
  1366. dev_err(td->dev, "couldn't get dvco reset\n");
  1367. return PTR_ERR(td->dvco_rst);
  1368. }
  1369. ret = dfll_fetch_common_params(td);
  1370. if (ret) {
  1371. dev_err(td->dev, "couldn't parse device tree parameters\n");
  1372. return ret;
  1373. }
  1374. ret = dfll_fetch_i2c_params(td);
  1375. if (ret)
  1376. return ret;
  1377. mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1378. if (!mem) {
  1379. dev_err(td->dev, "no control register resource\n");
  1380. return -ENODEV;
  1381. }
  1382. td->base = devm_ioremap(td->dev, mem->start, resource_size(mem));
  1383. if (!td->base) {
  1384. dev_err(td->dev, "couldn't ioremap DFLL control registers\n");
  1385. return -ENODEV;
  1386. }
  1387. mem = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  1388. if (!mem) {
  1389. dev_err(td->dev, "no i2c_base resource\n");
  1390. return -ENODEV;
  1391. }
  1392. td->i2c_base = devm_ioremap(td->dev, mem->start, resource_size(mem));
  1393. if (!td->i2c_base) {
  1394. dev_err(td->dev, "couldn't ioremap i2c_base resource\n");
  1395. return -ENODEV;
  1396. }
  1397. mem = platform_get_resource(pdev, IORESOURCE_MEM, 2);
  1398. if (!mem) {
  1399. dev_err(td->dev, "no i2c_controller_base resource\n");
  1400. return -ENODEV;
  1401. }
  1402. td->i2c_controller_base = devm_ioremap(td->dev, mem->start,
  1403. resource_size(mem));
  1404. if (!td->i2c_controller_base) {
  1405. dev_err(td->dev,
  1406. "couldn't ioremap i2c_controller_base resource\n");
  1407. return -ENODEV;
  1408. }
  1409. mem = platform_get_resource(pdev, IORESOURCE_MEM, 3);
  1410. if (!mem) {
  1411. dev_err(td->dev, "no lut_base resource\n");
  1412. return -ENODEV;
  1413. }
  1414. td->lut_base = devm_ioremap(td->dev, mem->start, resource_size(mem));
  1415. if (!td->lut_base) {
  1416. dev_err(td->dev,
  1417. "couldn't ioremap lut_base resource\n");
  1418. return -ENODEV;
  1419. }
  1420. ret = dfll_init_clks(td);
  1421. if (ret) {
  1422. dev_err(&pdev->dev, "DFLL clock init error\n");
  1423. return ret;
  1424. }
  1425. /* Enable the clocks and set the device up */
  1426. ret = dfll_init(td);
  1427. if (ret)
  1428. return ret;
  1429. ret = dfll_register_clk(td);
  1430. if (ret) {
  1431. dev_err(&pdev->dev, "DFLL clk registration failed\n");
  1432. return ret;
  1433. }
  1434. dfll_debug_init(td);
  1435. return 0;
  1436. }
  1437. EXPORT_SYMBOL(tegra_dfll_register);
  1438. /**
  1439. * tegra_dfll_unregister - release all of the DFLL driver resources for a device
  1440. * @pdev: DFLL platform_device *
  1441. *
  1442. * Unbind this driver from the DFLL hardware device represented by
  1443. * @pdev. The DFLL must be disabled for this to succeed. Returns a
  1444. * soc pointer upon success or -EBUSY if the DFLL is still active.
  1445. */
  1446. struct tegra_dfll_soc_data *tegra_dfll_unregister(struct platform_device *pdev)
  1447. {
  1448. struct tegra_dfll *td = platform_get_drvdata(pdev);
  1449. /* Try to prevent removal while the DFLL is active */
  1450. if (td->mode != DFLL_DISABLED) {
  1451. dev_err(&pdev->dev,
  1452. "must disable DFLL before removing driver\n");
  1453. return ERR_PTR(-EBUSY);
  1454. }
  1455. debugfs_remove_recursive(td->debugfs_dir);
  1456. dfll_unregister_clk(td);
  1457. pm_runtime_disable(&pdev->dev);
  1458. clk_unprepare(td->ref_clk);
  1459. clk_unprepare(td->soc_clk);
  1460. clk_unprepare(td->i2c_clk);
  1461. reset_control_assert(td->dvco_rst);
  1462. return td->soc;
  1463. }
  1464. EXPORT_SYMBOL(tegra_dfll_unregister);