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

📄 mmcsd_bus.c

📁 linux和2410结合开发 用他可以生成2410所需的zImage文件
💻 C
📖 第 1 页 / 共 2 页
字号:
	/* SET_RELATIVE_ADDR, Stand-by State */	/* in case of SD, the card assigns a rca */	cmd.cmd = MMC_CMD3;	cmd.arg = 0;	cmd.res_type = MMC_RES_TYPE_R6;	cmd.res_flag = 0;	cmd.t_res = MMC_TIME_NCR_MAX;	cmd.t_fin = MMC_TIME_NRC_MIN;	ret = slot->send_cmd(slot, &cmd);	DEBUG2(2, "sent CMD3\n");	if (ret < 0) {		DEBUG2(1, "CMD3 failed, ret = %d\n", ret);		return ret;	}	mmc_str2r6(&(slot->r6), cmd.res);	if (!(slot->r6.card_status & STATE_IDENT)) {		DEBUG2(1, "CMD3 failed, r6_status = 0x%04x\n", 		       slot->r6.card_status);		return -ENODEV;	}	slot->rca = (slot->r6).rca;	DEBUG2(3, "rca = %04x\n", slot->rca);	/* SEND_CSD, Stand-by State */	cmd.cmd = MMC_CMD9;	cmd.arg = (slot->rca << 16) & 0xffff0000;	cmd.res_type = MMC_RES_TYPE_R2;	cmd.res_flag = 0;	cmd.t_res = MMC_TIME_NCR_MAX;	cmd.t_fin = MMC_TIME_NRC_MIN;	ret = slot->send_cmd(slot, &cmd);	DEBUG2(2, "sent CMD9\n");	if (ret < 0) {		DEBUG2(1, "CMD9 failed, ret = %d\n", ret);		return ret;	}	mmc_str2csd(slot->sd, &(slot->csd), cmd.res);	DEBUG2(3, "csd(%d)  taac.man(%d) taac.exp(%d) nsac(%d)\n"	       "tran.man(%d) tran.exp(%d) ccc(%03x) read_len(%d)\n"	       "read_part(%d) write_mis(%d) read_mis(%d) dsr(%d) c_size(%d)\n"	       "vcc_r_min(%d) vcc_r_max(%d) vcc_w_min(%d) vcc_w_max(%d)\n"	       "c_size_mult(%d) er_size(%d) er_grp_size(%d) wp_grp_size(%d)\n"	       "wp_grp_en(%d)  r2w_factor(%d) write_len(%d)\n"	       "write_part(%d) ffmt_grp(%d) copy(%d) perm_wp(%d) tmp_wp(%d)\n"	       "ffmt(%d)\n",	       slot->csd.csd, slot->csd.taac.man, slot->csd.taac.exp, 	       slot->csd.nsac, slot->csd.tran_speed.man, 	       slot->csd.tran_speed.exp, slot->csd.ccc, slot->csd.read_len, 	       slot->csd.read_part, slot->csd.write_mis, slot->csd.read_mis,	       slot->csd.dsr, slot->csd.c_size, slot->csd.vcc_r_min, 	       slot->csd.vcc_r_max, slot->csd.vcc_w_min, slot->csd.vcc_w_max,	       slot->csd.c_size_mult, slot->csd.er_blk_en,	       slot->csd.er_sec_size, slot->csd.wp_grp_size,	       slot->csd.wp_grp_en, slot->csd.r2w_factor, slot->csd.write_len,	       slot->csd.write_part, slot->csd.ffmt_grp, 	       slot->csd.copy, slot->csd.perm_wp, slot->csd.tmp_wp,	       slot->csd.ffmt);	/* Get CSD value */	mmc_get_CSD_info(slot, &(slot->csd));	/* Set high clock rate for the normal data transfer */	slot->set_clock(slot, MMC_SD_CLOCK_HIGH);	/* Get SCR value */	/* SELECT CARD */	cmd.cmd = MMC_CMD7;	cmd.arg = (slot->rca << 16) & 0xffff0000;	cmd.res_type = MMC_RES_TYPE_R1B;	cmd.res_flag = 0;	cmd.t_res = MMC_TIME_NCR_MAX;	cmd.t_fin = MMC_TIME_NRC_MIN;	ret = slot->send_cmd(slot, &cmd);	DEBUG2(2, "sent CMD7\n");	if (ret < 0) {		DEBUG2(1, "CMD7 failed, ret = %d\n", ret);	}	mmc_str2r1(&(slot->r1), cmd.res);	if (slot->r1 & (R1_cc_err | R1_err)) {		DEBUG2(1, "CMD7 failed, r1 = 0x%08x\n", slot->r1);		return -ENODEV;	}	/* Skip this if the SD ASIC only support narrow bus */	if (slot->narrow_bus) {		slot->bus_width = 0;		goto skip_send_scr;	}	/* SEND_SCR */	cmd.cmd = MMC_CMD55;	cmd.arg = (slot->rca << 16) & 0xffff0000;	cmd.res_type = MMC_RES_TYPE_R1;	cmd.res_flag = 0;	cmd.t_res = MMC_TIME_NCR_MAX;	cmd.t_fin = MMC_TIME_NRC_MIN;	ret = slot->send_cmd(slot, &cmd);	DEBUG2(2, "sent CMD55\n");	if (ret < 0) {		DEBUG2(1, "CMD55 failed, ret = %d\n", ret);			}	mmc_str2r1(&(slot->r1), cmd.res);	if (slot->r1 & (R1_cc_err | R1_err)) {		DEBUG2(1, "CMD55 failed, r1 = 0x%08x\n", slot->r1);		goto skip_send_scr;	}	cmd.cmd = MMC_ACMD51;	cmd.arg = 0;	cmd.res_type = MMC_RES_TYPE_R1;	cmd.res_flag = MMC_RES_FLAG_DATALINE;	cmd.data_len = MMC_SCR_SIZE;	cmd.t_res = 0;	cmd.t_fin = MMC_TIME_NRC_MIN;	ret = slot->send_cmd(slot, &cmd);	DEBUG2(2, "sent ACMD51\n");	if (ret < 0) {		DEBUG2(1, "ACMD51 failed, ret = %d\n", ret);		goto skip_send_scr;	}	mmc_str2scr(&(slot->scr), cmd.res);	DEBUG2(3, "scr_version(%d) sd_spec_version(%d) data_status(%d)\n"	       "sd_security(%d) sd_bus_widths(0x%02x)\n", 	       slot->scr.scr_version, slot->scr.sd_spec_version,	       slot->scr.data_status, slot->scr.sd_security, 	       slot->scr.sd_bus_widths);	if ((slot->scr.sd_bus_widths) & SD_BUS_WIDTH_4) {		slot->bus_width = 0x02;	} else {		slot->bus_width = 0;	} skip_send_scr:	/* SET_BUS_WIDTH */	cmd.cmd = MMC_CMD55;	cmd.arg = (slot->rca << 16) & 0xffff0000;	cmd.res_type = MMC_RES_TYPE_R1;	cmd.res_flag = 0;	cmd.t_res = MMC_TIME_NCR_MAX;	cmd.t_fin = MMC_TIME_NRC_MIN;	ret = slot->send_cmd(slot, &cmd);	DEBUG2(2, "sent CMD55\n");	if (ret < 0) {		DEBUG2(1, "CMD55 failed, ret = %d\n", ret);		goto deselect;	}	mmc_str2r1(&(slot->r1), cmd.res);	if (slot->r1 & (R1_cc_err | R1_err)) {		DEBUG2(1, "CMD55 failed, r1 = 0x%08x\n", slot->r1);		goto deselect;	}	cmd.cmd = MMC_ACMD6;	cmd.arg = slot->bus_width;	cmd.res_type = MMC_RES_TYPE_R1;	cmd.res_flag = 0;	cmd.t_res = MMC_TIME_NCR_MAX;	cmd.t_fin = MMC_TIME_NRC_MIN;	ret = slot->send_cmd(slot, &cmd);	DEBUG2(2, "sent ACMD6\n");	if (ret < 0) {		DEBUG2(1, "ACMD6 failed, ret = %d\n", ret);		goto deselect;	}	mmc_str2r1(&(slot->r1), cmd.res);	if (slot->r1 & (R1_cc_err | R1_err)) {		DEBUG2(1, "ACMD6 failed, r1 = 0x%08x\n", slot->r1);	} deselect:	/* DESELECT CARD */	cmd.cmd = MMC_CMD7;	cmd.arg = 0;	cmd.res_type = MMC_RES_TYPE_NONE;	cmd.res_flag = 0;	cmd.t_fin = MMC_TIME_NCC_MIN;	ret = slot->send_cmd(slot, &cmd);	DEBUG2(2, "sent CMD7(DESELECT)\n");	return ret;}static int card_identify(struct mmc_slot *slot){	int ret;	int retry = MMC_RETRIES_SD_CHECK;	struct mmc_cmd cmd;	/* Initialize some slot variables */	slot->bus_width = 0;	slot->rca = 0;	/* Power up */	if (slot->power_up) {		slot->power_up(slot);	}	/* Set low clock rate for the indentification */	slot->set_clock(slot, MMC_MMC_CLOCK_LOW); retry_card_check:	/* go IDLE state */	ret = mmc_reset(slot);	if (ret < 0) {		return ret;	}	/* check whether it's a MMC or a SD card. */	/* APP_CMD */	cmd.cmd = MMC_CMD55;	cmd.arg = (slot->rca << 16) & 0xffff0000;	cmd.res_type = MMC_RES_TYPE_R1;	cmd.res_flag = 0;	cmd.t_res = MMC_TIME_NCR_MAX;	cmd.t_fin = MMC_TIME_NRC_MIN;	ret = slot->send_cmd(slot, &cmd);	DEBUG2(2, "sent CMD55\n");	if (ret < 0) {		if (ret == -ENODEV) {			return ret;		}		if (retry--) {			DEBUG2(1, "retry to check MMC or SD\n");			goto retry_card_check;		}		DEBUG2(1, "identify MultiMediaCard\n");		slot->sd = 0;		ret = mmc_identify(slot);	} else {		DEBUG2(1, "identify SD Memory Card\n");		slot->sd = 1;		ret = sd_identify(slot);	}	return ret;}#ifdef CONFIG_PROC_FSstatic int mmc_read_proc(char *page, char **start, off_t off,                         int count, int *eof, void *data){	char *p = page;	int len;	struct mmc_slot *slot = (struct mmc_slot *)data;	p += sprintf(p, "read-only\t: %s\n"			"card type\t: %s\n"			"product name\t: %s\n"			"card size\t: %ldMB\n",			slot->readonly ? "yes":"no", slot->sd ? "SD":"MMC",			slot->sd ? slot->cid.pnm_sd : slot->cid.pnm, 			slot->size/(1024 * 1024));	len = (p - page) - off;	if (len < 0) len = 0;	*eof = (len <= count) ? 1 : 0;	*start = page + off;	return len;}#endifint add_mmc_device(struct mmc_slot *slot){	int i;	DEBUG2(2, "[%s] slot id: %d\n", __FUNCTION__, slot->id);	down(&mmc_slots_mutex);	slot->stat = 0;	i = card_identify(slot);	if (i) {		up(&mmc_slots_mutex);		return i;	}	init_MUTEX(&slot->mutex);	slot->transfer1b = mmc_do_transfer_1blk;	slot->stat = 1;	for (i = 0; i < MAX_MMC_SLOTS; i++) {		if (!mmc_slots[i]) {			struct mmc_notifier *not=mmc_notifiers;			mmc_slots[i] = slot;			while (not) {				(*(not->add))(slot);				not = not->next;                        }			up(&mmc_slots_mutex);			MOD_INC_USE_COUNT;#ifdef CONFIG_PROC_FS			create_proc_read_entry ("driver/mmcsd", 0, NULL, 						mmc_read_proc, (void *)slot);#endif			return 0;		}	}	up(&mmc_slots_mutex);	return -ENOSPC;}int del_mmc_device(struct mmc_slot *slot){	int i;	DEBUG2(2, "[%s] slot id: %d\n", __FUNCTION__, slot->id);	down(&mmc_slots_mutex);	/* Power down */	if (slot->power_down) {		slot->power_down(slot);	}	for (i = 0; i < MAX_MMC_SLOTS; i++) {		if (mmc_slots[i] == slot) {			struct mmc_notifier *not=mmc_notifiers;#ifdef CONFIG_PROC_FS			remove_proc_entry ("driver/mmcsd", NULL);#endif			while (not) {				(*(not->remove))(slot);				not = not->next;			}			mmc_slots[i] = NULL;			up (&mmc_slots_mutex);			MOD_DEC_USE_COUNT;			return 0;		}	}	up(&mmc_slots_mutex);	return -EINVAL;}int reidentify_mmc_device(struct mmc_slot *slot){	int ret;	down(&mmc_slots_mutex);	ret = card_identify(slot);	up(&mmc_slots_mutex);	return ret;}void register_mmc_user(struct mmc_notifier *new){	int i;	down(&mmc_slots_mutex);	new->next = mmc_notifiers;	mmc_notifiers = new;	MOD_INC_USE_COUNT;	for (i=0; i< MAX_MMC_SLOTS; i++)		if (mmc_slots[i])			new->add(mmc_slots[i]);	up(&mmc_slots_mutex);}int unregister_mmc_user(struct mmc_notifier *old){	struct mmc_notifier **prev = &mmc_notifiers;	struct mmc_notifier *cur;	int i;	down(&mmc_slots_mutex);	while ((cur = *prev)) {		if (cur == old) {			*prev = cur->next;			MOD_DEC_USE_COUNT;			for (i=0; i< MAX_MMC_SLOTS; i++)				if (mmc_slots[i])					old->remove(mmc_slots[i]);			up(&mmc_slots_mutex);			return 0;		}		prev = &cur->next;	}	up(&mmc_slots_mutex);	return 1;}static int __init init_mmcsd_bus(void){	int i;	for (i = 0; i < MAX_MMC_SLOTS; i++) {		mmc_slots[i] = NULL;	}	mmc_notifiers = NULL;	return 0;}static void __exit exit_mmcsd_bus(void){}module_init(init_mmcsd_bus);module_exit(exit_mmcsd_bus);EXPORT_SYMBOL(add_mmc_device);EXPORT_SYMBOL(del_mmc_device);EXPORT_SYMBOL(reidentify_mmc_device);EXPORT_SYMBOL(register_mmc_user);EXPORT_SYMBOL(unregister_mmc_user);EXPORT_SYMBOL(mmc_res_len);MODULE_AUTHOR("Yong-iL Joh <tolkien@mizi.com>");MODULE_LICENSE("Not GPL, Proprietary License");MODULE_DESCRIPTION("MMC/SD bus protocol interfaces");

⌨️ 快捷键说明

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