[Sony Ericsson Xperia Mini, Mini Pro, Xperia Pro, A] jukkaman:
Hi,

Anyway, I have had the Xperia Mini for a while now, and its formfactor is perfect. But I have had some troubles lately, and wondered if anyone else had encountered them (and found a fix?).

ZellyCream 4.0

Kappa 1.6 kernel.

SD card is a Sandisk Ultra 64 gb SDXC, partitioned into one small ext3 partition and the rest a FAT32 one.

Whenever charging the phone for a while, leaving it alone, it seems as if the SD Card falls asleep. And as soon as I start using the phone, all hell breaks loose - the log fills with errors of files not found - see here:

And so it repeats. Only recourse is to reboot phone, and all gets back to normal.

Other users having a similar phone (Xperia mini pro) have reported almost the same behaviour.

I have tested adding some tape to the physical SD Card to increase contact in its slot - no result. I have tested with an old 16 gb card - which worked A-OK. I have checked the eMMC to see if there are memory faults in the phone - no.

What I was wondering, and which probably only a kernel dev would know more about is this:

There has been some discussions on a maemo-forum and here about timings for the SD Cards in the kernel drivers.

http://maemo.org/community/maemo-users/n900_microsd_card_i-o_errors_and_corruption/

http://xdaforums.com/showpost.php?p=17033833&postcount=5563

Specifically what was said was that

Another discussion at the maemo forums:

http://talk.maemo.org/showthread.php?t=72789

Now, I have taken a look at the source for Kappa 1.6,

https://github.com/KaSt/Kappa/blob/master/drivers/mmc/host/omap_hsmmc.c

and if I read the code correctly, it is not even remotely like the example given in the maemo-solution. It looks like the old Maemo code people were trying to improve:

static void set_data_timeout(struct omap_hsmmc_host *host,
unsigned int timeout_ns,
unsigned int timeout_clks)
{
unsigned int timeout, cycle_ns;
uint32_t reg, clkd, dto = 0;

reg = OMAP_HSMMC_READ(host->base, SYSCTL);
clkd = (reg & CLKD_MASK) >> CLKD_SHIFT;
if (clkd == 0)
clkd = 1;

cycle_ns = 1000000000 / (clk_get_rate(host->fclk) / clkd);
timeout = timeout_ns / cycle_ns;
timeout += timeout_clks;
if (timeout) {
while ((timeout & 0x80000000) == 0) {
dto += 1;
timeout <<= 1;
}
dto = 31 - dto;
timeout <<= 1;
if (timeout && dto)
dto += 1;
if (dto >= 13)
dto -= 13;
else
dto = 0;
if (dto > 14)
dto = 14;
}

reg &= ~DTO_MASK;
reg |= dto << DTO_SHIFT;
OMAP_HSMMC_WRITE(host->base, SYSCTL, reg);
}

The Maemo code from 2011 looks like this

static void set_data_timeout(struct omap_hsmmc_host *host,
unsigned int timeout_ns,
unsigned int timeout_clks)
{
unsigned int timeout, cycle_ns;
uint32_t reg, clkd, dto = 0;

reg = OMAP_HSMMC_READ(host->base, SYSCTL);
clkd = (reg & CLKD_MASK) >> CLKD_SHIFT;
if (clkd == 0)
clkd = 1;

cycle_ns = 1000000000 / (clk_get_rate(host->fclk) / clkd);
timeout = timeout_ns / cycle_ns;
timeout += timeout_clks;
if (timeout) {
while ((timeout & 0x80000000) == 0) {
dto += 1;
timeout <<= 1;
}
dto = 31 - dto;
timeout <<= 1;
if (timeout && dto)
dto += 1;
if (dto >= 13)
dto -= 13;
else
dto = 0;
if (dto > 14)
dto = 14;
}

reg &= ~DTO_MASK;
reg |= dto << DTO_SHIFT;
OMAP_HSMMC_WRITE(host->base, SYSCTL, reg);
}

http://gitorious.org/meego-device-adaptation/n900_kernel/blobs/master/drivers/mmc/host/omap_hsmmc.c

Now, my simple thought, and bear with me, I am no coder, just someone who likes to probe as far as I can in my hardware related troubles:

Could it be the case that more people with this kernel Kappa 1.6 and SD card Sandisk 64 gb, have had similar problems, and that the solution is modifying the kernel code?

Thanks BTW to all devs who have made my phone and so much more last longer.

Edited 130710 to include samples of Kappa code and Maemo code

Edited 130711 to remove some weird formatting