1*31a62963SBryan Wu /* 2*31a62963SBryan Wu * AD714X CapTouch Programmable Controller driver (SPI bus) 3*31a62963SBryan Wu * 4*31a62963SBryan Wu * Copyright 2009 Analog Devices Inc. 5*31a62963SBryan Wu * 6*31a62963SBryan Wu * Licensed under the GPL-2 or later. 7*31a62963SBryan Wu */ 8*31a62963SBryan Wu 9*31a62963SBryan Wu #include <linux/input.h> /* BUS_I2C */ 10*31a62963SBryan Wu #include <linux/module.h> 11*31a62963SBryan Wu #include <linux/spi/spi.h> 12*31a62963SBryan Wu #include <linux/types.h> 13*31a62963SBryan Wu #include "ad714x.h" 14*31a62963SBryan Wu 15*31a62963SBryan Wu #define AD714x_SPI_CMD_PREFIX 0xE000 /* bits 15:11 */ 16*31a62963SBryan Wu #define AD714x_SPI_READ BIT(10) 17*31a62963SBryan Wu 18*31a62963SBryan Wu #ifdef CONFIG_PM 19*31a62963SBryan Wu static int ad714x_spi_suspend(struct spi_device *spi, pm_message_t message) 20*31a62963SBryan Wu { 21*31a62963SBryan Wu return ad714x_disable(spi_get_drvdata(spi)); 22*31a62963SBryan Wu } 23*31a62963SBryan Wu 24*31a62963SBryan Wu static int ad714x_spi_resume(struct spi_device *spi) 25*31a62963SBryan Wu { 26*31a62963SBryan Wu return ad714x_enable(spi_get_drvdata(spi)); 27*31a62963SBryan Wu } 28*31a62963SBryan Wu #else 29*31a62963SBryan Wu # define ad714x_spi_suspend NULL 30*31a62963SBryan Wu # define ad714x_spi_resume NULL 31*31a62963SBryan Wu #endif 32*31a62963SBryan Wu 33*31a62963SBryan Wu static int ad714x_spi_read(struct device *dev, unsigned short reg, 34*31a62963SBryan Wu unsigned short *data) 35*31a62963SBryan Wu { 36*31a62963SBryan Wu struct spi_device *spi = to_spi_device(dev); 37*31a62963SBryan Wu unsigned short tx = AD714x_SPI_CMD_PREFIX | AD714x_SPI_READ | reg; 38*31a62963SBryan Wu 39*31a62963SBryan Wu return spi_write_then_read(spi, (u8 *)&tx, 2, (u8 *)data, 2); 40*31a62963SBryan Wu } 41*31a62963SBryan Wu 42*31a62963SBryan Wu static int ad714x_spi_write(struct device *dev, unsigned short reg, 43*31a62963SBryan Wu unsigned short data) 44*31a62963SBryan Wu { 45*31a62963SBryan Wu struct spi_device *spi = to_spi_device(dev); 46*31a62963SBryan Wu unsigned short tx[2] = { 47*31a62963SBryan Wu AD714x_SPI_CMD_PREFIX | reg, 48*31a62963SBryan Wu data 49*31a62963SBryan Wu }; 50*31a62963SBryan Wu 51*31a62963SBryan Wu return spi_write(spi, (u8 *)tx, 4); 52*31a62963SBryan Wu } 53*31a62963SBryan Wu 54*31a62963SBryan Wu static int __devinit ad714x_spi_probe(struct spi_device *spi) 55*31a62963SBryan Wu { 56*31a62963SBryan Wu struct ad714x_chip *chip; 57*31a62963SBryan Wu 58*31a62963SBryan Wu chip = ad714x_probe(&spi->dev, BUS_SPI, spi->irq, 59*31a62963SBryan Wu ad714x_spi_read, ad714x_spi_write); 60*31a62963SBryan Wu if (IS_ERR(chip)) 61*31a62963SBryan Wu return PTR_ERR(chip); 62*31a62963SBryan Wu 63*31a62963SBryan Wu spi_set_drvdata(spi, chip); 64*31a62963SBryan Wu 65*31a62963SBryan Wu return 0; 66*31a62963SBryan Wu } 67*31a62963SBryan Wu 68*31a62963SBryan Wu static int __devexit ad714x_spi_remove(struct spi_device *spi) 69*31a62963SBryan Wu { 70*31a62963SBryan Wu struct ad714x_chip *chip = spi_get_drvdata(spi); 71*31a62963SBryan Wu 72*31a62963SBryan Wu ad714x_remove(chip); 73*31a62963SBryan Wu spi_set_drvdata(spi, NULL); 74*31a62963SBryan Wu 75*31a62963SBryan Wu return 0; 76*31a62963SBryan Wu } 77*31a62963SBryan Wu 78*31a62963SBryan Wu static struct spi_driver ad714x_spi_driver = { 79*31a62963SBryan Wu .driver = { 80*31a62963SBryan Wu .name = "ad714x_captouch", 81*31a62963SBryan Wu .owner = THIS_MODULE, 82*31a62963SBryan Wu }, 83*31a62963SBryan Wu .probe = ad714x_spi_probe, 84*31a62963SBryan Wu .remove = __devexit_p(ad714x_spi_remove), 85*31a62963SBryan Wu .suspend = ad714x_spi_suspend, 86*31a62963SBryan Wu .resume = ad714x_spi_resume, 87*31a62963SBryan Wu }; 88*31a62963SBryan Wu 89*31a62963SBryan Wu static __init int ad714x_spi_init(void) 90*31a62963SBryan Wu { 91*31a62963SBryan Wu return spi_register_driver(&ad714x_spi_driver); 92*31a62963SBryan Wu } 93*31a62963SBryan Wu module_init(ad714x_spi_init); 94*31a62963SBryan Wu 95*31a62963SBryan Wu static __exit void ad714x_spi_exit(void) 96*31a62963SBryan Wu { 97*31a62963SBryan Wu spi_unregister_driver(&ad714x_spi_driver); 98*31a62963SBryan Wu } 99*31a62963SBryan Wu module_exit(ad714x_spi_exit); 100*31a62963SBryan Wu 101*31a62963SBryan Wu MODULE_DESCRIPTION("Analog Devices AD714X Capacitance Touch Sensor SPI Bus Driver"); 102*31a62963SBryan Wu MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>"); 103*31a62963SBryan Wu MODULE_LICENSE("GPL"); 104