proc_comm.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. #define MSM_A2M_INT(n) (MSM_CSR_BASE + 0x400 + (n) * 4)
  24. static inline void notify_other_proc_comm(void)
  25. {
  26. writel(1, MSM_A2M_INT(6));
  27. }
  28. #define APP_COMMAND 0x00
  29. #define APP_STATUS 0x04
  30. #define APP_DATA1 0x08
  31. #define APP_DATA2 0x0C
  32. #define MDM_COMMAND 0x10
  33. #define MDM_STATUS 0x14
  34. #define MDM_DATA1 0x18
  35. #define MDM_DATA2 0x1C
  36. static DEFINE_SPINLOCK(proc_comm_lock);
  37. /* The higher level SMD support will install this to
  38. * provide a way to check for and handle modem restart.
  39. */
  40. int (*msm_check_for_modem_crash)(void);
  41. /* Poll for a state change, checking for possible
  42. * modem crashes along the way (so we don't wait
  43. * forever while the ARM9 is blowing up).
  44. *
  45. * Return an error in the event of a modem crash and
  46. * restart so the msm_proc_comm() routine can restart
  47. * the operation from the beginning.
  48. */
  49. static int proc_comm_wait_for(void __iomem *addr, unsigned value)
  50. {
  51. for (;;) {
  52. if (readl(addr) == value)
  53. return 0;
  54. if (msm_check_for_modem_crash)
  55. if (msm_check_for_modem_crash())
  56. return -EAGAIN;
  57. }
  58. }
  59. int msm_proc_comm(unsigned cmd, unsigned *data1, unsigned *data2)
  60. {
  61. void __iomem *base = MSM_SHARED_RAM_BASE;
  62. unsigned long flags;
  63. int ret;
  64. spin_lock_irqsave(&proc_comm_lock, flags);
  65. for (;;) {
  66. if (proc_comm_wait_for(base + MDM_STATUS, PCOM_READY))
  67. continue;
  68. writel(cmd, base + APP_COMMAND);
  69. writel(data1 ? *data1 : 0, base + APP_DATA1);
  70. writel(data2 ? *data2 : 0, base + APP_DATA2);
  71. notify_other_proc_comm();
  72. if (proc_comm_wait_for(base + APP_COMMAND, PCOM_CMD_DONE))
  73. continue;
  74. if (readl(base + APP_STATUS) != PCOM_CMD_FAIL) {
  75. if (data1)
  76. *data1 = readl(base + APP_DATA1);
  77. if (data2)
  78. *data2 = readl(base + APP_DATA2);
  79. ret = 0;
  80. } else {
  81. ret = -EIO;
  82. }
  83. break;
  84. }
  85. writel(PCOM_CMD_IDLE, base + APP_COMMAND);
  86. spin_unlock_irqrestore(&proc_comm_lock, flags);
  87. return ret;
  88. }