static int __init hs_probe(struct platform_device *pdev)
{
    int result;
    mic.hsmajor = 0;
    mic.headset_state = 0;
    mic.hsbtime.tv.sec = 0;
    mic.hsbtime.tv.nsec = 0;
    mic.headset_pd = NULL;
#ifdef CONFIG_SWITCH
    result = hs_switchinit(&mic);
    if (result < 0) {
        return result;
    }
#endif
    result = hs_inputdev(&mic);
    if (result < 0) {
        goto err;
    }
    result = register_chrdev(mic.hsmajor, "BrcmHeadset", &hs_fops);
    if(result < 0)
    {
	goto err1;
    }
    else if(result > 0 && (mic.hsmajor == 0))    /* this is for dynamic major */
    {
        mic.hsmajor = result;
    }

    /* check if platform data is defined for a particular board variant */
    if (pdev->dev.platform_data)
    {
         mic.headset_pd = pdev->dev.platform_data;
         if (mic.headset_pd->hsgpio == NULL)
         {
             mic.hsirq = mic.headset_pd->hsirq;
         }
         else
         {
		bcm_gpio_set_db_val(mic.headset_pd->hsgpio, 0x7);
             if (gpio_request(mic.headset_pd->hsgpio, "headset detect") < 0)
		       {
	              pr_info("Could not reserve headset signal GPIO!\n");
			       goto err2;
		       }
            gpio_direction_input(mic.headset_pd->hsgpio);
            mic.hsirq = gpio_to_irq(mic.headset_pd->hsgpio);
         }
       mic.hsbirq = mic.headset_pd->hsbirq;
    }
    else
    {
     	mic.hsirq = platform_get_irq(pdev, 0);
     	mic.hsbirq = platform_get_irq(pdev, 1);
    }
    pr_info("HS irq %d\n",mic.hsirq);
    pr_info("HSB irq %d\n",mic.hsbirq);
#if defined(CONFIG_HAS_WAKELOCK)
    wake_lock_init(&headsetbutton_wake_lock, WAKE_LOCK_SUSPEND, "BrcmHeadsetButton");
#endif
    result = request_irq(mic.hsbirq, hs_buttonisr, IRQF_NO_SUSPEND, "BrcmHeadsetButton",  (void *) NULL);
    mic.hsbst = 1; /* Disabled */
    disable_irq(mic.hsbirq);
    if(result < 0)
    {
	goto err2;
    }
    result = request_irq(mic.hsirq, hs_isr,(IRQF_TRIGGER_RISING|IRQF_TRIGGER_FALLING|IRQF_NO_SUSPEND), "BrcmHeadset",  &mic);
    if(result < 0)
    {
	free_irq(mic.hsbirq, &mic);
	goto err2;
    }

    /* Check if the thresholds have been set for a particular board */
    if (!mic.headset_pd->keypress_threshold_lp)
        mic.headset_pd->keypress_threshold_lp = KEYPRESS_THRESHOLD;

    if (!mic.headset_pd->keypress_threshold_fp)
        mic.headset_pd->keypress_threshold_fp = KEYPRESS_THRESHOLD;

    /* Set the ANACR2 bit for mic power down */
    board_sysconfig(SYSCFG_HEADSET, SYSCFG_INIT);

    board_sysconfig(SYSCFG_AUXMIC, SYSCFG_INIT);
    
    if (mic.headset_pd->check_hs_state)
	writel(AUDIO_RX_LDO_OFF(readl(io_p2v(REG_ANACR2))), io_p2v(REG_ANACR2));

    /*Fix the audio path is wrong when headset already plugged in the device  then boot device case.*/
    hs_isr(mic.hsirq,&mic);
    return 0;
err2:   unregister_chrdev(mic.hsmajor,"BrcmHeadset");
err1:   hs_unreginputdev(&mic);
	input_free_device(&mic.headset_button_idev);
err:    hs_unregsysfs(&mic);
	return result;
}
static int __init hs_probe(struct platform_device *pdev)
{
	int result = 0;
	mic.hsmajor = 0;
	mic.headset_state = 0;
	mic.hsbtime.tv.sec = 0;
	mic.hsbtime.tv.nsec = 0;
	mic.headset_pd = NULL;
	mic.check_count = 0;

#ifdef CONFIG_SWITCH
	result = hs_switchinit(&mic);
	if (result < 0)
		return result;
#endif

	result = hs_inputdev(&mic);
	if (result < 0)
		goto err;

	result = register_chrdev(mic.hsmajor, "BrcmHeadset", &hs_fops);
	if(result < 0)
		goto err1;
	else if(result > 0 && (mic.hsmajor == 0))    /* this is for dynamic major */
		mic.hsmajor = result;

	wake_lock_init(&mic.det_wake_lock, WAKE_LOCK_SUSPEND, "sec_jack_det");
	INIT_DELAYED_WORK(&(mic.imsi_work), getIMSI_work_func);

	/* check if platform data is defined for a particular board variant */
	if (pdev->dev.platform_data)
	{
		mic.headset_pd = pdev->dev.platform_data;

		KEY_PRESS_THRESHOLD = mic.headset_pd->key_press_threshold;
		KEY_3POLE_THRESHOLD = mic.headset_pd->key_3pole_threshold;
		KEY1_THRESHOLD_L = mic.headset_pd->key1_threshold_l;
		KEY1_THRESHOLD_U = mic.headset_pd->key1_threshold_u;
		KEY2_THRESHOLD_L = mic.headset_pd->key2_threshold_l;
		KEY2_THRESHOLD_U = mic.headset_pd->key2_threshold_u;
		KEY3_THRESHOLD_L = mic.headset_pd->key3_threshold_l;
		KEY3_THRESHOLD_U = mic.headset_pd->key3_threshold_u;

		if (mic.headset_pd->hsgpio == NULL)
			mic.hsirq = mic.headset_pd->hsirq;
		else
		{
			setup_timer(&mic.timer, gpio_jack_timer, (unsigned long)&mic); // timer register. 

			if (gpio_request(mic.headset_pd->hsgpio, "headset detect") < 0)
			{
				printk("%s: Could not reserve headset signal GPIO!\n", __func__);
				goto err2;
			}
			gpio_direction_input(mic.headset_pd->hsgpio);
			bcm_gpio_set_db_val(mic.headset_pd->hsgpio, 0x7);
			mic.hsirq = gpio_to_irq(mic.headset_pd->hsgpio);
		}
		mic.hsbirq = mic.headset_pd->hsbirq;
	}
	else
	{
		mic.hsirq = platform_get_irq(pdev, 0);
		mic.hsbirq = platform_get_irq(pdev, 1);
	}

	printk("%s: HS irq %d\n", __func__, mic.hsirq);
	printk("%s: HSB irq %d\n", __func__, mic.hsbirq);
	result = request_irq(mic.hsbirq, hs_buttonisr,  IRQF_NO_SUSPEND, "BrcmHeadsetButton",  (void *) NULL);
	mic.hsbst = DISABLE;

	if(result < 0)
		goto err2;

	result = request_irq(mic.hsirq, hs_isr,(IRQF_DISABLED | IRQF_TRIGGER_RISING|IRQF_TRIGGER_FALLING | IRQF_NO_SUSPEND), "BrcmHeadset",  &mic);
	if(result < 0)
	{
		free_irq(mic.hsbirq, &mic);
		goto err2;
	}

	printk("%s: BrcmHeadset: module inserted >>>> . Major number is = %d\n", __func__, mic.hsmajor);

	/* Set the ANACR2 bit for mic power down */
	board_sysconfig(SYSCFG_AUXMIC, SYSCFG_INIT);
	board_sysconfig(SYSCFG_HEADSET, SYSCFG_INIT);

	/*Fix the audio path is wrong when headset already plugged in the device  then boot device case.*/
	if (mic.headset_pd->hsgpio != NULL)
	{
		mic.headset_pd->check_hs_state(&mic.headset_state);
		printk("%s: headset_state:%d\n", __func__, mic.headset_state); 
		set_irq_type(mic.hsirq, (mic.headset_state) ? IRQF_TRIGGER_RISING : IRQF_TRIGGER_FALLING);
		schedule_work(&(mic.switch_data.work));
		schedule_delayed_work(&(mic.imsi_work), GET_IMSI_REF_TIME);
	}

	return 0;

err2:   unregister_chrdev(mic.hsmajor,"BrcmHeadset");
	if(mic.headset_pd->hsgpio)
		del_timer_sync(&mic.timer);
err1:   hs_unreginputdev(&mic);
err:    hs_unregsysfs(&mic);
	return result;
}