Commit 34888602 authored by Jingkui Wang's avatar Jingkui Wang Committed by Dmitry Torokhov

Input: drv260x - use generic device properties

Update driver drv260x to use generic device properties so that it can be
used on non-DT systems. We also remove platform data as generic device
properties work on static board code as well.
Signed-off-by: default avatarJingkui Wang <jkwang@google.com>
Signed-off-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
parent ba4cf378
...@@ -18,8 +18,6 @@ ...@@ -18,8 +18,6 @@
#include <linux/i2c.h> #include <linux/i2c.h>
#include <linux/input.h> #include <linux/input.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/of_gpio.h>
#include <linux/platform_device.h>
#include <linux/regmap.h> #include <linux/regmap.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/delay.h> #include <linux/delay.h>
...@@ -27,7 +25,6 @@ ...@@ -27,7 +25,6 @@
#include <linux/regulator/consumer.h> #include <linux/regulator/consumer.h>
#include <dt-bindings/input/ti-drv260x.h> #include <dt-bindings/input/ti-drv260x.h>
#include <linux/platform_data/drv260x-pdata.h>
#define DRV260X_STATUS 0x0 #define DRV260X_STATUS 0x0
#define DRV260X_MODE 0x1 #define DRV260X_MODE 0x1
...@@ -468,86 +465,36 @@ static const struct regmap_config drv260x_regmap_config = { ...@@ -468,86 +465,36 @@ static const struct regmap_config drv260x_regmap_config = {
.cache_type = REGCACHE_NONE, .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, static int drv260x_probe(struct i2c_client *client,
const struct i2c_device_id *id) const struct i2c_device_id *id)
{ {
const struct drv260x_platform_data *pdata = dev_get_platdata(&client->dev);
struct device *dev = &client->dev; struct device *dev = &client->dev;
struct drv260x_data *haptics; struct drv260x_data *haptics;
u32 voltage;
int error; int error;
haptics = devm_kzalloc(dev, sizeof(*haptics), GFP_KERNEL); haptics = devm_kzalloc(dev, sizeof(*haptics), GFP_KERNEL);
if (!haptics) if (!haptics)
return -ENOMEM; return -ENOMEM;
haptics->overdrive_voltage = DRV260X_DEF_OD_CLAMP_VOLT; error = device_property_read_u32(dev, "mode", &haptics->mode);
haptics->rated_voltage = DRV260X_DEF_RATED_VOLT; if (error) {
dev_err(dev, "Can't fetch 'mode' property: %d\n", error);
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; return error;
} else {
dev_err(dev, "Platform data not set\n");
return -ENODEV;
} }
if (haptics->mode < DRV260X_LRA_MODE || if (haptics->mode < DRV260X_LRA_MODE ||
haptics->mode > DRV260X_ERM_MODE) { haptics->mode > DRV260X_ERM_MODE) {
dev_err(dev, "Vibrator mode is invalid: %i\n", haptics->mode); dev_err(dev, "Vibrator mode is invalid: %i\n", haptics->mode);
return -EINVAL; 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 || if (haptics->library < DRV260X_LIB_EMPTY ||
haptics->library > DRV260X_ERM_LIB_F) { haptics->library > DRV260X_ERM_LIB_F) {
dev_err(dev, dev_err(dev,
...@@ -569,6 +516,14 @@ static int drv260x_probe(struct i2c_client *client, ...@@ -569,6 +516,14 @@ static int drv260x_probe(struct i2c_client *client,
return -EINVAL; return -EINVAL;
} }
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"); haptics->regulator = devm_regulator_get(dev, "vbat");
if (IS_ERR(haptics->regulator)) { if (IS_ERR(haptics->regulator)) {
error = PTR_ERR(haptics->regulator); error = PTR_ERR(haptics->regulator);
......
/*
* Platform data for DRV260X haptics driver family
*
* Author: Dan Murphy <dmurphy@ti.com>
*
* Copyright: (C) 2014 Texas Instruments, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*/
#ifndef _LINUX_DRV260X_PDATA_H
#define _LINUX_DRV260X_PDATA_H
struct drv260x_platform_data {
u32 library_selection;
u32 mode;
u32 vib_rated_voltage;
u32 vib_overdrive_voltage;
};
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment