f9b43447183a7e090e7d07b168d965c16290a29a
[linux-2.6.git] / arch / arm / mach-tegra / board-touch-kai-synaptics-spi.c
1 /*
2  * arch/arm/mach-tegra/board-touch-synaptics-spi.c
3  *
4  * Copyright (C) 2010-2012 NVIDIA Corporation
5  *
6  * This software is licensed under the terms of the GNU General Public
7  * License version 2, as published by the Free Software Foundation, and
8  * may be copied, distributed, and modified under those terms.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  */
16
17 #include <linux/kernel.h>
18 #include <linux/spi/spi.h>
19 #include <linux/delay.h>
20 #include <linux/gpio.h>
21 #include <linux/input.h>
22 #include <linux/interrupt.h>
23 #include <linux/spi/spi.h>
24 #include <linux/rmi.h>
25
26 #include <mach/gpio-tegra.h>
27
28 #include "board.h"
29 #include "board-kai.h"
30
31 #define SYNAPTICS_SPI_CS 0
32 #define SYNAPTICS_BUTTON_CODES {KEY_HOME, KEY_BACK,}
33
34 static unsigned char synaptics_button_codes[] = SYNAPTICS_BUTTON_CODES;
35
36 static struct rmi_f19_button_map synaptics_button_map = {
37         .nbuttons = ARRAY_SIZE(synaptics_button_codes),
38         .map = synaptics_button_codes,
39 };
40
41 static int synaptics_touchpad_gpio_setup(void *gpio_data, bool configure)
42 {
43         if (configure) {
44                 gpio_request(SYNAPTICS_ATTN_GPIO, "synaptics-irq");
45                 gpio_direction_input(SYNAPTICS_ATTN_GPIO);
46
47                 gpio_request(SYNAPTICS_RESET_GPIO, "synaptics-reset");
48                 gpio_direction_output(SYNAPTICS_RESET_GPIO, 0);
49
50                 msleep(1);
51                 gpio_set_value(SYNAPTICS_RESET_GPIO, 1);
52                 msleep(100);
53         } else {
54                 gpio_free(SYNAPTICS_ATTN_GPIO);
55                 gpio_free(SYNAPTICS_RESET_GPIO);
56         }
57         return 0;
58 }
59
60 static struct rmi_device_platform_data synaptics_platformdata = {
61         .driver_name = "rmi_generic",
62         .irq = SYNAPTICS_ATTN_GPIO,
63         .irq_polarity = RMI_IRQ_ACTIVE_LOW,
64         .gpio_config = synaptics_touchpad_gpio_setup,
65         .spi_data = {
66                 .block_delay_us = 15,
67                 .read_delay_us = 15,
68                 .write_delay_us = 2,
69         },
70         .axis_align = {
71                 .flip_y = true,
72         },
73         .button_map = &synaptics_button_map,
74 };
75
76 struct spi_board_info synaptics_2002_spi_board[] = {
77         {
78                 .modalias = "rmi_spi",
79                 .bus_num = 0,
80                 .chip_select = 0,
81                 .irq = 999,  /* just to make sure this one is not being used */
82                 .max_speed_hz = 1*1000*1000,
83                 .mode = SPI_MODE_3,
84                 .platform_data = &synaptics_platformdata,
85         },
86 };
87
88 int __init touch_init_synaptics_kai(void)
89 {
90         pr_info("%s: registering synaptics_2002_spi_board\n", __func__);
91         pr_info("               modalias     = %s\n",
92                                         synaptics_2002_spi_board->modalias);
93         pr_info("               bus_num      = %d\n",
94                                         synaptics_2002_spi_board->bus_num);
95         pr_info("               chip_select  = %d\n",
96                                         synaptics_2002_spi_board->chip_select);
97         pr_info("               irq          = %d\n",
98                                         synaptics_2002_spi_board->irq);
99         pr_info("               max_speed_hz = %d\n",
100                                         synaptics_2002_spi_board->max_speed_hz);
101         pr_info("               mode         = %d\n",
102                                         synaptics_2002_spi_board->mode);
103
104         msleep(100);
105         spi_register_board_info(synaptics_2002_spi_board,
106                                         ARRAY_SIZE(synaptics_2002_spi_board));
107         return 0;
108 }