gpmc-nand.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * gpmc-nand.c
  3. *
  4. * Copyright (C) 2009 Texas Instruments
  5. * Vimal Singh <vimalsingh@ti.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/kernel.h>
  12. #include <linux/platform_device.h>
  13. #include <linux/io.h>
  14. #include <linux/mtd/nand.h>
  15. #include <asm/mach/flash.h>
  16. #include <plat/cpu.h>
  17. #include <plat/nand.h>
  18. #include <plat/board.h>
  19. #include <plat/gpmc.h>
  20. static struct resource gpmc_nand_resource = {
  21. .flags = IORESOURCE_MEM,
  22. };
  23. static struct platform_device gpmc_nand_device = {
  24. .name = "omap2-nand",
  25. .id = 0,
  26. .num_resources = 1,
  27. .resource = &gpmc_nand_resource,
  28. };
  29. static int omap2_nand_gpmc_retime(struct omap_nand_platform_data *gpmc_nand_data)
  30. {
  31. struct gpmc_timings t;
  32. int err;
  33. if (!gpmc_nand_data->gpmc_t)
  34. return 0;
  35. memset(&t, 0, sizeof(t));
  36. t.sync_clk = gpmc_nand_data->gpmc_t->sync_clk;
  37. t.cs_on = gpmc_round_ns_to_ticks(gpmc_nand_data->gpmc_t->cs_on);
  38. t.adv_on = gpmc_round_ns_to_ticks(gpmc_nand_data->gpmc_t->adv_on);
  39. /* Read */
  40. t.adv_rd_off = gpmc_round_ns_to_ticks(
  41. gpmc_nand_data->gpmc_t->adv_rd_off);
  42. t.oe_on = t.adv_on;
  43. t.access = gpmc_round_ns_to_ticks(gpmc_nand_data->gpmc_t->access);
  44. t.oe_off = gpmc_round_ns_to_ticks(gpmc_nand_data->gpmc_t->oe_off);
  45. t.cs_rd_off = gpmc_round_ns_to_ticks(gpmc_nand_data->gpmc_t->cs_rd_off);
  46. t.rd_cycle = gpmc_round_ns_to_ticks(gpmc_nand_data->gpmc_t->rd_cycle);
  47. /* Write */
  48. t.adv_wr_off = gpmc_round_ns_to_ticks(
  49. gpmc_nand_data->gpmc_t->adv_wr_off);
  50. t.we_on = t.oe_on;
  51. if (cpu_is_omap34xx()) {
  52. t.wr_data_mux_bus = gpmc_round_ns_to_ticks(
  53. gpmc_nand_data->gpmc_t->wr_data_mux_bus);
  54. t.wr_access = gpmc_round_ns_to_ticks(
  55. gpmc_nand_data->gpmc_t->wr_access);
  56. }
  57. t.we_off = gpmc_round_ns_to_ticks(gpmc_nand_data->gpmc_t->we_off);
  58. t.cs_wr_off = gpmc_round_ns_to_ticks(gpmc_nand_data->gpmc_t->cs_wr_off);
  59. t.wr_cycle = gpmc_round_ns_to_ticks(gpmc_nand_data->gpmc_t->wr_cycle);
  60. /* Configure GPMC */
  61. if (gpmc_nand_data->devsize == NAND_BUSWIDTH_16)
  62. gpmc_cs_configure(gpmc_nand_data->cs, GPMC_CONFIG_DEV_SIZE, 1);
  63. else
  64. gpmc_cs_configure(gpmc_nand_data->cs, GPMC_CONFIG_DEV_SIZE, 0);
  65. gpmc_cs_configure(gpmc_nand_data->cs,
  66. GPMC_CONFIG_DEV_TYPE, GPMC_DEVICETYPE_NAND);
  67. err = gpmc_cs_set_timings(gpmc_nand_data->cs, &t);
  68. if (err)
  69. return err;
  70. return 0;
  71. }
  72. int __init gpmc_nand_init(struct omap_nand_platform_data *gpmc_nand_data)
  73. {
  74. int err = 0;
  75. struct device *dev = &gpmc_nand_device.dev;
  76. gpmc_nand_device.dev.platform_data = gpmc_nand_data;
  77. err = gpmc_cs_request(gpmc_nand_data->cs, NAND_IO_SIZE,
  78. &gpmc_nand_data->phys_base);
  79. if (err < 0) {
  80. dev_err(dev, "Cannot request GPMC CS\n");
  81. return err;
  82. }
  83. /* Set timings in GPMC */
  84. err = omap2_nand_gpmc_retime(gpmc_nand_data);
  85. if (err < 0) {
  86. dev_err(dev, "Unable to set gpmc timings: %d\n", err);
  87. return err;
  88. }
  89. /* Enable RD PIN Monitoring Reg */
  90. if (gpmc_nand_data->dev_ready) {
  91. gpmc_cs_configure(gpmc_nand_data->cs, GPMC_CONFIG_RDY_BSY, 1);
  92. }
  93. err = platform_device_register(&gpmc_nand_device);
  94. if (err < 0) {
  95. dev_err(dev, "Unable to register NAND device\n");
  96. goto out_free_cs;
  97. }
  98. return 0;
  99. out_free_cs:
  100. gpmc_cs_free(gpmc_nand_data->cs);
  101. return err;
  102. }