tegra2_clocks.c 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359
  1. /*
  2. * arch/arm/mach-tegra/tegra2_clocks.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. #include <linux/kernel.h>
  20. #include <linux/module.h>
  21. #include <linux/list.h>
  22. #include <linux/spinlock.h>
  23. #include <linux/delay.h>
  24. #include <linux/io.h>
  25. #include <linux/hrtimer.h>
  26. #include <asm/clkdev.h>
  27. #include <mach/iomap.h>
  28. #include "clock.h"
  29. #define RST_DEVICES 0x004
  30. #define RST_DEVICES_SET 0x300
  31. #define RST_DEVICES_CLR 0x304
  32. #define CLK_OUT_ENB 0x010
  33. #define CLK_OUT_ENB_SET 0x320
  34. #define CLK_OUT_ENB_CLR 0x324
  35. #define OSC_CTRL 0x50
  36. #define OSC_CTRL_OSC_FREQ_MASK (3<<30)
  37. #define OSC_CTRL_OSC_FREQ_13MHZ (0<<30)
  38. #define OSC_CTRL_OSC_FREQ_19_2MHZ (1<<30)
  39. #define OSC_CTRL_OSC_FREQ_12MHZ (2<<30)
  40. #define OSC_CTRL_OSC_FREQ_26MHZ (3<<30)
  41. #define OSC_FREQ_DET 0x58
  42. #define OSC_FREQ_DET_TRIG (1<<31)
  43. #define OSC_FREQ_DET_STATUS 0x5C
  44. #define OSC_FREQ_DET_BUSY (1<<31)
  45. #define OSC_FREQ_DET_CNT_MASK 0xFFFF
  46. #define PERIPH_CLK_SOURCE_MASK (3<<30)
  47. #define PERIPH_CLK_SOURCE_SHIFT 30
  48. #define PERIPH_CLK_SOURCE_ENABLE (1<<28)
  49. #define PERIPH_CLK_SOURCE_DIV_MASK 0xFF
  50. #define PERIPH_CLK_SOURCE_DIV_SHIFT 0
  51. #define PLL_BASE 0x0
  52. #define PLL_BASE_BYPASS (1<<31)
  53. #define PLL_BASE_ENABLE (1<<30)
  54. #define PLL_BASE_REF_ENABLE (1<<29)
  55. #define PLL_BASE_OVERRIDE (1<<28)
  56. #define PLL_BASE_LOCK (1<<27)
  57. #define PLL_BASE_DIVP_MASK (0x7<<20)
  58. #define PLL_BASE_DIVP_SHIFT 20
  59. #define PLL_BASE_DIVN_MASK (0x3FF<<8)
  60. #define PLL_BASE_DIVN_SHIFT 8
  61. #define PLL_BASE_DIVM_MASK (0x1F)
  62. #define PLL_BASE_DIVM_SHIFT 0
  63. #define PLL_OUT_RATIO_MASK (0xFF<<8)
  64. #define PLL_OUT_RATIO_SHIFT 8
  65. #define PLL_OUT_OVERRIDE (1<<2)
  66. #define PLL_OUT_CLKEN (1<<1)
  67. #define PLL_OUT_RESET_DISABLE (1<<0)
  68. #define PLL_MISC(c) (((c)->flags & PLL_ALT_MISC_REG) ? 0x4 : 0xc)
  69. #define PLL_MISC_DCCON_SHIFT 20
  70. #define PLL_MISC_LOCK_ENABLE (1<<18)
  71. #define PLL_MISC_CPCON_SHIFT 8
  72. #define PLL_MISC_CPCON_MASK (0xF<<PLL_MISC_CPCON_SHIFT)
  73. #define PLL_MISC_LFCON_SHIFT 4
  74. #define PLL_MISC_LFCON_MASK (0xF<<PLL_MISC_LFCON_SHIFT)
  75. #define PLL_MISC_VCOCON_SHIFT 0
  76. #define PLL_MISC_VCOCON_MASK (0xF<<PLL_MISC_VCOCON_SHIFT)
  77. #define PLLD_MISC_CLKENABLE (1<<30)
  78. #define PLLD_MISC_DIV_RST (1<<23)
  79. #define PLLD_MISC_DCCON_SHIFT 12
  80. #define PERIPH_CLK_TO_ENB_REG(c) ((c->clk_num / 32) * 4)
  81. #define PERIPH_CLK_TO_ENB_SET_REG(c) ((c->clk_num / 32) * 8)
  82. #define PERIPH_CLK_TO_ENB_BIT(c) (1 << (c->clk_num % 32))
  83. #define SUPER_CLK_MUX 0x00
  84. #define SUPER_STATE_SHIFT 28
  85. #define SUPER_STATE_MASK (0xF << SUPER_STATE_SHIFT)
  86. #define SUPER_STATE_STANDBY (0x0 << SUPER_STATE_SHIFT)
  87. #define SUPER_STATE_IDLE (0x1 << SUPER_STATE_SHIFT)
  88. #define SUPER_STATE_RUN (0x2 << SUPER_STATE_SHIFT)
  89. #define SUPER_STATE_IRQ (0x3 << SUPER_STATE_SHIFT)
  90. #define SUPER_STATE_FIQ (0x4 << SUPER_STATE_SHIFT)
  91. #define SUPER_SOURCE_MASK 0xF
  92. #define SUPER_FIQ_SOURCE_SHIFT 12
  93. #define SUPER_IRQ_SOURCE_SHIFT 8
  94. #define SUPER_RUN_SOURCE_SHIFT 4
  95. #define SUPER_IDLE_SOURCE_SHIFT 0
  96. #define SUPER_CLK_DIVIDER 0x04
  97. #define BUS_CLK_DISABLE (1<<3)
  98. #define BUS_CLK_DIV_MASK 0x3
  99. static void __iomem *reg_clk_base = IO_ADDRESS(TEGRA_CLK_RESET_BASE);
  100. #define clk_writel(value, reg) \
  101. __raw_writel(value, (u32)reg_clk_base + (reg))
  102. #define clk_readl(reg) \
  103. __raw_readl((u32)reg_clk_base + (reg))
  104. unsigned long clk_measure_input_freq(void)
  105. {
  106. u32 clock_autodetect;
  107. clk_writel(OSC_FREQ_DET_TRIG | 1, OSC_FREQ_DET);
  108. do {} while (clk_readl(OSC_FREQ_DET_STATUS) & OSC_FREQ_DET_BUSY);
  109. clock_autodetect = clk_readl(OSC_FREQ_DET_STATUS);
  110. if (clock_autodetect >= 732 - 3 && clock_autodetect <= 732 + 3) {
  111. return 12000000;
  112. } else if (clock_autodetect >= 794 - 3 && clock_autodetect <= 794 + 3) {
  113. return 13000000;
  114. } else if (clock_autodetect >= 1172 - 3 && clock_autodetect <= 1172 + 3) {
  115. return 19200000;
  116. } else if (clock_autodetect >= 1587 - 3 && clock_autodetect <= 1587 + 3) {
  117. return 26000000;
  118. } else {
  119. pr_err("%s: Unexpected clock autodetect value %d", __func__, clock_autodetect);
  120. BUG();
  121. return 0;
  122. }
  123. }
  124. static int clk_div71_get_divider(struct clk *c, unsigned long rate)
  125. {
  126. unsigned long divider_u71;
  127. divider_u71 = DIV_ROUND_UP(c->rate * 2, rate);
  128. if (divider_u71 - 2 > 255 || divider_u71 - 2 < 0)
  129. return -EINVAL;
  130. return divider_u71 - 2;
  131. }
  132. static unsigned long tegra2_clk_recalculate_rate(struct clk *c)
  133. {
  134. unsigned long rate;
  135. rate = c->parent->rate;
  136. if (c->mul != 0 && c->div != 0)
  137. c->rate = rate * c->mul / c->div;
  138. else
  139. c->rate = rate;
  140. return c->rate;
  141. }
  142. /* clk_m functions */
  143. static unsigned long tegra2_clk_m_autodetect_rate(struct clk *c)
  144. {
  145. u32 auto_clock_control = clk_readl(OSC_CTRL) & ~OSC_CTRL_OSC_FREQ_MASK;
  146. c->rate = clk_measure_input_freq();
  147. switch (c->rate) {
  148. case 12000000:
  149. auto_clock_control |= OSC_CTRL_OSC_FREQ_12MHZ;
  150. break;
  151. case 13000000:
  152. auto_clock_control |= OSC_CTRL_OSC_FREQ_13MHZ;
  153. break;
  154. case 19200000:
  155. auto_clock_control |= OSC_CTRL_OSC_FREQ_19_2MHZ;
  156. break;
  157. case 26000000:
  158. auto_clock_control |= OSC_CTRL_OSC_FREQ_26MHZ;
  159. break;
  160. default:
  161. pr_err("%s: Unexpected clock rate %ld", __func__, c->rate);
  162. BUG();
  163. }
  164. clk_writel(auto_clock_control, OSC_CTRL);
  165. return c->rate;
  166. }
  167. static void tegra2_clk_m_init(struct clk *c)
  168. {
  169. pr_debug("%s on clock %s\n", __func__, c->name);
  170. tegra2_clk_m_autodetect_rate(c);
  171. }
  172. static int tegra2_clk_m_enable(struct clk *c)
  173. {
  174. pr_debug("%s on clock %s\n", __func__, c->name);
  175. return 0;
  176. }
  177. static void tegra2_clk_m_disable(struct clk *c)
  178. {
  179. pr_debug("%s on clock %s\n", __func__, c->name);
  180. BUG();
  181. }
  182. static struct clk_ops tegra_clk_m_ops = {
  183. .init = tegra2_clk_m_init,
  184. .enable = tegra2_clk_m_enable,
  185. .disable = tegra2_clk_m_disable,
  186. };
  187. /* super clock functions */
  188. /* "super clocks" on tegra have two-stage muxes and a clock skipping
  189. * super divider. We will ignore the clock skipping divider, since we
  190. * can't lower the voltage when using the clock skip, but we can if we
  191. * lower the PLL frequency.
  192. */
  193. static void tegra2_super_clk_init(struct clk *c)
  194. {
  195. u32 val;
  196. int source;
  197. int shift;
  198. const struct clk_mux_sel *sel;
  199. val = clk_readl(c->reg + SUPER_CLK_MUX);
  200. c->state = ON;
  201. BUG_ON(((val & SUPER_STATE_MASK) != SUPER_STATE_RUN) &&
  202. ((val & SUPER_STATE_MASK) != SUPER_STATE_IDLE));
  203. shift = ((val & SUPER_STATE_MASK) == SUPER_STATE_IDLE) ?
  204. SUPER_IDLE_SOURCE_SHIFT : SUPER_RUN_SOURCE_SHIFT;
  205. source = (val >> shift) & SUPER_SOURCE_MASK;
  206. for (sel = c->inputs; sel->input != NULL; sel++) {
  207. if (sel->value == source)
  208. break;
  209. }
  210. BUG_ON(sel->input == NULL);
  211. c->parent = sel->input;
  212. tegra2_clk_recalculate_rate(c);
  213. }
  214. static int tegra2_super_clk_enable(struct clk *c)
  215. {
  216. clk_writel(0, c->reg + SUPER_CLK_DIVIDER);
  217. return 0;
  218. }
  219. static void tegra2_super_clk_disable(struct clk *c)
  220. {
  221. pr_debug("%s on clock %s\n", __func__, c->name);
  222. /* oops - don't disable the CPU clock! */
  223. BUG();
  224. }
  225. static int tegra2_super_clk_set_parent(struct clk *c, struct clk *p)
  226. {
  227. u32 val;
  228. const struct clk_mux_sel *sel;
  229. int shift;
  230. val = clk_readl(c->reg + SUPER_CLK_MUX);;
  231. BUG_ON(((val & SUPER_STATE_MASK) != SUPER_STATE_RUN) &&
  232. ((val & SUPER_STATE_MASK) != SUPER_STATE_IDLE));
  233. shift = ((val & SUPER_STATE_MASK) == SUPER_STATE_IDLE) ?
  234. SUPER_IDLE_SOURCE_SHIFT : SUPER_RUN_SOURCE_SHIFT;
  235. for (sel = c->inputs; sel->input != NULL; sel++) {
  236. if (sel->input == p) {
  237. clk_reparent(c, p);
  238. val &= ~(SUPER_SOURCE_MASK << shift);
  239. val |= sel->value << shift;
  240. clk_writel(val, c->reg);
  241. c->rate = c->parent->rate;
  242. return 0;
  243. }
  244. }
  245. return -EINVAL;
  246. }
  247. static struct clk_ops tegra_super_ops = {
  248. .init = tegra2_super_clk_init,
  249. .enable = tegra2_super_clk_enable,
  250. .disable = tegra2_super_clk_disable,
  251. .set_parent = tegra2_super_clk_set_parent,
  252. .recalculate_rate = tegra2_clk_recalculate_rate,
  253. };
  254. /* bus clock functions */
  255. static void tegra2_bus_clk_init(struct clk *c)
  256. {
  257. u32 val = clk_readl(c->reg);
  258. c->state = ((val >> c->reg_shift) & BUS_CLK_DISABLE) ? OFF : ON;
  259. c->div = ((val >> c->reg_shift) & BUS_CLK_DIV_MASK) + 1;
  260. c->mul = 1;
  261. tegra2_clk_recalculate_rate(c);
  262. }
  263. static int tegra2_bus_clk_enable(struct clk *c)
  264. {
  265. u32 val = clk_readl(c->reg);
  266. val &= ~(BUS_CLK_DISABLE << c->reg_shift);
  267. clk_writel(val, c->reg);
  268. return 0;
  269. }
  270. static void tegra2_bus_clk_disable(struct clk *c)
  271. {
  272. u32 val = clk_readl(c->reg);
  273. val |= BUS_CLK_DISABLE << c->reg_shift;
  274. clk_writel(val, c->reg);
  275. }
  276. static int tegra2_bus_clk_set_rate(struct clk *c, unsigned long rate)
  277. {
  278. u32 val = clk_readl(c->reg);
  279. unsigned long parent_rate = c->parent->rate;
  280. int i;
  281. for (i = 1; i <= 4; i++) {
  282. if (rate == parent_rate / i) {
  283. val &= ~(BUS_CLK_DIV_MASK << c->reg_shift);
  284. val |= (i - 1) << c->reg_shift;
  285. clk_writel(val, c->reg);
  286. c->div = i;
  287. c->mul = 1;
  288. return 0;
  289. }
  290. }
  291. return -EINVAL;
  292. }
  293. static struct clk_ops tegra_bus_ops = {
  294. .init = tegra2_bus_clk_init,
  295. .enable = tegra2_bus_clk_enable,
  296. .disable = tegra2_bus_clk_disable,
  297. .set_rate = tegra2_bus_clk_set_rate,
  298. .recalculate_rate = tegra2_clk_recalculate_rate,
  299. };
  300. /* PLL Functions */
  301. static unsigned long tegra2_pll_clk_recalculate_rate(struct clk *c)
  302. {
  303. u64 rate;
  304. rate = c->parent->rate;
  305. rate *= c->n;
  306. do_div(rate, c->m);
  307. if (c->p == 2)
  308. rate >>= 1;
  309. c->rate = rate;
  310. return c->rate;
  311. }
  312. static int tegra2_pll_clk_wait_for_lock(struct clk *c)
  313. {
  314. ktime_t before;
  315. before = ktime_get();
  316. while (!(clk_readl(c->reg + PLL_BASE) & PLL_BASE_LOCK)) {
  317. if (ktime_us_delta(ktime_get(), before) > 5000) {
  318. pr_err("Timed out waiting for lock bit on pll %s",
  319. c->name);
  320. return -1;
  321. }
  322. }
  323. return 0;
  324. }
  325. static void tegra2_pll_clk_init(struct clk *c)
  326. {
  327. u32 val = clk_readl(c->reg + PLL_BASE);
  328. c->state = (val & PLL_BASE_ENABLE) ? ON : OFF;
  329. if (c->flags & PLL_FIXED && !(val & PLL_BASE_OVERRIDE)) {
  330. pr_warning("Clock %s has unknown fixed frequency\n", c->name);
  331. c->n = 1;
  332. c->m = 0;
  333. c->p = 1;
  334. } else if (val & PLL_BASE_BYPASS) {
  335. c->n = 1;
  336. c->m = 1;
  337. c->p = 1;
  338. } else {
  339. c->n = (val & PLL_BASE_DIVN_MASK) >> PLL_BASE_DIVN_SHIFT;
  340. c->m = (val & PLL_BASE_DIVM_MASK) >> PLL_BASE_DIVM_SHIFT;
  341. c->p = (val & PLL_BASE_DIVP_MASK) ? 2 : 1;
  342. }
  343. val = clk_readl(c->reg + PLL_MISC(c));
  344. if (c->flags & PLL_HAS_CPCON)
  345. c->cpcon = (val & PLL_MISC_CPCON_MASK) >> PLL_MISC_CPCON_SHIFT;
  346. tegra2_pll_clk_recalculate_rate(c);
  347. }
  348. static int tegra2_pll_clk_enable(struct clk *c)
  349. {
  350. u32 val;
  351. pr_debug("%s on clock %s\n", __func__, c->name);
  352. val = clk_readl(c->reg + PLL_BASE);
  353. val &= ~PLL_BASE_BYPASS;
  354. val |= PLL_BASE_ENABLE;
  355. clk_writel(val, c->reg + PLL_BASE);
  356. val = clk_readl(c->reg + PLL_MISC(c));
  357. val |= PLL_MISC_LOCK_ENABLE;
  358. clk_writel(val, c->reg + PLL_MISC(c));
  359. tegra2_pll_clk_wait_for_lock(c);
  360. return 0;
  361. }
  362. static void tegra2_pll_clk_disable(struct clk *c)
  363. {
  364. u32 val;
  365. pr_debug("%s on clock %s\n", __func__, c->name);
  366. val = clk_readl(c->reg);
  367. val &= ~(PLL_BASE_BYPASS | PLL_BASE_ENABLE);
  368. clk_writel(val, c->reg);
  369. }
  370. static int tegra2_pll_clk_set_rate(struct clk *c, unsigned long rate)
  371. {
  372. u32 val;
  373. unsigned long input_rate;
  374. const struct clk_pll_table *sel;
  375. pr_debug("%s: %s %lu\n", __func__, c->name, rate);
  376. BUG_ON(c->refcnt != 0);
  377. input_rate = c->parent->rate;
  378. for (sel = c->pll_table; sel->input_rate != 0; sel++) {
  379. if (sel->input_rate == input_rate && sel->output_rate == rate) {
  380. c->n = sel->n;
  381. c->m = sel->m;
  382. c->p = sel->p;
  383. c->cpcon = sel->cpcon;
  384. val = clk_readl(c->reg + PLL_BASE);
  385. if (c->flags & PLL_FIXED)
  386. val |= PLL_BASE_OVERRIDE;
  387. val &= ~(PLL_BASE_DIVP_MASK | PLL_BASE_DIVN_MASK |
  388. PLL_BASE_DIVM_MASK);
  389. val |= (c->m << PLL_BASE_DIVM_SHIFT) |
  390. (c->n << PLL_BASE_DIVN_SHIFT);
  391. BUG_ON(c->p > 2);
  392. if (c->p == 2)
  393. val |= 1 << PLL_BASE_DIVP_SHIFT;
  394. clk_writel(val, c->reg + PLL_BASE);
  395. if (c->flags & PLL_HAS_CPCON) {
  396. val = c->cpcon << PLL_MISC_CPCON_SHIFT;
  397. val |= PLL_MISC_LOCK_ENABLE;
  398. clk_writel(val, c->reg + PLL_MISC(c));
  399. }
  400. if (c->state == ON)
  401. tegra2_pll_clk_enable(c);
  402. c->rate = rate;
  403. return 0;
  404. }
  405. }
  406. return -EINVAL;
  407. }
  408. static struct clk_ops tegra_pll_ops = {
  409. .init = tegra2_pll_clk_init,
  410. .enable = tegra2_pll_clk_enable,
  411. .disable = tegra2_pll_clk_disable,
  412. .set_rate = tegra2_pll_clk_set_rate,
  413. .recalculate_rate = tegra2_pll_clk_recalculate_rate,
  414. };
  415. /* Clock divider ops */
  416. static void tegra2_pll_div_clk_init(struct clk *c)
  417. {
  418. u32 val = clk_readl(c->reg);
  419. u32 divu71;
  420. val >>= c->reg_shift;
  421. c->state = (val & PLL_OUT_CLKEN) ? ON : OFF;
  422. if (!(val & PLL_OUT_RESET_DISABLE))
  423. c->state = OFF;
  424. if (c->flags & DIV_U71) {
  425. divu71 = (val & PLL_OUT_RATIO_MASK) >> PLL_OUT_RATIO_SHIFT;
  426. c->div = (divu71 + 2);
  427. c->mul = 2;
  428. } else if (c->flags & DIV_2) {
  429. c->div = 2;
  430. c->mul = 1;
  431. } else {
  432. c->div = 1;
  433. c->mul = 1;
  434. }
  435. tegra2_clk_recalculate_rate(c);
  436. }
  437. static int tegra2_pll_div_clk_enable(struct clk *c)
  438. {
  439. u32 val;
  440. u32 new_val;
  441. pr_debug("%s: %s\n", __func__, c->name);
  442. if (c->flags & DIV_U71) {
  443. val = clk_readl(c->reg);
  444. new_val = val >> c->reg_shift;
  445. new_val &= 0xFFFF;
  446. new_val |= PLL_OUT_CLKEN | PLL_OUT_RESET_DISABLE;
  447. val &= ~(0xFFFF << c->reg_shift);
  448. val |= new_val << c->reg_shift;
  449. clk_writel(val, c->reg);
  450. return 0;
  451. } else if (c->flags & DIV_2) {
  452. BUG_ON(!(c->flags & PLLD));
  453. val = clk_readl(c->reg);
  454. val &= ~PLLD_MISC_DIV_RST;
  455. clk_writel(val, c->reg);
  456. return 0;
  457. }
  458. return -EINVAL;
  459. }
  460. static void tegra2_pll_div_clk_disable(struct clk *c)
  461. {
  462. u32 val;
  463. u32 new_val;
  464. pr_debug("%s: %s\n", __func__, c->name);
  465. if (c->flags & DIV_U71) {
  466. val = clk_readl(c->reg);
  467. new_val = val >> c->reg_shift;
  468. new_val &= 0xFFFF;
  469. new_val &= ~(PLL_OUT_CLKEN | PLL_OUT_RESET_DISABLE);
  470. val &= ~(0xFFFF << c->reg_shift);
  471. val |= new_val << c->reg_shift;
  472. clk_writel(val, c->reg);
  473. } else if (c->flags & DIV_2) {
  474. BUG_ON(!(c->flags & PLLD));
  475. val = clk_readl(c->reg);
  476. val |= PLLD_MISC_DIV_RST;
  477. clk_writel(val, c->reg);
  478. }
  479. }
  480. static int tegra2_pll_div_clk_set_rate(struct clk *c, unsigned long rate)
  481. {
  482. u32 val;
  483. u32 new_val;
  484. int divider_u71;
  485. pr_debug("%s: %s %lu\n", __func__, c->name, rate);
  486. if (c->flags & DIV_U71) {
  487. divider_u71 = clk_div71_get_divider(c->parent, rate);
  488. if (divider_u71 >= 0) {
  489. val = clk_readl(c->reg);
  490. new_val = val >> c->reg_shift;
  491. new_val &= 0xFFFF;
  492. if (c->flags & DIV_U71_FIXED)
  493. new_val |= PLL_OUT_OVERRIDE;
  494. new_val &= ~PLL_OUT_RATIO_MASK;
  495. new_val |= divider_u71 << PLL_OUT_RATIO_SHIFT;
  496. val &= ~(0xFFFF << c->reg_shift);
  497. val |= new_val << c->reg_shift;
  498. clk_writel(val, c->reg);
  499. c->div = divider_u71 + 2;
  500. c->mul = 2;
  501. tegra2_clk_recalculate_rate(c);
  502. return 0;
  503. }
  504. } else if (c->flags & DIV_2) {
  505. if (c->parent->rate == rate * 2) {
  506. c->rate = rate;
  507. return 0;
  508. }
  509. }
  510. return -EINVAL;
  511. }
  512. static struct clk_ops tegra_pll_div_ops = {
  513. .init = tegra2_pll_div_clk_init,
  514. .enable = tegra2_pll_div_clk_enable,
  515. .disable = tegra2_pll_div_clk_disable,
  516. .set_rate = tegra2_pll_div_clk_set_rate,
  517. .recalculate_rate = tegra2_clk_recalculate_rate,
  518. };
  519. /* Periph clk ops */
  520. static void tegra2_periph_clk_init(struct clk *c)
  521. {
  522. u32 val = clk_readl(c->reg);
  523. const struct clk_mux_sel *mux = 0;
  524. const struct clk_mux_sel *sel;
  525. if (c->flags & MUX) {
  526. for (sel = c->inputs; sel->input != NULL; sel++) {
  527. if (val >> PERIPH_CLK_SOURCE_SHIFT == sel->value)
  528. mux = sel;
  529. }
  530. BUG_ON(!mux);
  531. c->parent = mux->input;
  532. } else {
  533. c->parent = c->inputs[0].input;
  534. }
  535. if (c->flags & DIV_U71) {
  536. u32 divu71 = val & PERIPH_CLK_SOURCE_DIV_MASK;
  537. c->div = divu71 + 2;
  538. c->mul = 2;
  539. } else {
  540. c->div = 1;
  541. c->mul = 1;
  542. }
  543. c->state = ON;
  544. if (!(clk_readl(CLK_OUT_ENB + PERIPH_CLK_TO_ENB_REG(c)) &
  545. PERIPH_CLK_TO_ENB_BIT(c)))
  546. c->state = OFF;
  547. if (!(c->flags & PERIPH_NO_RESET))
  548. if (clk_readl(RST_DEVICES + PERIPH_CLK_TO_ENB_REG(c)) &
  549. PERIPH_CLK_TO_ENB_BIT(c))
  550. c->state = OFF;
  551. tegra2_clk_recalculate_rate(c);
  552. }
  553. static int tegra2_periph_clk_enable(struct clk *c)
  554. {
  555. u32 val;
  556. pr_debug("%s on clock %s\n", __func__, c->name);
  557. clk_writel(PERIPH_CLK_TO_ENB_BIT(c),
  558. CLK_OUT_ENB_SET + PERIPH_CLK_TO_ENB_SET_REG(c));
  559. if (!(c->flags & PERIPH_NO_RESET) && !(c->flags & PERIPH_MANUAL_RESET))
  560. clk_writel(PERIPH_CLK_TO_ENB_BIT(c),
  561. RST_DEVICES_CLR + PERIPH_CLK_TO_ENB_SET_REG(c));
  562. if (c->flags & PERIPH_EMC_ENB) {
  563. /* The EMC peripheral clock has 2 extra enable bits */
  564. /* FIXME: Do they need to be disabled? */
  565. val = clk_readl(c->reg);
  566. val |= 0x3 << 24;
  567. clk_writel(val, c->reg);
  568. }
  569. return 0;
  570. }
  571. static void tegra2_periph_clk_disable(struct clk *c)
  572. {
  573. pr_debug("%s on clock %s\n", __func__, c->name);
  574. clk_writel(PERIPH_CLK_TO_ENB_BIT(c),
  575. CLK_OUT_ENB_CLR + PERIPH_CLK_TO_ENB_SET_REG(c));
  576. }
  577. void tegra2_periph_reset_deassert(struct clk *c)
  578. {
  579. pr_debug("%s on clock %s\n", __func__, c->name);
  580. if (!(c->flags & PERIPH_NO_RESET))
  581. clk_writel(PERIPH_CLK_TO_ENB_BIT(c),
  582. RST_DEVICES_CLR + PERIPH_CLK_TO_ENB_SET_REG(c));
  583. }
  584. void tegra2_periph_reset_assert(struct clk *c)
  585. {
  586. pr_debug("%s on clock %s\n", __func__, c->name);
  587. if (!(c->flags & PERIPH_NO_RESET))
  588. clk_writel(PERIPH_CLK_TO_ENB_BIT(c),
  589. RST_DEVICES_SET + PERIPH_CLK_TO_ENB_SET_REG(c));
  590. }
  591. static int tegra2_periph_clk_set_parent(struct clk *c, struct clk *p)
  592. {
  593. u32 val;
  594. const struct clk_mux_sel *sel;
  595. pr_debug("%s: %s %s\n", __func__, c->name, p->name);
  596. for (sel = c->inputs; sel->input != NULL; sel++) {
  597. if (sel->input == p) {
  598. clk_reparent(c, p);
  599. val = clk_readl(c->reg);
  600. val &= ~PERIPH_CLK_SOURCE_MASK;
  601. val |= (sel->value) << PERIPH_CLK_SOURCE_SHIFT;
  602. clk_writel(val, c->reg);
  603. c->rate = c->parent->rate;
  604. return 0;
  605. }
  606. }
  607. return -EINVAL;
  608. }
  609. static int tegra2_periph_clk_set_rate(struct clk *c, unsigned long rate)
  610. {
  611. u32 val;
  612. int divider_u71;
  613. pr_debug("%s: %lu\n", __func__, rate);
  614. if (c->flags & DIV_U71) {
  615. divider_u71 = clk_div71_get_divider(c->parent, rate);
  616. if (divider_u71 >= 0) {
  617. val = clk_readl(c->reg);
  618. val &= ~PERIPH_CLK_SOURCE_DIV_MASK;
  619. val |= divider_u71;
  620. clk_writel(val, c->reg);
  621. c->div = divider_u71 + 2;
  622. c->mul = 2;
  623. tegra2_clk_recalculate_rate(c);
  624. return 0;
  625. }
  626. }
  627. return -EINVAL;
  628. }
  629. static struct clk_ops tegra_periph_clk_ops = {
  630. .init = &tegra2_periph_clk_init,
  631. .enable = &tegra2_periph_clk_enable,
  632. .disable = &tegra2_periph_clk_disable,
  633. .set_parent = &tegra2_periph_clk_set_parent,
  634. .set_rate = &tegra2_periph_clk_set_rate,
  635. .recalculate_rate = &tegra2_clk_recalculate_rate,
  636. };
  637. /* Clock doubler ops */
  638. static void tegra2_clk_double_init(struct clk *c)
  639. {
  640. c->mul = 2;
  641. c->div = 1;
  642. c->state = ON;
  643. if (!(clk_readl(CLK_OUT_ENB + PERIPH_CLK_TO_ENB_REG(c)) &
  644. PERIPH_CLK_TO_ENB_BIT(c)))
  645. c->state = OFF;
  646. tegra2_clk_recalculate_rate(c);
  647. };
  648. static struct clk_ops tegra_clk_double_ops = {
  649. .init = &tegra2_clk_double_init,
  650. .enable = &tegra2_periph_clk_enable,
  651. .disable = &tegra2_periph_clk_disable,
  652. .recalculate_rate = &tegra2_clk_recalculate_rate,
  653. };
  654. /* Clock definitions */
  655. static struct clk tegra_clk_32k = {
  656. .name = "clk_32k",
  657. .rate = 32678,
  658. .ops = NULL,
  659. };
  660. static struct clk_pll_table tegra_pll_s_table[] = {
  661. {32768, 12000000, 366, 1, 1, 0},
  662. {32768, 13000000, 397, 1, 1, 0},
  663. {32768, 19200000, 586, 1, 1, 0},
  664. {32768, 26000000, 793, 1, 1, 0},
  665. {0, 0, 0, 0, 0, 0},
  666. };
  667. static struct clk tegra_pll_s = {
  668. .name = "pll_s",
  669. .flags = PLL_ALT_MISC_REG,
  670. .ops = &tegra_pll_ops,
  671. .reg = 0xf0,
  672. .input_min = 32768,
  673. .input_max = 32768,
  674. .parent = &tegra_clk_32k,
  675. .cf_min = 0, /* FIXME */
  676. .cf_max = 0, /* FIXME */
  677. .vco_min = 12000000,
  678. .vco_max = 26000000,
  679. .pll_table = tegra_pll_s_table,
  680. };
  681. static struct clk_mux_sel tegra_clk_m_sel[] = {
  682. { .input = &tegra_clk_32k, .value = 0},
  683. { .input = &tegra_pll_s, .value = 1},
  684. { 0, 0},
  685. };
  686. static struct clk tegra_clk_m = {
  687. .name = "clk_m",
  688. .flags = ENABLE_ON_INIT,
  689. .ops = &tegra_clk_m_ops,
  690. .inputs = tegra_clk_m_sel,
  691. .reg = 0x1fc,
  692. .reg_mask = (1<<28),
  693. .reg_shift = 28,
  694. };
  695. static struct clk_pll_table tegra_pll_c_table[] = {
  696. { 0, 0, 0, 0, 0, 0 },
  697. };
  698. static struct clk tegra_pll_c = {
  699. .name = "pll_c",
  700. .flags = PLL_HAS_CPCON,
  701. .ops = &tegra_pll_ops,
  702. .reg = 0x80,
  703. .input_min = 2000000,
  704. .input_max = 31000000,
  705. .parent = &tegra_clk_m,
  706. .cf_min = 1000000,
  707. .cf_max = 6000000,
  708. .vco_min = 20000000,
  709. .vco_max = 1400000000,
  710. .pll_table = tegra_pll_c_table,
  711. };
  712. static struct clk tegra_pll_c_out1 = {
  713. .name = "pll_c_out1",
  714. .ops = &tegra_pll_div_ops,
  715. .flags = DIV_U71,
  716. .parent = &tegra_pll_c,
  717. .reg = 0x84,
  718. .reg_shift = 0,
  719. };
  720. static struct clk_pll_table tegra_pll_m_table[] = {
  721. { 0, 0, 0, 0, 0, 0 },
  722. };
  723. static struct clk tegra_pll_m = {
  724. .name = "pll_m",
  725. .flags = PLL_HAS_CPCON,
  726. .ops = &tegra_pll_ops,
  727. .reg = 0x90,
  728. .input_min = 2000000,
  729. .input_max = 31000000,
  730. .parent = &tegra_clk_m,
  731. .cf_min = 1000000,
  732. .cf_max = 6000000,
  733. .vco_min = 20000000,
  734. .vco_max = 1200000000,
  735. .pll_table = tegra_pll_m_table,
  736. };
  737. static struct clk tegra_pll_m_out1 = {
  738. .name = "pll_m_out1",
  739. .ops = &tegra_pll_div_ops,
  740. .flags = DIV_U71,
  741. .parent = &tegra_pll_m,
  742. .reg = 0x94,
  743. .reg_shift = 0,
  744. };
  745. static struct clk_pll_table tegra_pll_p_table[] = {
  746. { 12000000, 216000000, 432, 12, 2, 8},
  747. { 13000000, 216000000, 432, 13, 2, 8},
  748. { 19200000, 216000000, 90, 4, 2, 1},
  749. { 26000000, 216000000, 432, 26, 2, 8},
  750. { 12000000, 432000000, 432, 12, 1, 8},
  751. { 13000000, 432000000, 432, 13, 1, 8},
  752. { 19200000, 432000000, 90, 4, 1, 1},
  753. { 26000000, 432000000, 432, 26, 1, 8},
  754. { 0, 0, 0, 0, 0, 0 },
  755. };
  756. static struct clk tegra_pll_p = {
  757. .name = "pll_p",
  758. .flags = ENABLE_ON_INIT | PLL_FIXED | PLL_HAS_CPCON,
  759. .ops = &tegra_pll_ops,
  760. .reg = 0xa0,
  761. .input_min = 2000000,
  762. .input_max = 31000000,
  763. .parent = &tegra_clk_m,
  764. .cf_min = 1000000,
  765. .cf_max = 6000000,
  766. .vco_min = 20000000,
  767. .vco_max = 1400000000,
  768. .pll_table = tegra_pll_p_table,
  769. };
  770. static struct clk tegra_pll_p_out1 = {
  771. .name = "pll_p_out1",
  772. .ops = &tegra_pll_div_ops,
  773. .flags = ENABLE_ON_INIT | DIV_U71 | DIV_U71_FIXED,
  774. .parent = &tegra_pll_p,
  775. .reg = 0xa4,
  776. .reg_shift = 0,
  777. };
  778. static struct clk tegra_pll_p_out2 = {
  779. .name = "pll_p_out2",
  780. .ops = &tegra_pll_div_ops,
  781. .flags = ENABLE_ON_INIT | DIV_U71 | DIV_U71_FIXED,
  782. .parent = &tegra_pll_p,
  783. .reg = 0xa4,
  784. .reg_shift = 16,
  785. };
  786. static struct clk tegra_pll_p_out3 = {
  787. .name = "pll_p_out3",
  788. .ops = &tegra_pll_div_ops,
  789. .flags = ENABLE_ON_INIT | DIV_U71 | DIV_U71_FIXED,
  790. .parent = &tegra_pll_p,
  791. .reg = 0xa8,
  792. .reg_shift = 0,
  793. };
  794. static struct clk tegra_pll_p_out4 = {
  795. .name = "pll_p_out4",
  796. .ops = &tegra_pll_div_ops,
  797. .flags = ENABLE_ON_INIT | DIV_U71 | DIV_U71_FIXED,
  798. .parent = &tegra_pll_p,
  799. .reg = 0xa8,
  800. .reg_shift = 16,
  801. };
  802. static struct clk_pll_table tegra_pll_a_table[] = {
  803. { 28800000, 56448000, 49, 25, 1, 1},
  804. { 28800000, 73728000, 64, 25, 1, 1},
  805. { 28800000, 11289600, 49, 25, 1, 1},
  806. { 28800000, 12288000, 64, 25, 1, 1},
  807. { 0, 0, 0, 0, 0, 0 },
  808. };
  809. static struct clk tegra_pll_a = {
  810. .name = "pll_a",
  811. .flags = PLL_HAS_CPCON,
  812. .ops = &tegra_pll_ops,
  813. .reg = 0xb0,
  814. .input_min = 2000000,
  815. .input_max = 31000000,
  816. .parent = &tegra_pll_p_out1,
  817. .cf_min = 1000000,
  818. .cf_max = 6000000,
  819. .vco_min = 20000000,
  820. .vco_max = 1400000000,
  821. .pll_table = tegra_pll_a_table,
  822. };
  823. static struct clk tegra_pll_a_out0 = {
  824. .name = "pll_a_out0",
  825. .ops = &tegra_pll_div_ops,
  826. .flags = DIV_U71,
  827. .parent = &tegra_pll_a,
  828. .reg = 0xb4,
  829. .reg_shift = 0,
  830. };
  831. static struct clk_pll_table tegra_pll_d_table[] = {
  832. { 12000000, 1000000000, 1000, 12, 1, 12},
  833. { 13000000, 1000000000, 1000, 13, 1, 12},
  834. { 19200000, 1000000000, 625, 12, 1, 8},
  835. { 26000000, 1000000000, 1000, 26, 1, 12},
  836. { 0, 0, 0, 0, 0, 0 },
  837. };
  838. static struct clk tegra_pll_d = {
  839. .name = "pll_d",
  840. .flags = PLL_HAS_CPCON | PLLD,
  841. .ops = &tegra_pll_ops,
  842. .reg = 0xd0,
  843. .input_min = 2000000,
  844. .input_max = 40000000,
  845. .parent = &tegra_clk_m,
  846. .cf_min = 1000000,
  847. .cf_max = 6000000,
  848. .vco_min = 40000000,
  849. .vco_max = 1000000000,
  850. .pll_table = tegra_pll_d_table,
  851. };
  852. static struct clk tegra_pll_d_out0 = {
  853. .name = "pll_d_out0",
  854. .ops = &tegra_pll_div_ops,
  855. .flags = DIV_2 | PLLD,
  856. .parent = &tegra_pll_d,
  857. };
  858. static struct clk_pll_table tegra_pll_u_table[] = {
  859. { 12000000, 480000000, 960, 12, 1, 0},
  860. { 13000000, 480000000, 960, 13, 1, 0},
  861. { 19200000, 480000000, 200, 4, 1, 0},
  862. { 26000000, 480000000, 960, 26, 1, 0},
  863. { 0, 0, 0, 0, 0, 0 },
  864. };
  865. static struct clk tegra_pll_u = {
  866. .name = "pll_u",
  867. .flags = 0,
  868. .ops = &tegra_pll_ops,
  869. .reg = 0xc0,
  870. .input_min = 2000000,
  871. .input_max = 40000000,
  872. .parent = &tegra_clk_m,
  873. .cf_min = 1000000,
  874. .cf_max = 6000000,
  875. .vco_min = 480000000,
  876. .vco_max = 960000000,
  877. .pll_table = tegra_pll_u_table,
  878. };
  879. static struct clk_pll_table tegra_pll_x_table[] = {
  880. { 12000000, 1000000000, 1000, 12, 1, 12},
  881. { 13000000, 1000000000, 1000, 13, 1, 12},
  882. { 19200000, 1000000000, 625, 12, 1, 8},
  883. { 26000000, 1000000000, 1000, 26, 1, 12},
  884. { 12000000, 750000000, 750, 12, 1, 12},
  885. { 13000000, 750000000, 750, 13, 1, 12},
  886. { 19200000, 750000000, 625, 16, 1, 8},
  887. { 26000000, 750000000, 750, 26, 1, 12},
  888. { 0, 0, 0, 0, 0, 0 },
  889. };
  890. static struct clk tegra_pll_x = {
  891. .name = "pll_x",
  892. .flags = PLL_HAS_CPCON | PLL_ALT_MISC_REG,
  893. .ops = &tegra_pll_ops,
  894. .reg = 0xe0,
  895. .input_min = 2000000,
  896. .input_max = 31000000,
  897. .parent = &tegra_clk_m,
  898. .cf_min = 1000000,
  899. .cf_max = 6000000,
  900. .vco_min = 20000000,
  901. .vco_max = 1200000000,
  902. .pll_table = tegra_pll_x_table,
  903. };
  904. static struct clk tegra_clk_d = {
  905. .name = "clk_d",
  906. .flags = PERIPH_NO_RESET,
  907. .ops = &tegra_clk_double_ops,
  908. .clk_num = 90,
  909. .reg = 0x34,
  910. .reg_shift = 12,
  911. .parent = &tegra_clk_m,
  912. };
  913. /* FIXME: need tegra_audio
  914. static struct clk tegra_clk_audio_2x = {
  915. .name = "clk_d",
  916. .flags = PERIPH_NO_RESET,
  917. .ops = &tegra_clk_double_ops,
  918. .clk_num = 89,
  919. .reg = 0x34,
  920. .reg_shift = 8,
  921. .parent = &tegra_audio,
  922. }
  923. */
  924. static struct clk_mux_sel mux_cclk[] = {
  925. { .input = &tegra_clk_m, .value = 0},
  926. { .input = &tegra_pll_c, .value = 1},
  927. { .input = &tegra_clk_32k, .value = 2},
  928. { .input = &tegra_pll_m, .value = 3},
  929. { .input = &tegra_pll_p, .value = 4},
  930. { .input = &tegra_pll_p_out4, .value = 5},
  931. { .input = &tegra_pll_p_out3, .value = 6},
  932. { .input = &tegra_clk_d, .value = 7},
  933. { .input = &tegra_pll_x, .value = 8},
  934. { 0, 0},
  935. };
  936. static struct clk_mux_sel mux_sclk[] = {
  937. { .input = &tegra_clk_m, .value = 0},
  938. { .input = &tegra_pll_c_out1, .value = 1},
  939. { .input = &tegra_pll_p_out4, .value = 2},
  940. { .input = &tegra_pll_p_out3, .value = 3},
  941. { .input = &tegra_pll_p_out2, .value = 4},
  942. { .input = &tegra_clk_d, .value = 5},
  943. { .input = &tegra_clk_32k, .value = 6},
  944. { .input = &tegra_pll_m_out1, .value = 7},
  945. { 0, 0},
  946. };
  947. static struct clk tegra_clk_cpu = {
  948. .name = "cpu",
  949. .inputs = mux_cclk,
  950. .reg = 0x20,
  951. .ops = &tegra_super_ops,
  952. };
  953. static struct clk tegra_clk_sys = {
  954. .name = "sys",
  955. .inputs = mux_sclk,
  956. .reg = 0x28,
  957. .ops = &tegra_super_ops,
  958. };
  959. static struct clk tegra_clk_hclk = {
  960. .name = "hclk",
  961. .flags = DIV_BUS,
  962. .parent = &tegra_clk_sys,
  963. .reg = 0x30,
  964. .reg_shift = 4,
  965. .ops = &tegra_bus_ops,
  966. };
  967. static struct clk tegra_clk_pclk = {
  968. .name = "pclk",
  969. .flags = DIV_BUS,
  970. .parent = &tegra_clk_hclk,
  971. .reg = 0x30,
  972. .reg_shift = 0,
  973. .ops = &tegra_bus_ops,
  974. };
  975. static struct clk_mux_sel mux_pllm_pllc_pllp_plla[] = {
  976. { .input = &tegra_pll_m, .value = 0},
  977. { .input = &tegra_pll_c, .value = 1},
  978. { .input = &tegra_pll_p, .value = 2},
  979. { .input = &tegra_pll_a_out0, .value = 3},
  980. { 0, 0},
  981. };
  982. static struct clk_mux_sel mux_pllm_pllc_pllp_clkm[] = {
  983. { .input = &tegra_pll_m, .value = 0},
  984. { .input = &tegra_pll_c, .value = 1},
  985. { .input = &tegra_pll_p, .value = 2},
  986. { .input = &tegra_clk_m, .value = 3},
  987. { 0, 0},
  988. };
  989. static struct clk_mux_sel mux_pllp_pllc_pllm_clkm[] = {
  990. { .input = &tegra_pll_p, .value = 0},
  991. { .input = &tegra_pll_c, .value = 1},
  992. { .input = &tegra_pll_m, .value = 2},
  993. { .input = &tegra_clk_m, .value = 3},
  994. { 0, 0},
  995. };
  996. static struct clk_mux_sel mux_plla_audio_pllp_clkm[] = {
  997. {.input = &tegra_pll_a, .value = 0},
  998. /* FIXME: no mux defined for tegra_audio
  999. {.input = &tegra_audio, .value = 1},*/
  1000. {.input = &tegra_pll_p, .value = 2},
  1001. {.input = &tegra_clk_m, .value = 3},
  1002. { 0, 0},
  1003. };
  1004. static struct clk_mux_sel mux_pllp_plld_pllc_clkm[] = {
  1005. {.input = &tegra_pll_p, .value = 0},
  1006. {.input = &tegra_pll_d_out0, .value = 1},
  1007. {.input = &tegra_pll_c, .value = 2},
  1008. {.input = &tegra_clk_m, .value = 3},
  1009. { 0, 0},
  1010. };
  1011. static struct clk_mux_sel mux_pllp_pllc_audio_clkm_clk32[] = {
  1012. {.input = &tegra_pll_p, .value = 0},
  1013. {.input = &tegra_pll_c, .value = 1},
  1014. /* FIXME: no mux defined for tegra_audio
  1015. {.input = &tegra_audio, .value = 2},*/
  1016. {.input = &tegra_clk_m, .value = 3},
  1017. {.input = &tegra_clk_32k, .value = 4},
  1018. { 0, 0},
  1019. };
  1020. static struct clk_mux_sel mux_pllp_pllc_pllm[] = {
  1021. {.input = &tegra_pll_p, .value = 0},
  1022. {.input = &tegra_pll_c, .value = 1},
  1023. {.input = &tegra_pll_m, .value = 2},
  1024. { 0, 0},
  1025. };
  1026. static struct clk_mux_sel mux_clk_m[] = {
  1027. { .input = &tegra_clk_m, .value = 0},
  1028. { 0, 0},
  1029. };
  1030. static struct clk_mux_sel mux_pllp_out3[] = {
  1031. { .input = &tegra_pll_p_out3, .value = 0},
  1032. { 0, 0},
  1033. };
  1034. static struct clk_mux_sel mux_plld[] = {
  1035. { .input = &tegra_pll_d, .value = 0},
  1036. { 0, 0},
  1037. };
  1038. static struct clk_mux_sel mux_clk_32k[] = {
  1039. { .input = &tegra_clk_32k, .value = 0},
  1040. { 0, 0},
  1041. };
  1042. #define PERIPH_CLK(_name, _dev, _con, _clk_num, _reg, _inputs, _flags) \
  1043. { \
  1044. .name = _name, \
  1045. .lookup = { \
  1046. .dev_id = _dev, \
  1047. .con_id = _con, \
  1048. }, \
  1049. .ops = &tegra_periph_clk_ops, \
  1050. .clk_num = _clk_num, \
  1051. .reg = _reg, \
  1052. .inputs = _inputs, \
  1053. .flags = _flags, \
  1054. }
  1055. struct clk tegra_periph_clks[] = {
  1056. PERIPH_CLK("rtc", "rtc-tegra", NULL, 4, 0, mux_clk_32k, PERIPH_NO_RESET),
  1057. PERIPH_CLK("timer", "timer", NULL, 5, 0, mux_clk_m, 0),
  1058. PERIPH_CLK("i2s1", "i2s.0", NULL, 11, 0x100, mux_plla_audio_pllp_clkm, MUX | DIV_U71),
  1059. PERIPH_CLK("i2s2", "i2s.1", NULL, 18, 0x104, mux_plla_audio_pllp_clkm, MUX | DIV_U71),
  1060. /* FIXME: spdif has 2 clocks but 1 enable */
  1061. PERIPH_CLK("spdif_out", "spdif_out", NULL, 10, 0x108, mux_plla_audio_pllp_clkm, MUX | DIV_U71),
  1062. PERIPH_CLK("spdif_in", "spdif_in", NULL, 10, 0x10c, mux_pllp_pllc_pllm, MUX | DIV_U71),
  1063. PERIPH_CLK("pwm", "pwm", NULL, 17, 0x110, mux_pllp_pllc_audio_clkm_clk32, MUX | DIV_U71),
  1064. PERIPH_CLK("spi", "spi", NULL, 43, 0x114, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
  1065. PERIPH_CLK("xio", "xio", NULL, 45, 0x120, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
  1066. PERIPH_CLK("twc", "twc", NULL, 16, 0x12c, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
  1067. PERIPH_CLK("sbc1", "spi_tegra.0", NULL, 41, 0x134, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
  1068. PERIPH_CLK("sbc2", "spi_tegra.1", NULL, 44, 0x118, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
  1069. PERIPH_CLK("sbc3", "spi_tegra.2", NULL, 46, 0x11c, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
  1070. PERIPH_CLK("sbc4", "spi_tegra.3", NULL, 68, 0x1b4, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
  1071. PERIPH_CLK("ide", "ide", NULL, 25, 0x144, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
  1072. PERIPH_CLK("ndflash", "tegra_nand", NULL, 13, 0x160, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
  1073. /* FIXME: vfir shares an enable with uartb */
  1074. PERIPH_CLK("vfir", "vfir", NULL, 7, 0x168, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
  1075. PERIPH_CLK("sdmmc1", "sdhci-tegra.0", NULL, 14, 0x150, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
  1076. PERIPH_CLK("sdmmc2", "sdhci-tegra.1", NULL, 9, 0x154, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
  1077. PERIPH_CLK("sdmmc3", "sdhci-tegra.2", NULL, 69, 0x1bc, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
  1078. PERIPH_CLK("sdmmc4", "sdhci-tegra.3", NULL, 15, 0x160, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
  1079. PERIPH_CLK("vde", "vde", NULL, 61, 0x1c8, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
  1080. PERIPH_CLK("csite", "csite", NULL, 73, 0x1d4, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
  1081. /* FIXME: what is la? */
  1082. PERIPH_CLK("la", "la", NULL, 76, 0x1f8, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
  1083. PERIPH_CLK("owr", "owr", NULL, 71, 0x1cc, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
  1084. PERIPH_CLK("nor", "nor", NULL, 42, 0x1d0, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
  1085. PERIPH_CLK("mipi", "mipi", NULL, 50, 0x174, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
  1086. PERIPH_CLK("i2c1", "tegra-i2c.0", NULL, 12, 0x124, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
  1087. PERIPH_CLK("i2c2", "tegra-i2c.1", NULL, 54, 0x198, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
  1088. PERIPH_CLK("i2c3", "tegra-i2c.2", NULL, 67, 0x1b8, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
  1089. PERIPH_CLK("dvc", "tegra-i2c.3", NULL, 47, 0x128, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
  1090. PERIPH_CLK("i2c1_i2c", "tegra-i2c.0", "i2c", 0, 0, mux_pllp_out3, 0),
  1091. PERIPH_CLK("i2c2_i2c", "tegra-i2c.1", "i2c", 0, 0, mux_pllp_out3, 0),
  1092. PERIPH_CLK("i2c3_i2c", "tegra-i2c.2", "i2c", 0, 0, mux_pllp_out3, 0),
  1093. PERIPH_CLK("dvc_i2c", "tegra-i2c.3", "i2c", 0, 0, mux_pllp_out3, 0),
  1094. PERIPH_CLK("uarta", "uart.0", NULL, 6, 0x178, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
  1095. PERIPH_CLK("uartb", "uart.1", NULL, 7, 0x17c, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
  1096. PERIPH_CLK("uartc", "uart.2", NULL, 55, 0x1a0, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
  1097. PERIPH_CLK("uartd", "uart.3", NULL, 65, 0x1c0, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
  1098. PERIPH_CLK("uarte", "uart.4", NULL, 66, 0x1c4, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
  1099. PERIPH_CLK("3d", "3d", NULL, 24, 0x158, mux_pllm_pllc_pllp_plla, MUX | DIV_U71 | PERIPH_MANUAL_RESET),
  1100. PERIPH_CLK("2d", "2d", NULL, 21, 0x15c, mux_pllm_pllc_pllp_plla, MUX | DIV_U71),
  1101. /* FIXME: vi and vi_sensor share an enable */
  1102. PERIPH_CLK("vi", "vi", NULL, 20, 0x148, mux_pllm_pllc_pllp_plla, MUX | DIV_U71),
  1103. PERIPH_CLK("vi_sensor", "vi_sensor", NULL, 20, 0x1a8, mux_pllm_pllc_pllp_plla, MUX | DIV_U71),
  1104. PERIPH_CLK("epp", "epp", NULL, 19, 0x16c, mux_pllm_pllc_pllp_plla, MUX | DIV_U71),
  1105. PERIPH_CLK("mpe", "mpe", NULL, 60, 0x170, mux_pllm_pllc_pllp_plla, MUX | DIV_U71),
  1106. PERIPH_CLK("host1x", "host1x", NULL, 28, 0x180, mux_pllm_pllc_pllp_plla, MUX | DIV_U71),
  1107. /* FIXME: cve and tvo share an enable */
  1108. PERIPH_CLK("cve", "cve", NULL, 49, 0x140, mux_pllp_plld_pllc_clkm, MUX | DIV_U71),
  1109. PERIPH_CLK("tvo", "tvo", NULL, 49, 0x188, mux_pllp_plld_pllc_clkm, MUX | DIV_U71),
  1110. PERIPH_CLK("hdmi", "hdmi", NULL, 51, 0x18c, mux_pllp_plld_pllc_clkm, MUX | DIV_U71),
  1111. PERIPH_CLK("tvdac", "tvdac", NULL, 53, 0x194, mux_pllp_plld_pllc_clkm, MUX | DIV_U71),
  1112. PERIPH_CLK("disp1", "tegrafb.0", NULL, 27, 0x138, mux_pllp_plld_pllc_clkm, MUX | DIV_U71),
  1113. PERIPH_CLK("disp2", "tegrafb.1", NULL, 26, 0x13c, mux_pllp_plld_pllc_clkm, MUX | DIV_U71),
  1114. PERIPH_CLK("usbd", "fsl-tegra-udc", NULL, 22, 0, mux_clk_m, 0),
  1115. PERIPH_CLK("usb2", "usb.1", NULL, 58, 0, mux_clk_m, 0),
  1116. PERIPH_CLK("usb3", "usb.2", NULL, 59, 0, mux_clk_m, 0),
  1117. PERIPH_CLK("emc", "emc", NULL, 57, 0x19c, mux_pllm_pllc_pllp_clkm, MUX | DIV_U71 | PERIPH_EMC_ENB),
  1118. PERIPH_CLK("dsi", "dsi", NULL, 48, 0, mux_plld, 0),
  1119. };
  1120. #define CLK_DUPLICATE(_name, _dev, _con) \
  1121. { \
  1122. .name = _name, \
  1123. .lookup = { \
  1124. .dev_id = _dev, \
  1125. .con_id = _con, \
  1126. }, \
  1127. }
  1128. /* Some clocks may be used by different drivers depending on the board
  1129. * configuration. List those here to register them twice in the clock lookup
  1130. * table under two names.
  1131. */
  1132. struct clk_duplicate tegra_clk_duplicates[] = {
  1133. CLK_DUPLICATE("uarta", "tegra_uart.0", NULL),
  1134. CLK_DUPLICATE("uartb", "tegra_uart.1", NULL),
  1135. CLK_DUPLICATE("uartc", "tegra_uart.2", NULL),
  1136. CLK_DUPLICATE("uartd", "tegra_uart.3", NULL),
  1137. CLK_DUPLICATE("uarte", "tegra_uart.4", NULL),
  1138. };
  1139. #define CLK(dev, con, ck) \
  1140. { \
  1141. .dev_id = dev, \
  1142. .con_id = con, \
  1143. .clk = ck, \
  1144. }
  1145. struct clk_lookup tegra_clk_lookups[] = {
  1146. /* external root sources */
  1147. CLK(NULL, "32k_clk", &tegra_clk_32k),
  1148. CLK(NULL, "pll_s", &tegra_pll_s),
  1149. CLK(NULL, "clk_m", &tegra_clk_m),
  1150. CLK(NULL, "pll_m", &tegra_pll_m),
  1151. CLK(NULL, "pll_m_out1", &tegra_pll_m_out1),
  1152. CLK(NULL, "pll_c", &tegra_pll_c),
  1153. CLK(NULL, "pll_c_out1", &tegra_pll_c_out1),
  1154. CLK(NULL, "pll_p", &tegra_pll_p),
  1155. CLK(NULL, "pll_p_out1", &tegra_pll_p_out1),
  1156. CLK(NULL, "pll_p_out2", &tegra_pll_p_out2),
  1157. CLK(NULL, "pll_p_out3", &tegra_pll_p_out3),
  1158. CLK(NULL, "pll_p_out4", &tegra_pll_p_out4),
  1159. CLK(NULL, "pll_a", &tegra_pll_a),
  1160. CLK(NULL, "pll_a_out0", &tegra_pll_a_out0),
  1161. CLK(NULL, "pll_d", &tegra_pll_d),
  1162. CLK(NULL, "pll_d_out0", &tegra_pll_d_out0),
  1163. CLK(NULL, "pll_u", &tegra_pll_u),
  1164. CLK(NULL, "pll_x", &tegra_pll_x),
  1165. CLK(NULL, "cpu", &tegra_clk_cpu),
  1166. CLK(NULL, "sys", &tegra_clk_sys),
  1167. CLK(NULL, "hclk", &tegra_clk_hclk),
  1168. CLK(NULL, "pclk", &tegra_clk_pclk),
  1169. CLK(NULL, "clk_d", &tegra_clk_d),
  1170. };
  1171. void __init tegra2_init_clocks(void)
  1172. {
  1173. int i;
  1174. struct clk_lookup *cl;
  1175. struct clk *c;
  1176. struct clk_duplicate *cd;
  1177. for (i = 0; i < ARRAY_SIZE(tegra_clk_lookups); i++) {
  1178. cl = &tegra_clk_lookups[i];
  1179. clk_init(cl->clk);
  1180. clkdev_add(cl);
  1181. }
  1182. for (i = 0; i < ARRAY_SIZE(tegra_periph_clks); i++) {
  1183. c = &tegra_periph_clks[i];
  1184. cl = &c->lookup;
  1185. cl->clk = c;
  1186. clk_init(cl->clk);
  1187. clkdev_add(cl);
  1188. }
  1189. for (i = 0; i < ARRAY_SIZE(tegra_clk_duplicates); i++) {
  1190. cd = &tegra_clk_duplicates[i];
  1191. c = tegra_get_clock_by_name(cd->name);
  1192. if (c) {
  1193. cl = &cd->lookup;
  1194. cl->clk = c;
  1195. clkdev_add(cl);
  1196. } else {
  1197. pr_err("%s: Unknown duplicate clock %s\n", __func__,
  1198. cd->name);
  1199. }
  1200. }
  1201. }