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, ®_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; }
static int max77803_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id) { struct max77803_dev *max77803; struct max77803_platform_data *pdata = i2c->dev.platform_data; u8 reg_data; int ret = 0; max77803 = kzalloc(sizeof(struct max77803_dev), GFP_KERNEL); if (max77803 == NULL) return -ENOMEM; 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; /* WA for V1 MUIC RESET */ max77803->muic_reset_irq = pdata->muic_reset_irq; max77803->wakeup = pdata->wakeup; } else goto err; mutex_init(&max77803->iolock); if (max77803_read_reg(i2c, MAX77803_PMIC_REG_PMIC_ID2, ®_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); } /* No active discharge on safeout ldo 1,2 */ 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); err_irq_init: i2c_unregister_device(max77803->muic); i2c_unregister_device(max77803->haptic); err: kfree(max77803); return ret; }