ARM: SPRD: fix build warnings for sc8830
[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         return 0;
45 }
46
47 static  int __mfp_validate(unsigned long c)
48 {
49         return 1;
50 }
51
52 static unsigned long __mfp_get_pin_reg(int pin_offset)
53 {
54         if (!(pin_offset & A_DIE_PIN)) {
55                 return (unsigned long)SPRD_PIN_PHYS + pin_offset;
56         } else {
57 //              pin_offset &= ~A_DIE_PIN;
58 //              return (unsigned long)ANA_PIN_CTL_BASE + pin_offset;
59         }
60         return 0;
61 }
62
63 #ifdef DEBUG
64 #define MFP_DBG(fmt...) pr_debug(fmt)
65 #else
66 #define MFP_DBG(fmt...)
67 #endif
68
69 static int __mfp_config_pin(unsigned long c)
70 {
71         unsigned long pin_reg;
72         unsigned long pin_cfg;
73         int pin_offset;
74
75         pin_offset = MFP_CFG_TO_REG_OFFS(c);
76         pin_reg = __mfp_get_pin_reg(pin_offset);
77
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));
81
82         //local_irq_save(flags);
83         pin_cfg =__raw_readl(pin_reg);
84         if (c & MFP_IO_SET) {
85                 pin_cfg = (pin_cfg & ~MFP_IO_MASK) | (c & MFP_IO_MASK);
86         }
87
88         if (c & MFP_S_PULL_SET) {
89                 pin_cfg = (pin_cfg & ~MFP_S_PULL_MASK) | (c & MFP_S_PULL_MASK);
90         }
91
92         if (c & MFP_AF_SET) {
93                 pin_cfg = (pin_cfg & ~MFP_AF_MASK) | (c & MFP_AF_MASK);
94         }
95
96         if (c & MFP_F_PULL_SET) {
97                 pin_cfg = (pin_cfg & ~MFP_F_PULL_MASK) | (c & MFP_F_PULL_MASK);
98         }
99
100         if (c & MFP_DS_SET) {
101                 pin_cfg = (pin_cfg & ~MFP_DS_MASK) | (c & MFP_DS_MASK);
102         }
103
104         __raw_writel(pin_cfg, pin_reg);
105 //      local_irq_restore(flags);
106
107         MFP_DBG("new config is :%x\r\n", (int)pin_cfg);
108
109         return 0;
110 }
111
112 void sprd_mfp_config(unsigned long *mfp_cfgs, int num)
113 {
114         unsigned long *c;
115         int res;
116         int i;
117
118         for (i = 0, c = mfp_cfgs; i < num; i++, c++) {
119
120                 res = __mfp_validate((*c));
121                 if (res < 0)
122                         continue;
123
124         //      local_irq_save(flags);
125
126                 __mfp_config_pin(*c);
127
128         //      local_irq_restore(flags);
129         }
130 }
131 //EXPORT_SYMBOL_GPL(sprd_mfp_config);