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