denali_dt.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. static const struct of_device_id denali_nand_dt_ids[] = {
  30. { .compatible = "denali,denali-nand-dt" },
  31. { /* sentinel */ }
  32. };
  33. MODULE_DEVICE_TABLE(of, denali_nand_dt_ids);
  34. static u64 denali_dma_mask;
  35. static int denali_dt_probe(struct platform_device *ofdev)
  36. {
  37. struct resource *denali_reg, *nand_data;
  38. struct denali_dt *dt;
  39. struct denali_nand_info *denali;
  40. int ret;
  41. const struct of_device_id *of_id;
  42. of_id = of_match_device(denali_nand_dt_ids, &ofdev->dev);
  43. if (of_id) {
  44. ofdev->id_entry = of_id->data;
  45. } else {
  46. pr_err("Failed to find the right device id.\n");
  47. return -ENOMEM;
  48. }
  49. dt = devm_kzalloc(&ofdev->dev, sizeof(*dt), GFP_KERNEL);
  50. if (!dt)
  51. return -ENOMEM;
  52. denali = &dt->denali;
  53. denali->platform = DT;
  54. denali->dev = &ofdev->dev;
  55. denali->irq = platform_get_irq(ofdev, 0);
  56. if (denali->irq < 0) {
  57. dev_err(&ofdev->dev, "no irq defined\n");
  58. return denali->irq;
  59. }
  60. denali_reg = platform_get_resource_byname(ofdev, IORESOURCE_MEM, "denali_reg");
  61. denali->flash_reg = devm_ioremap_resource(&ofdev->dev, denali_reg);
  62. if (IS_ERR(denali->flash_reg))
  63. return PTR_ERR(denali->flash_reg);
  64. nand_data = platform_get_resource_byname(ofdev, IORESOURCE_MEM, "nand_data");
  65. denali->flash_mem = devm_ioremap_resource(&ofdev->dev, nand_data);
  66. if (IS_ERR(denali->flash_mem))
  67. return PTR_ERR(denali->flash_mem);
  68. if (!of_property_read_u32(ofdev->dev.of_node,
  69. "dma-mask", (u32 *)&denali_dma_mask)) {
  70. denali->dev->dma_mask = &denali_dma_mask;
  71. } else {
  72. denali->dev->dma_mask = NULL;
  73. }
  74. dt->clk = devm_clk_get(&ofdev->dev, NULL);
  75. if (IS_ERR(dt->clk)) {
  76. dev_err(&ofdev->dev, "no clk available\n");
  77. return PTR_ERR(dt->clk);
  78. }
  79. clk_prepare_enable(dt->clk);
  80. ret = denali_init(denali);
  81. if (ret)
  82. goto out_disable_clk;
  83. platform_set_drvdata(ofdev, dt);
  84. return 0;
  85. out_disable_clk:
  86. clk_disable_unprepare(dt->clk);
  87. return ret;
  88. }
  89. static int denali_dt_remove(struct platform_device *ofdev)
  90. {
  91. struct denali_dt *dt = platform_get_drvdata(ofdev);
  92. denali_remove(&dt->denali);
  93. clk_disable_unprepare(dt->clk);
  94. return 0;
  95. }
  96. static struct platform_driver denali_dt_driver = {
  97. .probe = denali_dt_probe,
  98. .remove = denali_dt_remove,
  99. .driver = {
  100. .name = "denali-nand-dt",
  101. .of_match_table = denali_nand_dt_ids,
  102. },
  103. };
  104. module_platform_driver(denali_dt_driver);
  105. MODULE_LICENSE("GPL");
  106. MODULE_AUTHOR("Jamie Iles");
  107. MODULE_DESCRIPTION("DT driver for Denali NAND controller");