atmel-sdramc.c 2.6 KB

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