Staging: mrst-touchscreen - register platform interface
AC: Reworked to merge with upstream input device work from Dmitry et al. Signed-off-by: Alek Du <alek.du@intel.com> Signed-off-by: Alan Cox <alan@linux.intel.com> Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
This commit is contained in:
@@ -32,7 +32,8 @@
|
|||||||
#include <linux/interrupt.h>
|
#include <linux/interrupt.h>
|
||||||
#include <linux/err.h>
|
#include <linux/err.h>
|
||||||
#include <linux/param.h>
|
#include <linux/param.h>
|
||||||
#include <linux/spi/spi.h>
|
#include <linux/slab.h>
|
||||||
|
#include <linux/platform_device.h>
|
||||||
#include <linux/irq.h>
|
#include <linux/irq.h>
|
||||||
#include <linux/delay.h>
|
#include <linux/delay.h>
|
||||||
#include <asm/intel_scu_ipc.h>
|
#include <asm/intel_scu_ipc.h>
|
||||||
@@ -94,7 +95,7 @@
|
|||||||
|
|
||||||
/* Touch screen device structure */
|
/* Touch screen device structure */
|
||||||
struct mrstouch_dev {
|
struct mrstouch_dev {
|
||||||
struct spi_device *spi;
|
struct device *dev; /* device associated with touch screen */
|
||||||
struct input_dev *input;
|
struct input_dev *input;
|
||||||
char phys[32];
|
char phys[32];
|
||||||
u16 asr; /* Address selection register */
|
u16 asr; /* Address selection register */
|
||||||
@@ -162,7 +163,7 @@ static int mrstouch_nec_adc_read_finish(struct mrstouch_dev *tsdev)
|
|||||||
|
|
||||||
if (!pendet_enabled) {
|
if (!pendet_enabled) {
|
||||||
if (++retry >= 10) {
|
if (++retry >= 10) {
|
||||||
dev_err(&tsdev->spi->dev,
|
dev_err(tsdev->dev,
|
||||||
"Touch screen disabled.\n");
|
"Touch screen disabled.\n");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
@@ -282,7 +283,7 @@ static int mrstouch_nec_adc_read(struct mrstouch_dev *tsdev,
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
ipc_error:
|
ipc_error:
|
||||||
dev_err(&tsdev->spi->dev, "ipc error during adc read\n");
|
dev_err(tsdev->dev, "ipc error during adc read\n");
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -341,7 +342,7 @@ static int mrstouch_fs_adc_read_prepare(struct mrstouch_dev *tsdev)
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
ipc_error:
|
ipc_error:
|
||||||
dev_err(&tsdev->spi->dev, "ipc error during %s\n", __func__);
|
dev_err(tsdev->dev, "ipc error during %s\n", __func__);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -387,7 +388,7 @@ static int mrstouch_fs_adc_read(struct mrstouch_dev *tsdev,
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
ipc_error:
|
ipc_error:
|
||||||
dev_err(&tsdev->spi->dev, "ipc error during %s\n", __func__);
|
dev_err(tsdev->dev, "ipc error during %s\n", __func__);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -428,7 +429,7 @@ static int mrstouch_fs_adc_read_finish(struct mrstouch_dev *tsdev)
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
ipc_error:
|
ipc_error:
|
||||||
dev_err(&tsdev->spi->dev, "ipc error during %s\n", __func__);
|
dev_err(tsdev->dev, "ipc error during %s\n", __func__);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -560,7 +561,7 @@ static int __devinit mrstouch_adc_init(struct mrstouch_dev *tsdev)
|
|||||||
|
|
||||||
err = mrstouch_read_pmic_id(&tsdev->vendor, &tsdev->rev);
|
err = mrstouch_read_pmic_id(&tsdev->vendor, &tsdev->rev);
|
||||||
if (err) {
|
if (err) {
|
||||||
dev_err(&tsdev->spi->dev, "Unable to read PMIC id\n");
|
dev_err(tsdev->dev, "Unable to read PMIC id\n");
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -579,14 +580,14 @@ static int __devinit mrstouch_adc_init(struct mrstouch_dev *tsdev)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
dev_err(&tsdev->spi->dev,
|
dev_err(tsdev->dev,
|
||||||
"Unsupported touchscreen: %d\n", tsdev->vendor);
|
"Unsupported touchscreen: %d\n", tsdev->vendor);
|
||||||
return -ENXIO;
|
return -ENXIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
start = mrstouch_chan_parse(tsdev);
|
start = mrstouch_chan_parse(tsdev);
|
||||||
if (start < 0) {
|
if (start < 0) {
|
||||||
dev_err(&tsdev->spi->dev, "Unable to parse channels\n");
|
dev_err(tsdev->dev, "Unable to parse channels\n");
|
||||||
return start;
|
return start;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -627,41 +628,43 @@ static int __devinit mrstouch_adc_init(struct mrstouch_dev *tsdev)
|
|||||||
|
|
||||||
|
|
||||||
/* Probe function for touch screen driver */
|
/* Probe function for touch screen driver */
|
||||||
static int __devinit mrstouch_probe(struct spi_device *spi)
|
static int __devinit mrstouch_probe(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
struct mrstouch_dev *tsdev;
|
struct mrstouch_dev *tsdev;
|
||||||
struct input_dev *input;
|
struct input_dev *input;
|
||||||
int err;
|
int err;
|
||||||
|
int irq;
|
||||||
|
|
||||||
if (!spi->irq) {
|
irq = platform_get_irq(pdev, 0);
|
||||||
dev_err(&spi->dev, "no interrupt assigned\n");
|
if (irq < 0) {
|
||||||
|
dev_err(&pdev->dev, "no interrupt assigned\n");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
tsdev = kzalloc(sizeof(struct mrstouch_dev), GFP_KERNEL);
|
tsdev = kzalloc(sizeof(struct mrstouch_dev), GFP_KERNEL);
|
||||||
input = input_allocate_device();
|
input = input_allocate_device();
|
||||||
if (!tsdev || !input) {
|
if (!tsdev || !input) {
|
||||||
dev_err(&spi->dev, "unable to allocate memory\n");
|
dev_err(&pdev->dev, "unable to allocate memory\n");
|
||||||
err = -ENOMEM;
|
err = -ENOMEM;
|
||||||
goto err_free_mem;
|
goto err_free_mem;
|
||||||
}
|
}
|
||||||
|
|
||||||
tsdev->spi = spi;
|
tsdev->dev = &pdev->dev;
|
||||||
tsdev->input = input;
|
tsdev->input = input;
|
||||||
tsdev->irq = spi->irq;
|
tsdev->irq = irq;
|
||||||
|
|
||||||
snprintf(tsdev->phys, sizeof(tsdev->phys),
|
snprintf(tsdev->phys, sizeof(tsdev->phys),
|
||||||
"%s/input0", dev_name(&spi->dev));
|
"%s/input0", dev_name(tsdev->dev));
|
||||||
|
|
||||||
err = mrstouch_adc_init(tsdev);
|
err = mrstouch_adc_init(tsdev);
|
||||||
if (err) {
|
if (err) {
|
||||||
dev_err(&spi->dev, "ADC initialization failed\n");
|
dev_err(&pdev->dev, "ADC initialization failed\n");
|
||||||
goto err_free_mem;
|
goto err_free_mem;
|
||||||
}
|
}
|
||||||
|
|
||||||
input->name = "mrst_touchscreen";
|
input->name = "mrst_touchscreen";
|
||||||
input->phys = tsdev->phys;
|
input->phys = tsdev->phys;
|
||||||
input->dev.parent = &spi->dev;
|
input->dev.parent = tsdev->dev;
|
||||||
|
|
||||||
input->id.vendor = tsdev->vendor;
|
input->id.vendor = tsdev->vendor;
|
||||||
input->id.version = tsdev->rev;
|
input->id.version = tsdev->rev;
|
||||||
@@ -679,17 +682,17 @@ static int __devinit mrstouch_probe(struct spi_device *spi)
|
|||||||
err = request_threaded_irq(tsdev->irq, NULL, mrstouch_pendet_irq,
|
err = request_threaded_irq(tsdev->irq, NULL, mrstouch_pendet_irq,
|
||||||
0, "mrstouch", tsdev);
|
0, "mrstouch", tsdev);
|
||||||
if (err) {
|
if (err) {
|
||||||
dev_err(&tsdev->spi->dev, "unable to allocate irq\n");
|
dev_err(tsdev->dev, "unable to allocate irq\n");
|
||||||
goto err_free_mem;
|
goto err_free_mem;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = input_register_device(tsdev->input);
|
err = input_register_device(tsdev->input);
|
||||||
if (err) {
|
if (err) {
|
||||||
dev_err(&tsdev->spi->dev, "unable to register input device\n");
|
dev_err(tsdev->dev, "unable to register input device\n");
|
||||||
goto err_free_irq;
|
goto err_free_irq;
|
||||||
}
|
}
|
||||||
|
|
||||||
spi_set_drvdata(spi, tsdev);
|
platform_set_drvdata(pdev, tsdev);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
err_free_irq:
|
err_free_irq:
|
||||||
@@ -700,38 +703,37 @@ err_free_mem:
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int __devexit mrstouch_remove(struct spi_device *spi)
|
static int __devexit mrstouch_remove(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
struct mrstouch_dev *tsdev = spi_get_drvdata(spi);
|
struct mrstouch_dev *tsdev = platform_get_drvdata(pdev);
|
||||||
|
|
||||||
free_irq(tsdev->irq, tsdev);
|
free_irq(tsdev->irq, tsdev);
|
||||||
input_unregister_device(tsdev->input);
|
input_unregister_device(tsdev->input);
|
||||||
kfree(tsdev);
|
kfree(tsdev);
|
||||||
|
|
||||||
spi_set_drvdata(spi, NULL);
|
platform_set_drvdata(pdev, NULL);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct spi_driver mrstouch_driver = {
|
static struct platform_driver mrstouch_driver = {
|
||||||
.driver = {
|
.driver = {
|
||||||
.name = "pmic_touch",
|
.name = "pmic_touch",
|
||||||
.bus = &spi_bus_type,
|
.owner = THIS_MODULE,
|
||||||
.owner = THIS_MODULE,
|
|
||||||
},
|
},
|
||||||
.probe = mrstouch_probe,
|
.probe = mrstouch_probe,
|
||||||
.remove = __devexit_p(mrstouch_remove),
|
.remove = __devexit_p(mrstouch_remove),
|
||||||
};
|
};
|
||||||
|
|
||||||
static int __init mrstouch_init(void)
|
static int __init mrstouch_init(void)
|
||||||
{
|
{
|
||||||
return spi_register_driver(&mrstouch_driver);
|
return platform_driver_register(&mrstouch_driver);
|
||||||
}
|
}
|
||||||
module_init(mrstouch_init);
|
module_init(mrstouch_init);
|
||||||
|
|
||||||
static void __exit mrstouch_exit(void)
|
static void __exit mrstouch_exit(void)
|
||||||
{
|
{
|
||||||
spi_unregister_driver(&mrstouch_driver);
|
platform_driver_unregister(&mrstouch_driver);
|
||||||
}
|
}
|
||||||
module_exit(mrstouch_exit);
|
module_exit(mrstouch_exit);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user