blob: ad856092c06aa889c149a70142f0397573b26a8a [file] [log] [blame]
Mike Rapoport96974a22011-04-25 01:09:05 +03001/*
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
Arnd Bergmann22037472012-08-24 15:21:06 +020027#include <linux/platform_data/spi-omap2-mcspi.h>
Mike Rapoport96974a22011-04-25 01:09:05 +030028
Tony Lindgren7d7e1eb2012-08-27 17:43:01 -070029#include "common.h"
Mike Rapoport96974a22011-04-25 01:09:05 +030030#include "common-board-devices.h"
31
Mike Rapoport9a3f39f2011-04-25 01:09:07 +030032#if defined(CONFIG_TOUCHSCREEN_ADS7846) || \
33 defined(CONFIG_TOUCHSCREEN_ADS7846_MODULE)
Mike Rapoport96974a22011-04-25 01:09:05 +030034static struct omap2_mcspi_device_config ads7846_mcspi_config = {
35 .turbo_mode = 0,
Mike Rapoport96974a22011-04-25 01:09:05 +030036};
37
38static 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
50static 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
60void __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
Igor Grinberg97ee9f012012-06-21 01:36:02 -070066 err = gpio_request_one(gpio_pendown, GPIOF_IN, "TSPenDown");
67 if (err) {
68 pr_err("Couldn't obtain gpio for TSPenDown: %d\n", err);
69 return;
Mike Rapoport96974a22011-04-25 01:09:05 +030070 }
71
Igor Grinberg97ee9f012012-06-21 01:36:02 -070072 if (gpio_debounce)
73 gpio_set_debounce(gpio_pendown, gpio_debounce);
74
Mike Rapoport96974a22011-04-25 01:09:05 +030075 spi_bi->bus_num = bus_num;
Tarun Kanti DebBarma46a0a542012-03-29 08:41:01 -070076 spi_bi->irq = gpio_to_irq(gpio_pendown);
Mike Rapoport96974a22011-04-25 01:09:05 +030077
Ilya Yanok7db74d52012-03-05 16:11:02 -080078 if (board_pdata) {
79 board_pdata->gpio_pendown = gpio_pendown;
Mike Rapoport96974a22011-04-25 01:09:05 +030080 spi_bi->platform_data = board_pdata;
Igor Grinberg97ee9f012012-06-21 01:36:02 -070081 if (board_pdata->get_pendown_state)
82 gpio_export(gpio_pendown, 0);
Ilya Yanok7db74d52012-03-05 16:11:02 -080083 } else {
84 ads7846_config.gpio_pendown = gpio_pendown;
85 }
Mike Rapoport96974a22011-04-25 01:09:05 +030086
Igor Grinberg97ee9f012012-06-21 01:36:02 -070087 if (!board_pdata || (board_pdata && !board_pdata->get_pendown_state))
88 gpio_free(gpio_pendown);
89
Mike Rapoport96974a22011-04-25 01:09:05 +030090 spi_register_board_info(&ads7846_spi_board_info, 1);
91}
Mike Rapoport9a3f39f2011-04-25 01:09:07 +030092#else
93void __init omap_ads7846_init(int bus_num, int gpio_pendown, int gpio_debounce,
94 struct ads7846_platform_data *board_pdata)
95{
96}
97#endif