dt-compat.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <linux/clk-provider.h>
  3. #include <linux/clk/at91_pmc.h>
  4. #include <linux/of.h>
  5. #include <linux/mfd/syscon.h>
  6. #include <linux/regmap.h>
  7. #include <linux/slab.h>
  8. #include "pmc.h"
  9. #define MASTER_SOURCE_MAX 4
  10. #define PERIPHERAL_AT91RM9200 0
  11. #define PERIPHERAL_AT91SAM9X5 1
  12. #define PERIPHERAL_MAX 64
  13. #define PERIPHERAL_ID_MIN 2
  14. #define PROG_SOURCE_MAX 5
  15. #define PROG_ID_MAX 7
  16. #define SYSTEM_MAX_ID 31
  17. #ifdef CONFIG_HAVE_AT91_AUDIO_PLL
  18. static void __init of_sama5d2_clk_audio_pll_frac_setup(struct device_node *np)
  19. {
  20. struct clk_hw *hw;
  21. const char *name = np->name;
  22. const char *parent_name;
  23. struct regmap *regmap;
  24. regmap = syscon_node_to_regmap(of_get_parent(np));
  25. if (IS_ERR(regmap))
  26. return;
  27. parent_name = of_clk_get_parent_name(np, 0);
  28. hw = at91_clk_register_audio_pll_frac(regmap, name, parent_name);
  29. if (IS_ERR(hw))
  30. return;
  31. of_clk_add_hw_provider(np, of_clk_hw_simple_get, hw);
  32. }
  33. CLK_OF_DECLARE(of_sama5d2_clk_audio_pll_frac_setup,
  34. "atmel,sama5d2-clk-audio-pll-frac",
  35. of_sama5d2_clk_audio_pll_frac_setup);
  36. static void __init of_sama5d2_clk_audio_pll_pad_setup(struct device_node *np)
  37. {
  38. struct clk_hw *hw;
  39. const char *name = np->name;
  40. const char *parent_name;
  41. struct regmap *regmap;
  42. regmap = syscon_node_to_regmap(of_get_parent(np));
  43. if (IS_ERR(regmap))
  44. return;
  45. parent_name = of_clk_get_parent_name(np, 0);
  46. hw = at91_clk_register_audio_pll_pad(regmap, name, parent_name);
  47. if (IS_ERR(hw))
  48. return;
  49. of_clk_add_hw_provider(np, of_clk_hw_simple_get, hw);
  50. }
  51. CLK_OF_DECLARE(of_sama5d2_clk_audio_pll_pad_setup,
  52. "atmel,sama5d2-clk-audio-pll-pad",
  53. of_sama5d2_clk_audio_pll_pad_setup);
  54. static void __init of_sama5d2_clk_audio_pll_pmc_setup(struct device_node *np)
  55. {
  56. struct clk_hw *hw;
  57. const char *name = np->name;
  58. const char *parent_name;
  59. struct regmap *regmap;
  60. regmap = syscon_node_to_regmap(of_get_parent(np));
  61. if (IS_ERR(regmap))
  62. return;
  63. parent_name = of_clk_get_parent_name(np, 0);
  64. hw = at91_clk_register_audio_pll_pmc(regmap, name, parent_name);
  65. if (IS_ERR(hw))
  66. return;
  67. of_clk_add_hw_provider(np, of_clk_hw_simple_get, hw);
  68. }
  69. CLK_OF_DECLARE(of_sama5d2_clk_audio_pll_pmc_setup,
  70. "atmel,sama5d2-clk-audio-pll-pmc",
  71. of_sama5d2_clk_audio_pll_pmc_setup);
  72. #endif /* CONFIG_HAVE_AT91_AUDIO_PLL */
  73. #ifdef CONFIG_HAVE_AT91_GENERATED_CLK
  74. #define GENERATED_SOURCE_MAX 6
  75. #define GCK_ID_I2S0 54
  76. #define GCK_ID_I2S1 55
  77. #define GCK_ID_CLASSD 59
  78. static void __init of_sama5d2_clk_generated_setup(struct device_node *np)
  79. {
  80. int num;
  81. u32 id;
  82. const char *name;
  83. struct clk_hw *hw;
  84. unsigned int num_parents;
  85. const char *parent_names[GENERATED_SOURCE_MAX];
  86. struct device_node *gcknp;
  87. struct clk_range range = CLK_RANGE(0, 0);
  88. struct regmap *regmap;
  89. num_parents = of_clk_get_parent_count(np);
  90. if (num_parents == 0 || num_parents > GENERATED_SOURCE_MAX)
  91. return;
  92. of_clk_parent_fill(np, parent_names, num_parents);
  93. num = of_get_child_count(np);
  94. if (!num || num > PERIPHERAL_MAX)
  95. return;
  96. regmap = syscon_node_to_regmap(of_get_parent(np));
  97. if (IS_ERR(regmap))
  98. return;
  99. for_each_child_of_node(np, gcknp) {
  100. bool pll_audio = false;
  101. if (of_property_read_u32(gcknp, "reg", &id))
  102. continue;
  103. if (id < PERIPHERAL_ID_MIN || id >= PERIPHERAL_MAX)
  104. continue;
  105. if (of_property_read_string(np, "clock-output-names", &name))
  106. name = gcknp->name;
  107. of_at91_get_clk_range(gcknp, "atmel,clk-output-range",
  108. &range);
  109. if (of_device_is_compatible(np, "atmel,sama5d2-clk-generated") &&
  110. (id == GCK_ID_I2S0 || id == GCK_ID_I2S1 ||
  111. id == GCK_ID_CLASSD))
  112. pll_audio = true;
  113. hw = at91_clk_register_generated(regmap, &pmc_pcr_lock, name,
  114. parent_names, num_parents,
  115. id, pll_audio, &range);
  116. if (IS_ERR(hw))
  117. continue;
  118. of_clk_add_hw_provider(gcknp, of_clk_hw_simple_get, hw);
  119. }
  120. }
  121. CLK_OF_DECLARE(of_sama5d2_clk_generated_setup, "atmel,sama5d2-clk-generated",
  122. of_sama5d2_clk_generated_setup);
  123. #endif /* CONFIG_HAVE_AT91_GENERATED_CLK */
  124. #ifdef CONFIG_HAVE_AT91_H32MX
  125. static void __init of_sama5d4_clk_h32mx_setup(struct device_node *np)
  126. {
  127. struct clk_hw *hw;
  128. const char *name = np->name;
  129. const char *parent_name;
  130. struct regmap *regmap;
  131. regmap = syscon_node_to_regmap(of_get_parent(np));
  132. if (IS_ERR(regmap))
  133. return;
  134. parent_name = of_clk_get_parent_name(np, 0);
  135. hw = at91_clk_register_h32mx(regmap, name, parent_name);
  136. if (IS_ERR(hw))
  137. return;
  138. of_clk_add_hw_provider(np, of_clk_hw_simple_get, hw);
  139. }
  140. CLK_OF_DECLARE(of_sama5d4_clk_h32mx_setup, "atmel,sama5d4-clk-h32mx",
  141. of_sama5d4_clk_h32mx_setup);
  142. #endif /* CONFIG_HAVE_AT91_H32MX */
  143. #ifdef CONFIG_HAVE_AT91_I2S_MUX_CLK
  144. #define I2S_BUS_NR 2
  145. static void __init of_sama5d2_clk_i2s_mux_setup(struct device_node *np)
  146. {
  147. struct regmap *regmap_sfr;
  148. u8 bus_id;
  149. const char *parent_names[2];
  150. struct device_node *i2s_mux_np;
  151. struct clk_hw *hw;
  152. int ret;
  153. regmap_sfr = syscon_regmap_lookup_by_compatible("atmel,sama5d2-sfr");
  154. if (IS_ERR(regmap_sfr))
  155. return;
  156. for_each_child_of_node(np, i2s_mux_np) {
  157. if (of_property_read_u8(i2s_mux_np, "reg", &bus_id))
  158. continue;
  159. if (bus_id > I2S_BUS_NR)
  160. continue;
  161. ret = of_clk_parent_fill(i2s_mux_np, parent_names, 2);
  162. if (ret != 2)
  163. continue;
  164. hw = at91_clk_i2s_mux_register(regmap_sfr, i2s_mux_np->name,
  165. parent_names, 2, bus_id);
  166. if (IS_ERR(hw))
  167. continue;
  168. of_clk_add_hw_provider(i2s_mux_np, of_clk_hw_simple_get, hw);
  169. }
  170. }
  171. CLK_OF_DECLARE(sama5d2_clk_i2s_mux, "atmel,sama5d2-clk-i2s-mux",
  172. of_sama5d2_clk_i2s_mux_setup);
  173. #endif /* CONFIG_HAVE_AT91_I2S_MUX_CLK */
  174. static void __init of_at91rm9200_clk_main_osc_setup(struct device_node *np)
  175. {
  176. struct clk_hw *hw;
  177. const char *name = np->name;
  178. const char *parent_name;
  179. struct regmap *regmap;
  180. bool bypass;
  181. of_property_read_string(np, "clock-output-names", &name);
  182. bypass = of_property_read_bool(np, "atmel,osc-bypass");
  183. parent_name = of_clk_get_parent_name(np, 0);
  184. regmap = syscon_node_to_regmap(of_get_parent(np));
  185. if (IS_ERR(regmap))
  186. return;
  187. hw = at91_clk_register_main_osc(regmap, name, parent_name, bypass);
  188. if (IS_ERR(hw))
  189. return;
  190. of_clk_add_hw_provider(np, of_clk_hw_simple_get, hw);
  191. }
  192. CLK_OF_DECLARE(at91rm9200_clk_main_osc, "atmel,at91rm9200-clk-main-osc",
  193. of_at91rm9200_clk_main_osc_setup);
  194. static void __init of_at91sam9x5_clk_main_rc_osc_setup(struct device_node *np)
  195. {
  196. struct clk_hw *hw;
  197. u32 frequency = 0;
  198. u32 accuracy = 0;
  199. const char *name = np->name;
  200. struct regmap *regmap;
  201. of_property_read_string(np, "clock-output-names", &name);
  202. of_property_read_u32(np, "clock-frequency", &frequency);
  203. of_property_read_u32(np, "clock-accuracy", &accuracy);
  204. regmap = syscon_node_to_regmap(of_get_parent(np));
  205. if (IS_ERR(regmap))
  206. return;
  207. hw = at91_clk_register_main_rc_osc(regmap, name, frequency, accuracy);
  208. if (IS_ERR(hw))
  209. return;
  210. of_clk_add_hw_provider(np, of_clk_hw_simple_get, hw);
  211. }
  212. CLK_OF_DECLARE(at91sam9x5_clk_main_rc_osc, "atmel,at91sam9x5-clk-main-rc-osc",
  213. of_at91sam9x5_clk_main_rc_osc_setup);
  214. static void __init of_at91rm9200_clk_main_setup(struct device_node *np)
  215. {
  216. struct clk_hw *hw;
  217. const char *parent_name;
  218. const char *name = np->name;
  219. struct regmap *regmap;
  220. parent_name = of_clk_get_parent_name(np, 0);
  221. of_property_read_string(np, "clock-output-names", &name);
  222. regmap = syscon_node_to_regmap(of_get_parent(np));
  223. if (IS_ERR(regmap))
  224. return;
  225. hw = at91_clk_register_rm9200_main(regmap, name, parent_name);
  226. if (IS_ERR(hw))
  227. return;
  228. of_clk_add_hw_provider(np, of_clk_hw_simple_get, hw);
  229. }
  230. CLK_OF_DECLARE(at91rm9200_clk_main, "atmel,at91rm9200-clk-main",
  231. of_at91rm9200_clk_main_setup);
  232. static void __init of_at91sam9x5_clk_main_setup(struct device_node *np)
  233. {
  234. struct clk_hw *hw;
  235. const char *parent_names[2];
  236. unsigned int num_parents;
  237. const char *name = np->name;
  238. struct regmap *regmap;
  239. num_parents = of_clk_get_parent_count(np);
  240. if (num_parents == 0 || num_parents > 2)
  241. return;
  242. of_clk_parent_fill(np, parent_names, num_parents);
  243. regmap = syscon_node_to_regmap(of_get_parent(np));
  244. if (IS_ERR(regmap))
  245. return;
  246. of_property_read_string(np, "clock-output-names", &name);
  247. hw = at91_clk_register_sam9x5_main(regmap, name, parent_names,
  248. num_parents);
  249. if (IS_ERR(hw))
  250. return;
  251. of_clk_add_hw_provider(np, of_clk_hw_simple_get, hw);
  252. }
  253. CLK_OF_DECLARE(at91sam9x5_clk_main, "atmel,at91sam9x5-clk-main",
  254. of_at91sam9x5_clk_main_setup);
  255. static struct clk_master_characteristics * __init
  256. of_at91_clk_master_get_characteristics(struct device_node *np)
  257. {
  258. struct clk_master_characteristics *characteristics;
  259. characteristics = kzalloc(sizeof(*characteristics), GFP_KERNEL);
  260. if (!characteristics)
  261. return NULL;
  262. if (of_at91_get_clk_range(np, "atmel,clk-output-range", &characteristics->output))
  263. goto out_free_characteristics;
  264. of_property_read_u32_array(np, "atmel,clk-divisors",
  265. characteristics->divisors, 4);
  266. characteristics->have_div3_pres =
  267. of_property_read_bool(np, "atmel,master-clk-have-div3-pres");
  268. return characteristics;
  269. out_free_characteristics:
  270. kfree(characteristics);
  271. return NULL;
  272. }
  273. static void __init
  274. of_at91_clk_master_setup(struct device_node *np,
  275. const struct clk_master_layout *layout)
  276. {
  277. struct clk_hw *hw;
  278. unsigned int num_parents;
  279. const char *parent_names[MASTER_SOURCE_MAX];
  280. const char *name = np->name;
  281. struct clk_master_characteristics *characteristics;
  282. struct regmap *regmap;
  283. num_parents = of_clk_get_parent_count(np);
  284. if (num_parents == 0 || num_parents > MASTER_SOURCE_MAX)
  285. return;
  286. of_clk_parent_fill(np, parent_names, num_parents);
  287. of_property_read_string(np, "clock-output-names", &name);
  288. characteristics = of_at91_clk_master_get_characteristics(np);
  289. if (!characteristics)
  290. return;
  291. regmap = syscon_node_to_regmap(of_get_parent(np));
  292. if (IS_ERR(regmap))
  293. return;
  294. hw = at91_clk_register_master(regmap, name, num_parents,
  295. parent_names, layout,
  296. characteristics);
  297. if (IS_ERR(hw))
  298. goto out_free_characteristics;
  299. of_clk_add_hw_provider(np, of_clk_hw_simple_get, hw);
  300. return;
  301. out_free_characteristics:
  302. kfree(characteristics);
  303. }
  304. static void __init of_at91rm9200_clk_master_setup(struct device_node *np)
  305. {
  306. of_at91_clk_master_setup(np, &at91rm9200_master_layout);
  307. }
  308. CLK_OF_DECLARE(at91rm9200_clk_master, "atmel,at91rm9200-clk-master",
  309. of_at91rm9200_clk_master_setup);
  310. static void __init of_at91sam9x5_clk_master_setup(struct device_node *np)
  311. {
  312. of_at91_clk_master_setup(np, &at91sam9x5_master_layout);
  313. }
  314. CLK_OF_DECLARE(at91sam9x5_clk_master, "atmel,at91sam9x5-clk-master",
  315. of_at91sam9x5_clk_master_setup);
  316. static void __init
  317. of_at91_clk_periph_setup(struct device_node *np, u8 type)
  318. {
  319. int num;
  320. u32 id;
  321. struct clk_hw *hw;
  322. const char *parent_name;
  323. const char *name;
  324. struct device_node *periphclknp;
  325. struct regmap *regmap;
  326. parent_name = of_clk_get_parent_name(np, 0);
  327. if (!parent_name)
  328. return;
  329. num = of_get_child_count(np);
  330. if (!num || num > PERIPHERAL_MAX)
  331. return;
  332. regmap = syscon_node_to_regmap(of_get_parent(np));
  333. if (IS_ERR(regmap))
  334. return;
  335. for_each_child_of_node(np, periphclknp) {
  336. if (of_property_read_u32(periphclknp, "reg", &id))
  337. continue;
  338. if (id >= PERIPHERAL_MAX)
  339. continue;
  340. if (of_property_read_string(np, "clock-output-names", &name))
  341. name = periphclknp->name;
  342. if (type == PERIPHERAL_AT91RM9200) {
  343. hw = at91_clk_register_peripheral(regmap, name,
  344. parent_name, id);
  345. } else {
  346. struct clk_range range = CLK_RANGE(0, 0);
  347. of_at91_get_clk_range(periphclknp,
  348. "atmel,clk-output-range",
  349. &range);
  350. hw = at91_clk_register_sam9x5_peripheral(regmap,
  351. &pmc_pcr_lock,
  352. name,
  353. parent_name,
  354. id, &range);
  355. }
  356. if (IS_ERR(hw))
  357. continue;
  358. of_clk_add_hw_provider(periphclknp, of_clk_hw_simple_get, hw);
  359. }
  360. }
  361. static void __init of_at91rm9200_clk_periph_setup(struct device_node *np)
  362. {
  363. of_at91_clk_periph_setup(np, PERIPHERAL_AT91RM9200);
  364. }
  365. CLK_OF_DECLARE(at91rm9200_clk_periph, "atmel,at91rm9200-clk-peripheral",
  366. of_at91rm9200_clk_periph_setup);
  367. static void __init of_at91sam9x5_clk_periph_setup(struct device_node *np)
  368. {
  369. of_at91_clk_periph_setup(np, PERIPHERAL_AT91SAM9X5);
  370. }
  371. CLK_OF_DECLARE(at91sam9x5_clk_periph, "atmel,at91sam9x5-clk-peripheral",
  372. of_at91sam9x5_clk_periph_setup);
  373. static struct clk_pll_characteristics * __init
  374. of_at91_clk_pll_get_characteristics(struct device_node *np)
  375. {
  376. int i;
  377. int offset;
  378. u32 tmp;
  379. int num_output;
  380. u32 num_cells;
  381. struct clk_range input;
  382. struct clk_range *output;
  383. u8 *out = NULL;
  384. u16 *icpll = NULL;
  385. struct clk_pll_characteristics *characteristics;
  386. if (of_at91_get_clk_range(np, "atmel,clk-input-range", &input))
  387. return NULL;
  388. if (of_property_read_u32(np, "#atmel,pll-clk-output-range-cells",
  389. &num_cells))
  390. return NULL;
  391. if (num_cells < 2 || num_cells > 4)
  392. return NULL;
  393. if (!of_get_property(np, "atmel,pll-clk-output-ranges", &tmp))
  394. return NULL;
  395. num_output = tmp / (sizeof(u32) * num_cells);
  396. characteristics = kzalloc(sizeof(*characteristics), GFP_KERNEL);
  397. if (!characteristics)
  398. return NULL;
  399. output = kcalloc(num_output, sizeof(*output), GFP_KERNEL);
  400. if (!output)
  401. goto out_free_characteristics;
  402. if (num_cells > 2) {
  403. out = kcalloc(num_output, sizeof(*out), GFP_KERNEL);
  404. if (!out)
  405. goto out_free_output;
  406. }
  407. if (num_cells > 3) {
  408. icpll = kcalloc(num_output, sizeof(*icpll), GFP_KERNEL);
  409. if (!icpll)
  410. goto out_free_output;
  411. }
  412. for (i = 0; i < num_output; i++) {
  413. offset = i * num_cells;
  414. if (of_property_read_u32_index(np,
  415. "atmel,pll-clk-output-ranges",
  416. offset, &tmp))
  417. goto out_free_output;
  418. output[i].min = tmp;
  419. if (of_property_read_u32_index(np,
  420. "atmel,pll-clk-output-ranges",
  421. offset + 1, &tmp))
  422. goto out_free_output;
  423. output[i].max = tmp;
  424. if (num_cells == 2)
  425. continue;
  426. if (of_property_read_u32_index(np,
  427. "atmel,pll-clk-output-ranges",
  428. offset + 2, &tmp))
  429. goto out_free_output;
  430. out[i] = tmp;
  431. if (num_cells == 3)
  432. continue;
  433. if (of_property_read_u32_index(np,
  434. "atmel,pll-clk-output-ranges",
  435. offset + 3, &tmp))
  436. goto out_free_output;
  437. icpll[i] = tmp;
  438. }
  439. characteristics->input = input;
  440. characteristics->num_output = num_output;
  441. characteristics->output = output;
  442. characteristics->out = out;
  443. characteristics->icpll = icpll;
  444. return characteristics;
  445. out_free_output:
  446. kfree(icpll);
  447. kfree(out);
  448. kfree(output);
  449. out_free_characteristics:
  450. kfree(characteristics);
  451. return NULL;
  452. }
  453. static void __init
  454. of_at91_clk_pll_setup(struct device_node *np,
  455. const struct clk_pll_layout *layout)
  456. {
  457. u32 id;
  458. struct clk_hw *hw;
  459. struct regmap *regmap;
  460. const char *parent_name;
  461. const char *name = np->name;
  462. struct clk_pll_characteristics *characteristics;
  463. if (of_property_read_u32(np, "reg", &id))
  464. return;
  465. parent_name = of_clk_get_parent_name(np, 0);
  466. of_property_read_string(np, "clock-output-names", &name);
  467. regmap = syscon_node_to_regmap(of_get_parent(np));
  468. if (IS_ERR(regmap))
  469. return;
  470. characteristics = of_at91_clk_pll_get_characteristics(np);
  471. if (!characteristics)
  472. return;
  473. hw = at91_clk_register_pll(regmap, name, parent_name, id, layout,
  474. characteristics);
  475. if (IS_ERR(hw))
  476. goto out_free_characteristics;
  477. of_clk_add_hw_provider(np, of_clk_hw_simple_get, hw);
  478. return;
  479. out_free_characteristics:
  480. kfree(characteristics);
  481. }
  482. static void __init of_at91rm9200_clk_pll_setup(struct device_node *np)
  483. {
  484. of_at91_clk_pll_setup(np, &at91rm9200_pll_layout);
  485. }
  486. CLK_OF_DECLARE(at91rm9200_clk_pll, "atmel,at91rm9200-clk-pll",
  487. of_at91rm9200_clk_pll_setup);
  488. static void __init of_at91sam9g45_clk_pll_setup(struct device_node *np)
  489. {
  490. of_at91_clk_pll_setup(np, &at91sam9g45_pll_layout);
  491. }
  492. CLK_OF_DECLARE(at91sam9g45_clk_pll, "atmel,at91sam9g45-clk-pll",
  493. of_at91sam9g45_clk_pll_setup);
  494. static void __init of_at91sam9g20_clk_pllb_setup(struct device_node *np)
  495. {
  496. of_at91_clk_pll_setup(np, &at91sam9g20_pllb_layout);
  497. }
  498. CLK_OF_DECLARE(at91sam9g20_clk_pllb, "atmel,at91sam9g20-clk-pllb",
  499. of_at91sam9g20_clk_pllb_setup);
  500. static void __init of_sama5d3_clk_pll_setup(struct device_node *np)
  501. {
  502. of_at91_clk_pll_setup(np, &sama5d3_pll_layout);
  503. }
  504. CLK_OF_DECLARE(sama5d3_clk_pll, "atmel,sama5d3-clk-pll",
  505. of_sama5d3_clk_pll_setup);
  506. static void __init
  507. of_at91sam9x5_clk_plldiv_setup(struct device_node *np)
  508. {
  509. struct clk_hw *hw;
  510. const char *parent_name;
  511. const char *name = np->name;
  512. struct regmap *regmap;
  513. parent_name = of_clk_get_parent_name(np, 0);
  514. of_property_read_string(np, "clock-output-names", &name);
  515. regmap = syscon_node_to_regmap(of_get_parent(np));
  516. if (IS_ERR(regmap))
  517. return;
  518. hw = at91_clk_register_plldiv(regmap, name, parent_name);
  519. if (IS_ERR(hw))
  520. return;
  521. of_clk_add_hw_provider(np, of_clk_hw_simple_get, hw);
  522. }
  523. CLK_OF_DECLARE(at91sam9x5_clk_plldiv, "atmel,at91sam9x5-clk-plldiv",
  524. of_at91sam9x5_clk_plldiv_setup);
  525. static void __init
  526. of_at91_clk_prog_setup(struct device_node *np,
  527. const struct clk_programmable_layout *layout)
  528. {
  529. int num;
  530. u32 id;
  531. struct clk_hw *hw;
  532. unsigned int num_parents;
  533. const char *parent_names[PROG_SOURCE_MAX];
  534. const char *name;
  535. struct device_node *progclknp;
  536. struct regmap *regmap;
  537. num_parents = of_clk_get_parent_count(np);
  538. if (num_parents == 0 || num_parents > PROG_SOURCE_MAX)
  539. return;
  540. of_clk_parent_fill(np, parent_names, num_parents);
  541. num = of_get_child_count(np);
  542. if (!num || num > (PROG_ID_MAX + 1))
  543. return;
  544. regmap = syscon_node_to_regmap(of_get_parent(np));
  545. if (IS_ERR(regmap))
  546. return;
  547. for_each_child_of_node(np, progclknp) {
  548. if (of_property_read_u32(progclknp, "reg", &id))
  549. continue;
  550. if (of_property_read_string(np, "clock-output-names", &name))
  551. name = progclknp->name;
  552. hw = at91_clk_register_programmable(regmap, name,
  553. parent_names, num_parents,
  554. id, layout);
  555. if (IS_ERR(hw))
  556. continue;
  557. of_clk_add_hw_provider(progclknp, of_clk_hw_simple_get, hw);
  558. }
  559. }
  560. static void __init of_at91rm9200_clk_prog_setup(struct device_node *np)
  561. {
  562. of_at91_clk_prog_setup(np, &at91rm9200_programmable_layout);
  563. }
  564. CLK_OF_DECLARE(at91rm9200_clk_prog, "atmel,at91rm9200-clk-programmable",
  565. of_at91rm9200_clk_prog_setup);
  566. static void __init of_at91sam9g45_clk_prog_setup(struct device_node *np)
  567. {
  568. of_at91_clk_prog_setup(np, &at91sam9g45_programmable_layout);
  569. }
  570. CLK_OF_DECLARE(at91sam9g45_clk_prog, "atmel,at91sam9g45-clk-programmable",
  571. of_at91sam9g45_clk_prog_setup);
  572. static void __init of_at91sam9x5_clk_prog_setup(struct device_node *np)
  573. {
  574. of_at91_clk_prog_setup(np, &at91sam9x5_programmable_layout);
  575. }
  576. CLK_OF_DECLARE(at91sam9x5_clk_prog, "atmel,at91sam9x5-clk-programmable",
  577. of_at91sam9x5_clk_prog_setup);
  578. static void __init of_at91sam9260_clk_slow_setup(struct device_node *np)
  579. {
  580. struct clk_hw *hw;
  581. const char *parent_names[2];
  582. unsigned int num_parents;
  583. const char *name = np->name;
  584. struct regmap *regmap;
  585. num_parents = of_clk_get_parent_count(np);
  586. if (num_parents != 2)
  587. return;
  588. of_clk_parent_fill(np, parent_names, num_parents);
  589. regmap = syscon_node_to_regmap(of_get_parent(np));
  590. if (IS_ERR(regmap))
  591. return;
  592. of_property_read_string(np, "clock-output-names", &name);
  593. hw = at91_clk_register_sam9260_slow(regmap, name, parent_names,
  594. num_parents);
  595. if (IS_ERR(hw))
  596. return;
  597. of_clk_add_hw_provider(np, of_clk_hw_simple_get, hw);
  598. }
  599. CLK_OF_DECLARE(at91sam9260_clk_slow, "atmel,at91sam9260-clk-slow",
  600. of_at91sam9260_clk_slow_setup);
  601. #ifdef CONFIG_HAVE_AT91_SMD
  602. #define SMD_SOURCE_MAX 2
  603. static void __init of_at91sam9x5_clk_smd_setup(struct device_node *np)
  604. {
  605. struct clk_hw *hw;
  606. unsigned int num_parents;
  607. const char *parent_names[SMD_SOURCE_MAX];
  608. const char *name = np->name;
  609. struct regmap *regmap;
  610. num_parents = of_clk_get_parent_count(np);
  611. if (num_parents == 0 || num_parents > SMD_SOURCE_MAX)
  612. return;
  613. of_clk_parent_fill(np, parent_names, num_parents);
  614. of_property_read_string(np, "clock-output-names", &name);
  615. regmap = syscon_node_to_regmap(of_get_parent(np));
  616. if (IS_ERR(regmap))
  617. return;
  618. hw = at91sam9x5_clk_register_smd(regmap, name, parent_names,
  619. num_parents);
  620. if (IS_ERR(hw))
  621. return;
  622. of_clk_add_hw_provider(np, of_clk_hw_simple_get, hw);
  623. }
  624. CLK_OF_DECLARE(at91sam9x5_clk_smd, "atmel,at91sam9x5-clk-smd",
  625. of_at91sam9x5_clk_smd_setup);
  626. #endif /* CONFIG_HAVE_AT91_SMD */
  627. static void __init of_at91rm9200_clk_sys_setup(struct device_node *np)
  628. {
  629. int num;
  630. u32 id;
  631. struct clk_hw *hw;
  632. const char *name;
  633. struct device_node *sysclknp;
  634. const char *parent_name;
  635. struct regmap *regmap;
  636. num = of_get_child_count(np);
  637. if (num > (SYSTEM_MAX_ID + 1))
  638. return;
  639. regmap = syscon_node_to_regmap(of_get_parent(np));
  640. if (IS_ERR(regmap))
  641. return;
  642. for_each_child_of_node(np, sysclknp) {
  643. if (of_property_read_u32(sysclknp, "reg", &id))
  644. continue;
  645. if (of_property_read_string(np, "clock-output-names", &name))
  646. name = sysclknp->name;
  647. parent_name = of_clk_get_parent_name(sysclknp, 0);
  648. hw = at91_clk_register_system(regmap, name, parent_name, id);
  649. if (IS_ERR(hw))
  650. continue;
  651. of_clk_add_hw_provider(sysclknp, of_clk_hw_simple_get, hw);
  652. }
  653. }
  654. CLK_OF_DECLARE(at91rm9200_clk_sys, "atmel,at91rm9200-clk-system",
  655. of_at91rm9200_clk_sys_setup);
  656. #ifdef CONFIG_HAVE_AT91_USB_CLK
  657. #define USB_SOURCE_MAX 2
  658. static void __init of_at91sam9x5_clk_usb_setup(struct device_node *np)
  659. {
  660. struct clk_hw *hw;
  661. unsigned int num_parents;
  662. const char *parent_names[USB_SOURCE_MAX];
  663. const char *name = np->name;
  664. struct regmap *regmap;
  665. num_parents = of_clk_get_parent_count(np);
  666. if (num_parents == 0 || num_parents > USB_SOURCE_MAX)
  667. return;
  668. of_clk_parent_fill(np, parent_names, num_parents);
  669. of_property_read_string(np, "clock-output-names", &name);
  670. regmap = syscon_node_to_regmap(of_get_parent(np));
  671. if (IS_ERR(regmap))
  672. return;
  673. hw = at91sam9x5_clk_register_usb(regmap, name, parent_names,
  674. num_parents);
  675. if (IS_ERR(hw))
  676. return;
  677. of_clk_add_hw_provider(np, of_clk_hw_simple_get, hw);
  678. }
  679. CLK_OF_DECLARE(at91sam9x5_clk_usb, "atmel,at91sam9x5-clk-usb",
  680. of_at91sam9x5_clk_usb_setup);
  681. static void __init of_at91sam9n12_clk_usb_setup(struct device_node *np)
  682. {
  683. struct clk_hw *hw;
  684. const char *parent_name;
  685. const char *name = np->name;
  686. struct regmap *regmap;
  687. parent_name = of_clk_get_parent_name(np, 0);
  688. if (!parent_name)
  689. return;
  690. of_property_read_string(np, "clock-output-names", &name);
  691. regmap = syscon_node_to_regmap(of_get_parent(np));
  692. if (IS_ERR(regmap))
  693. return;
  694. hw = at91sam9n12_clk_register_usb(regmap, name, parent_name);
  695. if (IS_ERR(hw))
  696. return;
  697. of_clk_add_hw_provider(np, of_clk_hw_simple_get, hw);
  698. }
  699. CLK_OF_DECLARE(at91sam9n12_clk_usb, "atmel,at91sam9n12-clk-usb",
  700. of_at91sam9n12_clk_usb_setup);
  701. static void __init of_at91rm9200_clk_usb_setup(struct device_node *np)
  702. {
  703. struct clk_hw *hw;
  704. const char *parent_name;
  705. const char *name = np->name;
  706. u32 divisors[4] = {0, 0, 0, 0};
  707. struct regmap *regmap;
  708. parent_name = of_clk_get_parent_name(np, 0);
  709. if (!parent_name)
  710. return;
  711. of_property_read_u32_array(np, "atmel,clk-divisors", divisors, 4);
  712. if (!divisors[0])
  713. return;
  714. of_property_read_string(np, "clock-output-names", &name);
  715. regmap = syscon_node_to_regmap(of_get_parent(np));
  716. if (IS_ERR(regmap))
  717. return;
  718. hw = at91rm9200_clk_register_usb(regmap, name, parent_name, divisors);
  719. if (IS_ERR(hw))
  720. return;
  721. of_clk_add_hw_provider(np, of_clk_hw_simple_get, hw);
  722. }
  723. CLK_OF_DECLARE(at91rm9200_clk_usb, "atmel,at91rm9200-clk-usb",
  724. of_at91rm9200_clk_usb_setup);
  725. #endif /* CONFIG_HAVE_AT91_USB_CLK */
  726. #ifdef CONFIG_HAVE_AT91_UTMI
  727. static void __init of_at91sam9x5_clk_utmi_setup(struct device_node *np)
  728. {
  729. struct clk_hw *hw;
  730. const char *parent_name;
  731. const char *name = np->name;
  732. struct regmap *regmap_pmc, *regmap_sfr;
  733. parent_name = of_clk_get_parent_name(np, 0);
  734. of_property_read_string(np, "clock-output-names", &name);
  735. regmap_pmc = syscon_node_to_regmap(of_get_parent(np));
  736. if (IS_ERR(regmap_pmc))
  737. return;
  738. /*
  739. * If the device supports different mainck rates, this value has to be
  740. * set in the UTMI Clock Trimming register.
  741. * - 9x5: mainck supports several rates but it is indicated that a
  742. * 12 MHz is needed in case of USB.
  743. * - sama5d3 and sama5d2: mainck supports several rates. Configuring
  744. * the FREQ field of the UTMI Clock Trimming register is mandatory.
  745. * - sama5d4: mainck is at 12 MHz.
  746. *
  747. * We only need to retrieve sama5d3 or sama5d2 sfr regmap.
  748. */
  749. regmap_sfr = syscon_regmap_lookup_by_compatible("atmel,sama5d3-sfr");
  750. if (IS_ERR(regmap_sfr)) {
  751. regmap_sfr = syscon_regmap_lookup_by_compatible("atmel,sama5d2-sfr");
  752. if (IS_ERR(regmap_sfr))
  753. regmap_sfr = NULL;
  754. }
  755. hw = at91_clk_register_utmi(regmap_pmc, regmap_sfr, name, parent_name);
  756. if (IS_ERR(hw))
  757. return;
  758. of_clk_add_hw_provider(np, of_clk_hw_simple_get, hw);
  759. }
  760. CLK_OF_DECLARE(at91sam9x5_clk_utmi, "atmel,at91sam9x5-clk-utmi",
  761. of_at91sam9x5_clk_utmi_setup);
  762. #endif /* CONFIG_HAVE_AT91_UTMI */