ti-gpmc.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * TI GMPC driver
  3. *
  4. * (C) Copyright 2015
  5. * Texas Instruments, <www.ti.com>
  6. *
  7. * SPDX-License-Identifier: GPL-2.0+
  8. */
  9. #include <common.h>
  10. #include <command.h>
  11. #include <asm/ti-common/ti-gpmc.h>
  12. #include <linux/mtd/omap_gpmc.h>
  13. const struct gpmc *gpmc_cfg;
  14. /*****************************************************
  15. * omap_gpmc_init(): init gpmc bus
  16. * Init GPMC for x16, MuxMode (SDRAM in x32).
  17. * This code can only be executed from SRAM or SDRAM.
  18. *****************************************************/
  19. /* FIXME: for now we only support one CS */
  20. void ti_gpmc_init(struct ti_gpmc_config *cfg)
  21. {
  22. /* putting a blanket check on GPMC based on ZeBu for now */
  23. gpmc_cfg = (struct gpmc *)TI_GPMC_BASE;
  24. #if defined(CONFIG_NOR)
  25. u32 base = CONFIG_SYS_FLASH_BASE;
  26. u32 size = (CONFIG_SYS_FLASH_SIZE > 0x08000000) ? GPMC_SIZE_256M :
  27. /* > 64MB */ ((CONFIG_SYS_FLASH_SIZE > 0x04000000) ? GPMC_SIZE_128M :
  28. /* > 32MB */ ((CONFIG_SYS_FLASH_SIZE > 0x02000000) ? GPMC_SIZE_64M :
  29. /* > 16MB */ ((CONFIG_SYS_FLASH_SIZE > 0x01000000) ? GPMC_SIZE_32M :
  30. /* min 16MB */ GPMC_SIZE_16M)));
  31. #elif defined(CONFIG_NAND) || defined(CONFIG_CMD_NAND)
  32. /* configure GPMC for NAND */
  33. u32 base = CONFIG_SYS_NAND_BASE;
  34. u32 size = GPMC_SIZE_16M;
  35. #elif defined(CONFIG_CMD_ONENAND)
  36. u32 size = GPMC_SIZE_128M;
  37. u32 base = CONFIG_SYS_ONENAND_BASE;
  38. #else
  39. u32 size = 0;
  40. u32 base = 0;
  41. #endif
  42. /* global settings */
  43. writel(0x00000008, &gpmc_cfg->sysconfig);
  44. writel(0x00000000, &gpmc_cfg->irqstatus);
  45. writel(0x00000000, &gpmc_cfg->irqenable);
  46. /* disable timeout, set a safe reset value */
  47. writel(0x00001ff0, &gpmc_cfg->timeout_control);
  48. #ifdef CONFIG_NOR
  49. writel(0x00000200, &gpmc_cfg->config);
  50. #else
  51. writel(0x00000012, &gpmc_cfg->config);
  52. #endif
  53. /*
  54. * Disable the GPMC0 config set by ROM code
  55. */
  56. writel(0, &gpmc_cfg->cs[0].config7);
  57. sdelay(1000);
  58. /* enable chip-select specific configurations */
  59. if (base != 0) {
  60. writel(0, &gpmc_cfg->cs[0].config7);
  61. sdelay(1000);
  62. /* Delay for settling */
  63. writel(cfg->config1, &gpmc_cfg->cs[0].config1);
  64. writel(cfg->config2, &gpmc_cfg->cs[0].config2);
  65. writel(cfg->config3, &gpmc_cfg->cs[0].config3);
  66. writel(cfg->config4, &gpmc_cfg->cs[0].config4);
  67. writel(cfg->config5, &gpmc_cfg->cs[0].config5);
  68. writel(cfg->config6, &gpmc_cfg->cs[0].config6);
  69. /* Enable the config */
  70. writel((((size & 0xF) << 8) | ((base >> 24) & 0x3F) |
  71. (1 << 6)), &gpmc_cfg->cs[0].config7);
  72. sdelay(2000);
  73. }
  74. }