clk-main.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638
  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. return ERR_PTR(ret);
  142. if (bypass)
  143. pmc_write(pmc, AT91_CKGR_MOR,
  144. (pmc_read(pmc, AT91_CKGR_MOR) &
  145. ~(MOR_KEY_MASK | AT91_PMC_MOSCEN)) |
  146. AT91_PMC_OSCBYPASS | AT91_PMC_KEY);
  147. clk = clk_register(NULL, &osc->hw);
  148. if (IS_ERR(clk)) {
  149. free_irq(irq, osc);
  150. kfree(osc);
  151. }
  152. return clk;
  153. }
  154. void __init of_at91rm9200_clk_main_osc_setup(struct device_node *np,
  155. struct at91_pmc *pmc)
  156. {
  157. struct clk *clk;
  158. unsigned int irq;
  159. const char *name = np->name;
  160. const char *parent_name;
  161. bool bypass;
  162. of_property_read_string(np, "clock-output-names", &name);
  163. bypass = of_property_read_bool(np, "atmel,osc-bypass");
  164. parent_name = of_clk_get_parent_name(np, 0);
  165. irq = irq_of_parse_and_map(np, 0);
  166. if (!irq)
  167. return;
  168. clk = at91_clk_register_main_osc(pmc, irq, name, parent_name, bypass);
  169. if (IS_ERR(clk))
  170. return;
  171. of_clk_add_provider(np, of_clk_src_simple_get, clk);
  172. }
  173. static irqreturn_t clk_main_rc_osc_irq_handler(int irq, void *dev_id)
  174. {
  175. struct clk_main_rc_osc *osc = dev_id;
  176. wake_up(&osc->wait);
  177. disable_irq_nosync(osc->irq);
  178. return IRQ_HANDLED;
  179. }
  180. static int clk_main_rc_osc_prepare(struct clk_hw *hw)
  181. {
  182. struct clk_main_rc_osc *osc = to_clk_main_rc_osc(hw);
  183. struct at91_pmc *pmc = osc->pmc;
  184. u32 tmp;
  185. tmp = pmc_read(pmc, AT91_CKGR_MOR) & ~MOR_KEY_MASK;
  186. if (!(tmp & AT91_PMC_MOSCRCEN)) {
  187. tmp |= AT91_PMC_MOSCRCEN | AT91_PMC_KEY;
  188. pmc_write(pmc, AT91_CKGR_MOR, tmp);
  189. }
  190. while (!(pmc_read(pmc, AT91_PMC_SR) & AT91_PMC_MOSCRCS)) {
  191. enable_irq(osc->irq);
  192. wait_event(osc->wait,
  193. pmc_read(pmc, AT91_PMC_SR) & AT91_PMC_MOSCRCS);
  194. }
  195. return 0;
  196. }
  197. static void clk_main_rc_osc_unprepare(struct clk_hw *hw)
  198. {
  199. struct clk_main_rc_osc *osc = to_clk_main_rc_osc(hw);
  200. struct at91_pmc *pmc = osc->pmc;
  201. u32 tmp = pmc_read(pmc, AT91_CKGR_MOR);
  202. if (!(tmp & AT91_PMC_MOSCRCEN))
  203. return;
  204. tmp &= ~(MOR_KEY_MASK | AT91_PMC_MOSCRCEN);
  205. pmc_write(pmc, AT91_CKGR_MOR, tmp | AT91_PMC_KEY);
  206. }
  207. static int clk_main_rc_osc_is_prepared(struct clk_hw *hw)
  208. {
  209. struct clk_main_rc_osc *osc = to_clk_main_rc_osc(hw);
  210. struct at91_pmc *pmc = osc->pmc;
  211. return !!((pmc_read(pmc, AT91_PMC_SR) & AT91_PMC_MOSCRCS) &&
  212. (pmc_read(pmc, AT91_CKGR_MOR) & AT91_PMC_MOSCRCEN));
  213. }
  214. static unsigned long clk_main_rc_osc_recalc_rate(struct clk_hw *hw,
  215. unsigned long parent_rate)
  216. {
  217. struct clk_main_rc_osc *osc = to_clk_main_rc_osc(hw);
  218. return osc->frequency;
  219. }
  220. static unsigned long clk_main_rc_osc_recalc_accuracy(struct clk_hw *hw,
  221. unsigned long parent_acc)
  222. {
  223. struct clk_main_rc_osc *osc = to_clk_main_rc_osc(hw);
  224. return osc->accuracy;
  225. }
  226. static const struct clk_ops main_rc_osc_ops = {
  227. .prepare = clk_main_rc_osc_prepare,
  228. .unprepare = clk_main_rc_osc_unprepare,
  229. .is_prepared = clk_main_rc_osc_is_prepared,
  230. .recalc_rate = clk_main_rc_osc_recalc_rate,
  231. .recalc_accuracy = clk_main_rc_osc_recalc_accuracy,
  232. };
  233. static struct clk * __init
  234. at91_clk_register_main_rc_osc(struct at91_pmc *pmc,
  235. unsigned int irq,
  236. const char *name,
  237. u32 frequency, u32 accuracy)
  238. {
  239. int ret;
  240. struct clk_main_rc_osc *osc;
  241. struct clk *clk = NULL;
  242. struct clk_init_data init;
  243. if (!pmc || !irq || !name || !frequency)
  244. return ERR_PTR(-EINVAL);
  245. osc = kzalloc(sizeof(*osc), GFP_KERNEL);
  246. if (!osc)
  247. return ERR_PTR(-ENOMEM);
  248. init.name = name;
  249. init.ops = &main_rc_osc_ops;
  250. init.parent_names = NULL;
  251. init.num_parents = 0;
  252. init.flags = CLK_IS_ROOT | CLK_IGNORE_UNUSED;
  253. osc->hw.init = &init;
  254. osc->pmc = pmc;
  255. osc->irq = irq;
  256. osc->frequency = frequency;
  257. osc->accuracy = accuracy;
  258. init_waitqueue_head(&osc->wait);
  259. irq_set_status_flags(osc->irq, IRQ_NOAUTOEN);
  260. ret = request_irq(osc->irq, clk_main_rc_osc_irq_handler,
  261. IRQF_TRIGGER_HIGH, name, osc);
  262. if (ret)
  263. return ERR_PTR(ret);
  264. clk = clk_register(NULL, &osc->hw);
  265. if (IS_ERR(clk)) {
  266. free_irq(irq, osc);
  267. kfree(osc);
  268. }
  269. return clk;
  270. }
  271. void __init of_at91sam9x5_clk_main_rc_osc_setup(struct device_node *np,
  272. struct at91_pmc *pmc)
  273. {
  274. struct clk *clk;
  275. unsigned int irq;
  276. u32 frequency = 0;
  277. u32 accuracy = 0;
  278. const char *name = np->name;
  279. of_property_read_string(np, "clock-output-names", &name);
  280. of_property_read_u32(np, "clock-frequency", &frequency);
  281. of_property_read_u32(np, "clock-accuracy", &accuracy);
  282. irq = irq_of_parse_and_map(np, 0);
  283. if (!irq)
  284. return;
  285. clk = at91_clk_register_main_rc_osc(pmc, irq, name, frequency,
  286. accuracy);
  287. if (IS_ERR(clk))
  288. return;
  289. of_clk_add_provider(np, of_clk_src_simple_get, clk);
  290. }
  291. static int clk_main_probe_frequency(struct at91_pmc *pmc)
  292. {
  293. unsigned long prep_time, timeout;
  294. u32 tmp;
  295. timeout = jiffies + usecs_to_jiffies(MAINFRDY_TIMEOUT);
  296. do {
  297. prep_time = jiffies;
  298. tmp = pmc_read(pmc, AT91_CKGR_MCFR);
  299. if (tmp & AT91_PMC_MAINRDY)
  300. return 0;
  301. usleep_range(MAINF_LOOP_MIN_WAIT, MAINF_LOOP_MAX_WAIT);
  302. } while (time_before(prep_time, timeout));
  303. return -ETIMEDOUT;
  304. }
  305. static unsigned long clk_main_recalc_rate(struct at91_pmc *pmc,
  306. unsigned long parent_rate)
  307. {
  308. u32 tmp;
  309. if (parent_rate)
  310. return parent_rate;
  311. tmp = pmc_read(pmc, AT91_CKGR_MCFR);
  312. if (!(tmp & AT91_PMC_MAINRDY))
  313. return 0;
  314. return ((tmp & AT91_PMC_MAINF) * SLOW_CLOCK_FREQ) / MAINF_DIV;
  315. }
  316. static int clk_rm9200_main_prepare(struct clk_hw *hw)
  317. {
  318. struct clk_rm9200_main *clkmain = to_clk_rm9200_main(hw);
  319. return clk_main_probe_frequency(clkmain->pmc);
  320. }
  321. static int clk_rm9200_main_is_prepared(struct clk_hw *hw)
  322. {
  323. struct clk_rm9200_main *clkmain = to_clk_rm9200_main(hw);
  324. return !!(pmc_read(clkmain->pmc, AT91_CKGR_MCFR) & AT91_PMC_MAINRDY);
  325. }
  326. static unsigned long clk_rm9200_main_recalc_rate(struct clk_hw *hw,
  327. unsigned long parent_rate)
  328. {
  329. struct clk_rm9200_main *clkmain = to_clk_rm9200_main(hw);
  330. return clk_main_recalc_rate(clkmain->pmc, parent_rate);
  331. }
  332. static const struct clk_ops rm9200_main_ops = {
  333. .prepare = clk_rm9200_main_prepare,
  334. .is_prepared = clk_rm9200_main_is_prepared,
  335. .recalc_rate = clk_rm9200_main_recalc_rate,
  336. };
  337. static struct clk * __init
  338. at91_clk_register_rm9200_main(struct at91_pmc *pmc,
  339. const char *name,
  340. const char *parent_name)
  341. {
  342. struct clk_rm9200_main *clkmain;
  343. struct clk *clk = NULL;
  344. struct clk_init_data init;
  345. if (!pmc || !name)
  346. return ERR_PTR(-EINVAL);
  347. if (!parent_name)
  348. return ERR_PTR(-EINVAL);
  349. clkmain = kzalloc(sizeof(*clkmain), GFP_KERNEL);
  350. if (!clkmain)
  351. return ERR_PTR(-ENOMEM);
  352. init.name = name;
  353. init.ops = &rm9200_main_ops;
  354. init.parent_names = &parent_name;
  355. init.num_parents = 1;
  356. init.flags = 0;
  357. clkmain->hw.init = &init;
  358. clkmain->pmc = pmc;
  359. clk = clk_register(NULL, &clkmain->hw);
  360. if (IS_ERR(clk))
  361. kfree(clkmain);
  362. return clk;
  363. }
  364. void __init of_at91rm9200_clk_main_setup(struct device_node *np,
  365. struct at91_pmc *pmc)
  366. {
  367. struct clk *clk;
  368. const char *parent_name;
  369. const char *name = np->name;
  370. parent_name = of_clk_get_parent_name(np, 0);
  371. of_property_read_string(np, "clock-output-names", &name);
  372. clk = at91_clk_register_rm9200_main(pmc, name, parent_name);
  373. if (IS_ERR(clk))
  374. return;
  375. of_clk_add_provider(np, of_clk_src_simple_get, clk);
  376. }
  377. static irqreturn_t clk_sam9x5_main_irq_handler(int irq, void *dev_id)
  378. {
  379. struct clk_sam9x5_main *clkmain = dev_id;
  380. wake_up(&clkmain->wait);
  381. disable_irq_nosync(clkmain->irq);
  382. return IRQ_HANDLED;
  383. }
  384. static int clk_sam9x5_main_prepare(struct clk_hw *hw)
  385. {
  386. struct clk_sam9x5_main *clkmain = to_clk_sam9x5_main(hw);
  387. struct at91_pmc *pmc = clkmain->pmc;
  388. while (!(pmc_read(pmc, AT91_PMC_SR) & AT91_PMC_MOSCSELS)) {
  389. enable_irq(clkmain->irq);
  390. wait_event(clkmain->wait,
  391. pmc_read(pmc, AT91_PMC_SR) & AT91_PMC_MOSCSELS);
  392. }
  393. return clk_main_probe_frequency(pmc);
  394. }
  395. static int clk_sam9x5_main_is_prepared(struct clk_hw *hw)
  396. {
  397. struct clk_sam9x5_main *clkmain = to_clk_sam9x5_main(hw);
  398. return !!(pmc_read(clkmain->pmc, AT91_PMC_SR) & AT91_PMC_MOSCSELS);
  399. }
  400. static unsigned long clk_sam9x5_main_recalc_rate(struct clk_hw *hw,
  401. unsigned long parent_rate)
  402. {
  403. struct clk_sam9x5_main *clkmain = to_clk_sam9x5_main(hw);
  404. return clk_main_recalc_rate(clkmain->pmc, parent_rate);
  405. }
  406. static int clk_sam9x5_main_set_parent(struct clk_hw *hw, u8 index)
  407. {
  408. struct clk_sam9x5_main *clkmain = to_clk_sam9x5_main(hw);
  409. struct at91_pmc *pmc = clkmain->pmc;
  410. u32 tmp;
  411. if (index > 1)
  412. return -EINVAL;
  413. tmp = pmc_read(pmc, AT91_CKGR_MOR) & ~MOR_KEY_MASK;
  414. if (index && !(tmp & AT91_PMC_MOSCSEL))
  415. pmc_write(pmc, AT91_CKGR_MOR, tmp | AT91_PMC_MOSCSEL);
  416. else if (!index && (tmp & AT91_PMC_MOSCSEL))
  417. pmc_write(pmc, AT91_CKGR_MOR, tmp & ~AT91_PMC_MOSCSEL);
  418. while (!(pmc_read(pmc, AT91_PMC_SR) & AT91_PMC_MOSCSELS)) {
  419. enable_irq(clkmain->irq);
  420. wait_event(clkmain->wait,
  421. pmc_read(pmc, AT91_PMC_SR) & AT91_PMC_MOSCSELS);
  422. }
  423. return 0;
  424. }
  425. static u8 clk_sam9x5_main_get_parent(struct clk_hw *hw)
  426. {
  427. struct clk_sam9x5_main *clkmain = to_clk_sam9x5_main(hw);
  428. return !!(pmc_read(clkmain->pmc, AT91_CKGR_MOR) & AT91_PMC_MOSCEN);
  429. }
  430. static const struct clk_ops sam9x5_main_ops = {
  431. .prepare = clk_sam9x5_main_prepare,
  432. .is_prepared = clk_sam9x5_main_is_prepared,
  433. .recalc_rate = clk_sam9x5_main_recalc_rate,
  434. .set_parent = clk_sam9x5_main_set_parent,
  435. .get_parent = clk_sam9x5_main_get_parent,
  436. };
  437. static struct clk * __init
  438. at91_clk_register_sam9x5_main(struct at91_pmc *pmc,
  439. unsigned int irq,
  440. const char *name,
  441. const char **parent_names,
  442. int num_parents)
  443. {
  444. int ret;
  445. struct clk_sam9x5_main *clkmain;
  446. struct clk *clk = NULL;
  447. struct clk_init_data init;
  448. if (!pmc || !irq || !name)
  449. return ERR_PTR(-EINVAL);
  450. if (!parent_names || !num_parents)
  451. return ERR_PTR(-EINVAL);
  452. clkmain = kzalloc(sizeof(*clkmain), GFP_KERNEL);
  453. if (!clkmain)
  454. return ERR_PTR(-ENOMEM);
  455. init.name = name;
  456. init.ops = &sam9x5_main_ops;
  457. init.parent_names = parent_names;
  458. init.num_parents = num_parents;
  459. init.flags = CLK_SET_PARENT_GATE;
  460. clkmain->hw.init = &init;
  461. clkmain->pmc = pmc;
  462. clkmain->irq = irq;
  463. clkmain->parent = !!(pmc_read(clkmain->pmc, AT91_CKGR_MOR) &
  464. AT91_PMC_MOSCEN);
  465. init_waitqueue_head(&clkmain->wait);
  466. irq_set_status_flags(clkmain->irq, IRQ_NOAUTOEN);
  467. ret = request_irq(clkmain->irq, clk_sam9x5_main_irq_handler,
  468. IRQF_TRIGGER_HIGH, name, clkmain);
  469. if (ret)
  470. return ERR_PTR(ret);
  471. clk = clk_register(NULL, &clkmain->hw);
  472. if (IS_ERR(clk)) {
  473. free_irq(clkmain->irq, clkmain);
  474. kfree(clkmain);
  475. }
  476. return clk;
  477. }
  478. void __init of_at91sam9x5_clk_main_setup(struct device_node *np,
  479. struct at91_pmc *pmc)
  480. {
  481. struct clk *clk;
  482. const char *parent_names[2];
  483. int num_parents;
  484. unsigned int irq;
  485. const char *name = np->name;
  486. int i;
  487. num_parents = of_count_phandle_with_args(np, "clocks", "#clock-cells");
  488. if (num_parents <= 0 || num_parents > 2)
  489. return;
  490. for (i = 0; i < num_parents; ++i) {
  491. parent_names[i] = of_clk_get_parent_name(np, i);
  492. if (!parent_names[i])
  493. return;
  494. }
  495. of_property_read_string(np, "clock-output-names", &name);
  496. irq = irq_of_parse_and_map(np, 0);
  497. if (!irq)
  498. return;
  499. clk = at91_clk_register_sam9x5_main(pmc, irq, name, parent_names,
  500. num_parents);
  501. if (IS_ERR(clk))
  502. return;
  503. of_clk_add_provider(np, of_clk_src_simple_get, clk);
  504. }