ti-aemif.c 2.4 KB

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