sun6i_drc.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * Copyright (C) 2016 Free Electrons
  3. *
  4. * Maxime Ripard <maxime.ripard@free-electrons.com>
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License as
  8. * published by the Free Software Foundation; either version 2 of
  9. * the License, or (at your option) any later version.
  10. */
  11. #include <linux/clk.h>
  12. #include <linux/component.h>
  13. #include <linux/module.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/regmap.h>
  16. #include <linux/reset.h>
  17. struct sun6i_drc {
  18. struct clk *bus_clk;
  19. struct clk *mod_clk;
  20. struct reset_control *reset;
  21. };
  22. static int sun6i_drc_bind(struct device *dev, struct device *master,
  23. void *data)
  24. {
  25. struct sun6i_drc *drc;
  26. int ret;
  27. drc = devm_kzalloc(dev, sizeof(*drc), GFP_KERNEL);
  28. if (!drc)
  29. return -ENOMEM;
  30. dev_set_drvdata(dev, drc);
  31. drc->reset = devm_reset_control_get(dev, NULL);
  32. if (IS_ERR(drc->reset)) {
  33. dev_err(dev, "Couldn't get our reset line\n");
  34. return PTR_ERR(drc->reset);
  35. }
  36. ret = reset_control_deassert(drc->reset);
  37. if (ret) {
  38. dev_err(dev, "Couldn't deassert our reset line\n");
  39. return ret;
  40. }
  41. drc->bus_clk = devm_clk_get(dev, "ahb");
  42. if (IS_ERR(drc->bus_clk)) {
  43. dev_err(dev, "Couldn't get our bus clock\n");
  44. ret = PTR_ERR(drc->bus_clk);
  45. goto err_assert_reset;
  46. }
  47. clk_prepare_enable(drc->bus_clk);
  48. drc->mod_clk = devm_clk_get(dev, "mod");
  49. if (IS_ERR(drc->mod_clk)) {
  50. dev_err(dev, "Couldn't get our mod clock\n");
  51. ret = PTR_ERR(drc->mod_clk);
  52. goto err_disable_bus_clk;
  53. }
  54. clk_prepare_enable(drc->mod_clk);
  55. return 0;
  56. err_disable_bus_clk:
  57. clk_disable_unprepare(drc->bus_clk);
  58. err_assert_reset:
  59. reset_control_assert(drc->reset);
  60. return ret;
  61. }
  62. static void sun6i_drc_unbind(struct device *dev, struct device *master,
  63. void *data)
  64. {
  65. struct sun6i_drc *drc = dev_get_drvdata(dev);
  66. clk_disable_unprepare(drc->mod_clk);
  67. clk_disable_unprepare(drc->bus_clk);
  68. reset_control_assert(drc->reset);
  69. }
  70. static const struct component_ops sun6i_drc_ops = {
  71. .bind = sun6i_drc_bind,
  72. .unbind = sun6i_drc_unbind,
  73. };
  74. static int sun6i_drc_probe(struct platform_device *pdev)
  75. {
  76. return component_add(&pdev->dev, &sun6i_drc_ops);
  77. }
  78. static int sun6i_drc_remove(struct platform_device *pdev)
  79. {
  80. component_del(&pdev->dev, &sun6i_drc_ops);
  81. return 0;
  82. }
  83. static const struct of_device_id sun6i_drc_of_table[] = {
  84. { .compatible = "allwinner,sun6i-a31-drc" },
  85. { .compatible = "allwinner,sun6i-a31s-drc" },
  86. { .compatible = "allwinner,sun8i-a33-drc" },
  87. { }
  88. };
  89. MODULE_DEVICE_TABLE(of, sun6i_drc_of_table);
  90. static struct platform_driver sun6i_drc_platform_driver = {
  91. .probe = sun6i_drc_probe,
  92. .remove = sun6i_drc_remove,
  93. .driver = {
  94. .name = "sun6i-drc",
  95. .of_match_table = sun6i_drc_of_table,
  96. },
  97. };
  98. module_platform_driver(sun6i_drc_platform_driver);
  99. MODULE_AUTHOR("Maxime Ripard <maxime.ripard@free-electrons.com>");
  100. MODULE_DESCRIPTION("Allwinner A31 Dynamic Range Control (DRC) Driver");
  101. MODULE_LICENSE("GPL");