emif4.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * emif4.c
  3. *
  4. * AM33XX emif4 configuration file
  5. *
  6. * Copyright (C) 2011, Texas Instruments, Incorporated - http://www.ti.com/
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR /PURPOSE. See the
  16. * GNU General Public License for more details.
  17. */
  18. #include <common.h>
  19. #include <asm/arch/cpu.h>
  20. #include <asm/arch/ddr_defs.h>
  21. #include <asm/arch/hardware.h>
  22. #include <asm/arch/clock.h>
  23. #include <asm/arch/sys_proto.h>
  24. #include <asm/io.h>
  25. #include <asm/emif.h>
  26. DECLARE_GLOBAL_DATA_PTR;
  27. int dram_init(void)
  28. {
  29. /* dram_init must store complete ramsize in gd->ram_size */
  30. gd->ram_size = get_ram_size(
  31. (void *)CONFIG_SYS_SDRAM_BASE,
  32. CONFIG_MAX_RAM_BANK_SIZE);
  33. return 0;
  34. }
  35. void dram_init_banksize(void)
  36. {
  37. gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
  38. gd->bd->bi_dram[0].size = gd->ram_size;
  39. }
  40. #ifdef CONFIG_SPL_BUILD
  41. static struct vtp_reg *vtpreg = (struct vtp_reg *)VTP0_CTRL_ADDR;
  42. static struct ddr_ctrl *ddrctrl = (struct ddr_ctrl *)DDR_CTRL_ADDR;
  43. static void config_vtp(void)
  44. {
  45. writel(readl(&vtpreg->vtp0ctrlreg) | VTP_CTRL_ENABLE,
  46. &vtpreg->vtp0ctrlreg);
  47. writel(readl(&vtpreg->vtp0ctrlreg) & (~VTP_CTRL_START_EN),
  48. &vtpreg->vtp0ctrlreg);
  49. writel(readl(&vtpreg->vtp0ctrlreg) | VTP_CTRL_START_EN,
  50. &vtpreg->vtp0ctrlreg);
  51. /* Poll for READY */
  52. while ((readl(&vtpreg->vtp0ctrlreg) & VTP_CTRL_READY) !=
  53. VTP_CTRL_READY)
  54. ;
  55. }
  56. void config_ddr(unsigned int pll, unsigned int ioctrl,
  57. const struct ddr_data *data, const struct cmd_control *ctrl,
  58. const struct emif_regs *regs)
  59. {
  60. enable_emif_clocks();
  61. ddr_pll_config(pll);
  62. config_vtp();
  63. config_cmd_ctrl(ctrl);
  64. config_ddr_data(0, data);
  65. config_ddr_data(1, data);
  66. config_io_ctrl(ioctrl);
  67. /* Set CKE to be controlled by EMIF/DDR PHY */
  68. writel(DDR_CKE_CTRL_NORMAL, &ddrctrl->ddrckectrl);
  69. /* Program EMIF instance */
  70. config_ddr_phy(regs);
  71. set_sdram_timings(regs);
  72. config_sdram(regs);
  73. }
  74. #endif