1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
|
/**
@file link_device_memory_command.c
@brief common functions for all types of memory interface media
@date 2014/02/18
@author Hankook Jang (hankook.jang@samsung.com)
*/
/*
* Copyright (C) 2011 Samsung Electronics.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#include <linux/irq.h>
#include <linux/gpio.h>
#include <linux/interrupt.h>
#include <linux/platform_device.h>
#include <linux/time.h>
#include <linux/timer.h>
#include <linux/delay.h>
#include <linux/wait.h>
#include <linux/sched.h>
#include <linux/wakelock.h>
#include <linux/vmalloc.h>
#include <linux/netdevice.h>
#include "modem_prj.h"
#include "modem_utils.h"
#include "link_device_memory.h"
#ifdef GROUP_MEM_LINK_COMMAND
/**
@weakgroup group_mem_link_command
@{
*/
/**
* iosm wrapper functions called from mem_init_comm function
*/
void __tx_iosm_message(struct mem_link_device *mld, u8 id)
{
send_ipc_irq(mld, cmd2int(id));
}
void tx_iosm_message(struct mem_link_device *mld, u8 id, u32 *args) {}
static bool rild_ready(struct link_device *ld)
{
struct io_device *fmt_iod;
struct io_device *rfs_iod;
int fmt_opened;
int rfs_opened;
fmt_iod = link_get_iod_with_channel(ld, SIPC5_CH_ID_FMT_0);
if (!fmt_iod) {
mif_err("%s: No FMT io_device\n", ld->name);
return false;
}
rfs_iod = link_get_iod_with_channel(ld, SIPC5_CH_ID_RFS_0);
if (!rfs_iod) {
mif_err("%s: No RFS io_device\n", ld->name);
return false;
}
fmt_opened = atomic_read(&fmt_iod->opened);
rfs_opened = atomic_read(&rfs_iod->opened);
mif_err("%s: %s.opened=%d, %s.opened=%d\n", ld->name,
fmt_iod->name, fmt_opened, rfs_iod->name, rfs_opened);
if (fmt_opened > 0 && rfs_opened > 0)
return true;
return false;
}
#ifdef CONFIG_LINK_DEVICE_WITH_SBD_ARCH
static void cmd_init_start_handler(struct mem_link_device *mld)
{
struct link_device *ld = &mld->link_dev;
struct modem_ctl *mc = ld->mc;
int err;
mif_err("%s: INIT_START <- %s (%s.state:%s cp_boot_done:%d)\n",
ld->name, mc->name, mc->name, mc_state(mc),
atomic_read(&mld->cp_boot_done));
if (!ld->sbd_ipc) {
mif_err("%s: LINK_ATTR_SBD_IPC is NOT set\n", ld->name);
return;
}
err = init_sbd_link(&mld->sbd_link_dev);
if (err < 0) {
mif_err("%s: init_sbd_link fail(%d)\n", ld->name, err);
return;
}
if (mld->attrs & LINK_ATTR(LINK_ATTR_IPC_ALIGNED))
ld->aligned = true;
else
ld->aligned = false;
sbd_activate(&mld->sbd_link_dev);
mif_err("%s: PIF_INIT_DONE -> %s\n", ld->name, mc->name);
send_ipc_irq(mld, cmd2int(CMD_PIF_INIT_DONE));
}
#endif
static void cmd_phone_start_handler(struct mem_link_device *mld)
{
struct link_device *ld = &mld->link_dev;
struct modem_ctl *mc = ld->mc;
unsigned long flags;
int err;
mif_err("%s: CP_START <- %s (%s.state:%s cp_boot_done:%d)\n",
ld->name, mc->name, mc->name, mc_state(mc),
atomic_read(&mld->cp_boot_done));
#ifdef CONFIG_LINK_POWER_MANAGEMENT
if (mld->start_pm)
mld->start_pm(mld);
#endif
spin_lock_irqsave(&ld->lock, flags);
if (ld->state == LINK_STATE_IPC) {
/*
If there is no INIT_END command from AP, CP sends a CP_START
command to AP periodically until it receives INIT_END from AP
even though it has already been in ONLINE state.
*/
if (rild_ready(ld)) {
mif_err("%s: INIT_END -> %s\n", ld->name, mc->name);
send_ipc_irq(mld, cmd2int(CMD_INIT_END));
}
goto exit;
}
err = mem_reset_ipc_link(mld);
if (err) {
mif_err("%s: mem_reset_ipc_link fail(%d)\n", ld->name, err);
goto exit;
}
if (rild_ready(ld)) {
mif_err("%s: INIT_END -> %s\n", ld->name, mc->name);
send_ipc_irq(mld, cmd2int(CMD_INIT_END));
atomic_set(&mld->cp_boot_done, 1);
}
ld->state = LINK_STATE_IPC;
complete_all(&mc->init_cmpl);
exit:
spin_unlock_irqrestore(&ld->lock, flags);
}
static void cmd_crash_reset_handler(struct mem_link_device *mld)
{
struct link_device *ld = &mld->link_dev;
struct modem_ctl *mc = ld->mc;
unsigned long flags;
spin_lock_irqsave(&ld->lock, flags);
ld->state = LINK_STATE_OFFLINE;
spin_unlock_irqrestore(&ld->lock, flags);
mif_err("%s<-%s: ERR! CP_CRASH_RESET\n", ld->name, mc->name);
modemctl_notify_event(MDM_CRASH_CMD_RESET);
}
static void cmd_crash_exit_handler(struct mem_link_device *mld)
{
struct link_device *ld = &mld->link_dev;
struct modem_ctl *mc = ld->mc;
unsigned long flags;
spin_lock_irqsave(&ld->lock, flags);
ld->state = LINK_STATE_CP_CRASH;
spin_unlock_irqrestore(&ld->lock, flags);
if (timer_pending(&mc->crash_ack_timer))
del_timer(&mc->crash_ack_timer);
mif_err("%s<-%s: ERR! CP_CRASH_EXIT\n", ld->name, mc->name);
modemctl_notify_event(MDM_CRASH_CMD_EXIT);
}
/**
@brief process a MEMORY command from CP
@param mld the pointer to a mem_link_device instance
@param cmd the MEMORY command from CP
*/
void mem_cmd_handler(struct mem_link_device *mld, u16 cmd)
{
struct link_device *ld = &mld->link_dev;
switch (cmd) {
#ifdef CONFIG_LINK_DEVICE_WITH_SBD_ARCH
case CMD_INIT_START:
cmd_init_start_handler(mld);
break;
#endif
case CMD_PHONE_START:
cmd_phone_start_handler(mld);
break;
case CMD_CRASH_RESET:
cmd_crash_reset_handler(mld);
break;
case CMD_CRASH_EXIT:
cmd_crash_exit_handler(mld);
break;
default:
mif_err("%s: Unknown command 0x%04X\n", ld->name, cmd);
break;
}
}
/**
@}
*/
#endif
|