clk-main.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  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. pr_warn("Main crystal frequency not set, using approximate value\n");
  312. tmp = pmc_read(pmc, AT91_CKGR_MCFR);
  313. if (!(tmp & AT91_PMC_MAINRDY))
  314. return 0;
  315. return ((tmp & AT91_PMC_MAINF) * SLOW_CLOCK_FREQ) / MAINF_DIV;
  316. }
  317. static int clk_rm9200_main_prepare(struct clk_hw *hw)
  318. {
  319. struct clk_rm9200_main *clkmain = to_clk_rm9200_main(hw);
  320. return clk_main_probe_frequency(clkmain->pmc);
  321. }
  322. static int clk_rm9200_main_is_prepared(struct clk_hw *hw)
  323. {
  324. struct clk_rm9200_main *clkmain = to_clk_rm9200_main(hw);
  325. return !!(pmc_read(clkmain->pmc, AT91_CKGR_MCFR) & AT91_PMC_MAINRDY);
  326. }
  327. static unsigned long clk_rm9200_main_recalc_rate(struct clk_hw *hw,
  328. unsigned long parent_rate)
  329. {
  330. struct clk_rm9200_main *clkmain = to_clk_rm9200_main(hw);
  331. return clk_main_recalc_rate(clkmain->pmc, parent_rate);
  332. }
  333. static const struct clk_ops rm9200_main_ops = {
  334. .prepare = clk_rm9200_main_prepare,
  335. .is_prepared = clk_rm9200_main_is_prepared,
  336. .recalc_rate = clk_rm9200_main_recalc_rate,
  337. };
  338. static struct clk * __init
  339. at91_clk_register_rm9200_main(struct at91_pmc *pmc,
  340. const char *name,
  341. const char *parent_name)
  342. {
  343. struct clk_rm9200_main *clkmain;
  344. struct clk *clk = NULL;
  345. struct clk_init_data init;
  346. if (!pmc || !name)
  347. return ERR_PTR(-EINVAL);
  348. if (!parent_name)
  349. return ERR_PTR(-EINVAL);
  350. clkmain = kzalloc(sizeof(*clkmain), GFP_KERNEL);
  351. if (!clkmain)
  352. return ERR_PTR(-ENOMEM);
  353. init.name = name;
  354. init.ops = &rm9200_main_ops;
  355. init.parent_names = &parent_name;
  356. init.num_parents = 1;
  357. init.flags = 0;
  358. clkmain->hw.init = &init;
  359. clkmain->pmc = pmc;
  360. clk = clk_register(NULL, &clkmain->hw);
  361. if (IS_ERR(clk))
  362. kfree(clkmain);
  363. return clk;
  364. }
  365. void __init of_at91rm9200_clk_main_setup(struct device_node *np,
  366. struct at91_pmc *pmc)
  367. {
  368. struct clk *clk;
  369. const char *parent_name;
  370. const char *name = np->name;
  371. parent_name = of_clk_get_parent_name(np, 0);
  372. of_property_read_string(np, "clock-output-names", &name);
  373. clk = at91_clk_register_rm9200_main(pmc, name, parent_name);
  374. if (IS_ERR(clk))
  375. return;
  376. of_clk_add_provider(np, of_clk_src_simple_get, clk);
  377. }
  378. static irqreturn_t clk_sam9x5_main_irq_handler(int irq, void *dev_id)
  379. {
  380. struct clk_sam9x5_main *clkmain = dev_id;
  381. wake_up(&clkmain->wait);
  382. disable_irq_nosync(clkmain->irq);
  383. return IRQ_HANDLED;
  384. }
  385. static int clk_sam9x5_main_prepare(struct clk_hw *hw)
  386. {
  387. struct clk_sam9x5_main *clkmain = to_clk_sam9x5_main(hw);
  388. struct at91_pmc *pmc = clkmain->pmc;
  389. while (!(pmc_read(pmc, AT91_PMC_SR) & AT91_PMC_MOSCSELS)) {
  390. enable_irq(clkmain->irq);
  391. wait_event(clkmain->wait,
  392. pmc_read(pmc, AT91_PMC_SR) & AT91_PMC_MOSCSELS);
  393. }
  394. return clk_main_probe_frequency(pmc);
  395. }
  396. static int clk_sam9x5_main_is_prepared(struct clk_hw *hw)
  397. {
  398. struct clk_sam9x5_main *clkmain = to_clk_sam9x5_main(hw);
  399. return !!(pmc_read(clkmain->pmc, AT91_PMC_SR) & AT91_PMC_MOSCSELS);
  400. }
  401. static unsigned long clk_sam9x5_main_recalc_rate(struct clk_hw *hw,
  402. unsigned long parent_rate)
  403. {
  404. struct clk_sam9x5_main *clkmain = to_clk_sam9x5_main(hw);
  405. return clk_main_recalc_rate(clkmain->pmc, parent_rate);
  406. }
  407. static int clk_sam9x5_main_set_parent(struct clk_hw *hw, u8 index)
  408. {
  409. struct clk_sam9x5_main *clkmain = to_clk_sam9x5_main(hw);
  410. struct at91_pmc *pmc = clkmain->pmc;
  411. u32 tmp;
  412. if (index > 1)
  413. return -EINVAL;
  414. tmp = pmc_read(pmc, AT91_CKGR_MOR) & ~MOR_KEY_MASK;
  415. if (index && !(tmp & AT91_PMC_MOSCSEL))
  416. pmc_write(pmc, AT91_CKGR_MOR, tmp | AT91_PMC_MOSCSEL);
  417. else if (!index && (tmp & AT91_PMC_MOSCSEL))
  418. pmc_write(pmc, AT91_CKGR_MOR, tmp & ~AT91_PMC_MOSCSEL);
  419. while (!(pmc_read(pmc, AT91_PMC_SR) & AT91_PMC_MOSCSELS)) {
  420. enable_irq(clkmain->irq);
  421. wait_event(clkmain->wait,
  422. pmc_read(pmc, AT91_PMC_SR) & AT91_PMC_MOSCSELS);
  423. }
  424. return 0;
  425. }
  426. static u8 clk_sam9x5_main_get_parent(struct clk_hw *hw)
  427. {
  428. struct clk_sam9x5_main *clkmain = to_clk_sam9x5_main(hw);
  429. return !!(pmc_read(clkmain->pmc, AT91_CKGR_MOR) & AT91_PMC_MOSCEN);
  430. }
  431. static const struct clk_ops sam9x5_main_ops = {
  432. .prepare = clk_sam9x5_main_prepare,
  433. .is_prepared = clk_sam9x5_main_is_prepared,
  434. .recalc_rate = clk_sam9x5_main_recalc_rate,
  435. .set_parent = clk_sam9x5_main_set_parent,
  436. .get_parent = clk_sam9x5_main_get_parent,
  437. };
  438. static struct clk * __init
  439. at91_clk_register_sam9x5_main(struct at91_pmc *pmc,
  440. unsigned int irq,
  441. const char *name,
  442. const char **parent_names,
  443. int num_parents)
  444. {
  445. int ret;
  446. struct clk_sam9x5_main *clkmain;
  447. struct clk *clk = NULL;
  448. struct clk_init_data init;
  449. if (!pmc || !irq || !name)
  450. return ERR_PTR(-EINVAL);
  451. if (!parent_names || !num_parents)
  452. return ERR_PTR(-EINVAL);
  453. clkmain = kzalloc(sizeof(*clkmain), GFP_KERNEL);
  454. if (!clkmain)
  455. return ERR_PTR(-ENOMEM);
  456. init.name = name;
  457. init.ops = &sam9x5_main_ops;
  458. init.parent_names = parent_names;
  459. init.num_parents = num_parents;
  460. init.flags = CLK_SET_PARENT_GATE;
  461. clkmain->hw.init = &init;
  462. clkmain->pmc = pmc;
  463. clkmain->irq = irq;
  464. clkmain->parent = !!(pmc_read(clkmain->pmc, AT91_CKGR_MOR) &
  465. AT91_PMC_MOSCEN);
  466. init_waitqueue_head(&clkmain->wait);
  467. irq_set_status_flags(clkmain->irq, IRQ_NOAUTOEN);
  468. ret = request_irq(clkmain->irq, clk_sam9x5_main_irq_handler,
  469. IRQF_TRIGGER_HIGH, name, clkmain);
  470. if (ret)
  471. return ERR_PTR(ret);
  472. clk = clk_register(NULL, &clkmain->hw);
  473. if (IS_ERR(clk)) {
  474. free_irq(clkmain->irq, clkmain);
  475. kfree(clkmain);
  476. }
  477. return clk;
  478. }
  479. void __init of_at91sam9x5_clk_main_setup(struct device_node *np,
  480. struct at91_pmc *pmc)
  481. {
  482. struct clk *clk;
  483. const char *parent_names[2];
  484. int num_parents;
  485. unsigned int irq;
  486. const char *name = np->name;
  487. int i;
  488. num_parents = of_count_phandle_with_args(np, "clocks", "#clock-cells");
  489. if (num_parents <= 0 || num_parents > 2)
  490. return;
  491. for (i = 0; i < num_parents; ++i) {
  492. parent_names[i] = of_clk_get_parent_name(np, i);
  493. if (!parent_names[i])
  494. return;
  495. }
  496. of_property_read_string(np, "clock-output-names", &name);
  497. irq = irq_of_parse_and_map(np, 0);
  498. if (!irq)
  499. return;
  500. clk = at91_clk_register_sam9x5_main(pmc, irq, name, parent_names,
  501. num_parents);
  502. if (IS_ERR(clk))
  503. return;
  504. of_clk_add_provider(np, of_clk_src_simple_get, clk);
  505. }