Esempio n. 1
0
static int modem_sync_init(void)
{
    int ret = 0;
    struct asc_infor user;
    struct asc_config cfg;

    /*Registe the cbp tx handle*/
    if(GPIO_OEM_VALID(GPIO_VIATEL_AP_WAKE_MDM) && GPIO_OEM_VALID(GPIO_VIATEL_MDM_RDY)){
        memset(&cfg, 0, sizeof(struct asc_config));
        strncpy(cfg.name, CBP_TX_HD_NAME, ASC_NAME_LEN);
        cfg.gpio_wake = GPIO_VIATEL_AP_WAKE_MDM;
        cfg.gpio_ready = GPIO_VIATEL_MDM_RDY;
        cfg.polar = 1;
        ret = asc_tx_register_handle(&cfg);
        if(ret < 0){
            printk("%s: fail to regist tx handle %s\n", __FUNCTION__, CBP_TX_HD_NAME);
            goto end_sync_init;
        }
    }

    /*Registe the usb rx handle*/
    if(GPIO_OEM_VALID(GPIO_VIATEL_USB_MDM_WAKE_AP) && GPIO_OEM_VALID(GPIO_VIATEL_USB_AP_RDY)){
        memset(&cfg, 0, sizeof(struct asc_config));
        strncpy(cfg.name, USB_RX_HD_NAME, ASC_NAME_LEN);
        cfg.gpio_wake = GPIO_VIATEL_USB_MDM_WAKE_AP;
        cfg.gpio_ready = GPIO_VIATEL_USB_AP_RDY;
        cfg.polar = 1;
        ret = asc_rx_register_handle(&cfg);
        if(ret < 0){
            printk("%s: fail to regist rx handle %s\n", __FUNCTION__, USB_RX_HD_NAME);
            goto end_sync_init;
        }
        memset(&user, 0, sizeof(struct asc_infor));
        user.notifier = modem_userspace_notifier,
        user.data = USB_RX_HD_NAME,
        snprintf(user.name, ASC_NAME_LEN, USB_RX_USER_NAME);
        ret = asc_rx_add_user(USB_RX_HD_NAME, &user);
        if(ret < 0){
            printk("%s: fail to regist rx user %s\n", __FUNCTION__, USB_RX_USER_NAME);
            goto end_sync_init;
        }
    }

    /*Registe the uart rx handle*/
    if(GPIO_OEM_VALID(GPIO_VIATEL_UART_MDM_WAKE_AP) && GPIO_OEM_VALID(GPIO_VIATEL_UART_AP_RDY)){
        memset(&cfg, 0, sizeof(struct asc_config));
        strncpy(cfg.name, UART_RX_HD_NAME, ASC_NAME_LEN);
        cfg.gpio_wake = GPIO_VIATEL_UART_MDM_WAKE_AP;
        cfg.gpio_ready = GPIO_VIATEL_UART_AP_RDY;
        cfg.polar = 1;
        ret = asc_rx_register_handle(&cfg);
        if(ret < 0){
            printk("%s: fail to regist rx handle %s\n", __FUNCTION__, UART_RX_HD_NAME);
            goto end_sync_init;
        }

        memset(&user, 0, sizeof(struct asc_infor));
        user.notifier = modem_userspace_notifier,
        user.data = UART_RX_HD_NAME,
        snprintf(user.name, ASC_NAME_LEN, UART_RX_USER_NAME);
        ret = asc_rx_add_user(UART_RX_HD_NAME, &user);
        if(ret < 0){
            printk("%s: fail to regist rx user %s\n", __FUNCTION__, UART_RX_USER_NAME);
            goto end_sync_init;
        }
    }

end_sync_init:
    if(ret){
        printk("%s: error\n", __FUNCTION__);
    }
    return ret;
}
Esempio n. 2
0
//static int __devinit cbp_probe(struct platform_device *pdev)
static int cbp_probe(struct platform_device *pdev)
{
	struct cbp_platform_data *plat = pdev->dev.platform_data;
	int ret = -1;
	
	/* must have platform data */
	if (!plat) {
		LOGPRT(LOG_ERR,  "%s: no platform data!\n", __func__);
		ret = -EINVAL;
		goto out;
	}
	
	if(plat->bus && !strcmp(plat->bus,"sdio")){
		if(plat->detect_host){
			ret = plat->detect_host(plat->host_id);
			if(ret){
				LOGPRT(LOG_ERR,  "%s: host %s dectect failed!\n", __func__, plat->host_id);
				goto out;
			}
		}
		else{
			LOGPRT(LOG_ERR,  "%s: bus %s have no dectect function!\n", __func__, plat->bus);
			goto out;
		}
	}
	else{
		LOGPRT(LOG_ERR,  "%s: unknow bus!\n", __func__);
		goto out;
	}

	if((GPIO_OEM_VALID(plat->gpio_sd_select)) && (GPIO_OEM_VALID(plat->gpio_mc3_enable))){
		ret = oem_gpio_request(plat->gpio_mc3_enable, DRIVER_NAME"(MC3_EN_N)");
		if(ret < 0){
			LOGPRT(LOG_ERR,  "%s: %d fail to requset MC3_EN_N gpio %d ret =%d!!\n",
				__func__, __LINE__, plat->gpio_mc3_enable,ret);
			goto out;
		}
		ret = oem_gpio_request(plat->gpio_sd_select, DRIVER_NAME"(SD_SEL_N)");
		if(ret < 0){
			LOGPRT(LOG_ERR,  "%s: %d fail to requset SD_SEL_N gpio %d ret =%d!!\n", 
				__func__, __LINE__, plat->gpio_sd_select,ret);
			goto err_req_sd_sel;
		}
		oem_gpio_direction_output(GPIO_VIATEL_MC3_EN_N, 0); //MC3_EN_N
		oem_gpio_direction_output(GPIO_VIATEL_SD_SEL_N, 0); //SD_SEL_N
	}

	if(GPIO_OEM_VALID(plat->gpio_data_ack)){
		cbp_data_ack = kzalloc(sizeof(struct cbp_wait_event), GFP_KERNEL);
		if (!cbp_data_ack){
			ret = -ENOMEM;
			LOGPRT(LOG_ERR,  "%s %d kzalloc cbp_data_ack failed \n",__func__, __LINE__);
			goto err_kzalloc_cbp_data_ack;    
		}

		init_waitqueue_head(&cbp_data_ack->wait_q);
		atomic_set(&cbp_data_ack->state, MODEM_ST_UNKNOW);
		cbp_data_ack->wait_gpio = plat->gpio_data_ack;
		cbp_data_ack->wait_polar = plat->gpio_data_ack_polar;
		LOGPRT(LOG_ERR,  "cbp_data_ack->wait_gpio=%d\n",cbp_data_ack->wait_gpio);
		LOGPRT(LOG_ERR,  "cbp_data_ack->wait_polar=%d\n",cbp_data_ack->wait_polar);
		ret = oem_gpio_request(plat->gpio_data_ack, DRIVER_NAME "(data_ack)");
		if(ret < 0){
			LOGPRT(LOG_ERR,  "%s: %d fail to requset data_ack gpio %d ret =%d!!\n", 
				__func__, __LINE__, plat->gpio_data_ack, ret);
			goto err_req_data_ack;
		}
		oem_gpio_irq_mask(plat->gpio_data_ack);
		oem_gpio_direction_input_for_irq(plat->gpio_data_ack);
		oem_gpio_set_irq_type(plat->gpio_data_ack, IRQF_TRIGGER_FALLING);
		ret = oem_gpio_request_irq(plat->gpio_data_ack, gpio_irq_data_ack, 
				IRQF_SHARED | IRQF_TRIGGER_FALLING, DRIVER_NAME "(data_ack)", cbp_data_ack);
		oem_gpio_irq_unmask(plat->gpio_data_ack);
		if (ret < 0) {
			LOGPRT(LOG_ERR,  "%s: %d fail to request irq for data_ack!!\n", __func__, __LINE__);
			goto err_req_irq_data_ack;
		}
		plat->cbp_data_ack = cbp_data_ack;
		plat->data_ack_wait_event = data_ack_wait_event;
		plat->data_ack_enable =true;
	}

	if(GPIO_OEM_VALID(plat->gpio_flow_ctrl)){
		cbp_flow_ctrl = kzalloc(sizeof(struct cbp_wait_event), GFP_KERNEL);
		if (!cbp_flow_ctrl){
			ret = -ENOMEM;
			LOGPRT(LOG_ERR,  "%s %d kzalloc cbp_flow_ctrl failed \n",__func__, __LINE__);
			goto err_kzalloc_cbp_flow_ctrl;    
		}

		init_waitqueue_head(&cbp_flow_ctrl->wait_q);
		atomic_set(&cbp_flow_ctrl->state, FLOW_CTRL_DISABLE);
		cbp_flow_ctrl->wait_gpio = plat->gpio_flow_ctrl;
		cbp_flow_ctrl->wait_polar = plat->gpio_flow_ctrl_polar;
		LOGPRT(LOG_ERR,  "cbp_flow_ctrl->wait_gpio=%d\n",cbp_flow_ctrl->wait_gpio);
		LOGPRT(LOG_ERR,  "cbp_flow_ctrl->wait_polar=%d\n",cbp_flow_ctrl->wait_polar);
		ret = oem_gpio_request(plat->gpio_flow_ctrl, DRIVER_NAME "(flow_ctrl)");
		if(ret < 0){
			LOGPRT(LOG_ERR,  "%s: %d fail to requset flow_ctrl gpio %d ret =%d!!\n", 
				__func__, __LINE__, plat->gpio_flow_ctrl, ret);
			goto err_req_flow_ctrl;
		}
		oem_gpio_irq_mask(plat->gpio_flow_ctrl);
		oem_gpio_direction_input_for_irq(plat->gpio_flow_ctrl);
		//oem_gpio_set_irq_type(plat->gpio_flow_ctrl, IRQ_TYPE_LEVEL_LOW |IRQ_TYPE_LEVEL_HIGH);
		oem_gpio_set_irq_type(plat->gpio_flow_ctrl, IRQF_TRIGGER_FALLING);
		ret = oem_gpio_request_irq(plat->gpio_flow_ctrl, gpio_irq_flow_ctrl, 
				IRQF_SHARED | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, 
				DRIVER_NAME "(flow_ctrl)", cbp_flow_ctrl);
		oem_gpio_irq_unmask(plat->gpio_flow_ctrl);
		if (ret < 0) {
			LOGPRT(LOG_ERR,  "%s: %d fail to request irq for flow_ctrl!!\n", __func__, __LINE__);
			goto err_req_irq_flow_ctrl;
		}
		
		plat->cbp_flow_ctrl= cbp_flow_ctrl;
		plat->flow_ctrl_wait_event = flow_ctrl_wait_event;
		plat->flow_ctrl_enable = true;
	}
	
	
	if(GPIO_OEM_VALID(plat->gpio_rst_ind)){
		cbp_rst_ind = kzalloc(sizeof(struct cbp_reset), GFP_KERNEL);
		if (!cbp_rst_ind){
			ret = -ENOMEM;
			LOGPRT(LOG_ERR,  "%s %d kzalloc cbp_rst_ind failed \n",__func__, __LINE__);
			goto err_kzalloc_cbp_rst_ind;    
		}

		cbp_rst_ind->name = "cbp_rst_ind_wq";
		cbp_rst_ind->reset_wq = create_singlethread_workqueue(cbp_rst_ind->name);
		if (cbp_rst_ind->reset_wq == NULL) {
			ret = -ENOMEM;
			LOGPRT(LOG_ERR,  "%s %d error creat rst_ind_workqueue \n",__func__, __LINE__);
			goto err_create_work_queue;
		}
		INIT_WORK(&cbp_rst_ind->reset_work, modem_detect);
		cbp_rst_ind->rst_ind_gpio = plat->gpio_rst_ind;
		cbp_rst_ind->rst_ind_polar = plat->gpio_rst_ind_polar;
		cbp_rst_ind->host = NULL;
#if 0		
		ret = oem_gpio_request(plat->gpio_rst_ind, DRIVER_NAME "(rst_ind)");
		if(ret < 0){
			LOGPRT(LOG_ERR,  "%s: %d fail to requset rst_ind gpio %d ret =%d!!\n", 
				__func__, __LINE__, plat->gpio_rst_ind, ret);
			goto err_req_rst_ind;
		}

		oem_gpio_irq_mask(plat->gpio_rst_ind);
		oem_gpio_direction_input_for_irq(plat->gpio_rst_ind);
		oem_gpio_set_irq_type(plat->gpio_rst_ind, IRQF_TRIGGER_FALLING |IRQF_TRIGGER_RISING);
		ret = oem_gpio_request_irq(plat->gpio_rst_ind, gpio_irq_cbp_rst_ind, 
			IRQF_SHARED |IRQF_TRIGGER_FALLING |IRQF_TRIGGER_RISING, 
			DRIVER_NAME "(rst_ind)", cbp_rst_ind);
		oem_gpio_irq_unmask(plat->gpio_rst_ind);
		if (ret < 0) {
			LOGPRT(LOG_ERR,  "%s: %d fail to request irq for rst_ind!!\n", __func__, __LINE__);
			goto err_req_irq_rst_ind;
		}
#endif
		plat->rst_ind_enable = true;
	}

	if((GPIO_OEM_VALID(plat->gpio_ap_wkup_cp)) && (GPIO_OEM_VALID(plat->gpio_cp_ready)) &&
		(GPIO_OEM_VALID(plat->gpio_cp_wkup_ap))  && (GPIO_OEM_VALID(plat->gpio_ap_ready))){
		sdio_tx_handle.gpio_wake = plat->gpio_ap_wkup_cp;
		sdio_tx_handle.gpio_ready = plat->gpio_cp_ready;
		sdio_tx_handle.polar = plat->gpio_sync_polar;
		ret = asc_tx_register_handle(&sdio_tx_handle);
		if(ret){
			LOGPRT(LOG_ERR,  "%s %d asc_tx_register_handle failed.\n",__FUNCTION__,__LINE__);
			goto err_ipc;
		}
		ret = asc_tx_add_user(sdio_tx_handle.name, &sdio_tx_user);
		if(ret){
			LOGPRT(LOG_ERR,  "%s %d asc_tx_add_user failed.\n",__FUNCTION__,__LINE__);
			goto err_ipc;
		}

		sdio_rx_handle.gpio_wake = plat->gpio_cp_wkup_ap;
		sdio_rx_handle.gpio_ready = plat->gpio_ap_ready;
		sdio_rx_handle.polar = plat->gpio_sync_polar;
		ret = asc_rx_register_handle(&sdio_rx_handle);
		if(ret){
			LOGPRT(LOG_ERR,  "%s %d asc_rx_register_handle failed.\n",__FUNCTION__,__LINE__);
			goto err_ipc;
		}
		ret = asc_rx_add_user(sdio_rx_handle.name, &sdio_rx_user);
		if(ret){
			LOGPRT(LOG_ERR,  "%s %d asc_rx_add_user failed.\n",__FUNCTION__,__LINE__);
			goto err_ipc;
		}
		plat->ipc_enable = true;
		plat->tx_handle = &sdio_tx_handle;
	}
	
	ret = plat->cbp_setup(plat);
	if(ret){
		LOGPRT(LOG_ERR,  "%s: host %s setup failed!\n", __func__, plat->host_id);
		goto err_ipc;
	}
	cbp_power_kobj = viatel_kobject_add("power");
	if (!cbp_power_kobj){
		LOGPRT(LOG_ERR,  "error viatel_kobject_add!\n");
		ret = -ENOMEM;
		goto err_create_kobj;
	}
	LOGPRT(LOG_INFO,  " cbp initialized on host %s successfully, bus is %s !\n", plat->host_id, plat->bus);
	return sysfs_create_group(cbp_power_kobj, &g_power_attr_group);
	
err_create_kobj:
	plat->cbp_destroy();
err_ipc:
#if 0
	if(GPIO_OEM_VALID(plat->gpio_rst_ind)){
		free_irq(oem_gpio_to_irq(plat->gpio_rst_ind), cbp_rst_ind);
	}
err_req_irq_rst_ind:
	if(GPIO_OEM_VALID(plat->gpio_rst_ind)){
		oem_gpio_free(plat->gpio_rst_ind);
	}
#endif
err_req_rst_ind:
	if(GPIO_OEM_VALID(plat->gpio_rst_ind)){
		destroy_workqueue(cbp_rst_ind->reset_wq);
	}
err_create_work_queue:
	if(GPIO_OEM_VALID(plat->gpio_rst_ind)){
		kfree(cbp_rst_ind);
	}
err_kzalloc_cbp_rst_ind:
	if(GPIO_OEM_VALID(plat->gpio_flow_ctrl)){
		free_irq(oem_gpio_to_irq(plat->gpio_flow_ctrl), cbp_flow_ctrl);
	}
err_req_irq_flow_ctrl:
	if(GPIO_OEM_VALID(plat->gpio_flow_ctrl)){
		oem_gpio_free(plat->gpio_flow_ctrl);
	}
err_req_flow_ctrl:
	if(GPIO_OEM_VALID(plat->gpio_flow_ctrl)){
		kfree(cbp_flow_ctrl);
	}
err_kzalloc_cbp_flow_ctrl:
	if(GPIO_OEM_VALID(plat->gpio_data_ack)){
		free_irq(oem_gpio_to_irq(plat->gpio_data_ack), cbp_data_ack);
	}
err_req_irq_data_ack:
	if(GPIO_OEM_VALID(plat->gpio_data_ack)){
		oem_gpio_free(plat->gpio_data_ack);
	}
err_req_data_ack:
	if(GPIO_OEM_VALID(plat->gpio_data_ack)){
		kfree(cbp_data_ack);
	}
err_kzalloc_cbp_data_ack:
	if((GPIO_OEM_VALID(plat->gpio_sd_select)) && (GPIO_OEM_VALID(plat->gpio_mc3_enable))){
		oem_gpio_free(plat->gpio_sd_select);
	}
err_req_sd_sel:
	if((GPIO_OEM_VALID(plat->gpio_sd_select)) && (GPIO_OEM_VALID(plat->gpio_mc3_enable))){
		oem_gpio_free(plat->gpio_mc3_enable);
	}
out:
	return ret;
}
Esempio n. 3
0
//static int __devinit cbp_probe(struct platform_device *pdev)
static int cbp_probe(struct platform_device *pdev)
{
	struct cbp_platform_data *plat = pdev->dev.platform_data;
	int ret = -1;
	
	/* must have platform data */
	if (!plat) {
		LOGPRT(LOG_ERR,  "%s: no platform data!\n", __func__);
		ret = -EINVAL;
		goto out;
	}
#if 0
	if(plat->bus && !strcmp(plat->bus,"sdio")){
		if(plat->detect_host){
			ret = plat->detect_host(plat->host_id);
			if(ret){
				LOGPRT(LOG_ERR,  "%s: host %s dectect failed!\n", __func__, plat->host_id);
				goto out;
			}
		}
		else{
			LOGPRT(LOG_ERR,  "%s: bus %s have no dectect function!\n", __func__, plat->bus);
			goto out;
		}
	}
	else{
		LOGPRT(LOG_ERR,  "%s: unknow bus!\n", __func__);
		goto out;
	}
#endif

	if(GPIO_C2K_VALID(plat->gpio_data_ack)){
		cbp_data_ack = kzalloc(sizeof(struct cbp_wait_event), GFP_KERNEL);
		if (!cbp_data_ack){
			ret = -ENOMEM;
			LOGPRT(LOG_ERR,  "%s %d kzalloc cbp_data_ack failed \n",__func__, __LINE__);
			goto err_kzalloc_cbp_data_ack;    
		}

		init_waitqueue_head(&cbp_data_ack->wait_q);
		atomic_set(&cbp_data_ack->state, MODEM_ST_UNKNOW);
		cbp_data_ack->wait_gpio = plat->gpio_data_ack;
		cbp_data_ack->wait_polar = plat->gpio_data_ack_polar;
		LOGPRT(LOG_ERR,  "cbp_data_ack->wait_gpio=%d\n",cbp_data_ack->wait_gpio);
		LOGPRT(LOG_ERR,  "cbp_data_ack->wait_polar=%d\n",cbp_data_ack->wait_polar);
		
		c2k_gpio_irq_mask(plat->gpio_data_ack);
		c2k_gpio_direction_input_for_irq(plat->gpio_data_ack);
		c2k_gpio_set_irq_type(plat->gpio_data_ack, IRQF_TRIGGER_FALLING);
		ret = c2k_gpio_request_irq(plat->gpio_data_ack, gpio_irq_data_ack, 
				IRQF_SHARED | IRQF_TRIGGER_FALLING, DRIVER_NAME "(data_ack)", cbp_data_ack);
		c2k_gpio_irq_unmask(plat->gpio_data_ack);
		if (ret < 0) {
			LOGPRT(LOG_ERR,  "%s: %d fail to request irq for data_ack!!\n", __func__, __LINE__);
			goto err_req_irq_data_ack;
		}
		plat->cbp_data_ack = cbp_data_ack;
		plat->data_ack_wait_event = data_ack_wait_event;
		plat->data_ack_enable =true;
	}

	if(GPIO_C2K_VALID(plat->gpio_flow_ctrl)){
		cbp_flow_ctrl = kzalloc(sizeof(struct cbp_wait_event), GFP_KERNEL);
		if (!cbp_flow_ctrl){
			ret = -ENOMEM;
			LOGPRT(LOG_ERR,  "%s %d kzalloc cbp_flow_ctrl failed \n",__func__, __LINE__);
			goto err_kzalloc_cbp_flow_ctrl;    
		}

		init_waitqueue_head(&cbp_flow_ctrl->wait_q);
		atomic_set(&cbp_flow_ctrl->state, FLOW_CTRL_DISABLE);
		cbp_flow_ctrl->wait_gpio = plat->gpio_flow_ctrl;
		cbp_flow_ctrl->wait_polar = plat->gpio_flow_ctrl_polar;
		LOGPRT(LOG_ERR,  "cbp_flow_ctrl->wait_gpio=%d\n",cbp_flow_ctrl->wait_gpio);
		LOGPRT(LOG_ERR,  "cbp_flow_ctrl->wait_polar=%d\n",cbp_flow_ctrl->wait_polar);
		
		c2k_gpio_irq_mask(plat->gpio_flow_ctrl);
		c2k_gpio_direction_input_for_irq(plat->gpio_flow_ctrl);
		//c2k_gpio_set_irq_type(plat->gpio_flow_ctrl, IRQ_TYPE_LEVEL_LOW |IRQ_TYPE_LEVEL_HIGH);
		c2k_gpio_set_irq_type(plat->gpio_flow_ctrl, IRQF_TRIGGER_FALLING);
		ret = c2k_gpio_request_irq(plat->gpio_flow_ctrl, gpio_irq_flow_ctrl, 
				IRQF_SHARED | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, 
				DRIVER_NAME "(flow_ctrl)", cbp_flow_ctrl);
		c2k_gpio_irq_unmask(plat->gpio_flow_ctrl);
		if (ret < 0) {
			LOGPRT(LOG_ERR,  "%s: %d fail to request irq for flow_ctrl!!\n", __func__, __LINE__);
			goto err_req_irq_flow_ctrl;
		}
		
		plat->cbp_flow_ctrl= cbp_flow_ctrl;
		plat->flow_ctrl_wait_event = flow_ctrl_wait_event;
		plat->flow_ctrl_enable = true;
	}
	
	
	if(GPIO_C2K_VALID(plat->gpio_rst_ind)){
		cbp_rst_ind = kzalloc(sizeof(struct cbp_reset), GFP_KERNEL);
		if (!cbp_rst_ind){
			ret = -ENOMEM;
			LOGPRT(LOG_ERR,  "%s %d kzalloc cbp_rst_ind failed \n",__func__, __LINE__);
			goto err_kzalloc_cbp_rst_ind;    
		}

		cbp_rst_ind->name = "cbp_rst_ind_wq";
		cbp_rst_ind->reset_wq = create_singlethread_workqueue(cbp_rst_ind->name);
		if (cbp_rst_ind->reset_wq == NULL) {
			ret = -ENOMEM;
			LOGPRT(LOG_ERR,  "%s %d error creat rst_ind_workqueue \n",__func__, __LINE__);
			goto err_create_work_queue;
		}
		INIT_WORK(&cbp_rst_ind->reset_work, modem_detect);
		cbp_rst_ind->rst_ind_gpio = plat->gpio_rst_ind;
		cbp_rst_ind->rst_ind_polar = plat->gpio_rst_ind_polar;
		cbp_rst_ind->host = NULL;
#if 0		
		c2k_gpio_irq_mask(plat->gpio_rst_ind);
		c2k_gpio_direction_input_for_irq(plat->gpio_rst_ind);
		c2k_gpio_set_irq_type(plat->gpio_rst_ind, IRQF_TRIGGER_FALLING |IRQF_TRIGGER_RISING);
		ret = c2k_gpio_request_irq(plat->gpio_rst_ind, gpio_irq_cbp_rst_ind, 
			IRQF_SHARED |IRQF_TRIGGER_FALLING |IRQF_TRIGGER_RISING, 
			DRIVER_NAME "(rst_ind)", cbp_rst_ind);
		c2k_gpio_irq_unmask(plat->gpio_rst_ind);
		if (ret < 0) {
			LOGPRT(LOG_ERR,  "%s: %d fail to request irq for rst_ind!!\n", __func__, __LINE__);
			goto err_req_irq_rst_ind;
		}
#endif
		plat->rst_ind_enable = true;
	}

		cbp_excp_ind = kzalloc(sizeof(struct cbp_exception), GFP_KERNEL);
		if (!cbp_excp_ind){
			ret = -ENOMEM;
			LOGPRT(LOG_ERR,  "%s %d kzalloc cbp_rst_ind failed \n",__func__, __LINE__);
			goto err_kzalloc_cbp_excp_ind;	 
		}

		cbp_excp_ind->name = "cbp_excp_ind_wq";
		cbp_excp_ind->excp_wq = create_singlethread_workqueue(cbp_excp_ind->name);
		if (cbp_excp_ind->excp_wq == NULL) {
			ret = -ENOMEM;
			LOGPRT(LOG_ERR,  "%s %d error creat rst_ind_workqueue \n",__func__, __LINE__);
			goto err_create_excp_work_queue;
		}
		//Todo: workqueue function need to be implemented
		//INIT_WORK(&cbp_excp_ind->excp_work, modem_detect);
		INIT_WORK(&cbp_excp_ind->excp_work, modem_detect_for_excp);
		cbp_excp_ind->host = NULL;

#ifndef CONFIG_EVDO_DT_VIA_SUPPORT
	if (GPIO_C2K_VALID(plat->gpio_cp_exception)){
		cbp_excp_ind->excp_ind_gpio = plat->gpio_cp_exception;
		
		c2k_gpio_irq_mask(plat->gpio_cp_exception);
		c2k_gpio_set_irq_type(plat->gpio_cp_exception, IRQF_TRIGGER_FALLING);
		ret = c2k_gpio_request_irq(plat->gpio_cp_exception, gpio_irq_cbp_excp_ind, 
				IRQF_SHARED | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, 
				DRIVER_NAME "(c2k EE)", cbp_excp_ind);
		c2k_gpio_irq_unmask(plat->gpio_cp_exception);
		if (ret < 0) {
			LOGPRT(LOG_ERR,  "%s: %d fail to request irq for flow_ctrl!!\n", __func__, __LINE__);
			goto err_req_irq_excp;
		}
	}
	plat->c2k_wdt_irq_id = get_c2k_wdt_irq_id();
	LOGPRT(LOG_INFO, "get c2k wdt irq id %d\n", plat->c2k_wdt_irq_id);
#if 1
	if (plat->c2k_wdt_irq_id)
		ret = request_irq(plat->c2k_wdt_irq_id, c2k_wdt_isr, IRQF_TRIGGER_NONE, "C2K_CCCI", plat);
	else
		LOGPRT(LOG_ERR,  "%s: %d fail to get wdt irq id!!\n", __func__, __LINE__);
#endif
#endif

	if((GPIO_C2K_VALID(plat->gpio_ap_wkup_cp)) && (GPIO_C2K_VALID(plat->gpio_cp_ready)) &&
		(GPIO_C2K_VALID(plat->gpio_cp_wkup_ap))  && (GPIO_C2K_VALID(plat->gpio_ap_ready))){
		sdio_tx_handle.gpio_wake = plat->gpio_ap_wkup_cp;
		sdio_tx_handle.gpio_ready = plat->gpio_cp_ready;
		sdio_tx_handle.polar = plat->gpio_sync_polar;
		ret = asc_tx_register_handle(&sdio_tx_handle);
		if(ret){
			LOGPRT(LOG_ERR,  "%s %d asc_tx_register_handle failed.\n",__FUNCTION__,__LINE__);
			goto err_ipc;
		}
		ret = asc_tx_add_user(sdio_tx_handle.name, &sdio_tx_user);
		if(ret){
			LOGPRT(LOG_ERR,  "%s %d asc_tx_add_user failed.\n",__FUNCTION__,__LINE__);
			goto err_ipc;
		}

		sdio_rx_handle.gpio_wake = plat->gpio_cp_wkup_ap;
		sdio_rx_handle.gpio_ready = plat->gpio_ap_ready;
		sdio_rx_handle.polar = plat->gpio_sync_polar;
		ret = asc_rx_register_handle(&sdio_rx_handle);
		if(ret){
			LOGPRT(LOG_ERR,  "%s %d asc_rx_register_handle failed.\n",__FUNCTION__,__LINE__);
			goto err_ipc;
		}
		ret = asc_rx_add_user(sdio_rx_handle.name, &sdio_rx_user);
		if(ret){
			LOGPRT(LOG_ERR,  "%s %d asc_rx_add_user failed.\n",__FUNCTION__,__LINE__);
			goto err_ipc;
		}
		plat->ipc_enable = true;
		plat->tx_handle = &sdio_tx_handle;
	}
	
	ret = plat->cbp_setup(plat);
	if(ret){
		LOGPRT(LOG_ERR,  "%s: host %s setup failed!\n", __func__, plat->host_id);
		goto err_ipc;
	}
	cbp_power_kobj = c2k_kobject_add("power");
	if (!cbp_power_kobj){
		LOGPRT(LOG_ERR,  "error c2k_kobject_add!\n");
		ret = -ENOMEM;
		goto err_create_kobj;
	}
	LOGPRT(LOG_INFO,  " cbp initialized on host %s successfully, bus is %s !\n", plat->host_id, plat->bus);
	return sysfs_create_group(cbp_power_kobj, &g_power_attr_group);
	
err_create_kobj:
	plat->cbp_destroy();
err_ipc:
#if 0
	if(GPIO_C2K_VALID(plat->gpio_rst_ind)){
		free_irq(c2k_gpio_to_irq(plat->gpio_rst_ind), cbp_rst_ind);
	}
err_req_irq_rst_ind:
	if(GPIO_C2K_VALID(plat->gpio_rst_ind)){
	}
#endif

#ifndef CONFIG_EVDO_DT_VIA_SUPPORT
err_req_irq_excp:
	if(GPIO_C2K_VALID(plat->gpio_cp_exception)){
		destroy_workqueue(cbp_excp_ind->excp_wq);
	}
#endif
err_create_excp_work_queue:
		kfree(cbp_excp_ind);
err_kzalloc_cbp_excp_ind:

	if(GPIO_C2K_VALID(plat->gpio_rst_ind)){
		destroy_workqueue(cbp_rst_ind->reset_wq);
	}
err_create_work_queue:
	if(GPIO_C2K_VALID(plat->gpio_rst_ind)){
		kfree(cbp_rst_ind);
	}
err_kzalloc_cbp_rst_ind:
	if(GPIO_C2K_VALID(plat->gpio_flow_ctrl)){
		free_irq(c2k_gpio_to_irq(plat->gpio_flow_ctrl), cbp_flow_ctrl);
	}
err_req_irq_flow_ctrl:
	if(GPIO_C2K_VALID(plat->gpio_flow_ctrl)){
		kfree(cbp_flow_ctrl);
	}
err_kzalloc_cbp_flow_ctrl:
	if(GPIO_C2K_VALID(plat->gpio_data_ack)){
		free_irq(c2k_gpio_to_irq(plat->gpio_data_ack), cbp_data_ack);
	}
err_req_irq_data_ack:
	if(GPIO_C2K_VALID(plat->gpio_data_ack)){
		kfree(cbp_data_ack);
	}
err_kzalloc_cbp_data_ack:
out:
	return ret;
}
Esempio n. 4
0
static int cbp_probe(struct platform_device *pdev)
{
	struct cbp_platform_data *plat = NULL;
	int ret = -1;
	struct device *dev = &pdev->dev;
	struct device_node *np = dev->of_node;

	ret = platform_device_add_data(pdev, &cbp_data, sizeof(struct cbp_platform_data));
	if (ret < 0) {
		hwlog_err("%s: add platform_data failed!\n", __func__);
		goto err_add_data_to_platform_device;
	}

	plat = pdev->dev.platform_data;
	/* must have platform data */
	if (!plat) {
		hwlog_err("%s: no platform data!\n", __func__);
		ret = -EINVAL;
		goto err_add_data_to_platform_device;
	}

	plat->gpio_data_ack = of_get_named_gpio(np, "via_data_ack", 0);
	hwlog_info(">>>> %s get via_data_ack gpio %d\n", __func__, plat->gpio_data_ack);
	if(GPIO_OEM_VALID(plat->gpio_data_ack)){
		cbp_data_ack = kzalloc(sizeof(struct cbp_wait_event), GFP_KERNEL);
		if (!cbp_data_ack){
			ret = -ENOMEM;
			hwlog_err("%s %d kzalloc cbp_data_ack failed \n",__func__, __LINE__);
			goto err_kzalloc_cbp_data_ack;
		}

		init_waitqueue_head(&cbp_data_ack->wait_q);
		atomic_set(&cbp_data_ack->state, MODEM_ST_UNKNOW);
		cbp_data_ack->wait_gpio = plat->gpio_data_ack;
		cbp_data_ack->wait_polar = plat->gpio_data_ack_polar;
		hwlog_info("cbp_data_ack->wait_gpio=%d\n",cbp_data_ack->wait_gpio);
		hwlog_info("cbp_data_ack->wait_polar=%d\n",cbp_data_ack->wait_polar);
		ret = oem_gpio_request(plat->gpio_data_ack, DRIVER_NAME "(data_ack)");
		if(ret < 0){
			hwlog_err("%s: %d fail to requset data_ack gpio %d ret =%d!!\n",
				__func__, __LINE__, plat->gpio_data_ack, ret);
			goto err_req_data_ack;
		}
		oem_gpio_irq_mask(plat->gpio_data_ack);
		oem_gpio_direction_input_for_irq(plat->gpio_data_ack);
		//on powerup, there is ack low level to high level jump.
		oem_gpio_set_irq_type(plat->gpio_data_ack, IRQF_TRIGGER_FALLING);
		ret = oem_gpio_request_irq(plat->gpio_data_ack, gpio_irq_via_spi_tx_rx_fifo_empty_ack,
				IRQF_SHARED | IRQF_TRIGGER_FALLING, DRIVER_NAME "(data_ack)", cbp_data_ack);
		oem_gpio_irq_unmask(plat->gpio_data_ack);
		if (ret < 0) {
			hwlog_err("%s: %d fail to request irq for data_ack!!\n", __func__, __LINE__);
			goto err_req_irq_data_ack;
		}
		plat->cbp_data_ack = cbp_data_ack;
		plat->data_ack_wait_event = data_ack_wait_event;
		plat->data_ack_enable =true;
	}

	plat->gpio_flow_ctrl = of_get_named_gpio(np, "via_flow_ctrl", 0);
	hwlog_info(">>>> %s get via_flow_ctrl gpio %d\n", __func__, plat->gpio_flow_ctrl);
	if(GPIO_OEM_VALID(plat->gpio_flow_ctrl)){
		cbp_flow_ctrl = kzalloc(sizeof(struct cbp_wait_event), GFP_KERNEL);
		if (!cbp_flow_ctrl){
			ret = -ENOMEM;
			hwlog_err("%s %d kzalloc cbp_flow_ctrl failed \n",__func__, __LINE__);
			goto err_kzalloc_cbp_flow_ctrl;
		}

		init_waitqueue_head(&cbp_flow_ctrl->wait_q);
		atomic_set(&cbp_flow_ctrl->state, FLOW_CTRL_DISABLE);
		cbp_flow_ctrl->wait_gpio = plat->gpio_flow_ctrl;
		cbp_flow_ctrl->wait_polar = plat->gpio_flow_ctrl_polar;
		hwlog_info("cbp_flow_ctrl->wait_gpio=%d\n",cbp_flow_ctrl->wait_gpio);
		hwlog_info("cbp_flow_ctrl->wait_polar=%d\n",cbp_flow_ctrl->wait_polar);
		ret = oem_gpio_request(plat->gpio_flow_ctrl, DRIVER_NAME "(flow_ctrl)");
		if(ret < 0){
			hwlog_err("%s: %d fail to requset flow_ctrl gpio %d ret =%d!!\n",
				__func__, __LINE__, plat->gpio_flow_ctrl, ret);
			goto err_req_flow_ctrl;
		}
		oem_gpio_irq_mask(plat->gpio_flow_ctrl);
		oem_gpio_direction_input_for_irq(plat->gpio_flow_ctrl);
		oem_gpio_set_irq_type(plat->gpio_flow_ctrl, IRQF_TRIGGER_FALLING);
		ret = oem_gpio_request_irq(plat->gpio_flow_ctrl, gpio_irq_flow_ctrl,
				IRQF_SHARED | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
				DRIVER_NAME "(flow_ctrl)", cbp_flow_ctrl);
		oem_gpio_irq_unmask(plat->gpio_flow_ctrl);
		if (ret < 0) {
			hwlog_err("%s: %d fail to request irq for flow_ctrl!!\n", __func__, __LINE__);
			goto err_req_irq_flow_ctrl;
		}

		plat->cbp_flow_ctrl= cbp_flow_ctrl;
		plat->flow_ctrl_wait_event = flow_ctrl_wait_event;
		plat->flow_ctrl_enable = true;
	}

	plat->gpio_via_requst_to_send = of_get_named_gpio(np, "via_requst_to_send", 0);
	hwlog_info(">>>> %s get via_requst_to_send gpio %d\n", __func__, plat->gpio_via_requst_to_send);
	if(GPIO_OEM_VALID(plat->gpio_via_requst_to_send)){
		ret = oem_gpio_request(plat->gpio_via_requst_to_send, DRIVER_NAME "(via_requst_to_send)");
		if(ret < 0){
			hwlog_err("%s: %d fail to requset flow_ctrl gpio %d ret =%d!!\n",
				__func__, __LINE__, plat->gpio_via_requst_to_send, ret);
			goto err_req_via_requst_to_send;
		}
		oem_gpio_irq_mask(plat->gpio_via_requst_to_send);
		oem_gpio_direction_input_for_irq(plat->gpio_via_requst_to_send);
		oem_gpio_set_irq_type(plat->gpio_via_requst_to_send, IRQF_TRIGGER_FALLING);
		ret = oem_gpio_request_irq(plat->gpio_via_requst_to_send, gpio_irq_via_rts,
				IRQF_SHARED | IRQF_TRIGGER_RISING,
				DRIVER_NAME "(via_requst_to_send)", &cbp_data); //api request the fifth argu NOT NULL.
		oem_gpio_irq_unmask(plat->gpio_via_requst_to_send);
		if (ret < 0) {
			hwlog_err("%s: %d fail to request irq for via_requst_to_send!!\n", __func__, __LINE__);
			goto err_req_irq_via_requst_to_send;
		}
	}

	plat->gpio_rst_ind = of_get_named_gpio(np, "via_reset_ind", 0);
	hwlog_info(">>>> %s get rst_ind gpio %d\n", __func__, plat->gpio_rst_ind);
	if(GPIO_OEM_VALID(plat->gpio_rst_ind)){
		cbp_data.gpio_rst_ind= plat->gpio_rst_ind;
		cbp_data.gpio_rst_ind_polar = plat->gpio_rst_ind_polar;

		atomic_set(&cbp_rst_ind_finished, 0);
		plat->rst_ind_enable = true;
	}
	plat->gpio_ap_wkup_cp= of_get_named_gpio(np, "via_ap_wkup_cp", 0);
	hwlog_info(">>>> %s get ap_wkup_cp gpio %d\n", __func__, plat->gpio_ap_wkup_cp);

	plat->gpio_cp_ready= of_get_named_gpio(np, "via_cp_ready", 0);
	hwlog_info(">>>> %s get cp_ready gpio %d\n", __func__, plat->gpio_cp_ready);

	plat->gpio_cp_wkup_ap= of_get_named_gpio(np, "via_cp_wkup_ap", 0);
	hwlog_info(">>>> %s get cp_wkup_ap gpio %d\n", __func__, plat->gpio_cp_wkup_ap);

	plat->gpio_ap_ready= of_get_named_gpio(np, "via_ap_ready", 0);
	hwlog_info(">>>> %s get ap_ready gpio %d\n", __func__, plat->gpio_ap_ready);
	if((GPIO_OEM_VALID(plat->gpio_ap_wkup_cp)) && (GPIO_OEM_VALID(plat->gpio_cp_ready)) &&
		(GPIO_OEM_VALID(plat->gpio_cp_wkup_ap))  && (GPIO_OEM_VALID(plat->gpio_ap_ready))){
		spi_tx_handle.gpio_wake = plat->gpio_ap_wkup_cp;
		spi_tx_handle.gpio_ready = plat->gpio_cp_ready;
		spi_tx_handle.polar = plat->gpio_sync_polar;
		ret = asc_tx_register_handle(&spi_tx_handle);
		if(ret){
			hwlog_err("%s %d asc_tx_register_handle failed.\n",__FUNCTION__,__LINE__);
			goto err_ipc;
		}
		ret = asc_tx_add_user(spi_tx_handle.name, &spi_tx_user);
		if(ret){
			hwlog_err("%s %d asc_tx_add_user failed.\n",__FUNCTION__,__LINE__);
			goto err_ipc;
		}

		spi_rx_handle.gpio_wake = plat->gpio_cp_wkup_ap;
		spi_rx_handle.gpio_ready = plat->gpio_ap_ready;
		spi_rx_handle.polar = plat->gpio_sync_polar;
		ret = asc_rx_register_handle(&spi_rx_handle);
		if(ret){
			hwlog_err("%s %d asc_rx_register_handle failed.\n",__FUNCTION__,__LINE__);
			goto err_ipc;
		}
		ret = asc_rx_add_user(spi_rx_handle.name, &spi_rx_user);
		if(ret){
			hwlog_err("%s %d asc_rx_add_user failed.\n",__FUNCTION__,__LINE__);
			goto err_ipc;
		}
		plat->ipc_enable = true;
		plat->tx_handle = &spi_tx_handle;
	}

	ret = plat->cbp_setup(plat);
	if(ret){
		hwlog_err("%s: host %s setup failed!\n", __func__, plat->host_id);
		goto err_ipc;
	}

	cbp_power_kobj = viatel_kobject_add("power");
	if (!cbp_power_kobj){
		hwlog_err("error viatel_kobject_add!\n");
		ret = -ENOMEM;
		goto err_create_kobj;
	}

	hwlog_debug(" cbp initialized on host %s successfully, bus is %s !\n", plat->host_id, plat->bus);
	return sysfs_create_group(cbp_power_kobj, &g_power_attr_group);

err_create_kobj:
	plat->cbp_destroy();
err_ipc:
	if(GPIO_OEM_VALID(plat->gpio_via_requst_to_send)){
		free_irq(oem_gpio_to_irq(plat->gpio_via_requst_to_send), NULL);
	}
err_req_irq_via_requst_to_send:
	if(GPIO_OEM_VALID(plat->gpio_via_requst_to_send)){
		oem_gpio_free(plat->gpio_via_requst_to_send);
	}
err_req_via_requst_to_send:
	if(GPIO_OEM_VALID(plat->gpio_data_ack)){
		free_irq(oem_gpio_to_irq(plat->gpio_flow_ctrl), cbp_flow_ctrl);
	}
err_req_irq_flow_ctrl:
	if(GPIO_OEM_VALID(plat->gpio_flow_ctrl)){
		oem_gpio_free(plat->gpio_flow_ctrl);
	}
err_req_flow_ctrl:
	if(GPIO_OEM_VALID(plat->gpio_flow_ctrl)){
		kfree(cbp_flow_ctrl);
	}
err_kzalloc_cbp_flow_ctrl:
	if(GPIO_OEM_VALID(plat->gpio_data_ack)){
		free_irq(oem_gpio_to_irq(plat->gpio_data_ack), cbp_data_ack);
	}
err_req_irq_data_ack:
	if(GPIO_OEM_VALID(plat->gpio_data_ack)){
		oem_gpio_free(plat->gpio_data_ack);
	}
err_req_data_ack:
	if(GPIO_OEM_VALID(plat->gpio_data_ack)){
		kfree(cbp_data_ack);
	}
err_kzalloc_cbp_data_ack:
err_add_data_to_platform_device:
	return ret;
}