Commit c72f61e7 authored by Robert Jarzmik's avatar Robert Jarzmik Committed by Mark Brown

Input: wm97xx: split out touchscreen registering

wm97xx-core does several things in it initialization :
 - touchscreen input device setup
 - battery device creation

As the wm97xx is actually a multi-function device handling an audio
codec, a touchscreen, a gpio block and an ADC, reshape the probing to
isolate what is truly input/touchscreen specific from the remaining
part.

This is only code shuffling, there is no functional change.
Signed-off-by: default avatarRobert Jarzmik <robert.jarzmik@free.fr>
Acked-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
Acked-by: default avatarCharles Keepax <ckeepax@opensource.wolfsonmicro.com>
Signed-off-by: default avatarMark Brown <broonie@kernel.org>
parent 2bd6bf03
...@@ -581,27 +581,85 @@ static void wm97xx_ts_input_close(struct input_dev *idev) ...@@ -581,27 +581,85 @@ static void wm97xx_ts_input_close(struct input_dev *idev)
wm->codec->acc_enable(wm, 0); wm->codec->acc_enable(wm, 0);
} }
static int wm97xx_probe(struct device *dev) static int wm97xx_register_touch(struct wm97xx *wm)
{ {
struct wm97xx *wm; struct wm97xx_pdata *pdata = dev_get_platdata(wm->dev);
struct wm97xx_pdata *pdata = dev_get_platdata(dev); int ret;
int ret = 0, id = 0;
wm = kzalloc(sizeof(struct wm97xx), GFP_KERNEL); wm->input_dev = devm_input_allocate_device(wm->dev);
if (!wm) if (wm->input_dev == NULL)
return -ENOMEM; return -ENOMEM;
mutex_init(&wm->codec_mutex);
wm->dev = dev; /* set up touch configuration */
dev_set_drvdata(dev, wm); wm->input_dev->name = "wm97xx touchscreen";
wm->ac97 = to_ac97_t(dev); wm->input_dev->phys = "wm97xx";
wm->input_dev->open = wm97xx_ts_input_open;
wm->input_dev->close = wm97xx_ts_input_close;
__set_bit(EV_ABS, wm->input_dev->evbit);
__set_bit(EV_KEY, wm->input_dev->evbit);
__set_bit(BTN_TOUCH, wm->input_dev->keybit);
input_set_abs_params(wm->input_dev, ABS_X, abs_x[0], abs_x[1],
abs_x[2], 0);
input_set_abs_params(wm->input_dev, ABS_Y, abs_y[0], abs_y[1],
abs_y[2], 0);
input_set_abs_params(wm->input_dev, ABS_PRESSURE, abs_p[0], abs_p[1],
abs_p[2], 0);
input_set_drvdata(wm->input_dev, wm);
wm->input_dev->dev.parent = wm->dev;
ret = input_register_device(wm->input_dev);
if (ret)
return ret;
/*
* register our extended touch device (for machine specific
* extensions)
*/
wm->touch_dev = platform_device_alloc("wm97xx-touch", -1);
if (!wm->touch_dev) {
ret = -ENOMEM;
goto touch_err;
}
platform_set_drvdata(wm->touch_dev, wm);
wm->touch_dev->dev.parent = wm->dev;
wm->touch_dev->dev.platform_data = pdata;
ret = platform_device_add(wm->touch_dev);
if (ret < 0)
goto touch_reg_err;
return 0;
touch_reg_err:
platform_device_put(wm->touch_dev);
touch_err:
input_unregister_device(wm->input_dev);
wm->input_dev = NULL;
return ret;
}
static void wm97xx_unregister_touch(struct wm97xx *wm)
{
platform_device_unregister(wm->touch_dev);
input_unregister_device(wm->input_dev);
wm->input_dev = NULL;
}
static int _wm97xx_probe(struct wm97xx *wm)
{
int id = 0;
mutex_init(&wm->codec_mutex);
dev_set_drvdata(wm->dev, wm);
/* check that we have a supported codec */ /* check that we have a supported codec */
id = wm97xx_reg_read(wm, AC97_VENDOR_ID1); id = wm97xx_reg_read(wm, AC97_VENDOR_ID1);
if (id != WM97XX_ID1) { if (id != WM97XX_ID1) {
dev_err(dev, "Device with vendor %04x is not a wm97xx\n", id); dev_err(wm->dev,
ret = -ENODEV; "Device with vendor %04x is not a wm97xx\n", id);
goto alloc_err; return -ENODEV;
} }
wm->id = wm97xx_reg_read(wm, AC97_VENDOR_ID2); wm->id = wm97xx_reg_read(wm, AC97_VENDOR_ID2);
...@@ -629,8 +687,7 @@ static int wm97xx_probe(struct device *dev) ...@@ -629,8 +687,7 @@ static int wm97xx_probe(struct device *dev)
default: default:
dev_err(wm->dev, "Support for wm97%02x not compiled in.\n", dev_err(wm->dev, "Support for wm97%02x not compiled in.\n",
wm->id & 0xff); wm->id & 0xff);
ret = -ENODEV; return -ENODEV;
goto alloc_err;
} }
/* set up physical characteristics */ /* set up physical characteristics */
...@@ -644,79 +701,58 @@ static int wm97xx_probe(struct device *dev) ...@@ -644,79 +701,58 @@ static int wm97xx_probe(struct device *dev)
wm->gpio[4] = wm97xx_reg_read(wm, AC97_GPIO_STATUS); wm->gpio[4] = wm97xx_reg_read(wm, AC97_GPIO_STATUS);
wm->gpio[5] = wm97xx_reg_read(wm, AC97_MISC_AFE); wm->gpio[5] = wm97xx_reg_read(wm, AC97_MISC_AFE);
wm->input_dev = input_allocate_device(); return wm97xx_register_touch(wm);
if (wm->input_dev == NULL) { }
ret = -ENOMEM;
goto alloc_err;
}
/* set up touch configuration */
wm->input_dev->name = "wm97xx touchscreen";
wm->input_dev->phys = "wm97xx";
wm->input_dev->open = wm97xx_ts_input_open;
wm->input_dev->close = wm97xx_ts_input_close;
__set_bit(EV_ABS, wm->input_dev->evbit);
__set_bit(EV_KEY, wm->input_dev->evbit);
__set_bit(BTN_TOUCH, wm->input_dev->keybit);
input_set_abs_params(wm->input_dev, ABS_X, abs_x[0], abs_x[1],
abs_x[2], 0);
input_set_abs_params(wm->input_dev, ABS_Y, abs_y[0], abs_y[1],
abs_y[2], 0);
input_set_abs_params(wm->input_dev, ABS_PRESSURE, abs_p[0], abs_p[1],
abs_p[2], 0);
input_set_drvdata(wm->input_dev, wm); static void wm97xx_remove_battery(struct wm97xx *wm)
wm->input_dev->dev.parent = dev; {
platform_device_unregister(wm->battery_dev);
}
ret = input_register_device(wm->input_dev); static int wm97xx_add_battery(struct wm97xx *wm,
if (ret < 0) struct wm97xx_batt_pdata *pdata)
goto dev_alloc_err; {
int ret;
/* register our battery device */
wm->battery_dev = platform_device_alloc("wm97xx-battery", -1); wm->battery_dev = platform_device_alloc("wm97xx-battery", -1);
if (!wm->battery_dev) { if (!wm->battery_dev)
ret = -ENOMEM; return -ENOMEM;
goto batt_err;
}
platform_set_drvdata(wm->battery_dev, wm); platform_set_drvdata(wm->battery_dev, wm);
wm->battery_dev->dev.parent = dev; wm->battery_dev->dev.parent = wm->dev;
wm->battery_dev->dev.platform_data = pdata ? pdata->batt_pdata : NULL; wm->battery_dev->dev.platform_data = pdata;
ret = platform_device_add(wm->battery_dev); ret = platform_device_add(wm->battery_dev);
if (ret < 0) if (ret)
goto batt_reg_err; platform_device_put(wm->battery_dev);
/* register our extended touch device (for machine specific return ret;
* extensions) */ }
wm->touch_dev = platform_device_alloc("wm97xx-touch", -1);
if (!wm->touch_dev) { static int wm97xx_probe(struct device *dev)
ret = -ENOMEM; {
goto touch_err; struct wm97xx *wm;
} int ret;
platform_set_drvdata(wm->touch_dev, wm); struct wm97xx_pdata *pdata = dev_get_platdata(dev);
wm->touch_dev->dev.parent = dev;
wm->touch_dev->dev.platform_data = pdata; wm = devm_kzalloc(dev, sizeof(struct wm97xx), GFP_KERNEL);
ret = platform_device_add(wm->touch_dev); if (!wm)
return -ENOMEM;
wm->dev = dev;
wm->ac97 = to_ac97_t(dev);
ret = _wm97xx_probe(wm);
if (ret)
return ret;
ret = wm97xx_add_battery(wm, pdata ? pdata->batt_pdata : NULL);
if (ret < 0) if (ret < 0)
goto touch_reg_err; goto batt_err;
return ret; return ret;
touch_reg_err: batt_err:
platform_device_put(wm->touch_dev); wm97xx_unregister_touch(wm);
touch_err:
platform_device_del(wm->battery_dev);
batt_reg_err:
platform_device_put(wm->battery_dev);
batt_err:
input_unregister_device(wm->input_dev);
wm->input_dev = NULL;
dev_alloc_err:
input_free_device(wm->input_dev);
alloc_err:
kfree(wm);
return ret; return ret;
} }
...@@ -724,10 +760,8 @@ static int wm97xx_remove(struct device *dev) ...@@ -724,10 +760,8 @@ static int wm97xx_remove(struct device *dev)
{ {
struct wm97xx *wm = dev_get_drvdata(dev); struct wm97xx *wm = dev_get_drvdata(dev);
platform_device_unregister(wm->battery_dev); wm97xx_remove_battery(wm);
platform_device_unregister(wm->touch_dev); wm97xx_unregister_touch(wm);
input_unregister_device(wm->input_dev);
kfree(wm);
return 0; return 0;
} }
......
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