ad714x-spi.c (c0409feb86893f5ccf73964c7b2b47ca64bdb014) | ad714x-spi.c (9eff794b777ac9ca034129a1b637204000c8fb29) |
---|---|
1/* 2 * AD714X CapTouch Programmable Controller driver (SPI bus) 3 * | 1/* 2 * AD714X CapTouch Programmable Controller driver (SPI bus) 3 * |
4 * Copyright 2009 Analog Devices Inc. | 4 * Copyright 2009-2011 Analog Devices Inc. |
5 * 6 * Licensed under the GPL-2 or later. 7 */ 8 9#include <linux/input.h> /* BUS_SPI */ 10#include <linux/module.h> 11#include <linux/spi/spi.h> 12#include <linux/pm.h> --- 13 unchanged lines hidden (view full) --- 26{ 27 return ad714x_enable(spi_get_drvdata(to_spi_device(dev))); 28} 29#endif 30 31static SIMPLE_DEV_PM_OPS(ad714x_spi_pm, ad714x_spi_suspend, ad714x_spi_resume); 32 33static int ad714x_spi_read(struct ad714x_chip *chip, | 5 * 6 * Licensed under the GPL-2 or later. 7 */ 8 9#include <linux/input.h> /* BUS_SPI */ 10#include <linux/module.h> 11#include <linux/spi/spi.h> 12#include <linux/pm.h> --- 13 unchanged lines hidden (view full) --- 26{ 27 return ad714x_enable(spi_get_drvdata(to_spi_device(dev))); 28} 29#endif 30 31static SIMPLE_DEV_PM_OPS(ad714x_spi_pm, ad714x_spi_suspend, ad714x_spi_resume); 32 33static int ad714x_spi_read(struct ad714x_chip *chip, |
34 unsigned short reg, unsigned short *data) | 34 unsigned short reg, unsigned short *data, size_t len) |
35{ 36 struct spi_device *spi = to_spi_device(chip->dev); 37 struct spi_message message; 38 struct spi_transfer xfer[2]; | 35{ 36 struct spi_device *spi = to_spi_device(chip->dev); 37 struct spi_message message; 38 struct spi_transfer xfer[2]; |
39 int i; |
|
39 int error; 40 41 spi_message_init(&message); 42 memset(xfer, 0, sizeof(xfer)); 43 44 chip->xfer_buf[0] = cpu_to_be16(AD714x_SPI_CMD_PREFIX | 45 AD714x_SPI_READ | reg); 46 xfer[0].tx_buf = &chip->xfer_buf[0]; 47 xfer[0].len = sizeof(chip->xfer_buf[0]); 48 spi_message_add_tail(&xfer[0], &message); 49 50 xfer[1].rx_buf = &chip->xfer_buf[1]; | 40 int error; 41 42 spi_message_init(&message); 43 memset(xfer, 0, sizeof(xfer)); 44 45 chip->xfer_buf[0] = cpu_to_be16(AD714x_SPI_CMD_PREFIX | 46 AD714x_SPI_READ | reg); 47 xfer[0].tx_buf = &chip->xfer_buf[0]; 48 xfer[0].len = sizeof(chip->xfer_buf[0]); 49 spi_message_add_tail(&xfer[0], &message); 50 51 xfer[1].rx_buf = &chip->xfer_buf[1]; |
51 xfer[1].len = sizeof(chip->xfer_buf[1]); | 52 xfer[1].len = sizeof(chip->xfer_buf[1]) * len; |
52 spi_message_add_tail(&xfer[1], &message); 53 54 error = spi_sync(spi, &message); 55 if (unlikely(error)) { 56 dev_err(chip->dev, "SPI read error: %d\n", error); 57 return error; 58 } 59 | 53 spi_message_add_tail(&xfer[1], &message); 54 55 error = spi_sync(spi, &message); 56 if (unlikely(error)) { 57 dev_err(chip->dev, "SPI read error: %d\n", error); 58 return error; 59 } 60 |
60 *data = be16_to_cpu(chip->xfer_buf[1]); | 61 for (i = 0; i < len; i++) 62 data[i] = be16_to_cpu(chip->xfer_buf[i + 1]); 63 |
61 return 0; 62} 63 64static int ad714x_spi_write(struct ad714x_chip *chip, 65 unsigned short reg, unsigned short data) 66{ 67 struct spi_device *spi = to_spi_device(chip->dev); 68 int error; --- 69 unchanged lines hidden --- | 64 return 0; 65} 66 67static int ad714x_spi_write(struct ad714x_chip *chip, 68 unsigned short reg, unsigned short data) 69{ 70 struct spi_device *spi = to_spi_device(chip->dev); 71 int error; --- 69 unchanged lines hidden --- |