block: move down direct IO plugging
[linux/fpc-iii.git] / arch / arm / mach-omap2 / common-board-devices.c
blob14734746457c2bd8bdfcabd1ea4681dc4edab36e
1 /*
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
19 * 02110-1301 USA
23 #include <linux/gpio.h>
24 #include <linux/spi/spi.h>
25 #include <linux/spi/ads7846.h>
27 #include <plat/mcspi.h>
28 #include <plat/nand.h>
30 #include "common-board-devices.h"
32 #if defined(CONFIG_TOUCHSCREEN_ADS7846) || \
33 defined(CONFIG_TOUCHSCREEN_ADS7846_MODULE)
34 static struct omap2_mcspi_device_config ads7846_mcspi_config = {
35 .turbo_mode = 0,
39 * ADS7846 driver maybe request a gpio according to the value
40 * of pdata->get_pendown_state, but we have done this. So set
41 * get_pendown_state to avoid twice gpio requesting.
43 static int omap3_get_pendown_state(void)
45 return !gpio_get_value(OMAP3_EVM_TS_GPIO);
48 static struct ads7846_platform_data ads7846_config = {
49 .x_max = 0x0fff,
50 .y_max = 0x0fff,
51 .x_plate_ohms = 180,
52 .pressure_max = 255,
53 .debounce_max = 10,
54 .debounce_tol = 3,
55 .debounce_rep = 1,
56 .gpio_pendown = -EINVAL,
57 .keep_vref_on = 1,
58 .get_pendown_state = &omap3_get_pendown_state,
61 static struct spi_board_info ads7846_spi_board_info __initdata = {
62 .modalias = "ads7846",
63 .bus_num = -EINVAL,
64 .chip_select = 0,
65 .max_speed_hz = 1500000,
66 .controller_data = &ads7846_mcspi_config,
67 .irq = -EINVAL,
68 .platform_data = &ads7846_config,
71 void __init omap_ads7846_init(int bus_num, int gpio_pendown, int gpio_debounce,
72 struct ads7846_platform_data *board_pdata)
74 struct spi_board_info *spi_bi = &ads7846_spi_board_info;
75 int err;
77 err = gpio_request_one(gpio_pendown, GPIOF_IN, "TSPenDown");
78 if (err) {
79 pr_err("Couldn't obtain gpio for TSPenDown: %d\n", err);
80 return;
83 if (gpio_debounce)
84 gpio_set_debounce(gpio_pendown, gpio_debounce);
86 spi_bi->bus_num = bus_num;
87 spi_bi->irq = gpio_to_irq(gpio_pendown);
89 if (board_pdata) {
90 board_pdata->gpio_pendown = gpio_pendown;
91 spi_bi->platform_data = board_pdata;
92 if (board_pdata->get_pendown_state)
93 gpio_export(gpio_pendown, 0);
94 } else {
95 ads7846_config.gpio_pendown = gpio_pendown;
98 if (!board_pdata || (board_pdata && !board_pdata->get_pendown_state))
99 gpio_free(gpio_pendown);
101 spi_register_board_info(&ads7846_spi_board_info, 1);
103 #else
104 void __init omap_ads7846_init(int bus_num, int gpio_pendown, int gpio_debounce,
105 struct ads7846_platform_data *board_pdata)
108 #endif
110 #if defined(CONFIG_MTD_NAND_OMAP2) || defined(CONFIG_MTD_NAND_OMAP2_MODULE)
111 static struct omap_nand_platform_data nand_data;
113 void __init omap_nand_flash_init(int options, struct mtd_partition *parts,
114 int nr_parts)
116 u8 cs = 0;
117 u8 nandcs = GPMC_CS_NUM + 1;
119 /* find out the chip-select on which NAND exists */
120 while (cs < GPMC_CS_NUM) {
121 u32 ret = 0;
122 ret = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG1);
124 if ((ret & 0xC00) == 0x800) {
125 printk(KERN_INFO "Found NAND on CS%d\n", cs);
126 if (nandcs > GPMC_CS_NUM)
127 nandcs = cs;
129 cs++;
132 if (nandcs > GPMC_CS_NUM) {
133 printk(KERN_INFO "NAND: Unable to find configuration "
134 "in GPMC\n ");
135 return;
138 if (nandcs < GPMC_CS_NUM) {
139 nand_data.cs = nandcs;
140 nand_data.parts = parts;
141 nand_data.nr_parts = nr_parts;
142 nand_data.devsize = options;
144 printk(KERN_INFO "Registering NAND on CS%d\n", nandcs);
145 if (gpmc_nand_init(&nand_data) < 0)
146 printk(KERN_ERR "Unable to register NAND device\n");
149 #else
150 void __init omap_nand_flash_init(int options, struct mtd_partition *parts,
151 int nr_parts)
154 #endif