Received: from mail.onstor.com (66.201.51.107) by exch1.onstor.net
 (10.0.0.225) with Microsoft SMTP Server id 8.1.311.2; Fri, 6 Mar 2009
 08:24:10 -0800
Received: from ausesmta2-2.messageone.com ([64.20.241.45]) by mail.onstor.com
 with Microsoft SMTPSVC(6.0.3790.3959);	 Fri, 6 Mar 2009 08:24:09 -0800
Received: from ftp.linux-mips.org (ftp.linux-mips.org [213.58.128.207])	by
 ausesmta2-2.messageone.com (8.13.8/8.13.8) with ESMTP id n26GO0r6002434	for
 <andy.sharp@onstor.com>; Fri, 6 Mar 2009 10:24:08 -0600
Received: from localhost.localdomain ([127.0.0.1]:52386 "EHLO
	ftp.linux-mips.org") by ftp.linux-mips.org with ESMTP	id S21366446AbZCFQXG
 (ORCPT <rfc822;andy.sharp@onstor.com>);	Fri, 6 Mar 2009 16:23:06 +0000
Received: with ECARTIS (v1.0.0; list linux-mips); Fri, 06 Mar 2009 16:22:49
 +0000 (GMT)
Received: from mx1.rmicorp.com ([63.111.213.197]:35445 "EHLO mx1.rmicorp.com")
	by ftp.linux-mips.org with ESMTP id S21366487AbZCFQUV (ORCPT
	<rfc822;linux-mips@linux-mips.org>); Fri, 6 Mar 2009 16:20:21 +0000
Received: from sark.razamicroelectronics.com ([10.8.0.254]) by mx1.rmicorp.com
 with Microsoft SMTPSVC(6.0.3790.3959);	 Fri, 6 Mar 2009 08:20:09 -0800
Received: from localhost.localdomain (unknown [10.8.0.23])	by
 sark.razamicroelectronics.com (Postfix) with ESMTP id D573CEE76AA;	Fri,  6
 Mar 2009 09:42:10 -0600 (CST)
From: Kevin Hickey <khickey@rmicorp.com>
To: "ralf@linux-mips.org" <ralf@linux-mips.org>, "linux-mips@linux-mips.org"
	<linux-mips@linux-mips.org>
CC: Kevin Hickey <khickey@rmicorp.com>
Sender: "linux-mips-bounce@linux-mips.org" <linux-mips-bounce@linux-mips.org>
Date: Fri, 6 Mar 2009 08:20:04 -0800
Subject: [PATCH 05/10] Alchemy: Au1300/DB1300 MMC support
Thread-Topic: [PATCH 05/10] Alchemy: Au1300/DB1300 MMC support
Thread-Index: Acmed/sO048bV4O7SpCdkUxLLDW0GQ==
Message-ID:
 <394c116b9fa5bd1865ac21d11185f09e07bd2ab5.1236354153.git.khickey@rmicorp.com>
References:
 <788248524efc28ba2608ed79bfb7080ee476b12d.1236354153.git.khickey@rmicorp.com>
In-Reply-To:
 <788248524efc28ba2608ed79bfb7080ee476b12d.1236354153.git.khickey@rmicorp.com>
Accept-Language: en-US
Content-Language: en-US
X-MS-Exchange-Organization-AuthAs: Internal
X-MS-Exchange-Organization-AuthMechanism: 0b
X-MS-Exchange-Organization-AuthSource: exch1.onstor.net
X-MS-Has-Attach:
X-Auto-Response-Suppress: All
X-MS-TNEF-Correlator:
x-originalarrivaltime: 06 Mar 2009 16:20:09.0903 (UTC)
 FILETIME=[6B864BF0:01C99E77]
errors-to: linux-mips-bounce@linux-mips.org
x-ems-proccessed: 2K3Xl1OQTInXD6xxuA8z3Q==
x-ems-stamp: NN2IMMwxG9VLUXxXrc1YXg==
x-messageone-virus-version: vendor=fsecure
 engine=4.65.7400:2.4.4,1.2.40,4.0.164
 definitions=2009-02-22_03:2009-02-10,2009-02-22,2009-02-22 signatures=0
x-messageone-virus-scanned: Clean
x-messageone-envelope-sender: linux-mips-bounce@linux-mips.org
x-messageone-spam-details: rule=m773emszm_notspam policy=m773emszm score=0
 spamscore=0 ipscore=0 phishscore=0 bulkscore=0 adultscore=0 classifier=spam
 adjust=0 reason=mlx engine=3.1.0-0810130000 definitions=main-0902220252
x-messageone-spam-score: 0
x-messageone-spam-bar:
x-list: linux-mips
x-archive-position: 22023
x-ecartis-version: Ecartis v1.0.0
x-original-sender: khickey@rmicorp.com
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0

Supports the MMC/SD controller on Au1300 and the single slot on the DB1300
board.

Signed-off-by: Kevin Hickey <khickey@rmicorp.com>
---
 arch/mips/alchemy/devboards/db1300/mmc.c |  154 ++++++++++++++++++++++++++=
++++
 drivers/mmc/host/Kconfig                 |    2 +-
 drivers/mmc/host/au1xmmc.c               |   18 ++--
 3 files changed, 164 insertions(+), 10 deletions(-)
 create mode 100644 arch/mips/alchemy/devboards/db1300/mmc.c

diff --git a/arch/mips/alchemy/devboards/db1300/mmc.c b/arch/mips/alchemy/d=
evboards/db1300/mmc.c
new file mode 100644
index 0000000..821658c
--- /dev/null
+++ b/arch/mips/alchemy/devboards/db1300/mmc.c
@@ -0,0 +1,154 @@
+/*
+ * Copyright 2003-2008 RMI Corporation. All rights reserved.
+ * Author: Kevin Hickey <khickey@rmicorp.com>
+ *
+ *  This program is free software; you can redistribute  it and/or modify =
it
+ *  under  the terms of  the GNU General  Public License as published by t=
he
+ *  Free Software Foundation;  either version 2 of the  License, or (at yo=
ur
+ *  option) any later version.
+ *
+ * THIS SOFTWARE IS PROVIDED BY RMI Corporation 'AS IS' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTI=
ES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.=
 IN
+ * NO EVENT SHALL RMI OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BU=
T
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF US=
E,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE O=
F
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *  You should have received a copy of the  GNU General Public License alo=
ng
+ *  with this program; if not, write  to the Free Software Foundation, Inc=
.,
+ *  675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <linux/leds.h>
+#include <linux/platform_device.h>
+#include <asm/mips-boards/db1300.h>
+#include <asm/mach-au1x00/au1100_mmc.h>
+#include <asm/mach-au1x00/au1xxx_dbdma.h>
+#include <linux/dma-mapping.h>
+
+static volatile struct bcsr_regs *const bcsr =3D
+	(struct bcsr_regs *)(DB1300_BCSR_REGS_PHYS_ADDR + KSEG1_OFFSET);
+
+static int mmc_activity;
+static u64 au1xxx_mmc_dmamask =3D  DMA_32BIT_MASK;
+
+
+static void db1300_mmcled_set(struct led_classdev *led,
+                       enum led_brightness brightness)
+{
+       if (brightness !=3D LED_OFF) {
+               if (++mmc_activity =3D=3D 1)
+                       bcsr->disk_leds &=3D ~(1 << 8);
+       } else {
+               if (--mmc_activity =3D=3D 0)
+                       bcsr->disk_leds |=3D (1 << 8);
+       }
+}
+
+static struct led_classdev db1300mmc_led =3D {
+       .brightness_set =3D db1300_mmcled_set,
+};
+
+
+static int db1300mmc1_card_readonly(void *mmc_host)
+{
+       return (bcsr->status & BCSR_STATUS_SD1_WP) ? 1 : 0;
+}
+
+static int db1300mmc1_card_inserted(void *mmc_host)
+{
+	int retval;
+	retval =3D  (bcsr->sig_status & BCSR_INT_SD1_INSERT) ? 1 : 0;
+	return retval;
+}
+
+struct au1xmmc_platform_data au1xmmc_platdata[2] =3D {
+       [0] =3D {
+               .set_power      =3D NULL,
+               .card_inserted  =3D NULL,
+               .card_readonly  =3D NULL,
+               .cd_setup       =3D NULL,         /* use poll-timer in driv=
er */
+               .led            =3D &db1300mmc_led,
+       },
+       [1] =3D {
+               .set_power      =3D NULL,
+               .card_inserted  =3D db1300mmc1_card_inserted,
+               .card_readonly  =3D db1300mmc1_card_readonly,
+               .cd_setup       =3D NULL,         /* use poll-timer in driv=
er */
+               .led            =3D &db1300mmc_led,
+       },
+};
+
+static struct resource au13xx_mmc0_resources[] =3D {
+       [0] =3D {
+               .start          =3D SD0_PHYS_ADDR,
+               .end            =3D SD0_PHYS_ADDR + 0x7ffff,
+               .flags          =3D IORESOURCE_MEM,
+       },
+       [1] =3D {
+               .start          =3D AU1300_IRQ_SD0 + GPINT_LINUX_IRQ_OFFSET=
,
+               .end            =3D AU1300_IRQ_SD0 + GPINT_LINUX_IRQ_OFFSET=
,
+               .flags          =3D IORESOURCE_IRQ,
+       },
+       [2] =3D {
+               .start          =3D DSCR_CMD0_SDMS_TX0,
+               .end            =3D DSCR_CMD0_SDMS_TX0,
+               .flags          =3D IORESOURCE_DMA,
+       },
+       [3] =3D {
+               .start          =3D DSCR_CMD0_SDMS_RX0,
+               .end            =3D DSCR_CMD0_SDMS_RX0,
+               .flags          =3D IORESOURCE_DMA,
+       }
+};
+
+struct platform_device au13xx_mmc0_device =3D {
+	.name =3D "au1xxx-mmc",
+	.id =3D 0,
+	.dev =3D {
+		.dma_mask               =3D &au1xxx_mmc_dmamask,
+		.coherent_dma_mask      =3D DMA_32BIT_MASK,
+		.platform_data          =3D &au1xmmc_platdata[0],
+	},
+	.num_resources  =3D ARRAY_SIZE(au13xx_mmc0_resources),
+	.resource       =3D au13xx_mmc0_resources,
+};
+
+static struct resource au13xx_mmc1_resources[] =3D {
+       [0] =3D {
+               .start          =3D SD1_PHYS_ADDR,
+               .end            =3D SD1_PHYS_ADDR + 0x7ffff,
+               .flags          =3D IORESOURCE_MEM,
+       },
+       [1] =3D {
+               .start          =3D AU1300_IRQ_SD1 + GPINT_LINUX_IRQ_OFFSET=
,
+               .end            =3D AU1300_IRQ_SD1 + GPINT_LINUX_IRQ_OFFSET=
,
+               .flags          =3D IORESOURCE_IRQ,
+       },
+       [2] =3D {
+               .start          =3D DSCR_CMD0_SDMS_TX1,
+               .end            =3D DSCR_CMD0_SDMS_TX1,
+               .flags          =3D IORESOURCE_DMA,
+       },
+       [3] =3D {
+               .start          =3D DSCR_CMD0_SDMS_RX1,
+               .end            =3D DSCR_CMD0_SDMS_RX1,
+               .flags          =3D IORESOURCE_DMA,
+       }
+};
+
+struct platform_device au13xx_mmc1_device =3D {
+       .name =3D "au1xxx-mmc",
+       .id =3D 1,
+       .dev =3D {
+               .dma_mask               =3D &au1xxx_mmc_dmamask,
+               .coherent_dma_mask      =3D DMA_32BIT_MASK,
+               .platform_data          =3D &au1xmmc_platdata[1],
+       },
+       .num_resources  =3D ARRAY_SIZE(au13xx_mmc1_resources),
+       .resource       =3D au13xx_mmc1_resources,
+};
diff --git a/drivers/mmc/host/Kconfig b/drivers/mmc/host/Kconfig
index 99d4b28..a37bfee 100644
--- a/drivers/mmc/host/Kconfig
+++ b/drivers/mmc/host/Kconfig
@@ -99,7 +99,7 @@ config MMC_WBSD
=20
 config MMC_AU1X
 	tristate "Alchemy AU1XX0 MMC Card Interface support"
-	depends on SOC_AU1200
+	depends on (SOC_AU1200 || SOC_AU13XX)
 	help
 	  This selects the AMD Alchemy(R) Multimedia card interface.
 	  If you have a Alchemy platform with a MMC slot, say Y or M here.
diff --git a/drivers/mmc/host/au1xmmc.c b/drivers/mmc/host/au1xmmc.c
index d3f5561..a3b8ac7 100644
--- a/drivers/mmc/host/au1xmmc.c
+++ b/drivers/mmc/host/au1xmmc.c
@@ -353,7 +353,7 @@ static void au1xmmc_data_complete(struct au1xmmc_host *=
host, u32 status)
=20
 	if (!data->error) {
 		if (host->flags & HOST_F_DMA) {
-#ifdef CONFIG_SOC_AU1200	/* DBDMA */
+#if defined(CONFIG_SOC_AU1200) || defined(CONFIG_SOC_AU13XX)	/* DBDMA */
 			u32 chan =3D DMA_CHANNEL(host);
=20
 			chan_tab_t *c =3D *((chan_tab_t **)chan);
@@ -570,7 +570,7 @@ static void au1xmmc_cmd_complete(struct au1xmmc_host *h=
ost, u32 status)
 	host->status =3D HOST_S_DATA;
=20
 	if (host->flags & HOST_F_DMA) {
-#ifdef CONFIG_SOC_AU1200	/* DBDMA */
+#if defined(CONFIG_SOC_AU1200) || defined(CONFIG_SOC_AU13XX)	/* DBDMA */
 		u32 channel =3D DMA_CHANNEL(host);
=20
 		/* Start the DMA as soon as the buffer gets something in it */
@@ -633,7 +633,7 @@ static int au1xmmc_prepare_data(struct au1xmmc_host *ho=
st,
 	au_writel(data->blksz - 1, HOST_BLKSIZE(host));
=20
 	if (host->flags & HOST_F_DMA) {
-#ifdef CONFIG_SOC_AU1200	/* DBDMA */
+#if defined(CONFIG_SOC_AU1200) || defined(CONFIG_SOC_AU13XX)	/* DBDMA */
 		int i;
 		u32 channel =3D DMA_CHANNEL(host);
=20
@@ -837,7 +837,7 @@ static irqreturn_t au1xmmc_irq(int irq, void *dev_id)
 	return IRQ_HANDLED;
 }
=20
-#ifdef CONFIG_SOC_AU1200
+#if defined(CONFIG_SOC_AU1200) || defined(CONFIG_SOC_AU13XX)
 /* 8bit memory DMA device */
 static dbdev_tab_t au1xmmc_mem_dbdev =3D {
 	.dev_id		=3D DSCR_CMD0_ALWAYS,
@@ -1023,7 +1023,7 @@ static int __devinit au1xmmc_probe(struct platform_de=
vice *pdev)
 	tasklet_init(&host->finish_task, au1xmmc_tasklet_finish,
 			(unsigned long)host);
=20
-#ifdef CONFIG_SOC_AU1200
+#if defined(CONFIG_SOC_AU1200) || defined(CONFIG_SOC_AU13XX)
 	ret =3D au1xmmc_dbdma_init(host);
 	if (ret)
 		printk(KERN_INFO DRIVER_NAME ": DBDMA init failed; using PIO\n");
@@ -1068,7 +1068,7 @@ out5:
 	au_writel(0, HOST_CONFIG2(host));
 	au_sync();
=20
-#ifdef CONFIG_SOC_AU1200
+#if defined(CONFIG_SOC_AU1200) || defined(CONFIG_SOC_AU13XX)
 	au1xmmc_dbdma_shutdown(host);
 #endif
=20
@@ -1115,7 +1115,7 @@ static int __devexit au1xmmc_remove(struct platform_d=
evice *pdev)
 		tasklet_kill(&host->data_task);
 		tasklet_kill(&host->finish_task);
=20
-#ifdef CONFIG_SOC_AU1200
+#if defined(CONFIG_SOC_AU1200) || defined(CONFIG_SOC_AU13XX)
 		au1xmmc_dbdma_shutdown(host);
 #endif
 		au1xmmc_set_power(host, 0);
@@ -1176,7 +1176,7 @@ static struct platform_driver au1xmmc_driver =3D {
=20
 static int __init au1xmmc_init(void)
 {
-#ifdef CONFIG_SOC_AU1200
+#if defined(CONFIG_SOC_AU1200) || defined(CONFIG_SOC_AU13XX)
 	/* DSCR_CMD0_ALWAYS has a stride of 32 bits, we need a stride
 	 * of 8 bits.  And since devices are shared, we need to create
 	 * our own to avoid freaking out other devices.
@@ -1190,7 +1190,7 @@ static int __init au1xmmc_init(void)
=20
 static void __exit au1xmmc_exit(void)
 {
-#ifdef CONFIG_SOC_AU1200
+#if defined(CONFIG_SOC_AU1200) || defined(CONFIG_SOC_AU13XX)
 	if (memid)
 		au1xxx_ddma_del_device(memid);
 #endif
--=20
1.5.4.3


