static int __devinit ts_probe(struct platform_device *pdev)
{
int result;
struct input_dev *input_dev;
struct resource *res, *ioarea;
struct ts *ts;
unsigned int x_max, y_max, pressure_max;
struct msm_ts_platform_data *pdata = pdev->dev.platform_data;
/* The primary initialization of the TS Hardware
* is taken care of by the ADC code on the modem side
*/
ts = kzalloc(sizeof(struct ts), GFP_KERNEL);
input_dev = input_allocate_device();
if (!input_dev || !ts) {
result = -ENOMEM;
goto fail_alloc_mem;
}
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!res) {
dev_err(&pdev->dev, "Cannot get IORESOURCE_MEM\n");
result = -ENOENT;
goto fail_alloc_mem;
}
ts->irq = platform_get_irq(pdev, 0);
if (!ts->irq) {
dev_err(&pdev->dev, "Could not get IORESOURCE_IRQ\n");
result = -ENODEV;
goto fail_alloc_mem;
}
ioarea = request_mem_region(res->start, resource_size(res), pdev->name);
if (!ioarea) {
dev_err(&pdev->dev, "Could not allocate io region\n");
result = -EBUSY;
goto fail_alloc_mem;
}
virt = ioremap(res->start, resource_size(res));
if (!virt) {
dev_err(&pdev->dev, "Could not ioremap region\n");
result = -ENOMEM;
goto fail_ioremap;
}
input_dev->name = TS_DRIVER_NAME;
input_dev->phys = "msm_touch/input0";
input_dev->id.bustype = BUS_HOST;
input_dev->id.vendor = 0x0001;
input_dev->id.product = 0x0002;
input_dev->id.version = 0x0100;
input_dev->dev.parent = &pdev->dev;
input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
input_dev->absbit[0] = BIT(ABS_X) | BIT(ABS_Y) | BIT(ABS_PRESSURE);
input_dev->absbit[BIT_WORD(ABS_MISC)] = BIT_MASK(ABS_MISC);
input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
if (pdata) {
x_max = pdata->x_max ? : X_MAX;
y_max = pdata->y_max ? : Y_MAX;
pressure_max = pdata->pressure_max ? : P_MAX;
} else {
x_max = X_MAX;
y_max = Y_MAX;
pressure_max = P_MAX;
}
ts->x_max = x_max;
ts->y_max = y_max;
input_set_abs_params(input_dev, ABS_X, 0, x_max, 0, 0);
input_set_abs_params(input_dev, ABS_Y, 0, y_max, 0, 0);
input_set_abs_params(input_dev, ABS_PRESSURE, 0, pressure_max, 0, 0);
result = input_register_device(input_dev);
if (result)
goto fail_ip_reg;
ts->input = input_dev;
setup_timer(&ts->timer, ts_timer, (unsigned long)ts);
result = request_irq(ts->irq, ts_interrupt, IRQF_TRIGGER_RISING,
"touchscreen", ts);
if (result)
goto fail_req_irq;
platform_set_drvdata(pdev, ts);
return 0;
fail_req_irq:
input_unregister_device(input_dev);
input_dev = NULL;
fail_ip_reg:
iounmap(virt);
fail_ioremap:
release_mem_region(res->start, resource_size(res));
fail_alloc_mem:
input_free_device(input_dev);
kfree(ts);
return result;
}
static int __devexit ts_remove(struct platform_device *pdev)
{
struct resource *res;
struct ts *ts = platform_get_drvdata(pdev);
free_irq(ts->irq, ts);
del_timer_sync(&ts->timer);
input_unregister_device(ts->input);
iounmap(virt);
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
release_mem_region(res->start, resource_size(res));
platform_set_drvdata(pdev, NULL);
kfree(ts);
return 0;
}
static struct platform_driver ts_driver = {
.probe = ts_probe,
.remove = __devexit_p(ts_remove),
.driver = {
.name = TS_DRIVER_NAME,
.owner = THIS_MODULE,
},
};
static int __init ts_init(void)
{
return platform_driver_register(&ts_driver);
}
module_init(ts_init);
static void __exit ts_exit(void)
{
platform_driver_unregister(&ts_driver);
}
module_exit(ts_exit);
MODULE_DESCRIPTION("MSM Touch Screen driver");
MODULE_LICENSE("GPL v2");
MODULE_ALIAS("platform:msm_touchscreen");