2 * linux/arch/arm/mach-sc8800s/mfp-sprd.c
4 * Spreadtrum SoC multi-function pin configuration support
6 * The GPIOs on SoC can be configured as one of many alternate
9 * Author: Yingchun Li(yingchun.li@spreadtrum.com)
10 * Created: March 10, 2010
11 * Copyright: Spreadtrum Inc.
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License version 2 as
15 * published by the Free Software Foundation.
19 #include <asm/arch/mfp.h>
20 #include <asm/arch/sprd_reg.h>
21 //#include <asm/arch/analog_reg_v3.h>
22 //#include <asm/arch/regs_adi.h>
27 NOTE: pin to gpio's map, you should check it from your chip's spec
29 in the map table, pin as the index, for mostly we use
30 MFP_PIN_TO_GPIO to get the gpio from the pin
32 const static unsigned long pin_gpio_map[MFP_PIN_MAX] = {
33 [MFP_PIN_MAX - 1] = 0xffff
39 we cann't find a easy way to map pin to gpio, so drop it.
41 unsigned long mfp_to_gpio(int pin)
47 static int __mfp_validate(unsigned long c)
52 static unsigned long __mfp_get_pin_reg(int pin_offset)
54 if (!(pin_offset & A_DIE_PIN)) {
55 return (unsigned long)SPRD_PIN_PHYS + pin_offset;
57 // pin_offset &= ~A_DIE_PIN;
58 // return (unsigned long)ANA_PIN_CTL_BASE + pin_offset;
64 #define MFP_DBG(fmt...) pr_debug(fmt)
66 #define MFP_DBG(fmt...)
69 static int __mfp_config_pin(unsigned long c)
71 unsigned long pin_reg;
72 unsigned long pin_cfg;
75 pin_offset = MFP_CFG_TO_REG_OFFS(c);
76 pin_reg = __mfp_get_pin_reg(pin_offset);
78 MFP_DBG("register is :0x%x, old config is %x\r\n",
79 __mfp_get_pin_reg(pin_offset),
80 __raw_readl(pin_reg));
82 //local_irq_save(flags);
83 pin_cfg =__raw_readl(pin_reg);
85 pin_cfg = (pin_cfg & ~MFP_IO_MASK) | (c & MFP_IO_MASK);
88 if (c & MFP_S_PULL_SET) {
89 pin_cfg = (pin_cfg & ~MFP_S_PULL_MASK) | (c & MFP_S_PULL_MASK);
93 pin_cfg = (pin_cfg & ~MFP_AF_MASK) | (c & MFP_AF_MASK);
96 if (c & MFP_F_PULL_SET) {
97 pin_cfg = (pin_cfg & ~MFP_F_PULL_MASK) | (c & MFP_F_PULL_MASK);
100 if (c & MFP_DS_SET) {
101 pin_cfg = (pin_cfg & ~MFP_DS_MASK) | (c & MFP_DS_MASK);
104 __raw_writel(pin_cfg, pin_reg);
105 // local_irq_restore(flags);
107 MFP_DBG("new config is :%x\r\n", (int)pin_cfg);
112 void sprd_mfp_config(unsigned long *mfp_cfgs, int num)
118 for (i = 0, c = mfp_cfgs; i < num; i++, c++) {
120 res = __mfp_validate((*c));
124 // local_irq_save(flags);
126 __mfp_config_pin(*c);
128 // local_irq_restore(flags);
131 //EXPORT_SYMBOL_GPL(sprd_mfp_config);