clk-bringup.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * Copyright (c) 2015 MediaTek Inc.
  3. * Author: James Liao <jamesjj.liao@mediatek.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. */
  14. #include <linux/clk.h>
  15. #include <linux/clk-provider.h>
  16. #include <linux/kernel.h>
  17. #include <linux/module.h>
  18. #include <linux/of.h>
  19. #include <linux/of_platform.h>
  20. static const struct of_device_id bring_up_id_table[] = {
  21. { .compatible = "mediatek,clk-bring-up",},
  22. { .compatible = "mediatek,mt8163-bring-up",},
  23. { .compatible = "mediatek,mt8173-bring-up",},
  24. { },
  25. };
  26. MODULE_DEVICE_TABLE(of, bring_up_id_table);
  27. static int bring_up_probe(struct platform_device *pdev)
  28. {
  29. struct clk *clk;
  30. int clk_con, i;
  31. int ret = 0;
  32. clk_con = of_count_phandle_with_args(pdev->dev.of_node, "clocks",
  33. "#clock-cells");
  34. pr_notice("sum: %d\n", clk_con);
  35. for (i = 0; i < clk_con; i++) {
  36. clk = of_clk_get(pdev->dev.of_node, i);
  37. if (IS_ERR(clk)) {
  38. long ret = PTR_ERR(clk);
  39. if (ret == -EPROBE_DEFER)
  40. pr_notice("clk %d is not ready\n", i);
  41. else
  42. pr_notice("get clk %d fail, ret=%d, clk_con=%d\n",
  43. i, (int)ret, clk_con);
  44. } else {
  45. pr_notice("get clk [%d]: %s ok\n", i,
  46. __clk_get_name(clk));
  47. ret = clk_prepare_enable(clk);
  48. if (ret) {
  49. pr_err("cannot force-on bringup clk node\n");
  50. goto fail;
  51. }
  52. }
  53. }
  54. fail:
  55. return ret;
  56. }
  57. static int bring_up_remove(struct platform_device *pdev)
  58. {
  59. return 0;
  60. }
  61. static struct platform_driver bring_up = {
  62. .probe = bring_up_probe,
  63. .remove = bring_up_remove,
  64. .driver = {
  65. .name = "bring_up",
  66. .owner = THIS_MODULE,
  67. .of_match_table = bring_up_id_table,
  68. },
  69. };
  70. module_platform_driver(bring_up);