/** @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 #include #include #include #include #include #include #include #include #include #include #include #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