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