From patchwork Thu May 12 08:45:11 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Hennerich, Michael" X-Patchwork-Id: 779432 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.3) with ESMTP id p4C8u61Z018568 for ; Thu, 12 May 2011 08:56:06 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754873Ab1ELI4F (ORCPT ); Thu, 12 May 2011 04:56:05 -0400 Received: from am1ehsobe003.messaging.microsoft.com ([213.199.154.206]:36626 "EHLO AM1EHSOBE003.bigfish.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754558Ab1ELI4E (ORCPT ); Thu, 12 May 2011 04:56:04 -0400 Received: from mail16-am1-R.bigfish.com (10.3.201.246) by AM1EHSOBE003.bigfish.com (10.3.204.23) with Microsoft SMTP Server id 14.1.225.22; Thu, 12 May 2011 08:56:02 +0000 Received: from mail16-am1 (localhost.localdomain [127.0.0.1]) by mail16-am1-R.bigfish.com (Postfix) with ESMTP id BE395CC0252; Thu, 12 May 2011 08:56:02 +0000 (UTC) X-SpamScore: 0 X-BigFish: VPS0(zzzz1202hzz8275bhz2dh2a8h668h839h64h) X-Spam-TCS-SCL: 3:0 X-Forefront-Antispam-Report: CIP:137.71.25.57; KIP:(null); UIP:(null); IPVD:NLI; H:nwd2mta2.analog.com; RD:nwd2mail11.analog.com; EFVD:NLI Received: from mail16-am1 (localhost.localdomain [127.0.0.1]) by mail16-am1 (MessageSwitch) id 1305190560363349_19207; Thu, 12 May 2011 08:56:00 +0000 (UTC) Received: from AM1EHSMHS018.bigfish.com (unknown [10.3.201.253]) by mail16-am1.bigfish.com (Postfix) with ESMTP id 3BF061438067; Thu, 12 May 2011 08:54:40 +0000 (UTC) Received: from nwd2mta2.analog.com (137.71.25.57) by AM1EHSMHS018.bigfish.com (10.3.206.21) with Microsoft SMTP Server (TLS) id 14.1.225.22; Thu, 12 May 2011 08:54:39 +0000 Received: from NWD2HUBCAS2.ad.analog.com (nwd2hubcas2.ad.analog.com [10.64.73.30]) by nwd2mta2.analog.com (8.13.8/8.13.8) with ESMTP id p4C8scw3022342 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=FAIL); Thu, 12 May 2011 04:54:38 -0400 Received: from zeus.spd.analog.com (10.64.82.11) by NWD2HUBCAS2.ad.analog.com (10.64.73.30) with Microsoft SMTP Server id 8.1.358.0; Thu, 12 May 2011 04:54:37 -0400 Received: from localhost.localdomain ([10.44.2.88]) by zeus.spd.analog.com (8.14.1/8.14.1) with ESMTP id p4C8sTvF006977; Thu, 12 May 2011 04:54:36 -0400 (EDT) From: To: CC: , , , , Michael Hennerich Subject: [PATCH v2 6/6] input: misc: AD714x: Fix endianness issues. Date: Thu, 12 May 2011 10:45:11 +0200 Message-ID: <1305189911-24769-6-git-send-email-michael.hennerich@analog.com> X-Mailer: git-send-email 1.6.0.2 In-Reply-To: <1305189911-24769-1-git-send-email-michael.hennerich@analog.com> References: <1305189911-24769-1-git-send-email-michael.hennerich@analog.com> MIME-Version: 1.0 X-OriginatorOrg: analog.com Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Thu, 12 May 2011 08:56:06 +0000 (UTC) From: Michael Hennerich Add support for Big Endian. Force SPI bus into the default 8-bit mode. Signed-off-by: Michael Hennerich --- drivers/input/misc/ad714x-i2c.c | 43 ++++++++++---------------------------- drivers/input/misc/ad714x-spi.c | 33 +++++++++++++++++++++++------ 2 files changed, 38 insertions(+), 38 deletions(-) diff --git a/drivers/input/misc/ad714x-i2c.c b/drivers/input/misc/ad714x-i2c.c index fb6564e..9794b36 100644 --- a/drivers/input/misc/ad714x-i2c.c +++ b/drivers/input/misc/ad714x-i2c.c @@ -32,17 +32,12 @@ static int ad714x_i2c_write(struct device *dev, unsigned short reg, { struct i2c_client *client = to_i2c_client(dev); int ret = 0; - u8 *_reg = (u8 *)® - u8 *_data = (u8 *)&data; - - u8 tx[4] = { - _reg[1], - _reg[0], - _data[1], - _data[0] + unsigned short tx[2] = { + cpu_to_be16(reg), + cpu_to_be16(data) }; - ret = i2c_master_send(client, tx, 4); + ret = i2c_master_send(client, (u8 *)tx, 4); if (ret < 0) dev_err(&client->dev, "I2C write error\n"); @@ -54,25 +49,16 @@ static int ad714x_i2c_read(struct device *dev, unsigned short reg, { struct i2c_client *client = to_i2c_client(dev); int ret = 0; - u8 *_reg = (u8 *)® - u8 *_data = (u8 *)data; + unsigned short tx = cpu_to_be16(reg); - u8 tx[2] = { - _reg[1], - _reg[0] - }; - u8 rx[2]; - - ret = i2c_master_send(client, tx, 2); + ret = i2c_master_send(client, (u8 *)&tx, 2); if (ret >= 0) - ret = i2c_master_recv(client, rx, 2); + ret = i2c_master_recv(client, (u8 *)data, 2); - if (unlikely(ret < 0)) { + if (unlikely(ret < 0)) dev_err(&client->dev, "I2C read error\n"); - } else { - _data[0] = rx[1]; - _data[1] = rx[0]; - } + else + *data = be16_to_cpu(*data); return ret; } @@ -82,14 +68,9 @@ static int ad714x_i2c_read_seq(struct device *dev, unsigned short reg, { struct i2c_client *client = to_i2c_client(dev); int ret = 0, i; - u8 *_reg = (u8 *)® - - u8 tx[2] = { - _reg[1], - _reg[0] - }; + unsigned short tx = cpu_to_be16(reg); - ret = i2c_master_send(client, tx, 2); + ret = i2c_master_send(client, (u8 *)&tx, 2); if (ret >= 0) ret = i2c_master_recv(client, (u8 *)data, len * 2); diff --git a/drivers/input/misc/ad714x-spi.c b/drivers/input/misc/ad714x-spi.c index d352aa5..4418b5b 100644 --- a/drivers/input/misc/ad714x-spi.c +++ b/drivers/input/misc/ad714x-spi.c @@ -6,7 +6,7 @@ * Licensed under the GPL-2 or later. */ -#include /* BUS_I2C */ +#include /* BUS_SPI */ #include #include #include @@ -34,18 +34,31 @@ static int ad714x_spi_read(struct device *dev, unsigned short reg, unsigned short *data) { struct spi_device *spi = to_spi_device(dev); - unsigned short tx = AD714x_SPI_CMD_PREFIX | AD714x_SPI_READ | reg; + int ret; + unsigned short tx = cpu_to_be16(AD714x_SPI_CMD_PREFIX | + AD714x_SPI_READ | reg); - return spi_write_then_read(spi, (u8 *)&tx, 2, (u8 *)data, 2); + ret = spi_write_then_read(spi, (u8 *)&tx, 2, (u8 *)data, 2); + + *data = be16_to_cpu(*data); + + return ret; } static int ad714x_spi_read_seq(struct device *dev, unsigned short reg, unsigned short *data, unsigned len) { struct spi_device *spi = to_spi_device(dev); - unsigned short tx = AD714x_SPI_CMD_PREFIX | AD714x_SPI_READ | reg; + int ret, i; + unsigned short tx = cpu_to_be16(AD714x_SPI_CMD_PREFIX | + AD714x_SPI_READ | reg); + + ret = spi_write_then_read(spi, (u8 *)&tx, 2, (u8 *)data, len * 2); - return spi_write_then_read(spi, (u8 *)&tx, 2, (u8 *)data, len * 2); + for (i = 0; i < len; i++) + data[i] = be16_to_cpu(data[i]); + + return ret; } static int ad714x_spi_write(struct device *dev, unsigned short reg, @@ -53,8 +66,8 @@ static int ad714x_spi_write(struct device *dev, unsigned short reg, { struct spi_device *spi = to_spi_device(dev); unsigned short tx[2] = { - AD714x_SPI_CMD_PREFIX | reg, - data + cpu_to_be16(AD714x_SPI_CMD_PREFIX | reg), + cpu_to_be16(data) }; return spi_write(spi, (u8 *)tx, 4); @@ -63,6 +76,12 @@ static int ad714x_spi_write(struct device *dev, unsigned short reg, static int __devinit ad714x_spi_probe(struct spi_device *spi) { struct ad714x_chip *chip; + int err; + + spi->bits_per_word = 8; + err = spi_setup(spi); + if (err < 0) + return err; chip = ad714x_probe(&spi->dev, BUS_SPI, spi->irq, ad714x_spi_read, ad714x_spi_read_seq,