Received: from milmhbs1.lsil.com (147.145.21.209) by coscas01.lsi.com
 (172.21.36.60) with Microsoft SMTP Server id 8.1.393.1; Mon, 12 Oct 2009
 20:49:04 -0600
Received: from mail2.lsil.com (mail2.lsil.com [147.145.40.22])	by
 milmhbs1.lsil.com (8.12.11/8.12.11) with ESMTP id n9D2n4CZ025368	for
 <andy.sharp@lsi.com>; Mon, 12 Oct 2009 19:49:04 -0700
Received: from psmtp.com (na3sys009amx243.postini.com [74.125.149.127])	by
 mail2.lsil.com (8.12.11/8.12.11) with SMTP id n9D2jQ5H009319	for
 <andy.sharp@lsi.com>; Mon, 12 Oct 2009 19:45:26 -0700 (PDT)
Received: from source ([78.24.191.182]) by na3sys009amx243.postini.com
 ([74.125.148.14]) with SMTP;	Tue, 13 Oct 2009 02:49:03 GMT
Received: from localhost.localdomain ([127.0.0.1]:47892 "EHLO
	eddie.linux-mips.org" rhost-flags-OK-OK-OK-FAIL) by ftp.linux-mips.org	with
 ESMTP id S1491842AbZJMCs4 (ORCPT <rfc822;andy.sharp@lsi.com>);	Tue, 13 Oct
 2009 04:48:56 +0200
Received: with ECARTIS (v1.0.0; list linux-mips); Tue, 13 Oct 2009 04:48:38
 +0200 (CEST)
Received: from TYO202.gate.nec.co.jp ([202.32.8.206]:47460 "EHLO
	tyo202.gate.nec.co.jp" rhost-flags-OK-OK-OK-OK) by ftp.linux-mips.org	with
 ESMTP id S1491849AbZJMCsb (ORCPT	<rfc822;linux-mips@linux-mips.org>); Tue, 13
 Oct 2009 04:48:31 +0200
Received: from relay11.aps.necel.com ([10.29.19.46])	by tyo202.gate.nec.co.jp
 (8.13.8/8.13.4) with ESMTP id n9D2mJSJ021698;	Tue, 13 Oct 2009 11:48:21 +0900
 (JST)
Received: from realmbox31.aps.necel.com ([10.29.19.36] [10.29.19.36]) by
 relay11.aps.necel.com with ESMTP; Tue, 13 Oct 2009 11:48:21 +0900
Received: from [10.114.180.134] ([10.114.180.134] [10.114.180.134]) by
 mbox02.aps.necel.com with ESMTP; Tue, 13 Oct 2009 11:48:20 +0900
From: Shinya Kuribayashi <shinya.kuribayashi@necel.com>
To: "baruch@tkos.co.il" <baruch@tkos.co.il>, "linux-i2c@vger.kernel.org"
	<linux-i2c@vger.kernel.org>
CC: "ben-linux@fluff.org" <ben-linux@fluff.org>, "linux-mips@linux-mips.org"
	<linux-mips@linux-mips.org>, "linux-arm-kernel@lists.infradead.org"
	<linux-arm-kernel@lists.infradead.org>
Sender: "linux-mips-bounce@linux-mips.org" <linux-mips-bounce@linux-mips.org>
Date: Mon, 12 Oct 2009 20:48:28 -0600
Subject: [PATCH 01/16] i2c-designware: Consolidate to use 32-bit word
 accesses
Thread-Topic: [PATCH 01/16] i2c-designware: Consolidate to use 32-bit word
 accesses
Thread-Index: AcpLr7prUzOaEEvIRWuPJfjgCySBxQ==
Message-ID: <4AD3EA7C.6020206@necel.com>
References: <4AD3E974.8080200@necel.com>
In-Reply-To: <4AD3E974.8080200@necel.com>
Accept-Language: en-US
Content-Language: en-US
X-MS-Exchange-Organization-AuthAs: Anonymous
X-MS-Exchange-Organization-AuthSource: coscas01.lsi.com
X-MS-Has-Attach:
X-Auto-Response-Suppress: All
X-MS-TNEF-Correlator:
x-scanned-by: MIMEDefang 2.39
errors-to: linux-mips-bounce@linux-mips.org
x-pstn-levels: (S:99.90000/99.90000 CV:99.9000 FC:95.5390 LC:95.5390
 R:95.9108 P:95.9108 M:97.0282 C:98.6951 )
x-pstn-settings: 3 (1.0000:1.0000) s cv gt3 gt2 gt1 r p m c 
x-pstn-addresses: from <shinya.kuribayashi@necel.com> [db-null] 
x-pstn-neptune: 0/0/0.00/0
user-agent: Thunderbird 2.0.0.23 (Windows/20090812)
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0

This driver looks originally meant for armel machines where readw()/
writew() works perfectly fine.  But that doens't work for big-endian
systems.

This patch converts all 8/16-bit-aware usages to 32-bit variants, so
that the driver works for MIPS big-endian machines, too.

Signed-off-by: Shinya Kuribayashi <shinya.kuribayashi@necel.com>
---
 drivers/i2c/busses/i2c-designware.c |   76 +++++++++++++++++--------------=
---
 1 files changed, 38 insertions(+), 38 deletions(-)

diff --git a/drivers/i2c/busses/i2c-designware.c b/drivers/i2c/busses/i2c-d=
esignware.c
index b444762..a4f928e 100644
--- a/drivers/i2c/busses/i2c-designware.c
+++ b/drivers/i2c/busses/i2c-designware.c
@@ -162,14 +162,14 @@ struct dw_i2c_dev {
 	struct i2c_msg		*msgs;
 	int			msgs_num;
 	int			msg_write_idx;
-	u16			tx_buf_len;
+	u32			tx_buf_len;
 	u8			*tx_buf;
 	int			msg_read_idx;
-	u16			rx_buf_len;
+	u32			rx_buf_len;
 	u8			*rx_buf;
 	int			msg_err;
 	unsigned int		status;
-	u16			abort_source;
+	u32			abort_source;
 	int			irq;
 	struct i2c_adapter	adapter;
 	unsigned int		tx_fifo_depth;
@@ -187,25 +187,25 @@ struct dw_i2c_dev {
 static void i2c_dw_init(struct dw_i2c_dev *dev)
 {
 	u32 input_clock_khz =3D clk_get_rate(dev->clk) / 1000;
-	u16 ic_con;
+	u32 ic_con;
=20
 	/* Disable the adapter */
-	writeb(0, dev->base + DW_IC_ENABLE);
+	writel(0, dev->base + DW_IC_ENABLE);
=20
 	/* set standard and fast speed deviders for high/low periods */
-	writew((input_clock_khz * 40 / 10000)+1, /* std speed high, 4us */
+	writel((input_clock_khz * 40 / 10000)+1, /* std speed high, 4us */
 			dev->base + DW_IC_SS_SCL_HCNT);
-	writew((input_clock_khz * 47 / 10000)+1, /* std speed low, 4.7us */
+	writel((input_clock_khz * 47 / 10000)+1, /* std speed low, 4.7us */
 			dev->base + DW_IC_SS_SCL_LCNT);
-	writew((input_clock_khz *  6 / 10000)+1, /* fast speed high, 0.6us */
+	writel((input_clock_khz *  6 / 10000)+1, /* fast speed high, 0.6us */
 			dev->base + DW_IC_FS_SCL_HCNT);
-	writew((input_clock_khz * 13 / 10000)+1, /* fast speed low, 1.3us */
+	writel((input_clock_khz * 13 / 10000)+1, /* fast speed low, 1.3us */
 			dev->base + DW_IC_FS_SCL_LCNT);
=20
 	/* configure the i2c master */
 	ic_con =3D DW_IC_CON_MASTER | DW_IC_CON_SLAVE_DISABLE |
 		DW_IC_CON_RESTART_EN | DW_IC_CON_SPEED_FAST;
-	writew(ic_con, dev->base + DW_IC_CON);
+	writel(ic_con, dev->base + DW_IC_CON);
 }
=20
 /*
@@ -215,7 +215,7 @@ static int i2c_dw_wait_bus_not_busy(struct dw_i2c_dev *=
dev)
 {
 	int timeout =3D TIMEOUT;
=20
-	while (readb(dev->base + DW_IC_STATUS) & DW_IC_STATUS_ACTIVITY) {
+	while (readl(dev->base + DW_IC_STATUS) & DW_IC_STATUS_ACTIVITY) {
 		if (timeout <=3D 0) {
 			dev_warn(dev->dev, "timeout waiting for bus ready\n");
 			return -ETIMEDOUT;
@@ -239,29 +239,29 @@ i2c_dw_xfer_msg(struct i2c_adapter *adap)
 	struct dw_i2c_dev *dev =3D i2c_get_adapdata(adap);
 	struct i2c_msg *msgs =3D dev->msgs;
 	int num =3D dev->msgs_num;
-	u16 ic_con, intr_mask;
-	int tx_limit =3D dev->tx_fifo_depth - readb(dev->base + DW_IC_TXFLR);
-	int rx_limit =3D dev->rx_fifo_depth - readb(dev->base + DW_IC_RXFLR);
-	u16 addr =3D msgs[dev->msg_write_idx].addr;
-	u16 buf_len =3D dev->tx_buf_len;
+	u32 ic_con, intr_mask;
+	int tx_limit =3D dev->tx_fifo_depth - readl(dev->base + DW_IC_TXFLR);
+	int rx_limit =3D dev->rx_fifo_depth - readl(dev->base + DW_IC_RXFLR);
+	u32 addr =3D msgs[dev->msg_write_idx].addr;
+	u32 buf_len =3D dev->tx_buf_len;
=20
 	if (!(dev->status & STATUS_WRITE_IN_PROGRESS)) {
 		/* Disable the adapter */
-		writeb(0, dev->base + DW_IC_ENABLE);
+		writel(0, dev->base + DW_IC_ENABLE);
=20
 		/* set the slave (target) address */
-		writew(msgs[dev->msg_write_idx].addr, dev->base + DW_IC_TAR);
+		writel(msgs[dev->msg_write_idx].addr, dev->base + DW_IC_TAR);
=20
 		/* if the slave address is ten bit address, enable 10BITADDR */
-		ic_con =3D readw(dev->base + DW_IC_CON);
+		ic_con =3D readl(dev->base + DW_IC_CON);
 		if (msgs[dev->msg_write_idx].flags & I2C_M_TEN)
 			ic_con |=3D DW_IC_CON_10BITADDR_MASTER;
 		else
 			ic_con &=3D ~DW_IC_CON_10BITADDR_MASTER;
-		writew(ic_con, dev->base + DW_IC_CON);
+		writel(ic_con, dev->base + DW_IC_CON);
=20
 		/* Enable the adapter */
-		writeb(1, dev->base + DW_IC_ENABLE);
+		writel(1, dev->base + DW_IC_ENABLE);
 	}
=20
 	for (; dev->msg_write_idx < num; dev->msg_write_idx++) {
@@ -287,10 +287,10 @@ i2c_dw_xfer_msg(struct i2c_adapter *adap)
=20
 		while (buf_len > 0 && tx_limit > 0 && rx_limit > 0) {
 			if (msgs[dev->msg_write_idx].flags & I2C_M_RD) {
-				writew(0x100, dev->base + DW_IC_DATA_CMD);
+				writel(0x100, dev->base + DW_IC_DATA_CMD);
 				rx_limit--;
 			} else
-				writew(*(dev->tx_buf++),
+				writel(*(dev->tx_buf++),
 						dev->base + DW_IC_DATA_CMD);
 			tx_limit--; buf_len--;
 		}
@@ -302,7 +302,7 @@ i2c_dw_xfer_msg(struct i2c_adapter *adap)
 		dev->status |=3D STATUS_WRITE_IN_PROGRESS;
 	} else
 		dev->status &=3D ~STATUS_WRITE_IN_PROGRESS;
-	writew(intr_mask, dev->base + DW_IC_INTR_MASK);
+	writel(intr_mask, dev->base + DW_IC_INTR_MASK);
=20
 	dev->tx_buf_len =3D buf_len;
 }
@@ -313,11 +313,11 @@ i2c_dw_read(struct i2c_adapter *adap)
 	struct dw_i2c_dev *dev =3D i2c_get_adapdata(adap);
 	struct i2c_msg *msgs =3D dev->msgs;
 	int num =3D dev->msgs_num;
-	u16 addr =3D msgs[dev->msg_read_idx].addr;
-	int rx_valid =3D readw(dev->base + DW_IC_RXFLR);
+	u32 addr =3D msgs[dev->msg_read_idx].addr;
+	int rx_valid =3D readl(dev->base + DW_IC_RXFLR);
=20
 	for (; dev->msg_read_idx < num; dev->msg_read_idx++) {
-		u16 len;
+		u32 len;
 		u8 *buf;
=20
 		if (!(msgs[dev->msg_read_idx].flags & I2C_M_RD))
@@ -336,7 +336,7 @@ i2c_dw_read(struct i2c_adapter *adap)
 		}
=20
 		for (; len > 0 && rx_valid > 0; len--, rx_valid--)
-			*buf++ =3D readb(dev->base + DW_IC_DATA_CMD);
+			*buf++ =3D readl(dev->base + DW_IC_DATA_CMD);
=20
 		if (len > 0) {
 			dev->status |=3D STATUS_READ_IN_PROGRESS;
@@ -398,7 +398,7 @@ i2c_dw_xfer(struct i2c_adapter *adap, struct i2c_msg ms=
gs[], int num)
 		do {
 			i2c_dw_read(adap);
 		} while (dev->status & STATUS_READ_IN_PROGRESS);
-		writeb(0, dev->base + DW_IC_ENABLE);
+		writel(0, dev->base + DW_IC_ENABLE);
 		ret =3D num;
 		goto done;
 	}
@@ -428,7 +428,7 @@ static u32 i2c_dw_func(struct i2c_adapter *adap)
 static void dw_i2c_pump_msg(unsigned long data)
 {
 	struct dw_i2c_dev *dev =3D (struct dw_i2c_dev *) data;
-	u16 intr_mask;
+	u32 intr_mask;
=20
 	i2c_dw_read(&dev->adapter);
 	i2c_dw_xfer_msg(&dev->adapter);
@@ -436,7 +436,7 @@ static void dw_i2c_pump_msg(unsigned long data)
 	intr_mask =3D DW_IC_INTR_STOP_DET | DW_IC_INTR_TX_ABRT;
 	if (dev->status & STATUS_WRITE_IN_PROGRESS)
 		intr_mask |=3D DW_IC_INTR_TX_EMPTY;
-	writew(intr_mask, dev->base + DW_IC_INTR_MASK);
+	writel(intr_mask, dev->base + DW_IC_INTR_MASK);
 }
=20
 /*
@@ -446,19 +446,19 @@ static void dw_i2c_pump_msg(unsigned long data)
 static irqreturn_t i2c_dw_isr(int this_irq, void *dev_id)
 {
 	struct dw_i2c_dev *dev =3D dev_id;
-	u16 stat;
+	u32 stat;
=20
-	stat =3D readw(dev->base + DW_IC_INTR_STAT);
+	stat =3D readl(dev->base + DW_IC_INTR_STAT);
 	dev_dbg(dev->dev, "%s: stat=3D0x%x\n", __func__, stat);
 	if (stat & DW_IC_INTR_TX_ABRT) {
-		dev->abort_source =3D readw(dev->base + DW_IC_TX_ABRT_SOURCE);
+		dev->abort_source =3D readl(dev->base + DW_IC_TX_ABRT_SOURCE);
 		dev->cmd_err |=3D DW_IC_ERR_TX_ABRT;
 		dev->status =3D STATUS_IDLE;
 	} else if (stat & DW_IC_INTR_TX_EMPTY)
 		tasklet_schedule(&dev->pump_msg);
=20
-	readb(dev->base + DW_IC_CLR_INTR);	/* clear interrupts */
-	writew(0, dev->base + DW_IC_INTR_MASK);	/* disable interrupts */
+	readl(dev->base + DW_IC_CLR_INTR);	/* clear interrupts */
+	writel(0, dev->base + DW_IC_INTR_MASK);	/* disable interrupts */
 	if (stat & (DW_IC_INTR_TX_ABRT | DW_IC_INTR_STOP_DET))
 		complete(&dev->cmd_complete);
=20
@@ -531,7 +531,7 @@ static int __devinit dw_i2c_probe(struct platform_devic=
e *pdev)
 	}
 	i2c_dw_init(dev);
=20
-	writew(0, dev->base + DW_IC_INTR_MASK); /* disable IRQ */
+	writel(0, dev->base + DW_IC_INTR_MASK); /* disable IRQ */
 	r =3D request_irq(dev->irq, i2c_dw_isr, 0, pdev->name, dev);
 	if (r) {
 		dev_err(&pdev->dev, "failure requesting irq %i\n", dev->irq);
@@ -587,7 +587,7 @@ static int __devexit dw_i2c_remove(struct platform_devi=
ce *pdev)
 	clk_put(dev->clk);
 	dev->clk =3D NULL;
=20
-	writeb(0, dev->base + DW_IC_ENABLE);
+	writel(0, dev->base + DW_IC_ENABLE);
 	free_irq(dev->irq, dev);
 	kfree(dev);
=20
--=20
1.6.5


