static void _max77849_restore_muic_reg(struct max77849_dev *max77849) { pr_info("%s:Restore muic irq\n", __func__); max77849_write_reg(max77849->muic, MAX77849_MUIC_REG_INTMASK1, 0x09); max77849_write_reg(max77849->muic, MAX77849_MUIC_REG_INTMASK2, 0x11); max77849_update_reg(max77849->muic, MAX77849_MUIC_REG_CDETCTRL1, (0x01 << CHGTYPM_SHIFT), CHGTYPM_MASK); max77849_write_reg(max77849->muic, MAX77849_MUIC_REG_CTRL4, 0x02); max77849_muic_regdump(); }
static int max77849_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *dev_id) { struct max77849_dev *max77849; struct max77849_platform_data *pdata = i2c->dev.platform_data; u8 reg_data; int ret = 0; pr_info("%s:%s\n", MFD_DEV_NAME, __func__); max77849 = kzalloc(sizeof(struct max77849_dev), GFP_KERNEL); if (!max77849) { dev_err(&i2c->dev, "%s: Failed to alloc mem for max77849\n", __func__); return -ENOMEM; } if (i2c->dev.of_node) { pdata = devm_kzalloc(&i2c->dev, sizeof(struct max77849_platform_data), GFP_KERNEL); if (!pdata) { dev_err(&i2c->dev, "Failed to allocate memory \n"); ret = -ENOMEM; goto err; } ret = of_max77849_dt(&i2c->dev, pdata); if (ret < 0){ dev_err(&i2c->dev, "Failed to get device of_node \n"); goto err; } i2c->dev.platform_data = pdata; } else pdata = i2c->dev.platform_data; max77849->dev = &i2c->dev; max77849->i2c = i2c; max77849->irq = i2c->irq; if (pdata) { max77849->pdata = pdata; pdata->irq_base = irq_alloc_descs(-1, 0, MAX77849_IRQ_NR, -1); if (pdata->irq_base < 0) { pr_err("%s:%s irq_alloc_descs Fail! ret(%d)\n", MFD_DEV_NAME, __func__, pdata->irq_base); ret = -EINVAL; goto err; } else max77849->irq_base = pdata->irq_base; max77849->irq_gpio = pdata->irq_gpio; max77849->wakeup = pdata->wakeup; } else { ret = -EINVAL; goto err; } mutex_init(&max77849->i2c_lock); i2c_set_clientdata(i2c, max77849); if (max77849_read_reg(i2c, MAX77849_PMIC_REG_PMICREV, ®_data) < 0) { dev_err(max77849->dev, "device not found on this channel (this is not an error)\n"); ret = -ENODEV; goto err_w_lock; } else { /* print rev */ max77849->pmic_rev = (reg_data & 0x7); max77849->pmic_ver = ((reg_data & 0xF8) >> 0x3); pr_info("%s:%s device found: rev.0x%x, ver.0x%x\n", MFD_DEV_NAME, __func__, max77849->pmic_rev, max77849->pmic_ver); } /* No active discharge on safeout ldo 1,2 */ max77849_update_reg(i2c, MAX77849_PMIC_REG_SAFEOUT_CTRL, 0x00, 0x02); max77849->muic = i2c_new_dummy(i2c->adapter, I2C_ADDR_MUIC); i2c_set_clientdata(max77849->muic, max77849); max77849->charger = max77849->i2c; //max77849->charger = i2c_new_dummy(i2c->adapter, I2C_ADDR_CHG); //i2c_set_clientdata(max77849->charger, max77849); //max77849->fuelgauge = i2c_new_dummy(i2c->adapter, I2C_ADDR_FG); //i2c_set_clientdata(max77849->fuelgauge, max77849); ret = max77849_irq_init(max77849); if (ret < 0) goto err_irq_init; ret = mfd_add_devices(max77849->dev, -1, max77849_devs, ARRAY_SIZE(max77849_devs), NULL, 0, NULL); if (ret < 0) goto err_mfd; device_init_wakeup(max77849->dev, pdata->wakeup); return ret; err_mfd: mfd_remove_devices(max77849->dev); err_irq_init: i2c_unregister_device(max77849->muic); err_w_lock: mutex_destroy(&max77849->i2c_lock); err: kfree(max77849); return ret; }
static int max77849_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id) { struct max77849_dev *max77849; struct max77849_platform_data *pdata; int ret = 0; struct pinctrl *muic_pinctrl; dev_info(&i2c->dev, "%s\n", __func__); msleep(500); max77849 = kzalloc(sizeof(struct max77849_dev), GFP_KERNEL); if (max77849 == NULL) return -ENOMEM; if (i2c->dev.of_node) { pdata = devm_kzalloc(&i2c->dev, sizeof(struct max77849_platform_data), GFP_KERNEL); if (!pdata) { dev_err(&i2c->dev, "Failed to allocate memory \n"); ret = -ENOMEM; goto err; } ret = of_max77849_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->muic_data = &max77849_muic; #if defined(CONFIG_REGULATOR_MAX77849) pdata->num_regulators = MAX77849_REG_MAX; pdata->regulators = max77849_regulators, #endif /*pdata update to other modules*/ i2c->dev.platform_data = pdata; muic_pinctrl = devm_pinctrl_get_select(&i2c->dev, "muic_i2c_active"); if (IS_ERR(muic_pinctrl)) { if (PTR_ERR(muic_pinctrl) == -EPROBE_DEFER) return -EPROBE_DEFER; pr_debug("Target does not use pinctrl\n"); muic_pinctrl = NULL; } } else { pdata = i2c->dev.platform_data; } i2c_set_clientdata(i2c, max77849); max77849->dev = &i2c->dev; max77849->i2c = i2c; max77849->irq = i2c->irq; if (pdata) { max77849->irq_base = pdata->irq_base; max77849->irq_gpio = pdata->irq_gpio; #ifdef CONFIG_MUIC_RESET_PIN_ENABLE if (muic_reset_pin) { max77849->irq_reset_gpio = pdata->irq_reset_gpio; gpio_tlmm_config(GPIO_CFG(max77849->irq_reset_gpio, 0, GPIO_CFG_INPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA), GPIO_CFG_DISABLE); } #endif } else { goto err; } mutex_init(&max77849->iolock); /* No active discharge on safeout ldo 1,2 */ max77849_update_reg(i2c, MAX77849_CHG_REG_SAFEOUT_CTRL, 0x00, 0x30); pr_info("%s: i2c->name=%s irq=%d !!!\n",__func__, i2c->name, i2c->irq); max77849->muic = i2c_new_dummy(i2c->adapter, I2C_ADDR_MUIC); i2c_set_clientdata(max77849->muic, max77849); ret = max77849_irq_init(max77849); if (ret < 0) goto err_irq_init; ret = mfd_add_devices(max77849->dev, -1, max77849_devs, ARRAY_SIZE(max77849_devs), NULL, 0, NULL); if (ret < 0) goto err_mfd; device_init_wakeup(max77849->dev, 1); #if defined(CONFIG_ADC_ONESHOT) /* Set oneshot mode */ max77849_update_reg(max77849->muic, MAX77849_MUIC_REG_CTRL4, ADC_ONESHOT<<CTRL4_ADCMODE_SHIFT, CTRL4_ADCMODE_MASK); #else /* Set continuous mode */ max77849_update_reg(max77849->muic, MAX77849_MUIC_REG_CTRL4, ADC_ALWAYS<<CTRL4_ADCMODE_SHIFT, CTRL4_ADCMODE_MASK); #endif return ret; err_mfd: mfd_remove_devices(max77849->dev); max77849_irq_exit(max77849); pr_info("%s1\n", __func__); err_irq_init: i2c_unregister_device(max77849->muic); pr_info("%s2\n", __func__); err: kfree(max77849); pr_info("%s3\n", __func__); return ret; }