Commit f5189d07 authored by Beomho Seo's avatar Beomho Seo Committed by Dmitry Torokhov

Input: mcs5000_ts - switch to using managed resources

Let's switch the driver to use managed resources, this will simplify
error handling and driver unbinding logic.
Signed-off-by: default avatarBeomho Seo <beomho.seo@samsung.com>
Signed-off-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
parent 21d128a7
...@@ -161,10 +161,9 @@ static irqreturn_t mcs5000_ts_interrupt(int irq, void *dev_id) ...@@ -161,10 +161,9 @@ static irqreturn_t mcs5000_ts_interrupt(int irq, void *dev_id)
return IRQ_HANDLED; return IRQ_HANDLED;
} }
static void mcs5000_ts_phys_init(struct mcs5000_ts_data *data) static void mcs5000_ts_phys_init(struct mcs5000_ts_data *data,
const struct mcs_platform_data *platform_data)
{ {
const struct mcs_platform_data *platform_data =
data->platform_data;
struct i2c_client *client = data->client; struct i2c_client *client = data->client;
/* Touch reset & sleep mode */ /* Touch reset & sleep mode */
...@@ -187,26 +186,30 @@ static void mcs5000_ts_phys_init(struct mcs5000_ts_data *data) ...@@ -187,26 +186,30 @@ static void mcs5000_ts_phys_init(struct mcs5000_ts_data *data)
} }
static int mcs5000_ts_probe(struct i2c_client *client, static int mcs5000_ts_probe(struct i2c_client *client,
const struct i2c_device_id *id) const struct i2c_device_id *id)
{ {
const struct mcs_platform_data *pdata;
struct mcs5000_ts_data *data; struct mcs5000_ts_data *data;
struct input_dev *input_dev; struct input_dev *input_dev;
int ret; int error;
if (!dev_get_platdata(&client->dev)) pdata = dev_get_platdata(&client->dev);
if (!pdata)
return -EINVAL; return -EINVAL;
data = kzalloc(sizeof(struct mcs5000_ts_data), GFP_KERNEL); data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL);
input_dev = input_allocate_device(); if (!data) {
if (!data || !input_dev) {
dev_err(&client->dev, "Failed to allocate memory\n"); dev_err(&client->dev, "Failed to allocate memory\n");
ret = -ENOMEM; return -ENOMEM;
goto err_free_mem;
} }
data->client = client; data->client = client;
data->input_dev = input_dev;
data->platform_data = dev_get_platdata(&client->dev); input_dev = devm_input_allocate_device(&client->dev);
if (!input_dev) {
dev_err(&client->dev, "Failed to allocate input device\n");
return -ENOMEM;
}
input_dev->name = "MELFAS MCS-5000 Touchscreen"; input_dev->name = "MELFAS MCS-5000 Touchscreen";
input_dev->id.bustype = BUS_I2C; input_dev->id.bustype = BUS_I2C;
...@@ -219,43 +222,29 @@ static int mcs5000_ts_probe(struct i2c_client *client, ...@@ -219,43 +222,29 @@ static int mcs5000_ts_probe(struct i2c_client *client,
input_set_abs_params(input_dev, ABS_Y, 0, MCS5000_MAX_YC, 0, 0); input_set_abs_params(input_dev, ABS_Y, 0, MCS5000_MAX_YC, 0, 0);
input_set_drvdata(input_dev, data); input_set_drvdata(input_dev, data);
data->input_dev = input_dev;
if (data->platform_data->cfg_pin) if (pdata->cfg_pin)
data->platform_data->cfg_pin(); pdata->cfg_pin();
ret = request_threaded_irq(client->irq, NULL, mcs5000_ts_interrupt,
IRQF_TRIGGER_LOW | IRQF_ONESHOT, "mcs5000_ts", data);
if (ret < 0) { error = devm_request_threaded_irq(&client->dev, client->irq,
NULL, mcs5000_ts_interrupt,
IRQF_TRIGGER_LOW | IRQF_ONESHOT,
"mcs5000_ts", data);
if (error) {
dev_err(&client->dev, "Failed to register interrupt\n"); dev_err(&client->dev, "Failed to register interrupt\n");
goto err_free_mem; return error;
} }
ret = input_register_device(data->input_dev); error = input_register_device(data->input_dev);
if (ret < 0) if (error) {
goto err_free_irq; dev_err(&client->dev, "Failed to register input device\n");
return error;
}
mcs5000_ts_phys_init(data); mcs5000_ts_phys_init(data, pdata);
i2c_set_clientdata(client, data); i2c_set_clientdata(client, data);
return 0;
err_free_irq:
free_irq(client->irq, data);
err_free_mem:
input_free_device(input_dev);
kfree(data);
return ret;
}
static int mcs5000_ts_remove(struct i2c_client *client)
{
struct mcs5000_ts_data *data = i2c_get_clientdata(client);
free_irq(client->irq, data);
input_unregister_device(data->input_dev);
kfree(data);
return 0; return 0;
} }
...@@ -274,14 +263,15 @@ static int mcs5000_ts_resume(struct device *dev) ...@@ -274,14 +263,15 @@ static int mcs5000_ts_resume(struct device *dev)
{ {
struct i2c_client *client = to_i2c_client(dev); struct i2c_client *client = to_i2c_client(dev);
struct mcs5000_ts_data *data = i2c_get_clientdata(client); struct mcs5000_ts_data *data = i2c_get_clientdata(client);
const struct mcs_platform_data *pdata = dev_get_platdata(dev);
mcs5000_ts_phys_init(data); mcs5000_ts_phys_init(data, pdata);
return 0; return 0;
} }
#endif
static SIMPLE_DEV_PM_OPS(mcs5000_ts_pm, mcs5000_ts_suspend, mcs5000_ts_resume); static SIMPLE_DEV_PM_OPS(mcs5000_ts_pm, mcs5000_ts_suspend, mcs5000_ts_resume);
#endif
static const struct i2c_device_id mcs5000_ts_id[] = { static const struct i2c_device_id mcs5000_ts_id[] = {
{ "mcs5000_ts", 0 }, { "mcs5000_ts", 0 },
...@@ -291,12 +281,9 @@ MODULE_DEVICE_TABLE(i2c, mcs5000_ts_id); ...@@ -291,12 +281,9 @@ MODULE_DEVICE_TABLE(i2c, mcs5000_ts_id);
static struct i2c_driver mcs5000_ts_driver = { static struct i2c_driver mcs5000_ts_driver = {
.probe = mcs5000_ts_probe, .probe = mcs5000_ts_probe,
.remove = mcs5000_ts_remove,
.driver = { .driver = {
.name = "mcs5000_ts", .name = "mcs5000_ts",
#ifdef CONFIG_PM
.pm = &mcs5000_ts_pm, .pm = &mcs5000_ts_pm,
#endif
}, },
.id_table = mcs5000_ts_id, .id_table = mcs5000_ts_id,
}; };
......
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