950-0810-fixup-Add-support-for-all-the-downstream-rpi-sound-c.patch 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. From 3ece03b1575b0c3a0989e372aaaa4557ae74dc89 Mon Sep 17 00:00:00 2001
  2. From: Phil Elwell <[email protected]>
  3. Date: Thu, 20 Jul 2023 11:28:20 +0100
  4. Subject: [PATCH] fixup! Add support for all the downstream rpi sound card
  5. drivers
  6. Replace the Allo Dac clock driver with an extension of the
  7. HiFiBerry clock driver that it cloned.
  8. Signed-off-by: Phil Elwell <[email protected]>
  9. ---
  10. drivers/clk/Makefile | 1 -
  11. drivers/clk/clk-allo-dac.c | 161 -----------------------------
  12. drivers/clk/clk-hifiberry-dacpro.c | 57 ++++++----
  13. sound/soc/bcm/Kconfig | 1 +
  14. 4 files changed, 40 insertions(+), 180 deletions(-)
  15. delete mode 100644 drivers/clk/clk-allo-dac.c
  16. --- a/drivers/clk/Makefile
  17. +++ b/drivers/clk/Makefile
  18. @@ -19,7 +19,6 @@ endif
  19. # hardware specific clock types
  20. # please keep this section sorted lexicographically by file path name
  21. -obj-$(CONFIG_SND_BCM2708_SOC_ALLO_BOSS_DAC) += clk-allo-dac.o
  22. obj-$(CONFIG_COMMON_CLK_APPLE_NCO) += clk-apple-nco.o
  23. obj-$(CONFIG_MACH_ASM9260) += clk-asm9260.o
  24. obj-$(CONFIG_COMMON_CLK_AXI_CLKGEN) += clk-axi-clkgen.o
  25. --- a/drivers/clk/clk-allo-dac.c
  26. +++ /dev/null
  27. @@ -1,161 +0,0 @@
  28. -/*
  29. - * Clock Driver for Allo DAC
  30. - *
  31. - * Author: Baswaraj K <[email protected]>
  32. - * Copyright 2016
  33. - * based on code by Stuart MacLean
  34. - *
  35. - * This program is free software; you can redistribute it and/or
  36. - * modify it under the terms of the GNU General Public License
  37. - * version 2 as published by the Free Software Foundation.
  38. - *
  39. - * This program is distributed in the hope that it will be useful, but
  40. - * WITHOUT ANY WARRANTY; without even the implied warranty of
  41. - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  42. - * General Public License for more details.
  43. - */
  44. -
  45. -#include <linux/clk-provider.h>
  46. -#include <linux/clkdev.h>
  47. -#include <linux/kernel.h>
  48. -#include <linux/module.h>
  49. -#include <linux/of.h>
  50. -#include <linux/slab.h>
  51. -#include <linux/platform_device.h>
  52. -
  53. -/* Clock rate of CLK44EN attached to GPIO6 pin */
  54. -#define CLK_44EN_RATE 45158400UL
  55. -/* Clock rate of CLK48EN attached to GPIO3 pin */
  56. -#define CLK_48EN_RATE 49152000UL
  57. -
  58. -/**
  59. - * struct allo_dac_clk - Common struct to the Allo DAC
  60. - * @hw: clk_hw for the common clk framework
  61. - * @mode: 0 => CLK44EN, 1 => CLK48EN
  62. - */
  63. -struct clk_allo_hw {
  64. - struct clk_hw hw;
  65. - uint8_t mode;
  66. -};
  67. -
  68. -#define to_allo_clk(_hw) container_of(_hw, struct clk_allo_hw, hw)
  69. -
  70. -static const struct of_device_id clk_allo_dac_dt_ids[] = {
  71. - { .compatible = "allo,dac-clk",},
  72. - { }
  73. -};
  74. -MODULE_DEVICE_TABLE(of, clk_allo_dac_dt_ids);
  75. -
  76. -static unsigned long clk_allo_dac_recalc_rate(struct clk_hw *hw,
  77. - unsigned long parent_rate)
  78. -{
  79. - return (to_allo_clk(hw)->mode == 0) ? CLK_44EN_RATE :
  80. - CLK_48EN_RATE;
  81. -}
  82. -
  83. -static long clk_allo_dac_round_rate(struct clk_hw *hw,
  84. - unsigned long rate, unsigned long *parent_rate)
  85. -{
  86. - long actual_rate;
  87. -
  88. - if (rate <= CLK_44EN_RATE) {
  89. - actual_rate = (long)CLK_44EN_RATE;
  90. - } else if (rate >= CLK_48EN_RATE) {
  91. - actual_rate = (long)CLK_48EN_RATE;
  92. - } else {
  93. - long diff44Rate = (long)(rate - CLK_44EN_RATE);
  94. - long diff48Rate = (long)(CLK_48EN_RATE - rate);
  95. -
  96. - if (diff44Rate < diff48Rate)
  97. - actual_rate = (long)CLK_44EN_RATE;
  98. - else
  99. - actual_rate = (long)CLK_48EN_RATE;
  100. - }
  101. - return actual_rate;
  102. -}
  103. -
  104. -
  105. -static int clk_allo_dac_set_rate(struct clk_hw *hw,
  106. - unsigned long rate, unsigned long parent_rate)
  107. -{
  108. - unsigned long actual_rate;
  109. - struct clk_allo_hw *clk = to_allo_clk(hw);
  110. -
  111. - actual_rate = (unsigned long)clk_allo_dac_round_rate(hw, rate,
  112. - &parent_rate);
  113. - clk->mode = (actual_rate == CLK_44EN_RATE) ? 0 : 1;
  114. - return 0;
  115. -}
  116. -
  117. -
  118. -const struct clk_ops clk_allo_dac_rate_ops = {
  119. - .recalc_rate = clk_allo_dac_recalc_rate,
  120. - .round_rate = clk_allo_dac_round_rate,
  121. - .set_rate = clk_allo_dac_set_rate,
  122. -};
  123. -
  124. -static int clk_allo_dac_probe(struct platform_device *pdev)
  125. -{
  126. - int ret;
  127. - struct clk_allo_hw *proclk;
  128. - struct clk *clk;
  129. - struct device *dev;
  130. - struct clk_init_data init;
  131. -
  132. - dev = &pdev->dev;
  133. -
  134. - proclk = kzalloc(sizeof(struct clk_allo_hw), GFP_KERNEL);
  135. - if (!proclk)
  136. - return -ENOMEM;
  137. -
  138. - init.name = "clk-allo-dac";
  139. - init.ops = &clk_allo_dac_rate_ops;
  140. - init.flags = 0;
  141. - init.parent_names = NULL;
  142. - init.num_parents = 0;
  143. -
  144. - proclk->mode = 0;
  145. - proclk->hw.init = &init;
  146. -
  147. - clk = devm_clk_register(dev, &proclk->hw);
  148. - if (!IS_ERR(clk)) {
  149. - ret = of_clk_add_provider(dev->of_node, of_clk_src_simple_get,
  150. - clk);
  151. - } else {
  152. - dev_err(dev, "Fail to register clock driver\n");
  153. - kfree(proclk);
  154. - ret = PTR_ERR(clk);
  155. - }
  156. - return ret;
  157. -}
  158. -
  159. -static int clk_allo_dac_remove(struct platform_device *pdev)
  160. -{
  161. - of_clk_del_provider(pdev->dev.of_node);
  162. - return 0;
  163. -}
  164. -
  165. -static struct platform_driver clk_allo_dac_driver = {
  166. - .probe = clk_allo_dac_probe,
  167. - .remove = clk_allo_dac_remove,
  168. - .driver = {
  169. - .name = "clk-allo-dac",
  170. - .of_match_table = clk_allo_dac_dt_ids,
  171. - },
  172. -};
  173. -
  174. -static int __init clk_allo_dac_init(void)
  175. -{
  176. - return platform_driver_register(&clk_allo_dac_driver);
  177. -}
  178. -core_initcall(clk_allo_dac_init);
  179. -
  180. -static void __exit clk_allo_dac_exit(void)
  181. -{
  182. - platform_driver_unregister(&clk_allo_dac_driver);
  183. -}
  184. -module_exit(clk_allo_dac_exit);
  185. -
  186. -MODULE_DESCRIPTION("Allo DAC clock driver");
  187. -MODULE_LICENSE("GPL v2");
  188. -MODULE_ALIAS("platform:clk-allo-dac");
  189. --- a/drivers/clk/clk-hifiberry-dacpro.c
  190. +++ b/drivers/clk/clk-hifiberry-dacpro.c
  191. @@ -22,10 +22,12 @@
  192. #include <linux/slab.h>
  193. #include <linux/platform_device.h>
  194. -/* Clock rate of CLK44EN attached to GPIO6 pin */
  195. -#define CLK_44EN_RATE 22579200UL
  196. -/* Clock rate of CLK48EN attached to GPIO3 pin */
  197. -#define CLK_48EN_RATE 24576000UL
  198. +struct ext_clk_rates {
  199. + /* Clock rate of CLK44EN attached to GPIO6 pin */
  200. + unsigned long clk_44en;
  201. + /* Clock rate of CLK48EN attached to GPIO3 pin */
  202. + unsigned long clk_48en;
  203. +};
  204. /**
  205. * struct hifiberry_dacpro_clk - Common struct to the HiFiBerry DAC Pro
  206. @@ -35,12 +37,24 @@
  207. struct clk_hifiberry_hw {
  208. struct clk_hw hw;
  209. uint8_t mode;
  210. + struct ext_clk_rates clk_rates;
  211. };
  212. #define to_hifiberry_clk(_hw) container_of(_hw, struct clk_hifiberry_hw, hw)
  213. +static const struct ext_clk_rates hifiberry_dacpro_clks = {
  214. + .clk_44en = 22579200UL,
  215. + .clk_48en = 24576000UL,
  216. +};
  217. +
  218. +static const struct ext_clk_rates allo_dac_clks = {
  219. + .clk_44en = 45158400UL,
  220. + .clk_48en = 49152000UL,
  221. +};
  222. +
  223. static const struct of_device_id clk_hifiberry_dacpro_dt_ids[] = {
  224. - { .compatible = "hifiberry,dacpro-clk",},
  225. + { .compatible = "hifiberry,dacpro-clk", &hifiberry_dacpro_clks },
  226. + { .compatible = "allo,dac-clk", &allo_dac_clks },
  227. { }
  228. };
  229. MODULE_DEVICE_TABLE(of, clk_hifiberry_dacpro_dt_ids);
  230. @@ -48,27 +62,29 @@ MODULE_DEVICE_TABLE(of, clk_hifiberry_da
  231. static unsigned long clk_hifiberry_dacpro_recalc_rate(struct clk_hw *hw,
  232. unsigned long parent_rate)
  233. {
  234. - return (to_hifiberry_clk(hw)->mode == 0) ? CLK_44EN_RATE :
  235. - CLK_48EN_RATE;
  236. + struct clk_hifiberry_hw *clk = to_hifiberry_clk(hw);
  237. + return (clk->mode == 0) ? clk->clk_rates.clk_44en :
  238. + clk->clk_rates.clk_48en;
  239. }
  240. static long clk_hifiberry_dacpro_round_rate(struct clk_hw *hw,
  241. unsigned long rate, unsigned long *parent_rate)
  242. {
  243. + struct clk_hifiberry_hw *clk = to_hifiberry_clk(hw);
  244. long actual_rate;
  245. - if (rate <= CLK_44EN_RATE) {
  246. - actual_rate = (long)CLK_44EN_RATE;
  247. - } else if (rate >= CLK_48EN_RATE) {
  248. - actual_rate = (long)CLK_48EN_RATE;
  249. + if (rate <= clk->clk_rates.clk_44en) {
  250. + actual_rate = (long)clk->clk_rates.clk_44en;
  251. + } else if (rate >= clk->clk_rates.clk_48en) {
  252. + actual_rate = (long)clk->clk_rates.clk_48en;
  253. } else {
  254. - long diff44Rate = (long)(rate - CLK_44EN_RATE);
  255. - long diff48Rate = (long)(CLK_48EN_RATE - rate);
  256. + long diff44Rate = (long)(rate - clk->clk_rates.clk_44en);
  257. + long diff48Rate = (long)(clk->clk_rates.clk_48en - rate);
  258. if (diff44Rate < diff48Rate)
  259. - actual_rate = (long)CLK_44EN_RATE;
  260. + actual_rate = (long)clk->clk_rates.clk_44en;
  261. else
  262. - actual_rate = (long)CLK_48EN_RATE;
  263. + actual_rate = (long)clk->clk_rates.clk_48en;
  264. }
  265. return actual_rate;
  266. }
  267. @@ -77,12 +93,12 @@ static long clk_hifiberry_dacpro_round_r
  268. static int clk_hifiberry_dacpro_set_rate(struct clk_hw *hw,
  269. unsigned long rate, unsigned long parent_rate)
  270. {
  271. - unsigned long actual_rate;
  272. struct clk_hifiberry_hw *clk = to_hifiberry_clk(hw);
  273. + unsigned long actual_rate;
  274. actual_rate = (unsigned long)clk_hifiberry_dacpro_round_rate(hw, rate,
  275. &parent_rate);
  276. - clk->mode = (actual_rate == CLK_44EN_RATE) ? 0 : 1;
  277. + clk->mode = (actual_rate == clk->clk_rates.clk_44en) ? 0 : 1;
  278. return 0;
  279. }
  280. @@ -95,13 +111,17 @@ const struct clk_ops clk_hifiberry_dacpr
  281. static int clk_hifiberry_dacpro_probe(struct platform_device *pdev)
  282. {
  283. - int ret;
  284. + const struct of_device_id *of_id;
  285. struct clk_hifiberry_hw *proclk;
  286. struct clk *clk;
  287. struct device *dev;
  288. struct clk_init_data init;
  289. + int ret;
  290. dev = &pdev->dev;
  291. + of_id = of_match_node(clk_hifiberry_dacpro_dt_ids, dev->of_node);
  292. + if (!of_id)
  293. + return -EINVAL;
  294. proclk = kzalloc(sizeof(struct clk_hifiberry_hw), GFP_KERNEL);
  295. if (!proclk)
  296. @@ -115,6 +135,7 @@ static int clk_hifiberry_dacpro_probe(st
  297. proclk->mode = 0;
  298. proclk->hw.init = &init;
  299. + memcpy(&proclk->clk_rates, of_id->data, sizeof(proclk->clk_rates));
  300. clk = devm_clk_register(dev, &proclk->hw);
  301. if (!IS_ERR(clk)) {
  302. --- a/sound/soc/bcm/Kconfig
  303. +++ b/sound/soc/bcm/Kconfig
  304. @@ -271,6 +271,7 @@ config SND_BCM2708_SOC_ALLO_BOSS_DAC
  305. tristate "Support for Allo Boss DAC"
  306. depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
  307. select SND_SOC_PCM512x_I2C
  308. + select COMMON_CLK_HIFIBERRY_DACPRO
  309. help
  310. Say Y or M if you want to add support for Allo Boss DAC.