static int __devinit act8846_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id)
{
	struct act8846 *act8846;	
	struct act8846_platform_data *pdata = i2c->dev.platform_data;
	int ret;
	u16 val = 0;//add by nition 
	act8846 = kzalloc(sizeof(struct act8846), GFP_KERNEL);
	if (act8846 == NULL) {
		ret = -ENOMEM;		
		goto err;
	}
	act8846->i2c = i2c;
	act8846->dev = &i2c->dev;
	i2c_set_clientdata(i2c, act8846);
	mutex_init(&act8846->io_lock);	

	ret = act8846_reg_read(act8846,0x22);
	if ((ret < 0) || (ret == 0xff)){
		printk("The device is not act8846 \n");
		return 0;
	}

	ret = act8846_set_bits(act8846, 0xf4,(0x1<<7),(0x0<<7));
	if (ret < 0) {
		printk("act8846 set 0xf4 error!\n");
		goto err;
	}
	
	if (pdata) {
		ret = setup_regulators(act8846, pdata);
		if (ret < 0)		
			goto err;
	} else
		dev_warn(act8846->dev, "No platform init data supplied\n");

	g_act8846 = act8846;
	pdata->set_init(act8846);

	#ifdef CONFIG_HAS_EARLYSUSPEND
	act8846->act8846_suspend.suspend = act8846_early_suspend,
	act8846->act8846_suspend.resume = act8846_late_resume,
	act8846->act8846_suspend.level = EARLY_SUSPEND_LEVEL_DISABLE_FB + 1,
	register_early_suspend(&act8846->act8846_suspend);
	#endif
/****add by nition at 20130527 s********************/	
	act8846_i2c_read(act8846->i2c, 0xe4, 1, &val);
	printk("act8846 0xe4 = %d******************nition-1\n",val);
	val=0x8f;
	ret = act8846_i2c_write(act8846->i2c, 0xe4, 1, val);
	act8846_i2c_read(act8846->i2c, 0xe4, 1, &val);
	printk("act8846 0xe4 = %d******************nition-2\n",val);
/****add by nition at 20130527 e********************/	
	return 0;

err:
	return ret;	

}
static int __devinit act8931_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id)
{
	struct act8931 *act8931;	
	struct act8931_platform_data *pdata = i2c->dev.platform_data;
	int ret;
	u8 val;
	act8931 = kzalloc(sizeof(struct act8931), GFP_KERNEL);
	if (act8931 == NULL) {
		ret = -ENOMEM;		
		goto err;
	}
	act8931->i2c = i2c;
	act8931->dev = &i2c->dev;
	i2c_set_clientdata(i2c, act8931);
	mutex_init(&act8931->io_lock);	

	ret = act8931_reg_read(act8931,0x22);
	if ((ret < 0) || (ret == 0xff)){
		printk("The device is not act8931 \n");
		return 0;
	}
	
	if (pdata) {
		ret = setup_regulators(act8931, pdata);
		if (ret < 0)		
			goto err;
	} else
		dev_warn(act8931->dev, "No platform init data supplied\n");

	ret = act8931_reg_read(act8931,0x01);
	if (ret < 0)		
			goto err;
	ret = act8931_set_bits(act8931, 0x01,(0x1<<5) | (0x1<<0),(0x1<<0));
	if (ret < 0) {
		printk("act8931 set 0x01 error!\n");
		goto err;
	}
	
	g_act8931 = act8931;
	
	pdata->set_init(act8931);

	/* Initialize charge status */
	val = act8931_reg_read(act8931,0x78);
	act8931_charge_det = (val & INDAT_MASK )? 1:0;
	act8931_charge_ok = (val & CHGDAT_MASK )? 1:0;
	DBG("usb is=%s\n",act8931_charge_det? "connect! " : "disconnect ");
	DBG("usb =%s\n",act8931_charge_ok? "charge ok! \n" : "charging or discharge! \n");
#if 0	
	ret = act8931_set_bits(act8931, 0x78, INSTAT_MASK | CHGSTAT_MASK, 
			INSTAT_MASK | CHGSTAT_MASK);
	if (ret < 0) {
		printk("act8931 set 0x78 error!\n");
		goto err;
	}
	
	ret = act8931_set_bits(act8931, 0x79, INCON_MASK | CHGEOCIN_MASK | INDIS_MASK | CHGEOCOUT_MASK, 
			INCON_MASK | CHGEOCIN_MASK | INDIS_MASK | CHGEOCOUT_MASK);
	if (ret < 0) {
		printk("act8931 set 0x79 error!\n");
		goto err;
	}

	ret = gpio_request(i2c->irq, "act8931 gpio");
	if(ret)
	{
		printk("act8931 gpio request fail\n");
		gpio_free(i2c->irq);
		goto err;
	}
	
	act8931->irq = gpio_to_irq(i2c->irq);
	gpio_pull_updown(i2c->irq,GPIOPullUp);
	ret = request_threaded_irq(act8931->irq, NULL, act8931_irq_thread,
				IRQF_TRIGGER_FALLING | IRQF_ONESHOT, i2c->dev.driver->name, act8931);
	if (ret < 0)
	{
		printk("request act8931 irq fail\n");
		goto err;
	}	

	enable_irq_wake(act8931->irq);
#endif
#if defined(CONFIG_REGULATOR_ACT8931_BATLOW)
	batlow_irq_config(0);
#endif

#if defined(CONFIG_REGULATOR_ACT8931_CHARGE)
	act8931_charge_init();
#endif

	return 0;

err:
	return ret;	

}
Exemple #3
0
static int __devinit lp8720_i2c_probe(struct i2c_client *i2c,
			    const struct i2c_device_id *id)
{
	struct lp8720 *lp8720;
	struct lp8720_platform_data *pdata = i2c->dev.platform_data;
	int ret;
	u8 readbyte = 0;
	u8 enable = 0;

	if (!pdata) {
		dev_dbg(&i2c->dev, "No platform init data supplied\n");
		return -ENODEV;
	}

	lp8720 = kzalloc(sizeof(struct lp8720), GFP_KERNEL);
	if (!lp8720)
		return -ENOMEM;

	lp8720->i2c = i2c;
	lp8720->dev = &i2c->dev;

	mutex_init(&lp8720->io_lock);
#if 0 /* don't verify pmic register because pmic register is changed by bootloader */
	ret = lp8720_i2c_read(i2c, 0x00, 1, &readbyte);
	if (ret == 0 &&
		readbyte != 0x05) {
		ret = -ENODEV;
		dev_err(&i2c->dev, "chip reported: [00h]= 0x%x\n", readbyte);
	}
	if (ret < 0) {
		dev_err(&i2c->dev, "failed to detect device. ret = %d\n", ret);
		goto err_detect;
	}
#endif

	ret = setup_regulators(lp8720, pdata);
	if (ret < 0)
		goto err_detect;

	i2c_set_clientdata(i2c, lp8720);

	ret = gpio_request(pdata->en_pin, pdata->name);
	if (ret) {
		printk(KERN_ERR "%s, ERROR [%s] - gpio_request(%d) failed\n",
				__func__,
				pdata->name,
				pdata->en_pin);
	}

	ret = gpio_direction_output(pdata->en_pin, 1);
	if (ret) {
		printk(KERN_ERR "%s, ERROR [%s] - gpio_direction_output(%d) failed\n",
				__func__,
				pdata->name,
				pdata->en_pin);
	}

	/* EXT_DVS_CTRL, EXT_SLEEP_CTRL => serial interface control */
	lp8720_i2c_read(i2c, LP8720_GENERAL_SETTINGS_REG, 1, &readbyte);
	enable = readbyte & ~0x06;
	lp8720_i2c_write(i2c, LP8720_GENERAL_SETTINGS_REG, 1, enable);
#if 0 /* keep pmic state set by bootloader */
	/* all ldo & buck disabled */
	lp8720_i2c_read(i2c, LP8720_ENABLE_REG, 1, &readbyte);
	enable = readbyte & 0xC0;
	lp8720_i2c_write(i2c, LP8720_ENABLE_REG, 1, enable);
#endif

	lp8720_i2c_read(i2c, LP8720_ENABLE_REG, 1, &readbyte);
	printk(KERN_DEBUG "%s, [%s] - ENABLE_REG : 0x%2x\n",
			__func__, pdata->name, readbyte);

	return 0;

err_detect:
	kfree(lp8720);
	return ret;
}