change source file mode to 0644 instead of 0755
[profile/mobile/platform/kernel/u-boot-tm1.git] / arch / arm / cpu / armv7 / sc8830 / mfp_sprd.c
1 /*
2  *  linux/arch/arm/mach-sc8800s/mfp-sprd.c
3  *
4  *  Spreadtrum SoC multi-function pin configuration support
5  *
6  *  The GPIOs on SoC can be configured as one of many alternate
7  *  functions,
8  *
9  *  Author:     Yingchun Li(yingchun.li@spreadtrum.com)
10  *  Created:    March 10, 2010
11  *  Copyright:  Spreadtrum Inc.
12  *
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.
16 */
17 //#define DEBUG
18
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>
23 #include <common.h>
24 #include <asm/io.h>
25
26 /*
27 NOTE: pin to gpio's map, you should check it from your chip's spec
28         carefully.
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
31
32 const static unsigned long pin_gpio_map[MFP_PIN_MAX] = {
33         [MFP_PIN_MAX - 1] = 0xffff
34 };
35
36 */
37
38 /*
39         we cann't find a easy way to map pin to gpio, so drop it.
40 */
41 unsigned long mfp_to_gpio(int pin)
42 {
43         BUG_ON(1);
44 }
45
46 static  int __mfp_validate(unsigned long c)
47 {
48         return 1;
49 }
50
51 static unsigned long __mfp_get_pin_reg(int pin_offset)
52 {
53         if (!(pin_offset & A_DIE_PIN)) {
54                 return (unsigned long)SPRD_PIN_PHYS + pin_offset;
55         } else {
56 //              pin_offset &= ~A_DIE_PIN;
57 //              return (unsigned long)ANA_PIN_CTL_BASE + pin_offset;
58         }
59         return 0;
60 }
61
62 #ifdef DEBUG
63 #define MFP_DBG(fmt...) pr_debug(fmt)
64 #else
65 #define MFP_DBG(fmt...)
66 #endif
67
68 static int __mfp_config_pin(unsigned long c)
69 {
70         unsigned long pin_reg;
71         unsigned long pin_cfg;
72         int pin_offset;
73
74         pin_offset = MFP_CFG_TO_REG_OFFS(c);
75         pin_reg = __mfp_get_pin_reg(pin_offset);
76
77         MFP_DBG("register is :0x%x, old config is %x\r\n",
78                 __mfp_get_pin_reg(pin_offset),
79                 __raw_readl(pin_reg));
80
81         //local_irq_save(flags);
82         pin_cfg =__raw_readl(pin_reg);
83         if (c & MFP_IO_SET) {
84                 pin_cfg = (pin_cfg & ~MFP_IO_MASK) | (c & MFP_IO_MASK);
85         }
86
87         if (c & MFP_S_PULL_SET) {
88                 pin_cfg = (pin_cfg & ~MFP_S_PULL_MASK) | (c & MFP_S_PULL_MASK);
89         }
90
91         if (c & MFP_AF_SET) {
92                 pin_cfg = (pin_cfg & ~MFP_AF_MASK) | (c & MFP_AF_MASK);
93         }
94
95         if (c & MFP_F_PULL_SET) {
96                 pin_cfg = (pin_cfg & ~MFP_F_PULL_MASK) | (c & MFP_F_PULL_MASK);
97         }
98
99         if (c & MFP_DS_SET) {
100                 pin_cfg = (pin_cfg & ~MFP_DS_MASK) | (c & MFP_DS_MASK);
101         }
102
103         __raw_writel(pin_cfg, pin_reg);
104 //      local_irq_restore(flags);
105
106         MFP_DBG("new config is :%x\r\n", (int)pin_cfg);
107
108         return 0;
109 }
110
111 static unsigned long spi_cs1_gpio_cfg = MFP_CFG_X(SPI_CSN0, GPIO, DS1, F_PULL_NONE, S_PULL_DOWN, IO_NONE);
112
113 void sprd_mfp_config(unsigned long *mfp_cfgs, int num)
114 {
115         unsigned long *c;
116         int res;
117         int i;
118
119         for (i = 0, c = mfp_cfgs; i < num; i++, c++) {
120
121                 res = __mfp_validate((*c));
122                 if (res < 0)
123                         continue;
124
125         //      local_irq_save(flags);
126
127                 __mfp_config_pin(*c);
128
129         //      local_irq_restore(flags);
130         }
131 }
132 //EXPORT_SYMBOL_GPL(sprd_mfp_config);