Mike Rapoport | 96974a2 | 2011-04-25 01:09:05 +0300 | [diff] [blame] | 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 | |
Arnd Bergmann | 2203747 | 2012-08-24 15:21:06 +0200 | [diff] [blame] | 27 | #include <linux/platform_data/spi-omap2-mcspi.h> |
| 28 | #include <linux/platform_data/mtd-nand-omap2.h> |
Mike Rapoport | 96974a2 | 2011-04-25 01:09:05 +0300 | [diff] [blame] | 29 | |
Tony Lindgren | 7d7e1eb | 2012-08-27 17:43:01 -0700 | [diff] [blame] | 30 | #include "common.h" |
Mike Rapoport | 96974a2 | 2011-04-25 01:09:05 +0300 | [diff] [blame] | 31 | #include "common-board-devices.h" |
| 32 | |
Mike Rapoport | 9a3f39f | 2011-04-25 01:09:07 +0300 | [diff] [blame] | 33 | #if defined(CONFIG_TOUCHSCREEN_ADS7846) || \ |
| 34 | defined(CONFIG_TOUCHSCREEN_ADS7846_MODULE) |
Mike Rapoport | 96974a2 | 2011-04-25 01:09:05 +0300 | [diff] [blame] | 35 | static struct omap2_mcspi_device_config ads7846_mcspi_config = { |
| 36 | .turbo_mode = 0, |
Mike Rapoport | 96974a2 | 2011-04-25 01:09:05 +0300 | [diff] [blame] | 37 | }; |
| 38 | |
| 39 | static struct ads7846_platform_data ads7846_config = { |
| 40 | .x_max = 0x0fff, |
| 41 | .y_max = 0x0fff, |
| 42 | .x_plate_ohms = 180, |
| 43 | .pressure_max = 255, |
| 44 | .debounce_max = 10, |
| 45 | .debounce_tol = 3, |
| 46 | .debounce_rep = 1, |
| 47 | .gpio_pendown = -EINVAL, |
| 48 | .keep_vref_on = 1, |
| 49 | }; |
| 50 | |
| 51 | static struct spi_board_info ads7846_spi_board_info __initdata = { |
| 52 | .modalias = "ads7846", |
| 53 | .bus_num = -EINVAL, |
| 54 | .chip_select = 0, |
| 55 | .max_speed_hz = 1500000, |
| 56 | .controller_data = &ads7846_mcspi_config, |
| 57 | .irq = -EINVAL, |
| 58 | .platform_data = &ads7846_config, |
| 59 | }; |
| 60 | |
| 61 | void __init omap_ads7846_init(int bus_num, int gpio_pendown, int gpio_debounce, |
| 62 | struct ads7846_platform_data *board_pdata) |
| 63 | { |
| 64 | struct spi_board_info *spi_bi = &ads7846_spi_board_info; |
| 65 | int err; |
| 66 | |
Igor Grinberg | 0a0d628 | 2012-11-20 23:00:51 -0800 | [diff] [blame^] | 67 | /* |
| 68 | * If a board defines get_pendown_state() function, request the pendown |
| 69 | * GPIO and set the GPIO debounce time. |
| 70 | * If a board does not define the get_pendown_state() function, then |
| 71 | * the ads7846 driver will setup the pendown GPIO itself. |
| 72 | */ |
| 73 | if (board_pdata && board_pdata->get_pendown_state) { |
| 74 | err = gpio_request_one(gpio_pendown, GPIOF_IN, "TSPenDown"); |
| 75 | if (err) { |
| 76 | pr_err("Couldn't obtain gpio for TSPenDown: %d\n", err); |
| 77 | return; |
| 78 | } |
Mike Rapoport | 96974a2 | 2011-04-25 01:09:05 +0300 | [diff] [blame] | 79 | |
Igor Grinberg | 0a0d628 | 2012-11-20 23:00:51 -0800 | [diff] [blame^] | 80 | if (gpio_debounce) |
| 81 | gpio_set_debounce(gpio_pendown, gpio_debounce); |
| 82 | |
| 83 | gpio_export(gpio_pendown, 0); |
| 84 | } |
Igor Grinberg | 97ee9f01 | 2012-06-21 01:36:02 -0700 | [diff] [blame] | 85 | |
Mike Rapoport | 96974a2 | 2011-04-25 01:09:05 +0300 | [diff] [blame] | 86 | spi_bi->bus_num = bus_num; |
Tarun Kanti DebBarma | 46a0a54 | 2012-03-29 08:41:01 -0700 | [diff] [blame] | 87 | spi_bi->irq = gpio_to_irq(gpio_pendown); |
Mike Rapoport | 96974a2 | 2011-04-25 01:09:05 +0300 | [diff] [blame] | 88 | |
Igor Grinberg | 0a0d628 | 2012-11-20 23:00:51 -0800 | [diff] [blame^] | 89 | ads7846_config.gpio_pendown = gpio_pendown; |
| 90 | |
Ilya Yanok | 7db74d5 | 2012-03-05 16:11:02 -0800 | [diff] [blame] | 91 | if (board_pdata) { |
| 92 | board_pdata->gpio_pendown = gpio_pendown; |
Igor Grinberg | 0a0d628 | 2012-11-20 23:00:51 -0800 | [diff] [blame^] | 93 | board_pdata->gpio_pendown_debounce = gpio_debounce; |
Mike Rapoport | 96974a2 | 2011-04-25 01:09:05 +0300 | [diff] [blame] | 94 | spi_bi->platform_data = board_pdata; |
Ilya Yanok | 7db74d5 | 2012-03-05 16:11:02 -0800 | [diff] [blame] | 95 | } |
Mike Rapoport | 96974a2 | 2011-04-25 01:09:05 +0300 | [diff] [blame] | 96 | |
| 97 | spi_register_board_info(&ads7846_spi_board_info, 1); |
| 98 | } |
Mike Rapoport | 9a3f39f | 2011-04-25 01:09:07 +0300 | [diff] [blame] | 99 | #else |
| 100 | void __init omap_ads7846_init(int bus_num, int gpio_pendown, int gpio_debounce, |
| 101 | struct ads7846_platform_data *board_pdata) |
| 102 | { |
| 103 | } |
| 104 | #endif |
| 105 | |
| 106 | #if defined(CONFIG_MTD_NAND_OMAP2) || defined(CONFIG_MTD_NAND_OMAP2_MODULE) |
Grazvydas Ignotas | 7a559c7 | 2011-06-03 19:56:33 +0000 | [diff] [blame] | 107 | static struct omap_nand_platform_data nand_data; |
Mike Rapoport | 9a3f39f | 2011-04-25 01:09:07 +0300 | [diff] [blame] | 108 | |
| 109 | void __init omap_nand_flash_init(int options, struct mtd_partition *parts, |
| 110 | int nr_parts) |
| 111 | { |
| 112 | u8 cs = 0; |
| 113 | u8 nandcs = GPMC_CS_NUM + 1; |
| 114 | |
| 115 | /* find out the chip-select on which NAND exists */ |
| 116 | while (cs < GPMC_CS_NUM) { |
| 117 | u32 ret = 0; |
| 118 | ret = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG1); |
| 119 | |
| 120 | if ((ret & 0xC00) == 0x800) { |
| 121 | printk(KERN_INFO "Found NAND on CS%d\n", cs); |
| 122 | if (nandcs > GPMC_CS_NUM) |
| 123 | nandcs = cs; |
| 124 | } |
| 125 | cs++; |
| 126 | } |
| 127 | |
| 128 | if (nandcs > GPMC_CS_NUM) { |
Paul Walmsley | 7852ec0 | 2012-07-26 00:54:26 -0600 | [diff] [blame] | 129 | pr_info("NAND: Unable to find configuration in GPMC\n"); |
Mike Rapoport | 9a3f39f | 2011-04-25 01:09:07 +0300 | [diff] [blame] | 130 | return; |
| 131 | } |
| 132 | |
| 133 | if (nandcs < GPMC_CS_NUM) { |
| 134 | nand_data.cs = nandcs; |
| 135 | nand_data.parts = parts; |
| 136 | nand_data.nr_parts = nr_parts; |
Grazvydas Ignotas | 7a559c7 | 2011-06-03 19:56:33 +0000 | [diff] [blame] | 137 | nand_data.devsize = options; |
Mike Rapoport | 9a3f39f | 2011-04-25 01:09:07 +0300 | [diff] [blame] | 138 | |
| 139 | printk(KERN_INFO "Registering NAND on CS%d\n", nandcs); |
| 140 | if (gpmc_nand_init(&nand_data) < 0) |
| 141 | printk(KERN_ERR "Unable to register NAND device\n"); |
| 142 | } |
| 143 | } |
| 144 | #else |
| 145 | void __init omap_nand_flash_init(int options, struct mtd_partition *parts, |
| 146 | int nr_parts) |
| 147 | { |
| 148 | } |
| 149 | #endif |