aemif.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * TNETV107X: Asynchronous EMIF Configuration
  3. *
  4. * See file CREDITS for list of people who contributed to this
  5. * project.
  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 as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. */
  21. #include <common.h>
  22. #include <asm/io.h>
  23. #include <asm/arch/clock.h>
  24. #include <asm/arch/mux.h>
  25. #define ASYNC_EMIF_BASE TNETV107X_ASYNC_EMIF_CNTRL_BASE
  26. #define ASYNC_EMIF_CONFIG(cs) (ASYNC_EMIF_BASE+0x10+(cs)*4)
  27. #define ASYNC_EMIF_ONENAND_CONTROL (ASYNC_EMIF_BASE+0x5c)
  28. #define ASYNC_EMIF_NAND_CONTROL (ASYNC_EMIF_BASE+0x60)
  29. #define ASYNC_EMIF_WAITCYCLE_CONFIG (ASYNC_EMIF_BASE+0x4)
  30. #define CONFIG_SELECT_STROBE(v) ((v) ? 1 << 31 : 0)
  31. #define CONFIG_EXTEND_WAIT(v) ((v) ? 1 << 30 : 0)
  32. #define CONFIG_WR_SETUP(v) (((v) & 0x0f) << 26)
  33. #define CONFIG_WR_STROBE(v) (((v) & 0x3f) << 20)
  34. #define CONFIG_WR_HOLD(v) (((v) & 0x07) << 17)
  35. #define CONFIG_RD_SETUP(v) (((v) & 0x0f) << 13)
  36. #define CONFIG_RD_STROBE(v) (((v) & 0x3f) << 7)
  37. #define CONFIG_RD_HOLD(v) (((v) & 0x07) << 4)
  38. #define CONFIG_TURN_AROUND(v) (((v) & 0x03) << 2)
  39. #define CONFIG_WIDTH(v) (((v) & 0x03) << 0)
  40. #define NUM_CS 4
  41. #define set_config_field(reg, field, val) \
  42. do { \
  43. if (val != -1) { \
  44. reg &= ~CONFIG_##field(0xffffffff); \
  45. reg |= CONFIG_##field(val); \
  46. } \
  47. } while (0)
  48. void configure_async_emif(int cs, struct async_emif_config *cfg)
  49. {
  50. unsigned long tmp;
  51. if (cfg->mode == ASYNC_EMIF_MODE_NAND) {
  52. tmp = __raw_readl(ASYNC_EMIF_NAND_CONTROL);
  53. tmp |= (1 << cs);
  54. __raw_writel(tmp, ASYNC_EMIF_NAND_CONTROL);
  55. } else if (cfg->mode == ASYNC_EMIF_MODE_ONENAND) {
  56. tmp = __raw_readl(ASYNC_EMIF_ONENAND_CONTROL);
  57. tmp |= (1 << cs);
  58. __raw_writel(tmp, ASYNC_EMIF_ONENAND_CONTROL);
  59. }
  60. tmp = __raw_readl(ASYNC_EMIF_CONFIG(cs));
  61. set_config_field(tmp, SELECT_STROBE, cfg->select_strobe);
  62. set_config_field(tmp, EXTEND_WAIT, cfg->extend_wait);
  63. set_config_field(tmp, WR_SETUP, cfg->wr_setup);
  64. set_config_field(tmp, WR_STROBE, cfg->wr_strobe);
  65. set_config_field(tmp, WR_HOLD, cfg->wr_hold);
  66. set_config_field(tmp, RD_SETUP, cfg->rd_setup);
  67. set_config_field(tmp, RD_STROBE, cfg->rd_strobe);
  68. set_config_field(tmp, RD_HOLD, cfg->rd_hold);
  69. set_config_field(tmp, TURN_AROUND, cfg->turn_around);
  70. set_config_field(tmp, WIDTH, cfg->width);
  71. __raw_writel(tmp, ASYNC_EMIF_CONFIG(cs));
  72. }
  73. void init_async_emif(int num_cs, struct async_emif_config *config)
  74. {
  75. int cs;
  76. clk_enable(TNETV107X_LPSC_AEMIF);
  77. for (cs = 0; cs < num_cs; cs++)
  78. configure_async_emif(cs, config + cs);
  79. }