Add S3C2410 MMC/SD support
PATCH 1/1 Add S3C2410 MMC/SD support
This patch adds MMC/SD support to the S3C2410 SoC code in u-boot
cpu/arm920t/s3c24x0/Makefile +1 -1
@@ -26,7 +26,7 @@ LIB = $(obj)lib$(SOC).a COBJS = i2c.o interrupts.o serial.o speed.o \ - usb_ohci.o nand_read.o nand.o cmd_s3c2410.o + usb_ohci.o nand_read.o nand.o mmc.o cmd_s3c2410.o SRCS := $(SOBJS:.o=.S) $(COBJS:.o=.c) OBJS := $(addprefix $(obj),$(SOBJS) $(COBJS))
cpu/arm920t/s3c24x0/mmc.c new file +504 -0
504 lines not on this page · raw message
include/asm-arm/arch-s3c24x0/mmc.h new file +112 -0
112 lines not on this page · raw message
include/asm-arm/arch-s3c24x0/regs-sdi.h new file +110 -0
110 lines not on this page · raw message
include/s3c24x0.h +2 -12
@@ -637,13 +637,7 @@S3C24X0_REG32 SDIDCNT ;S3C24X0_REG32 SDIDSTA ;S3C24X0_REG32 SDIFSTA ; -#ifdef __BIG_ENDIAN -S3C24X0_REG8 res[3 ]; -S3C24X0_REG8 SDIDAT ; -#else -S3C24X0_REG8 SDIDAT ; -S3C24X0_REG8 res[3 ]; -#endif +S3C24X0_REG32 SDIDAT ;S3C24X0_REG32 SDIIMSK ; }/*__attribute__((__packed__))*/ S3C2410_SDI ;
@@ -1123,11 +1117,7 @@#define rSDIDatCnt (*(volatile unsigned *)0x5A000030)#define rSDIDatSta (*(volatile unsigned *)0x5A000034)#define rSDIFSTA (*(volatile unsigned *)0x5A000038) -#ifdef __BIG_ENDIAN -#define rSDIDAT (*(volatile unsigned char *)0x5A00003F) -#else -#define rSDIDAT (*(volatile unsigned char *)0x5A00003C) -#endif +#define rSDIDAT (*(volatile unsigned *)0x5A00003C)#define rSDIIntMsk (*(volatile unsigned *)0x5A000040)#endif
Signature · 3 lines
- Harald Welte <[email protected]> http://openmoko.org/ ============================================================================ Software for the world's first truly open Free Software mobile phone
PATCH 1/1 Add S3C2410 MMC/SD support
cpu/arm920t/s3c24x0/mmc.c line 446
Quoted 5 lines · Harald Welte
This patch adds MMC/SD support to the S3C2410 SoC code in u-boot
cpu/arm920t/s3c24x0/mmc.c new file +3
-0+/* FIXME fill in the correct size (is set to 32MByte) */ + mmc_dev.blksz =512 ; + mmc_dev.lba =0x10000 ;
So...what happens if the card really isn't exactly 32 MB?
include/asm-arm/arch-s3c24x0/mmc.h 2007-02-16 23:42:19.000000000 +0100 line 2
Quoted 7 lines
Index:
u-boot/include/asm-arm/arch-s3c24x0/mmc.h
===================================================================include/asm-arm/arch-s3c24x0/mmc.h 2007-02-16 23:42:19.000000000 +0100 renamed from dev/null 1970-01-01 00:00:00.000000000 +0000 +2
-0@@ -0,0 +1,112 @@ +/* + * linux/drivers/mmc/mmc_pxa.h
This looks like it's been copied from pxa with few modifications ;)
I wonder if we could perhaps create a common header file for the mmc protocol definitions instead of duplicating them all over the place? This file consists entirely of constants and data structures from the MMC spec, and isn't really arch-specific at all.
I have a patch that adds support for the mmc controller on the AT32AP7000 chip, and which adds the exact same definitions all over again to the AVR32 include directory. The same driver should work on several AT91 chips, which means that we need to add them to the at91rm9200 and at91sam926x directories too.
Or we could just move everything to a common file and be done with it...
Haavard
PATCH 1/1 Add S3C2410 MMC/SD support
Quoted 8 lines · Haavard Skinnemoen
cpu/arm920t/s3c24x0/mmc.c line 446
Quoted 5 lines · Harald Welte
This patch adds MMC/SD support to the S3C2410 SoC code in u-boot
cpu/arm920t/s3c24x0/mmc.c new file +3
-0+/* FIXME fill in the correct size (is set to 32MByte) */ + mmc_dev.blksz =512 ; + mmc_dev.lba =0x10000 ;So...what happens if the card really isn't exactly 32 MB?
nothing really. I've used up to 1GB cards so far. Just the size indication printed is wrong. Yes, this is ugly. I should either remove printing the size, or implement it correctly.
Quoted 1 line
This looks like it's been copied from pxa with few modifications ;)
indeed.
Quoted 5 lines
I wonder if we could perhaps create a common header file for the mmc protocol definitions instead of duplicating them all over the place? This file consists entirely of constants and data structures from the MMC spec, and isn't really arch-specific at all.
Quoted 7 lines
I have a patch that adds support for the mmc controller on the AT32AP7000 chip, and which adds the exact same definitions all over again to the AVR32 include directory. The same driver should work on several AT91 chips, which means that we need to add them to the at91rm9200 and at91sam926x directories too.
Or we could just move everything to a common file and be done with it...
will do so in the next version of the patch.
Signature · 3 lines
- Harald Welte <[email protected]> http://openmoko.org/ ============================================================================ Software for the world's first truly open Free Software mobile phone
PATCH 1/1 Add S3C2410 MMC/SD support
Quoted 4 lines · In message <[email protected]> you wrote:
nothing really. I've used up to 1GB cards so far. Just the size indication printed is wrong. Yes, this is ugly. I should either remove printing the size, or implement it correctly.
Obviously "implement it correctly" is the correct thing to do :-)
Best regards,
Wolfgang Denk
Signature · 5 lines
DENX Software Engineering GmbH, HRB 165235 Munich, CEO: Wolfgang Denk Office: Kirchenstr. 5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de For those who like this sort of thing, this is the sort of thing they like. - Abraham Lincoln
PATCH 1/1 Add S3C2410 MMC/SD support
In reply to Harald WelteQuoted 10 lines
-----Original Message-----
From: u-boot-users-bounces at lists.sourceforge.net [mailto:u-boot-users-bounces at lists.sourceforge.net] On Behalf Of Harald Welte
Sent: 17 February 2007 11:19
To: Haavard Skinnemoen
Quoted 3 lines
will do so in the next version of the patch.
Harald
Did you ever re-submit?
Regards
Peter
PATCH 1/1 Add S3C2410 MMC/SD support
In reply to Harald WelteHere are some comments after a quick review.
Cheers,
g.
Quoted 21 lines · Harald Welte
This patch adds MMC/SD support to the S3C2410 SoC code in u-boot
Signed-off-by Harald Welte <[email protected]>Index: u-boot/cpu/arm920t/s3c24x0/Makefile
===================================================================cpu/arm920t/s3c24x0/Makefile 2007-02-16 23:42:19.000000000 +0100 renamed from cpu/arm920t/s3c24x0/Makefile 2007-02-16 23:42:19.000000000 +0100 +1
-1@@ -26,7 +26,7 @@ LIB = $(obj)lib$(SOC).a COBJS = i2c.o interrupts.o serial.o speed.o \ - usb_ohci.o nand_read.o nand.o cmd_s3c2410.o + usb_ohci.o nand_read.o nand.o mmc.o cmd_s3c2410.o SRCS := $(SOBJS:.o=.S) $(COBJS:.o=.c) OBJS := $(addprefix $(obj),$(SOBJS) $(COBJS))Index:
u-boot/cpu/arm920t/s3c24x0/mmc.c
===================================================================
cpu/arm920t/s3c24x0/mmc.c 2007-02-16 23:43:28.000000000 +0100
Quoted 2 lines
cpu/arm920t/s3c24x0/mmc.c 2007-02-16 23:43:28.000000000 +0100 renamed from dev/null 1970-01-01 00:00:00.000000000 +0000 +2
-0+ +//#define MMC_DEBUG
C++ style comment; bad! :-)
cpu/arm920t/s3c24x0/mmc.c 2007-02-16 23:43:28.000000000 +0100
Quoted 6 lines
cpu/arm920t/s3c24x0/mmc.c 2007-02-16 23:43:28.000000000 +0100 renamed from dev/null 1970-01-01 00:00:00.000000000 +0000 +6
-0+ +#ifdef MMC_DEBUG +#define DEBUGP printf +#else +#define DEBUGP(x, args ...) do { } while(0) +#endif
Should really use the debug/debugX macros from common.h. To enable them for a single file, just add '#define DEBUG' at the top of the file before any #include statements.
I know this is done a lot in u-boot; but I think it should be avoided as much as possible; especially in new code.
cpu/arm920t/s3c24x0/mmc.c 2007-02-16 23:43:28.000000000 +0100
Quoted 5 lines
cpu/arm920t/s3c24x0/mmc.c 2007-02-16 23:43:28.000000000 +0100 renamed from dev/null 1970-01-01 00:00:00.000000000 +0000 +5
-0+ +static S3C2410_SDI *sdi; + +extern int +fat_register_device(block_dev_desc_t *dev_desc, int part_no);
External prototype in a .c file; bad practice. Include the correct header instead. If the prototype doesn't exist in a header included by the function implementation, then write a patch to add it.
Doing it this way means that the compiler cannot verify that your interface and implementation match.
Quoted 15 lines
cpu/arm920t/s3c24x0/mmc.c 2007-02-16 23:43:28.000000000 +0100 renamed from dev/null 1970-01-01 00:00:00.000000000 +0000 +15
-0+ +static block_dev_desc_t mmc_dev; + +block_dev_desc_t * mmc_get_dev(int dev) +{ + return ((block_dev_desc_t *)&mmc_dev); +} + +/* + * FIXME needs to read cid and csd info to determine block size + * and other parameters + */ +static uchar mmc_buf[MMC_BLOCK_SIZE]; +static mmc_csd_t mmc_csd; +static int mmc_ready = 0;
cpu/arm920t/s3c24x0/mmc.c 2007-02-16 23:43:28.000000000 +0100
Quoted 10 lines
cpu/arm920t/s3c24x0/mmc.c 2007-02-16 23:43:28.000000000 +0100 renamed from dev/null 1970-01-01 00:00:00.000000000 +0000 +10
-0+static int wide = 0; + + +#define CMD_F_RESP 0x01 +#define CMD_F_RESP_LONG 0x02 + +static u_int32_t * +/****************************************************/ +mmc_cmd(ushort cmd, ulong arg, ushort flags) +/****************************************************/
I'm not so fond of the style putting a comment line between the function name and the return type. I think they should be together. What does everyone else think?
Quoted 60 lines
cpu/arm920t/s3c24x0/mmc.c 2007-02-16 23:43:28.000000000 +0100 renamed from dev/null 1970-01-01 00:00:00.000000000 +0000 +60
-0+{ + static u_int32_t resp[5]; + ulong status; + int i; + + u_int32_t ccon, csta; + u_int32_t csta_rdy_bit = S3C2410_SDICMDSTAT_CMDSENT; + + memset(resp, 0, sizeof(resp)); + + DEBUGP("mmc_cmd CMD%d arg=0x%08x flags=%x\n", cmd, arg, flags); + + sdi->SDICSTA = 0xffffffff; + sdi->SDIDSTA = 0xffffffff; + sdi->SDIFSTA = 0xffffffff; + + sdi->SDICARG = arg; + + ccon = cmd & S3C2410_SDICMDCON_INDEX; + ccon |= S3C2410_SDICMDCON_SENDERHOST|S3C2410_SDICMDCON_CMDSTART; + + if (flags & CMD_F_RESP) { + ccon |= S3C2410_SDICMDCON_WAITRSP; + csta_rdy_bit = S3C2410_SDICMDSTAT_RSPFIN; /* 1 << 9 */ + } + + if (flags & CMD_F_RESP_LONG) + ccon |= S3C2410_SDICMDCON_LONGRSP; + + sdi->SDICCON = ccon; + + while (1) { + csta = sdi->SDICSTA; + if (csta & csta_rdy_bit) + break; + if (csta & S3C2410_SDICMDSTAT_CMDTIMEOUT) { + printf("===============> MMC CMD Timeout\n"); + sdi->SDICSTA |= S3C2410_SDICMDSTAT_CMDTIMEOUT; + break; + } + } + + DEBUGP("final MMC CMD status 0x%x\n", csta); + + sdi->SDICSTA |= csta_rdy_bit; + + if (flags & CMD_F_RESP) { + resp[0] = sdi->SDIRSP0; + resp[1] = sdi->SDIRSP1; + resp[2] = sdi->SDIRSP2; + resp[3] = sdi->SDIRSP3; + } + + return resp; +} + +#define FIFO_FILL(host) ((host->SDIFSTA & S3C2410_SDIFSTA_COUNTMASK) >> 2) + +static int +/****************************************************/
cpu/arm920t/s3c24x0/mmc.c 2007-02-16 23:43:28.000000000 +0100
Quoted 10 lines
cpu/arm920t/s3c24x0/mmc.c 2007-02-16 23:43:28.000000000 +0100 renamed from dev/null 1970-01-01 00:00:00.000000000 +0000 +10
-0+mmc_block_read(uchar *dst, ulong src, ulong len) +/****************************************************/ +{ + u_int32_t dcon, fifo; + u_int32_t *dst_u32 = (u_int32_t *)dst; + u_int32_t *resp; + + if (len == 0) { + return 0; + }
braces not necessary on single line conditionals
Quoted 30 lines
cpu/arm920t/s3c24x0/mmc.c 2007-02-16 23:43:28.000000000 +0100 renamed from dev/null 1970-01-01 00:00:00.000000000 +0000 +30
-0+ + DEBUGP("mmc_block_rd dst %lx src %lx len %d\n", (ulong)dst, src, len); + + /* set block len */ + resp = mmc_cmd(MMC_CMD_SET_BLOCKLEN, len, CMD_F_RESP); + sdi->SDIBSIZE = len; + + //sdi->SDIPRE = 0xff; + + /* setup data */ + dcon = (len >> 9) & S3C2410_SDIDCON_BLKNUM_MASK; + dcon |= S3C2410_SDIDCON_BLOCKMODE; + dcon |= S3C2410_SDIDCON_RXAFTERCMD|S3C2410_SDIDCON_XFER_RXSTART; + if (wide) + dcon |= S3C2410_SDIDCON_WIDEBUS; + sdi->SDIDCON = dcon; + + /* send read command */ + resp = mmc_cmd(MMC_CMD_READ_BLOCK, src, CMD_F_RESP); + + while (len > 0) { + u_int32_t sdidsta = sdi->SDIDSTA; + fifo = FIFO_FILL(sdi); + if (sdidsta & (S3C2410_SDIDSTA_FIFOFAIL| + S3C2410_SDIDSTA_CRCFAIL| + S3C2410_SDIDSTA_RXCRCFAIL| + S3C2410_SDIDSTA_DATATIMEOUT)) { + printf("mmc_block_read: err SDIDSTA=0x%08x\n", sdidsta); + return -EIO; + }
cpu/arm920t/s3c24x0/mmc.c 2007-02-16 23:43:28.000000000 +0100
Quoted 10 lines
cpu/arm920t/s3c24x0/mmc.c 2007-02-16 23:43:28.000000000 +0100 renamed from dev/null 1970-01-01 00:00:00.000000000 +0000 +10
-0+ + while (fifo--) { + //DEBUGP("dst_u32 = 0x%08x\n", dst_u32); + *(dst_u32++) = sdi->SDIDAT; + if (len >= 4) + len -= 4; + else { + len = 0; + break; + }
Seems a little verbose; what about something like this? for ( ; fifo && len > 0; fifo--, len += 4)
*(dst_u32++) = sdi->SDIDAT;
cpu/arm920t/s3c24x0/mmc.c 2007-02-16 23:43:28.000000000 +0100
Quoted 6 lines
cpu/arm920t/s3c24x0/mmc.c 2007-02-16 23:43:28.000000000 +0100 renamed from dev/null 1970-01-01 00:00:00.000000000 +0000 +6
-0+ } + } + + DEBUGP("waiting for SDIDSTA (currently 0x%08x\n", sdi->SDIDSTA); + while (!(sdi->SDIDSTA & (1 << 4))) {} + DEBUGP("done waiting for SDIDSTA (currently 0x%08x\n", sdi->SDIDSTA);
Can/should this ever time out?
Should (1 << 4) be a #defined constant?
Quoted 20 lines
cpu/arm920t/s3c24x0/mmc.c 2007-02-16 23:43:28.000000000 +0100 renamed from dev/null 1970-01-01 00:00:00.000000000 +0000 +20
-0+int +/****************************************************/ +mmc_read(ulong src, uchar *dst, int size) +/****************************************************/ +{ + ulong end, part_start, part_end, part_len, aligned_start, aligned_end; + ulong mmc_block_size, mmc_block_address; + + if (size == 0) { + return 0; + } + + if (!mmc_ready) { + printf("Please initialize the MMC first\n"); + return -1; + } + + mmc_block_size = MMC_BLOCK_SIZE; + mmc_block_address = ~(mmc_block_size - 1); +
cpu/arm920t/s3c24x0/mmc.c 2007-02-16 23:43:28.000000000 +0100
Quoted 10 lines
cpu/arm920t/s3c24x0/mmc.c 2007-02-16 23:43:28.000000000 +0100 renamed from dev/null 1970-01-01 00:00:00.000000000 +0000 +10
-0+ src -= CFG_MMC_BASE; + end = src + size; + part_start = ~mmc_block_address & src; + part_end = ~mmc_block_address & end; + aligned_start = mmc_block_address & src; + aligned_end = mmc_block_address & end; + + /* all block aligned accesses */ + DEBUGP("src %lx dst %lx end %lx pstart %lx pend %lx astart %lx aend %lx\n", + src, (ulong)dst, end, part_start, part_end, aligned_start, aligned_end);
This long debug statement appears a lot; should it be a macro?
Quoted 6 lines
Index:
u-boot/include/asm-arm/arch-s3c24x0/mmc.h
===================================================================include/asm-arm/arch-s3c24x0/mmc.h 2007-02-16 23:42:19.000000000 +0100 renamed from dev/null 1970-01-01 00:00:00.000000000 +0000 +2
-0+ +typedef struct mmc_cid
include/asm-arm/arch-s3c24x0/mmc.h 2007-02-16 23:42:19.000000000 +0100
Quoted 10 lines
include/asm-arm/arch-s3c24x0/mmc.h 2007-02-16 23:42:19.000000000 +0100 renamed from dev/null 1970-01-01 00:00:00.000000000 +0000 +10
-0+{ +/* 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;
- Inconsistent line spacing
- Bit fields are non-portable (but that might not matter for this code)
Quoted 30 lines
include/asm-arm/arch-s3c24x0/mmc.h 2007-02-16 23:42:19.000000000 +0100 renamed from dev/null 1970-01-01 00:00:00.000000000 +0000 +30
-0+ +typedef struct mmc_csd +{ + uchar ecc:2, + file_format:2, + tmp_write_protect:1, + perm_write_protect:1, + copy:1, + file_format_grp: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;
include/asm-arm/arch-s3c24x0/mmc.h 2007-02-16 23:42:19.000000000 +0100
Quoted 10 lines
include/asm-arm/arch-s3c24x0/mmc.h 2007-02-16 23:42:19.000000000 +0100 renamed from dev/null 1970-01-01 00:00:00.000000000 +0000 +10
-0+ + 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;
Ditto here
Quoted 8 lines
include/asm-arm/arch-s3c24x0/mmc.h 2007-02-16 23:42:19.000000000 +0100 renamed from dev/null 1970-01-01 00:00:00.000000000 +0000 +3
-0+ + +#endif /* __MMC_PXA_P_H__ */Index:
u-boot/include/s2c24x0.h
===================================================================
include/s3c24x0.h 2007-02-16 23:42:19.000000000 +0100 line 646
Quoted 10 lines
include/s3c24x0.h 2007-02-16 23:42:19.000000000 +0100 renamed from include/s3c24x0.h 2007-02-16 23:42:02.000000000 +0100 +0
-7@@ -637,13 +637,7 @@ S3C24X0_REG32 SDIDCNT; S3C24X0_REG32 SDIDSTA; S3C24X0_REG32 SDIFSTA; -#ifdef __BIG_ENDIAN - S3C24X0_REG8 res[3]; - S3C24X0_REG8 SDIDAT; -#else - S3C24X0_REG8 SDIDAT; - S3C24X0_REG8 res[3]; -#endif
Is this a bug fix? If so, it should go in another patch with an appropriate description
Quoted 5 lines
include/s3c24x0.h 2007-02-16 23:42:19.000000000 +0100 renamed from include/s3c24x0.h 2007-02-16 23:42:02.000000000 +0100 +1
-0+ S3C24X0_REG32 SDIDAT; S3C24X0_REG32 SDIIMSK; } /*__attribute__((__packed__))*/ S3C2410_SDI;
include/s3c24x0.h 2007-02-16 23:42:19.000000000 +0100 line 1120
Quoted 9 lines
include/s3c24x0.h 2007-02-16 23:42:19.000000000 +0100 renamed from include/s3c24x0.h 2007-02-16 23:42:02.000000000 +0100 +1
-5@@ -1123,11 +1117,7 @@ #define rSDIDatCnt (*(volatile unsigned *)0x5A000030) #define rSDIDatSta (*(volatile unsigned *)0x5A000034) #define rSDIFSTA (*(volatile unsigned *)0x5A000038) -#ifdef __BIG_ENDIAN -#define rSDIDAT (*(volatile unsigned char *)0x5A00003F) -#else -#define rSDIDAT (*(volatile unsigned char *)0x5A00003C) -#endif +#define rSDIDAT (*(volatile unsigned *)0x5A00003C)
Ditto
Cheers,
g.
Signature · 4 lines
Grant Likely, B.Sc. P.Eng. Secret Lab Technologies Ltd. grant.likely at secretlab.ca (403) 399-0195
PATCH 1/1 Add S3C2410 MMC/SD support
Quoted 1 line · Grant Likely
Here are some comments after a quick review.
And some more...
<snip>
Quoted 8 lines
cpu/arm920t/s3c24x0/mmc.c line 73
Quoted 4 lines
cpu/arm920t/s3c24x0/mmc.c new file +4
-0+static u_int32_t * +/****************************************************/ +mmc_cmd (ushort cmd,ulong arg,ushort flags) +/****************************************************/ I'm not so fond of the style putting a comment line between the function name and the return type. I think they should be together. What does everyone else think?
ACK. Very confusing this way.
Best regards,
Stefan
PATCH 1/1 Add S3C2410 MMC/SD support
Quoted 11 lines · Stefan Roese
<snip>
Quoted 8 lines
cpu/arm920t/s3c24x0/mmc.c line 73
Quoted 4 lines
cpu/arm920t/s3c24x0/mmc.c new file +4
-0+static u_int32_t * +/****************************************************/ +mmc_cmd (ushort cmd,ulong arg,ushort flags) +/****************************************************/ I'm not so fond of the style putting a comment line between the function name and the return type. I think they should be together. What does everyone else think?
ACK. Very confusing this way.
Ok. This is actually a remnescent from the original mmc code that I used as an example/basis. I'll remove it from my patch, thanks.
Signature · 3 lines
- Harald Welte <[email protected]> http://openmoko.org/ ============================================================================ Software for the world's first truly open Free Software mobile phone
PATCH 1/1 Add S3C2410 MMC/SD support
In reply to Grant LikelyCheers,
Quoted 6 lines · Grant Likely
cpu/arm920t/s3c24x0/mmc.c 2007-02-16 23:43:28.000000000 +0100
Quoted 4 lines
cpu/arm920t/s3c24x0/mmc.c 2007-02-16 23:43:28.000000000 +0100 renamed from dev/null 1970-01-01 00:00:00.000000000 +0000 +2
-0+ +//#define MMC_DEBUGC++ style comment; bad! :-)
well, I was a long-time proponent of this, too. But it's now officially part of the C99 standard. So there's not really much [technical] argument you can still make about this :(
Quoted 10 lines
cpu/arm920t/s3c24x0/mmc.c 2007-02-16 23:43:28.000000000 +0100
Quoted 5 lines
cpu/arm920t/s3c24x0/mmc.c 2007-02-16 23:43:28.000000000 +0100 renamed from dev/null 1970-01-01 00:00:00.000000000 +0000 +5
-0+#ifdef MMC_DEBUG +#define DEBUGP printf +#else +#define DEBUGP(x, args ...) do { } while(0) +#endifShould really use the debug/debugX macros from
common.h. To enable them for a single file, just add '#define DEBUG' at the top of the file before any #include statements.
Quoted 2 lines
I know this is done a lot in u-boot; but I think it should be avoided as much as possible; especially in new code.
ok, no problem, have changed in my tree
Quoted 7 lines
cpu/arm920t/s3c24x0/mmc.c 2007-02-16 23:43:28.000000000 +0100
Quoted 5 lines
cpu/arm920t/s3c24x0/mmc.c 2007-02-16 23:43:28.000000000 +0100 renamed from dev/null 1970-01-01 00:00:00.000000000 +0000 +5
-0+ +static S3C2410_SDI *sdi; + +extern int +fat_register_device(block_dev_desc_t *dev_desc, int part_no);External prototype in a .c file; bad practice.
A very common one in u-boot. I'm just trying to fit in ;) Using '#include <fat.h>' now.
Quoted 3 lines
Include the correct header instead. If the prototype doesn't exist in a header included by the function implementation, then write a patch to add it.
will do.
Quoted 7 lines
cpu/arm920t/s3c24x0/mmc.c 2007-02-16 23:43:28.000000000 +0100
Quoted 3 lines
cpu/arm920t/s3c24x0/mmc.c 2007-02-16 23:43:28.000000000 +0100 renamed from dev/null 1970-01-01 00:00:00.000000000 +0000 +3
-0+/****************************************************/ +mmc_cmd(ushort cmd, ulong arg, ushort flags) +/****************************************************/I'm not so fond of the style putting a comment line between the function name and the return type. I think they should be together. What does everyone else think?
I've removed this already in my tree.
Quoted 1 line
braces not necessary on single line conditionals
removed them in my tree.
Quoted 10 lines
cpu/arm920t/s3c24x0/mmc.c 2007-02-16 23:43:28.000000000 +0100
Quoted 9 lines
cpu/arm920t/s3c24x0/mmc.c 2007-02-16 23:43:28.000000000 +0100 renamed from dev/null 1970-01-01 00:00:00.000000000 +0000 +9
-0+ while (fifo--) { + //DEBUGP("dst_u32 = 0x%08x\n", dst_u32); + *(dst_u32++) = sdi->SDIDAT; + if (len >= 4) + len -= 4; + else { + len = 0; + break; + }
Quoted 3 lines
Seems a little verbose; what about something like this? for ( ; fifo && len > 0; fifo--, len += 4)
*(dst_u32++) =sdi->SDIDAT;
I guess this si a question of taste/preferecne. I personally think the explicit variant (minus the //indented DEBUGP statement) is more readable than a for loop with no initial statement and ',' style multiple commands in each loop.
Quoted 1 line
Can/should this ever time out?
probably yes, if you do something strange to the hardware...
Quoted 1 line
Should (1 << 4) be a #defined constant?
probably, too.
Quoted 7 lines
Quoted 5 lines
cpu/arm920t/s3c24x0/mmc.c 2007-02-16 23:43:28.000000000 +0100 renamed from dev/null 1970-01-01 00:00:00.000000000 +0000 +2
-0+ /* all block aligned accesses */ + DEBUGP("src %lx dst %lx end %lx pstart %lx pend %lx astart %lxaend %lx\n",
+ src, (ulong)dst, end,part_start,part_end,aligned_start,aligned_end);This long debug statement appears a lot; should it be a macro?
that's (like much of the stuff) just a copy of something that is already in u-boot. So one of the things while adopting it from pxa to s3c2410
was: keep it as close as possible to the original. It seems like that one was a bad example ;)
Quoted 5 lines
Quoted 5 lines
cpu/arm920t/s3c24x0/mmc.c 2007-02-16 23:43:28.000000000 +0100 renamed from dev/null 1970-01-01 00:00:00.000000000 +0000 +5
-0+typedef struct mmc_cid +{ +/* FIXME: BYTE_ORDER */ + uchar year:4, + month:4;
Quoted 8 lines
cpu/arm920t/s3c24x0/mmc.c 2007-02-16 23:43:28.000000000 +0100
Quoted 6 lines
cpu/arm920t/s3c24x0/mmc.c 2007-02-16 23:43:28.000000000 +0100 renamed from dev/null 1970-01-01 00:00:00.000000000 +0000 +6
-0+ uchar sn[3]; + uchar fwrev:4, + hwrev:4; + uchar name[6]; + uchar id[3]; +} mmc_cid_t;- Inconsistent line spacing
will fix that.
Quoted 1 line
- Bit fields are non-portable (but that might not matter for this code)
yes. S3C2410 supports big-endian mode, but I doubt that anyone is using it, especially so in combination with u-boot.
Quoted 1 line
Ditto here
sine those are actual MMC protocol definitions, it might be worth having
one common definition. Much the same goes for the MMC read/write code
in general. But I don't really know too many SD/MMC controllers to decide on the level of the API, etc.
Quoted 10 lines
Quoted 10 lines
Index:
u-boot/include/s2c24x0.h
===================================================================include/s3c24x0.h 2007-02-16 23:42:19.000000000 +0100 renamed from include/s3c24x0.h 2007-02-16 23:42:02.000000000 +0100 +0
-2@@ -637,13 +637,7 @@ S3C24X0_REG32 SDIDCNT; S3C24X0_REG32 SDIDSTA; S3C24X0_REG32 SDIFSTA; -#ifdef __BIG_ENDIAN - S3C24X0_REG8 res[3];
Quoted 8 lines
include/s3c24x0.h 2007-02-16 23:42:19.000000000 +0100 line 646
Quoted 5 lines
include/s3c24x0.h 2007-02-16 23:42:19.000000000 +0100 renamed from include/s3c24x0.h 2007-02-16 23:42:02.000000000 +0100 +0
-5- S3C24X0_REG8 SDIDAT; -#else - S3C24X0_REG8 SDIDAT; - S3C24X0_REG8 res[3]; -#endifIs this a bug fix? If so, it should go in another patch with an appropriate description
well, you can access those registers as byte or as long register. If you use the long address, it will be the same addres independent of the endianness.
There was no existing user of those regs in u-boot.
Since my code uses long accesses to use it, there's no point in having them defined as byte registers.
So it's not really a bugfix, just adopting the existing unused definitions to the needs of my mmc driver.
Quoted 6 lines
Quoted 6 lines
include/s3c24x0.h 2007-02-16 23:42:19.000000000 +0100 renamed from include/s3c24x0.h 2007-02-16 23:42:02.000000000 +0100 +0
-2@@ -1123,11 +1117,7 @@ #define rSDIDatCnt (*(volatile unsigned *)0x5A000030) #define rSDIDatSta (*(volatile unsigned *)0x5A000034) #define rSDIFSTA (*(volatile unsigned *)0x5A000038) -#ifdef __BIG_ENDIAN -#define rSDIDAT (*(volatile unsigned char
Quoted 8 lines
include/s3c24x0.h 2007-02-16 23:42:19.000000000 +0100 line 1122
Quoted 6 lines
include/s3c24x0.h 2007-02-16 23:42:19.000000000 +0100 renamed from include/s3c24x0.h 2007-02-16 23:42:02.000000000 +0100 +1
-3*)0x5A00003F) -#else -#define rSDIDAT (*(volatile unsigned char *)0x5A00003C) -#endif +#define rSDIDAT (*(volatile unsigned *)0x5A00003C)Ditto
ditto ;)
Signature · 3 lines
- Harald Welte <[email protected]> http://openmoko.org/ ============================================================================ Software for the world's first truly open Free Software mobile phone
PATCH 1/1 Add S3C2410 MMC/SD support
Quoted 6 lines · In message <[email protected]> you wrote:
Quoted 2 lines
C++ style comment; bad! :-)
well, I was a long-time proponent of this, too. But it's now officially part of the C99 standard. So there's not really much [technical] argument you can still make about this :(
Not technical, but stylish. It's forbidden in U-Boot code, so please fix it.
Quoted 8 lines
Quoted 3 lines
Seems a little verbose; what about something like this? for ( ; fifo && len > 0; fifo--, len += 4)
*(dst_u32++) =sdi->SDIDAT;I guess this si a question of taste/preferecne. I personally think the explicit variant (minus the //indented DEBUGP statement) is more readable than a for loop with no initial statement and ',' style multiple commands in each loop.
IMO the shorter version is much easier to read, so please change this, too.
Quoted 7 lines
Quoted 1 line
Can/should this ever time out?
probably yes, if you do something strange to the hardware...
Quoted 1 line
Should (1 << 4) be a #defined constant?
probably, too.
Then please change these, too.
Quoted 6 lines
Quoted 1 line
This long debug statement appears a lot; should it be a macro?
that's (like much of the stuff) just a copy of something that is already in u-boot. So one of the things while adopting it from pxa to s3c2410
was: keep it as close as possible to the original. It seems like that one was a bad example ;)
If you decide to submit a second patch to also clean up the pxa code this is just the more appreciated. If you see ways to improve the code, please always do. Do not follow bad examples just because there are so many of them around.
Best regards,
Wolfgang Denk
Signature · 6 lines
DENX Software Engineering GmbH, HRB 165235 Munich, CEO: Wolfgang Denk Office: Kirchenstr. 5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de They're usually so busy thinking about what happens next that the only time they ever find out what is happening now is when they come to look back on it. - Terry Pratchett, _Wyrd Sisters_