static int max77828_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *dev_id) { struct max77828_dev *max77828; struct max77828_platform_data *pdata = i2c->dev.platform_data; u8 reg_data; int ret = 0; pr_info("%s:%s\n", MFD_DEV_NAME, __func__); max77828 = kzalloc(sizeof(struct max77828_dev), GFP_KERNEL); if (!max77828) { dev_err(&i2c->dev, "%s: Failed to alloc mem for max77828\n", __func__); return -ENOMEM; } if (i2c->dev.of_node) { pdata = devm_kzalloc(&i2c->dev, sizeof(struct max77828_platform_data), GFP_KERNEL); if (!pdata) { dev_err(&i2c->dev, "Failed to allocate memory \n"); ret = -ENOMEM; goto err; } ret = of_max77828_dt(&i2c->dev, pdata); if (ret < 0){ dev_err(&i2c->dev, "Failed to get device of_node \n"); return ret; } i2c->dev.platform_data = pdata; } else pdata = i2c->dev.platform_data; max77828->dev = &i2c->dev; max77828->i2c = i2c; max77828->irq = i2c->irq; if (pdata) { max77828->pdata = pdata; pdata->irq_base = irq_alloc_descs(-1, 0, MAX77828_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 max77828->irq_base = pdata->irq_base; max77828->irq_gpio = pdata->irq_gpio; max77828->wakeup = pdata->wakeup; } else { ret = -EINVAL; goto err; } mutex_init(&max77828->i2c_lock); i2c_set_clientdata(i2c, max77828); if (max77828_read_reg(i2c, MAX77828_PMIC_REG_PMICREV, ®_data) < 0) { dev_err(max77828->dev, "device not found on this channel (this is not an error)\n"); ret = -ENODEV; goto err; } else { /* print rev */ max77828->pmic_rev = (reg_data & 0x7); max77828->pmic_ver = ((reg_data & 0xF8) >> 0x3); pr_info("%s:%s device found: rev.0x%x, ver.0x%x\n", MFD_DEV_NAME, __func__, max77828->pmic_rev, max77828->pmic_ver); } max77828->muic = i2c_new_dummy(i2c->adapter, I2C_ADDR_MUIC); i2c_set_clientdata(max77828->muic, max77828); max77828->led = i2c_new_dummy(i2c->adapter, I2C_ADDR_LED); i2c_set_clientdata(max77828->led, max77828); ret = max77828_irq_init(max77828); if (ret < 0) goto err_irq_init; ret = mfd_add_devices(max77828->dev, -1, max77828_devs, ARRAY_SIZE(max77828_devs), NULL, 0, NULL); if (ret < 0) goto err_mfd; device_init_wakeup(max77828->dev, pdata->wakeup); return ret; err_mfd: mfd_remove_devices(max77828->dev); err_irq_init: i2c_unregister_device(max77828->muic); i2c_unregister_device(max77828->led); err: kfree(max77828); return ret; }
static int max77828_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id) { struct max77828_dev *max77828; struct max77828_platform_data *pdata = i2c->dev.platform_data; u8 reg_data; int ret = 0; dev_info(&i2c->dev, "%s\n", __func__); max77828 = kzalloc(sizeof(struct max77828_dev), GFP_KERNEL); if (!max77828) { dev_err(&i2c->dev, "%s: Failed to alloc mem for max77828\n", __func__); return -ENOMEM; } if (i2c->dev.of_node) { pdata = devm_kzalloc(&i2c->dev, sizeof(struct max77828_platform_data), GFP_KERNEL); if (!pdata) { dev_err(&i2c->dev, "Failed to allocate memory \n"); ret = -ENOMEM; goto err; } ret = of_max77828_dt(&i2c->dev, pdata); if (ret < 0){ dev_err(&i2c->dev, "Failed to get device of_node \n"); return ret; } /*pdata update to other modules*/ pdata->muic_data = &max77828_muic; #ifdef CONFIG_LEDS_MAX77828 pdata->led_data = &max77828_led_pdata; #endif i2c->dev.platform_data = pdata; } else pdata = i2c->dev.platform_data; max77828->dev = &i2c->dev; max77828->i2c = i2c; max77828->irq = i2c->irq; if (pdata) { max77828->pdata = pdata; max77828->irq_base = pdata->irq_base; max77828->irq_gpio = pdata->irq_gpio; max77828->wakeup = pdata->wakeup; gpio_tlmm_config(GPIO_CFG(max77828->irq_gpio, 0, GPIO_CFG_INPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA), GPIO_CFG_DISABLE); } else { ret = -EINVAL; goto err; } mutex_init(&max77828->iolock); i2c_set_clientdata(i2c, max77828); if (max77828_read_reg(i2c, MAX77828_PMIC_REG_PMICREV, ®_data) < 0) { dev_err(max77828->dev, "device not found on this channel (this is not an error)\n"); ret = -ENODEV; goto err; } else { /* print rev */ max77828->pmic_rev = (reg_data & 0x7); max77828->pmic_ver = ((reg_data & 0xF8) >> 0x3); pr_info("%s: device found: rev.0x%x, ver.0x%x\n", __func__, max77828->pmic_rev, max77828->pmic_ver); } max77828->muic = i2c_new_dummy(i2c->adapter, I2C_ADDR_MUIC); i2c_set_clientdata(max77828->muic, max77828); max77828->led = i2c_new_dummy(i2c->adapter, I2C_ADDR_LED); i2c_set_clientdata(max77828->led, max77828); ret = max77828_irq_init(max77828); if (ret < 0) goto err_irq_init; ret = mfd_add_devices(max77828->dev, -1, max77828_devs, ARRAY_SIZE(max77828_devs), NULL, 0); if (ret < 0) goto err_mfd; device_init_wakeup(max77828->dev, pdata->wakeup); return ret; err_mfd: mfd_remove_devices(max77828->dev); max77828_irq_exit(max77828); err_irq_init: i2c_unregister_device(max77828->muic); i2c_unregister_device(max77828->led); err: kfree(max77828); return ret; }