Пример #1
0
static int ifx_spi_probe(struct spi_device *spi)
{
     int status;
     struct ifx_spi_data *spi_data;
     

    spi_data = (struct ifx_spi_data*)kmalloc(sizeof(struct ifx_spi_data), GFP_KERNEL);
    if (!spi_data)
    {    
	IFX_SPI_PRINTK("Failed to allocate memory for spi_data");    
	return -ENOMEM;
    }

     IFX_SPI_PRINTK("start !!");

    //initialize all member variables of ifx_spi_data
    memset((void*)spi_data, 0, sizeof(struct ifx_spi_data));

	spi_data->ifx_tty = NULL;
#ifdef WAKE_LOCK_RESUME
	spi_data->wake_lock_flag = 0;
#endif

    status = ifx_spi_allocate_frame_memory(spi_data, (IFX_SPI_MAX_BUF_SIZE + IFX_SPI_HEADER_SIZE));
    if(status != 0)
    {
	IFX_SPI_PRINTK("Failed to allocate memory for buffers");
 	
	return -ENOMEM;
    }

    dev_set_drvdata(&spi->dev,spi_data);
    spin_lock_init(&spi_data->spi_lock);
    INIT_WORK(&spi_data->ifx_work,ifx_spi_handle_work);   
	
    spi_data->ifx_wq = create_singlethread_workqueue("ifxn721");
    if(!spi_data->ifx_wq)
    {
	IFX_SPI_PRINTK("Failed to setup workqueue - ifx_wq");          
    }
	
	init_completion(&spi_data->ifx_read_write_completion);
	
      //config srdy,mrdy gpio value according to hw revision
       IFX_MRDY = TEGRA_GPIO_PO0;  //ULPI_DATA7
       IFX_SRDY =  TEGRA_GPIO_PO5;  //ULPI_DATA4

        /* Configure SPI */
	spi_data->spi = spi;

	spi->mode = SPI_MODE_1 ;
	spi->bits_per_word = 8; //32 is mdm only
	spi->chip_select = 0 ;
	spi->max_speed_hz = 24000000; //48000000; //to 24Mhz	

	status = spi_setup(spi);
        if(status < 0)
	{
		IFX_SPI_PRINTK("Failed to setup SPI \n");
        }             

#ifdef WAKE_LOCK_RESUME
	wake_lock_init(&spi_data->wake_lock, WAKE_LOCK_SUSPEND, "mspi_wake");
#endif

	gpio_request(IFX_MRDY, "ifx_mrdy");	
 	tegra_gpio_enable(IFX_MRDY);
		
	gpio_request(IFX_SRDY, "ifx_srdy");	
 	tegra_gpio_enable(IFX_SRDY);	
	
	gpio_direction_input(IFX_SRDY);

/* changed to level trigger */

	status = request_irq(gpio_to_irq(IFX_SRDY), 
					    ifx_spi_handle_srdy_irq,
					    IRQF_TRIGGER_RISING, 
					    spi->dev.driver->name, 
					    spi_data);

	if (status != 0)
	{
		IFX_SPI_PRINTK("Failed to request IRQ for SRDY");
		IFX_SPI_PRINTK("IFX SPI Probe Failed");
		ifx_spi_free_frame_memory(spi_data);
		if(spi_data)
		{
			kfree(spi_data);
		}          
	}
 	else
	{
		ifx_gspi_data = spi_data;
	}

	enable_irq_wake(gpio_to_irq(IFX_SRDY)); //wake irq...	
	
	IFX_SPI_PRINTK(" end !!!  ");
	return status;
}
static int
ifx_spi_probe(struct spi_device *spi)
{
	int status;
	struct ifx_spi_data *spi_data;
	/* Allocate SPI driver data */
	spi_data = (struct ifx_spi_data*)kmalloc(sizeof(struct ifx_spi_data), GFP_KERNEL);
	memset(spi_data, 0, sizeof(struct ifx_spi_data)) ;

	if (!spi_data){
		return -ENOMEM;
    }

    status = ifx_spi_allocate_frame_memory(IFX_SPI_MAX_BUF_SIZE + IFX_SPI_HEADER_SIZE);
    if(status != 0){
	printk("File: ifx_n721_spi.c\tFunction: int ifx_spi_probe\tFailed to allocate memory for buffers\n");
	return -ENOMEM;
    }

    dev_set_drvdata(&spi->dev,spi_data);
    spin_lock_init(&spi_data->spi_lock);

    spi_data->ifx_wq = create_singlethread_workqueue("ifxn721");
    if(!spi_data->ifx_wq){
		printk("Failed to setup workqueue - ifx_wq \n");
    }
	INIT_WORK(&spi_data->ifx_work,ifx_spi_handle_work);

	init_completion(&spi_data->ifx_read_write_completion);

        /* Configure SPI */

	spi_data->spi = spi;
#if 1
	// spi->mode = SPI_MODE_1 | SPI_CS_HIGH | SPI_NO_CS;
	spi->mode = SPI_MODE_1 | SPI_CS_HIGH | SPI_NO_CS;
	// spi->mode = SPI_MODE_0 | SPI_CS_HIGH ;
    // spi->bits_per_word = 8;
    spi->bits_per_word = 8;
	spi->max_speed_hz = SPI_CLOCK;
	spi->chip_select = 0 ;
	//spi->irq = gpio_to_irq(TEGRA_GPIO_PO5);//0;
	memcpy(spi->modalias, "ifxn721", sizeof("ifxn721")) ;
//
#endif
	status = spi_setup(spi);
    if(status < 0){
		printk("Failed to setup SPI \n");
    }

// hgahn
//	spi_data->ifx_spi_lock =1;

	/* Enable SRDY Interrupt request - If the SRDY signal is high then ifx_spi_handle_srdy_irq() is called */
	//status = request_irq(spi->irq, ifx_spi_handle_srdy_irq,  IRQF_TRIGGER_RISING, spi->dev.driver->name, spi_data);

	gpio_request(TEGRA_GPIO_PO0, "ifx_mrdy");
 	tegra_gpio_enable(TEGRA_GPIO_PO0);

	gpio_request(TEGRA_GPIO_PO5, "ifx_srdy");
 	tegra_gpio_enable(TEGRA_GPIO_PO5);

	// gpio_set_value(TEGRA_GPIO_PO0, 0);
	gpio_direction_output(TEGRA_GPIO_PO0, 0);

	gpio_direction_input(TEGRA_GPIO_PO5);
	spi->irq = gpio_to_irq(TEGRA_GPIO_PO5) ;

    // enable gpios for modem shutdown
    //tegra_gpio_enable(GPIO_IFX_RESET_1V8_N);
    //tegra_gpio_enable(GPIO_IFX_PWRON_1V8);

    //gpio_request_one(GPIO_IFX_RESET_1V8_N, GPIOF_IN, "modem_reset_n");
    //gpio_request_one(GPIO_IFX_PWRON_1V8, GPIOF_OUT_INIT_HIGH, "modem_pwron");

	spi_data->is_suspend = 0 ;
	spi_data->packet_count = 0 ;
	status = request_irq(spi->irq, ifx_spi_handle_srdy_irq,IRQF_TRIGGER_RISING ,spi->dev.driver->name, spi_data);
	if(is_modem_connected()){
		set_irq_wake(spi->irq, 1);
	}
	else {
		disable_irq(spi->irq);
	}

//20100927-1, [email protected], Hold wake-lock for cp interrupt [START]
#ifdef WAKE_LOCK_RESUME
	wake_lock_init(&spi_data->wake_lock, WAKE_LOCK_SUSPEND, "mspi_wake");
	spi_data->wake_lock_flag = 0;
#endif
//20100927-1, [email protected], Hold wake-lock for cp interrupt [END]

	if (status != 0){
		printk(KERN_ERR "Failed to request IRQ for SRDY\n");
		printk(KERN_ERR "IFX SPI Probe Failed\n");
		if(ifx_tx_buffer){
			kfree(ifx_tx_buffer);
		}
		if(ifx_rx_buffer){
			kfree(ifx_rx_buffer);
		}
		if(spi_data){
			kfree(spi_data);
		}
	}
	else{
		gspi_data = spi_data;
	}
/////////////////////////////////////////////////////////////////////////////////////////////
// jeehp
//        enable_irq_wake(spi->irq);
////////////////////////////////////////////////////////////////////////////////////////////
	printk("**** %s \n",__FUNCTION__);
	return status;
}
Пример #3
0
static int 
ifx_spi_probe(struct spi_device *spi)
{
	int ret;
	int status;
	int err;
	struct ifx_spi_data *spi_data;

	printk("[e] ifx_spi_probe\n");

	/* Allocate SPI driver data */
	spi_data = (struct ifx_spi_data*)kmalloc(sizeof(struct ifx_spi_data), GFP_KERNEL);
	if (!spi_data){
		return -ENOMEM;
        }

        status = ifx_spi_allocate_frame_memory(IFX_SPI_MAX_BUF_SIZE + IFX_SPI_HEADER_SIZE);
        if(status != 0){
		printk("File: ifx_n721_spi.c\tFunction: int ifx_spi_probe\tFailed to allocate memory for buffers\n");
		// WBT DEFECT FIX [email protected]
		kfree(spi_data);
		// WBT DEFECT FIX [email protected]
		return -ENOMEM;
        }
	
        dev_set_drvdata(&spi->dev,spi_data);
        spin_lock_init(&spi_data->spi_lock);
        INIT_WORK(&spi_data->ifx_work,ifx_spi_handle_work);
		printk("[e] INIT_WORK\n");

        spi_data->ifx_wq = create_singlethread_workqueue("ifxn721");
        if(!spi_data->ifx_wq){
		printk("Failed to setup workqueue - ifx_wq \n");          
        }
	init_completion(&spi_data->ifx_read_write_completion);

        /* Configure SPI */
        spi_data->spi = spi;
        spi->mode = SPI_MODE_1;
        spi->bits_per_word = 8;
        status = spi_setup(spi);
        if(status < 0){
			printk("Failed to setup SPI \n");
        }             

// hgahn
	spi_data->ifx_spi_lock =1;

	/* Enable SRDY Interrupt request - If the SRDY signal is high then ifx_spi_handle_srdy_irq() is called */
	status = request_irq(spi->irq, ifx_spi_handle_srdy_irq,  IRQF_TRIGGER_RISING, spi->dev.driver->name, spi_data);
	printk("[e] spi->irq:%d  status:%d\n", spi->irq, status);
	if (status != 0){
		printk(KERN_ERR "Failed to request IRQ for SRDY\n");
		printk(KERN_ERR "IFX SPI Probe Failed\n");
		if(ifx_tx_buffer){
			kfree(ifx_tx_buffer);
		}
		if(ifx_rx_buffer){
			kfree(ifx_rx_buffer);            
		}
		if(spi_data){
			kfree(spi_data);
		}          
	}
	else{
		gspi_data = spi_data;
	}
        /////////////////////////////////////////////////////////////////////////////////////////////
// jeehp
        enable_irq_wake(spi->irq);
//LGE_CHANGE [[email protected]] use MODEM_SNED pin as sleep status of AP.
	ret = gpio_request(MODEM_SEND, "MODEM_SEND");
	if (ret < 0) {
		printk(KERN_ERR "%s: Failed to request GPIO_%d for MODEM_SEND\n", __func__, MODEM_SEND);
		return -ENOSYS;
	}
        gpio_direction_output(MODEM_SEND,1);
        gpio_set_value(MODEM_SEND,1);
////////////////////////////////////////////////////////////////////////////////////////////


// [email protected]  20110105 CP Crash INT [START]
	#define CP_CRASH_INT_N  26
	
	/* Assign GPIO  */
	ret = gpio_request(CP_CRASH_INT_N, "CP CRASH IRQ GPIO");
	if (ret < 0) {
		printk(KERN_INFO "[CP CRASH IRQ] GPIO#%03d is already occupied by other driver!\n", CP_CRASH_INT_N);
		return -ENOSYS;
	}

	/* Initializes GPIO direction before use or IRQ setting */
	ret = gpio_direction_input(CP_CRASH_INT_N);
	if (ret < 0) {
		printk(KERN_INFO "[CP CRASH IRQ] GPIO#%03d direction initialization failed!\n", CP_CRASH_INT_N);
		return -ENOSYS;
	}

	/* Registers MUIC work queue function */

	INIT_WORK(&CP_CRASH_INT_wq, CP_CRASH_wq_func);
// CHEOLGWAK  2011-5-14 delayed work queue
	INIT_DELAYED_WORK(&cp_crash_int_delayed_wq, CP_CRASH_wq_func);
// CHEOLGWAK  2011-5-14 delayed work queue
	/* 
	 * Set up an IRQ line and enable the involved interrupt handler.
	 * From this point, a MUIC_INT_N can invoke muic_interrupt_handler().
	 * muic_interrupt_handler merely calls schedule_work() with muic_wq_func().
	 * muic_wq_func() actually performs the accessory detection.
	 */
#ifdef CONFIG_MACH_LGE_COSMO_DOMASTIC
	ret = request_irq(gpio_to_irq(CP_CRASH_INT_N), CP_CRASH_interrupt_handler, IRQF_TRIGGER_FALLING, "cp_crash_irq", &spi->dev);
#else
	ret = request_irq(gpio_to_irq(CP_CRASH_INT_N), CP_CRASH_interrupt_handler, IRQF_TRIGGER_RISING, "cp_crash_irq", &spi->dev);
#endif
	if (ret < 0) {
		printk(KERN_INFO "[CP CRASH IRQ] GPIO#%03d IRQ line set up failed!\n", CP_CRASH_INT_N);
		free_irq(gpio_to_irq(CP_CRASH_INT_N), &spi->dev);
		return -ENOSYS;
	}
// [email protected]  20110105 CP Crash INT [END]

#ifndef ENABLE_CP_CRASH_RESET
	//20110301 eunae.kim LGE_RIL_RECOVERY
	in_dev = input_allocate_device();
	if (!in_dev) {
		printk("Can't allocate power button\n");
		return -ENOMEM;
	}

	in_dev->evbit[0] = BIT_MASK(EV_KEY);
	in_dev->keybit[BIT_WORD(EVENT_KEY)] = BIT_MASK(EVENT_KEY);
	in_dev->name = "ifxn721";
	in_dev->phys = "ifxn721/input0";
	in_dev->dev.parent = &spi->dev;

	err = input_register_device(in_dev);
	if (err) {
		printk("Can't register EVENT_KEY button: %d\n", err);
	}

#endif

	return status;
}