clk-main.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  1. /*
  2. * Copyright (C) 2013 Boris BREZILLON <b.brezillon@overkiz.com>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. */
  10. #include <linux/clk-provider.h>
  11. #include <linux/clkdev.h>
  12. #include <linux/clk/at91_pmc.h>
  13. #include <linux/delay.h>
  14. #include <linux/of.h>
  15. #include <linux/of_address.h>
  16. #include <linux/of_irq.h>
  17. #include <linux/io.h>
  18. #include <linux/interrupt.h>
  19. #include <linux/irq.h>
  20. #include <linux/sched.h>
  21. #include <linux/wait.h>
  22. #include "pmc.h"
  23. #define SLOW_CLOCK_FREQ 32768
  24. #define MAINF_DIV 16
  25. #define MAINFRDY_TIMEOUT (((MAINF_DIV + 1) * USEC_PER_SEC) / \
  26. SLOW_CLOCK_FREQ)
  27. #define MAINF_LOOP_MIN_WAIT (USEC_PER_SEC / SLOW_CLOCK_FREQ)
  28. #define MAINF_LOOP_MAX_WAIT MAINFRDY_TIMEOUT
  29. #define MOR_KEY_MASK (0xff << 16)
  30. struct clk_main_osc {
  31. struct clk_hw hw;
  32. struct at91_pmc *pmc;
  33. unsigned int irq;
  34. wait_queue_head_t wait;
  35. };
  36. #define to_clk_main_osc(hw) container_of(hw, struct clk_main_osc, hw)
  37. struct clk_main_rc_osc {
  38. struct clk_hw hw;
  39. struct at91_pmc *pmc;
  40. unsigned int irq;
  41. wait_queue_head_t wait;
  42. unsigned long frequency;
  43. unsigned long accuracy;
  44. };
  45. #define to_clk_main_rc_osc(hw) container_of(hw, struct clk_main_rc_osc, hw)
  46. struct clk_rm9200_main {
  47. struct clk_hw hw;
  48. struct at91_pmc *pmc;
  49. };
  50. #define to_clk_rm9200_main(hw) container_of(hw, struct clk_rm9200_main, hw)
  51. struct clk_sam9x5_main {
  52. struct clk_hw hw;
  53. struct at91_pmc *pmc;
  54. unsigned int irq;
  55. wait_queue_head_t wait;
  56. u8 parent;
  57. };
  58. #define to_clk_sam9x5_main(hw) container_of(hw, struct clk_sam9x5_main, hw)
  59. static irqreturn_t clk_main_osc_irq_handler(int irq, void *dev_id)
  60. {
  61. struct clk_main_osc *osc = dev_id;
  62. wake_up(&osc->wait);
  63. disable_irq_nosync(osc->irq);
  64. return IRQ_HANDLED;
  65. }
  66. static int clk_main_osc_prepare(struct clk_hw *hw)
  67. {
  68. struct clk_main_osc *osc = to_clk_main_osc(hw);
  69. struct at91_pmc *pmc = osc->pmc;
  70. u32 tmp;
  71. tmp = pmc_read(pmc, AT91_CKGR_MOR) & ~MOR_KEY_MASK;
  72. if (tmp & AT91_PMC_OSCBYPASS)
  73. return 0;
  74. if (!(tmp & AT91_PMC_MOSCEN)) {
  75. tmp |= AT91_PMC_MOSCEN | AT91_PMC_KEY;
  76. pmc_write(pmc, AT91_CKGR_MOR, tmp);
  77. }
  78. while (!(pmc_read(pmc, AT91_PMC_SR) & AT91_PMC_MOSCS)) {
  79. enable_irq(osc->irq);
  80. wait_event(osc->wait,
  81. pmc_read(pmc, AT91_PMC_SR) & AT91_PMC_MOSCS);
  82. }
  83. return 0;
  84. }
  85. static void clk_main_osc_unprepare(struct clk_hw *hw)
  86. {
  87. struct clk_main_osc *osc = to_clk_main_osc(hw);
  88. struct at91_pmc *pmc = osc->pmc;
  89. u32 tmp = pmc_read(pmc, AT91_CKGR_MOR);
  90. if (tmp & AT91_PMC_OSCBYPASS)
  91. return;
  92. if (!(tmp & AT91_PMC_MOSCEN))
  93. return;
  94. tmp &= ~(AT91_PMC_KEY | AT91_PMC_MOSCEN);
  95. pmc_write(pmc, AT91_CKGR_MOR, tmp | AT91_PMC_KEY);
  96. }
  97. static int clk_main_osc_is_prepared(struct clk_hw *hw)
  98. {
  99. struct clk_main_osc *osc = to_clk_main_osc(hw);
  100. struct at91_pmc *pmc = osc->pmc;
  101. u32 tmp = pmc_read(pmc, AT91_CKGR_MOR);
  102. if (tmp & AT91_PMC_OSCBYPASS)
  103. return 1;
  104. return !!((pmc_read(pmc, AT91_PMC_SR) & AT91_PMC_MOSCS) &&
  105. (pmc_read(pmc, AT91_CKGR_MOR) & AT91_PMC_MOSCEN));
  106. }
  107. static const struct clk_ops main_osc_ops = {
  108. .prepare = clk_main_osc_prepare,
  109. .unprepare = clk_main_osc_unprepare,
  110. .is_prepared = clk_main_osc_is_prepared,
  111. };
  112. static struct clk * __init
  113. at91_clk_register_main_osc(struct at91_pmc *pmc,
  114. unsigned int irq,
  115. const char *name,
  116. const char *parent_name,
  117. bool bypass)
  118. {
  119. int ret;
  120. struct clk_main_osc *osc;
  121. struct clk *clk = NULL;
  122. struct clk_init_data init;
  123. if (!pmc || !irq || !name || !parent_name)
  124. return ERR_PTR(-EINVAL);
  125. osc = kzalloc(sizeof(*osc), GFP_KERNEL);
  126. if (!osc)
  127. return ERR_PTR(-ENOMEM);
  128. init.name = name;
  129. init.ops = &main_osc_ops;
  130. init.parent_names = &parent_name;
  131. init.num_parents = 1;
  132. init.flags = CLK_IGNORE_UNUSED;
  133. osc->hw.init = &init;
  134. osc->pmc = pmc;
  135. osc->irq = irq;
  136. init_waitqueue_head(&osc->wait);
  137. irq_set_status_flags(osc->irq, IRQ_NOAUTOEN);
  138. ret = request_irq(osc->irq, clk_main_osc_irq_handler,
  139. IRQF_TRIGGER_HIGH, name, osc);
  140. if (ret) {
  141. kfree(osc);
  142. return ERR_PTR(ret);
  143. }
  144. if (bypass)
  145. pmc_write(pmc, AT91_CKGR_MOR,
  146. (pmc_read(pmc, AT91_CKGR_MOR) &
  147. ~(MOR_KEY_MASK | AT91_PMC_MOSCEN)) |
  148. AT91_PMC_OSCBYPASS | AT91_PMC_KEY);
  149. clk = clk_register(NULL, &osc->hw);
  150. if (IS_ERR(clk)) {
  151. free_irq(irq, osc);
  152. kfree(osc);
  153. }
  154. return clk;
  155. }
  156. void __init of_at91rm9200_clk_main_osc_setup(struct device_node *np,
  157. struct at91_pmc *pmc)
  158. {
  159. struct clk *clk;
  160. unsigned int irq;
  161. const char *name = np->name;
  162. const char *parent_name;
  163. bool bypass;
  164. of_property_read_string(np, "clock-output-names", &name);
  165. bypass = of_property_read_bool(np, "atmel,osc-bypass");
  166. parent_name = of_clk_get_parent_name(np, 0);
  167. irq = irq_of_parse_and_map(np, 0);
  168. if (!irq)
  169. return;
  170. clk = at91_clk_register_main_osc(pmc, irq, name, parent_name, bypass);
  171. if (IS_ERR(clk))
  172. return;
  173. of_clk_add_provider(np, of_clk_src_simple_get, clk);
  174. }
  175. static irqreturn_t clk_main_rc_osc_irq_handler(int irq, void *dev_id)
  176. {
  177. struct clk_main_rc_osc *osc = dev_id;
  178. wake_up(&osc->wait);
  179. disable_irq_nosync(osc->irq);
  180. return IRQ_HANDLED;
  181. }
  182. static int clk_main_rc_osc_prepare(struct clk_hw *hw)
  183. {
  184. struct clk_main_rc_osc *osc = to_clk_main_rc_osc(hw);
  185. struct at91_pmc *pmc = osc->pmc;
  186. u32 tmp;
  187. tmp = pmc_read(pmc, AT91_CKGR_MOR) & ~MOR_KEY_MASK;
  188. if (!(tmp & AT91_PMC_MOSCRCEN)) {
  189. tmp |= AT91_PMC_MOSCRCEN | AT91_PMC_KEY;
  190. pmc_write(pmc, AT91_CKGR_MOR, tmp);
  191. }
  192. while (!(pmc_read(pmc, AT91_PMC_SR) & AT91_PMC_MOSCRCS)) {
  193. enable_irq(osc->irq);
  194. wait_event(osc->wait,
  195. pmc_read(pmc, AT91_PMC_SR) & AT91_PMC_MOSCRCS);
  196. }
  197. return 0;
  198. }
  199. static void clk_main_rc_osc_unprepare(struct clk_hw *hw)
  200. {
  201. struct clk_main_rc_osc *osc = to_clk_main_rc_osc(hw);
  202. struct at91_pmc *pmc = osc->pmc;
  203. u32 tmp = pmc_read(pmc, AT91_CKGR_MOR);
  204. if (!(tmp & AT91_PMC_MOSCRCEN))
  205. return;
  206. tmp &= ~(MOR_KEY_MASK | AT91_PMC_MOSCRCEN);
  207. pmc_write(pmc, AT91_CKGR_MOR, tmp | AT91_PMC_KEY);
  208. }
  209. static int clk_main_rc_osc_is_prepared(struct clk_hw *hw)
  210. {
  211. struct clk_main_rc_osc *osc = to_clk_main_rc_osc(hw);
  212. struct at91_pmc *pmc = osc->pmc;
  213. return !!((pmc_read(pmc, AT91_PMC_SR) & AT91_PMC_MOSCRCS) &&
  214. (pmc_read(pmc, AT91_CKGR_MOR) & AT91_PMC_MOSCRCEN));
  215. }
  216. static unsigned long clk_main_rc_osc_recalc_rate(struct clk_hw *hw,
  217. unsigned long parent_rate)
  218. {
  219. struct clk_main_rc_osc *osc = to_clk_main_rc_osc(hw);
  220. return osc->frequency;
  221. }
  222. static unsigned long clk_main_rc_osc_recalc_accuracy(struct clk_hw *hw,
  223. unsigned long parent_acc)
  224. {
  225. struct clk_main_rc_osc *osc = to_clk_main_rc_osc(hw);
  226. return osc->accuracy;
  227. }
  228. static const struct clk_ops main_rc_osc_ops = {
  229. .prepare = clk_main_rc_osc_prepare,
  230. .unprepare = clk_main_rc_osc_unprepare,
  231. .is_prepared = clk_main_rc_osc_is_prepared,
  232. .recalc_rate = clk_main_rc_osc_recalc_rate,
  233. .recalc_accuracy = clk_main_rc_osc_recalc_accuracy,
  234. };
  235. static struct clk * __init
  236. at91_clk_register_main_rc_osc(struct at91_pmc *pmc,
  237. unsigned int irq,
  238. const char *name,
  239. u32 frequency, u32 accuracy)
  240. {
  241. int ret;
  242. struct clk_main_rc_osc *osc;
  243. struct clk *clk = NULL;
  244. struct clk_init_data init;
  245. if (!pmc || !irq || !name || !frequency)
  246. return ERR_PTR(-EINVAL);
  247. osc = kzalloc(sizeof(*osc), GFP_KERNEL);
  248. if (!osc)
  249. return ERR_PTR(-ENOMEM);
  250. init.name = name;
  251. init.ops = &main_rc_osc_ops;
  252. init.parent_names = NULL;
  253. init.num_parents = 0;
  254. init.flags = CLK_IS_ROOT | CLK_IGNORE_UNUSED;
  255. osc->hw.init = &init;
  256. osc->pmc = pmc;
  257. osc->irq = irq;
  258. osc->frequency = frequency;
  259. osc->accuracy = accuracy;
  260. init_waitqueue_head(&osc->wait);
  261. irq_set_status_flags(osc->irq, IRQ_NOAUTOEN);
  262. ret = request_irq(osc->irq, clk_main_rc_osc_irq_handler,
  263. IRQF_TRIGGER_HIGH, name, osc);
  264. if (ret)
  265. return ERR_PTR(ret);
  266. clk = clk_register(NULL, &osc->hw);
  267. if (IS_ERR(clk)) {
  268. free_irq(irq, osc);
  269. kfree(osc);
  270. }
  271. return clk;
  272. }
  273. void __init of_at91sam9x5_clk_main_rc_osc_setup(struct device_node *np,
  274. struct at91_pmc *pmc)
  275. {
  276. struct clk *clk;
  277. unsigned int irq;
  278. u32 frequency = 0;
  279. u32 accuracy = 0;
  280. const char *name = np->name;
  281. of_property_read_string(np, "clock-output-names", &name);
  282. of_property_read_u32(np, "clock-frequency", &frequency);
  283. of_property_read_u32(np, "clock-accuracy", &accuracy);
  284. irq = irq_of_parse_and_map(np, 0);
  285. if (!irq)
  286. return;
  287. clk = at91_clk_register_main_rc_osc(pmc, irq, name, frequency,
  288. accuracy);
  289. if (IS_ERR(clk))
  290. return;
  291. of_clk_add_provider(np, of_clk_src_simple_get, clk);
  292. }
  293. static int clk_main_probe_frequency(struct at91_pmc *pmc)
  294. {
  295. unsigned long prep_time, timeout;
  296. u32 tmp;
  297. timeout = jiffies + usecs_to_jiffies(MAINFRDY_TIMEOUT);
  298. do {
  299. prep_time = jiffies;
  300. tmp = pmc_read(pmc, AT91_CKGR_MCFR);
  301. if (tmp & AT91_PMC_MAINRDY)
  302. return 0;
  303. usleep_range(MAINF_LOOP_MIN_WAIT, MAINF_LOOP_MAX_WAIT);
  304. } while (time_before(prep_time, timeout));
  305. return -ETIMEDOUT;
  306. }
  307. static unsigned long clk_main_recalc_rate(struct at91_pmc *pmc,
  308. unsigned long parent_rate)
  309. {
  310. u32 tmp;
  311. if (parent_rate)
  312. return parent_rate;
  313. pr_warn("Main crystal frequency not set, using approximate value\n");
  314. tmp = pmc_read(pmc, AT91_CKGR_MCFR);
  315. if (!(tmp & AT91_PMC_MAINRDY))
  316. return 0;
  317. return ((tmp & AT91_PMC_MAINF) * SLOW_CLOCK_FREQ) / MAINF_DIV;
  318. }
  319. static int clk_rm9200_main_prepare(struct clk_hw *hw)
  320. {
  321. struct clk_rm9200_main *clkmain = to_clk_rm9200_main(hw);
  322. return clk_main_probe_frequency(clkmain->pmc);
  323. }
  324. static int clk_rm9200_main_is_prepared(struct clk_hw *hw)
  325. {
  326. struct clk_rm9200_main *clkmain = to_clk_rm9200_main(hw);
  327. return !!(pmc_read(clkmain->pmc, AT91_CKGR_MCFR) & AT91_PMC_MAINRDY);
  328. }
  329. static unsigned long clk_rm9200_main_recalc_rate(struct clk_hw *hw,
  330. unsigned long parent_rate)
  331. {
  332. struct clk_rm9200_main *clkmain = to_clk_rm9200_main(hw);
  333. return clk_main_recalc_rate(clkmain->pmc, parent_rate);
  334. }
  335. static const struct clk_ops rm9200_main_ops = {
  336. .prepare = clk_rm9200_main_prepare,
  337. .is_prepared = clk_rm9200_main_is_prepared,
  338. .recalc_rate = clk_rm9200_main_recalc_rate,
  339. };
  340. static struct clk * __init
  341. at91_clk_register_rm9200_main(struct at91_pmc *pmc,
  342. const char *name,
  343. const char *parent_name)
  344. {
  345. struct clk_rm9200_main *clkmain;
  346. struct clk *clk = NULL;
  347. struct clk_init_data init;
  348. if (!pmc || !name)
  349. return ERR_PTR(-EINVAL);
  350. if (!parent_name)
  351. return ERR_PTR(-EINVAL);
  352. clkmain = kzalloc(sizeof(*clkmain), GFP_KERNEL);
  353. if (!clkmain)
  354. return ERR_PTR(-ENOMEM);
  355. init.name = name;
  356. init.ops = &rm9200_main_ops;
  357. init.parent_names = &parent_name;
  358. init.num_parents = 1;
  359. init.flags = 0;
  360. clkmain->hw.init = &init;
  361. clkmain->pmc = pmc;
  362. clk = clk_register(NULL, &clkmain->hw);
  363. if (IS_ERR(clk))
  364. kfree(clkmain);
  365. return clk;
  366. }
  367. void __init of_at91rm9200_clk_main_setup(struct device_node *np,
  368. struct at91_pmc *pmc)
  369. {
  370. struct clk *clk;
  371. const char *parent_name;
  372. const char *name = np->name;
  373. parent_name = of_clk_get_parent_name(np, 0);
  374. of_property_read_string(np, "clock-output-names", &name);
  375. clk = at91_clk_register_rm9200_main(pmc, name, parent_name);
  376. if (IS_ERR(clk))
  377. return;
  378. of_clk_add_provider(np, of_clk_src_simple_get, clk);
  379. }
  380. static irqreturn_t clk_sam9x5_main_irq_handler(int irq, void *dev_id)
  381. {
  382. struct clk_sam9x5_main *clkmain = dev_id;
  383. wake_up(&clkmain->wait);
  384. disable_irq_nosync(clkmain->irq);
  385. return IRQ_HANDLED;
  386. }
  387. static int clk_sam9x5_main_prepare(struct clk_hw *hw)
  388. {
  389. struct clk_sam9x5_main *clkmain = to_clk_sam9x5_main(hw);
  390. struct at91_pmc *pmc = clkmain->pmc;
  391. while (!(pmc_read(pmc, AT91_PMC_SR) & AT91_PMC_MOSCSELS)) {
  392. enable_irq(clkmain->irq);
  393. wait_event(clkmain->wait,
  394. pmc_read(pmc, AT91_PMC_SR) & AT91_PMC_MOSCSELS);
  395. }
  396. return clk_main_probe_frequency(pmc);
  397. }
  398. static int clk_sam9x5_main_is_prepared(struct clk_hw *hw)
  399. {
  400. struct clk_sam9x5_main *clkmain = to_clk_sam9x5_main(hw);
  401. return !!(pmc_read(clkmain->pmc, AT91_PMC_SR) & AT91_PMC_MOSCSELS);
  402. }
  403. static unsigned long clk_sam9x5_main_recalc_rate(struct clk_hw *hw,
  404. unsigned long parent_rate)
  405. {
  406. struct clk_sam9x5_main *clkmain = to_clk_sam9x5_main(hw);
  407. return clk_main_recalc_rate(clkmain->pmc, parent_rate);
  408. }
  409. static int clk_sam9x5_main_set_parent(struct clk_hw *hw, u8 index)
  410. {
  411. struct clk_sam9x5_main *clkmain = to_clk_sam9x5_main(hw);
  412. struct at91_pmc *pmc = clkmain->pmc;
  413. u32 tmp;
  414. if (index > 1)
  415. return -EINVAL;
  416. tmp = pmc_read(pmc, AT91_CKGR_MOR) & ~MOR_KEY_MASK;
  417. if (index && !(tmp & AT91_PMC_MOSCSEL))
  418. pmc_write(pmc, AT91_CKGR_MOR, tmp | AT91_PMC_MOSCSEL);
  419. else if (!index && (tmp & AT91_PMC_MOSCSEL))
  420. pmc_write(pmc, AT91_CKGR_MOR, tmp & ~AT91_PMC_MOSCSEL);
  421. while (!(pmc_read(pmc, AT91_PMC_SR) & AT91_PMC_MOSCSELS)) {
  422. enable_irq(clkmain->irq);
  423. wait_event(clkmain->wait,
  424. pmc_read(pmc, AT91_PMC_SR) & AT91_PMC_MOSCSELS);
  425. }
  426. return 0;
  427. }
  428. static u8 clk_sam9x5_main_get_parent(struct clk_hw *hw)
  429. {
  430. struct clk_sam9x5_main *clkmain = to_clk_sam9x5_main(hw);
  431. return !!(pmc_read(clkmain->pmc, AT91_CKGR_MOR) & AT91_PMC_MOSCEN);
  432. }
  433. static const struct clk_ops sam9x5_main_ops = {
  434. .prepare = clk_sam9x5_main_prepare,
  435. .is_prepared = clk_sam9x5_main_is_prepared,
  436. .recalc_rate = clk_sam9x5_main_recalc_rate,
  437. .set_parent = clk_sam9x5_main_set_parent,
  438. .get_parent = clk_sam9x5_main_get_parent,
  439. };
  440. static struct clk * __init
  441. at91_clk_register_sam9x5_main(struct at91_pmc *pmc,
  442. unsigned int irq,
  443. const char *name,
  444. const char **parent_names,
  445. int num_parents)
  446. {
  447. int ret;
  448. struct clk_sam9x5_main *clkmain;
  449. struct clk *clk = NULL;
  450. struct clk_init_data init;
  451. if (!pmc || !irq || !name)
  452. return ERR_PTR(-EINVAL);
  453. if (!parent_names || !num_parents)
  454. return ERR_PTR(-EINVAL);
  455. clkmain = kzalloc(sizeof(*clkmain), GFP_KERNEL);
  456. if (!clkmain)
  457. return ERR_PTR(-ENOMEM);
  458. init.name = name;
  459. init.ops = &sam9x5_main_ops;
  460. init.parent_names = parent_names;
  461. init.num_parents = num_parents;
  462. init.flags = CLK_SET_PARENT_GATE;
  463. clkmain->hw.init = &init;
  464. clkmain->pmc = pmc;
  465. clkmain->irq = irq;
  466. clkmain->parent = !!(pmc_read(clkmain->pmc, AT91_CKGR_MOR) &
  467. AT91_PMC_MOSCEN);
  468. init_waitqueue_head(&clkmain->wait);
  469. irq_set_status_flags(clkmain->irq, IRQ_NOAUTOEN);
  470. ret = request_irq(clkmain->irq, clk_sam9x5_main_irq_handler,
  471. IRQF_TRIGGER_HIGH, name, clkmain);
  472. if (ret)
  473. return ERR_PTR(ret);
  474. clk = clk_register(NULL, &clkmain->hw);
  475. if (IS_ERR(clk)) {
  476. free_irq(clkmain->irq, clkmain);
  477. kfree(clkmain);
  478. }
  479. return clk;
  480. }
  481. void __init of_at91sam9x5_clk_main_setup(struct device_node *np,
  482. struct at91_pmc *pmc)
  483. {
  484. struct clk *clk;
  485. const char *parent_names[2];
  486. int num_parents;
  487. unsigned int irq;
  488. const char *name = np->name;
  489. num_parents = of_clk_get_parent_count(np);
  490. if (num_parents <= 0 || num_parents > 2)
  491. return;
  492. of_clk_parent_fill(np, parent_names, num_parents);
  493. of_property_read_string(np, "clock-output-names", &name);
  494. irq = irq_of_parse_and_map(np, 0);
  495. if (!irq)
  496. return;
  497. clk = at91_clk_register_sam9x5_main(pmc, irq, name, parent_names,
  498. num_parents);
  499. if (IS_ERR(clk))
  500. return;
  501. of_clk_add_provider(np, of_clk_src_simple_get, clk);
  502. }