Beispiel #1
0
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;	

}
Beispiel #2
0
static int act8846_ldo_get_voltage(struct regulator_dev *dev)
{
	struct act8846 *act8846 = rdev_get_drvdata(dev);
	int ldo= rdev_get_id(dev) - ACT8846_LDO1;
	u16 reg = 0;
	int val;
	reg = act8846_reg_read(act8846,act8846_LDO_SET_VOL_REG(ldo));
	reg &= LDO_VOL_MASK;
	val = 1000 * ldo_voltage_map[reg];	
	return val;
}
Beispiel #3
0
int act8846_set_bits(struct act8846 *act8846, enum act8846_reg reg,
		     u8 mask, u8 val)
{
	u8 tmp;
	int err;

	err = act8846_reg_read(act8846, reg, &tmp);
	tmp = (tmp & ~mask) | val;

	if (!err)
		err = act8846_reg_write(act8846, reg, tmp);

	return err;
}
Beispiel #4
0
static int act8846_dcdc_is_enabled(struct regulator_dev *dev)
{
	struct act8846 *act8846 = rdev_get_drvdata(dev);
	int buck = rdev_get_id(dev) - ACT8846_DCDC1;
	u16 val;
	u16 mask=0x80;	
	val = act8846_reg_read(act8846, act8846_BUCK_CONTR_REG(buck));
	if (val < 0)
		return val;
	 val=val&~0x7f;
	if (val & mask)
		return 1;
	else
		return 0; 	
}
Beispiel #5
0
static int act8846_ldo_is_enabled(struct regulator_dev *dev)
{
	struct act8846 *act8846 = rdev_get_drvdata(dev);
	int ldo = rdev_get_id(dev) - ACT8846_LDO1;
	u16 val;
	u16 mask=0x80;
	val = act8846_reg_read(act8846, act8846_LDO_CONTR_REG(ldo));	 
	if (val < 0)
		return val;
	val=val&~0x7f;
	if (val & mask)
		return 1;
	else
		return 0; 	
}
Beispiel #6
0
void regulator_ctrl_vcc_tp(bool on)
{
	int ret;
	struct act8846 *act8846 = g_act8846;
	const char REG9 = 0x71;
	if(on)
	{
		/*close out9*/
		reg9_val = act8846_reg_read(act8846,REG9);
		DBG("before set REG9 = %d\n", reg9_val);
		ret = act8846_set_bits(act8846, REG9,(0x1<<7),(0x0<<7));
		DBG("after set REG89 = %d\n", act8846_reg_read(act8846,REG9));
		if (ret < 0) {
			DBG("act8846 set 0xc3 error!\n");
		}
	}
	else
	{
		/*resume reg9*/
		act8846_i2c_write(act8846->i2c, REG9, 1, reg9_val);
		reg9_val = act8846_reg_read(act8846,REG9);
		DBG("resume REG8 = %d\n", reg9_val);
	}
}
Beispiel #7
0
static unsigned int act8846_dcdc_get_mode(struct regulator_dev *dev)
{
	struct act8846 *act8846 = rdev_get_drvdata(dev);
	int buck = rdev_get_id(dev) - ACT8846_DCDC1;
	u16 mask = 0x08;
	u16 val;
	val = act8846_reg_read(act8846, act8846_BUCK_CONTR_REG(buck));
        if (val < 0) {
                return val;
        }
	val=val & mask;
	if (val== mask)
		return REGULATOR_MODE_NORMAL;
	else
		return REGULATOR_MODE_STANDBY;

}
Beispiel #8
0
static unsigned int act8846_ldo_get_mode(struct regulator_dev *dev)
{
	struct act8846 *act8846 = rdev_get_drvdata(dev);
	int ldo = rdev_get_id(dev) - ACT8846_LDO1;
	u16 mask = 0x80;
	u16 val;
	val = act8846_reg_read(act8846, act8846_LDO_CONTR_REG(ldo));
        if (val < 0) {
                return val;
        }
	val=val & mask;
	if (val== mask)
		return REGULATOR_MODE_NORMAL;
	else
		return REGULATOR_MODE_STANDBY;

}
Beispiel #9
0
int act8846_device_shutdown(void)
{
	int ret;
	int err = -1;
	struct act8846 *act8846 = g_act8846;
	
	printk("%s\n",__func__);

	ret = act8846_reg_read(act8846,0xc3);
	ret = act8846_set_bits(act8846, 0xc3,(0x1<<3),(0x1<<3));
	ret = act8846_set_bits(act8846, 0xc3,(0x1<<4),(0x1<<4));
	if (ret < 0) {
		printk("act8846 set 0xc3 error!\n");
		return err;
	}
	return 0;	
}
Beispiel #10
0
static ssize_t act8846_read(struct cdev *cdev, void *_buf, size_t count,
			    loff_t offset, ulong flags)
{
	struct act8846 *act8846 = to_act8846(cdev);
	u8 *buf = _buf;
	size_t i = count;
	int err;

	while (i) {
		err = act8846_reg_read(act8846, offset, buf);
		if (err)
			return (ssize_t)err;
		buf++;
		i--;
		offset++;
	}

	return count;
}
Beispiel #11
0
static int act8846_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id)
{
	struct act8846 *act8846;	
	struct act8846_board *pdev ;
	const struct of_device_id *match;
	struct regulator_config config = { };
	struct regulator_dev *act_rdev;
	struct regulator_init_data *reg_data;
	const char *rail_name = NULL;
	int ret,i=0;
	
	printk("%s,line=%d\n", __func__,__LINE__);	

	if (i2c->dev.of_node) {
		match = of_match_device(act8846_of_match, &i2c->dev);
		if (!match) {
			printk("Failed to find matching dt id\n");
			return -EINVAL;
		}
	}

	act8846 = devm_kzalloc(&i2c->dev,sizeof(struct act8846), GFP_KERNEL);
	if (act8846 == NULL) {
		ret = -ENOMEM;		
		goto err;
	}
	act8846->i2c = i2c;
	act8846->dev = &i2c->dev;
	i2c_set_clientdata(i2c, act8846);
	g_act8846 = act8846;
	
	act8846->regmap = devm_regmap_init_i2c(i2c, &act8846_regmap_config);
	if (IS_ERR(act8846->regmap)) {
		ret = PTR_ERR(act8846->regmap);
		printk("regmap initialization failed: %d\n", ret);
		return ret;
	}
	
	mutex_init(&act8846->io_lock);	

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

	ret = act8846_set_bits(act8846, 0xf4,(0x1<<7),(0x0<<7));
	if (ret < 0) {
		printk("act8846 set 0xf4 error!\n");
		goto err;
	}

	if (act8846->dev->of_node)
		pdev = act8846_parse_dt(act8846);

	#ifdef CONFIG_OF
	act8846->pmic_hold_gpio = pdev->pmic_hold_gpio;
	if (act8846->pmic_hold_gpio) {
			ret = gpio_request(act8846->pmic_hold_gpio, "act8846_pmic_hold");
			if (ret < 0) {
				dev_err(act8846->dev,"Failed to request gpio %d with ret:""%d\n",	act8846->pmic_hold_gpio, ret);
				return IRQ_NONE;
			}
			gpio_direction_output(act8846->pmic_hold_gpio,1);
			ret = gpio_get_value(act8846->pmic_hold_gpio);
	//		gpio_free(act8846->pmic_hold_gpio);
			printk("%s: act8846_pmic_hold=%x\n", __func__, ret);
	}
	#endif
	
	/******************************set sleep vol & dcdc mode******************/
	#ifdef CONFIG_OF
	act8846->pmic_sleep_gpio = pdev->pmic_sleep_gpio;
	if (act8846->pmic_sleep_gpio) {
			ret = gpio_request(act8846->pmic_sleep_gpio, "act8846_pmic_sleep");
			if (ret < 0) {
				dev_err(act8846->dev,"Failed to request gpio %d with ret:""%d\n",	act8846->pmic_sleep_gpio, ret);
				return IRQ_NONE;
			}
			gpio_direction_output(act8846->pmic_sleep_gpio,1);
			ret = gpio_get_value(act8846->pmic_sleep_gpio);
			gpio_free(act8846->pmic_sleep_gpio);
			printk("%s: act8846_pmic_sleep=%x\n", __func__, ret);
	}
	#endif
	
    /****************************set cpu_det high **************************/
    #ifdef CONFIG_OF
    act8846->pmic_cpu_det_gpio = pdev->pmic_cpu_det_gpio;
    if (act8846->pmic_cpu_det_gpio) {
            ret = gpio_request(act8846->pmic_cpu_det_gpio, "act8846_pmic_cpu_det");
            if (ret < 0) {
                dev_err(act8846->dev,"Failed to request gpio %d with ret:""%d\n",       act8846->pmic_cpu_det_gpio, ret);
                return IRQ_NONE;
            }
            gpio_direction_output(act8846->pmic_cpu_det_gpio, 1);
            ret = gpio_get_value(act8846->pmic_cpu_det_gpio);
            printk("%s: act8846_pmic_cpu_det_gpio=%x\n", __func__, ret);
    }
    #endif
    
    #ifdef CONFIG_OF
    act8846->pmic_usb_hub_reset_gpio = pdev->pmic_usb_hub_reset_gpio;
    if (act8846->pmic_usb_hub_reset_gpio) {
            ret = gpio_request(act8846->pmic_usb_hub_reset_gpio, "act8846_pmic_usb_hub_reset_gpio");
            if (ret < 0) {
                dev_err(act8846->dev,"Failed to request gpio %d with ret:""%d\n",       act8846->pmic_usb_hub_reset_gpio, ret);
                return IRQ_NONE;
            }
            gpio_direction_output(act8846->pmic_usb_hub_reset_gpio, 1);
            ret = gpio_get_value(act8846->pmic_usb_hub_reset_gpio);
            printk("%s: act8846_pmic_usb_hub_reset_gpio=%x\n", __func__, ret);
    }
    #endif
	
	if (pdev) {
		act8846->num_regulators = act8846_NUM_REGULATORS;
		act8846->rdev = kcalloc(act8846_NUM_REGULATORS,sizeof(struct regulator_dev *), GFP_KERNEL);
		if (!act8846->rdev) {
			return -ENOMEM;
		}
		/* Instantiate the regulators */
		for (i = 0; i < act8846_NUM_REGULATORS; i++) {
		reg_data = pdev->act8846_init_data[i];
		if (!reg_data)
			continue;
		config.dev = act8846->dev;
		config.driver_data = act8846;
		config.regmap = act8846->regmap;
		if (act8846->dev->of_node)
			config.of_node = pdev->of_node[i];

			if (reg_data && reg_data->constraints.name)
				rail_name = reg_data->constraints.name;
			else
				rail_name = regulators[i].name;
			reg_data->supply_regulator = rail_name;
	
		config.init_data =reg_data;
		
		act_rdev = regulator_register(&regulators[i],&config);
		if (IS_ERR(act_rdev)) {
			printk("failed to register %d regulator\n",i);
		goto err;
		}
		act8846->rdev[i] = act_rdev;
		}
	}

	if (pdev->pm_off && !pm_power_off) {
		pm_power_off = act8846_device_shutdown;
	}
	
	#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	

	return 0;

err:
	return ret;	

}