2 * AD714X CapTouch Programmable Controller driver (SPI bus)
4 * Copyright 2009 Analog Devices Inc.
6 * Licensed under the GPL-2 or later.
9 #include <linux/input.h> /* BUS_I2C */
10 #include <linux/module.h>
11 #include <linux/spi/spi.h>
12 #include <linux/types.h>
15 #define AD714x_SPI_CMD_PREFIX 0xE000 /* bits 15:11 */
16 #define AD714x_SPI_READ BIT(10)
19 static int ad714x_spi_suspend(struct spi_device
*spi
, pm_message_t message
)
21 return ad714x_disable(spi_get_drvdata(spi
));
24 static int ad714x_spi_resume(struct spi_device
*spi
)
26 return ad714x_enable(spi_get_drvdata(spi
));
29 # define ad714x_spi_suspend NULL
30 # define ad714x_spi_resume NULL
33 static int ad714x_spi_read(struct device
*dev
, unsigned short reg
,
36 struct spi_device
*spi
= to_spi_device(dev
);
37 unsigned short tx
= AD714x_SPI_CMD_PREFIX
| AD714x_SPI_READ
| reg
;
39 return spi_write_then_read(spi
, (u8
*)&tx
, 2, (u8
*)data
, 2);
42 static int ad714x_spi_write(struct device
*dev
, unsigned short reg
,
45 struct spi_device
*spi
= to_spi_device(dev
);
46 unsigned short tx
[2] = {
47 AD714x_SPI_CMD_PREFIX
| reg
,
51 return spi_write(spi
, (u8
*)tx
, 4);
54 static int __devinit
ad714x_spi_probe(struct spi_device
*spi
)
56 struct ad714x_chip
*chip
;
58 chip
= ad714x_probe(&spi
->dev
, BUS_SPI
, spi
->irq
,
59 ad714x_spi_read
, ad714x_spi_write
);
63 spi_set_drvdata(spi
, chip
);
68 static int __devexit
ad714x_spi_remove(struct spi_device
*spi
)
70 struct ad714x_chip
*chip
= spi_get_drvdata(spi
);
73 spi_set_drvdata(spi
, NULL
);
78 static struct spi_driver ad714x_spi_driver
= {
80 .name
= "ad714x_captouch",
83 .probe
= ad714x_spi_probe
,
84 .remove
= __devexit_p(ad714x_spi_remove
),
85 .suspend
= ad714x_spi_suspend
,
86 .resume
= ad714x_spi_resume
,
89 static __init
int ad714x_spi_init(void)
91 return spi_register_driver(&ad714x_spi_driver
);
93 module_init(ad714x_spi_init
);
95 static __exit
void ad714x_spi_exit(void)
97 spi_unregister_driver(&ad714x_spi_driver
);
99 module_exit(ad714x_spi_exit
);
101 MODULE_DESCRIPTION("Analog Devices AD714X Capacitance Touch Sensor SPI Bus Driver");
102 MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>");
103 MODULE_LICENSE("GPL");