Commit | Line | Data |
---|---|---|
96974a24 MR |
1 | /* |
2 | * common-board-devices.c | |
3 | * | |
4 | * Copyright (C) 2011 CompuLab, Ltd. | |
5 | * Author: Mike Rapoport <mike@compulab.co.il> | |
6 | * | |
7 | * This program is free software; you can redistribute it and/or | |
8 | * modify it under the terms of the GNU General Public License | |
9 | * version 2 as published by the Free Software Foundation. | |
10 | * | |
11 | * This program is distributed in the hope that it will be useful, but | |
12 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | * General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with this program; if not, write to the Free Software | |
18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | |
19 | * 02110-1301 USA | |
20 | * | |
21 | */ | |
22 | ||
23 | #include <linux/gpio.h> | |
24 | #include <linux/spi/spi.h> | |
25 | #include <linux/spi/ads7846.h> | |
26 | ||
2203747c | 27 | #include <linux/platform_data/spi-omap2-mcspi.h> |
96974a24 | 28 | |
7d7e1eba | 29 | #include "common.h" |
96974a24 MR |
30 | #include "common-board-devices.h" |
31 | ||
9a3f39ff MR |
32 | #if defined(CONFIG_TOUCHSCREEN_ADS7846) || \ |
33 | defined(CONFIG_TOUCHSCREEN_ADS7846_MODULE) | |
96974a24 MR |
34 | static struct omap2_mcspi_device_config ads7846_mcspi_config = { |
35 | .turbo_mode = 0, | |
96974a24 MR |
36 | }; |
37 | ||
38 | static struct ads7846_platform_data ads7846_config = { | |
39 | .x_max = 0x0fff, | |
40 | .y_max = 0x0fff, | |
41 | .x_plate_ohms = 180, | |
42 | .pressure_max = 255, | |
43 | .debounce_max = 10, | |
44 | .debounce_tol = 3, | |
45 | .debounce_rep = 1, | |
46 | .gpio_pendown = -EINVAL, | |
47 | .keep_vref_on = 1, | |
48 | }; | |
49 | ||
50 | static struct spi_board_info ads7846_spi_board_info __initdata = { | |
51 | .modalias = "ads7846", | |
52 | .bus_num = -EINVAL, | |
53 | .chip_select = 0, | |
54 | .max_speed_hz = 1500000, | |
55 | .controller_data = &ads7846_mcspi_config, | |
56 | .irq = -EINVAL, | |
57 | .platform_data = &ads7846_config, | |
58 | }; | |
59 | ||
60 | void __init omap_ads7846_init(int bus_num, int gpio_pendown, int gpio_debounce, | |
61 | struct ads7846_platform_data *board_pdata) | |
62 | { | |
63 | struct spi_board_info *spi_bi = &ads7846_spi_board_info; | |
64 | int err; | |
65 | ||
0a0d6285 IG |
66 | /* |
67 | * If a board defines get_pendown_state() function, request the pendown | |
68 | * GPIO and set the GPIO debounce time. | |
69 | * If a board does not define the get_pendown_state() function, then | |
70 | * the ads7846 driver will setup the pendown GPIO itself. | |
71 | */ | |
72 | if (board_pdata && board_pdata->get_pendown_state) { | |
73 | err = gpio_request_one(gpio_pendown, GPIOF_IN, "TSPenDown"); | |
74 | if (err) { | |
75 | pr_err("Couldn't obtain gpio for TSPenDown: %d\n", err); | |
76 | return; | |
77 | } | |
78 | ||
79 | if (gpio_debounce) | |
80 | gpio_set_debounce(gpio_pendown, gpio_debounce); | |
96974a24 | 81 | |
0a0d6285 IG |
82 | gpio_export(gpio_pendown, 0); |
83 | } | |
97ee9f01 | 84 | |
96974a24 | 85 | spi_bi->bus_num = bus_num; |
46a0a540 | 86 | spi_bi->irq = gpio_to_irq(gpio_pendown); |
96974a24 | 87 | |
0a0d6285 IG |
88 | ads7846_config.gpio_pendown = gpio_pendown; |
89 | ||
7db74d5e IY |
90 | if (board_pdata) { |
91 | board_pdata->gpio_pendown = gpio_pendown; | |
0a0d6285 | 92 | board_pdata->gpio_pendown_debounce = gpio_debounce; |
96974a24 | 93 | spi_bi->platform_data = board_pdata; |
7db74d5e | 94 | } |
96974a24 MR |
95 | |
96 | spi_register_board_info(&ads7846_spi_board_info, 1); | |
97 | } | |
9a3f39ff MR |
98 | #else |
99 | void __init omap_ads7846_init(int bus_num, int gpio_pendown, int gpio_debounce, | |
100 | struct ads7846_platform_data *board_pdata) | |
101 | { | |
102 | } | |
103 | #endif |