clk-twl6040.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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/clk.h>
  23. #include <linux/module.h>
  24. #include <linux/slab.h>
  25. #include <linux/platform_device.h>
  26. #include <linux/mfd/twl6040.h>
  27. #include <linux/clk-provider.h>
  28. struct twl6040_clk {
  29. struct twl6040 *twl6040;
  30. struct device *dev;
  31. struct clk_hw mcpdm_fclk;
  32. struct clk *clk;
  33. int enabled;
  34. };
  35. static int twl6040_bitclk_is_enabled(struct clk_hw *hw)
  36. {
  37. struct twl6040_clk *twl6040_clk = container_of(hw, struct twl6040_clk,
  38. mcpdm_fclk);
  39. return twl6040_clk->enabled;
  40. }
  41. static int twl6040_bitclk_prepare(struct clk_hw *hw)
  42. {
  43. struct twl6040_clk *twl6040_clk = container_of(hw, struct twl6040_clk,
  44. mcpdm_fclk);
  45. int ret;
  46. ret = twl6040_power(twl6040_clk->twl6040, 1);
  47. if (!ret)
  48. twl6040_clk->enabled = 1;
  49. return ret;
  50. }
  51. static void twl6040_bitclk_unprepare(struct clk_hw *hw)
  52. {
  53. struct twl6040_clk *twl6040_clk = container_of(hw, struct twl6040_clk,
  54. mcpdm_fclk);
  55. int ret;
  56. ret = twl6040_power(twl6040_clk->twl6040, 0);
  57. if (!ret)
  58. twl6040_clk->enabled = 0;
  59. }
  60. static const struct clk_ops twl6040_mcpdm_ops = {
  61. .is_enabled = twl6040_bitclk_is_enabled,
  62. .prepare = twl6040_bitclk_prepare,
  63. .unprepare = twl6040_bitclk_unprepare,
  64. };
  65. static struct clk_init_data wm831x_clkout_init = {
  66. .name = "mcpdm_fclk",
  67. .ops = &twl6040_mcpdm_ops,
  68. .flags = CLK_IS_ROOT,
  69. };
  70. static int twl6040_clk_probe(struct platform_device *pdev)
  71. {
  72. struct twl6040 *twl6040 = dev_get_drvdata(pdev->dev.parent);
  73. struct twl6040_clk *clkdata;
  74. clkdata = devm_kzalloc(&pdev->dev, sizeof(*clkdata), GFP_KERNEL);
  75. if (!clkdata)
  76. return -ENOMEM;
  77. clkdata->dev = &pdev->dev;
  78. clkdata->twl6040 = twl6040;
  79. clkdata->mcpdm_fclk.init = &wm831x_clkout_init;
  80. clkdata->clk = clk_register(&pdev->dev, &clkdata->mcpdm_fclk);
  81. if (IS_ERR(clkdata->clk))
  82. return PTR_ERR(clkdata->clk);
  83. platform_set_drvdata(pdev, clkdata);
  84. return 0;
  85. }
  86. static int twl6040_clk_remove(struct platform_device *pdev)
  87. {
  88. struct twl6040_clk *clkdata = platform_get_drvdata(pdev);
  89. clk_unregister(clkdata->clk);
  90. return 0;
  91. }
  92. static struct platform_driver twl6040_clk_driver = {
  93. .driver = {
  94. .name = "twl6040-clk",
  95. },
  96. .probe = twl6040_clk_probe,
  97. .remove = twl6040_clk_remove,
  98. };
  99. module_platform_driver(twl6040_clk_driver);
  100. MODULE_DESCRIPTION("TWL6040 clock driver for McPDM functional clock");
  101. MODULE_AUTHOR("Peter Ujfalusi <peter.ujfalusi@ti.com>");
  102. MODULE_ALIAS("platform:twl6040-clk");
  103. MODULE_LICENSE("GPL");