atmel-hlcdc.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * Copyright (C) 2014 Free Electrons
  3. * Copyright (C) 2014 Atmel
  4. *
  5. * Author: Boris BREZILLON <boris.brezillon@free-electrons.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License version 2 as published by
  9. * the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  14. * more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along with
  17. * this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include <linux/clk.h>
  20. #include <linux/mfd/atmel-hlcdc.h>
  21. #include <linux/mfd/core.h>
  22. #include <linux/module.h>
  23. #include <linux/platform_device.h>
  24. #include <linux/regmap.h>
  25. #define ATMEL_HLCDC_REG_MAX (0x4000 - 0x4)
  26. static const struct mfd_cell atmel_hlcdc_cells[] = {
  27. {
  28. .name = "atmel-hlcdc-pwm",
  29. .of_compatible = "atmel,hlcdc-pwm",
  30. },
  31. {
  32. .name = "atmel-hlcdc-dc",
  33. .of_compatible = "atmel,hlcdc-display-controller",
  34. },
  35. };
  36. static const struct regmap_config atmel_hlcdc_regmap_config = {
  37. .reg_bits = 32,
  38. .val_bits = 32,
  39. .reg_stride = 4,
  40. .max_register = ATMEL_HLCDC_REG_MAX,
  41. };
  42. static int atmel_hlcdc_probe(struct platform_device *pdev)
  43. {
  44. struct device *dev = &pdev->dev;
  45. struct atmel_hlcdc *hlcdc;
  46. struct resource *res;
  47. void __iomem *regs;
  48. hlcdc = devm_kzalloc(dev, sizeof(*hlcdc), GFP_KERNEL);
  49. if (!hlcdc)
  50. return -ENOMEM;
  51. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  52. regs = devm_ioremap_resource(dev, res);
  53. if (IS_ERR(regs))
  54. return PTR_ERR(regs);
  55. hlcdc->irq = platform_get_irq(pdev, 0);
  56. if (hlcdc->irq < 0)
  57. return hlcdc->irq;
  58. hlcdc->periph_clk = devm_clk_get(dev, "periph_clk");
  59. if (IS_ERR(hlcdc->periph_clk)) {
  60. dev_err(dev, "failed to get peripheral clock\n");
  61. return PTR_ERR(hlcdc->periph_clk);
  62. }
  63. hlcdc->sys_clk = devm_clk_get(dev, "sys_clk");
  64. if (IS_ERR(hlcdc->sys_clk)) {
  65. dev_err(dev, "failed to get system clock\n");
  66. return PTR_ERR(hlcdc->sys_clk);
  67. }
  68. hlcdc->slow_clk = devm_clk_get(dev, "slow_clk");
  69. if (IS_ERR(hlcdc->slow_clk)) {
  70. dev_err(dev, "failed to get slow clock\n");
  71. return PTR_ERR(hlcdc->slow_clk);
  72. }
  73. hlcdc->regmap = devm_regmap_init_mmio(dev, regs,
  74. &atmel_hlcdc_regmap_config);
  75. if (IS_ERR(hlcdc->regmap))
  76. return PTR_ERR(hlcdc->regmap);
  77. dev_set_drvdata(dev, hlcdc);
  78. return mfd_add_devices(dev, -1, atmel_hlcdc_cells,
  79. ARRAY_SIZE(atmel_hlcdc_cells),
  80. NULL, 0, NULL);
  81. }
  82. static int atmel_hlcdc_remove(struct platform_device *pdev)
  83. {
  84. mfd_remove_devices(&pdev->dev);
  85. return 0;
  86. }
  87. static const struct of_device_id atmel_hlcdc_match[] = {
  88. { .compatible = "atmel,sama5d3-hlcdc" },
  89. { /* sentinel */ },
  90. };
  91. static struct platform_driver atmel_hlcdc_driver = {
  92. .probe = atmel_hlcdc_probe,
  93. .remove = atmel_hlcdc_remove,
  94. .driver = {
  95. .name = "atmel-hlcdc",
  96. .of_match_table = atmel_hlcdc_match,
  97. },
  98. };
  99. module_platform_driver(atmel_hlcdc_driver);
  100. MODULE_ALIAS("platform:atmel-hlcdc");
  101. MODULE_AUTHOR("Boris Brezillon <boris.brezillon@free-electrons.com>");
  102. MODULE_DESCRIPTION("Atmel HLCDC driver");
  103. MODULE_LICENSE("GPL v2");