sun6i_drc.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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/mod_devicetable.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/regmap.h>
  17. #include <linux/reset.h>
  18. struct sun6i_drc {
  19. struct clk *bus_clk;
  20. struct clk *mod_clk;
  21. struct reset_control *reset;
  22. };
  23. static int sun6i_drc_bind(struct device *dev, struct device *master,
  24. void *data)
  25. {
  26. struct sun6i_drc *drc;
  27. int ret;
  28. drc = devm_kzalloc(dev, sizeof(*drc), GFP_KERNEL);
  29. if (!drc)
  30. return -ENOMEM;
  31. dev_set_drvdata(dev, drc);
  32. drc->reset = devm_reset_control_get(dev, NULL);
  33. if (IS_ERR(drc->reset)) {
  34. dev_err(dev, "Couldn't get our reset line\n");
  35. return PTR_ERR(drc->reset);
  36. }
  37. ret = reset_control_deassert(drc->reset);
  38. if (ret) {
  39. dev_err(dev, "Couldn't deassert our reset line\n");
  40. return ret;
  41. }
  42. drc->bus_clk = devm_clk_get(dev, "ahb");
  43. if (IS_ERR(drc->bus_clk)) {
  44. dev_err(dev, "Couldn't get our bus clock\n");
  45. ret = PTR_ERR(drc->bus_clk);
  46. goto err_assert_reset;
  47. }
  48. clk_prepare_enable(drc->bus_clk);
  49. drc->mod_clk = devm_clk_get(dev, "mod");
  50. if (IS_ERR(drc->mod_clk)) {
  51. dev_err(dev, "Couldn't get our mod clock\n");
  52. ret = PTR_ERR(drc->mod_clk);
  53. goto err_disable_bus_clk;
  54. }
  55. clk_prepare_enable(drc->mod_clk);
  56. return 0;
  57. err_disable_bus_clk:
  58. clk_disable_unprepare(drc->bus_clk);
  59. err_assert_reset:
  60. reset_control_assert(drc->reset);
  61. return ret;
  62. }
  63. static void sun6i_drc_unbind(struct device *dev, struct device *master,
  64. void *data)
  65. {
  66. struct sun6i_drc *drc = dev_get_drvdata(dev);
  67. clk_disable_unprepare(drc->mod_clk);
  68. clk_disable_unprepare(drc->bus_clk);
  69. reset_control_assert(drc->reset);
  70. }
  71. static const struct component_ops sun6i_drc_ops = {
  72. .bind = sun6i_drc_bind,
  73. .unbind = sun6i_drc_unbind,
  74. };
  75. static int sun6i_drc_probe(struct platform_device *pdev)
  76. {
  77. return component_add(&pdev->dev, &sun6i_drc_ops);
  78. }
  79. static int sun6i_drc_remove(struct platform_device *pdev)
  80. {
  81. component_del(&pdev->dev, &sun6i_drc_ops);
  82. return 0;
  83. }
  84. static const struct of_device_id sun6i_drc_of_table[] = {
  85. { .compatible = "allwinner,sun6i-a31-drc" },
  86. { .compatible = "allwinner,sun6i-a31s-drc" },
  87. { .compatible = "allwinner,sun8i-a33-drc" },
  88. { .compatible = "allwinner,sun9i-a80-drc" },
  89. { }
  90. };
  91. MODULE_DEVICE_TABLE(of, sun6i_drc_of_table);
  92. static struct platform_driver sun6i_drc_platform_driver = {
  93. .probe = sun6i_drc_probe,
  94. .remove = sun6i_drc_remove,
  95. .driver = {
  96. .name = "sun6i-drc",
  97. .of_match_table = sun6i_drc_of_table,
  98. },
  99. };
  100. module_platform_driver(sun6i_drc_platform_driver);
  101. MODULE_AUTHOR("Maxime Ripard <maxime.ripard@free-electrons.com>");
  102. MODULE_DESCRIPTION("Allwinner A31 Dynamic Range Control (DRC) Driver");
  103. MODULE_LICENSE("GPL");