[PATCH] add-types.h-files-and-change-something-try-make-glamo-mmc.c-can-compile

xiangfu xiangfu at openmoko.org
Tue Aug 19 18:53:40 CEST 2008


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

add a file types.h , i see there some some "typedef unsigned char uchar"
in  files :-)
and add some struct into glamo-mmc.h that glamo-mmc.c need.
try to make glamo-mmc.c can compile  but there still have some problem!

Hi Andy  Matt
you work so fast :-) and many things i don't understand. :-)

- ---
 include/qi.h            |    5 +-
 include/types.h         |   17 +++++++
 src/calc_pclk.c         |    4 +-
 src/calc_pclk.h         |   27 +++++++++++
 src/drivers/glamo-mmc.c |   81 +++++++++++++++++-----------------
 src/drivers/glamo-mmc.h |  110
+++++++++++++++++++++++++++++++++++++++++++++++
 src/part.h              |    3 +-
 7 files changed, 202 insertions(+), 45 deletions(-)
 create mode 100644 include/types.h
 create mode 100644 src/calc_pclk.h

diff --git a/include/qi.h b/include/qi.h
index b168ae7..7fb4862 100644
- --- a/include/qi.h
+++ b/include/qi.h
@@ -23,12 +23,13 @@

 #include <stdarg.h>
 #include <qi-ctype.h>
- -
+#include <types.h>
+/*
 #define u32 unsigned int
 #define u16 unsigned short
 #define u8 unsigned char
 typedef unsigned int uint32_t;
- -
+*/
 #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))

 enum filesystem {
diff --git a/include/types.h b/include/types.h
new file mode 100644
index 0000000..ba56535
- --- /dev/null
+++ b/include/types.h
@@ -0,0 +1,17 @@
+#ifndef __TYPES_H__
+#define __TYPES_H__
+
+typedef unsigned char	uchar;
+typedef unsigned char	uint8_t;
+/* typedef unsigned long   uint64_t; */
+typedef unsigned short	ushort;
+typedef unsigned short  u_int16_t;
+typedef unsigned short  u16;
+typedef unsigned char   u8;
+typedef unsigned int    uint32_t;
+typedef unsigned int    u32;
+
+typedef unsigned long	ulong;
+typedef ulong lbaint_t;
+
+#endif
diff --git a/src/calc_pclk.c b/src/calc_pclk.c
index 777ad03..1659d2c 100644
- --- a/src/calc_pclk.c
+++ b/src/calc_pclk.c
@@ -23,6 +23,8 @@
  * is already show in other files
  */

+# include "calc_pclk.h"
+
 # define CLKDIVN_val    (7)
 # define CAMDIVN_val    (0)
 # define CONFIG_SYS_CLK_FREQ  (12000000)/* the GTA02 has this input
clock */
@@ -30,8 +32,6 @@
 # define MPLL    ((142 << 12) + (7 << 4) + 1)
 # define BAUDRATE    	(115200)

- -typedef unsigned long   ulong;
- -
 static ulong get_PLLCLK(int pllreg)
 {
   ulong r, m, p, s;
diff --git a/src/calc_pclk.h b/src/calc_pclk.h
new file mode 100644
index 0000000..80b8c7d
- --- /dev/null
+++ b/src/calc_pclk.h
@@ -0,0 +1,27 @@
+/*
+ * (C) Copyright 2007 OpenMoko, Inc.
+ * Author: xiangfu liu <xiangfu at openmoko.org>
+ *
+ *
+ * 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 the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+#ifndef __CALC_PCLK_H__
+#define __CALC_PCLK_H__
+
+#include <types.h>
+ulong get_PCLK(void);
+
+#endif
diff --git a/src/drivers/glamo-mmc.c b/src/drivers/glamo-mmc.c
index b010235..2122828 100644
- --- a/src/drivers/glamo-mmc.c
+++ b/src/drivers/glamo-mmc.c
@@ -1,5 +1,5 @@
 /*
- - *  linux/drivers/mmc/host/glamo-mmc.c - Glamo MMC driver
+ *  Glamo MMC driver
  *
  *  Copyright (C) 2007 OpenMoko, Inc,  Andy Green <andy at openmoko.com>
  *  Based on the Glamo MCI driver that was -->
@@ -26,18 +26,19 @@
  */

 #if 0
- -
+/*
 #include <config.h>
- -#include <common.h>
- -#include <mmc.h>
 #include <asm/errno.h>
 #include <asm/io.h>
- -#include <part.h>
 #include <fat.h>
 #include <pcf50633.h>
+#include <common.h>
+*/

+#include "../part.h"
 #include "glamo-regs.h"
 #include "glamo-mmc.h"
+#include "../serial.h"

 #define MMC_BLOCK_SIZE_BITS 9
 #define MMC_BLOCK_SIZE (1 << MMC_BLOCK_SIZE_BITS)
@@ -318,8 +319,8 @@ static int mmc_cmd(int opcode, int arg, int flags,
 		return 0;

 	if (error) {
- -		printf("cmd 0x%x, arg 0x%x flags 0x%x\n", opcode, arg, flags);
- -		printf("Error after cmd: 0x%x\n", error);
+		printk("cmd 0x%x, arg 0x%x flags 0x%x\n", opcode, arg, flags);
+		printk("Error after cmd: 0x%x\n", error);
 		goto done;
 	}
 	/*
@@ -357,8 +358,8 @@ static int mmc_cmd(int opcode, int arg, int flags,
 	if (status & GLAMO_STAT1_MMC_RTOUT)
 		error = -5;
 	if (error) {
- -		printf("cmd 0x%x, arg 0x%x flags 0x%x\n", opcode, arg, flags);
- -		printf("Error after resp: 0x%x\n", status);
+		printk("cmd 0x%x, arg 0x%x flags 0x%x\n", opcode, arg, flags);
+		printk("Error after resp: 0x%x\n", status);
 		goto done;
 	}
 #if 0
@@ -413,12 +414,12 @@ int mmc_read(ulong src, uchar *dst, int size)
 	int size_original = size;

 	if ((!size) || (size & (MMC_BLOCK_SIZE - 1))) {
- -		printf("Bad size %d\n", size);
+		printk("Bad size %d\n", size);
 		return 0;
 	}

 	if (((int)dst) & 1) {
- -		printf("Bad align on dst\n");
+		printk("Bad align on dst\n");
 		return 0;
 	}

@@ -461,12 +462,12 @@ int mmc_write(uchar *src, ulong dst, int size)
 	int size_original = size;

 	if ((!size) || (size & (MMC_BLOCK_SIZE - 1))) {
- -		printf("Bad size %d\n", size);
+		printk("Bad size %d\n", size);
 		return 0;
 	}

 	if (((int)dst) & 1) {
- -		printf("Bad align on dst\n");
+		printk("Bad align on dst\n");
 		return 0;
 	}

@@ -505,50 +506,50 @@ int mmc_write(uchar *src, ulong dst, int size)

 static void print_mmc_cid(mmc_cid_t *cid)
 {
- -	printf("MMC found. Card desciption is:\n");
- -	printf("Manufacturer ID = %02x%02x%02x\n",
+	printk("MMC found. Card desciption is:\n");
+	printk("Manufacturer ID = %02x%02x%02x\n",
 		cid->id[0], cid->id[1], cid->id[2]);
- -	printf("HW/FW Revision = %x %x\n",cid->hwrev, cid->fwrev);
+	printk("HW/FW Revision = %x %x\n",cid->hwrev, cid->fwrev);
 	cid->hwrev = cid->fwrev = 0;	/* null terminate string */
- -	printf("Product Name = %s\n",cid->name);
- -	printf("Serial Number = %02x%02x%02x\n",
+	printk("Product Name = %s\n",cid->name);
+	printk("Serial Number = %02x%02x%02x\n",
 		cid->sn[0], cid->sn[1], cid->sn[2]);
- -	printf("Month = %d\n",cid->month);
- -	printf("Year = %d\n",1997 + cid->year);
+	printk("Month = %d\n",cid->month);
+	printk("Year = %d\n",1997 + cid->year);
 }

 static void print_sd_cid(const struct sd_cid *cid)
 {
- -	printf("Card Type:          ");
+	printk("Card Type:          ");
 	switch (card_type) {
 	case CARDTYPE_NONE:
- -		printf("(None)\n");
+		printk("(None)\n");
 		break;
 	case CARDTYPE_MMC:
- -		printf("MMC\n");
+		printk("MMC\n");
 		break;
 	case CARDTYPE_SD:
- -		printf("SD\n");
+		printk("SD\n");
 		break;
 	case CARDTYPE_SD20:
- -		printf("SD 2.0\n");
+		printk("SD 2.0\n");
 		break;
 	case CARDTYPE_SDHC:
- -		printf("SD 2.0 SDHC\n");
+		printk("SD 2.0 SDHC\n");
 		break;
 	}
- -	printf("Manufacturer:       0x%02x, OEM \"%c%c\"\n",
+	printk("Manufacturer:       0x%02x, OEM \"%c%c\"\n",
 	    cid->mid, cid->oid_0, cid->oid_1);
- -	printf("Product name:       \"%c%c%c%c%c\", revision %d.%d\n",
+	printk("Product name:       \"%c%c%c%c%c\", revision %d.%d\n",
 	    cid->pnm_0, cid->pnm_1, cid->pnm_2, cid->pnm_3, cid->pnm_4,
 	    cid->prv >> 4, cid->prv & 15);
- -	printf("Serial number:      %u\n",
+	printk("Serial number:      %u\n",
 	    cid->psn_0 << 24 | cid->psn_1 << 16 | cid->psn_2 << 8 |
 	    cid->psn_3);
- -	printf("Manufacturing date: %d/%d\n",
+	printk("Manufacturing date: %d/%d\n",
 	    cid->mdt_1 & 15,
 	    2000+((cid->mdt_0 & 15) << 4)+((cid->mdt_1 & 0xf0) >> 4));
- -/*	printf("CRC:                0x%02x, b0 = %d\n",
+/*	printk("CRC:                0x%02x, b0 = %d\n",
 	    cid->crc >> 1, cid->crc & 1); */
 }

@@ -655,7 +656,7 @@ int mmc_init(int verbose)

 	if (card_type == CARDTYPE_NONE) {
 		retries = 10;
- -		printf("failed to detect SD Card, trying MMC\n");
+		printk("failed to detect SD Card, trying MMC\n");
 		do {
 			resp = mmc_cmd(MMC_SEND_OP_COND, 0x00ffc000,
 				       MMC_CMD_BCR | MMC_RSP_R3, 0, 0, 0,
@@ -694,12 +695,12 @@ int mmc_init(int verbose)

 		if (verbose)
 			print_mmc_cid(mmc_cid);
- -		sprintf((char *) mmc_dev.vendor,
+		sprintk((char *) mmc_dev.vendor,
 			"Man %02x%02x%02x Snr %02x%02x%02x",
 			mmc_cid->id[0], mmc_cid->id[1], mmc_cid->id[2],
 			mmc_cid->sn[0], mmc_cid->sn[1], mmc_cid->sn[2]);
- -		sprintf((char *) mmc_dev.product, "%s", mmc_cid->name);
- -		sprintf((char *) mmc_dev.revision, "%x %x",
+		sprintk((char *) mmc_dev.product, "%s", mmc_cid->name);
+		sprintk((char *) mmc_dev.revision, "%x %x",
 			mmc_cid->hwrev, mmc_cid->fwrev);

 		/* MMC exists, get CSD too */
@@ -713,15 +714,15 @@ int mmc_init(int verbose)
 	case CARDTYPE_SDHC:
 		if (verbose)
 			print_sd_cid(sd_cid);
- -		sprintf((char *) mmc_dev.vendor,
+		sprintk((char *) mmc_dev.vendor,
 			"Man %02 OEM %c%c \"%c%c%c%c%c\"",
 			sd_cid->mid, sd_cid->oid_0, sd_cid->oid_1,
 			sd_cid->pnm_0, sd_cid->pnm_1, sd_cid->pnm_2,
 			sd_cid->pnm_3, sd_cid->pnm_4);
- -		sprintf((char *) mmc_dev.product, "%d",
+		sprintk((char *) mmc_dev.product, "%d",
 			sd_cid->psn_0 << 24 | sd_cid->psn_1 << 16 |
 			sd_cid->psn_2 << 8 | sd_cid->psn_3);
- -		sprintf((char *) mmc_dev.revision, "%d.%d",
+		sprintk((char *) mmc_dev.revision, "%d.%d",
 			sd_cid->prv >> 4, sd_cid->prv & 15);

 		resp = mmc_cmd(SD_SEND_RELATIVE_ADDR, MMC_DEFAULT_RCA,
@@ -746,13 +747,13 @@ int mmc_init(int verbose)
 		rc = 0;
 		mmc_ready = 1;
 		/* FIXME add verbose printout for csd */
- -		/* printf("READ_BL_LEN=%u, C_SIZE_MULT=%u, C_SIZE=%u\n",
+		/* printk("READ_BL_LEN=%u, C_SIZE_MULT=%u, C_SIZE=%u\n",
 			csd->read_bl_len, csd->c_size_mult1,
 			csd->c_size); */
 		mmc_dev.blksz = 512;
 		mmc_dev.lba = (((unsigned long)1 << csd->c_size_mult1) *
 				(unsigned long)csd->c_size) >> 9;
- -		printf("MMC/SD size:        %dMiB\n", mmc_dev.lba >> 1);
+		printk("MMC/SD size:        %dMiB\n", mmc_dev.lba >> 1);
 	}

 	resp = mmc_cmd(MMC_SELECT_CARD, rca<<16, MMC_CMD_AC | MMC_RSP_R1,
diff --git a/src/drivers/glamo-mmc.h b/src/drivers/glamo-mmc.h
index 3f2294c..82f192a 100644
- --- a/src/drivers/glamo-mmc.h
+++ b/src/drivers/glamo-mmc.h
@@ -1,6 +1,111 @@
 #ifndef __GLAMO_MMC_H__
 #define __GLAMO_MMC_H__

+#include <types.h>
+
+/* this is the glamo-mmc.c need i copy from uboot files */
+#define CONFIG_GLAMO_BASE	0x08000000
+#define ENODEV		19/* No such device */
+#define CFG_MMC_BASE  	0xff000000
+/* this is the glamo-mmc.c need i copy from uboot files */
+
+/* copy from  include/asm-arm/arch-s3c24x0 */
+#define MMC_DEFAULT_RCA			(1<<16)
+
+/* #define MMC_BLOCK_SIZE			512 */
+#define MMC_CMD_RESET			0
+#define MMC_CMD_SEND_OP_COND		1
+#define MMC_CMD_ALL_SEND_CID 		2
+#define MMC_CMD_SET_RCA			3
+#define MMC_CMD_SELECT_CARD		7
+#define MMC_CMD_SEND_CSD 		9
+#define MMC_CMD_SEND_CID 		10
+#define MMC_CMD_SEND_STATUS		13
+#define MMC_CMD_SET_BLOCKLEN		16
+#define MMC_CMD_READ_BLOCK		17
+#define MMC_CMD_RD_BLK_MULTI		18
+#define MMC_CMD_WRITE_BLOCK		24
+
+#define MMC_MAX_BLOCK_SIZE		512
+
+#define MMC_R1_IDLE_STATE		0x01
+#define MMC_R1_ERASE_STATE		0x02
+#define MMC_R1_ILLEGAL_CMD		0x04
+#define MMC_R1_COM_CRC_ERR		0x08
+#define MMC_R1_ERASE_SEQ_ERR		0x01
+#define MMC_R1_ADDR_ERR			0x02
+#define MMC_R1_PARAM_ERR		0x04
+
+#define MMC_R1B_WP_ERASE_SKIP		0x0002
+#define MMC_R1B_ERR			0x0004
+#define MMC_R1B_CC_ERR			0x0008
+#define MMC_R1B_CARD_ECC_ERR		0x0010
+#define MMC_R1B_WP_VIOLATION		0x0020
+#define MMC_R1B_ERASE_PARAM		0x0040
+#define MMC_R1B_OOR			0x0080
+#define MMC_R1B_IDLE_STATE		0x0100
+#define MMC_R1B_ERASE_RESET		0x0200
+#define MMC_R1B_ILLEGAL_CMD		0x0400
+#define MMC_R1B_COM_CRC_ERR		0x0800
+#define MMC_R1B_ERASE_SEQ_ERR		0x1000
+#define MMC_R1B_ADDR_ERR		0x2000
+#define MMC_R1B_PARAM_ERR		0x4000
+
+typedef struct mmc_cid
+{
+	/* FIXME: BYTE_ORDER */
+	uchar	year:4,
+		month:4;
+	uchar	sn[3];
+	uchar	fwrev:4,
+		hwrev:4;
+	uchar	name[6];
+	uchar	id[3];
+} mmc_cid_t;
+
+typedef struct mmc_csd
+{
+	uchar	ecc:2,
+		file_format:2,
+		tmp_write_protect:1,
+		perm_write_protect:1,
+		copy:1,
+		file_format_grp:1;
+	unsigned short content_prot_app:1,
+/*	uint64_t content_prot_app:1, */
+		rsvd3:4,
+		write_bl_partial:1,
+		write_bl_len:4,
+		r2w_factor:3,
+		default_ecc:2,
+		wp_grp_enable:1,
+		wp_grp_size:5,
+		erase_grp_mult:5,
+		erase_grp_size:5,
+		c_size_mult1:3,
+		vdd_w_curr_max:3,
+		vdd_w_curr_min:3,
+		vdd_r_curr_max:3,
+		vdd_r_curr_min:3,
+		c_size:12,
+		rsvd2:2,
+		dsr_imp:1,
+		read_blk_misalign:1,
+		write_blk_misalign:1,
+		read_bl_partial:1;
+
+	ushort	read_bl_len:4,
+		ccc:12;
+	uchar	tran_speed;
+	uchar	nsac;
+	uchar	taac;
+	uchar	rsvd1:2,
+  		spec_vers:4,
+		csd_structure:2;
+} mmc_csd_t;
+/* copy from  include/asm-arm/arch-s3c24x0 */
+
+
 /* Standard MMC commands (4.1)           type  argument     response */
    /* class 1 */
 #define MMC_GO_IDLE_STATE         0   /* bc                          */
@@ -146,4 +251,9 @@ enum card_type {
 };


+int mmc_init(int verbose);
+int mmc_read(ulong src, uchar *dst, int size);
+int mmc_write(uchar *src, ulong dst, int size);
+int mmc2info(ulong addr);
+
 #endif /* __GLAMO_MMC_H__ */
diff --git a/src/part.h b/src/part.h
index b22a637..98b0703 100644
- --- a/src/part.h
+++ b/src/part.h
@@ -23,7 +23,8 @@
 #ifndef _PART_H
 #define _PART_H

- -#include <ide.h>
+/*#include <ide.h> */
+#include <types.h>

 typedef struct block_dev_desc {
 	int		if_type;	/* type of the interface */
- --
1.5.5
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iQEVAwUBSKr6kxFuNemPXNFjAQJUSAf7Bn4YYQvUhyoupRweKGZmUGRB8tY9SVTl
9qrfr82EiDqJuucsGTYwdr3E2tfP/hGQfUkd/1viNK+qFllNZhF+Vri2+WHzYO4l
6hrWoy7z5FovbhA7bNy7lR4LJBVlPIUos7n+McGZfYMh0DMerRGtdak3P8azjCKJ
3ugu9T058Du5dbm+nVlk8GMWXZ+wRL6djdXIVaJy6UUrgT/G6nTnFkj3YZbqq5qP
CPWbrUoTSbQhL3h8k172fWv6HzMGhZ/fSEPeeqrAkqMagbMovY7W0buyoYjyftuP
nPlZwRLcqSoxjNSQzqS88gT5jLmUHEO1uNBwJrWHDHGOqcK6oEZZdQ==
=vdrT
-----END PGP SIGNATURE-----



More information about the openmoko-kernel mailing list