clk-twl6040.c 2.9 KB

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