gpmc-nand.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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/nand.h>
  17. #include <plat/gpmc.h>
  18. #include "soc.h"
  19. static struct resource gpmc_nand_resource[] = {
  20. {
  21. .flags = IORESOURCE_MEM,
  22. },
  23. {
  24. .flags = IORESOURCE_IRQ,
  25. },
  26. {
  27. .flags = IORESOURCE_IRQ,
  28. },
  29. };
  30. static struct platform_device gpmc_nand_device = {
  31. .name = "omap2-nand",
  32. .id = 0,
  33. .num_resources = ARRAY_SIZE(gpmc_nand_resource),
  34. .resource = gpmc_nand_resource,
  35. };
  36. static int omap2_nand_gpmc_retime(struct omap_nand_platform_data *gpmc_nand_data)
  37. {
  38. struct gpmc_timings t;
  39. int err;
  40. if (!gpmc_nand_data->gpmc_t)
  41. return 0;
  42. memset(&t, 0, sizeof(t));
  43. t.sync_clk = gpmc_nand_data->gpmc_t->sync_clk;
  44. t.cs_on = gpmc_round_ns_to_ticks(gpmc_nand_data->gpmc_t->cs_on);
  45. t.adv_on = gpmc_round_ns_to_ticks(gpmc_nand_data->gpmc_t->adv_on);
  46. /* Read */
  47. t.adv_rd_off = gpmc_round_ns_to_ticks(
  48. gpmc_nand_data->gpmc_t->adv_rd_off);
  49. t.oe_on = t.adv_on;
  50. t.access = gpmc_round_ns_to_ticks(gpmc_nand_data->gpmc_t->access);
  51. t.oe_off = gpmc_round_ns_to_ticks(gpmc_nand_data->gpmc_t->oe_off);
  52. t.cs_rd_off = gpmc_round_ns_to_ticks(gpmc_nand_data->gpmc_t->cs_rd_off);
  53. t.rd_cycle = gpmc_round_ns_to_ticks(gpmc_nand_data->gpmc_t->rd_cycle);
  54. /* Write */
  55. t.adv_wr_off = gpmc_round_ns_to_ticks(
  56. gpmc_nand_data->gpmc_t->adv_wr_off);
  57. t.we_on = t.oe_on;
  58. if (cpu_is_omap34xx()) {
  59. t.wr_data_mux_bus = gpmc_round_ns_to_ticks(
  60. gpmc_nand_data->gpmc_t->wr_data_mux_bus);
  61. t.wr_access = gpmc_round_ns_to_ticks(
  62. gpmc_nand_data->gpmc_t->wr_access);
  63. }
  64. t.we_off = gpmc_round_ns_to_ticks(gpmc_nand_data->gpmc_t->we_off);
  65. t.cs_wr_off = gpmc_round_ns_to_ticks(gpmc_nand_data->gpmc_t->cs_wr_off);
  66. t.wr_cycle = gpmc_round_ns_to_ticks(gpmc_nand_data->gpmc_t->wr_cycle);
  67. /* Configure GPMC */
  68. if (gpmc_nand_data->devsize == NAND_BUSWIDTH_16)
  69. gpmc_cs_configure(gpmc_nand_data->cs, GPMC_CONFIG_DEV_SIZE, 1);
  70. else
  71. gpmc_cs_configure(gpmc_nand_data->cs, GPMC_CONFIG_DEV_SIZE, 0);
  72. gpmc_cs_configure(gpmc_nand_data->cs,
  73. GPMC_CONFIG_DEV_TYPE, GPMC_DEVICETYPE_NAND);
  74. gpmc_cs_configure(gpmc_nand_data->cs, GPMC_CONFIG_WP, 0);
  75. err = gpmc_cs_set_timings(gpmc_nand_data->cs, &t);
  76. if (err)
  77. return err;
  78. return 0;
  79. }
  80. int __init gpmc_nand_init(struct omap_nand_platform_data *gpmc_nand_data)
  81. {
  82. int err = 0;
  83. struct device *dev = &gpmc_nand_device.dev;
  84. gpmc_nand_device.dev.platform_data = gpmc_nand_data;
  85. err = gpmc_cs_request(gpmc_nand_data->cs, NAND_IO_SIZE,
  86. (unsigned long *)&gpmc_nand_resource[0].start);
  87. if (err < 0) {
  88. dev_err(dev, "Cannot request GPMC CS\n");
  89. return err;
  90. }
  91. gpmc_nand_resource[0].end = gpmc_nand_resource[0].start +
  92. NAND_IO_SIZE - 1;
  93. gpmc_nand_resource[1].start =
  94. gpmc_get_client_irq(GPMC_IRQ_FIFOEVENTENABLE);
  95. gpmc_nand_resource[2].start =
  96. gpmc_get_client_irq(GPMC_IRQ_COUNT_EVENT);
  97. /* Set timings in GPMC */
  98. err = omap2_nand_gpmc_retime(gpmc_nand_data);
  99. if (err < 0) {
  100. dev_err(dev, "Unable to set gpmc timings: %d\n", err);
  101. return err;
  102. }
  103. /* Enable RD PIN Monitoring Reg */
  104. if (gpmc_nand_data->dev_ready) {
  105. gpmc_cs_configure(gpmc_nand_data->cs, GPMC_CONFIG_RDY_BSY, 1);
  106. }
  107. gpmc_update_nand_reg(&gpmc_nand_data->reg, gpmc_nand_data->cs);
  108. err = platform_device_register(&gpmc_nand_device);
  109. if (err < 0) {
  110. dev_err(dev, "Unable to register NAND device\n");
  111. goto out_free_cs;
  112. }
  113. return 0;
  114. out_free_cs:
  115. gpmc_cs_free(gpmc_nand_data->cs);
  116. return err;
  117. }