blob: 4ba070e1288c75a06d0a468e5ac4e4ee464a93e9 [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
27#include <plat/mcspi.h>
Mike Rapoport9a3f39f2011-04-25 01:09:07 +030028#include <plat/nand.h>
Mike Rapoport96974a22011-04-25 01:09:05 +030029
30#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
Zumeng Chen16aced82012-06-20 17:14:53 +080038/*
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.
42 */
43static int omap3_get_pendown_state(void)
44{
45 return !gpio_get_value(OMAP3_EVM_TS_GPIO);
46}
47
Mike Rapoport96974a22011-04-25 01:09:05 +030048static 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,
Zumeng Chen16aced82012-06-20 17:14:53 +080058 .get_pendown_state = &omap3_get_pendown_state,
Mike Rapoport96974a22011-04-25 01:09:05 +030059};
60
61static 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,
69};
70
71void __init omap_ads7846_init(int bus_num, int gpio_pendown, int gpio_debounce,
72 struct ads7846_platform_data *board_pdata)
73{
74 struct spi_board_info *spi_bi = &ads7846_spi_board_info;
75 int err;
76
Zumeng Chen16aced82012-06-20 17:14:53 +080077 if (gpio_pendown) {
Igor Grinberge68273b2011-05-04 18:04:55 +030078 err = gpio_request_one(gpio_pendown, GPIOF_IN, "TSPenDown");
79 if (err) {
80 pr_err("Couldn't obtain gpio for TSPenDown: %d\n", err);
81 return;
82 }
Igor Grinberge68273b2011-05-04 18:04:55 +030083
Zumeng Chen16aced82012-06-20 17:14:53 +080084 /* TS GPIOPendown doesn't allow user to change the direction */
85 gpio_export(gpio_pendown, false);
86
87 /* Set proper debouce time for ads7846. */
Igor Grinberge68273b2011-05-04 18:04:55 +030088 if (gpio_debounce)
89 gpio_set_debounce(gpio_pendown, gpio_debounce);
Mike Rapoport96974a22011-04-25 01:09:05 +030090 }
91
Mike Rapoport96974a22011-04-25 01:09:05 +030092 spi_bi->bus_num = bus_num;
Tarun Kanti DebBarma46a0a542012-03-29 08:41:01 -070093 spi_bi->irq = gpio_to_irq(gpio_pendown);
Mike Rapoport96974a22011-04-25 01:09:05 +030094
Ilya Yanok7db74d52012-03-05 16:11:02 -080095 if (board_pdata) {
96 board_pdata->gpio_pendown = gpio_pendown;
Mike Rapoport96974a22011-04-25 01:09:05 +030097 spi_bi->platform_data = board_pdata;
Ilya Yanok7db74d52012-03-05 16:11:02 -080098 } else {
99 ads7846_config.gpio_pendown = gpio_pendown;
100 }
Mike Rapoport96974a22011-04-25 01:09:05 +0300101
102 spi_register_board_info(&ads7846_spi_board_info, 1);
103}
Mike Rapoport9a3f39f2011-04-25 01:09:07 +0300104#else
105void __init omap_ads7846_init(int bus_num, int gpio_pendown, int gpio_debounce,
106 struct ads7846_platform_data *board_pdata)
107{
108}
109#endif
110
111#if defined(CONFIG_MTD_NAND_OMAP2) || defined(CONFIG_MTD_NAND_OMAP2_MODULE)
Grazvydas Ignotas7a559c72011-06-03 19:56:33 +0000112static struct omap_nand_platform_data nand_data;
Mike Rapoport9a3f39f2011-04-25 01:09:07 +0300113
114void __init omap_nand_flash_init(int options, struct mtd_partition *parts,
115 int nr_parts)
116{
117 u8 cs = 0;
118 u8 nandcs = GPMC_CS_NUM + 1;
119
120 /* find out the chip-select on which NAND exists */
121 while (cs < GPMC_CS_NUM) {
122 u32 ret = 0;
123 ret = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG1);
124
125 if ((ret & 0xC00) == 0x800) {
126 printk(KERN_INFO "Found NAND on CS%d\n", cs);
127 if (nandcs > GPMC_CS_NUM)
128 nandcs = cs;
129 }
130 cs++;
131 }
132
133 if (nandcs > GPMC_CS_NUM) {
134 printk(KERN_INFO "NAND: Unable to find configuration "
135 "in GPMC\n ");
136 return;
137 }
138
139 if (nandcs < GPMC_CS_NUM) {
140 nand_data.cs = nandcs;
141 nand_data.parts = parts;
142 nand_data.nr_parts = nr_parts;
Grazvydas Ignotas7a559c72011-06-03 19:56:33 +0000143 nand_data.devsize = options;
Mike Rapoport9a3f39f2011-04-25 01:09:07 +0300144
145 printk(KERN_INFO "Registering NAND on CS%d\n", nandcs);
146 if (gpmc_nand_init(&nand_data) < 0)
147 printk(KERN_ERR "Unable to register NAND device\n");
148 }
149}
150#else
151void __init omap_nand_flash_init(int options, struct mtd_partition *parts,
152 int nr_parts)
153{
154}
155#endif