diff options
Diffstat (limited to 'drivers/mfd/max8997.c')
| -rw-r--r-- | drivers/mfd/max8997.c | 52 | 
1 files changed, 31 insertions, 21 deletions
diff --git a/drivers/mfd/max8997.c b/drivers/mfd/max8997.c index cee098c0dae..595364ee178 100644 --- a/drivers/mfd/max8997.c +++ b/drivers/mfd/max8997.c @@ -24,6 +24,7 @@  #include <linux/err.h>  #include <linux/slab.h>  #include <linux/i2c.h> +#include <linux/of.h>  #include <linux/of_irq.h>  #include <linux/interrupt.h>  #include <linux/pm_runtime.h> @@ -39,7 +40,7 @@  #define I2C_ADDR_RTC	(0x0C >> 1)  #define I2C_ADDR_HAPTIC	(0x90 >> 1) -static struct mfd_cell max8997_devs[] = { +static const struct mfd_cell max8997_devs[] = {  	{ .name = "max8997-pmic", },  	{ .name = "max8997-rtc", },  	{ .name = "max8997-battery", }, @@ -50,7 +51,7 @@ static struct mfd_cell max8997_devs[] = {  };  #ifdef CONFIG_OF -static struct of_device_id max8997_pmic_dt_match[] = { +static const struct of_device_id max8997_pmic_dt_match[] = {  	{ .compatible = "maxim,max8997-pmic", .data = (void *)TYPE_MAX8997 },  	{},  }; @@ -132,7 +133,6 @@ int max8997_update_reg(struct i2c_client *i2c, u8 reg, u8 val, u8 mask)  }  EXPORT_SYMBOL_GPL(max8997_update_reg); -#ifdef CONFIG_OF  /*   * Only the common platform data elements for max8997 are parsed here from the   * device tree. Other sub-modules of max8997 such as pmic, rtc and others have @@ -163,25 +163,16 @@ static struct max8997_platform_data *max8997_i2c_parse_dt_pdata(  	return pd;  } -#else -static struct max8997_platform_data *max8997_i2c_parse_dt_pdata( -					struct device *dev) -{ -	return 0; -} -#endif -static inline int max8997_i2c_get_driver_data(struct i2c_client *i2c, +static inline unsigned long max8997_i2c_get_driver_data(struct i2c_client *i2c,  						const struct i2c_device_id *id)  { -#ifdef CONFIG_OF -	if (i2c->dev.of_node) { +	if (IS_ENABLED(CONFIG_OF) && i2c->dev.of_node) {  		const struct of_device_id *match;  		match = of_match_node(max8997_pmic_dt_match, i2c->dev.of_node); -		return (int)match->data; +		return (unsigned long)match->data;  	} -#endif -	return (int)id->driver_data; +	return id->driver_data;  }  static int max8997_i2c_probe(struct i2c_client *i2c, @@ -202,7 +193,7 @@ static int max8997_i2c_probe(struct i2c_client *i2c,  	max8997->type = max8997_i2c_get_driver_data(i2c, id);  	max8997->irq = i2c->irq; -	if (max8997->dev->of_node) { +	if (IS_ENABLED(CONFIG_OF) && max8997->dev->of_node) {  		pdata = max8997_i2c_parse_dt_pdata(max8997->dev);  		if (IS_ERR(pdata))  			return PTR_ERR(pdata); @@ -217,28 +208,45 @@ static int max8997_i2c_probe(struct i2c_client *i2c,  	mutex_init(&max8997->iolock);  	max8997->rtc = i2c_new_dummy(i2c->adapter, I2C_ADDR_RTC); +	if (!max8997->rtc) { +		dev_err(max8997->dev, "Failed to allocate I2C device for RTC\n"); +		return -ENODEV; +	}  	i2c_set_clientdata(max8997->rtc, max8997); +  	max8997->haptic = i2c_new_dummy(i2c->adapter, I2C_ADDR_HAPTIC); +	if (!max8997->haptic) { +		dev_err(max8997->dev, "Failed to allocate I2C device for Haptic\n"); +		ret = -ENODEV; +		goto err_i2c_haptic; +	}  	i2c_set_clientdata(max8997->haptic, max8997); +  	max8997->muic = i2c_new_dummy(i2c->adapter, I2C_ADDR_MUIC); +	if (!max8997->muic) { +		dev_err(max8997->dev, "Failed to allocate I2C device for MUIC\n"); +		ret = -ENODEV; +		goto err_i2c_muic; +	}  	i2c_set_clientdata(max8997->muic, max8997);  	pm_runtime_set_active(max8997->dev);  	max8997_irq_init(max8997); -	mfd_add_devices(max8997->dev, -1, max8997_devs, +	ret = mfd_add_devices(max8997->dev, -1, max8997_devs,  			ARRAY_SIZE(max8997_devs),  			NULL, 0, NULL); +	if (ret < 0) { +		dev_err(max8997->dev, "failed to add MFD devices %d\n", ret); +		goto err_mfd; +	}  	/*  	 * TODO: enable others (flash, muic, rtc, battery, ...) and  	 * check the return value  	 */ -	if (ret < 0) -		goto err_mfd; -  	/* MAX8997 has a power button input. */  	device_init_wakeup(max8997->dev, pdata->wakeup); @@ -247,7 +255,9 @@ static int max8997_i2c_probe(struct i2c_client *i2c,  err_mfd:  	mfd_remove_devices(max8997->dev);  	i2c_unregister_device(max8997->muic); +err_i2c_muic:  	i2c_unregister_device(max8997->haptic); +err_i2c_haptic:  	i2c_unregister_device(max8997->rtc);  	return ret;  }  | 
