denali_dt.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * NAND Flash Controller Device Driver for DT
  3. *
  4. * Copyright © 2011, Picochip.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms and conditions of the GNU General Public License,
  8. * version 2, as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. */
  15. #include <linux/clk.h>
  16. #include <linux/err.h>
  17. #include <linux/io.h>
  18. #include <linux/ioport.h>
  19. #include <linux/kernel.h>
  20. #include <linux/module.h>
  21. #include <linux/platform_device.h>
  22. #include <linux/of.h>
  23. #include <linux/of_device.h>
  24. #include "denali.h"
  25. struct denali_dt {
  26. struct denali_nand_info denali;
  27. struct clk *clk;
  28. };
  29. struct denali_dt_data {
  30. unsigned int revision;
  31. unsigned int caps;
  32. };
  33. static const struct denali_dt_data denali_socfpga_data = {
  34. .caps = DENALI_CAP_HW_ECC_FIXUP,
  35. };
  36. static const struct of_device_id denali_nand_dt_ids[] = {
  37. {
  38. .compatible = "altr,socfpga-denali-nand",
  39. .data = &denali_socfpga_data,
  40. },
  41. { /* sentinel */ }
  42. };
  43. MODULE_DEVICE_TABLE(of, denali_nand_dt_ids);
  44. static int denali_dt_probe(struct platform_device *pdev)
  45. {
  46. struct resource *denali_reg, *nand_data;
  47. struct denali_dt *dt;
  48. const struct denali_dt_data *data;
  49. struct denali_nand_info *denali;
  50. int ret;
  51. dt = devm_kzalloc(&pdev->dev, sizeof(*dt), GFP_KERNEL);
  52. if (!dt)
  53. return -ENOMEM;
  54. denali = &dt->denali;
  55. data = of_device_get_match_data(&pdev->dev);
  56. if (data) {
  57. denali->revision = data->revision;
  58. denali->caps = data->caps;
  59. }
  60. denali->platform = DT;
  61. denali->dev = &pdev->dev;
  62. denali->irq = platform_get_irq(pdev, 0);
  63. if (denali->irq < 0) {
  64. dev_err(&pdev->dev, "no irq defined\n");
  65. return denali->irq;
  66. }
  67. denali_reg = platform_get_resource_byname(pdev, IORESOURCE_MEM,
  68. "denali_reg");
  69. denali->flash_reg = devm_ioremap_resource(&pdev->dev, denali_reg);
  70. if (IS_ERR(denali->flash_reg))
  71. return PTR_ERR(denali->flash_reg);
  72. nand_data = platform_get_resource_byname(pdev, IORESOURCE_MEM,
  73. "nand_data");
  74. denali->flash_mem = devm_ioremap_resource(&pdev->dev, nand_data);
  75. if (IS_ERR(denali->flash_mem))
  76. return PTR_ERR(denali->flash_mem);
  77. dt->clk = devm_clk_get(&pdev->dev, NULL);
  78. if (IS_ERR(dt->clk)) {
  79. dev_err(&pdev->dev, "no clk available\n");
  80. return PTR_ERR(dt->clk);
  81. }
  82. clk_prepare_enable(dt->clk);
  83. ret = denali_init(denali);
  84. if (ret)
  85. goto out_disable_clk;
  86. platform_set_drvdata(pdev, dt);
  87. return 0;
  88. out_disable_clk:
  89. clk_disable_unprepare(dt->clk);
  90. return ret;
  91. }
  92. static int denali_dt_remove(struct platform_device *pdev)
  93. {
  94. struct denali_dt *dt = platform_get_drvdata(pdev);
  95. denali_remove(&dt->denali);
  96. clk_disable_unprepare(dt->clk);
  97. return 0;
  98. }
  99. static struct platform_driver denali_dt_driver = {
  100. .probe = denali_dt_probe,
  101. .remove = denali_dt_remove,
  102. .driver = {
  103. .name = "denali-nand-dt",
  104. .of_match_table = denali_nand_dt_ids,
  105. },
  106. };
  107. module_platform_driver(denali_dt_driver);
  108. MODULE_LICENSE("GPL");
  109. MODULE_AUTHOR("Jamie Iles");
  110. MODULE_DESCRIPTION("DT driver for Denali NAND controller");