gpmc-nand.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. memset(&t, 0, sizeof(t));
  34. t.sync_clk = gpmc_round_ns_to_ticks(gpmc_nand_data->gpmc_t->sync_clk);
  35. t.cs_on = gpmc_round_ns_to_ticks(gpmc_nand_data->gpmc_t->cs_on);
  36. t.adv_on = gpmc_round_ns_to_ticks(gpmc_nand_data->gpmc_t->adv_on);
  37. /* Read */
  38. t.adv_rd_off = gpmc_round_ns_to_ticks(
  39. gpmc_nand_data->gpmc_t->adv_rd_off);
  40. t.oe_on = t.adv_on;
  41. t.access = gpmc_round_ns_to_ticks(gpmc_nand_data->gpmc_t->access);
  42. t.oe_off = gpmc_round_ns_to_ticks(gpmc_nand_data->gpmc_t->oe_off);
  43. t.cs_rd_off = gpmc_round_ns_to_ticks(gpmc_nand_data->gpmc_t->cs_rd_off);
  44. t.rd_cycle = gpmc_round_ns_to_ticks(gpmc_nand_data->gpmc_t->rd_cycle);
  45. /* Write */
  46. t.adv_wr_off = gpmc_round_ns_to_ticks(
  47. gpmc_nand_data->gpmc_t->adv_wr_off);
  48. t.we_on = t.oe_on;
  49. if (cpu_is_omap34xx()) {
  50. t.wr_data_mux_bus = gpmc_round_ns_to_ticks(
  51. gpmc_nand_data->gpmc_t->wr_data_mux_bus);
  52. t.wr_access = gpmc_round_ns_to_ticks(
  53. gpmc_nand_data->gpmc_t->wr_access);
  54. }
  55. t.we_off = gpmc_round_ns_to_ticks(gpmc_nand_data->gpmc_t->we_off);
  56. t.cs_wr_off = gpmc_round_ns_to_ticks(gpmc_nand_data->gpmc_t->cs_wr_off);
  57. t.wr_cycle = gpmc_round_ns_to_ticks(gpmc_nand_data->gpmc_t->wr_cycle);
  58. /* Configure GPMC */
  59. gpmc_cs_write_reg(gpmc_nand_data->cs, GPMC_CS_CONFIG1,
  60. GPMC_CONFIG1_DEVICESIZE(gpmc_nand_data->devsize) |
  61. GPMC_CONFIG1_DEVICETYPE_NAND);
  62. err = gpmc_cs_set_timings(gpmc_nand_data->cs, &t);
  63. if (err)
  64. return err;
  65. return 0;
  66. }
  67. static int gpmc_nand_setup(void)
  68. {
  69. struct device *dev = &gpmc_nand_device.dev;
  70. /* Set timings in GPMC */
  71. if (omap2_nand_gpmc_retime() < 0) {
  72. dev_err(dev, "Unable to set gpmc timings\n");
  73. return -EINVAL;
  74. }
  75. return 0;
  76. }
  77. int __init gpmc_nand_init(struct omap_nand_platform_data *_nand_data)
  78. {
  79. unsigned int val;
  80. int err = 0;
  81. struct device *dev = &gpmc_nand_device.dev;
  82. gpmc_nand_data = _nand_data;
  83. gpmc_nand_data->nand_setup = gpmc_nand_setup;
  84. gpmc_nand_device.dev.platform_data = gpmc_nand_data;
  85. err = gpmc_cs_request(gpmc_nand_data->cs, NAND_IO_SIZE,
  86. &gpmc_nand_data->phys_base);
  87. if (err < 0) {
  88. dev_err(dev, "Cannot request GPMC CS\n");
  89. return err;
  90. }
  91. err = gpmc_nand_setup();
  92. if (err < 0) {
  93. dev_err(dev, "NAND platform setup failed: %d\n", err);
  94. return err;
  95. }
  96. /* Enable RD PIN Monitoring Reg */
  97. if (gpmc_nand_data->dev_ready) {
  98. val = gpmc_cs_read_reg(gpmc_nand_data->cs,
  99. GPMC_CS_CONFIG1);
  100. val |= WR_RD_PIN_MONITORING;
  101. gpmc_cs_write_reg(gpmc_nand_data->cs,
  102. GPMC_CS_CONFIG1, val);
  103. }
  104. err = platform_device_register(&gpmc_nand_device);
  105. if (err < 0) {
  106. dev_err(dev, "Unable to register NAND device\n");
  107. goto out_free_cs;
  108. }
  109. return 0;
  110. out_free_cs:
  111. gpmc_cs_free(gpmc_nand_data->cs);
  112. return err;
  113. }