basicAlgorithmEncapsulation.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. * linux/arch/arm/mach-omap2/gpmc-onenand.c
  3. *
  4. * Copyright (C) 2006 - 2009 Nokia Corporation
  5. * Contacts: Juha Yrjola
  6. * Tony Lindgren
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #include <linux/string.h>
  13. #include <linux/kernel.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/mtd/onenand_regs.h>
  16. #include <linux/io.h>
  17. #include <linux/platform_data/mtd-onenand-omap2.h>
  18. #include <linux/err.h>
  19. #include <asm/mach/flash.h>
  20. #include "gpmc.h"
  21. #include "soc.h"
  22. #include "gpmc-onenand.h"
  23. #define ONENAND_IO_SIZE SZ_128K
  24. #define ONENAND_FLAG_SYNCREAD (1 << 0)
  25. #define ONENAND_FLAG_SYNCWRITE (1 << 1)
  26. #define ONENAND_FLAG_HF (1 << 2)
  27. #define ONENAND_FLAG_VHF (1 << 3)
  28. static unsigned onenand_flags;
  29. static unsigned latency;
  30. static struct omap_onenand_platform_data *gpmc_onenand_data;
  31. static struct resource gpmc_onenand_resource = {
  32. .flags = IORESOURCE_MEM,
  33. };
  34. static struct platform_device gpmc_onenand_device = {
  35. .name = "omap2-onenand",
  36. .id = -1,
  37. .num_resources = 1,
  38. .resource = &gpmc_onenand_resource,
  39. };
  40. static struct gpmc_timings omap2_onenand_calc_async_timings(void)
  41. {
  42. struct gpmc_device_timings dev_t;
  43. struct gpmc_timings t;
  44. const int t_cer = 15;
  45. const int t_avdp = 12;
  46. const int t_aavdh = 7;
  47. const int t_ce = 76;
  48. const int t_aa = 76;
  49. const int t_oe = 20;
  50. const int t_cez = 20; /* max of t_cez, t_oez */
  51. const int t_wpl = 40;
  52. const int t_wph = 30;
  53. memset(&dev_t, 0, sizeof(dev_t));
  54. dev_t.mux = true;
  55. dev_t.t_avdp_r = max_t(int, t_avdp, t_cer) * 1000;
  56. dev_t.t_avdp_w = dev_t.t_avdp_r;
  57. dev_t.t_aavdh = t_aavdh * 1000;
  58. dev_t.t_aa = t_aa * 1000;
  59. dev_t.t_ce = t_ce * 1000;
  60. dev_t.t_oe = t_oe * 1000;
  61. dev_t.t_cez_r = t_cez * 1000;
  62. dev_t.t_cez_w = dev_t.t_cez_r;
  63. dev_t.t_wpl = t_wpl * 1000;
  64. dev_t.t_wph = t_wph * 1000;
  65. gpmc_calc_timings(&t, &dev_t);
  66. return t;
  67. }
  68. static int gpmc_set_async_mode(int cs, struct gpmc_timings *t)
  69. {
  70. /* Configure GPMC for asynchronous read */
  71. gpmc_cs_write_reg(cs, GPMC_CS_CONFIG1,
  72. GPMC_CONFIG1_DEVICESIZE_16 |
  73. GPMC_CONFIG1_MUXADDDATA);
  74. return gpmc_cs_set_timings(cs, t);
  75. }
  76. static void omap2_onenand_set_async_mode(void __iomem *onenand_base)
  77. {
  78. u32 reg;
  79. /* Ensure sync read and sync write are disabled */
  80. reg = readw(onenand_base + ONENAND_REG_SYS_CFG1);
  81. reg &= ~ONENAND_SYS_CFG1_SYNC_READ & ~ONENAND_SYS_CFG1_SYNC_WRITE;
  82. writew(reg, onenand_base + ONENAND_REG_SYS_CFG1);
  83. }
  84. static void set_onenand_cfg(void __iomem *onenand_base)
  85. {
  86. u32 reg;