static int qrd_gpios_request_enable(const struct msm_gpio *table, int size) { int i; const struct msm_gpio *g; struct gpiomux_setting setting; int rc = msm_gpios_request(table, size); if (!rc){ for (i = 0; i < size; i++) { g = table + i; /* use msm_gpiomux_write which can save old configuration */ setting.func = GPIO_FUNC(g->gpio_cfg); setting.dir = GPIO_DIR(g->gpio_cfg); setting.pull = GPIO_PULL(g->gpio_cfg); setting.drv = GPIO_DRVSTR(g->gpio_cfg); msm_gpiomux_write(GPIO_PIN(g->gpio_cfg), GPIOMUX_ACTIVE, &setting, NULL); pr_debug("I2C pin %d func %d dir %d pull %d drvstr %d\n", GPIO_PIN(g->gpio_cfg), GPIO_FUNC(g->gpio_cfg), GPIO_DIR(g->gpio_cfg), GPIO_PULL(g->gpio_cfg), GPIO_DRVSTR(g->gpio_cfg)); } } return rc; }
static int tlmm_dump_cfg(char* buf,unsigned gpio, unsigned cfg, int output_val) { static char* drvstr_str[] = { "2", "4", "6", "8", "10", "12", "14", "16" }; // mA static char* pull_str[] = { "N", "D", "K", "U" }; // "NO_PULL", "PULL_DOWN", "KEEPER", "PULL_UP" static char* dir_str[] = { "I", "O" }; // "Input", "Output" char func_str[20]; char* p = buf; int drvstr = GPIO_DRVSTR(cfg); int pull = GPIO_PULL(cfg); int dir = GPIO_DIR(cfg); int func = GPIO_FUNC(cfg); //printk("%s(), drvstr=%d, pull=%d, dir=%d, func=%d\n", __func__, drvstr, pull, dir, func); sprintf(func_str, "%d", func); p += sprintf(p, "%d:0x%x %s%s%s%s", gpio, cfg, func_str, pull_str[pull], dir_str[dir], drvstr_str[drvstr]); p += sprintf(p, " = %d", output_val); p += sprintf(p, "\n"); return p - buf; }
/*=========================================================================== FUNCTION GPIO_TLMM_CONFIG DESCRIPTION Configures the GPIO TLMM as per the signal value used for the given GPIO. DEPENDENCIES None. RETURN VALUE None ===========================================================================*/ void gpio_tlmm_config(GPIO_SignalType gpio_signal) { GPIO_PolarityType gpio_polarity; uint32 gpio_oe_register; uint32 gpio_mask; uint8 gpio_number; gpio_number = GPIO_NUMBER(gpio_signal); if (gpio_number >= GPIO_NUM_GPIOS) { #ifndef BUILD_BOOT_CHAIN ERR_FATAL("Invalid GPIO number 0x%x",gpio_number, 0, 0); #endif return; } gpio_polarity = GPIO_POLARITY(gpio_signal); gpio_oe_register = GPIO_GROUP(gpio_signal); gpio_mask = 1 <<(gpio_number-GPIO_GROUP_START[gpio_oe_register]); INTLOCK(); if (gpio_oe_register < 2) { HWIO_OUT(GPIO_PAGE,gpio_number); HWIO_OUT(GPIO_CFG,(GPIO_SIGNAL(gpio_signal)<<2) | GPIO_PULL(gpio_signal)); } else { HWIO_OUT(GPIO2_PAGE,gpio_number); HWIO_OUT(GPIO2_CFG,(GPIO_SIGNAL(gpio_signal)<<2) | GPIO_PULL(gpio_signal)); } INTFREE(); if ( gpio_polarity == GPIO_OUTPUT ) { BIO_TRISTATE(gpio_oe_register, gpio_mask, gpio_mask); } else { BIO_TRISTATE(gpio_oe_register, gpio_mask, 0); } gpio_configs[gpio_number] = gpio_signal; }
void __gpio_tlmm_config(unsigned config) { uint32_t flags; unsigned gpio = GPIO_PIN(config); flags = ((GPIO_DIR(config) << 9) & (0x1 << 9)) | ((GPIO_DRVSTR(config) << 6) & (0x7 << 6)) | ((GPIO_FUNC(config) << 2) & (0xf << 2)) | ((GPIO_PULL(config) & 0x3)); __raw_writel(flags, GPIO_CONFIG(gpio)); }
int gpio_tlmm_config(unsigned config, unsigned disable) { uint32_t flags; unsigned gpio = GPIO_PIN(config); if (gpio > NR_MSM_GPIOS) return -EINVAL; flags = ((GPIO_DIR(config) << 9) & (0x1 << 9)) | ((GPIO_DRVSTR(config) << 6) & (0x7 << 6)) | ((GPIO_FUNC(config) << 2) & (0xf << 2)) | ((GPIO_PULL(config) & 0x3)); writel(flags, GPIO_CONFIG(gpio)); return 0; }
int gpio_tlmm_config(unsigned config, unsigned disable) { uint32_t v2flags; unsigned long irq_flags; unsigned gpio = GPIO_PIN(config); if (gpio > NR_MSM_GPIOS) return -EINVAL; v2flags = ((GPIO_DIR(config) << 9) & (0x1 << 9)) | ((GPIO_DRVSTR(config) << 6) & (0x7 << 6)) | ((GPIO_FUNC(config) << 2) & (0xf << 2)) | ((GPIO_PULL(config) & 0x3)); spin_lock_irqsave(&gpio_lock, irq_flags); writel(v2flags, GPIO_CONFIG(gpio)); spin_unlock_irqrestore(&gpio_lock, irq_flags); return 0; }
static int tlmm_get_cfg(unsigned gpio, unsigned* cfg) { unsigned flags; BUG_ON(gpio >= TLMM_NUM_GPIO); //printk("%s(), gpio=%d, addr=0x%08x\n", __func__, gpio, (unsigned int)GPIO_CONFIG(gpio)); #if 0 flags = ((GPIO_DIR(config) << 9) & (0x1 << 9)) | ((GPIO_DRVSTR(config) << 6) & (0x7 << 6)) | ((GPIO_FUNC(config) << 2) & (0xf << 2)) | ((GPIO_PULL(config) & 0x3)); #else flags = __raw_readl(GPIO_CONFIG(gpio)); #endif *cfg = GPIO_CFG(gpio, (flags >> 2) & 0xf, (flags >> 9) & 0x1, flags & 0x3, (flags >> 6) & 0x7); return 0; }
int msm_gpios_disable(const struct msm_gpio *table, int size) { int rc = 0; int i; const struct msm_gpio *g; for (i = size-1; i >= 0; i--) { int tmp; g = table + i; tmp = gpio_tlmm_config(g->gpio_cfg, GPIO_CFG_DISABLE); if (tmp) { pr_err("gpio_tlmm_config(0x%08x, GPIO_CFG_DISABLE)" " <%s> failed: %d\n", g->gpio_cfg, g->label ?: "?", rc); pr_err("pin %d func %d dir %d pull %d drvstr %d\n", GPIO_PIN(g->gpio_cfg), GPIO_FUNC(g->gpio_cfg), GPIO_DIR(g->gpio_cfg), GPIO_PULL(g->gpio_cfg), GPIO_DRVSTR(g->gpio_cfg)); if (!rc) rc = tmp; } } return rc; }
int msm_gpios_enable(const struct msm_gpio *table, int size) { int rc; int i; const struct msm_gpio *g; for (i = 0; i < size; i++) { g = table + i; rc = gpio_tlmm_config(g->gpio_cfg, GPIO_CFG_ENABLE); if (rc) { pr_err("gpio_tlmm_config(0x%08x, GPIO_CFG_ENABLE)" " <%s> failed: %d\n", g->gpio_cfg, g->label ?: "?", rc); pr_err("pin %d func %d dir %d pull %d drvstr %d\n", GPIO_PIN(g->gpio_cfg), GPIO_FUNC(g->gpio_cfg), GPIO_DIR(g->gpio_cfg), GPIO_PULL(g->gpio_cfg), GPIO_DRVSTR(g->gpio_cfg)); goto err; } } return 0; err: msm_gpios_disable(table, i); return rc; }
/*=========================================================================== FUNCTION GPIO_INIT DESCRIPTION Initializes GPIO TLMM as per the TLMM configuration defined at boot time. DEPENDENCIES None. RETURN VALUE None ===========================================================================*/ void gpio_init(void) { uint32 gpio_number; uint32 gpio_mask; uint32 gpio_oe_register; uint32 gpio_oe_0_value = 0; uint32 gpio_oe_1_value = 0; uint32 gpio_oe_2_value = 0; uint32 gpio_oe_3_value = 0; GPIO_PolarityType gpio_polarity; GPIO_SignalType gpio_signal; for (gpio_number=0; gpio_number < GPIO_NUM_GPIOS; gpio_number++ ) { gpio_signal = TLMM_GPIO_CONFIG[gpio_number]; #ifndef CUST_EDITION // Configure GPIO # 30 for PA_R1 in Pedro 2.0 if ( gpio_number == 30 && VERSION_GET_VERSION_ID() == 1 ) { gpio_signal = MSM2_PA_R1; } #endif gpio_polarity = GPIO_POLARITY(gpio_signal); gpio_oe_register = GPIO_GROUP(gpio_signal); if (GPIO_SIGNAL(gpio_signal) == 0 && gpio_polarity == GPIO_OUTPUT) // pin is under traditional GPIO control { gpio_mask = 1 << (gpio_number - GPIO_GROUP_START[gpio_oe_register]); if (gpio_oe_register == 0) { /* Group 0: GPIO numbers from 12, 14-30 are used GPIO_XXX_0 * GPIO_XXX_0: * Bit [30:14] -- GPIO[30:14] * Bit [13] -- reserved * Bit [12] -- GPIO[12] * Bit [11:0] -- reserve */ gpio_oe_0_value |= gpio_mask; } else if (gpio_oe_register == 1) { /* Group 1: GPIO numbers from 34-41, 53, 55-62 are used GPIO_XXX_1 * GPIO_XXX_1: * Bit [30:23] -- GPIO[62:55] * Bit [22] -- reserved * Bit [21] -- GPIO[53] * Bit [20:10] -- reserved * Bit [9:2] -- GPIO[41:34] * Bit [1:0] -- reserved */ gpio_oe_1_value |= gpio_mask; } else if (gpio_oe_register == 2) { /* Group 2: GPIO numbers from 0-11, 13, 31 are used GPIO2_XXX_0 * GPIO2_XXX_0: * Bit [31] -- GPIO[31] * Bit [30:14] -- reserved * Bit [13] -- GPIO[13] * Bit [29:12] -- reserved * Bit [11-0] -- GPIO[11:0] */ gpio_oe_2_value |= gpio_mask; } else if (gpio_oe_register == 3) { /* Group 3: GPIO numbers from 32-33, 42-52, 54 are used GPIO2_XXX_1 * GPIO2_XXX_1: * Bit [22] -- GPIO[54] * Bit [21] -- reserved * Bit [20:10] -- GPIO[52:42] * Bit [9:2] -- reserved * Bit [1:0] -- GPIO[33:32] */ gpio_oe_3_value |= gpio_mask; } } if (gpio_oe_register < 2) { HWIO_OUT(GPIO_PAGE,gpio_number); HWIO_OUT(GPIO_CFG, (GPIO_SIGNAL(gpio_signal)<<2) | GPIO_PULL(gpio_signal)); } else { HWIO_OUT(GPIO2_PAGE,gpio_number); HWIO_OUT(GPIO2_CFG, (GPIO_SIGNAL(gpio_signal)<<2) | GPIO_PULL(gpio_signal)); } } HWIO_OUT(GPIO_OE_0,gpio_oe_0_value); HWIO_OUT(GPIO_OE_1,gpio_oe_1_value); HWIO_OUT(GPIO2_OE_0,gpio_oe_2_value); HWIO_OUT(GPIO2_OE_1,gpio_oe_3_value); }
int main(int argc, char*argv[]){ setup_io(); printf("%x\n", _INIT_GPIO(GPA0_)); // 22222222 printf("%x\n", _INIT_GPIO(GPA1_)); // 2222 printf("%x\n", _INIT_GPIO(GPB_)); // 0 printf("%x\n", _INIT_GPIO(GPC_)); // 44444 printf("%x\n", _INIT_GPIO(GPD_)); // 22022 printf("%x\n", _INIT_GPIO(GPE0_)); // 22222222 printf("%x\n", _INIT_GPIO(GPE1_)); // 222222 printf("%x\n", _INIT_GPIO(GPF0_)); // 22222200 printf("%x\n", _INIT_GPIO(GPF1_)); // 22222222 printf("%x\n", _INIT_GPIO(GPF2_)); // 11111111 printf("%x\n", _INIT_GPIO(GPF3_)); // 0 printf("%x\n", _INIT_GPIO(GPG0_)); // 0 printf("%x\n", _INIT_GPIO(GPG1_)); // 0 printf("%x\n", _INIT_GPIO(GPG2_)); // 0 printf("%x\n", _INIT_GPIO(GPG3_)); // 0 printf("%x\n", _INIT_GPIO(GPH0_)); // ERR printf("%x\n", _INIT_GPIO(GPH1_)); // ERR printf("%x\n", _INIT_GPIO(GPH2_)); // ERR printf("%x\n", _INIT_GPIO(GPH3_)); printf("%x\n", _INIT_GPIO(GPI_)); // 0 printf("%x\n", _INIT_GPIO(GPJ0_)); // 0 printf("%x\n", _INIT_GPIO(GPJ1_)); // 0 printf("%x\n", _INIT_GPIO(GPJ2_)); // ff printf("%x\n", _INIT_GPIO(GPJ3_)); // ff printf("%x\n", _INIT_GPIO(GPJ4_)); // 0 printf("%x\n", _INIT_GPIO(GPK0_)); // 0 printf("%x\n", _INIT_GPIO(GPK1_)); // 0 printf("%x\n", _INIT_GPIO(GPK2_)); // 0 printf("%x\n", _INIT_GPIO(GPK3_)); // 200100 printf("%x\n", _INIT_GPIO(GPL0_)); // 0 printf("%x\n", _INIT_GPIO(GPL1_)); // 0 printf("%x\n", _INIT_GPIO(GPL2_)); // 0 printf("%x\n", _INIT_GPIO(GPL3_)); // 0 printf("%x\n", _INIT_GPIO(GPL4_)); // 0 printf(" \n"); printf("%x\n", GPIO_PULL(GPA0_)); // 5555 printf("%x\n", GPIO_PULL(GPA1_)); // 1695 printf("%x\n", GPIO_PULL(GPB_)); // 5555 printf("%x\n", GPIO_PULL(GPC_)); // 5 printf("%x\n", GPIO_PULL(GPD_)); // 5555 printf("%x\n", GPIO_PULL(GPE0_)); // 55 printf("%x\n", GPIO_PULL(GPE1_)); // 885 printf("%x\n", GPIO_PULL(GPF0_)); // 0 printf("%x\n", GPIO_PULL(GPF1_)); // 0 printf("%x\n", GPIO_PULL(GPF2_)); // 0 printf("%x\n", GPIO_PULL(GPF3_)); // 8555 printf("%x\n", GPIO_PULL(GPG0_)); // 8555 printf("%x\n", GPIO_PULL(GPG1_)); // 0 printf("%x\n", GPIO_PULL(GPG2_)); // 0 printf("%x\n", GPIO_PULL(GPG3_)); // 0 printf("%x\n", GPIO_PULL(GPH0_)); // ERR printf("%x\n", GPIO_PULL(GPH1_)); // ERR printf("%x\n", GPIO_PULL(GPH2_)); // ERR printf("%x\n", GPIO_PULL(GPH3_)); printf("%x\n", GPIO_PULL(GPI_)); // 0 printf("%x\n", GPIO_PULL(GPJ0_)); // 0 printf("%x\n", GPIO_PULL(GPJ1_)); // 0 printf("%x\n", GPIO_PULL(GPJ2_)); // ff printf("%x\n", GPIO_PULL(GPJ3_)); // ff printf("%x\n", GPIO_PULL(GPJ4_)); // 0 printf("%x\n", GPIO_PULL(GPK0_)); // 0 printf("%x\n", GPIO_PULL(GPK1_)); // 0 printf("%x\n", GPIO_PULL(GPK2_)); // 0 printf("%x\n", GPIO_PULL(GPK3_)); // 5955 printf("%x\n", GPIO_PULL(GPL0_)); // 0 printf("%x\n", GPIO_PULL(GPL1_)); // 0 printf("%x\n", GPIO_PULL(GPL2_)); // 0 printf("%x\n", GPIO_PULL(GPL3_)); // 0 printf("%x\n", GPIO_PULL(GPL4_)); // 0 printf(" \n"); printf("%x\n", _INIT_GPIO(GPA0_)); // 22222222 printf("%x\n", _INIT_GPIO(GPA1_)); // 22022 printf("%x\n", _INIT_GPIO(GPB_)); // 22222222 printf("%x\n", _INIT_GPIO(GPC_)); // 200 printf("%x\n", _INIT_GPIO(GPD_)); // 0 printf("%x\n", _INIT_GPIO(GPE0_)); // 0 printf("%x\n", _INIT_GPIO(GPE1_)); // 44444444 printf("%x\n", _INIT_GPIO(GPF0_)); // 22222222 printf("%x\n", _INIT_GPIO(GPF1_)); // 0 printf("%x\n", _INIT_GPIO(GPF2_)); // 0 printf("%x\n", _INIT_GPIO(GPF3_)); // 8555 printf("%x\n", _INIT_GPIO(GPG0_)); // 8555 printf("%x\n", _INIT_GPIO(GPG1_)); // 0 printf("%x\n", _INIT_GPIO(GPG2_)); // 0 printf("%x\n", _INIT_GPIO(GPG3_)); // 0 printf("%x\n", _INIT_GPIO(GPH0_)); // ERR printf("%x\n", _INIT_GPIO(GPH1_)); // ERR printf("%x\n", _INIT_GPIO(GPH2_)); // ERR printf("%x\n", _INIT_GPIO(GPH3_)); printf("%x\n", _INIT_GPIO(GPI_)); // 0 printf("%x\n", _INIT_GPIO(GPJ0_)); // 0 printf("%x\n", _INIT_GPIO(GPJ1_)); // 0 printf("%x\n", _INIT_GPIO(GPJ2_)); // ff printf("%x\n", _INIT_GPIO(GPJ3_)); // ff printf("%x\n", _INIT_GPIO(GPJ4_)); // 0 printf("%x\n", _INIT_GPIO(GPK0_)); // 0 printf("%x\n", _INIT_GPIO(GPK1_)); // 0 printf("%x\n", _INIT_GPIO(GPK2_)); // 0 printf("%x\n", _INIT_GPIO(GPK3_)); // 200100 printf("%x\n", _INIT_GPIO(GPL0_)); // 0 printf("%x\n", _INIT_GPIO(GPL1_)); // 0 printf("%x\n", _INIT_GPIO(GPL2_)); // 0 printf("%x\n", _INIT_GPIO(GPL3_)); // 0 printf("%x\n", _INIT_GPIO(GPL4_)); // 0 munmap((caddr_t)gpio_map, BLOCK_SIZE); return 0; }