emif4.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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[2] = {
  42. (struct vtp_reg *)VTP0_CTRL_ADDR,
  43. (struct vtp_reg *)VTP1_CTRL_ADDR};
  44. #ifdef CONFIG_AM33XX
  45. static struct ddr_ctrl *ddrctrl = (struct ddr_ctrl *)DDR_CTRL_ADDR;
  46. #endif
  47. static void config_vtp(int nr)
  48. {
  49. writel(readl(&vtpreg[nr]->vtp0ctrlreg) | VTP_CTRL_ENABLE,
  50. &vtpreg[nr]->vtp0ctrlreg);
  51. writel(readl(&vtpreg[nr]->vtp0ctrlreg) & (~VTP_CTRL_START_EN),
  52. &vtpreg[nr]->vtp0ctrlreg);
  53. writel(readl(&vtpreg[nr]->vtp0ctrlreg) | VTP_CTRL_START_EN,
  54. &vtpreg[nr]->vtp0ctrlreg);
  55. /* Poll for READY */
  56. while ((readl(&vtpreg[nr]->vtp0ctrlreg) & VTP_CTRL_READY) !=
  57. VTP_CTRL_READY)
  58. ;
  59. }
  60. void config_ddr(unsigned int pll, unsigned int ioctrl,
  61. const struct ddr_data *data, const struct cmd_control *ctrl,
  62. const struct emif_regs *regs, int nr)
  63. {
  64. enable_emif_clocks();
  65. ddr_pll_config(pll);
  66. config_vtp(nr);
  67. config_cmd_ctrl(ctrl, nr);
  68. config_ddr_data(data, nr);
  69. #ifdef CONFIG_AM33XX
  70. config_io_ctrl(ioctrl);
  71. /* Set CKE to be controlled by EMIF/DDR PHY */
  72. writel(DDR_CKE_CTRL_NORMAL, &ddrctrl->ddrckectrl);
  73. #endif
  74. /* Program EMIF instance */
  75. config_ddr_phy(regs, nr);
  76. set_sdram_timings(regs, nr);
  77. config_sdram(regs, nr);
  78. }
  79. #endif