blob: cea31dda3a7322a2ca7306280bb013449928332c [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
Mike Rapoportfbd80712011-04-25 01:09:06 +030023#include <linux/i2c.h>
24#include <linux/i2c/twl.h>
25
Mike Rapoport96974a22011-04-25 01:09:05 +030026#include <linux/gpio.h>
27#include <linux/spi/spi.h>
28#include <linux/spi/ads7846.h>
29
Mike Rapoportfbd80712011-04-25 01:09:06 +030030#include <plat/i2c.h>
Mike Rapoport96974a22011-04-25 01:09:05 +030031#include <plat/mcspi.h>
32
33#include "common-board-devices.h"
34
Mike Rapoportfbd80712011-04-25 01:09:06 +030035static struct i2c_board_info __initdata pmic_i2c_board_info = {
36 .addr = 0x48,
37 .flags = I2C_CLIENT_WAKE,
38};
39
40void __init omap_pmic_init(int bus, u32 clkrate,
41 const char *pmic_type, int pmic_irq,
42 struct twl4030_platform_data *pmic_data)
43{
44 strncpy(pmic_i2c_board_info.type, pmic_type,
45 sizeof(pmic_i2c_board_info.type));
46 pmic_i2c_board_info.irq = pmic_irq;
47 pmic_i2c_board_info.platform_data = pmic_data;
48
49 omap_register_i2c_bus(bus, clkrate, &pmic_i2c_board_info, 1);
50}
51
Mike Rapoport96974a22011-04-25 01:09:05 +030052static struct omap2_mcspi_device_config ads7846_mcspi_config = {
53 .turbo_mode = 0,
54 .single_channel = 1, /* 0: slave, 1: master */
55};
56
57static struct ads7846_platform_data ads7846_config = {
58 .x_max = 0x0fff,
59 .y_max = 0x0fff,
60 .x_plate_ohms = 180,
61 .pressure_max = 255,
62 .debounce_max = 10,
63 .debounce_tol = 3,
64 .debounce_rep = 1,
65 .gpio_pendown = -EINVAL,
66 .keep_vref_on = 1,
67};
68
69static struct spi_board_info ads7846_spi_board_info __initdata = {
70 .modalias = "ads7846",
71 .bus_num = -EINVAL,
72 .chip_select = 0,
73 .max_speed_hz = 1500000,
74 .controller_data = &ads7846_mcspi_config,
75 .irq = -EINVAL,
76 .platform_data = &ads7846_config,
77};
78
79void __init omap_ads7846_init(int bus_num, int gpio_pendown, int gpio_debounce,
80 struct ads7846_platform_data *board_pdata)
81{
82 struct spi_board_info *spi_bi = &ads7846_spi_board_info;
83 int err;
84
85 err = gpio_request(gpio_pendown, "TS PenDown");
86 if (err) {
87 pr_err("Could not obtain gpio for TS PenDown: %d\n", err);
88 return;
89 }
90
91 gpio_direction_input(gpio_pendown);
92 gpio_export(gpio_pendown, 0);
93
94 if (gpio_debounce)
95 gpio_set_debounce(gpio_pendown, gpio_debounce);
96
97 ads7846_config.gpio_pendown = gpio_pendown;
98
99 spi_bi->bus_num = bus_num;
100 spi_bi->irq = OMAP_GPIO_IRQ(gpio_pendown);
101
102 if (board_pdata)
103 spi_bi->platform_data = board_pdata;
104
105 spi_register_board_info(&ads7846_spi_board_info, 1);
106}