Exemplo n.º 1
0
static int __devinit pm8058_probe(struct platform_device *pdev)
{
	int rc;
	struct pm8058_platform_data *pdata = pdev->dev.platform_data;
	struct pm8058_chip *pmic;

	if (pdata == NULL) {
		pr_err("%s: No platform_data or IRQ.\n", __func__);
		return -ENODEV;
	}

	pmic = kzalloc(sizeof *pmic, GFP_KERNEL);
	if (pmic == NULL) {
		pr_err("%s: kzalloc() failed.\n", __func__);
		return -ENOMEM;
	}

	pmic->dev = &pdev->dev;

	pm8058_drvdata.pm_chip_data = pmic;
	platform_set_drvdata(pdev, &pm8058_drvdata);

	/* Read PMIC chip revision */
	rc = pm8058_readb(pmic->dev, PM8058_REG_REV, &pmic->revision);
	if (rc)
		pr_err("%s: Failed on pm8058_readb for revision: rc=%d.\n",
			__func__, rc);

	pr_info("%s: PMIC revision: %X\n", __func__, pmic->revision);

	(void) memcpy((void *)&pmic->pdata, (const void *)pdata,
		      sizeof(pmic->pdata));

	rc = pm8058_add_subdevices(pdata, pmic);
	if (rc) {
		pr_err("Cannot add subdevices rc=%d\n", rc);
		goto err;
	}
#ifdef CONFIG_LGE_PM //[email protected] : reboot when hard-reset
	rc = pm8xxx_hard_reset_config(PM8XXX_RESTART_ON_HARD_RESET);
#else
	rc = pm8xxx_hard_reset_config(PM8XXX_SHUTDOWN_ON_HARD_RESET);
#endif
	if (rc < 0)
		pr_err("%s: failed to config shutdown on hard reset: %d\n",
								__func__, rc);

	return 0;

err:
	mfd_remove_devices(pmic->dev);
	platform_set_drvdata(pdev, NULL);
	kfree(pmic);
	return rc;
}
static int max77693_i2c_probe(struct i2c_client *i2c,
			      const struct i2c_device_id *id)
{
	struct max77693_dev *max77693;
	struct max77693_platform_data *pdata = i2c->dev.platform_data;
	u8 reg_data;
	int ret = 0;

	max77693 = kzalloc(sizeof(struct max77693_dev), GFP_KERNEL);
	if (max77693 == NULL)
		return -ENOMEM;

	i2c_set_clientdata(i2c, max77693);
	max77693->dev = &i2c->dev;
	max77693->i2c = i2c;
	max77693->irq = i2c->irq;
	max77693->type = id->driver_data;
	if (pdata) {
		max77693->irq_base = pdata->irq_base;
		max77693->irq_gpio = pdata->irq_gpio;
		max77693->wakeup = pdata->wakeup;
	} else
		goto err;

	mutex_init(&max77693->iolock);

	if (max77693_read_reg(i2c, MAX77693_PMIC_REG_PMIC_ID2, &reg_data) < 0) {
		dev_err(max77693->dev,
			"device not found on this channel (this is not an error)\n");
		ret = -ENODEV;
		goto err;
	} else {
		/* print rev */
		max77693->pmic_rev = (reg_data & 0x7);
		max77693->pmic_ver = ((reg_data & 0xF8) >> 0x3);
		pr_info("%s: device found: rev.0x%x, ver.0x%x\n", __func__,
				max77693->pmic_rev, max77693->pmic_ver);
	}

#if defined(CONFIG_MACH_JF_VZW) || defined(CONFIG_MACH_JF_LGT)
	if (kernel_sec_get_debug_level() == KERNEL_SEC_DEBUG_LEVEL_LOW) {
		pm8xxx_hard_reset_config(PM8XXX_DISABLE_HARD_RESET);
		max77693_write_reg(i2c, MAX77693_PMIC_REG_MAINCTRL1, 0x04);
	} else {
		pm8xxx_hard_reset_config(PM8XXX_DISABLE_HARD_RESET);
		max77693_write_reg(i2c, MAX77693_PMIC_REG_MAINCTRL1, 0x0c);
	}
#else
	if (kernel_sec_get_debug_level() == KERNEL_SEC_DEBUG_LEVEL_LOW) {
		max77693_write_reg(i2c, MAX77693_PMIC_REG_MAINCTRL1, 0x04);
	} else {
		pm8xxx_hard_reset_config(PM8XXX_DISABLE_HARD_RESET);
		max77693_write_reg(i2c, MAX77693_PMIC_REG_MAINCTRL1, 0x0c);
	}
#endif
	max77693_update_reg(i2c, MAX77693_CHG_REG_SAFEOUT_CTRL, 0x00, 0x30);

	max77693->muic = i2c_new_dummy(i2c->adapter, I2C_ADDR_MUIC);
	i2c_set_clientdata(max77693->muic, max77693);

	max77693->haptic = i2c_new_dummy(i2c->adapter, I2C_ADDR_HAPTIC);
	i2c_set_clientdata(max77693->haptic, max77693);

	ret = max77693_irq_init(max77693);
	if (ret < 0)
		goto err_irq_init;

	ret = mfd_add_devices(max77693->dev, -1, max77693_devs,
			ARRAY_SIZE(max77693_devs), NULL, 0);
	if (ret < 0)
		goto err_mfd;

	device_init_wakeup(max77693->dev, pdata->wakeup);

	return ret;

err_mfd:
	mfd_remove_devices(max77693->dev);
err_irq_init:
	i2c_unregister_device(max77693->muic);
	i2c_unregister_device(max77693->haptic);
err:
	kfree(max77693);
	return ret;
}
Exemplo n.º 3
0
static int max77803_i2c_probe(struct i2c_client *i2c,
			      const struct i2c_device_id *id)
{
	struct max77803_dev *max77803;
	struct max77803_platform_data *pdata;
	u8 reg_data;
	int ret = 0;
	dev_info(&i2c->dev, "%s\n", __func__);

	max77803 = kzalloc(sizeof(struct max77803_dev), GFP_KERNEL);
	if (max77803 == NULL)
		return -ENOMEM;

	if (i2c->dev.of_node) {
		pdata = devm_kzalloc(&i2c->dev,
				sizeof(struct max77803_platform_data),
				GFP_KERNEL);
		if (!pdata) {
			dev_err(&i2c->dev, "Failed to allocate memory \n");
			ret = -ENOMEM;
			goto err;
		}

		ret = of_max77803_dt(&i2c->dev, pdata);
		if (ret < 0){
			dev_err(&i2c->dev, "Failed to get device of_node \n");
			return ret;
		}
		/*Filling the platform data*/
		pdata->num_regulators = MAX77803_REG_MAX;
		pdata->muic_data = &max77803_muic;
		pdata->charger_data = &sec_battery_pdata;
		pdata->regulators = max77803_regulators,
#ifdef CONFIG_VIBETONZ
		pdata->haptic_data = &max77803_haptic_pdata;
#endif
		pdata->led_data = &max77803_led_pdata;
		/* set irq_base at sec_battery_pdata */
		sec_battery_pdata.bat_irq = pdata->irq_base + MAX77803_CHG_IRQ_BATP_I;
		/*pdata update to other modules*/
		i2c->dev.platform_data = pdata;
	} else
		pdata = i2c->dev.platform_data;

	i2c_set_clientdata(i2c, max77803);
	max77803->dev = &i2c->dev;

	max77803->i2c = i2c;
	max77803->irq = i2c->irq;
//	max77803->type = id->driver_data;
	if (pdata) {
		max77803->irq_base = pdata->irq_base;
		max77803->irq_gpio = pdata->irq_gpio;
		max77803->wakeup = pdata->wakeup;
		gpio_tlmm_config(GPIO_CFG(max77803->irq_gpio,  0, GPIO_CFG_INPUT,
                GPIO_CFG_NO_PULL, GPIO_CFG_2MA), GPIO_CFG_DISABLE);
	} else {
		ret = -EINVAL;
		goto err;
	}

	mutex_init(&max77803->iolock);

	if (max77803_read_reg(i2c, MAX77803_PMIC_REG_PMIC_ID2, &reg_data) < 0) {
		dev_err(max77803->dev,
			"device not found on this channel (this is not an error)\n");
		ret = -ENODEV;
		goto err;
	} else {
		/* print rev */
		max77803->pmic_rev = (reg_data & 0x7);
		max77803->pmic_ver = ((reg_data & 0xF8) >> 0x3);
		pr_info("%s: device found: rev.0x%x, ver.0x%x\n", __func__,
				max77803->pmic_rev, max77803->pmic_ver);
	}
#if 0
#if defined(CONFIG_MACH_JF_VZW) || defined(CONFIG_MACH_JF_LGT)
	if (kernel_sec_get_debug_level() == KERNEL_SEC_DEBUG_LEVEL_LOW) {
		pm8xxx_hard_reset_config(PM8XXX_DISABLE_HARD_RESET);
		max77803_write_reg(i2c, MAX77803_PMIC_REG_MAINCTRL1, 0x04);
	} else {
		pm8xxx_hard_reset_config(PM8XXX_DISABLE_HARD_RESET);
		max77803_write_reg(i2c, MAX77803_PMIC_REG_MAINCTRL1, 0x0c);
	}
#else
	if (kernel_sec_get_debug_level() == KERNEL_SEC_DEBUG_LEVEL_LOW) {
		max77803_write_reg(i2c, MAX77803_PMIC_REG_MAINCTRL1, 0x04);
	} else {
		pm8xxx_hard_reset_config(PM8XXX_DISABLE_HARD_RESET);
		max77803_write_reg(i2c, MAX77803_PMIC_REG_MAINCTRL1, 0x0c);
	}
#endif
#endif
	max77803_update_reg(i2c, MAX77803_CHG_REG_SAFEOUT_CTRL, 0x00, 0x30);

	max77803->muic = i2c_new_dummy(i2c->adapter, I2C_ADDR_MUIC);
	i2c_set_clientdata(max77803->muic, max77803);

	max77803->haptic = i2c_new_dummy(i2c->adapter, I2C_ADDR_HAPTIC);
	i2c_set_clientdata(max77803->haptic, max77803);

	ret = max77803_irq_init(max77803);
	if (ret < 0)
		goto err_irq_init;

	ret = mfd_add_devices(max77803->dev, -1, max77803_devs,
			ARRAY_SIZE(max77803_devs), NULL, 0);
	if (ret < 0)
		goto err_mfd;

	device_init_wakeup(max77803->dev, pdata->wakeup);

	return ret;

err_mfd:
	mfd_remove_devices(max77803->dev);
	max77803_irq_exit(max77803);
err_irq_init:
	i2c_unregister_device(max77803->muic);
	i2c_unregister_device(max77803->haptic);
err:
	kfree(max77803);
	return ret;
}