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