proc_comm.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 "proc_comm.h"
  22. static inline void msm_a2m_int(uint32_t irq)
  23. {
  24. #if defined(CONFIG_ARCH_MSM7X30)
  25. writel(1 << irq, MSM_GCC_BASE + 0x8);
  26. #else
  27. writel(1, MSM_CSR_BASE + 0x400 + (irq * 4));
  28. #endif
  29. }
  30. static inline void notify_other_proc_comm(void)
  31. {
  32. msm_a2m_int(6);
  33. }
  34. #define APP_COMMAND 0x00
  35. #define APP_STATUS 0x04
  36. #define APP_DATA1 0x08
  37. #define APP_DATA2 0x0C
  38. #define MDM_COMMAND 0x10
  39. #define MDM_STATUS 0x14
  40. #define MDM_DATA1 0x18
  41. #define MDM_DATA2 0x1C
  42. static DEFINE_SPINLOCK(proc_comm_lock);
  43. /* The higher level SMD support will install this to
  44. * provide a way to check for and handle modem restart.
  45. */
  46. int (*msm_check_for_modem_crash)(void);
  47. /* Poll for a state change, checking for possible
  48. * modem crashes along the way (so we don't wait
  49. * forever while the ARM9 is blowing up).
  50. *
  51. * Return an error in the event of a modem crash and
  52. * restart so the msm_proc_comm() routine can restart
  53. * the operation from the beginning.
  54. */
  55. static int proc_comm_wait_for(void __iomem *addr, unsigned value)
  56. {
  57. for (;;) {
  58. if (readl(addr) == value)
  59. return 0;
  60. if (msm_check_for_modem_crash)
  61. if (msm_check_for_modem_crash())
  62. return -EAGAIN;
  63. }
  64. }
  65. int msm_proc_comm(unsigned cmd, unsigned *data1, unsigned *data2)
  66. {
  67. void __iomem *base = MSM_SHARED_RAM_BASE;
  68. unsigned long flags;
  69. int ret;
  70. spin_lock_irqsave(&proc_comm_lock, flags);
  71. for (;;) {
  72. if (proc_comm_wait_for(base + MDM_STATUS, PCOM_READY))
  73. continue;
  74. writel(cmd, base + APP_COMMAND);
  75. writel(data1 ? *data1 : 0, base + APP_DATA1);
  76. writel(data2 ? *data2 : 0, base + APP_DATA2);
  77. notify_other_proc_comm();
  78. if (proc_comm_wait_for(base + APP_COMMAND, PCOM_CMD_DONE))
  79. continue;
  80. if (readl(base + APP_STATUS) != PCOM_CMD_FAIL) {
  81. if (data1)
  82. *data1 = readl(base + APP_DATA1);
  83. if (data2)
  84. *data2 = readl(base + APP_DATA2);
  85. ret = 0;
  86. } else {
  87. ret = -EIO;
  88. }
  89. break;
  90. }
  91. writel(PCOM_CMD_IDLE, base + APP_COMMAND);
  92. spin_unlock_irqrestore(&proc_comm_lock, flags);
  93. return ret;
  94. }
  95. /*
  96. * We need to wait for the ARM9 to at least partially boot
  97. * up before we can continue. Since the ARM9 does resource
  98. * allocation, if we dont' wait we could end up crashing or in
  99. * and unknown state. This function should be called early to
  100. * wait on the ARM9.
  101. */
  102. void proc_comm_boot_wait(void)
  103. {
  104. void __iomem *base = MSM_SHARED_RAM_BASE;
  105. proc_comm_wait_for(base + MDM_STATUS, PCOM_READY);
  106. }