gpmc-nand.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 <asm/mach/flash.h>
  15. #include <plat/nand.h>
  16. #include <plat/board.h>
  17. #include <plat/gpmc.h>
  18. #define WR_RD_PIN_MONITORING 0x00600000
  19. static struct omap_nand_platform_data *gpmc_nand_data;
  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(void)
  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_round_ns_to_ticks(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. gpmc_cs_write_reg(gpmc_nand_data->cs, GPMC_CS_CONFIG1,
  62. GPMC_CONFIG1_DEVICESIZE(gpmc_nand_data->devsize) |
  63. GPMC_CONFIG1_DEVICETYPE_NAND);
  64. err = gpmc_cs_set_timings(gpmc_nand_data->cs, &t);
  65. if (err)
  66. return err;
  67. return 0;
  68. }
  69. static int gpmc_nand_setup(void)
  70. {
  71. struct device *dev = &gpmc_nand_device.dev;
  72. /* Set timings in GPMC */
  73. if (omap2_nand_gpmc_retime() < 0) {
  74. dev_err(dev, "Unable to set gpmc timings\n");
  75. return -EINVAL;
  76. }
  77. return 0;
  78. }
  79. int __init gpmc_nand_init(struct omap_nand_platform_data *_nand_data)
  80. {
  81. unsigned int val;
  82. int err = 0;
  83. struct device *dev = &gpmc_nand_device.dev;
  84. gpmc_nand_data = _nand_data;
  85. gpmc_nand_data->nand_setup = gpmc_nand_setup;
  86. gpmc_nand_device.dev.platform_data = gpmc_nand_data;
  87. err = gpmc_cs_request(gpmc_nand_data->cs, NAND_IO_SIZE,
  88. &gpmc_nand_data->phys_base);
  89. if (err < 0) {
  90. dev_err(dev, "Cannot request GPMC CS\n");
  91. return err;
  92. }
  93. err = gpmc_nand_setup();
  94. if (err < 0) {
  95. dev_err(dev, "NAND platform setup failed: %d\n", err);
  96. return err;
  97. }
  98. /* Enable RD PIN Monitoring Reg */
  99. if (gpmc_nand_data->dev_ready) {
  100. val = gpmc_cs_read_reg(gpmc_nand_data->cs,
  101. GPMC_CS_CONFIG1);
  102. val |= WR_RD_PIN_MONITORING;
  103. gpmc_cs_write_reg(gpmc_nand_data->cs,
  104. GPMC_CS_CONFIG1, val);
  105. }
  106. err = platform_device_register(&gpmc_nand_device);
  107. if (err < 0) {
  108. dev_err(dev, "Unable to register NAND device\n");
  109. goto out_free_cs;
  110. }
  111. return 0;
  112. out_free_cs:
  113. gpmc_cs_free(gpmc_nand_data->cs);
  114. return err;
  115. }