fm_s32 fm_fifo_release(struct fm_fifo *fifo) { if (fifo) { WCN_DBG(FM_NTC | LINK, "%s released\n", fifo->obj.name); if (fifo->obj.priv) fm_free(fifo->obj.priv); fm_free(fifo); } return 0; }
fm_s32 fm_link_setup(void *data) { fm_s32 ret = 0; if (!(link_event = fm_zalloc(sizeof(struct fm_link_event)))) { WCN_DBG(FM_ALT | LINK, "fm_zalloc(fm_link_event) -ENOMEM\n"); return -1; } link_event->ln_event = fm_flag_event_create("ln_evt"); if (!link_event->ln_event) { WCN_DBG(FM_ALT | LINK, "create mt6620_ln_event failed\n"); fm_free(link_event); return -1; } fm_flag_event_get(link_event->ln_event); WCN_DBG(FM_NTC | LINK, "fm link setup\n"); cmd_fifo = fm_trace_fifo_create("cmd_fifo"); if (!cmd_fifo) { WCN_DBG(FM_ALT | LINK, "create cmd_fifo failed\n"); ret = -1; goto failed; } evt_fifo = fm_trace_fifo_create("evt_fifo"); if (!evt_fifo) { WCN_DBG(FM_ALT | LINK, "create evt_fifo failed\n"); ret = -1; goto failed; } reset = data; /* get whole chip reset cb */ mtk_wcn_wmt_msgcb_reg(WMTDRV_TYPE_FM, WCNfm_wholechip_rst_cb); return 0; failed: fm_trace_fifo_release(evt_fifo); fm_trace_fifo_release(cmd_fifo); fm_flag_event_put(link_event->ln_event); if (link_event) { fm_free(link_event); } return ret; }
fm_s32 fm_work_put(struct fm_work *thiz) { FMR_ASSERT(thiz); thiz->ref--; if (thiz->ref == 0) { fm_free(thiz->priv); fm_free(thiz); return 0; } else if (thiz->ref > 0) { return -FM_EINUSE; } else { return -FM_EPARA; } }
struct fm_timer *fm_timer_create(const fm_s8 *name) { struct fm_timer *tmp; struct timer_list *timerlist; tmp = fm_zalloc(sizeof(struct fm_timer)); if (!tmp) { WCN_DBG(FM_ALT | MAIN, "fm_zalloc(fm_timer) -ENOMEM\n"); return NULL; } timerlist = fm_zalloc(sizeof(struct timer_list)); if (!timerlist) { WCN_DBG(FM_ALT | MAIN, "fm_zalloc(struct timer_list) -ENOMEM\n"); fm_free(tmp); return NULL; } init_timer(timerlist); fm_memcpy(tmp->name, name, (strlen(name) > FM_NAME_MAX) ? (FM_NAME_MAX) : (strlen(name))); tmp->priv = timerlist; tmp->ref = 0; tmp->init = fm_timer_init; tmp->start = fm_timer_start; tmp->stop = fm_timer_stop; tmp->update = fm_timer_update; tmp->control = fm_timer_control; return tmp; }
struct fm_lock *fm_spin_lock_create(const fm_s8 *name) { struct fm_lock *tmp; spinlock_t *spin_lock; tmp = fm_zalloc(sizeof(struct fm_lock)); if (!tmp) { WCN_DBG(FM_ALT | MAIN, "fm_zalloc(fm_lock) -ENOMEM\n"); return NULL; } spin_lock = fm_zalloc(sizeof(spinlock_t)); if (!spin_lock) { WCN_DBG(FM_ALT | MAIN, "fm_zalloc(spinlock_t) -ENOMEM\n"); fm_free(tmp); return NULL; } tmp->priv = spin_lock; spin_lock_init(spin_lock); tmp->ref = 0; fm_memcpy(tmp->name, name, (strlen(name) > FM_NAME_MAX) ? (FM_NAME_MAX) : (strlen(name))); tmp->lock = fm_spin_lock_lock; tmp->unlock = fm_spin_lock_unlock; return tmp; }
struct fm_lock *fm_lock_create(const fm_s8 *name) { struct fm_lock *tmp; struct semaphore *mutex; tmp = fm_zalloc(sizeof(struct fm_lock)); if (!tmp) { WCN_DBG(FM_ALT | MAIN, "fm_zalloc(fm_lock) -ENOMEM\n"); return NULL; } mutex = fm_zalloc(sizeof(struct semaphore)); if (!mutex) { WCN_DBG(FM_ALT | MAIN, "fm_zalloc(struct semaphore) -ENOMEM\n"); fm_free(tmp); return NULL; } tmp->priv = mutex; sema_init(mutex, 1); tmp->ref = 0; fm_memcpy(tmp->name, name, (strlen(name) > FM_NAME_MAX) ? (FM_NAME_MAX) : (strlen(name))); tmp->lock = fm_lock_lock; tmp->trylock = fm_lock_try; tmp->unlock = fm_lock_unlock; return tmp; }
/* delete mutex */ void fm_mutex_delete(fm_mutex_t *target){ /* delete from mutex queue */ if(target == NULL || *target == NULL){ return; } fm_uint32_t level = _fm_interrupt_disable_(); _remove_system_mutex_list(&(fm_mutex_que), *target); /* free thread */ fm_tcb *ptr = (*target)->mutex.wait_queue.head; /* disable schedule */ disable_schedule(); while(ptr != NULL){ fm_thread_resume(&ptr); ptr = ptr->sem_next_thread; } enable_schedule(); /* free resource */ (*target)->next = (*target)->prev = NULL; fm_free(*target); *target = NULL; _fm_interrupt_enable_(level); if(need_schedule){ fm_thread_schedule(); } }
static fm_s32 MT6628fm_cust_config_file(const fm_s8 *filename, fm_cust_cfg *cfg) { fm_s32 ret = 0; fm_s8 *buf = NULL; fm_s32 file_len = 0; if (!(buf = fm_zalloc(4096))) { WCN_DBG(FM_ALT | MAIN, "-ENOMEM\n"); return -ENOMEM; } // fm_index = 0; file_len = fm_file_read(filename, buf, 4096, 0); if (file_len <= 0) { ret = -1; goto out; } ret = cfg_parser(buf, MT6628cfg_item_handler, cfg); out: if (buf) { fm_free(buf); } return ret; }
struct fm_flag_event *fm_flag_event_create(const fm_s8 *name) { struct fm_flag_event *tmp; wait_queue_head_t *wq; tmp = fm_zalloc(sizeof(struct fm_flag_event)); if (!tmp) { WCN_DBG(FM_ALT | MAIN, "fm_zalloc(fm_event) -ENOMEM\n"); return NULL; } wq = fm_zalloc(sizeof(wait_queue_head_t)); if (!wq) { WCN_DBG(FM_ALT | MAIN, "fm_zalloc(wait_queue_head_t) -ENOMEM\n"); fm_free(tmp); return NULL; } fm_memcpy(tmp->name, name, (strlen(name) > FM_NAME_MAX) ? (FM_NAME_MAX) : (strlen(name))); tmp->priv = wq; init_waitqueue_head(wq); tmp->ref = 0; tmp->send = fm_event_send; tmp->wait = fm_event_wait; tmp->wait_timeout = fm_event_wait_timeout; tmp->clr = fm_event_clr; tmp->get = fm_event_get; tmp->rst = fm_event_rst; tmp->rst(tmp); /* set flag to 0x00000000 */ return tmp; }
fm_s32 fm_trace_fifo_release(struct fm_trace_fifo_t *fifo) { if (fifo) { WCN_DBG(FM_NTC | LINK, "%s released\n", fifo->name); fm_free(fifo); } return 0; }
fm_s32 fm_link_release(void) { fm_flag_event_put(link_event->ln_event); if (link_event) { fm_free(link_event); } WCN_DBG(FM_NTC | LINK, "fm link release\n"); i2c_del_driver(&MT6626_driver); return 0; }
fm_s32 fm_link_release(void) { fm_trace_fifo_release(evt_fifo); fm_trace_fifo_release(cmd_fifo); fm_flag_event_put(link_event->ln_event); if (link_event) { fm_free(link_event); } WCN_DBG(FM_NTC | LINK, "fm link release\n"); return 0; }
fm_s32 fm_workthread_put(struct fm_workthread *thiz) { FMR_ASSERT(thiz); thiz->ref--; if (thiz->ref == 0) { destroy_workqueue((struct workqueue_struct *)thiz->priv); fm_free(thiz); return 0; } else if (thiz->ref > 0) { return -FM_EINUSE; } else { return -FM_EPARA; } }
fm_s32 fm_link_setup(void* data) { if (!(link_event = kzalloc(sizeof(struct fm_link_event), GFP_KERNEL))) { WCN_DBG(FM_ALT | LINK, "kzalloc(fm_link_event) -ENOMEM\n"); return -1; } link_event->ln_event = fm_flag_event_create("ln_evt"); if (!link_event->ln_event) { WCN_DBG(FM_ALT | LINK, "create mt6626_ln_event failed\n"); fm_free(link_event); return -1; } fm_flag_event_get(link_event->ln_event); WCN_DBG(FM_NTC | LINK, "fm link setup\n"); return i2c_add_driver(&MT6626_driver); }
struct fm_work* fm_work_create(const fm_s8 *name) { struct fm_work *my_work; struct work_struct *sys_work; if (!(my_work = fm_zalloc(sizeof(struct fm_work)))) { WCN_DBG(FM_ALT | MAIN, "fm_zalloc(fm_work) -ENOMEM\n"); return NULL; } if (!(sys_work = fm_zalloc(sizeof(struct work_struct)))) { WCN_DBG(FM_ALT | MAIN, "fm_zalloc(struct work_struct) -ENOMEM\n"); fm_free(my_work); return NULL; } fm_memcpy(my_work->name, name, (strlen(name)>FM_NAME_MAX)?(FM_NAME_MAX):(strlen(name))); my_work->priv = sys_work; my_work->init = fm_work_init; return my_work; }
struct fm_fifo* fm_fifo_create(const fm_s8 *name, fm_s32 item_size, fm_s32 item_num) { struct fm_fifo *tmp; void *buf; if (!(tmp = fm_zalloc(sizeof(struct fm_fifo)))) { WCN_DBG(FM_ALT | MAIN, "fm_zalloc(fm_fifo) -ENOMEM\n"); return NULL; } if (!(buf = fm_zalloc(item_size * item_num))) { WCN_DBG(FM_ALT | MAIN, "fm_zalloc(fm_fifo) -ENOMEM\n"); fm_free(tmp); return NULL; } tmp = fm_fifo_init(tmp, buf, name, item_size, item_num); WCN_DBG(FM_NTC | LINK, "%s created\n", tmp->obj.name); return tmp; }
int parameter_editor(FORMPTR fmp) { DFORMPTR dfmp; char *save_ptr; /*------ temporarily modify validation message table ------*/ save_ptr = _vv_valmsg[15]; _vv_valmsg[15] = "Field may not be edited - Press <F2> for choice list."; latt_rpl(LWAIT,LREVERSE|BLINK,RED|BLINK,BLUE,LATT_SYS); /*------ add hot-keys to form event table ------*/ et_rplevnt(KEY_CD,(EVENTFP)restore_defaults,FMETP); et_rplevnt(KEY_CS,(EVENTFP)save_defaults, FMETP); /*------ define memory file and read choice list text ------*/ clist_mfp = mf_def(60,40); mf_rd("CLIST.TXT",clist_mfp); /*------ create and process the parameters form ------*/ dfmp = create_parameters_form(); fm_proc(0,dfmp); fm_free(dfmp); mf_free(clist_mfp); /*------ restore form event table ------*/ et_rplevnt(KEY_CD,NULLFP,FMETP); et_rplevnt(KEY_CS,NULLFP,FMETP); /*------ restore validation message table ------*/ _vv_valmsg[15] = save_ptr; return(SAMELEVEL); } /* parameter_editor() */
static long fm_ops_ioctl(struct file *filp, fm_u32 cmd, unsigned long arg) { fm_s32 ret = 0; struct fm_platform *plat = container_of(filp->f_dentry->d_inode->i_cdev, struct fm_platform, cdev); struct fm *fm = container_of(plat, struct fm, platform); WCN_DBG(FM_NTC | MAIN, "%s---pid(%d)---cmd(0x%08x)---arg(0x%08x)\n", current->comm, current->pid, cmd, (fm_u32)arg); if (fm_sys_state_get(fm) != FM_SUBSYS_RST_OFF) { WCN_DBG(FM_ALT | MAIN, "FM subsys is resetting, retry later\n"); ret = -FM_ESRST; return ret; } switch (cmd) { case FM_IOCTL_POWERUP: { struct fm_tune_parm parm; WCN_DBG(FM_NTC | MAIN, "FM_IOCTL_POWERUP:0\n"); if (copy_from_user(&parm, (void*)arg, sizeof(struct fm_tune_parm))) { ret = -EFAULT; goto out; } ret = fm_powerup(fm, &parm); if (ret < 0) goto out; ret = fm_tune(fm, &parm); if (ret < 0) goto out; if (copy_to_user((void*)arg, &parm, sizeof(struct fm_tune_parm))) { ret = -EFAULT; goto out; } WCN_DBG(FM_NTC | MAIN, "FM_IOCTL_POWERUP:1\n"); break; } case FM_IOCTL_POWERDOWN: { WCN_DBG(FM_NTC | MAIN, "FM_IOCTL_POWERDOWN:0\n"); ret = fm_powerdown(fm); WCN_DBG(FM_NTC | MAIN, "FM_IOCTL_POWERDOWN:1\n"); break; } case FM_IOCTL_TUNE: { struct fm_tune_parm parm; WCN_DBG(FM_NTC | MAIN, "FM_IOCTL_TUNE:0\n"); if (copy_from_user(&parm, (void*)arg, sizeof(struct fm_tune_parm))) { ret = -EFAULT; goto out; } ret = fm_tune(fm, &parm); if (ret < 0) { goto out; } if (copy_to_user((void*)arg, &parm, sizeof(struct fm_tune_parm))) { ret = -EFAULT; goto out; } WCN_DBG(FM_NTC | MAIN, "FM_IOCTL_TUNE:1\n"); break; } case FM_IOCTL_SOFT_MUTE_TUNE: { struct fm_softmute_tune_t parm; fm_cqi_log();//cqi log tool WCN_DBG(FM_NTC | MAIN,"......FM_IOCTL_SOFT_MUTE_TUNE......\n"); if(copy_from_user(&parm, (void*)arg, sizeof(struct fm_softmute_tune_t))) { ret = -EFAULT; goto out; } ret = fm_soft_mute_tune(fm, &parm); if (ret < 0) { goto out; } if(copy_to_user((void*)arg, &parm, sizeof(struct fm_softmute_tune_t))) { ret = -EFAULT; goto out; } break; } case FM_IOCTL_SEEK: { struct fm_seek_parm parm; WCN_DBG(FM_NTC | MAIN, "FM_IOCTL_SEEK:0\n"); if (copy_from_user(&parm, (void*)arg, sizeof(struct fm_seek_parm))) { ret = -EFAULT; goto out; } ret = fm_seek(fm, &parm); if (ret < 0) { goto out; } if (copy_to_user((void*)arg, &parm, sizeof(struct fm_seek_parm))) { ret = -EFAULT; goto out; } WCN_DBG(FM_NTC | MAIN, "FM_IOCTL_SEEK:1\n"); break; } case FM_IOCTL_SCAN: { struct fm_scan_parm parm; WCN_DBG(FM_NTC | MAIN, "FM_IOCTL_SCAN start\n"); if (copy_from_user(&parm, (void*)arg, sizeof(struct fm_scan_parm))) { WCN_DBG(FM_ALT | MAIN, "copy_from_user failed\n"); ret = -EFAULT; goto out; } ret = fm_scan(fm, &parm); if (ret < 0) goto out; if (copy_to_user((void*)arg, &parm, sizeof(struct fm_scan_parm))) { ret = -EFAULT; goto out; } WCN_DBG(FM_NTC | MAIN, "FM_IOCTL_SCAN end\n"); break; } case FM_IOCTL_TUNE_NEW: { struct fm_tune_t tune_tmp; WCN_DBG(FM_NTC | MAIN, "FM_IOCTL_TUNE_NEW\n"); if (copy_from_user(&tune_tmp, (void*)arg, sizeof(struct fm_tune_t))) { WCN_DBG(FM_ERR | MAIN, "tune new copy_from_user error\n"); ret = -EFAULT; goto out; } ret = fm_tune_new(fm, &tune_tmp); if (ret < 0) { goto out; } if (copy_to_user((void*)arg, &tune_tmp, sizeof(struct fm_tune_t))) { WCN_DBG(FM_ERR | MAIN, "tune new copy_to_user error\n"); ret = -EFAULT; goto out; } break; } case FM_IOCTL_SEEK_NEW: { struct fm_seek_t seek_tmp; WCN_DBG(FM_NTC | MAIN, "FM_IOCTL_SEEK_NEW\n"); if (copy_from_user(&seek_tmp, (void*)arg, sizeof(struct fm_seek_t))) { WCN_DBG(FM_ERR | MAIN, "seek new copy_from_user error\n"); ret = -EFAULT; goto out; } ret = fm_seek_new(fm, &seek_tmp); if (ret < 0) { goto out; } if (copy_to_user((void*)arg, &seek_tmp, sizeof(struct fm_seek_t))) { WCN_DBG(FM_ERR | MAIN, "seek new copy_to_user error\n"); ret = -EFAULT; goto out; } break; } case FM_IOCTL_SCAN_NEW: { struct fm_scan_t tmp; WCN_DBG(FM_NTC | MAIN, "FM_IOCTL_SCAN_NEW\n"); if (copy_from_user(&tmp, (void*)arg, sizeof(struct fm_scan_t))) { WCN_DBG(FM_ERR | MAIN, "copy_from_user error\n"); ret = -EFAULT; goto out; } switch (tmp.cmd) { case FM_SCAN_CMD_START: if ((tmp.upper > 10800) || (tmp.lower < 7600) || (tmp.space < 5) || (tmp.space > 20)) { WCN_DBG(FM_ERR | MAIN, "scan para error\n"); ret = -EFAULT; goto out; } parm.cmd = tmp.cmd; parm.lower = tmp.lower; parm.upper = tmp.upper; parm.space = tmp.space; ret = fm_scan_new(fm, &parm); if (ret < 0) { goto out; } break; case FM_SCAN_CMD_GET_CH_RSSI: if (parm.sr_size && parm.sr.ch_rssi_buf) { if (copy_to_user(tmp.sr.ch_rssi_buf, parm.sr.ch_rssi_buf, parm.num * sizeof(struct fm_ch_rssi))) { WCN_DBG(FM_ERR | MAIN, "scan copy_to_user err\n"); ret = -EFAULT; goto out; } } break; default: break; } tmp.num = parm.num; if (copy_to_user((void*)arg, &tmp, sizeof(struct fm_scan_t))) { WCN_DBG(FM_ERR | MAIN, "copy_to_user error\n"); ret = -EFAULT; goto out; } break; } case FM_IOCTL_CQI_GET: { struct fm_cqi_req cqi_req; fm_s8 *buf = NULL; fm_s32 tmp; WCN_DBG(FM_DBG | MAIN, "FM_IOCTL_CQI_GET\n"); if (copy_from_user(&cqi_req, (void*)arg, sizeof(struct fm_cqi_req))) { WCN_DBG(FM_ALT | MAIN, "copy_from_user failed\n"); ret = -EFAULT; goto out; } if ((cqi_req.ch_num*sizeof(struct fm_cqi) > cqi_req.buf_size) || !cqi_req.cqi_buf) { ret = -FM_EPARA; goto out; } tmp = cqi_req.ch_num / 16 + ((cqi_req.ch_num % 16) ? 1 : 0); tmp = tmp * 16 * sizeof(struct fm_cqi); buf = fm_zalloc(tmp); if (!buf) { ret = -FM_ENOMEM; goto out; } ret = fm_cqi_get(fm, cqi_req.ch_num, buf, tmp); if (ret) { fm_free(buf); WCN_DBG(FM_ALT | MAIN, "get cqi failed\n"); goto out; } if (copy_to_user((void*)cqi_req.cqi_buf, buf, cqi_req.ch_num*sizeof(struct fm_cqi))) { fm_free(buf); ret = -EFAULT; goto out; } fm_free(buf); break; } case FM_IOCTL_GET_HW_INFO: { struct fm_hw_info info; WCN_DBG(FM_NTC | MAIN, "FM_IOCTL_GET_HW_INFO\n"); ret = fm_get_hw_info(fm, &info); if (ret) { WCN_DBG(FM_ALT | MAIN, "get hw info failed\n"); goto out; } if (copy_to_user((void*)arg, &info, sizeof(struct fm_hw_info))) { ret = -EFAULT; goto out; } break; } case FM_IOCTL_GET_I2S_INFO: { struct fm_i2s_info i2sinfo; WCN_DBG(FM_NTC | MAIN, "FM_IOCTL_GET_I2S_INFO\n"); ret = fm_get_i2s_info(fm, &i2sinfo); if (ret) { WCN_DBG(FM_ALT | MAIN, "get i2s info failed\n"); goto out; } if (copy_to_user((void*)arg, &i2sinfo, sizeof(struct fm_i2s_info))) { ret = -EFAULT; goto out; } break; } case FM_IOCTL_SETVOL: { fm_u32 vol; WCN_DBG(FM_NTC | MAIN, "FM_IOCTL_SETVOL start\n"); if (copy_from_user(&vol, (void*)arg, sizeof(fm_u32))) { WCN_DBG(FM_ALT | MAIN, "copy_from_user failed\n"); ret = -EFAULT; goto out; } ret = fm_setvol(fm, vol); WCN_DBG(FM_NTC | MAIN, "FM_IOCTL_SETVOL end:%d\n", vol); break; } case FM_IOCTL_GETVOL: { fm_u32 vol; WCN_DBG(FM_NTC | MAIN, "FM_IOCTL_GETVOL start\n"); ret = fm_getvol(fm, &vol); if (ret < 0) goto out; if (copy_to_user((void*)arg, &vol, sizeof(fm_u32))) { ret = -EFAULT; goto out; } WCN_DBG(FM_NTC | MAIN, "FM_IOCTL_GETVOL end=%d\n",vol); break; } case FM_IOCTL_MUTE: { fm_u32 bmute; WCN_DBG(FM_NTC| MAIN, "FM_IOCTL_MUTE start\n"); if (copy_from_user(&bmute, (void*)arg, sizeof(fm_u32))) { ret = -EFAULT; goto out; } ret = fm_mute(fm, bmute); WCN_DBG(FM_NTC| MAIN, "FM_IOCTL_MUTE end-%d\n", bmute); break; } case FM_IOCTL_GETRSSI: { fm_s32 rssi = 0; ret = fm_getrssi(fm, &rssi); if (ret < 0) goto out; if (copy_to_user((void*)arg, &rssi, sizeof(fm_s32))) { ret = -EFAULT; goto out; } WCN_DBG(FM_NTC | MAIN, "FM_IOCTL_GETRSSI:%d\n",rssi); break; } case FM_IOCTL_RW_REG: { struct fm_ctl_parm parm_ctl; WCN_DBG(FM_DBG | MAIN, "FM_IOCTL_RW_REG\n"); if (copy_from_user(&parm_ctl, (void*)arg, sizeof(struct fm_ctl_parm))) { ret = -EFAULT; goto out; } if (parm_ctl.rw_flag == 0) { ret = fm_reg_write(fm, parm_ctl.addr, parm_ctl.val); } else { ret = fm_reg_read(fm, parm_ctl.addr, &parm_ctl.val); } if (ret < 0) goto out; if ((parm_ctl.rw_flag == 0x01) && (!ret)) { if (copy_to_user((void*)arg, &parm_ctl, sizeof(struct fm_ctl_parm))) { ret = -EFAULT; goto out; } } break; } case FM_IOCTL_GETCHIPID: { fm_u16 chipid; ret = fm_chipid_get(fm, &chipid); WCN_DBG(FM_DBG | MAIN, "FM_IOCTL_GETCHIPID:%04x\n", chipid); if (ret < 0) goto out; if (copy_to_user((void*)arg, &chipid, sizeof(fm_u16))) { ret = -EFAULT; goto out; } break; } case FM_IOCTL_GETMONOSTERO: { fm_u16 usStereoMono; ret = fm_monostereo_get(fm, &usStereoMono); WCN_DBG(FM_DBG | MAIN, "FM_IOCTL_GETMONOSTERO:%04x\n", usStereoMono); if (ret < 0) goto out; if (copy_to_user((void*)arg, &usStereoMono, sizeof(fm_u16))) { ret = -EFAULT; goto out; } break; } case FM_IOCTL_SETMONOSTERO: { WCN_DBG(FM_DBG | MAIN, "FM_IOCTL_SETMONOSTERO, %d\n", (fm_s32)arg); ret = fm_monostereo_set(fm, (fm_s32)arg); break; } case FM_IOCTL_GETCURPAMD: { fm_u16 PamdLevl; ret = fm_pamd_get(fm, &PamdLevl); WCN_DBG(FM_DBG | MAIN, "FM_IOCTL_GETCURPAMD:%d\n", PamdLevl); if (ret < 0) goto out; if (copy_to_user((void*)arg, &PamdLevl, sizeof(fm_u16))) ret = -EFAULT; goto out; break; } case FM_IOCTL_GETCAPARRAY: { fm_s32 ca; ret = fm_caparray_get(fm, &ca); WCN_DBG(FM_DBG | MAIN, "FM_IOCTL_GETCAPARRAY:%d\n", ca); if (ret < 0) goto out; if (copy_to_user((void*)arg, &ca, sizeof(fm_s32))) { ret = -EFAULT; goto out; } break; } case FM_IOCTL_EM_TEST: { struct fm_em_parm parm_em; WCN_DBG(FM_DBG | MAIN, "FM_IOCTL_EM_TEST\n"); if (copy_from_user(&parm_em, (void*)arg, sizeof(struct fm_em_parm))) { ret = -EFAULT; goto out; } ret = fm_em_test(fm, parm_em.group_idx, parm_em.item_idx, parm_em.item_value); break; } case FM_IOCTL_RDS_SUPPORT: { fm_s32 support = FM_RDS_ENABLE; WCN_DBG(FM_NTC | MAIN, "FM_IOCTL_RDS_SUPPORT\n"); if (copy_to_user((void*)arg, &support, sizeof(fm_s32))) { ret = -EFAULT; goto out; } break; } case FM_IOCTL_IS_FM_POWERED_UP: { fm_u32 powerup; WCN_DBG(FM_DBG | MAIN, "FM_IOCTL_IS_FM_POWERED_UP"); if (fm->chipon && fm_pwr_state_get(fm)) { powerup = 1; } else { powerup = 0; } if (copy_to_user((void*)arg, &powerup, sizeof(fm_u32))) { ret = -EFAULT; goto out; } break; } case FM_IOCTL_RDS_ONOFF: { fm_u16 rdson_off = 0; WCN_DBG(FM_NTC | MAIN, "FM_IOCTL_RDS_ONOFF start\n"); if (copy_from_user(&rdson_off, (void*)arg, sizeof(fm_u16))) { ret = -EFAULT; goto out; } ret = fm_rds_onoff(fm, rdson_off); WCN_DBG(FM_NTC | MAIN, "FM_IOCTL_RDS_ONOFF end:%d\n",rdson_off); break; } case FM_IOCTL_GETGOODBCNT: { fm_u16 uGBLCNT = 0; ret = fm_rds_good_bc_get(fm, &uGBLCNT); WCN_DBG(FM_DBG | MAIN, "FM_IOCTL_GETGOODBCNT:%d\n", uGBLCNT); if (ret < 0) goto out; if (copy_to_user((void*)arg, &uGBLCNT, sizeof(fm_u16))) { ret = -EFAULT; goto out; } break; } case FM_IOCTL_GETBADBNT: { fm_u16 uBadBLCNT = 0; ret = fm_rds_bad_bc_get(fm, &uBadBLCNT); WCN_DBG(FM_DBG | MAIN, "FM_IOCTL_GETBADBNT:%d\n", uBadBLCNT); if (ret < 0) goto out; if (copy_to_user((void*)arg, &uBadBLCNT, sizeof(fm_u16))) { ret = -EFAULT; goto out; } break; } case FM_IOCTL_GETBLERRATIO: { fm_u16 uBlerRatio = 0; ret = fm_rds_bler_ratio_get(fm, &uBlerRatio); WCN_DBG(FM_DBG | MAIN, "FM_IOCTL_GETBLERRATIO:%d\n", uBlerRatio); if (ret < 0) goto out; if (copy_to_user((void*)arg, &uBlerRatio, sizeof(fm_u16))) { ret = -EFAULT; goto out; } break; } case FM_IOCTL_ANA_SWITCH: { fm_s32 antenna = -1; WCN_DBG(FM_DBG | MAIN, "FM_IOCTL_ANA_SWITCH\n"); if (copy_from_user(&antenna, (void*)arg, sizeof(fm_s32))) { WCN_DBG(FM_ALT | MAIN, "copy from user error\n"); ret = -EFAULT; goto out; } ret = fm_ana_switch(fm, antenna); break; } case FM_IOCTL_RDS_GROUPCNT: { struct rds_group_cnt_req_t gc_req; WCN_DBG(FM_DBG | MAIN, "......FM_IOCTL_RDS_GROUPCNT......\n"); if (copy_from_user(&gc_req, (void*)arg, sizeof(struct rds_group_cnt_req_t))) { WCN_DBG(FM_ALT | MAIN, "copy_from_user error\n"); ret = -EFAULT; goto out; } //handle group counter request switch (gc_req.op) { case RDS_GROUP_CNT_READ: ret = fm_rds_group_cnt_get(fm, &gc_req.gc); break; case RDS_GROUP_CNT_WRITE: break; case RDS_GROUP_CNT_RESET: ret = fm_rds_group_cnt_reset(fm); break; default: break; } if (copy_to_user((void*)arg, &gc_req, sizeof(struct rds_group_cnt_req_t))) { WCN_DBG(FM_ALT | MAIN, "copy_to_user error\n"); ret = -EFAULT; goto out; } break; } case FM_IOCTL_RDS_GET_LOG: { struct rds_raw_t rds_log; fm_s32 len; WCN_DBG(FM_DBG | MAIN, "......FM_IOCTL_RDS_GET_LOG......\n"); //fetch a record form RDS log buffer ret = fm_rds_log_get(fm, (struct rds_rx_t*) & (rds_log.data), &len); rds_log.dirty = TRUE; rds_log.len = (len < sizeof(rds_log.data)) ? len : sizeof(rds_log.data); if (ret < 0) goto out; if (copy_to_user((void*)arg, &rds_log, rds_log.len + 2*sizeof(fm_s32))) { WCN_DBG(FM_ALT | MAIN, "copy_to_user error\n"); ret = -EFAULT; goto out; } break; } case FM_IOCTL_RDS_BC_RST: { WCN_DBG(FM_DBG | MAIN, "FM_IOCTL_RDS_BC_RST\n"); ret = fm_rds_block_cnt_reset(fm); break; } case FM_IOCTL_I2S_SETTING: { struct fm_i2s_setting i2s_cfg; WCN_DBG(FM_DBG | MAIN, "FM_IOCTL_I2S_SETTING\n"); if (copy_from_user(&i2s_cfg, (void*)arg, sizeof(struct fm_i2s_setting))) { WCN_DBG(FM_ALT | MAIN, "i2s set, copy_from_user err\n"); ret = -EFAULT; goto out; } ret = fm_i2s_set(fm, i2s_cfg.onoff, i2s_cfg.mode, i2s_cfg.sample); if (ret) { WCN_DBG(FM_ALT | MAIN, "Set i2s err\n"); goto out; } break; } case FM_IOCTL_IS_DESE_CHAN: { fm_s32 tmp; WCN_DBG(FM_DBG | MAIN, "FM_IOCTL_IS_DESE_CHAN\n"); if (copy_from_user(&tmp, (void*)arg, sizeof(fm_s32))) { WCN_DBG(FM_ALT | MAIN, "is dese chan, copy_from_user err\n"); ret = -EFAULT; goto out; } tmp = fm_is_dese_chan(fm, (fm_u16)tmp); if (copy_to_user((void*)arg, &tmp, sizeof(fm_s32))) { WCN_DBG(FM_ALT | MAIN, "is dese chan, copy_to_user err\n"); ret = -EFAULT; goto out; } break; } case FM_IOCTL_DESENSE_CHECK: { fm_desense_check_t tmp; WCN_DBG(FM_DBG | MAIN, "FM_IOCTL_IS_DESE_CHAN\n"); if (copy_from_user(&tmp, (void*)arg, sizeof(fm_desense_check_t))) { WCN_DBG(FM_ALT | MAIN, "desene check, copy_from_user err\n"); ret = -EFAULT; goto out; } ret = fm_desense_check(fm, (fm_u16)tmp.freq,tmp.rssi); /*if (copy_to_user((void*)arg, &tmp, sizeof(fm_desense_check_t))) { WCN_DBG(FM_ALT | MAIN, "desene check, copy_to_user err\n"); ret = -EFAULT; goto out; }*/ break; } case FM_IOCTL_SCAN_GETRSSI: { /*struct fm_rssi_req *req; WCN_DBG(FM_DBG | MAIN, "FM_IOCTL_SCAN_GETRSSI\n"); if(!(req = fm_vmalloc(sizeof(struct fm_rssi_req)))) { WCN_DBG(FM_ALT | MAIN, "fm_vmalloc err\n"); ret = -EFAULT; goto out; } if(copy_from_user(req, (void*)arg, sizeof(struct fm_rssi_req))) { WCN_DBG(FM_ALT | MAIN, "copy_from_user err\n"); ret = -EFAULT; fm_vfree(req); goto out; } ret = fm_get_rssi_after_scan(fm, req); if(-ERR_FW_NORES == ret){ WCN_DBG(FM_ALT | MAIN, "fm_get_rssi_after_scan err\n"); } if(copy_to_user((void*)arg, req, sizeof(struct fm_rssi_req))) { WCN_DBG(FM_ALT | MAIN, "copy_to_user err\n"); ret = -EFAULT; fm_vfree(req); goto out; } */ WCN_DBG(FM_ALT | MAIN, "FM_IOCTL_SCAN_GETRSSI:not support\n"); break; } case FM_IOCTL_DUMP_REG: { WCN_DBG(FM_NTC | MAIN,"......FM_IOCTL_DUMP_REG......\n"); ret = fm_dump_reg(); if(ret) { WCN_DBG(FM_ALT | MAIN, "fm_dump_reg err\n"); } break; } case FM_IOCTL_GPS_RTC_DRIFT:{ struct fm_gps_rtc_info rtc_info; WCN_DBG(FM_NTC | MAIN,"......FM_IOCTL_GPS_RTC_DRIFT......\n"); if (fm_false == fm->chipon){ WCN_DBG(FM_ERR | MAIN,"ERROR, FM chip is OFF\n"); ret = -EFAULT; goto out; } if(copy_from_user(&rtc_info, (void*)arg, sizeof(struct fm_gps_rtc_info))){ WCN_DBG(FM_ERR | MAIN,"copy_from_user error\n"); ret = -EFAULT; goto out; } ret = fm_get_gps_rtc_info(&rtc_info); if(ret){ WCN_DBG(FM_ERR | MAIN,"fm_get_gps_rtc_info error\n"); goto out; } break; } case FM_IOCTL_OVER_BT_ENABLE: { fm_s32 fm_via_bt = -1; WCN_DBG(FM_NTC | MAIN,"......FM_IOCTL_OVER_BT_ENABLE......\n"); if(copy_from_user(&fm_via_bt, (void*)arg, sizeof(int32_t))){ WCN_DBG(FM_ERR | MAIN,"copy_from_user error\n"); ret = -EFAULT; goto out; } ret = fm_over_bt(fm, fm_via_bt); if(ret) { WCN_DBG(FM_ERR | MAIN, "fm_over_bt err\n"); } break; } /***************************FM Tx function************************************/ case FM_IOCTL_TX_SUPPORT: { fm_s32 tx_support = -1; WCN_DBG(FM_NTC | MAIN,"......FM_IOCTL_TX_SUPPORT......\n"); ret = fm_tx_support(fm,&tx_support); if(ret) { WCN_DBG(FM_ERR | MAIN, "fm_tx_support err\n"); } if (copy_to_user((void*)arg, &tx_support, sizeof(fm_s32))) { WCN_DBG(FM_ERR | MAIN,"copy_to_user error\n"); ret = -EFAULT; goto out; } break; } case FM_IOCTL_POWERUP_TX: { struct fm_tune_parm parm; WCN_DBG(FM_NTC | MAIN, "FM_IOCTL_POWERUP_TX:0\n"); if (copy_from_user(&parm, (void*)arg, sizeof(struct fm_tune_parm))) { ret = -EFAULT; goto out; } ret = fm_powerup_tx(fm, &parm); if (ret < 0) { goto out; } ret = fm_tune_tx(fm, &parm); if (ret < 0) goto out; if (copy_to_user((void*)arg, &parm, sizeof(struct fm_tune_parm))) { ret = -EFAULT; goto out; } WCN_DBG(FM_NTC | MAIN, "FM_IOCTL_POWERUP_TX:1\n"); break; } case FM_IOCTL_TUNE_TX: { struct fm_tune_parm parm; WCN_DBG(FM_NTC | MAIN, "FM_IOCTL_TUNE_TX:0\n"); if (copy_from_user(&parm, (void*)arg, sizeof(struct fm_tune_parm))) { ret = -EFAULT; goto out; } ret = fm_tune_tx(fm, &parm); if (ret < 0) { goto out; } if (copy_to_user((void*)arg, &parm, sizeof(struct fm_tune_parm))) { ret = -EFAULT; goto out; } WCN_DBG(FM_NTC | MAIN, "FM_IOCTL_TUNE_TX:1\n"); break; } case FM_IOCTL_RDSTX_SUPPORT: { fm_s32 rds_tx_support = -1; WCN_DBG(FM_NTC | MAIN,"......FM_IOCTL_RDSTX_SUPPORT......\n"); ret = fm_rdstx_support(fm,&rds_tx_support); if(ret) { WCN_DBG(FM_ERR | MAIN, "fm_rdstx_support err\n"); } if (copy_to_user((void*)arg, &rds_tx_support, sizeof(fm_s32))) { WCN_DBG(FM_ERR | MAIN,"copy_to_user error\n"); ret = -EFAULT; goto out; } break; } case FM_IOCTL_RDSTX_ENABLE: { fm_s32 rds_tx_enable = -1; WCN_DBG(FM_NTC | MAIN,"......FM_IOCTL_RDSTX_ENABLE......\n"); ret = fm_rdstx_enable(fm,&rds_tx_enable); if(ret) { WCN_DBG(FM_ERR | MAIN, "fm_rdstx_enable err\n"); } if (copy_to_user((void*)arg, &rds_tx_enable, sizeof(fm_s32))) { WCN_DBG(FM_ERR | MAIN,"copy_to_user error\n"); ret = -EFAULT; goto out; } break; } case FM_IOCTL_RDS_TX: { struct fm_rds_tx_parm parm; WCN_DBG(FM_NTC | MAIN, "......FM_IOCTL_RDS_TX......\n"); if (copy_from_user(&parm, (void*)arg, sizeof(struct fm_rds_tx_parm))) { WCN_DBG(FM_ALT | MAIN, "RDS Tx, copy_from_user err\n"); ret = -EFAULT; goto out; } ret = fm_rds_tx(fm, &parm); if(ret) { WCN_DBG(FM_ALT | MAIN, "fm_rds_tx err\n"); } if (copy_to_user((void*)arg, &parm, sizeof(struct fm_rds_tx_parm))){ WCN_DBG(FM_ALT | MAIN, "RDS Tx, copy_to_user err\n"); ret = -EFAULT; goto out; } break; } case FM_IOCTL_TX_SCAN: { struct fm_tx_scan_parm parm; WCN_DBG(FM_NTC | MAIN, "......FM_IOCTL_TX_SCAN......\n"); if (copy_from_user(&parm, (void*)arg, sizeof(struct fm_tx_scan_parm))){ WCN_DBG(FM_ALT | MAIN,"copy_from_user error\n"); ret = -EFAULT; goto out; } ret = fm_tx_scan(fm, &parm); if(ret < 0){ WCN_DBG(FM_ERR | MAIN,"FM_IOCTL_TX_SCAN failed\n"); } if (copy_to_user((void*)arg, &parm, sizeof(struct fm_tx_scan_parm))){ WCN_DBG(FM_ALT | MAIN,"copy_to_user error\n"); ret = -EFAULT; goto out; } break; } default: ret = -EPERM; } out: if (ret == -FM_EFW) { // subsystem reset fm_subsys_reset(fm); } return ret; }
/*----------------------------------------------------------------------------*/ int three_point_cal(FORMPTR fmp) { WINDOWPTR wnp; DFORMPTR dfmp; DFIELDPTR fldp; int status,done; int score,count; double heading; char cal_msg[81]; char serial_nbr[8],unit_type[5],cal_date[9]; char hardware_rev,software_rev; latt_rpl(L_BLINK,NORMAL|BLINK,BLUE|BLINK,WHITE,LATT_SYS); latt_rpl(L_ERROR,REVERSE, RED|BLINK, WHITE,LATT_SYS); wnp = wn_def(CENTER_WN,CENTER_WN,12,60,LREVERSE,BDR_DLNP); sw_shad(TRANSPARENT,LSHADOW,BOTTOMRIGHT,wnp); sw_updnfp(wn_expset,wn_expunset,wnp); wn_up(wnp); dfmp = fm_def(12,CENTER_WN,3,25,LNORMAL,BDR_DLNP); sw_shad(TRANSPARENT,LSHADOW,BOTTOMRIGHT,dfmp->wnp); sw_updnfp(wn_expset,wn_expunset,dfmp->wnp); fldp = fld_def(0,1,"Actual Heading: ",FADJACENT,"###@#", F_DOUBLE,&heading,dfmp); sf_msg("Enter actual compass heading and press ENTER.",fldp); status = c100_open_channel(dflt_port,dflt_baud); if (status != 0) { v_printf(wnp,"Error: unable to open compass channel - %s", c100_error_name(status)); goto END; } /* if */ status = c100_halt_data(); if (status != 0) { v_printf(wnp,"Error: unable to halt data messages - %s", c100_error_name(status)); goto END; } /* if */ status = c100_get_who(serial_nbr,&software_rev,&hardware_rev, unit_type,cal_date); if (status != 0) { v_printf(wnp,"Error: unable to read software revision level. %s", c100_error_name(status)); goto END; } /* if */ if (software_rev < 'C') { v_st("\nThree Point Cal requires software revision C or higher.",wnp); v_printf(wnp,"\nThis C100 has rev %c software.",software_rev); v_st("\n\nCalibration aborted.",wnp); goto END; } /* if */ v_st("Three-Point Calibration started.\n",wnp); done = FALSE; heading = 0.0; while (!done) { status = c100_cal_mode(THREE_POINT_CAL,&heading,cal_msg); switch (status) { case OK: v_printf(wnp,"\nPosition compass to about %.0fø and enter actual" " heading.",heading); if (fm_proc(0,dfmp) != AC_EXIT) { c100_cal_mode(ABORT_CAL,NULL,NULL); v_st("\n\nCalibration aborted by user.",wnp); done = TRUE; } /* if */ break; case DONE: v_st("\n\nThree-Point calibration complete!",wnp); status = c100_get_cal_score(SHORT_SCORE,&score,&count,NULL); if (status != 0) v_printf(wnp,"\nError: unable to read cal score - %s", c100_error_name(status)); else v_printf(wnp,"\nCal score = %d, count = %d.", score,count); done = TRUE; break; case MSG_NAKKED: v_printf(wnp,"\n\nError: %s",cal_msg); c100_cal_mode(ABORT_CAL,NULL,NULL); done = TRUE; break; default: v_printf(wnp,"\n\nError: unable to complete calibration - %s", c100_error_name(status)); c100_cal_mode(ABORT_CAL,NULL,NULL); done = TRUE; break; } /* switch */ } /* while */ END: if (c100_mode == SENDING) { c100_send_data(); } /* if */ sw_title("[Press any key...]",L_BLINK,BOTTOMCENTER,wnp); v_bdr(BDR_DLNP,wnp); beep_vv(BPMEDIUM,BPLOW); beep_vv(BPMEDIUM,BPMIDDLE); beep_vv(BPMEDIUM,BPHIGH); flush_keybuf(); ki(); c100_close_channel(); fm_free(dfmp); wn_dn(wnp); wn_free(wnp); return(SAMELEVEL); } /* three_point_cal() */
void* fm_realloc(struct fm_block* qm, void* p, unsigned long size) #endif { struct fm_frag *f; unsigned long diff; unsigned long orig_size; struct fm_frag *n; void *ptr; #ifdef DBG_F_MALLOC LM_DBG("params(%p, %p, %lu), called from %s: %s(%d)\n", qm, p, size, file, func, line); if ((p)&&(p>(void*)qm->last_frag || p<(void*)qm->first_frag)){ LM_CRIT("bad pointer %p (out of memory block!) - aborting\n", p); abort(); } #endif if (size==0) { if (p) #ifdef DBG_F_MALLOC fm_free(qm, p, file, func, line); #else fm_free(qm, p); #endif pkg_threshold_check(); return 0; } if (p==0) #ifdef DBG_F_MALLOC return fm_malloc(qm, size, file, func, line); #else return fm_malloc(qm, size); #endif f=(struct fm_frag*) ((char*)p-sizeof(struct fm_frag)); #ifdef DBG_F_MALLOC LM_DBG("realloc'ing frag %p alloc'ed from %s: %s(%ld)\n", f, f->file, f->func, f->line); #endif size=ROUNDUP(size); orig_size=f->size; if (f->size > size){ /* shrink */ #ifdef DBG_F_MALLOC LM_DBG("shrinking from %lu to %lu\n", f->size, size); fm_split_frag(qm, f, size, file, "frag. from fm_realloc", line); #else fm_split_frag(qm, f, size); #endif }else if (f->size<size){ /* grow */ #ifdef DBG_F_MALLOC LM_DBG("growing from %lu to %lu\n", f->size, size); #endif diff=size-f->size; n=FRAG_NEXT(f); if (((char*)n < (char*)qm->last_frag) && n->prev && ((n->size+FRAG_OVERHEAD)>=diff)){ fm_remove_free(qm,n); /* join */ f->size += n->size + FRAG_OVERHEAD; #if defined(DBG_F_MALLOC) || defined(STATISTICS) //qm->real_used -= FRAG_OVERHEAD; qm->used += FRAG_OVERHEAD; #endif /* split it if necessary */ if (f->size > size){ #ifdef DBG_F_MALLOC fm_split_frag(qm, f, size, file, "fragm. from fm_realloc", line); #else fm_split_frag(qm, f, size); #endif } }else{ /* could not join => realloc */ #ifdef DBG_F_MALLOC ptr=fm_malloc(qm, size, file, func, line); #else ptr = fm_malloc(qm, size); #endif if (ptr) { /* copy, need by libssl */ memcpy(ptr, p, orig_size); #ifdef DBG_F_MALLOC fm_free(qm, p, file, func, line); #else fm_free(qm, p); #endif } p = ptr; } }else{ /* do nothing */ #ifdef DBG_F_MALLOC LM_DBG("doing nothing, same size: %lu - %lu\n", f->size, size); #endif } #ifdef DBG_F_MALLOC LM_DBG("returning %p\n", p); #endif #if defined(DBG_F_MALLOC) || defined(STATISTICS) if (qm->max_real_used<qm->real_used) qm->max_real_used=qm->real_used; #endif pkg_threshold_check(); return p; }