亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? mmc_qspi.c

?? mmc_qspi.tar.gz mmc block driver code for uClinux
?? C
字號:
#include <linux/config.h>#include <linux/kernel.h>#include <linux/module.h>#include <linux/init.h>#include <linux/kmod.h>#include <linux/slab.h>#include <linux/delay.h>#include <asm/byteorder.h>#include <asm/errno.h>#include "qspi.h"#include "mmc_qspi.h"#include "mmc_crc.h"#define MMC_DEVICE 0 /* MMC device number on the qspi bus */#define CMD_SIZE 6#define MMC_BLOCK_SIZE 512#define MMC_BLOCK_NB 16 * 1024 * 2#define REG_SIZE 16/* MMC command */#define CMD_0 0 /* reset */#define CMD_1 1 /* initialization */#define CMD_9 2 /* send CSD register */#define CMD_10 3 /* send CID register */#define CMD_13 4 /* send status */#define CMD_17 5 /* read block */#define CMD_24 6 /* write block */#define CMD_59 7 /* set/unset CRC mode */#include "klog.h"struct cmd{	unsigned char cmd;	unsigned char a1;	unsigned char a2;	unsigned char a3;	unsigned char a4;	unsigned char checksum;} __attribute__((packed));static struct cmd mmc_cmd_array[] ={	{0x40, 0x00, 0x00, 0x00, 0x00, 0x95},	{0x41, 0x00, 0x00, 0x00, 0x00, 0xff},	{0x49, 0x00, 0x00, 0x00, 0x00, 0xff},	{0x4a, 0x00, 0x00, 0x00, 0x00, 0xff},	{0x4d, 0x00, 0x00, 0x00, 0x00, 0xff},	{0x51, 0x00, 0x00, 0x00, 0x00, 0xff},	{0x58, 0x00, 0x00, 0x00, 0x00, 0xff},	{0x7b, 0x00, 0x00, 0x00, 0x00, 0xff}};static int read_answer (unsigned char *);static int send_cmd (unsigned int, unsigned char *);static int get_status (unsigned char *);static int dummy_write (void);static char *get_card_register (unsigned int);	/* dummy write function :) */static int dummy_write (void){	int retval;	unsigned char dummy_char = 0xff;		retval = qspi_ioctl (MMC_DEVICE, CMD_CS_HIGHT, 0);	if (retval < 0)	{		return (retval);	}	retval = qspi_write (MMC_DEVICE, &dummy_char, sizeof (unsigned char));	if (retval < 0)		return (retval);		retval = qspi_ioctl (MMC_DEVICE, CMD_CS_LOW, 0);	if (retval < 0)	{		return (retval);	}	return (0);}static int get_status (unsigned char *status){	int retval, count = 10;	/* test cmd_num */	mmc_cmd_array[CMD_13].checksum = 0;	mmc_cmd_array[CMD_13].checksum = 		crc7 (&mmc_cmd_array[CMD_13].cmd, 5);	retval = qspi_write (MMC_DEVICE, 			(char*) &mmc_cmd_array[CMD_13].cmd, CMD_SIZE);	if (retval < 0)	{		return (retval);	}	if (retval != CMD_SIZE)	{		err("%s - incomplete command send (%d bytes instead of %d)", 				__FUNCTION__, retval, CMD_SIZE);		return (-EIO);	}	/* CMD_13 return a 2 bytes answer (R2 format) */	do	{		retval = qspi_read (MMC_DEVICE, &status[0],  				sizeof (unsigned char));		if (retval < 0)			return (retval);	} 	while ((status[0] == 0xff) && (count--));		retval = qspi_read (MMC_DEVICE, &status[1],  			sizeof (unsigned char));	if (retval < 0)		return (retval);			return (0);}static int read_answer (unsigned char *answer){	int retval = 0;	unsigned int count = 50;	do	{		retval = qspi_read (MMC_DEVICE, answer, sizeof (unsigned char));		if (retval < 0)			return (retval);				/* must handle the case retval == 0 */	} 	while ((*answer == 0xff) && (count--));	/* if the MMC is not ready, 0xff is returned as answer...	 * we retry count times... */		if (*answer == 0xff)		return (-EBUSY);	return (0);		}static int send_cmd (unsigned int cmd_num, unsigned char *answer){	int retval;	/* test cmd_num */	mmc_cmd_array[cmd_num].checksum = 0;	mmc_cmd_array[cmd_num].checksum = 		crc7 (&mmc_cmd_array[cmd_num].cmd, 5);	dbg("%s - cmd %d - checksum : 0x%x", __FUNCTION__, 			cmd_num, mmc_cmd_array[cmd_num].checksum & 0xff);	retval = qspi_write (MMC_DEVICE, 			(char*) &mmc_cmd_array[cmd_num].cmd, CMD_SIZE);	if (retval < 0)	{		return (retval);	}	if (retval != CMD_SIZE)	{		err("%s - incomplete command send (%d bytes instead of %d)", 				__FUNCTION__, retval, CMD_SIZE);		return (-EIO);	}	return (read_answer (answer));}int write_block (unsigned char a1, unsigned char a2, unsigned char a3, unsigned char a4, char *block){	int nb_bytes_write, retval;	int i;	unsigned int count = 5000;	char init_transfer = 0xfe;	unsigned short checksum = 0xffff;	unsigned char answer;	for (i = 0; i < DUMMY_NBR; i++)	{		retval = dummy_write ();		if (retval < 0)		{			err("%s - dummy_write() error", __FUNCTION__);			return (retval);		}	}	/* must lock the mmc cmd array */	mmc_cmd_array[CMD_24].a1 = a1;	mmc_cmd_array[CMD_24].a2 = a2;	mmc_cmd_array[CMD_24].a3 = a3;	mmc_cmd_array[CMD_24].a4 = a4;	retval = send_cmd (CMD_24, &answer);	if (retval < 0)	{		err("%s - failed to send CMD_24 (retval %d - answer 0x%x)", 				__FUNCTION__,				retval, 				answer & 0xff);		return (retval);	}	/* can unlock the mmc cmd array */	if (answer != 0x00)	{		/* may be we must be patient and 		 * read_answer() more times */		err("%s - CMD_24 - answer 0x%x instead of 0x00", 				__FUNCTION__, 				answer & 0xff);	        err("%s : block %d %d %d %d", __FUNCTION__, a1, a2, a3, a4);		return (-EPROTO);	}	retval = dummy_write ();	if (retval < 0)	{		err("%s - dummy_write () error", __FUNCTION__);		return (retval);	}	/* compute the block checksum and then send it to the MMC */ 	checksum = (unsigned short) crc16 (block, MMC_BLOCK_SIZE);	checksum = __cpu_to_be16(checksum); /* endianness */	/* send 0xfe to initiate block transfer  */	retval = qspi_write (MMC_DEVICE, &init_transfer, sizeof (char));	if (retval < 0)	{		err("%s - failed to init transfer", __FUNCTION__);		return (retval);	}	retval = qspi_write (MMC_DEVICE, block, 			MMC_BLOCK_SIZE * sizeof (unsigned char));	if (retval < 0)	{		err("%s - failed to write block", __FUNCTION__);		return (retval);	}	if (retval != MMC_BLOCK_SIZE)	{		err("%s - %d bytes write instead of %d", 				__FUNCTION__, retval, MMC_BLOCK_SIZE);	}	nb_bytes_write = retval;	/* send 0xffff as a checksum  */	retval = qspi_write (MMC_DEVICE, (char *) &checksum, sizeof (unsigned short));	if (retval < 0)	{		dbg("%s - failed to init transfer", __FUNCTION__);		return (retval);	}	count = 5000;	/* wait for 0xff as a MMC acknowledgement */	do	{		retval = qspi_read (MMC_DEVICE, &answer, sizeof (unsigned char));		if (retval < 0)			return (retval);				/* must handle the case retval == 0 */	} 	while ((answer != 0xff) && (count--));	if (!count)		return (-EPROTO);	for (i = 0; i < DUMMY_NBR; i++)	{		retval = dummy_write ();		if (retval < 0)		{			err("%s - dummy_write() error", __FUNCTION__);			return (retval);		}	}	return (nb_bytes_write);}int read_block (unsigned char a1, unsigned char a2, unsigned char a3, unsigned char a4, char *block){	int nb_bytes_read, retval;	unsigned int count = 10;	unsigned char answer;	unsigned short checksum, block_crc;	int i;	if (!block)	{		err("%s - first argument is a NULL pointer", __FUNCTION__);		return (-EINVAL);	}		for (i = 0; i < DUMMY_NBR; i++)	{		retval = dummy_write ();		if (retval < 0)		{			err("%s - dummy_write() error", __FUNCTION__);			return (retval);		}	}	/* TODO : must lock the mmc cmd array */		mmc_cmd_array[CMD_17].a1 = a1;	mmc_cmd_array[CMD_17].a2 = a2;	mmc_cmd_array[CMD_17].a3 = a3;	mmc_cmd_array[CMD_17].a4 = a4;	/* send the single read block command */	retval = send_cmd (CMD_17, &answer);	if (retval < 0)	{		err("%s - failed to send CMD_17", __FUNCTION__);		return (retval);	}		/* to do : can unlock the mmc cmd array */	while (((answer & 0xff) != 0xfe) && (count--))	{		retval = read_answer (&answer);		if (retval < 0)		{			err("%s - failed to read answer", __FUNCTION__);			return (retval);		}	}	if (answer != 0xfe)	{		err("%s - CMD_17 failure", __FUNCTION__);		/* may be we must be patient and 		 * read_answer() more times */		return (-EPROTO);	}	dbg("%s - CMD_17 success", __FUNCTION__);	retval = qspi_read (MMC_DEVICE, block, 			MMC_BLOCK_SIZE * sizeof (unsigned char));	if (retval < 0)	{		err("%s - failed to read block", __FUNCTION__);		return (retval);	}	if (retval != MMC_BLOCK_SIZE)	{		err("%s - %d bytes read instead of %d", 				__FUNCTION__, retval, MMC_BLOCK_SIZE);	}	nb_bytes_read = retval;	/*  read the checksum (2 bytes) */	retval = qspi_read (MMC_DEVICE, (char *) &checksum, 			sizeof (unsigned short));	if (retval < 0)	{		err("%s - failed to read checksum", __FUNCTION__);		return (retval);	}	if (retval != sizeof (unsigned short))	{		err("%s - failed to read checksum", __FUNCTION__);		return (-EIO);	}	/* compute the block checksum and compare with 	 * the checksum send by the MMC */	block_crc = (unsigned short) crc16 (block, MMC_BLOCK_SIZE);	block_crc = __cpu_to_be16(block_crc); /* endianness */	if (block_crc != checksum)	{		err("%s - bad checksum : compute %d instead of %d", 				__FUNCTION__, 				block_crc,				checksum);		return (-EIO);	}	for (i = 0; i < DUMMY_NBR; i++)	{		retval = dummy_write ();		if (retval < 0)		{			err("%s - dummy_write() error", __FUNCTION__);			return (retval);		}	}	return (nb_bytes_read);}char *get_cid (void){	return (get_card_register (CMD_10));}char *get_csd (void){	return (get_card_register (CMD_9));}/* funcion who permit to read card register as the CSD (Card Specific Data)  * and the CID (Card Identification Data) */static char *get_card_register (unsigned int cmd){	char *reg;	int retval;	unsigned int count = 10;	unsigned char answer;	unsigned short csd_crc, checksum;	reg = (char *) kmalloc (REG_SIZE, GFP_KERNEL);	if (reg == NULL)		return (NULL);	retval = send_cmd (cmd, &answer);	if (retval < 0)	{		err("%s - failed to send command (%d)", 				__FUNCTION__, cmd);		return (NULL);	}	while (((answer & 0xff) != 0xfe) && (count--))	{		retval = read_answer (&answer);		if (retval < 0) 			return (NULL);	}	if (answer != 0xfe)	{		err("%s - failed to send command (%d)", 				__FUNCTION__, cmd);		return (NULL);	}	retval = qspi_read (MMC_DEVICE, reg, REG_SIZE);	if (retval != REG_SIZE)	{		return (NULL);	}	retval = qspi_read (MMC_DEVICE, (char *) &checksum, 			sizeof (unsigned short));	if (retval != sizeof (unsigned short))	{		err("%s - failed to read checksum", __FUNCTION__);		return (NULL);	}	/* compute the block checksum and compare with 	 * the checksum send by the MMC */	csd_crc = (unsigned short) crc16 (reg, REG_SIZE);	csd_crc = __cpu_to_be16(csd_crc); /* endianness */	if (csd_crc != checksum)	{		err("%s - bad checksum : compute %d instead of %d", 				__FUNCTION__, 				csd_crc,				checksum);		return (NULL);	}	return (reg);}/* function to initiate the MMC */int open_mmc (void){	int retval;	int i;	unsigned char kbuffer[10];	unsigned char answer;	int count = 10;		dbg("enter %s", __FUNCTION__);	/* in first, we must open the qspi device associate 	 * to the MMC */	retval = qspi_open (MMC_DEVICE);	if (retval < 0)	{		err("%s - qspi_open faillure", __FUNCTION__);		return (retval);	}		/* put the chip select MMC_DEVICE hight during the 	 * initialization */	retval = qspi_ioctl (MMC_DEVICE, CMD_CS_HIGHT, 0);	if (retval < 0)	{		err("%s - qspi_ioctl faillure", __FUNCTION__);		return (retval);	}	/* generate 80 clock cycle to initialize the	 * MMC card */	for (i = 0; i < 10; i++)	{		kbuffer[i] = 0xff;	}		retval = qspi_write (MMC_DEVICE, kbuffer, 10 * sizeof (unsigned char));	if (retval < 0)	{		err("%s - qspi_write faillure", __FUNCTION__);		return (retval);	}	if (retval < 10 * sizeof (unsigned char))	{		err("%s - only %d bytes send to the mmc instead of %d", 				__FUNCTION__, retval, 10);		return (-EIO);	}		/* put the chip select MMC_DEVICE low to transfert data */	retval = qspi_ioctl (MMC_DEVICE, CMD_CS_LOW, 0);	if (retval < 0)	{		err("%s - qspi_ioctl failure", __FUNCTION__);		return (retval);	}	/* send the CMD0 to set the MMC in qspi mode 	 * as the MMC is in MMC mode during the CMD0 sending, 	 * CMD0 must have a valid checksum */	do	{		retval = send_cmd (CMD_0, &answer);		if (retval < 0)		{			err("%s - failed to send CMD0", __FUNCTION__);			return (retval);		}		mdelay(100);	} 	while ((count--) && (answer != 0x01));		/* the MMC must acquit the CMD_0 with 0x01 */	if (answer != 0x01)	{		err("%s - CMD0 failure", __FUNCTION__);		return (-EPROTO);	}	count = 1000;	do	{		retval = dummy_write ();		if (retval < 0)		{			err("%s - dummy_write() error", __FUNCTION__);			return (retval);		}		retval = send_cmd (CMD_1, &answer);		if (retval < 0)		{			err("%s - failed to send CMD_1", __FUNCTION__);			return (retval);		}	} 	while ((count--) && (answer != 0x00));		retval = dummy_write ();	if (retval < 0)	{		err("%s - dummy_write () error", __FUNCTION__);		return (retval);	}		if (answer != 0x00)	{		err("%s - CMD_1 failure", __FUNCTION__);		return (-EPROTO);	}	info("%s - MMC init success", __FUNCTION__);	/* send command 59 to turn on the checksum control */	mmc_cmd_array[CMD_59].a4 = 1;	retval = send_cmd (CMD_59, &answer);	if (retval < 0)	{		err("%s - failed to send CMD_59", __FUNCTION__);		return (retval);	}	if (answer != 0x00)	{		err("%s - CMD_59 failure (answer = 0x%x)", 				__FUNCTION__, answer & 0xff);		/* may be we must be patient and 		 * read_answer() more times */		return (-EPROTO);	}	return (0);}/* method to release the MMC device */int release_mmc (void){	int retval;		retval = qspi_close (MMC_DEVICE);	if (retval < 0)	{		err("%s - qspi_close faillure", __FUNCTION__);	}	else	{		info("%s success to release the MMC", __FUNCTION__);	}	return (retval);}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
久久久久国产成人精品亚洲午夜| 欧美日韩一级大片网址| 777a∨成人精品桃花网| 亚洲成av人片一区二区三区| 91丨porny丨蝌蚪视频| 日韩美女视频一区| 91麻豆国产福利精品| 一区二区三区在线不卡| 欧美偷拍一区二区| 日韩影视精彩在线| 91精品国产综合久久久久久漫画 | 日韩欧美激情四射| 免费精品视频在线| 久久久久久久久一| 不卡av在线免费观看| 亚洲精品五月天| 91麻豆精品国产综合久久久久久| 青椒成人免费视频| 久久影院午夜论| 成人免费黄色在线| 亚洲影院免费观看| 欧美一级xxx| 成人高清在线视频| 亚洲综合一二区| 精品粉嫩超白一线天av| 99在线热播精品免费| 日韩欧美一区二区三区在线| 国产美女精品一区二区三区| 2023国产一二三区日本精品2022| 国产一区999| 亚洲精品日韩综合观看成人91| 欧美精品一二三区| 成人视屏免费看| 亚洲国产精品人人做人人爽| 久久蜜臀精品av| 在线视频欧美精品| 国产黄色成人av| 亚洲电影你懂得| 日韩欧美国产综合在线一区二区三区| 国产在线精品一区二区不卡了| 日韩美女视频一区| 69p69国产精品| 成人av资源网站| 看电影不卡的网站| 中文字幕人成不卡一区| 91精品在线麻豆| 色婷婷亚洲综合| 国产v日产∨综合v精品视频| 亚洲一二三专区| 欧美不卡一二三| 欧美性受xxxx黑人xyx性爽| 激情文学综合网| 亚洲6080在线| 亚洲色图欧美在线| 久久影院视频免费| 欧美丰满少妇xxxxx高潮对白| 99精品久久久久久| 丁香婷婷综合色啪| 日本系列欧美系列| 亚洲欧美日韩国产综合| 中国色在线观看另类| 日韩精品中文字幕一区| 欧美色图片你懂的| 色狠狠桃花综合| 99精品国产视频| 国产69精品久久久久777| 激情久久久久久久久久久久久久久久| 午夜精品久久久久久久久| 久久久精品蜜桃| 欧美一级免费观看| 777午夜精品视频在线播放| 一本色道久久综合亚洲精品按摩| 国产超碰在线一区| 日韩和欧美一区二区| 最近日韩中文字幕| 成人免费一区二区三区在线观看| 国产欧美一区二区三区沐欲| 久久精品亚洲精品国产欧美 | 国产乱码精品一区二区三区av| 蜜臀av一区二区| 日韩在线播放一区二区| 亚洲sss视频在线视频| 日韩国产精品91| 青青草国产成人av片免费| 免费人成网站在线观看欧美高清| 日本不卡的三区四区五区| 美女诱惑一区二区| 青娱乐精品视频| 蜜桃视频一区二区三区| 精品一区二区三区日韩| 国内精品久久久久影院色 | 久久久久久一级片| 久久久无码精品亚洲日韩按摩| 欧美精品一区二区三区视频| 日韩欧美国产系列| 欧美一区二区精美| 日韩视频一区在线观看| 久久综合久久久久88| 国产欧美一区二区三区鸳鸯浴| 欧美韩国日本不卡| 亚洲色图另类专区| 日韩激情视频在线观看| 国内精品伊人久久久久av一坑| 成人高清伦理免费影院在线观看| 97精品国产露脸对白| av日韩在线网站| 在线观看三级视频欧美| 7777精品伊人久久久大香线蕉最新版| 欧美一区二区在线免费播放| 久久综合色8888| 亚洲麻豆国产自偷在线| 日韩中文字幕一区二区三区| 国产在线视视频有精品| 93久久精品日日躁夜夜躁欧美| 欧美日韩一区视频| 日韩欧美专区在线| 国产精品人人做人人爽人人添| 亚洲电影中文字幕在线观看| caoporn国产一区二区| 婷婷中文字幕综合| 国产一区二区三区四区五区入口| 成人动漫av在线| 欧美男女性生活在线直播观看 | 精品国产麻豆免费人成网站| 国产精品初高中害羞小美女文| 亚洲国产日韩一级| 国产经典欧美精品| 欧美色图免费看| 久久美女高清视频| 一二三区精品福利视频| 国产一区二区三区av电影| 色综合久久综合中文综合网| 精品奇米国产一区二区三区| 一区二区三区在线视频观看58| 久久国产剧场电影| 欧美亚洲国产怡红院影院| 久久久久久久久久久久久夜| 亚洲一区二区三区四区的| 国产高清无密码一区二区三区| 欧美日韩国产另类不卡| 亚洲欧洲av色图| 国产精品羞羞答答xxdd| 91超碰这里只有精品国产| 亚洲素人一区二区| 国产91综合一区在线观看| 欧美一区二区三区爱爱| 一区二区三区中文在线| 成人99免费视频| 久久精品视频一区二区| 婷婷综合另类小说色区| 欧美午夜精品一区二区三区| 国产精品卡一卡二卡三| 国产精品888| 精品国产一区二区三区久久久蜜月 | 麻豆精品久久精品色综合| 欧美在线视频全部完| 中文字幕欧美区| 国产乱码一区二区三区| 欧美日韩免费视频| 亚洲丝袜精品丝袜在线| 国产91高潮流白浆在线麻豆| 亚洲精品一区二区三区在线观看| 亚洲成在线观看| 国产精品久久久久久久久免费樱桃| 久久精品夜色噜噜亚洲aⅴ| 日韩不卡在线观看日韩不卡视频| 欧美性色综合网| 亚洲国产综合在线| 欧美无乱码久久久免费午夜一区| 亚洲视频免费在线观看| 91麻豆国产福利精品| 成人欧美一区二区三区小说 | 韩国欧美国产1区| 日韩欧美在线一区二区三区| 三级亚洲高清视频| 8x福利精品第一导航| 亚洲福利视频一区二区| 91精品国产乱码| 美女视频黄久久| 久久亚洲精品国产精品紫薇| 日韩精品高清不卡| 欧美精品久久99久久在免费线| 国产精品不卡在线观看| 91免费看视频| 性久久久久久久久| 制服丝袜亚洲网站| 久久精品国产亚洲5555| 欧美成人在线直播| 国产成人久久精品77777最新版本| 中文字幕二三区不卡| 99久久精品国产麻豆演员表| 国产精品夫妻自拍| kk眼镜猥琐国模调教系列一区二区| 国产精品美女久久久久久久| 91在线视频免费91| 午夜精品福利久久久| 精品噜噜噜噜久久久久久久久试看| 国产精品一区二区免费不卡 | 欧美国产精品一区二区三区| av不卡一区二区三区|