atmel-sdramc.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * Atmel (Multi-port DDR-)SDRAM Controller driver
  3. *
  4. * Author: Alexandre Belloni <alexandre.belloni@free-electrons.com>
  5. *
  6. * Copyright (C) 2014 Atmel
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation version 2 of the License.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. *
  20. */
  21. #include <linux/clk.h>
  22. #include <linux/err.h>
  23. #include <linux/kernel.h>
  24. #include <linux/init.h>
  25. #include <linux/of_platform.h>
  26. #include <linux/platform_device.h>
  27. struct at91_ramc_caps {
  28. bool has_ddrck;
  29. bool has_mpddr_clk;
  30. };
  31. static const struct at91_ramc_caps at91rm9200_caps = { };
  32. static const struct at91_ramc_caps at91sam9g45_caps = {
  33. .has_ddrck = 1,
  34. .has_mpddr_clk = 0,
  35. };
  36. static const struct at91_ramc_caps sama5d3_caps = {
  37. .has_ddrck = 1,
  38. .has_mpddr_clk = 1,
  39. };
  40. static const struct of_device_id atmel_ramc_of_match[] = {
  41. { .compatible = "atmel,at91rm9200-sdramc", .data = &at91rm9200_caps, },
  42. { .compatible = "atmel,at91sam9260-sdramc", .data = &at91rm9200_caps, },
  43. { .compatible = "atmel,at91sam9g45-ddramc", .data = &at91sam9g45_caps, },
  44. { .compatible = "atmel,sama5d3-ddramc", .data = &sama5d3_caps, },
  45. {},
  46. };
  47. static int atmel_ramc_probe(struct platform_device *pdev)
  48. {
  49. const struct at91_ramc_caps *caps;
  50. struct clk *clk;
  51. caps = of_device_get_match_data(&pdev->dev);
  52. if (caps->has_ddrck) {
  53. clk = devm_clk_get(&pdev->dev, "ddrck");
  54. if (IS_ERR(clk))
  55. return PTR_ERR(clk);
  56. clk_prepare_enable(clk);
  57. }
  58. if (caps->has_mpddr_clk) {
  59. clk = devm_clk_get(&pdev->dev, "mpddr");
  60. if (IS_ERR(clk)) {
  61. pr_err("AT91 RAMC: couldn't get mpddr clock\n");
  62. return PTR_ERR(clk);
  63. }
  64. clk_prepare_enable(clk);
  65. }
  66. return 0;
  67. }
  68. static struct platform_driver atmel_ramc_driver = {
  69. .probe = atmel_ramc_probe,
  70. .driver = {
  71. .name = "atmel-ramc",
  72. .of_match_table = atmel_ramc_of_match,
  73. },
  74. };
  75. static int __init atmel_ramc_init(void)
  76. {
  77. return platform_driver_register(&atmel_ramc_driver);
  78. }
  79. device_initcall(atmel_ramc_init);