Mediatek-x20 LED gpio set


#1

Hi,I have a doubt about LED GPIO setting.
In Led driver,we can see the LED GPIO setting,//kernel-3.18\drivers\misc\mediatek\led_96board\led_96board.c

#include “led_96board.h”
#include <mt-plat/mt_gpio.h>
#include <mach/gpio_const.h>

#define led_0 196|0x80000000
#define led_1 197|0x80000000
#define led_2 198|0x80000000
#define led_3 199|0x80000000
#define led_4 200|0x80000000
#define led_5 201|0x80000000

I don’t understand how 0x80000000 came。

Thanks for your help.


#2

From source (mt_gpio.c), it’s not clear to me why it has been introduced, but it just seems to be an ugly trick, (0x80000000 is masked):

void mt_gpio_pin_decrypt(u32 *cipher)
{
    //just for debug, find out who used pin number directly
    if((*cipher & (0x80000000)) == 0){
	    GPIOERR("Pin %u decrypt warning! \n",(unsigned int)*cipher);	
	    //dump_stack();
	    //return;
    }

    //GPIOERR("Pin magic number is %x\n",*cipher);
    *cipher &= ~(0x80000000);
    return;
}

#3

Hi,Loic,
After testing,I find 0x80000000 can be discarded。But I have another question.
#define led_0 196

196 is the address of GPIO196,And it dose not need to set Base address?

such as


#4

This is the ‘ID’ of the GPIO, mt_gpio driver uses this ID to access the correct GPIO registers.

e.g. from mt_gpio driver:

#define MT_GPIO_DIR_REG 0xF100C008
#define MT_GPIO_OUT_REG 0xF100C000
#define MT_GPIO_IN_REG 0xF100C010

static void mt_gpio_set_bit(u32 nr, u32 reg)
{
    u32 value;
    value = readl(reg);
    value |= 1L << nr;
    writel(value, reg);
}

   ... 
if (dir == GPIO_DIR_OUT)
   mt_gpio_set_bit(pin, MT_GPIO_DIR_REG);

#5

Hi,Loic
Thank you for solving my doubts.