denali_dt.c 3.2 KB

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