| 
									
										
										
										
											2011-04-25 01:09:05 +03:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * common-board-devices.c | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Copyright (C) 2011 CompuLab, Ltd. | 
					
						
							|  |  |  |  * Author: Mike Rapoport <mike@compulab.co.il> | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is free software; you can redistribute it and/or | 
					
						
							|  |  |  |  * modify it under the terms of the GNU General Public License | 
					
						
							|  |  |  |  * version 2 as published by the Free Software Foundation. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is distributed in the hope that it will be useful, but | 
					
						
							|  |  |  |  * WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU | 
					
						
							|  |  |  |  * General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  |  * along with this program; if not, write to the Free Software | 
					
						
							|  |  |  |  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | 
					
						
							|  |  |  |  * 02110-1301 USA | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <linux/gpio.h>
 | 
					
						
							|  |  |  | #include <linux/spi/spi.h>
 | 
					
						
							|  |  |  | #include <linux/spi/ads7846.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-24 15:21:06 +02:00
										 |  |  | #include <linux/platform_data/spi-omap2-mcspi.h>
 | 
					
						
							| 
									
										
										
										
											2011-04-25 01:09:05 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-27 17:43:01 -07:00
										 |  |  | #include "common.h"
 | 
					
						
							| 
									
										
										
										
											2011-04-25 01:09:05 +03:00
										 |  |  | #include "common-board-devices.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-25 01:09:07 +03:00
										 |  |  | #if defined(CONFIG_TOUCHSCREEN_ADS7846) || \
 | 
					
						
							|  |  |  | 	defined(CONFIG_TOUCHSCREEN_ADS7846_MODULE) | 
					
						
							| 
									
										
										
										
											2011-04-25 01:09:05 +03:00
										 |  |  | static struct omap2_mcspi_device_config ads7846_mcspi_config = { | 
					
						
							|  |  |  | 	.turbo_mode	= 0, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static struct ads7846_platform_data ads7846_config = { | 
					
						
							|  |  |  | 	.x_max			= 0x0fff, | 
					
						
							|  |  |  | 	.y_max			= 0x0fff, | 
					
						
							|  |  |  | 	.x_plate_ohms		= 180, | 
					
						
							|  |  |  | 	.pressure_max		= 255, | 
					
						
							|  |  |  | 	.debounce_max		= 10, | 
					
						
							|  |  |  | 	.debounce_tol		= 3, | 
					
						
							|  |  |  | 	.debounce_rep		= 1, | 
					
						
							|  |  |  | 	.gpio_pendown		= -EINVAL, | 
					
						
							|  |  |  | 	.keep_vref_on		= 1, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static struct spi_board_info ads7846_spi_board_info __initdata = { | 
					
						
							|  |  |  | 	.modalias		= "ads7846", | 
					
						
							|  |  |  | 	.bus_num		= -EINVAL, | 
					
						
							|  |  |  | 	.chip_select		= 0, | 
					
						
							|  |  |  | 	.max_speed_hz		= 1500000, | 
					
						
							|  |  |  | 	.controller_data	= &ads7846_mcspi_config, | 
					
						
							|  |  |  | 	.irq			= -EINVAL, | 
					
						
							|  |  |  | 	.platform_data		= &ads7846_config, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void __init omap_ads7846_init(int bus_num, int gpio_pendown, int gpio_debounce, | 
					
						
							|  |  |  | 			      struct ads7846_platform_data *board_pdata) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct spi_board_info *spi_bi = &ads7846_spi_board_info; | 
					
						
							|  |  |  | 	int err; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-20 23:00:51 -08:00
										 |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * If a board defines get_pendown_state() function, request the pendown | 
					
						
							|  |  |  | 	 * GPIO and set the GPIO debounce time. | 
					
						
							|  |  |  | 	 * If a board does not define the get_pendown_state() function, then | 
					
						
							|  |  |  | 	 * the ads7846 driver will setup the pendown GPIO itself. | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	if (board_pdata && board_pdata->get_pendown_state) { | 
					
						
							|  |  |  | 		err = gpio_request_one(gpio_pendown, GPIOF_IN, "TSPenDown"); | 
					
						
							|  |  |  | 		if (err) { | 
					
						
							|  |  |  | 			pr_err("Couldn't obtain gpio for TSPenDown: %d\n", err); | 
					
						
							|  |  |  | 			return; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (gpio_debounce) | 
					
						
							|  |  |  | 			gpio_set_debounce(gpio_pendown, gpio_debounce); | 
					
						
							| 
									
										
										
										
											2011-04-25 01:09:05 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-20 23:00:51 -08:00
										 |  |  | 		gpio_export(gpio_pendown, 0); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-06-21 01:36:02 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-25 01:09:05 +03:00
										 |  |  | 	spi_bi->bus_num	= bus_num; | 
					
						
							| 
									
										
										
										
											2012-03-29 08:41:01 -07:00
										 |  |  | 	spi_bi->irq	= gpio_to_irq(gpio_pendown); | 
					
						
							| 
									
										
										
										
											2011-04-25 01:09:05 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-20 23:00:51 -08:00
										 |  |  | 	ads7846_config.gpio_pendown = gpio_pendown; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-05 16:11:02 -08:00
										 |  |  | 	if (board_pdata) { | 
					
						
							|  |  |  | 		board_pdata->gpio_pendown = gpio_pendown; | 
					
						
							| 
									
										
										
										
											2012-11-20 23:00:51 -08:00
										 |  |  | 		board_pdata->gpio_pendown_debounce = gpio_debounce; | 
					
						
							| 
									
										
										
										
											2011-04-25 01:09:05 +03:00
										 |  |  | 		spi_bi->platform_data = board_pdata; | 
					
						
							| 
									
										
										
										
											2012-03-05 16:11:02 -08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-04-25 01:09:05 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	spi_register_board_info(&ads7846_spi_board_info, 1); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2011-04-25 01:09:07 +03:00
										 |  |  | #else
 | 
					
						
							|  |  |  | void __init omap_ads7846_init(int bus_num, int gpio_pendown, int gpio_debounce, | 
					
						
							|  |  |  | 			      struct ads7846_platform_data *board_pdata) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #endif
 |