proc_comm.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /* arch/arm/mach-msm/proc_comm.c
  2. *
  3. * Copyright (C) 2007-2008 Google, Inc.
  4. * Author: Brian Swetland <swetland@google.com>
  5. *
  6. * This software is licensed under the terms of the GNU General Public
  7. * License version 2, as published by the Free Software Foundation, and
  8. * may be copied, distributed, and modified under those terms.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. */
  16. #include <linux/delay.h>
  17. #include <linux/errno.h>
  18. #include <linux/io.h>
  19. #include <linux/spinlock.h>
  20. #include <mach/msm_iomap.h>
  21. #include <mach/system.h>
  22. #include "proc_comm.h"
  23. static inline void msm_a2m_int(uint32_t irq)
  24. {
  25. #if defined(CONFIG_ARCH_MSM7X30)
  26. writel(1 << irq, MSM_GCC_BASE + 0x8);
  27. #else
  28. writel(1, MSM_CSR_BASE + 0x400 + (irq * 4));
  29. #endif
  30. }
  31. static inline void notify_other_proc_comm(void)
  32. {
  33. msm_a2m_int(6);
  34. }
  35. #define APP_COMMAND 0x00
  36. #define APP_STATUS 0x04
  37. #define APP_DATA1 0x08
  38. #define APP_DATA2 0x0C
  39. #define MDM_COMMAND 0x10
  40. #define MDM_STATUS 0x14
  41. #define MDM_DATA1 0x18
  42. #define MDM_DATA2 0x1C
  43. static DEFINE_SPINLOCK(proc_comm_lock);
  44. /* The higher level SMD support will install this to
  45. * provide a way to check for and handle modem restart.
  46. */
  47. int (*msm_check_for_modem_crash)(void);
  48. /* Poll for a state change, checking for possible
  49. * modem crashes along the way (so we don't wait
  50. * forever while the ARM9 is blowing up).
  51. *
  52. * Return an error in the event of a modem crash and
  53. * restart so the msm_proc_comm() routine can restart
  54. * the operation from the beginning.
  55. */
  56. static int proc_comm_wait_for(void __iomem *addr, unsigned value)
  57. {
  58. for (;;) {
  59. if (readl(addr) == value)
  60. return 0;
  61. if (msm_check_for_modem_crash)
  62. if (msm_check_for_modem_crash())
  63. return -EAGAIN;
  64. }
  65. }
  66. int msm_proc_comm(unsigned cmd, unsigned *data1, unsigned *data2)
  67. {
  68. void __iomem *base = MSM_SHARED_RAM_BASE;
  69. unsigned long flags;
  70. int ret;
  71. spin_lock_irqsave(&proc_comm_lock, flags);
  72. for (;;) {
  73. if (proc_comm_wait_for(base + MDM_STATUS, PCOM_READY))
  74. continue;
  75. writel(cmd, base + APP_COMMAND);
  76. writel(data1 ? *data1 : 0, base + APP_DATA1);
  77. writel(data2 ? *data2 : 0, base + APP_DATA2);
  78. notify_other_proc_comm();
  79. if (proc_comm_wait_for(base + APP_COMMAND, PCOM_CMD_DONE))
  80. continue;
  81. if (readl(base + APP_STATUS) != PCOM_CMD_FAIL) {
  82. if (data1)
  83. *data1 = readl(base + APP_DATA1);
  84. if (data2)
  85. *data2 = readl(base + APP_DATA2);
  86. ret = 0;
  87. } else {
  88. ret = -EIO;
  89. }
  90. break;
  91. }
  92. writel(PCOM_CMD_IDLE, base + APP_COMMAND);
  93. spin_unlock_irqrestore(&proc_comm_lock, flags);
  94. return ret;
  95. }
  96. /*
  97. * We need to wait for the ARM9 to at least partially boot
  98. * up before we can continue. Since the ARM9 does resource
  99. * allocation, if we dont' wait we could end up crashing or in
  100. * and unknown state. This function should be called early to
  101. * wait on the ARM9.
  102. */
  103. void __init proc_comm_boot_wait(void)
  104. {
  105. void __iomem *base = MSM_SHARED_RAM_BASE;
  106. proc_comm_wait_for(base + MDM_STATUS, PCOM_READY);
  107. }