ti-aemif.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * Keystone2: Asynchronous EMIF Configuration
  3. *
  4. * (C) Copyright 2012-2014
  5. * Texas Instruments Incorporated, <www.ti.com>
  6. *
  7. * SPDX-License-Identifier: GPL-2.0+
  8. */
  9. #include <common.h>
  10. #include <asm/ti-common/ti-aemif.h>
  11. #define AEMIF_WAITCYCLE_CONFIG (CONFIG_AEMIF_CNTRL_BASE + 0x4)
  12. #define AEMIF_NAND_CONTROL (CONFIG_AEMIF_CNTRL_BASE + 0x60)
  13. #define AEMIF_ONENAND_CONTROL (CONFIG_AEMIF_CNTRL_BASE + 0x5c)
  14. #define AEMIF_CONFIG(cs) (CONFIG_AEMIF_CNTRL_BASE + 0x10 \
  15. + (cs * 4))
  16. #define AEMIF_CFG_SELECT_STROBE(v) ((v) ? 1 << 31 : 0)
  17. #define AEMIF_CFG_EXTEND_WAIT(v) ((v) ? 1 << 30 : 0)
  18. #define AEMIF_CFG_WR_SETUP(v) (((v) & 0x0f) << 26)
  19. #define AEMIF_CFG_WR_STROBE(v) (((v) & 0x3f) << 20)
  20. #define AEMIF_CFG_WR_HOLD(v) (((v) & 0x07) << 17)
  21. #define AEMIF_CFG_RD_SETUP(v) (((v) & 0x0f) << 13)
  22. #define AEMIF_CFG_RD_STROBE(v) (((v) & 0x3f) << 7)
  23. #define AEMIF_CFG_RD_HOLD(v) (((v) & 0x07) << 4)
  24. #define AEMIF_CFG_TURN_AROUND(v) (((v) & 0x03) << 2)
  25. #define AEMIF_CFG_WIDTH(v) (((v) & 0x03) << 0)
  26. #define set_config_field(reg, field, val) \
  27. do { \
  28. if (val != -1) { \
  29. reg &= ~AEMIF_CFG_##field(0xffffffff); \
  30. reg |= AEMIF_CFG_##field(val); \
  31. } \
  32. } while (0)
  33. static void aemif_configure(int cs, struct aemif_config *cfg)
  34. {
  35. unsigned long tmp;
  36. if (cfg->mode == AEMIF_MODE_NAND) {
  37. tmp = __raw_readl(AEMIF_NAND_CONTROL);
  38. tmp |= (1 << cs);
  39. __raw_writel(tmp, AEMIF_NAND_CONTROL);
  40. } else if (cfg->mode == AEMIF_MODE_ONENAND) {
  41. tmp = __raw_readl(AEMIF_ONENAND_CONTROL);
  42. tmp |= (1 << cs);
  43. __raw_writel(tmp, AEMIF_ONENAND_CONTROL);
  44. }
  45. tmp = __raw_readl(AEMIF_CONFIG(cs));
  46. set_config_field(tmp, SELECT_STROBE, cfg->select_strobe);
  47. set_config_field(tmp, EXTEND_WAIT, cfg->extend_wait);
  48. set_config_field(tmp, WR_SETUP, cfg->wr_setup);
  49. set_config_field(tmp, WR_STROBE, cfg->wr_strobe);
  50. set_config_field(tmp, WR_HOLD, cfg->wr_hold);
  51. set_config_field(tmp, RD_SETUP, cfg->rd_setup);
  52. set_config_field(tmp, RD_STROBE, cfg->rd_strobe);
  53. set_config_field(tmp, RD_HOLD, cfg->rd_hold);
  54. set_config_field(tmp, TURN_AROUND, cfg->turn_around);
  55. set_config_field(tmp, WIDTH, cfg->width);
  56. __raw_writel(tmp, AEMIF_CONFIG(cs));
  57. }
  58. void aemif_init(int num_cs, struct aemif_config *config)
  59. {
  60. int cs;
  61. if (num_cs > AEMIF_NUM_CS) {
  62. num_cs = AEMIF_NUM_CS;
  63. printf("AEMIF: csnum has to be <= 5");
  64. }
  65. for (cs = 0; cs < num_cs; cs++)
  66. aemif_configure(cs, config + cs);
  67. }