clk-twl6040.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * TWL6040 clock module driver for OMAP4 McPDM functional clock
  3. *
  4. * Copyright (C) 2012 Texas Instruments Inc.
  5. * Peter Ujfalusi <peter.ujfalusi@ti.com>
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * version 2 as published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  19. * 02110-1301 USA
  20. *
  21. */
  22. #include <linux/module.h>
  23. #include <linux/slab.h>
  24. #include <linux/platform_device.h>
  25. #include <linux/mfd/twl6040.h>
  26. #include <linux/clk-provider.h>
  27. struct twl6040_pdmclk {
  28. struct twl6040 *twl6040;
  29. struct device *dev;
  30. struct clk_hw pdmclk_hw;
  31. int enabled;
  32. };
  33. static int twl6040_pdmclk_is_prepared(struct clk_hw *hw)
  34. {
  35. struct twl6040_pdmclk *pdmclk = container_of(hw, struct twl6040_pdmclk,
  36. pdmclk_hw);
  37. return pdmclk->enabled;
  38. }
  39. static int twl6040_pdmclk_prepare(struct clk_hw *hw)
  40. {
  41. struct twl6040_pdmclk *pdmclk = container_of(hw, struct twl6040_pdmclk,
  42. pdmclk_hw);
  43. int ret;
  44. ret = twl6040_power(pdmclk->twl6040, 1);
  45. if (!ret)
  46. pdmclk->enabled = 1;
  47. return ret;
  48. }
  49. static void twl6040_pdmclk_unprepare(struct clk_hw *hw)
  50. {
  51. struct twl6040_pdmclk *pdmclk = container_of(hw, struct twl6040_pdmclk,
  52. pdmclk_hw);
  53. int ret;
  54. ret = twl6040_power(pdmclk->twl6040, 0);
  55. if (!ret)
  56. pdmclk->enabled = 0;
  57. }
  58. static unsigned long twl6040_pdmclk_recalc_rate(struct clk_hw *hw,
  59. unsigned long parent_rate)
  60. {
  61. struct twl6040_pdmclk *pdmclk = container_of(hw, struct twl6040_pdmclk,
  62. pdmclk_hw);
  63. return twl6040_get_sysclk(pdmclk->twl6040);
  64. }
  65. static const struct clk_ops twl6040_pdmclk_ops = {
  66. .is_prepared = twl6040_pdmclk_is_prepared,
  67. .prepare = twl6040_pdmclk_prepare,
  68. .unprepare = twl6040_pdmclk_unprepare,
  69. .recalc_rate = twl6040_pdmclk_recalc_rate,
  70. };
  71. static struct clk_init_data twl6040_pdmclk_init = {
  72. .name = "pdmclk",
  73. .ops = &twl6040_pdmclk_ops,
  74. .flags = CLK_GET_RATE_NOCACHE,
  75. };
  76. static int twl6040_pdmclk_probe(struct platform_device *pdev)
  77. {
  78. struct twl6040 *twl6040 = dev_get_drvdata(pdev->dev.parent);
  79. struct twl6040_pdmclk *clkdata;
  80. int ret;
  81. clkdata = devm_kzalloc(&pdev->dev, sizeof(*clkdata), GFP_KERNEL);
  82. if (!clkdata)
  83. return -ENOMEM;
  84. clkdata->dev = &pdev->dev;
  85. clkdata->twl6040 = twl6040;
  86. clkdata->pdmclk_hw.init = &twl6040_pdmclk_init;
  87. ret = devm_clk_hw_register(&pdev->dev, &clkdata->pdmclk_hw);
  88. if (ret)
  89. return ret;
  90. platform_set_drvdata(pdev, clkdata);
  91. return of_clk_add_hw_provider(pdev->dev.parent->of_node,
  92. of_clk_hw_simple_get,
  93. &clkdata->pdmclk_hw);
  94. }
  95. static struct platform_driver twl6040_pdmclk_driver = {
  96. .driver = {
  97. .name = "twl6040-pdmclk",
  98. },
  99. .probe = twl6040_pdmclk_probe,
  100. };
  101. module_platform_driver(twl6040_pdmclk_driver);
  102. MODULE_DESCRIPTION("TWL6040 clock driver for McPDM functional clock");
  103. MODULE_AUTHOR("Peter Ujfalusi <peter.ujfalusi@ti.com>");
  104. MODULE_ALIAS("platform:twl6040-pdmclk");
  105. MODULE_LICENSE("GPL");