OpenWrt Forum Archive

Topic: Optimized version of mmc.c

The content of this topic has been archived between 5 Jun 2014 and 7 Mar 2018. Unfortunately there are posts – most likely complete pages – missing.

I believe that there is a timing hazard in cycles_delay(), from spi.c (second function in the file).

I'm assuming that successive calls to get_cycle() in the loop:
   while (get_cycles() > future) ;
can (usually or always do) return values that differ by more than one from call to call.  Then, if future turns out to be the maximally small number (0x7FFFFFFF, if, indeed, cycle_t is a 32 bit signed integer, 0 if it is actually unsigned), it is possible, when get_cycle() wraps, that it will skip past the value in future, leading to an additional delay until at least the next time get_cycle() wraps.  A very easy fix is to change the loop to:
   while (get_cycles() > now) ;

This is not to say that I've experienced this problem, but I currently have too much time on my hands, and was reading the code because I'm curious about the SD interface.

Hi all,

I am using Kingston 512MB 50X SD card on WRT54GL@250MHz with mmc driver version 1.3.4.
I got write speed only 170KBps for 150MB testing data.

Please advise me what should I do for faster speed as Cyril said (850KB/s WRITE, 450KB/s READ).

Hi all,

I just want to report my test.
Now, I got 550KB/s WRITE, 400KB/s READ when I format SD card in ext2 format faster than vfat format.
However, I do not reach the max Cyril's speed.

Well, now I got 700KB/s WRITE, 445KB/s READ when using 2GB 150X SD. The old on is 512MB 50X SD.

(Last edited by lsomchai on 3 Feb 2008, 11:07)

Hey,

im runnin a Buffalo WHR-HP-G54.
kamikaze_0.7
sd: ScanDisk 512mb

i used the following layout:
SD_CS -> GPIO 1 (Bridge LED)
SD_DO -> GPIO 6 (AOSS LED)
SD_CLK -> GPIO 3 (Uninstalled LED)
SD_DI -> GPIO 5 (Auto/Bridge switch)

i got the src of 1.3.4 and changed the config.h to:

#define LOG_LEVEL 3
#define USE_CMD18
#define USE_CMD25

/* GPIO pin 2 */
//#define SD_DI 0x04
#define SD_DI 0x20
/* GPIO pin 4 */
//#define SD_DO 0x10
#define SD_DO 0x40
/* GPIO pin 3 */
#define SD_CLK 0x08
/* GPIO pin 7 */
#define SD_CS 0x02

#if SD_DO == 0x10
    #define SHIFT_DO 3
#else
#if SD_DO == 0x40
    #define SHIFT_DO 1
#endif
#endif
#if SD_DI == 0x04
    #define SHIFT_DI 5
#else
#if SD_DI == 0x20
    #define SHIFT_DI 2
#endif
#endif

and i always get this message:

[INFO] mmc_hardware_init: initializing GPIOs
[INFO] mmc_card_init: the period of a 380KHz frequency lasts 524 CPU cycles
[INFO] mmc_card_init: powering card on. sending 80 CLK
[INFO] mmc_card_init: 80 CLK sent in 44136 CPU cycles
[INFO] mmc_card_init: resetting card (CMD0)
[FATAL] mmc_card_init: invalid response from card: ff found, waiting for 01
[INFO] mmc_card_init: the period of a 380KHz frequency lasts 524 CPU cycles
[INFO] mmc_card_init: powering card on. sending 80 CLK
[INFO] mmc_card_init: 80 CLK sent in 43306 CPU cycles
[INFO] mmc_card_init: resetting card (CMD0)
[FATAL] mmc_card_init: invalid response from card: ff found, waiting for 01
[ERROR] mmc_init: got an error calling mmc_card_init: 01
[ERROR] mmc_check_media: change detected but was not able to initialize new card: ffffffff

any ideas?


Edit:
i tried the mmc.c from http://wiki.openwrt.org/OpenWrtDocs/Customizing/Hardware/MMC?highlight=%28mmc%29 (1.4)
seems to work, i just mnted the sd card and wrote some stuff
speed suxx like hell ,)

dmesg:

mmc: Device does not use v1 GPIO layout, trying to use v4 layout
mmc: Device does not use v4 layout, trying to use Buffalo layout
Size = 495488, hardsectsize = 512, sectors = 990976
Partition check:
 mmca: p1

Edit:
i tried dd-wrt with mmc, works fijne with manual gpio layout definition
write: 197 kb/s
read: 256 kb/s

dmesg:

mmc: starting module with: SD_DI=0x40, SD_DO=0x20, SD_CLK=0x8, SD_CS=0x2
Size = 495488, hardsectsize = 512, sectors = 990976
Partition check:
 mmca: p1
EXT2-fs warning: mounting unchecked fs, running e2fsck is recommended

(Last edited by dotb52 on 23 Feb 2008, 17:38)

how do you test read/write ?

mmc 1.3.4 is ok with SD emet 2Go 60x ~400ko/s read

(Last edited by $@m on 3 Mar 2008, 01:24)

i have wrt54g v2

i connect mmc card to him

i test all gpio with led albo its blinking when i run

while true; do gpio enable 5; sleep 1; gpio disable 5; sleep 1; done

but its little problem if i run "gpio enable 7" (DMZ LED) its turn OFF and if "gpio disable 7" the its ON

maybe this is a problem , card not work

or mmc.o is bad

help

Seems dead. But I don't care for 2.4 kernel any more.

And for 2.6 kernels their is a new mmc-over-gpio driver in the trunk source which works good smile

Hi
I need mmc driver for gpio 0,6,12 and 14 pins for my wap54g...
I use this howto:http://panteltje.com/panteltje/wap54g/to-linksys-wap54g-forum-2.txt and I'm using soft from this site now, but I have:

Jan  1 00:45:46 (none) daemon.warn klogd: mmc Hardware init
Jan  1 00:45:46 (none) daemon.warn klogd: mmc Card init
Jan  1 00:45:46 (none) daemon.warn klogd: mmc Card init
Jan  1 00:45:46 (none) daemon.warn klogd> > error in mmc_card_init (1)
Jan  1 00:45:46 (none) daemon.warn klogd: mmc: error in mmc_init (-1)

What can I do?
I can't download src for mmc driver.(site is down)
Please help my smile

(Last edited by dinek889 on 29 Apr 2008, 21:02)

Hey guys!! great work!!

The links seem to be offline or broken... you might wanna check your hosting....it would be really great if you could fix those download links...
or just send me a compiled version of the newest dirver GPIO2 (used this tutorial to make it: http://www.hendlsofen.de/WRT54GL/eng/WRT54GL_SDMod.html) for WRT54GL 1.1 (i would like to use it with kamikaze) on my mail: kantta@gmail.com

Right now i have tired many drivers from different pages, but i have no /dev/mmc/ device in dev directory.... so i would like to use THE drivers!

Cuz that would be just great!!

Hi everybody.
Do you can explain me how i can use mmc/sd card under Kamikaze 8.09_RC1 with 2.6 kernel?
Previously i use Witerusssian, and everithing work fine,  but now i not have right software ( kernel mod) for use mmc.
I already  install kmod-mmc  but is not work.
kmod-mmc-over-gpio_2.6.25.17-brcm47xx-2_mipsel
kmod-mmc-spi_2.6.25.17-brcm47xx-1_mipsel
kmod-mmc_2.6.25.17-brcm47xx-1_mipsel

Hi

I had many problems running mmc driver in openwrt (no problem in dd-wrt)  on wrt54gl 1.1
now i have kamikaze 8.09 2.4 and latest driver from this topic, everything works but writing is exremely slow
about 30-40 KB/s
i realized that after booting if i unmount mmc partition remove mmc module, load it and mount partition one more time everything is ok, reading and writing times such as others have (32 mb, 1m 18s - write)
so what's wrong with it?
this is my script loading mmc and mounting partiton:
cat /etc/init.d/mountmmc
#!/bin/sh
echo "0x9c" > /proc/diag/gpiomask
insmod mmc
mount /mmc
sleep 8s
swapon /dev/mmc/disc0/part2 -p 5
and /etc/fstab contains (i have modified /etc/config/fstab)
/dev/mmc/disc0/part1    /mmc    ext2    noauto,rw,sync  0       0
it's strange for me, what i did wrong?

ps. mounting swap in this script doesn't work also, why ?

Compile by yourself.....

hello
i'm integrating the mmc_drv in the 2.6 kernel tree
unfortunately i haven't understand the problem related to the 512Mb limit

i'm using the first release of the mmc_drv (for fonera 2100) that has a limit of the first 512Mb of the mmc/sd card.

What exactly has been modified in that driver to support 1Gb 2Gb ... mmc/sd card ?

/*
* Fonera MMC Driver
*
* 2003-2005 original idea by K. John Crispin, mail john@phrozen.org
*/

(this driver has been used in fonera 2100 mcc
http://www.dd-wrt.com/wiki/index.php/Fonera_SD-Card_hack#MMC_BETA_driver_for_the_LaFonera
http://www.larsen-b.com/Article/262.html)

(Last edited by flamemaniii on 10 Feb 2009, 03:32)

forum2008 wrote:

And for 2.6 kernels their is a new mmc-over-gpio driver in the trunk source which works good smile

where is it ?

could you post the source ?

(Last edited by flamemaniii on 9 Feb 2009, 22:29)

menuconfig / Kernel modules / Other modules / kmod-mmc-over-gpio

Yanira wrote:

menuconfig / Kernel modules / Other modules / kmod-mmc-over-gpio

i mean where are sources inside the trunk

ls trunk/package/mmc_over_gpio/files/

.svn/                 
mmc_over_gpio.config 
mmc_over_gpio.init



no .c found

i have to manually include them inside my kernel tree

It's the driver from the Linux Kernel...

ok if you mean the following

/*
* Driver for driving an MMC card over a bitbanging GPIO SPI bus.
*
* 2008 Michael Buesch <mb@bu3sch.de>
*
*/

it has documentation  uc-gentoo-2.6.26.8-fonera/Documentation/gpiommc.txt

GPIOMMC - Driver for an MMC/SD card on a bitbanging GPIO SPI bus
================================================================

The gpiommc module hooks up the mmc_spi and spi_gpio modules for running an
MMC or SD card on GPIO pins.

Two interfaces for registering a new MMC/SD card device are provided:
A static platform-device based mechanism and a dynamic configfs based interface.


Registering devices via platform-device
=======================================

The platform-device interface is used for registering MMC/SD devices that are
part of the hardware platform. This is most useful only for embedded machines
with MMC/SD devices statically connected to the platform GPIO bus.

The data structures are declared in <linux/mmc/gpiommc.h>.

To register a new device, define an instance of struct gpiommc_platform_data.
This structure holds any information about how the device is hooked up to the
GPIO pins and what hardware modes the device supports. See the docbook-style
documentation in the header file for more information on the struct fields.

Then allocate a new instance of a platform device by doing:

        pdev = platform_device_alloc(GPIOMMC_PLATDEV_NAME, gpiommc_next_id());

This will allocate the platform device data structures and hook it up to the
gpiommc driver.
Then add the gpiommc_platform_data to the platform device.

        err = platform_device_add_data(pdev, pdata, sizeof(struct gpiommc_platform_data));

You may free the local instance of struct gpiommc_platform_data now. (So the
struct may be allocated on the stack, too).
Now simply register the platform device.

        err = platform_device_add(pdev);

Done. The gpiommc probe routine will be invoked now and you should see a kernel
log message for the added device.


Registering devices via configfs
================================

MMC/SD cards connected via GPIO often are a pretty dynamic thing, as for example
selfmade hacks for soldering an MMC/SD card to standard GPIO pins on embedded
hardware are a common situation.
So we provide a dynamic interface to conveniently handle adding and removing
devices from userspace, without the need to recompile the kernel.

The "gpiommc" subdirectory at the configfs mountpoint is used for handling
the dynamic configuration.

i don't like this part

To create a new device, it must first be allocated with mkdir.
The following command will allocate a device named "my_mmc":
        mkdir /config/gpiommc/my_mmc

There are several configuration files available in the new
/config/gpiommc/my_mmc/ directory:

gpio_data_in                    = The SPI data-IN GPIO pin number.
gpio_data_out                   = The SPI data-OUT GPIO pin number.
gpio_clock                      = The SPI Clock GPIO pin number.
gpio_chipselect                 = The SPI Chipselect GPIO pin number.
gpio_chipselect_activelow       = Boolean. If 0, Chipselect is active-HIGH.
                                  If 1, Chipselect is active-LOW.
spi_mode                        = The SPI data mode. Can be 0-3.
spi_delay                       = Enable all delays in the lowlevel bitbanging.
max_bus_speed                   = The maximum SPI bus speed. In Hertz.

The device must first get configured and then registered by writing "1" to
the "register" file.
The configuration parameters "gpio_data_in", "gpio_data_out", "gpio_clock"
and "gpio_chipselect" are essential and _must_ be configured before writing
"1" to the "register" file. The registration will fail, otherwise.

The default values for the other parameters are:
gpio_chipselect_activelow       = 1             (CS active-LOW)
spi_mode                        = 0             (SPI_MODE_0)
spi_delay                       = 1             (enabled)
max_bus_speed                   = 5000000       (5 Mhz)

Configuration values can not be changed after registration. To unregister
the device, write a "0" to the "register" file. The configuration can be
changed again after unregistering.

To completely remove the device, simply rmdir the directory
(/config/gpiommc/my_mmc in this example).
There's no need to first unregister the device before removing it. That will
be done automatically.

i don't like that cause i have to bootstrap directly with root=/dev/mmc2, so this dynamic mechanism makes me to do an initram where to boot (root=/dev/ram0) and to root_pivot to /dev/mmc2

mmm my question is: is it possible to have a static configuration of the GPIO pins hardly compiled in the kernel ?

(Last edited by flamemaniii on 10 Feb 2009, 03:20)

z0rg wrote:

Hi everybody.
Do you can explain me how i can use mmc/sd card under Kamikaze 8.09_RC1 with 2.6 kernel?
Previously i use Witerusssian, and everithing work fine,  but now i not have right software ( kernel mod) for use mmc.
I already  install kmod-mmc  but is not work.
kmod-mmc-over-gpio_2.6.25.17-brcm47xx-2_mipsel
kmod-mmc-spi_2.6.25.17-brcm47xx-1_mipsel
kmod-mmc_2.6.25.17-brcm47xx-1_mipsel

has anyone got a sd card running with kmod-mmc-over-gpio
how do you use this module? does it use /proc/diag/gpiomask, too? does it work flawless.
want to be sure I can use my sd-card before switching to 2.6.

okar wrote:

has anyone got a sd card running with kmod-mmc-over-gpio

Yes, but not on Broadcom hardware. One on La Fonera (fon2100) and the other one one a D-Link DIR-300. Both working fine.

i opened this project -> http://www.elinux.org/Flameman/fonera
and a full and complete drive rewrite has been started

(Last edited by flamemaniii on 1 Mar 2009, 02:25)

Hello,

I compiled this driver for kamikaze 8.09 kernel 2.4.35.4

But seams that not working.
I have wrt54gl device working with mmc/sd card in whiterussian and at old past time he works in dd-wrt.

now in kamikaze 8.09  with wrt54gl have:

[INFO] mmc_hardware_init: initializing GPIOs
[INFO] mmc_card_init: the period of a 380KHz frequency lasts 654 CPU cycles
[INFO] mmc_card_init: powering card on. sending 80 CLK
[INFO] mmc_card_init: 80 CLK sent in 53726 CPU cycles
[INFO] mmc_card_init: resetting card (CMD0)
[FATAL] mmc_card_init: invalid response from card: ff found, waiting for 01
[INFO] mmc_card_init: the period of a 380KHz frequency lasts 654 CPU cycles
[INFO] mmc_card_init: powering card on. sending 80 CLK
[INFO] mmc_card_init: 80 CLK sent in 53327 CPU cycles
[INFO] mmc_card_init: resetting card (CMD0)
[FATAL] mmc_card_init: invalid response from card: ff found, waiting for 01
[ERROR] mmc_init: got an error calling mmc_card_init: 01
[ERROR] mmc_check_media: change detected but was not able to initialize new card: ffffffff

I tested this driver because the kmod-broadcom-mmc_2.4.35.4+0.1-brcm-2.4-1_mipsel.ipk was not work.

Please help.