clk-max77802.c 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * clk-max77802.c - Clock driver for Maxim 77802
  3. *
  4. * Copyright (C) 2014 Google, Inc
  5. *
  6. * Copyright (C) 2012 Samsung Electornics
  7. * Jonghwa Lee <jonghwa3.lee@samsung.com>
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License as published by the
  11. * Free Software Foundation; either version 2 of the License, or (at your
  12. * option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * This driver is based on clk-max77686.c
  20. */
  21. #include <linux/kernel.h>
  22. #include <linux/slab.h>
  23. #include <linux/err.h>
  24. #include <linux/module.h>
  25. #include <linux/platform_device.h>
  26. #include <linux/mfd/max77686-private.h>
  27. #include <linux/clk-provider.h>
  28. #include <linux/mutex.h>
  29. #include <linux/clkdev.h>
  30. #include <dt-bindings/clock/maxim,max77802.h>
  31. #include "clk-max-gen.h"
  32. #define MAX77802_CLOCK_OPMODE_MASK 0x1
  33. #define MAX77802_CLOCK_LOW_JITTER_SHIFT 0x3
  34. static struct clk_init_data max77802_clks_init[MAX77802_CLKS_NUM] = {
  35. [MAX77802_CLK_32K_AP] = {
  36. .name = "32khz_ap",
  37. .ops = &max_gen_clk_ops,
  38. .flags = CLK_IS_ROOT,
  39. },
  40. [MAX77802_CLK_32K_CP] = {
  41. .name = "32khz_cp",
  42. .ops = &max_gen_clk_ops,
  43. .flags = CLK_IS_ROOT,
  44. },
  45. };
  46. static int max77802_clk_probe(struct platform_device *pdev)
  47. {
  48. struct max77686_dev *iodev = dev_get_drvdata(pdev->dev.parent);
  49. int ret;
  50. ret = max_gen_clk_probe(pdev, iodev->regmap, MAX77802_REG_32KHZ,
  51. max77802_clks_init, MAX77802_CLKS_NUM);
  52. if (ret) {
  53. dev_err(&pdev->dev, "generic probe failed %d\n", ret);
  54. return ret;
  55. }
  56. /* Enable low-jitter mode on the 32khz clocks. */
  57. ret = regmap_update_bits(iodev->regmap, MAX77802_REG_32KHZ,
  58. 1 << MAX77802_CLOCK_LOW_JITTER_SHIFT,
  59. 1 << MAX77802_CLOCK_LOW_JITTER_SHIFT);
  60. if (ret < 0)
  61. dev_err(&pdev->dev, "failed to enable low-jitter mode\n");
  62. return ret;
  63. }
  64. static int max77802_clk_remove(struct platform_device *pdev)
  65. {
  66. return max_gen_clk_remove(pdev, MAX77802_CLKS_NUM);
  67. }
  68. static const struct platform_device_id max77802_clk_id[] = {
  69. { "max77802-clk", 0},
  70. { },
  71. };
  72. MODULE_DEVICE_TABLE(platform, max77802_clk_id);
  73. static struct platform_driver max77802_clk_driver = {
  74. .driver = {
  75. .name = "max77802-clk",
  76. },
  77. .probe = max77802_clk_probe,
  78. .remove = max77802_clk_remove,
  79. .id_table = max77802_clk_id,
  80. };
  81. module_platform_driver(max77802_clk_driver);
  82. MODULE_DESCRIPTION("MAXIM 77802 Clock Driver");
  83. MODULE_AUTHOR("Javier Martinez Canillas <javier@osg.samsung.com");
  84. MODULE_LICENSE("GPL");