blob: 799a617ade30ac934501bf3b97ce55d481f8717c [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,
36 .single_channel = 1, /* 0: slave, 1: master */
37};
38
39static 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
51static 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
61void __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 Grinberge68273b2011-05-04 18:04:55 +030067 if (board_pdata && board_pdata->get_pendown_state) {
68 err = gpio_request_one(gpio_pendown, GPIOF_IN, "TSPenDown");
69 if (err) {
70 pr_err("Couldn't obtain gpio for TSPenDown: %d\n", err);
71 return;
72 }
73 gpio_export(gpio_pendown, 0);
74
75 if (gpio_debounce)
76 gpio_set_debounce(gpio_pendown, gpio_debounce);
Mike Rapoport96974a22011-04-25 01:09:05 +030077 }
78
Mike Rapoport96974a22011-04-25 01:09:05 +030079 spi_bi->bus_num = bus_num;
80 spi_bi->irq = OMAP_GPIO_IRQ(gpio_pendown);
81
Ilya Yanok7db74d52012-03-05 16:11:02 -080082 if (board_pdata) {
83 board_pdata->gpio_pendown = gpio_pendown;
Mike Rapoport96974a22011-04-25 01:09:05 +030084 spi_bi->platform_data = board_pdata;
Ilya Yanok7db74d52012-03-05 16:11:02 -080085 } else {
86 ads7846_config.gpio_pendown = gpio_pendown;
87 }
Mike Rapoport96974a22011-04-25 01:09:05 +030088
89 spi_register_board_info(&ads7846_spi_board_info, 1);
90}
Mike Rapoport9a3f39f2011-04-25 01:09:07 +030091#else
92void __init omap_ads7846_init(int bus_num, int gpio_pendown, int gpio_debounce,
93 struct ads7846_platform_data *board_pdata)
94{
95}
96#endif
97
98#if defined(CONFIG_MTD_NAND_OMAP2) || defined(CONFIG_MTD_NAND_OMAP2_MODULE)
Grazvydas Ignotas7a559c72011-06-03 19:56:33 +000099static struct omap_nand_platform_data nand_data;
Mike Rapoport9a3f39f2011-04-25 01:09:07 +0300100
101void __init omap_nand_flash_init(int options, struct mtd_partition *parts,
102 int nr_parts)
103{
104 u8 cs = 0;
105 u8 nandcs = GPMC_CS_NUM + 1;
106
107 /* find out the chip-select on which NAND exists */
108 while (cs < GPMC_CS_NUM) {
109 u32 ret = 0;
110 ret = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG1);
111
112 if ((ret & 0xC00) == 0x800) {
113 printk(KERN_INFO "Found NAND on CS%d\n", cs);
114 if (nandcs > GPMC_CS_NUM)
115 nandcs = cs;
116 }
117 cs++;
118 }
119
120 if (nandcs > GPMC_CS_NUM) {
121 printk(KERN_INFO "NAND: Unable to find configuration "
122 "in GPMC\n ");
123 return;
124 }
125
126 if (nandcs < GPMC_CS_NUM) {
127 nand_data.cs = nandcs;
128 nand_data.parts = parts;
129 nand_data.nr_parts = nr_parts;
Grazvydas Ignotas7a559c72011-06-03 19:56:33 +0000130 nand_data.devsize = options;
Mike Rapoport9a3f39f2011-04-25 01:09:07 +0300131
132 printk(KERN_INFO "Registering NAND on CS%d\n", nandcs);
133 if (gpmc_nand_init(&nand_data) < 0)
134 printk(KERN_ERR "Unable to register NAND device\n");
135 }
136}
137#else
138void __init omap_nand_flash_init(int options, struct mtd_partition *parts,
139 int nr_parts)
140{
141}
142#endif