static int s5m87xx_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id) { struct s5m_platform_data *pdata = i2c->dev.platform_data; struct s5m87xx_dev *s5m87xx; int ret = 0; if (!pdata) return -EINVAL; s5m87xx = kzalloc(sizeof(struct s5m87xx_dev), GFP_KERNEL); if (s5m87xx == NULL) return -ENOMEM; i2c_set_clientdata(i2c, s5m87xx); s5m87xx->dev = &i2c->dev; s5m87xx->i2c = i2c; s5m87xx->irq = gpio_to_irq(pdata->irq_gpio); s5m87xx->type = id->driver_data; if (pdata) { s5m87xx->device_type = pdata->device_type; s5m87xx->ono = pdata->ono; s5m87xx->irq_base = pdata->irq_base; s5m87xx->wakeup = pdata->wakeup; } mutex_init(&s5m87xx->iolock); s5m87xx->rtc = i2c_new_dummy(i2c->adapter, RTC_I2C_ADDR); i2c_set_clientdata(s5m87xx->rtc, s5m87xx); if (pdata && pdata->cfg_pmic_irq) pdata->cfg_pmic_irq(); s5m_irq_init(s5m87xx); pm_runtime_set_active(s5m87xx->dev); ret = mfd_add_devices(s5m87xx->dev, -1, s5m87xx_devs, ARRAY_SIZE(s5m87xx_devs), NULL, 0); if (ret < 0) goto err; dev_info(s5m87xx->dev ,"S5M87xx MFD probe done!!! \n"); return ret; err: mfd_remove_devices(s5m87xx->dev); s5m_irq_exit(s5m87xx); i2c_unregister_device(s5m87xx->rtc); kfree(s5m87xx); return ret; }
static int s5m87xx_i2c_remove(struct i2c_client *i2c) { struct s5m87xx_dev *s5m87xx = i2c_get_clientdata(i2c); mfd_remove_devices(s5m87xx->dev); s5m_irq_exit(s5m87xx); i2c_unregister_device(s5m87xx->rtc); regmap_exit(s5m87xx->regmap); return 0; }
static int s5m87xx_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id) { struct s5m_platform_data *pdata = i2c->dev.platform_data; struct s5m87xx_dev *s5m87xx; int ret; s5m87xx = devm_kzalloc(&i2c->dev, sizeof(struct s5m87xx_dev), GFP_KERNEL); if (s5m87xx == NULL) return -ENOMEM; i2c_set_clientdata(i2c, s5m87xx); s5m87xx->dev = &i2c->dev; s5m87xx->i2c = i2c; s5m87xx->irq = i2c->irq; s5m87xx->type = id->driver_data; if (pdata) { s5m87xx->device_type = pdata->device_type; s5m87xx->ono = pdata->ono; s5m87xx->irq_base = pdata->irq_base; s5m87xx->wakeup = pdata->wakeup; } s5m87xx->regmap = regmap_init_i2c(i2c, &s5m_regmap_config); if (IS_ERR(s5m87xx->regmap)) { ret = PTR_ERR(s5m87xx->regmap); dev_err(&i2c->dev, "Failed to allocate register map: %d\n", ret); goto err; } s5m87xx->rtc = i2c_new_dummy(i2c->adapter, RTC_I2C_ADDR); i2c_set_clientdata(s5m87xx->rtc, s5m87xx); if (pdata && pdata->cfg_pmic_irq) pdata->cfg_pmic_irq(); s5m_irq_init(s5m87xx); pm_runtime_set_active(s5m87xx->dev); switch (s5m87xx->device_type) { case S5M8751X: ret = mfd_add_devices(s5m87xx->dev, -1, s5m8751_devs, ARRAY_SIZE(s5m8751_devs), NULL, 0); break; case S5M8763X: ret = mfd_add_devices(s5m87xx->dev, -1, s5m8763_devs, ARRAY_SIZE(s5m8763_devs), NULL, 0); break; case S5M8767X: ret = mfd_add_devices(s5m87xx->dev, -1, s5m8767_devs, ARRAY_SIZE(s5m8767_devs), NULL, 0); break; default: /* If this happens the probe function is problem */ BUG(); } if (ret < 0) goto err; return ret; err: mfd_remove_devices(s5m87xx->dev); s5m_irq_exit(s5m87xx); i2c_unregister_device(s5m87xx->rtc); regmap_exit(s5m87xx->regmap); return ret; }