diff options
Diffstat (limited to 'drivers/input/misc/drv260x.c')
-rw-r--r-- | drivers/input/misc/drv260x.c | 119 |
1 files changed, 33 insertions, 86 deletions
diff --git a/drivers/input/misc/drv260x.c b/drivers/input/misc/drv260x.c index 2adfd86c869a..0a2b865b1000 100644 --- a/drivers/input/misc/drv260x.c +++ b/drivers/input/misc/drv260x.c @@ -18,8 +18,6 @@ #include <linux/i2c.h> #include <linux/input.h> #include <linux/module.h> -#include <linux/of_gpio.h> -#include <linux/platform_device.h> #include <linux/regmap.h> #include <linux/slab.h> #include <linux/delay.h> @@ -27,7 +25,6 @@ #include <linux/regulator/consumer.h> #include <dt-bindings/input/ti-drv260x.h> -#include <linux/platform_data/drv260x-pdata.h> #define DRV260X_STATUS 0x0 #define DRV260X_MODE 0x1 @@ -468,90 +465,39 @@ static const struct regmap_config drv260x_regmap_config = { .cache_type = REGCACHE_NONE, }; -#ifdef CONFIG_OF -static int drv260x_parse_dt(struct device *dev, - struct drv260x_data *haptics) -{ - struct device_node *np = dev->of_node; - unsigned int voltage; - int error; - - error = of_property_read_u32(np, "mode", &haptics->mode); - if (error) { - dev_err(dev, "%s: No entry for mode\n", __func__); - return error; - } - - error = of_property_read_u32(np, "library-sel", &haptics->library); - if (error) { - dev_err(dev, "%s: No entry for library selection\n", - __func__); - return error; - } - - error = of_property_read_u32(np, "vib-rated-mv", &voltage); - if (!error) - haptics->rated_voltage = drv260x_calculate_voltage(voltage); - - - error = of_property_read_u32(np, "vib-overdrive-mv", &voltage); - if (!error) - haptics->overdrive_voltage = drv260x_calculate_voltage(voltage); - - return 0; -} -#else -static inline int drv260x_parse_dt(struct device *dev, - struct drv260x_data *haptics) -{ - dev_err(dev, "no platform data defined\n"); - - return -EINVAL; -} -#endif - static int drv260x_probe(struct i2c_client *client, const struct i2c_device_id *id) { - const struct drv260x_platform_data *pdata = dev_get_platdata(&client->dev); + struct device *dev = &client->dev; struct drv260x_data *haptics; + u32 voltage; int error; - haptics = devm_kzalloc(&client->dev, sizeof(*haptics), GFP_KERNEL); + haptics = devm_kzalloc(dev, sizeof(*haptics), GFP_KERNEL); if (!haptics) return -ENOMEM; - haptics->rated_voltage = DRV260X_DEF_OD_CLAMP_VOLT; - haptics->rated_voltage = DRV260X_DEF_RATED_VOLT; - - if (pdata) { - haptics->mode = pdata->mode; - haptics->library = pdata->library_selection; - if (pdata->vib_overdrive_voltage) - haptics->overdrive_voltage = drv260x_calculate_voltage(pdata->vib_overdrive_voltage); - if (pdata->vib_rated_voltage) - haptics->rated_voltage = drv260x_calculate_voltage(pdata->vib_rated_voltage); - } else if (client->dev.of_node) { - error = drv260x_parse_dt(&client->dev, haptics); - if (error) - return error; - } else { - dev_err(&client->dev, "Platform data not set\n"); - return -ENODEV; + error = device_property_read_u32(dev, "mode", &haptics->mode); + if (error) { + dev_err(dev, "Can't fetch 'mode' property: %d\n", error); + return error; } - if (haptics->mode < DRV260X_LRA_MODE || haptics->mode > DRV260X_ERM_MODE) { - dev_err(&client->dev, - "Vibrator mode is invalid: %i\n", - haptics->mode); + dev_err(dev, "Vibrator mode is invalid: %i\n", haptics->mode); return -EINVAL; } + error = device_property_read_u32(dev, "library-sel", &haptics->library); + if (error) { + dev_err(dev, "Can't fetch 'library-sel' property: %d\n", error); + return error; + } + if (haptics->library < DRV260X_LIB_EMPTY || haptics->library > DRV260X_ERM_LIB_F) { - dev_err(&client->dev, + dev_err(dev, "Library value is invalid: %i\n", haptics->library); return -EINVAL; } @@ -559,40 +505,44 @@ static int drv260x_probe(struct i2c_client *client, if (haptics->mode == DRV260X_LRA_MODE && haptics->library != DRV260X_LIB_EMPTY && haptics->library != DRV260X_LIB_LRA) { - dev_err(&client->dev, - "LRA Mode with ERM Library mismatch\n"); + dev_err(dev, "LRA Mode with ERM Library mismatch\n"); return -EINVAL; } if (haptics->mode == DRV260X_ERM_MODE && (haptics->library == DRV260X_LIB_EMPTY || haptics->library == DRV260X_LIB_LRA)) { - dev_err(&client->dev, - "ERM Mode with LRA Library mismatch\n"); + dev_err(dev, "ERM Mode with LRA Library mismatch\n"); return -EINVAL; } - haptics->regulator = devm_regulator_get(&client->dev, "vbat"); + error = device_property_read_u32(dev, "vib-rated-mv", &voltage); + haptics->rated_voltage = error ? DRV260X_DEF_RATED_VOLT : + drv260x_calculate_voltage(voltage); + + error = device_property_read_u32(dev, "vib-overdrive-mv", &voltage); + haptics->overdrive_voltage = error ? DRV260X_DEF_OD_CLAMP_VOLT : + drv260x_calculate_voltage(voltage); + + haptics->regulator = devm_regulator_get(dev, "vbat"); if (IS_ERR(haptics->regulator)) { error = PTR_ERR(haptics->regulator); - dev_err(&client->dev, - "unable to get regulator, error: %d\n", error); + dev_err(dev, "unable to get regulator, error: %d\n", error); return error; } - haptics->enable_gpio = devm_gpiod_get_optional(&client->dev, "enable", + haptics->enable_gpio = devm_gpiod_get_optional(dev, "enable", GPIOD_OUT_HIGH); if (IS_ERR(haptics->enable_gpio)) return PTR_ERR(haptics->enable_gpio); - haptics->input_dev = devm_input_allocate_device(&client->dev); + haptics->input_dev = devm_input_allocate_device(dev); if (!haptics->input_dev) { dev_err(&client->dev, "Failed to allocate input device\n"); return -ENOMEM; } haptics->input_dev->name = "drv260x:haptics"; - haptics->input_dev->dev.parent = client->dev.parent; haptics->input_dev->close = drv260x_close; input_set_drvdata(haptics->input_dev, haptics); input_set_capability(haptics->input_dev, EV_FF, FF_RUMBLE); @@ -600,8 +550,7 @@ static int drv260x_probe(struct i2c_client *client, error = input_ff_create_memless(haptics->input_dev, NULL, drv260x_haptics_play); if (error) { - dev_err(&client->dev, "input_ff_create() failed: %d\n", - error); + dev_err(dev, "input_ff_create() failed: %d\n", error); return error; } @@ -613,21 +562,19 @@ static int drv260x_probe(struct i2c_client *client, haptics->regmap = devm_regmap_init_i2c(client, &drv260x_regmap_config); if (IS_ERR(haptics->regmap)) { error = PTR_ERR(haptics->regmap); - dev_err(&client->dev, "Failed to allocate register map: %d\n", - error); + dev_err(dev, "Failed to allocate register map: %d\n", error); return error; } error = drv260x_init(haptics); if (error) { - dev_err(&client->dev, "Device init failed: %d\n", error); + dev_err(dev, "Device init failed: %d\n", error); return error; } error = input_register_device(haptics->input_dev); if (error) { - dev_err(&client->dev, "couldn't register input device: %d\n", - error); + dev_err(dev, "couldn't register input device: %d\n", error); return error; } |