psc.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 <linux/io.h>
  25. #include <mach/cputype.h>
  26. #include <mach/hardware.h>
  27. #include <mach/psc.h>
  28. #include <mach/mux.h>
  29. /* PSC register offsets */
  30. #define EPCPR 0x070
  31. #define PTCMD 0x120
  32. #define PTSTAT 0x128
  33. #define PDSTAT 0x200
  34. #define PDCTL1 0x304
  35. #define MDSTAT 0x800
  36. #define MDCTL 0xA00
  37. #define MDSTAT_STATE_MASK 0x1f
  38. /* Return nonzero iff the domain's clock is active */
  39. int __init davinci_psc_is_clk_active(unsigned int ctlr, unsigned int id)
  40. {
  41. void __iomem *psc_base;
  42. u32 mdstat;
  43. struct davinci_soc_info *soc_info = &davinci_soc_info;
  44. if (!soc_info->psc_bases || (ctlr >= soc_info->psc_bases_num)) {
  45. pr_warning("PSC: Bad psc data: 0x%x[%d]\n",
  46. (int)soc_info->psc_bases, ctlr);
  47. return 0;
  48. }
  49. psc_base = soc_info->psc_bases[ctlr];
  50. mdstat = __raw_readl(psc_base + MDSTAT + 4 * id);
  51. /* if clocked, state can be "Enable" or "SyncReset" */
  52. return mdstat & BIT(12);
  53. }
  54. /* Enable or disable a PSC domain */
  55. void davinci_psc_config(unsigned int domain, unsigned int ctlr,
  56. unsigned int id, char enable)
  57. {
  58. u32 epcpr, ptcmd, ptstat, pdstat, pdctl1, mdstat, mdctl;
  59. void __iomem *psc_base;
  60. struct davinci_soc_info *soc_info = &davinci_soc_info;
  61. u32 next_state = enable ? 0x3 : 0x2; /* 0x3 enables, 0x2 disables */
  62. if (!soc_info->psc_bases || (ctlr >= soc_info->psc_bases_num)) {
  63. pr_warning("PSC: Bad psc data: 0x%x[%d]\n",
  64. (int)soc_info->psc_bases, ctlr);
  65. return;
  66. }
  67. psc_base = soc_info->psc_bases[ctlr];
  68. mdctl = __raw_readl(psc_base + MDCTL + 4 * id);
  69. mdctl &= ~MDSTAT_STATE_MASK;
  70. mdctl |= next_state;
  71. __raw_writel(mdctl, psc_base + MDCTL + 4 * id);
  72. pdstat = __raw_readl(psc_base + PDSTAT);
  73. if ((pdstat & 0x00000001) == 0) {
  74. pdctl1 = __raw_readl(psc_base + PDCTL1);
  75. pdctl1 |= 0x1;
  76. __raw_writel(pdctl1, psc_base + PDCTL1);
  77. ptcmd = 1 << domain;
  78. __raw_writel(ptcmd, psc_base + PTCMD);
  79. do {
  80. epcpr = __raw_readl(psc_base + EPCPR);
  81. } while ((((epcpr >> domain) & 1) == 0));
  82. pdctl1 = __raw_readl(psc_base + PDCTL1);
  83. pdctl1 |= 0x100;
  84. __raw_writel(pdctl1, psc_base + PDCTL1);
  85. do {
  86. ptstat = __raw_readl(psc_base +
  87. PTSTAT);
  88. } while (!(((ptstat >> domain) & 1) == 0));
  89. } else {
  90. ptcmd = 1 << domain;
  91. __raw_writel(ptcmd, psc_base + PTCMD);
  92. do {
  93. ptstat = __raw_readl(psc_base + PTSTAT);
  94. } while (!(((ptstat >> domain) & 1) == 0));
  95. }
  96. do {
  97. mdstat = __raw_readl(psc_base + MDSTAT + 4 * id);
  98. } while (!((mdstat & MDSTAT_STATE_MASK) == next_state));
  99. }