⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mmc.patch

📁 patches for linux-2.6.
💻 PATCH
📖 第 1 页 / 共 3 页
字号:
diff -Nbur linux26-cvs/arch/mips/au1000/common/platform.c linux26-cvs.PMMMC/arch/mips/au1000/common/platform.c--- linux26-cvs/arch/mips/au1000/common/platform.c	2005-08-16 12:34:33.000000000 -0500+++ linux26-cvs.PMMMC/arch/mips/au1000/common/platform.c	2005-08-16 10:58:38.000000000 -0500@@ -179,6 +179,38 @@ 	.num_resources  = ARRAY_SIZE(au1200_lcd_resources), 	.resource       = au1200_lcd_resources, };++static struct resource au1xxx_mmc_resources[] = {+	[0] = {+		.start          = SD0_PHYS_ADDR,+		.end            = SD0_PHYS_ADDR + 0x40,+		.flags          = IORESOURCE_MEM,+	},+	[1] = {+		.start		= SD1_PHYS_ADDR,+		.end 		= SD1_PHYS_ADDR + 0x40,+		.flags		= IORESOURCE_MEM,+	},+	[2] = {+		.start          = AU1200_SD_INT,+		.end            = AU1200_SD_INT,+		.flags          = IORESOURCE_IRQ,+	}+};++static u64 au1xxx_mmc_dmamask =  ~(u32)0;++static struct platform_device au1xxx_mmc_device = {+	.name = "au1xxx-mmc",+	.id = 0,+	.dev = {+		.dma_mask               = &au1xxx_mmc_dmamask,+		.coherent_dma_mask      = 0xffffffff,+	},+	.num_resources  = ARRAY_SIZE(au1xxx_mmc_resources),+	.resource       = au1xxx_mmc_resources,+};+ #endif  static struct platform_device *au1xxx_platform_devices[] __initdata = {@@ -191,6 +223,7 @@ 	&au1xxx_usb_gdt_device, 	&au1xxx_usb_otg_device, 	&au1200_lcd_device,+	&au1xxx_mmc_device, #endif }; diff -Nbur linux26-cvs/drivers/mmc/au1xmmc.c linux26-cvs.PMMMC/drivers/mmc/au1xmmc.c--- linux26-cvs/drivers/mmc/au1xmmc.c	1969-12-31 18:00:00.000000000 -0600+++ linux26-cvs.PMMMC/drivers/mmc/au1xmmc.c	2005-08-16 12:42:23.000000000 -0500@@ -0,0 +1,1153 @@+/* + * linux/drivers/mmc/au1xmmc.c - AU1XX0 MMC driver + *  + *  Copyright (c) 2005, Advanced Micro Devices, Inc.+ *+ *  Developed with help from the 2.4.30 MMC AU1XXX controller including+ *  the following copyright notices:+ *     Copyright (c) 2003-2004 Embedded Edge, LLC.+ *     Portions Copyright (C) 2002 Embedix, Inc+ *     Copyright 2002 Hewlett-Packard Company++ *  2.6 version of this driver inspired by:+ *     (drivers/mmc/wbsd.c) Copyright (C) 2004-2005 Pierre Ossman, + *     All Rights Reserved.+ *     (drivers/mmc/pxa.c) Copyright (C) 2003 Russell King, + *     All Rights Reserved.++ * This program is free software; you can redistribute it and/or modify+ * it under the terms of the GNU General Public License version 2 as+ * published by the Free Software Foundation.+ */++/* Why is a timer used to detect insert events?+ *+ * From the AU1100 MMC application guide:+ * If the Au1100-based design is intended to support both MultiMediaCards + * and 1- or 4-data bit SecureDigital cards, then the solution is to + * connect a weak (560KOhm) pull-up resistor to connector pin 1. + * In doing so, a MMC card never enters SPI-mode communications, + * but now the SecureDigital card-detect feature of CD/DAT3 is ineffective+ * (the low to high transition will not occur).+ *+ * So we use the timer to check the status manually. + */++#include <linux/config.h>+#include <linux/module.h>+#include <linux/init.h>+#include <linux/device.h>+#include <linux/mm.h>+#include <linux/interrupt.h>+#include <linux/dma-mapping.h>++#include <linux/mmc/host.h>+#include <linux/mmc/protocol.h>+#include <asm/io.h>+#include <asm/mach-au1x00/au1000.h>+#include <asm/mach-au1x00/au1xxx_dbdma.h> +#include <asm/mach-au1x00/au1100_mmc.h>+#include <asm/scatterlist.h>++#ifdef CONFIG_MIPS_PB1200+#include <asm/mach-pb1x00/pb1200.h>+#endif++#ifdef CONFIG_MIPS_DB1200+#include <asm/mach-db1x00/db1200.h>+#endif++#ifdef CONFIG_PM+#include <asm/mach-au1x00/au1xxx_pm.h>+#endif+++#include "au1xmmc.h"++#define DRIVER_NAME "au1xxx-mmc"++/* Set this to enable special debugging macros */+/* #define MMC_DEBUG */++#ifdef MMC_DEBUG+#define DEBUG(fmt, idx, args...) printk("au1xx(%d): DEBUG: " fmt, idx, ##args)+#else+#define DEBUG(fmt, idx, args...)+#endif++#ifdef CONFIG_PM +int au1xmmc_pm_callback(au1xxx_power_dev_t *dev, +		au1xxx_request_t request, +		void *data);+au1xxx_power_dev_t *mmc_pm_dev;+static uint sleep_sd0[8];+static int volatile card_inserted, card_detected;+#if defined (CONFIG_MIPS_PB1200)+static uint sleep_sd1[8];+#endif+#endif+++const struct {+	u32 iobase;+	u32 tx_devid, rx_devid;+	u16 bcsrpwr;+	u16 bcsrstatus;+	u16 wpstatus;+} au1xmmc_card_table[] = {+	{ SD0_BASE, DSCR_CMD0_SDMS_TX0, DSCR_CMD0_SDMS_RX0, +	  BCSR_BOARD_SD0PWR, BCSR_INT_SD0INSERT, BCSR_STATUS_SD0WP },+#ifndef CONFIG_MIPS_DB1200+	{ SD1_BASE, DSCR_CMD0_SDMS_TX1, DSCR_CMD0_SDMS_RX1, +	  BCSR_BOARD_DS1PWR, BCSR_INT_SD1INSERT, BCSR_STATUS_SD1WP }+#endif+};++#define AU1XMMC_CONTROLLER_COUNT \+	(sizeof(au1xmmc_card_table) / sizeof(au1xmmc_card_table[0]))++/* This array stores pointers for the hosts (used by the IRQ handler) */+struct au1xmmc_host *au1xmmc_hosts[AU1XMMC_CONTROLLER_COUNT];+static int dma = 1;++#ifdef MODULE+MODULE_PARM(dma, "i");+MODULE_PARM_DESC(dma, "Use DMA engine for data transfers (0 = disabled)");+#endif++static inline void IRQ_ON(struct au1xmmc_host *host, u32 mask) {+	u32 val = au_readl(HOST_CONFIG(host));+	val |= mask;+	au_writel(val, HOST_CONFIG(host));+	au_sync();+}++static inline void FLUSH_FIFO(struct au1xmmc_host *host) {+	u32 val = au_readl(HOST_CONFIG2(host));++	au_writel(val | SD_CONFIG2_FF, HOST_CONFIG2(host));+	au_sync_delay(1);+	+	/* SEND_STOP will turn off clock control - this re-enables it */+	val &= ~SD_CONFIG2_DF;++	au_writel(val, HOST_CONFIG2(host));+	au_sync();+}++static inline void IRQ_OFF(struct au1xmmc_host *host, u32 mask) {+	u32 val = au_readl(HOST_CONFIG(host));+	val &= ~mask;+	au_writel(val, HOST_CONFIG(host));+	au_sync();+}++static inline void SEND_STOP(struct au1xmmc_host *host) {++	/* We know the value of CONFIG2, so avoid a read we don't need */+	u32 mask = SD_CONFIG2_EN;++	WARN_ON(host->status != HOST_S_DATA);+	host->status = HOST_S_STOP;++	au_writel(mask | SD_CONFIG2_DF, HOST_CONFIG2(host));+	au_sync();++	/* Send the stop commmand */+	au_writel(STOP_CMD, HOST_CMD(host));+}++static void au1xmmc_set_power(struct au1xmmc_host *host, int state) {++	u32 val = au1xmmc_card_table[host->id].bcsrpwr;++	bcsr->board &= ~val;+	if (state) bcsr->board |= val;+	+	au_sync_delay(1);+}++static inline int au1xmmc_card_inserted(struct au1xmmc_host *host) {+	return (bcsr->sig_status & au1xmmc_card_table[host->id].bcsrstatus) +		? 1 : 0;+}	++static inline int au1xmmc_card_readonly(struct au1xmmc_host *host) {+	return (bcsr->status & au1xmmc_card_table[host->id].wpstatus) +		? 1 : 0;+}++static void au1xmmc_finish_request(struct au1xmmc_host *host) {+  +	struct mmc_request *mrq = host->mrq;++	host->mrq = NULL;+	host->flags &= HOST_F_ACTIVE; ++	host->dma.len = 0;+	host->dma.dir = 0;++	host->pio.index  = 0;+	host->pio.offset = 0;+	host->pio.len = 0;++	host->status = HOST_S_IDLE;++	bcsr->disk_leds |= (1 << 8);++	mmc_request_done(host->mmc, mrq);+}++static void au1xmmc_tasklet_finish(unsigned long param) {+	struct au1xmmc_host *host = (struct au1xmmc_host *) param;+	au1xmmc_finish_request(host);+}++static int au1xmmc_send_command(struct au1xmmc_host *host, int wait,  +				struct mmc_command *cmd) {++	u32 mmccmd = (cmd->opcode << SD_CMD_CI_SHIFT);++	switch(cmd->flags) {+	case MMC_RSP_R1:+		mmccmd |= SD_CMD_RT_1;+		break;+	case MMC_RSP_R1B:+		mmccmd |= SD_CMD_RT_1B;+		break;+	case MMC_RSP_R2:+		mmccmd |= SD_CMD_RT_2;+		break;+	case MMC_RSP_R3:+		mmccmd |= SD_CMD_RT_3;+		break;+	}++	switch(cmd->opcode) {+	case MMC_READ_SINGLE_BLOCK:+	case SD_APP_SEND_SCR:+		mmccmd |= SD_CMD_CT_2;+		break;+	case MMC_READ_MULTIPLE_BLOCK:+		mmccmd |= SD_CMD_CT_4;+		break;+	case MMC_WRITE_BLOCK:+		mmccmd |= SD_CMD_CT_1;+		break;+	+	case MMC_WRITE_MULTIPLE_BLOCK:+		mmccmd |= SD_CMD_CT_3;+		break;+	case MMC_STOP_TRANSMISSION:+		mmccmd |= SD_CMD_CT_7;+		break;+	}+	+	au_writel(cmd->arg, HOST_CMDARG(host));+	au_sync();++	if (wait) +		IRQ_OFF(host, SD_CONFIG_CR);+	+	au_writel((mmccmd | SD_CMD_GO), HOST_CMD(host));+	au_sync();++	/* Wait for the command to go on the line */++	while(1) {+		if (!(au_readl(HOST_CMD(host)) & SD_CMD_GO))+			break;+	}++	/* Wait for the command to come back */++	if (wait) {+		u32 status = au_readl(HOST_STATUS(host));++		while(!(status & SD_STATUS_CR)) +			status = au_readl(HOST_STATUS(host));+		+		/* Clear the CR status */+		au_writel(SD_STATUS_CR, HOST_STATUS(host));++		IRQ_ON(host, SD_CONFIG_CR);+	}++	return MMC_ERR_NONE;+}++static void au1xmmc_data_complete(struct au1xmmc_host *host, u32 status) {++	struct mmc_request *mrq = host->mrq;+	struct mmc_data *data;+	u32 crc;++	WARN_ON(host->status != HOST_S_DATA && host->status != HOST_S_STOP);++	if (host->mrq == NULL)+		return;++	data = mrq->cmd->data;++	if (status == 0)+		status = au_readl(HOST_STATUS(host));++	/* The transaction is really over when the SD_STATUS_DB bit is clear */++	while((host->flags & HOST_F_XMIT) && (status & SD_STATUS_DB)) +		status = au_readl(HOST_STATUS(host));++	data->error = MMC_ERR_NONE;+	dma_unmap_sg(mmc_dev(host->mmc), data->sg, data->sg_len, host->dma.dir);++        /* Process any errors */++	crc = (status & (SD_STATUS_WC | SD_STATUS_RC));+	if (host->flags & HOST_F_XMIT) +		crc |= ((status & 0x07) == 0x02) ? 0 : 1;+	+	if (crc) +		data->error = MMC_ERR_BADCRC;++	/* Clear the CRC bits */+	au_writel(SD_STATUS_WC | SD_STATUS_RC, HOST_STATUS(host));++	data->bytes_xfered = 0;++	if (data->error == MMC_ERR_NONE) {+		if (host->flags & HOST_F_DMA) {+			u32 chan = DMA_CHANNEL(host);++			chan_tab_t *c = *((chan_tab_t **) chan);+			volatile au1x_dma_chan_t *cp = c->chan_ptr;+			data->bytes_xfered = cp->ddma_bytecnt;+		}+		else +			data->bytes_xfered = +				(data->blocks * (1 << data->blksz_bits)) - host->pio.len;+	}++	au1xmmc_finish_request(host);+}++static void au1xmmc_tasklet_data(unsigned long param) {+	struct au1xmmc_host *host = (struct au1xmmc_host *) param;++	u32 status = au_readl(HOST_STATUS(host));+	au1xmmc_data_complete(host, status);+}++#define AU1XMMC_MAX_TRANSFER 8++static void au1xmmc_send_pio(struct au1xmmc_host *host) {++	struct mmc_data *data = 0;+	int sg_len, max, count = 0;+	unsigned char *sg_ptr;+	u32 status = 0;++	data = host->mrq->data;++	if (!(host->flags & HOST_F_XMIT)) +		return;+	+	/* This is the pointer to the data buffer */+	sg_ptr = phys_to_virt(sg_dma_address(&data->sg[host->pio.index])) + +		host->pio.offset;++	/* This is the space left inside the buffer */+	sg_len = data->sg[host->pio.index].length - host->pio.offset;++	/* Check to if we need less then the size of the sg_buffer */++	max = (sg_len > host->pio.len) ? host->pio.len : sg_len;+	if (max > AU1XMMC_MAX_TRANSFER) max = AU1XMMC_MAX_TRANSFER;++	for(count = 0; count < max; count++ ) {+		unsigned char val;++		status = au_readl(HOST_STATUS(host));		++		if (!(status & SD_STATUS_TH))+			break;++		val = *sg_ptr++;++		au_writel((unsigned long) val, HOST_TXPORT(host));+		au_sync();+	}++	host->pio.len -= count;+	host->pio.offset += count;++	if (count == sg_len) {+		host->pio.index++;+		host->pio.offset = 0;+	}++	if (host->pio.len == 0) {+		IRQ_OFF(host, SD_CONFIG_TH);++		if (host->flags & HOST_F_STOP)+			SEND_STOP(host);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -