psc.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * TI DaVinci Power and Sleep Controller (PSC)
  3. *
  4. * Copyright (C) 2006 Texas Instruments.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. *
  20. */
  21. #include <linux/kernel.h>
  22. #include <linux/module.h>
  23. #include <linux/init.h>
  24. #include <asm/io.h>
  25. #include <asm/hardware.h>
  26. #include <asm/arch/psc.h>
  27. #define PTCMD __REG(0x01C41120)
  28. #define PDSTAT __REG(0x01C41200)
  29. #define PDCTL1 __REG(0x01C41304)
  30. #define EPCPR __REG(0x01C41070)
  31. #define PTSTAT __REG(0x01C41128)
  32. #define MDSTAT IO_ADDRESS(0x01C41800)
  33. #define MDCTL IO_ADDRESS(0x01C41A00)
  34. #define PINMUX0 __REG(0x01c40000)
  35. #define PINMUX1 __REG(0x01c40004)
  36. #define VDD3P3V_PWDN __REG(0x01C40048)
  37. static void davinci_psc_mux(unsigned int id)
  38. {
  39. switch (id) {
  40. case DAVINCI_LPSC_ATA:
  41. PINMUX0 |= (1 << 17) | (1 << 16);
  42. break;
  43. case DAVINCI_LPSC_MMC_SD:
  44. /* VDD power manupulations are done in U-Boot for CPMAC
  45. * so applies to MMC as well
  46. */
  47. /*Set up the pull regiter for MMC */
  48. VDD3P3V_PWDN = 0x0;
  49. PINMUX1 &= (~(1 << 9));
  50. break;
  51. case DAVINCI_LPSC_I2C:
  52. PINMUX1 |= (1 << 7);
  53. break;
  54. case DAVINCI_LPSC_McBSP:
  55. PINMUX1 |= (1 << 10);
  56. break;
  57. default:
  58. break;
  59. }
  60. }
  61. /* Enable or disable a PSC domain */
  62. void davinci_psc_config(unsigned int domain, unsigned int id, char enable)
  63. {
  64. volatile unsigned int *mdstat = (unsigned int *)((int)MDSTAT + 4 * id);
  65. volatile unsigned int *mdctl = (unsigned int *)((int)MDCTL + 4 * id);
  66. if (id < 0)
  67. return;
  68. if (enable)
  69. *mdctl |= 0x00000003; /* Enable Module */
  70. else
  71. *mdctl &= 0xFFFFFFF2; /* Disable Module */
  72. if ((PDSTAT & 0x00000001) == 0) {
  73. PDCTL1 |= 0x1;
  74. PTCMD = (1 << domain);
  75. while ((((EPCPR >> domain) & 1) == 0));
  76. PDCTL1 |= 0x100;
  77. while (!(((PTSTAT >> domain) & 1) == 0));
  78. } else {
  79. PTCMD = (1 << domain);
  80. while (!(((PTSTAT >> domain) & 1) == 0));
  81. }
  82. if (enable)
  83. while (!((*mdstat & 0x0000001F) == 0x3));
  84. else
  85. while (!((*mdstat & 0x0000001F) == 0x2));
  86. if (enable)
  87. davinci_psc_mux(id);
  88. }
  89. void __init davinci_psc_init(void)
  90. {
  91. davinci_psc_config(DAVINCI_GPSC_ARMDOMAIN, DAVINCI_LPSC_VPSSMSTR, 1);
  92. davinci_psc_config(DAVINCI_GPSC_ARMDOMAIN, DAVINCI_LPSC_VPSSSLV, 1);
  93. davinci_psc_config(DAVINCI_GPSC_ARMDOMAIN, DAVINCI_LPSC_TPCC, 1);
  94. davinci_psc_config(DAVINCI_GPSC_ARMDOMAIN, DAVINCI_LPSC_TPTC0, 1);
  95. davinci_psc_config(DAVINCI_GPSC_ARMDOMAIN, DAVINCI_LPSC_TPTC1, 1);
  96. davinci_psc_config(DAVINCI_GPSC_ARMDOMAIN, DAVINCI_LPSC_GPIO, 1);
  97. /* Turn on WatchDog timer LPSC. Needed for RESET to work */
  98. davinci_psc_config(DAVINCI_GPSC_ARMDOMAIN, DAVINCI_LPSC_TIMER2, 1);
  99. }