2 * common-board-devices.c
4 * Copyright (C) 2011 CompuLab, Ltd.
5 * Author: Mike Rapoport <mike@compulab.co.il>
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.
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.
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
23 #include <linux/gpio.h>
24 #include <linux/spi/spi.h>
25 #include <linux/spi/ads7846.h>
27 #include <linux/platform_data/spi-omap2-mcspi.h>
30 #include "common-board-devices.h"
32 #if IS_ENABLED(CONFIG_TOUCHSCREEN_ADS7846)
33 static struct omap2_mcspi_device_config ads7846_mcspi_config
= {
37 static struct ads7846_platform_data ads7846_config
= {
45 .gpio_pendown
= -EINVAL
,
49 static struct spi_board_info ads7846_spi_board_info __initdata
= {
50 .modalias
= "ads7846",
53 .max_speed_hz
= 1500000,
54 .controller_data
= &ads7846_mcspi_config
,
56 .platform_data
= &ads7846_config
,
59 void __init
omap_ads7846_init(int bus_num
, int gpio_pendown
, int gpio_debounce
,
60 struct ads7846_platform_data
*board_pdata
)
62 struct spi_board_info
*spi_bi
= &ads7846_spi_board_info
;
66 * If a board defines get_pendown_state() function, request the pendown
67 * GPIO and set the GPIO debounce time.
68 * If a board does not define the get_pendown_state() function, then
69 * the ads7846 driver will setup the pendown GPIO itself.
71 if (board_pdata
&& board_pdata
->get_pendown_state
) {
72 err
= gpio_request_one(gpio_pendown
, GPIOF_IN
, "TSPenDown");
74 pr_err("Couldn't obtain gpio for TSPenDown: %d\n", err
);
79 gpio_set_debounce(gpio_pendown
, gpio_debounce
);
81 gpio_export(gpio_pendown
, 0);
84 spi_bi
->bus_num
= bus_num
;
85 spi_bi
->irq
= gpio_to_irq(gpio_pendown
);
87 ads7846_config
.gpio_pendown
= gpio_pendown
;
90 board_pdata
->gpio_pendown
= gpio_pendown
;
91 board_pdata
->gpio_pendown_debounce
= gpio_debounce
;
92 spi_bi
->platform_data
= board_pdata
;
95 spi_register_board_info(&ads7846_spi_board_info
, 1);
98 void __init
omap_ads7846_init(int bus_num
, int gpio_pendown
, int gpio_debounce
,
99 struct ads7846_platform_data
*board_pdata
)