static ssize_t sled_reset(struct device *dev, struct device_attribute *attr,
			 const char *buf, size_t count)
{
    unsigned long value = simple_strtoul(buf, NULL, 10);

    if (value == 1) {
        SN3193_TurnOffOut_sled();
        SN3193_enable_sled(0);
        return count;
    } else {
        return count;
    }
}
static ssize_t sled_blink_store(struct device *dev, struct device_attribute *attr,
			 const char *buf, size_t count)
{
	unsigned long value = simple_strtoul(buf, NULL, 10);
	u8 t13,t2,t4;
	if(shine_debug) {
		printk("shineled----%s:   buf = %s: count = %d\n", __func__, buf, count);
		printk("shineled----%s:   totalMS = %d: onMS = %d\n", __func__, totalMS, onMS);

	}
	//if(value == 1 && totalMS && onMS)
	if(~(~value) && totalMS && onMS)
	{

		SN3193_TurnOnRGB_sled();	//turn on the RGB color
			
		SN3193_enable_sled(1);
		SN3193_config_feature_sled(0);
		SN3193_workmod_sled(1);		//select the program mode, for breath effect.

		SN3193_setCurrent_sled(0x01);

		t13 = get_register_t((onMS * 4) / 9);
		t2 = get_register_t(onMS  / 9);
		t4 = get_register_t(totalMS - onMS) + 1;

		if(shine_debug) {
			printk("shineled----%s:   t13 = %d: t2 = %d t4 = %d\n", __func__, t13, t2,t4);
		}
		SN3193_SetBreathTime_sled(1,0,t13,t2,t13, t4);
		SN3193_SetBreathTime_sled(2,0,t13,t2,t13, t4);
		SN3193_SetBreathTime_sled(3,0,t13,t2,t13, t4);

		SN3193_TimeUpdate_sled();	//start breath	

		SN3193_upData_sled();		//turn on the light
		
	}
	else
	{
		if(shine_debug) {
			printk("shineled----%s:   color_R = %d: color_G = %d: color_B = %d,\n", __func__, color_R, color_G,color_B);
		}
		if(color_R + color_G + color_B == 0)
		{
			//close
			SN3193_TurnOffOut_sled();
			SN3193_enable_sled(0);
		}
		else
		{
			SN3193_TurnOnRGB_sled();	//turn on the RGB color
			//light aways
			SN3193_enable_sled(1);			
			SN3193_config_feature_sled(0);	
			SN3193_workmod_sled(0); 	//select the RGB mode, 		
			SN3193_setCurrent_sled(0x01);
			SN3193_upData_sled();		//turn on the light
		}
	}
	
	return count;
}
static long SN3193_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{
	struct SN3193_sled *info = file->private_data;
   	unsigned int val;
	  /*
           t[0]:channel
           t[1]:T0
           t[2]:T1
           t[3]:T2
           t[4]:T3
           t[5]:T4
	  */
      u8 t[6];
      long r=0;

	switch (cmd) {
	case SLED_ENABLE:
		SN3193_enable_sled(1);
		SN3193_setCurrent_sled(0x01);
		pr_info("%s:enable sled\n",__func__);
		break;
	case SLED_DISABLE:		
		RGBctl = 0x00;
		SN3193_TurnOffOut_sled();
		SN3193_enable_sled(0);
             // mod_timer(&SN3193_sled_dev_sate->gsled_last_timer,0xffffffffL);
		pr_info("%s:disable sled\n",__func__);
		break;
	case SLED_SET_WORKMOD:
		if (copy_from_user(&val,(void __user *)arg, sizeof(unsigned int))) {
			r = -EFAULT;
		}
		pr_info("%s;set sled work mod ,val:%d\n",__func__,val);
		SN3193_workmod_sled(val);  //now we should set to val to 0
		break;
	case SLED_CONFIG_FEATURE:
		if (copy_from_user(&val,(void __user *)arg, sizeof(unsigned int))) {
			r = -EFAULT;
		}
		pr_info("%s;set stagnate mod,val:%d\n",__func__,val);
		SN3193_config_feature_sled(val);
		break;
	case SLED_SET_BTEATHTIME:
		if (copy_from_user(t,(void __user *)arg, sizeof(unsigned int))) {
			r = -EFAULT;
		}
		pr_info("%s;set stagnate modl:%d,%d,%d,%d,%d\n",__func__,t[1],t[2],t[3],t[4],t[5]);
		SN3193_SetBreathTime_sled(t[0],t[1],t[2],t[3],t[4],t[5]);
		SN3193_TimeUpdate_sled();
		break;
	case SLED_SET_RED :
		if (copy_from_user(&val,(void __user *)arg, sizeof(unsigned int))) {
			r = -EFAULT;
		}
/*OPPO yuyi 2014-01-07 modify begin for abandon red and green light*/
#ifndef CONFIG_MACH_MSM8974_14001
//ZhangPan@Mobile Phone Software Dept.Driver, 2013/12/19, Modify for blue_led
		RGBctl = RGBctl |0x01;
#else /* CONFIG_MACH_MSM8974_14001 */
		RGBctl = RGBctl |0x04;
#endif /* CONFIG_MACH_MSM8974_14001 */
/*OPPO yuyi 2014-01-07 modify end for abandon red and green light*/
		SN3193_TurnOnOut_sled(RGBctl);
		SN3193_SetBrightness(RED_SLED,val);
		SN3193_upData_sled();
		pr_info("%s:set sled red,val:%d\n",__func__,val);
		break;
	case SLED_SET_GREEEN:
		if (copy_from_user(&val,(void __user *)arg, sizeof(unsigned int))) {
			r = -EFAULT;
		}
/*OPPO yuyi 2014-01-07 modify begin for abandon red and green light*/
#ifndef CONFIG_MACH_MSM8974_14001
//ZhangPan@Mobile Phone Software Dept.Driver, 2013/12/19, Modify for blue_led
		RGBctl = RGBctl |0x02;
#else /* CONFIG_MACH_MSM8974_14001 */
		RGBctl = RGBctl |0x04;
#endif /* CONFIG_MACH_MSM8974_14001 */
/*OPPO yuyi 2014-01-07 modify end for abandon red and green light*/
		SN3193_TurnOnOut_sled(RGBctl);
		SN3193_SetBrightness(GREEN_SLED,val);
		SN3193_upData_sled();
		pr_info("%s:set sled green,val:%d\n",__func__,val);
		break;
      case SLED_SET_BLUE:
	  	if (copy_from_user(&val,(void __user *)arg, sizeof(unsigned int))) {
			r = -EFAULT;
		}
		RGBctl = RGBctl |0x04;
		SN3193_TurnOnOut_sled(RGBctl);
		SN3193_SetBrightness(BLUE_SLED,val);
		SN3193_upData_sled();
		pr_info("%s:set sled blue,val:%d\n",__func__,val);
		break;
	/*case SLED_SET_LASTTIME:
		if (copy_from_user(&val,(void __user *)arg, sizeof(unsigned int))) {
			r = -EFAULT;
		}
		pr_info("%s;set sledlast time,val:%d\n",__func__,val);
		mod_timer(&SN3193_sled_dev_sate->gsled_last_timer,jiffies+val*HZ);
		break;*/

	/*
	case SET_RED_BREATHE:case SET_GREEN_BREATHE:case SET_BLUE_BREATHE: 
	just for debug in EngineeringMode
	*/
	case SET_RED_BREATHE:
		if (copy_from_user(&val,(void __user *)arg, sizeof(unsigned int))) {
			r = -EFAULT;
		}
/*OPPO yuyi 2014-01-07 modify begin for abandon red and green light*/
#ifndef CONFIG_MACH_MSM8974_14001
//ZhangPan@Mobile Phone Software Dept.Driver, 2013/12/19, Modify for blue_led
		SN3193_TurnOnOut_sled((1<<RED_SLED));
#else /* CONFIG_MACH_MSM8974_14001 */
		SN3193_TurnOnOut_sled((1<<BLUE_SLED));
#endif /* CONFIG_MACH_MSM8974_14001 */
/*OPPO yuyi 2014-01-07 modify end for abandon red and green light*/
		SN3193_SetBrightness(RED_SLED,val);

		SN3193_enable_sled(1);
		SN3193_config_feature_sled(0);
		SN3193_workmod_sled(1); 
		SN3193_setCurrent_sled(0x01);
		  
		SN3193_SetBreathTime_sled(1,0,1,2,1,4);
			
		SN3193_TimeUpdate_sled();
		SN3193_upData_sled();
		break;
	case SET_GREEN_BREATHE:
		if (copy_from_user(&val,(void __user *)arg, sizeof(unsigned int))) {
			r = -EFAULT;
		}
/*OPPO yuyi 2014-01-07 modify begin for abandon red and green light*/
#ifndef CONFIG_MACH_MSM8974_14001
//ZhangPan@Mobile Phone Software Dept.Driver, 2013/12/19, Modify for blue_led
		SN3193_TurnOnOut_sled((1<<GREEN_SLED));
#else /* CONFIG_MACH_MSM8974_14001 */
		SN3193_TurnOnOut_sled((1<<BLUE_SLED));
#endif /* CONFIG_MACH_MSM8974_14001 */
/*OPPO yuyi 2014-01-07 modify end for abandon red and green light*/
		SN3193_SetBrightness(GREEN_SLED,val);

		SN3193_enable_sled(1);
		SN3193_config_feature_sled(0);
		SN3193_workmod_sled(1); 
		SN3193_setCurrent_sled(0x01);
		
		SN3193_SetBreathTime_sled(2,0,1,2,1,4);
		SN3193_TimeUpdate_sled();
		SN3193_upData_sled();
		break;
	case SET_BLUE_BREATHE:
	  	if (copy_from_user(&val,(void __user *)arg, sizeof(unsigned int))) {
			r = -EFAULT;
		}
		SN3193_TurnOnOut_sled((1<<BLUE_SLED));
		SN3193_SetBrightness(BLUE_SLED,val);
		 
		SN3193_enable_sled(1);
		SN3193_config_feature_sled(0);
		SN3193_workmod_sled(1); 
		SN3193_setCurrent_sled(0x01);	 
/*OPPO yuyi 2014-01-09 modify begin for different effect*/	
	#ifndef  CONFIG_MACH_MSM8974_14001
		SN3193_SetBreathTime_sled(3,0,1,2,1,4);
	#else
		SN3193_SetBreathTime_sled(3,0,4,3,4,5);
	#endif
/*OPPO yuyi 2014-01-09 modify end for different effect*/
		SN3193_TimeUpdate_sled();
		SN3193_upData_sled();
		break;	
	case SET_RED_OFF:
/*OPPO yuyi 2014-01-07 modify begin for abandon red and green light*/
#ifndef CONFIG_MACH_MSM8974_14001
//ZhangPan@Mobile Phone Software Dept.Driver, 2013/12/19, Modify for blue_led
		RGBctl = RGBctl & 0xFE;
#else /* CONFIG_MACH_MSM8974_14001 */
		RGBctl = RGBctl & 0xFB;
#endif /* CONFIG_MACH_MSM8974_14001 */
/*OPPO yuyi 2014-01-07 modify end for abandon red and green light*/
		SN3193_TurnOnOut_sled(RGBctl);
		SN3193_upData_sled();
		break;
	case SET_GREEN_OFF:
/*OPPO yuyi 2014-01-07 modify begin for abandon red and green light*/
#ifndef CONFIG_MACH_MSM8974_14001
//ZhangPan@Mobile Phone Software Dept.Driver, 2013/12/19, Modify for blue_led
		RGBctl = RGBctl & 0xFD;
#else /* CONFIG_MACH_MSM8974_14001 */
		RGBctl = RGBctl & 0xFB;
#endif /* CONFIG_MACH_MSM8974_14001 */
/*OPPO yuyi 2014-01-07 modify end for abandon red and green light*/
		SN3193_TurnOnOut_sled(RGBctl);
		SN3193_upData_sled();
		break;
	case SET_BLUE_OFF:
		RGBctl = RGBctl & 0xFB;
		SN3193_TurnOnOut_sled(RGBctl);
		SN3193_upData_sled();
		break;
	default:
		dev_err(&info->i2c_dev->dev, "Unknown ioctl 0x%x\n", cmd);
		r = -ENOIOCTLCMD;
		break;
	}
     return r;
}
static int SN3193_probe(struct i2c_client *client, const struct i2c_device_id *id)
{
	int ret=0;
	int i;
    	struct SN3193_sled * sn3193_sled_dev;

	//client->dev.platform_data = &rgb_pdata;

	SN3193_power();
	msleep(100);
	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
		pr_err("%s : need I2C_FUNC_I2C\n", __func__);
		return  -ENODEV;
		}
       SN3193_sled_dev_sate->gi2c_dev=client;
	sn3193_sled_dev = kzalloc(sizeof(struct SN3193_sled), GFP_KERNEL);
	if (sn3193_sled_dev == NULL) {
		dev_err(&client->dev,
				"failed to allocate memory for module data\n");
		ret = -ENOMEM;
		goto err_exit;
	}
	pr_info("%s:sn3193 probe\n",__func__);
	sn3193_sled_dev->i2c_dev   = client;
	sn3193_sled_dev->SN3193_miscdev.minor = MISC_DYNAMIC_MINOR;
	sn3193_sled_dev->SN3193_miscdev.name = "SN3193";
	sn3193_sled_dev->SN3193_miscdev.fops = &SN3193_fops;

	ret = misc_register(&sn3193_sled_dev->SN3193_miscdev);
	if (ret) {
		pr_err("%s : misc_register failed\n", __FILE__);
		goto err_misc_register;
	}

	for(i = 0; i < 3; i ++ )
	{
		if (led_classdev_register(&client->dev, &SN3193_lcds[i]))
		{
			printk(KERN_ERR "led_classdev_register failed of SN3193_lcds!\n");
			goto err_classdev_register;
		}
	}
	
	ret = sysfs_create_group(&client->dev.kobj, &blink_attr_group);
	if (ret) {
		pr_err( "%s : sysfs_create_group failed!\n", __func__);
		goto err_group_register;
	}

	i2c_set_clientdata(client, sn3193_sled_dev);

	//SN3193_config_feature_sled(0);		//dvt not breath

	//close, light as need
	SN3193_SetBrightness(RED_SLED,0);
	SN3193_SetBrightness(GREEN_SLED,0);
	SN3193_SetBrightness(BLUE_SLED,0);
	SN3193_upData_sled();
	SN3193_TurnOffOut_sled();
	SN3193_enable_sled(0);


	/**************************test*********************/
	//enable sled
	/*SN3193_enable_sled(1);
       SN3193_config_feature_sled(0x00);
	SN3193_workmod_sled(1);
	SN3193_setCurrent_sled(0x01);*/
        //SN3193_enable_diff_color_sled(BLUE_SLED);
        //mod_timer(&SN3193_sled_dev_sate->gsled_last_timer,jiffies+5*HZ);
       /**************************test******************/
	return 0;
err_group_register:
	for(i = 0; i < 3; i ++ )
		led_classdev_unregister(&SN3193_lcds[i]);
err_classdev_register:
	misc_deregister(&sn3193_sled_dev->SN3193_miscdev);
err_misc_register:
	kfree(sn3193_sled_dev);
err_exit:
	return ret;
}
static int SN3193_probe(struct i2c_client *client, const struct i2c_device_id *id)
{
    int ret = 0;
    int i, rc;
    enum of_gpio_flags gpio_flags;
    struct SN3193_sled * sn3193_sled_dev;

    SN3193_sled_dev_sate->ena_gpio = of_get_named_gpio_flags(client->dev.of_node, "sn3193,sdb-gpio", 0, &gpio_flags);
    pr_debug("%s ena_gpio:%d\n", __func__, SN3193_sled_dev_sate->ena_gpio);

    if (gpio_is_valid(SN3193_sled_dev_sate->ena_gpio)) {
        rc = gpio_request(SN3193_sled_dev_sate->ena_gpio, "sn3193");
        if (rc) {
            pr_err("%s gpio_request for %d failed rc=%d\n", __func__, SN3193_sled_dev_sate->ena_gpio, rc);
            return rc;
        }

        rc = gpio_direction_output(SN3193_sled_dev_sate->ena_gpio, 0);
        if (rc) {
            pr_err("%s set enable gpio direction fail\n",__func__);
            gpio_free(SN3193_sled_dev_sate->ena_gpio);
            return rc;
        }
    } else { 
        pr_err("%s SN3193 ena_gpio invalid\n",__func__);
        return -1;
    }

    //client->dev.platform_data = &rgb_pdata;

    /* i2c pull up Regulator configuration */
    SN3193_sled_dev_sate->vcc_i2c = regulator_get(&client->dev, "vcc_i2c_sn3193");
    if (IS_ERR(SN3193_sled_dev_sate->vcc_i2c)) {
       pr_err("%s: Failed to get i2c regulator\n", __func__);
        rc = PTR_ERR(SN3193_sled_dev_sate->vcc_i2c);
        return -1;//retval;
    }
    
    if (regulator_count_voltages(SN3193_sled_dev_sate->vcc_i2c) > 0) {
        rc = regulator_set_voltage(SN3193_sled_dev_sate->vcc_i2c, 1800000, 1800000);
        if (rc) {
            pr_err("regulator set i2c voltage failed! rc = %d\n", rc);
            return rc;
        }
    }
    
    rc = regulator_enable(SN3193_sled_dev_sate->vcc_i2c);
    if (rc) {
        pr_err("Regulator vcc_i2c enable failed! rc = %d\n", rc);
        return rc;
    }

    SN3193_power();
    msleep(100);
    if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
        pr_err("%s : need I2C_FUNC_I2C\n", __func__);
        return  -ENODEV;
    }

    SN3193_sled_dev_sate->gi2c_dev=client;
    sn3193_sled_dev = kzalloc(sizeof(struct SN3193_sled), GFP_KERNEL);
    if (sn3193_sled_dev == NULL) {
        dev_err(&client->dev, "failed to allocate memory for module data\n");
        ret = -ENOMEM;
        goto err_exit;
    }

    pr_info("%s:sn3193 probe\n",__func__);
    sn3193_sled_dev->i2c_dev   = client;
    sn3193_sled_dev->SN3193_miscdev.minor = MISC_DYNAMIC_MINOR;
    sn3193_sled_dev->SN3193_miscdev.name = "SN3193";
    sn3193_sled_dev->SN3193_miscdev.fops = &SN3193_fops;

    ret = misc_register(&sn3193_sled_dev->SN3193_miscdev);
    if (ret) {
        pr_err("%s : misc_register failed\n", __FILE__);
        goto err_misc_register;
    }

    for(i = 0; i < 3; i ++ ) {
        if (led_classdev_register(&client->dev, &SN3193_lcds[i])) {
            printk(KERN_ERR "led_classdev_register failed of SN3193_lcds!\n");
            goto err_classdev_register;
        }
    }

    ret = sysfs_create_group(&client->dev.kobj, &blink_attr_group);
    if (ret) {
        pr_err( "%s : sysfs_create_group failed!\n", __func__);
        goto err_group_register;
    }

    i2c_set_clientdata(client, sn3193_sled_dev);

    //SN3193_config_feature_sled(0);		//dvt not breath

    //close, light as need
    SN3193_SetBrightness(RED_SLED, 0);
    SN3193_SetBrightness(GREEN_SLED, 0);
    SN3193_SetBrightness(BLUE_SLED, 0);
    SN3193_upData_sled();
    SN3193_TurnOffOut_sled();
    SN3193_enable_sled(0);

    /**************************test*********************/
    //enable sled
    /*SN3193_enable_sled(1);
    SN3193_config_feature_sled(0x00);
    SN3193_workmod_sled(1);
    SN3193_setCurrent_sled(0x01);*/
    //SN3193_enable_diff_color_sled(BLUE_SLED);
    //mod_timer(&SN3193_sled_dev_sate->gsled_last_timer, jiffies+5*HZ);
    /**************************test******************/

    return 0;
err_group_register:
    for(i = 0; i < 3; i ++ )
        led_classdev_unregister(&SN3193_lcds[i]);
err_classdev_register:
    misc_deregister(&sn3193_sled_dev->SN3193_miscdev);
err_misc_register:
    kfree(sn3193_sled_dev);
err_exit:
    return ret;
}