Thursday, November 10, 2011

Wake-up enable for UART

Requirement
=========
Suspend the device to RAM. It should wake up on any key press from UART.

First Method
=============
This can be done by just adding  "no_console_suspend" to bootargs.
By doing this during suspends to RAM, Uart clk src will be kept alive.

Second Method
==============
For this method, hardware should have the capability to wake-up from UART interrupt.

All devices in the device model has two flags to control the wake-up events. They are "can_wakeup" and "wakeup" flags in

struct device {
....
struct dev_pm_info power;
....
}

struct dev_pm_info {
.......
unsigned int can_wakeup:1;
struct wakeup_source *wakeup;
........
}

Flag can_wakeup is initialized by the device driver code by using device_set_wakeup_capable().
And, device_set_wakeup_enable(&dev, 1) will initiallize the struct wakeup_source and add in the list of wake-able sources.

can_wakeup is used to mark whether the hardware can support the wake-up. For most of the devices wake-up will be NULL by default. But used by drivers like power buttons, keyboards and Ethernet.

I want to configure UART as my wake-up source, this patch does it on kernel-3.0.1

diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index ab2e6e7..2bae1aa 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -2401,7 +2401,7 @@ int uart_add_one_port(struct uart_driver *drv, struct uart_port *uport)
tty_dev = tty_register_device(drv->tty_driver, uport->line, uport->dev);
if (likely(!IS_ERR(tty_dev))) {
device_init_wakeup(tty_dev, 1);
- device_set_wakeup_enable(tty_dev, 0);
+ device_set_wakeup_enable(tty_dev, 1);
} else
printk(KERN_ERR "Cannot register tty device on line %d\n",
uport->line);

Then I tested it with echo mem > /sys/power/state

The device is able to wake-up from my UART1 interrupt which is also my console.

Now my board has many UART. I want to configure the UART2 as wake-able source, but my console is on UART1.

From the command prompt,
cat /dev/ttyS1 &

this done to initialize the UART2 port

And opened UART2 serial port on second instance of minicom. Then entering any character on second minicom wake-up my device.

Tuesday, September 27, 2011

Andriod Toolbox

Android comes with a user space utility called Toolbox which is not busybox. It is at system/core/toolbox. But with very limited features.

For using the busybox,

1) Git clone from http://git.busybox.net/busybox/
2) To cross compile with arm tool-chain and building it as static, used the following command.
$ make -j32 CROSS_COMPILE=/projects/mob_tools/CodeSourcery/Sourcery_G++_Lite/bin/arm-none-linux-gnueabi- -I/projects/mob_tools/CodeSourcery/Sourcery_G++_Lite/arm-none-linux-gnueabi/libc/usr/include/ CFLAGS=--static
3) for installing the busybox,

Building Individual Components in Android

Run

source build/envsetup.sh

Then you can use mm command to compile any Android.mk individually

For example to compile the android Toolbox.

cd system/core/toolbox.

mm

Wednesday, March 16, 2011

Free Electrons

http://free-electrons.com/

They offer free training materials about Linux kernel. And their blog is interesting to read to keep you updated about the current kernel developments.

Thursday, March 10, 2011

System revision

Development boards usally have many version. Because no board can be perfect first time. So in the process of improving the boards we end up in many system revisions. One way of doing this is to dedicate few gpio lines(may be 3 in this case you can have 2^3 = 8 board versions). Disadvantage of this way is thay you will end up waisting 3 gpios. Another way is to use the ADC for this purpose. The mechanism is to connect two resitance in series and varry the resistance amoung the boards. Measure the voltage across one resitor and find out the board.
For example, R1 = 100K and R2 = 100K. R1 and R2 are in series with volatge of 3.3V. So the voltage drop across R2 will be 1.65V, which we measured using ADC and decision is made.

In C110 processor we use ADC with resolution of 12 bits so the range is 0 to 4095. But the voltage range is 0 to 3.3V. Now we need to map adc value to our voltage range.

Here is the mathematics,
3.3V = 4095 units of ADC
1 unit of ADC = 3300 mV/4095 = 0.8058mv
for 3.3 v adc value is 4095 units( ie 3300/0.8058)

So in our case we need 1.65V or 1650 mV. So the adc value should read 2047(ie 1650/0.8058)

Tuesday, March 8, 2011

NOR Vs NAND

NOR
Access - linear random
Replace - ROM
Cost - expensive
Density - low
Earse time - 1 second
Programing - byte by byte
OOB data - no
NAND
Access - pagewise
Replace - mass strorage
Cost - cheap
Density - high
Earse time - 2 ms
Programming - pagewise, must be erased before
OOB - yes

yaffs2 and nand drivers

The crespo board was booting android with system and data partititons on the Movi-nand. Now the task is to move this to the one-nand memory. The main area to be modified is at the bootloader where partitons are defined. This will be passed to kernel as ATAGS. so modified the partition table to point the system and the data partitions to nand. Then edited the init.herring.rc file to
mount yaffs2 mtd@system /system wait ro
mount yaffs2 mtd@userdata /data wait noatime nosuid nodev

Next is to create yaffs2 filesystem. Initally I used the command,
./out/host/linux-x86/bin/mkyaffs2image out/target/product/crespo/system sytem.img
But file system was not mounting with this. The reason was that by default mkyaffs2image utility used page size as 2048 and spare area(OOM) as 64. Later when I checked the data sheet of the One-nand, it was 4096 and 128 respectively. So modifed the command to,
./out/host/linux-x86/bin/mkyaffs2image -c 4096 -s 128 out target/product/crespo/system system.img

But this time Odin was giving and flashing failure. So I checked the size of the system.img. It was 155MB and compared with the size of the system partitions which was only 152MB. So that was the reason for flashing failure. After stealling some space from data partiton, flashing works. And the yaffs2 filesystem was successfully mounted. :-)

If you want to know more about the NAND and Yaffs2 File System here is a good link.