Merge branch 'devel' of master.kernel.org:/home/rmk/linux-2.6-arm
[pandora-kernel.git] / arch / arm / mach-ux500 / board-mop500-stuib.c
1 /*
2  * Copyright (C) ST-Ericsson SA 2010
3  *
4  * License terms: GNU General Public License (GPL), version 2
5  */
6
7 #include <linux/kernel.h>
8 #include <linux/init.h>
9 #include <linux/mfd/stmpe.h>
10 #include <linux/input/bu21013.h>
11 #include <linux/gpio.h>
12 #include <linux/interrupt.h>
13 #include <linux/i2c.h>
14 #include <linux/input/matrix_keypad.h>
15 #include <asm/mach-types.h>
16
17 #include "board-mop500.h"
18
19 /* STMPE/SKE keypad use this key layout */
20 static const unsigned int mop500_keymap[] = {
21         KEY(2, 5, KEY_END),
22         KEY(4, 1, KEY_POWER),
23         KEY(3, 5, KEY_VOLUMEDOWN),
24         KEY(1, 3, KEY_3),
25         KEY(5, 2, KEY_RIGHT),
26         KEY(5, 0, KEY_9),
27
28         KEY(0, 5, KEY_MENU),
29         KEY(7, 6, KEY_ENTER),
30         KEY(4, 5, KEY_0),
31         KEY(6, 7, KEY_2),
32         KEY(3, 4, KEY_UP),
33         KEY(3, 3, KEY_DOWN),
34
35         KEY(6, 4, KEY_SEND),
36         KEY(6, 2, KEY_BACK),
37         KEY(4, 2, KEY_VOLUMEUP),
38         KEY(5, 5, KEY_1),
39         KEY(4, 3, KEY_LEFT),
40         KEY(3, 2, KEY_7),
41 };
42
43 static const struct matrix_keymap_data mop500_keymap_data = {
44         .keymap         = mop500_keymap,
45         .keymap_size    = ARRAY_SIZE(mop500_keymap),
46 };
47 /*
48  * STMPE1601
49  */
50 static struct stmpe_keypad_platform_data stmpe1601_keypad_data = {
51         .debounce_ms    = 64,
52         .scan_count     = 8,
53         .no_autorepeat  = true,
54         .keymap_data    = &mop500_keymap_data,
55 };
56
57 static struct stmpe_platform_data stmpe1601_data = {
58         .id             = 1,
59         .blocks         = STMPE_BLOCK_KEYPAD,
60         .irq_trigger    = IRQF_TRIGGER_FALLING,
61         .irq_base       = MOP500_STMPE1601_IRQ(0),
62         .keypad         = &stmpe1601_keypad_data,
63         .autosleep      = true,
64         .autosleep_timeout = 1024,
65 };
66
67 static struct i2c_board_info __initdata mop500_i2c0_devices_stuib[] = {
68         {
69                 I2C_BOARD_INFO("stmpe1601", 0x40),
70                 .irq = NOMADIK_GPIO_TO_IRQ(218),
71                 .platform_data = &stmpe1601_data,
72                 .flags = I2C_CLIENT_WAKE,
73         },
74 };
75
76 /*
77  * BU21013 ROHM touchscreen interface on the STUIBs
78  */
79
80 /* tracks number of bu21013 devices being enabled */
81 static int bu21013_devices;
82
83 #define TOUCH_GPIO_PIN  84
84
85 #define TOUCH_XMAX      384
86 #define TOUCH_YMAX      704
87
88 #define PRCMU_CLOCK_OCR         0x1CC
89 #define TSC_EXT_CLOCK_9_6MHZ    0x840000
90
91 /**
92  * bu21013_gpio_board_init : configures the touch panel.
93  * @reset_pin: reset pin number
94  * This function can be used to configures
95  * the voltage and reset the touch panel controller.
96  */
97 static int bu21013_gpio_board_init(int reset_pin)
98 {
99         int retval = 0;
100
101         bu21013_devices++;
102         if (bu21013_devices == 1) {
103                 retval = gpio_request(reset_pin, "touchp_reset");
104                 if (retval) {
105                         printk(KERN_ERR "Unable to request gpio reset_pin");
106                         return retval;
107                 }
108                 retval = gpio_direction_output(reset_pin, 1);
109                 if (retval < 0) {
110                         printk(KERN_ERR "%s: gpio direction failed\n",
111                                         __func__);
112                         return retval;
113                 }
114         }
115
116         return retval;
117 }
118
119 /**
120  * bu21013_gpio_board_exit : deconfigures the touch panel controller
121  * @reset_pin: reset pin number
122  * This function can be used to deconfigures the chip selection
123  * for touch panel controller.
124  */
125 static int bu21013_gpio_board_exit(int reset_pin)
126 {
127         int retval = 0;
128
129         if (bu21013_devices == 1) {
130                 retval = gpio_direction_output(reset_pin, 0);
131                 if (retval < 0) {
132                         printk(KERN_ERR "%s: gpio direction failed\n",
133                                         __func__);
134                         return retval;
135                 }
136                 gpio_set_value(reset_pin, 0);
137         }
138         bu21013_devices--;
139
140         return retval;
141 }
142
143 /**
144  * bu21013_read_pin_val : get the interrupt pin value
145  * This function can be used to get the interrupt pin value for touch panel
146  * controller.
147  */
148 static int bu21013_read_pin_val(void)
149 {
150         return gpio_get_value(TOUCH_GPIO_PIN);
151 }
152
153 static struct bu21013_platform_device tsc_plat_device = {
154         .cs_en = bu21013_gpio_board_init,
155         .cs_dis = bu21013_gpio_board_exit,
156         .irq_read_val = bu21013_read_pin_val,
157         .irq = NOMADIK_GPIO_TO_IRQ(TOUCH_GPIO_PIN),
158         .touch_x_max = TOUCH_XMAX,
159         .touch_y_max = TOUCH_YMAX,
160         .ext_clk = false,
161         .x_flip = false,
162         .y_flip = true,
163 };
164
165 static struct bu21013_platform_device tsc_plat2_device = {
166         .cs_en = bu21013_gpio_board_init,
167         .cs_dis = bu21013_gpio_board_exit,
168         .irq_read_val = bu21013_read_pin_val,
169         .irq = NOMADIK_GPIO_TO_IRQ(TOUCH_GPIO_PIN),
170         .touch_x_max = TOUCH_XMAX,
171         .touch_y_max = TOUCH_YMAX,
172         .ext_clk = false,
173         .x_flip = false,
174         .y_flip = true,
175 };
176
177 static struct i2c_board_info __initdata u8500_i2c3_devices_stuib[] = {
178         {
179                 I2C_BOARD_INFO("bu21013_tp", 0x5C),
180                 .platform_data = &tsc_plat_device,
181         },
182         {
183                 I2C_BOARD_INFO("bu21013_tp", 0x5D),
184                 .platform_data = &tsc_plat2_device,
185         },
186
187 };
188
189 void __init mop500_stuib_init(void)
190 {
191         if (machine_is_hrefv60()) {
192                 tsc_plat_device.cs_pin = HREFV60_TOUCH_RST_GPIO;
193                 tsc_plat2_device.cs_pin = HREFV60_TOUCH_RST_GPIO;
194         } else {
195                 tsc_plat_device.cs_pin = GPIO_BU21013_CS;
196                 tsc_plat2_device.cs_pin = GPIO_BU21013_CS;
197
198         }
199
200         mop500_uib_i2c_add(0, mop500_i2c0_devices_stuib,
201                         ARRAY_SIZE(mop500_i2c0_devices_stuib));
202
203         mop500_uib_i2c_add(3, u8500_i2c3_devices_stuib,
204                         ARRAY_SIZE(u8500_i2c3_devices_stuib));
205 }