All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ben Gardiner <bengardiner@nanometrics.ca>
To: Kevin Hilman <khilman@deeprootsystems.com>,
	davinci-linux-open-source@linux.davincidsp.com,
	linux-input@vger.kernel.org,
	Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: linux-kernel@vger.kernel.org,
	Chris Cordahi <christophercordahi@nanometrics.ca>,
	Paul Mundt <lethal@linux-sh.org>,
	Alexander Clouter <alex@digriz.org.uk>,
	"Govindarajan, Sriramakrishnan" <srk@ti.com>
Subject: [PATCH v2 4/4] da850-evm: add baseboard UI expander buttons, switches and LEDs
Date: Tue, 16 Nov 2010 14:39:37 -0500	[thread overview]
Message-ID: <d6d59b4a3c34149008f3681e0d6106efa15f354d.1289935504.git.bengardiner@nanometrics.ca> (raw)
In-Reply-To: <cover.1289935504.git.bengardiner@nanometrics.ca>

This patch adds a pca953x platform device for the tca6416 found on the evm
baseboard. The tca6416 is a GPIO expander, also found on the UI board at a
separate I2C address. The pins of the baseboard IO expander are connected to
software reset, deep sleep enable, test points, a push button, DIP switches and
LEDs.

Add support for the push button, DIP switches and LEDs and test points (as
free GPIOs). The reset and deep sleep enable connections are reserved by the
setup routine so that userspace can't toggle those lines.

The existing tca6416-keypad driver was not employed because there was no
apararent way to register the LEDs connected to gpio's on the tca6416 while
simultaneously registering the tca6416-keypad instance.

Signed-off-by: Ben Gardiner <bengardiner@nanometrics.ca>
Reviewed-by: Chris Cordahi <christophercordahi@nanometrics.ca>
CC: Govindarajan, Sriramakrishnan <srk@ti.com>

---

Changes since v1:
 * adding note about why the tca6416-keypad driver was not used.
 * adding Govindarajan, Sriramakrishnan, the author of the tca6416-keypad
   driver
---
 arch/arm/mach-davinci/board-da850-evm.c |  217 ++++++++++++++++++++++++++++++-
 1 files changed, 213 insertions(+), 4 deletions(-)

diff --git a/arch/arm/mach-davinci/board-da850-evm.c b/arch/arm/mach-davinci/board-da850-evm.c
index dcf21e5..79f2c95 100644
--- a/arch/arm/mach-davinci/board-da850-evm.c
+++ b/arch/arm/mach-davinci/board-da850-evm.c
@@ -410,6 +410,208 @@ static int da850_evm_ui_expander_teardown(struct i2c_client *client,
 	return 0;
 }
 
+/* assign the baseboard expander's GPIOs after the UI board's */
+#define DA850_UI_EXPANDER_N_GPIOS ARRAY_SIZE(ui_expander_names)
+#define DA850_BB_EXPANDER_GPIO_BASE (DAVINCI_N_GPIO + DA850_UI_EXPANDER_N_GPIOS)
+
+static const char const *baseboard_expander_names[] = {
+	"deep_sleep_en", "sw_rst", "tp_23", "tp_22", "tp_21", "user_pb1",
+	"user_led2", "user_led1", "user_sw_1", "user_sw_2", "user_sw_3",
+	"user_sw_4", "user_sw_5", "user_sw_6", "user_sw_7", "user_sw_8"
+};
+
+#define DA850_DEEP_SLEEP_EN_OFFSET		0
+#define DA850_SW_RST_OFFSET			1
+#define DA850_PB1_OFFSET			5
+#define DA850_USER_LED2_OFFSET			6
+#define DA850_USER_SW_1_OFFSET			8
+
+#define DA850_N_USER_SW				8
+#define DA850_N_USER_LED			2
+
+static struct gpio_keys_button user_pb_gpio_key = {
+	.code = KEY_PROG1,
+	.type = EV_KEY,
+	.active_low = 1,
+	.wakeup = 0,
+	.debounce_interval = DA850_PB_DEBOUNCE_MS,
+	.gpio = -1, /* assigned at runtime */
+	.desc = NULL, /* assigned at runtime */
+};
+
+static struct gpio_keys_platform_data user_pb_gpio_key_platform_data = {
+	.buttons = &user_pb_gpio_key,
+	.nbuttons = 1,
+	.rep = 0, /* disable auto-repeat */
+	.poll_interval = DA850_PB_POLL_MS,
+};
+
+static struct platform_device user_pb_gpio_key_device = {
+	.name = "gpio-keys",
+	.id = 1,
+	.dev = {
+		.platform_data = &user_pb_gpio_key_platform_data
+	}
+};
+
+static struct gpio_keys_button user_sw_gpio_keys[DA850_N_USER_SW];
+
+static struct gpio_keys_platform_data user_sw_gpio_key_platform_data = {
+	.buttons = user_sw_gpio_keys,
+	.nbuttons = ARRAY_SIZE(user_sw_gpio_keys),
+	.rep = 0, /* disable auto-repeat */
+	.poll_interval = DA850_SW_POLL_MS,
+};
+
+static struct platform_device user_sw_gpio_key_device = {
+	.name = "gpio-keys",
+	.id = 2,
+	.dev = {
+		.platform_data = &user_sw_gpio_key_platform_data
+	}
+};
+
+static void da850_user_switches_init(unsigned gpio)
+{
+	int i;
+	struct gpio_keys_button *button;
+
+	for (i = 0; i < DA850_N_USER_SW; i++) {
+		button = &user_sw_gpio_keys[i];
+
+		button->code = SW_LID + i;
+		button->type = EV_SW;
+		button->active_low = 1;
+		button->wakeup = 0;
+		button->debounce_interval = DA850_PB_DEBOUNCE_MS;
+		button->desc = (char *)
+			baseboard_expander_names[DA850_USER_SW_1_OFFSET + i];
+
+		button->gpio = gpio + DA850_USER_SW_1_OFFSET + i;
+	}
+}
+
+static struct gpio_led user_leds[DA850_N_USER_LED];
+
+static struct gpio_led_platform_data user_led_gpio_data = {
+	.leds = user_leds,
+	.num_leds = ARRAY_SIZE(user_leds),
+};
+
+static struct platform_device user_leds_gpio_device = {
+	.name		= "leds-gpio",
+	.id		= -1,
+	.dev = {
+		.platform_data = &user_led_gpio_data
+	}
+};
+
+static void da850_user_leds_init(unsigned gpio)
+{
+	int i;
+	struct gpio_led *led;
+
+	for (i = 0; i < DA850_N_USER_LED; i++) {
+		led = &user_leds[i];
+
+		led->active_low = 1;
+		led->gpio = gpio + DA850_USER_LED2_OFFSET + i;
+		led->name =
+			baseboard_expander_names[DA850_USER_LED2_OFFSET + i];
+	}
+}
+
+static int da850_evm_baseboard_expander_setup(struct i2c_client *client,
+						unsigned gpio, unsigned ngpio,
+						void *c)
+{
+	int ret;
+	int deep_sleep_en, sw_rst;
+
+	deep_sleep_en	= gpio + DA850_DEEP_SLEEP_EN_OFFSET;
+	sw_rst		= gpio + DA850_SW_RST_OFFSET;
+
+	/* Do not allow sysfs control of deep_sleep_en */
+	ret = gpio_request(deep_sleep_en,
+			baseboard_expander_names[DA850_DEEP_SLEEP_EN_OFFSET]);
+	if (ret) {
+		pr_warning("Cannot open IO expander pin %d\n", deep_sleep_en);
+		goto io_exp_setup_deep_sleep_en_fail;
+	}
+	/* do not drive a value on deep_sleep_en */
+	gpio_direction_input(deep_sleep_en);
+
+	/* Do not allow sysfs control of sw_rst */
+	ret = gpio_request(sw_rst,
+			baseboard_expander_names[DA850_SW_RST_OFFSET]);
+	if (ret) {
+		pr_warning("Cannot open IO expander pin %d\n", sw_rst);
+		goto io_exp_setup_sw_rst_fail;
+	}
+	/* do not drive a value on sw_rst */
+	gpio_direction_input(sw_rst);
+
+	/* Register user_pb1 as a gpio-keys button */
+	user_pb_gpio_key.desc = (char *)
+			baseboard_expander_names[DA850_PB1_OFFSET];
+	user_pb_gpio_key.gpio = gpio + DA850_PB1_OFFSET;
+	ret = platform_device_register(&user_pb_gpio_key_device);
+	if (ret) {
+		pr_warning("Cannot register user pb: %d\n", ret);
+		goto io_exp_setup_pb_fail;
+	}
+
+	/*
+	 * Register the switches as a separate gpio-keys device so the fast
+	 * polling interval for the pushbuttons is not wasted on switches
+	 */
+	da850_user_switches_init(gpio);
+	ret = platform_device_register(&user_sw_gpio_key_device);
+	if (ret) {
+		pr_warning("Could not register baseboard GPIO expander switches"
+						" device\n");
+		goto io_exp_setup_sw_fail;
+	}
+
+	da850_user_leds_init(gpio);
+	ret = platform_device_register(&user_leds_gpio_device);
+	if (ret) {
+		pr_warning("Could not register baseboard GPIO expander LEDS "
+				"device\n");
+		goto io_exp_setup_leds_fail;
+	}
+
+	return 0;
+
+io_exp_setup_leds_fail:
+	platform_device_unregister(&user_sw_gpio_key_device);
+io_exp_setup_sw_fail:
+	platform_device_unregister(&user_pb_gpio_key_device);
+io_exp_setup_pb_fail:
+	gpio_free(sw_rst);
+io_exp_setup_sw_rst_fail:
+	gpio_free(deep_sleep_en);
+io_exp_setup_deep_sleep_en_fail:
+	return ret;
+}
+
+static int da850_evm_baseboard_expander_teardown(struct i2c_client *client,
+					unsigned gpio, unsigned ngpio, void *c)
+{
+	int deep_sleep_en, sw_rst;
+
+	deep_sleep_en	= gpio + DA850_DEEP_SLEEP_EN_OFFSET;
+	sw_rst		= gpio + DA850_SW_RST_OFFSET;
+
+	platform_device_unregister(&user_leds_gpio_device);
+	platform_device_unregister(&user_sw_gpio_key_device);
+	platform_device_unregister(&user_pb_gpio_key_device);
+	gpio_free(sw_rst);
+	gpio_free(deep_sleep_en);
+
+	return 0;
+}
+
 static struct pca953x_platform_data da850_evm_ui_expander_info = {
 	.gpio_base	= DAVINCI_N_GPIO,
 	.setup		= da850_evm_ui_expander_setup,
@@ -417,6 +619,13 @@ static struct pca953x_platform_data da850_evm_ui_expander_info = {
 	.names		= ui_expander_names,
 };
 
+static struct pca953x_platform_data da850_evm_baseboard_expander_info = {
+	.gpio_base	= DA850_BB_EXPANDER_GPIO_BASE,
+	.setup		= da850_evm_baseboard_expander_setup,
+	.teardown	= da850_evm_baseboard_expander_teardown,
+	.names		= baseboard_expander_names,
+};
+
 static struct i2c_board_info __initdata da850_evm_i2c_devices[] = {
 	{
 		I2C_BOARD_INFO("tlv320aic3x", 0x18),
@@ -424,10 +633,10 @@ static struct i2c_board_info __initdata da850_evm_i2c_devices[] = {
 	{
 		I2C_BOARD_INFO("tca6416", 0x20),
 		.platform_data = &da850_evm_ui_expander_info,
-		/*
-		 * TODO : populate at runtime using
-		 * .irq = gpio_to_irq(GPIO_TO_PIN(2,7)),
-		 */
+	},
+	{
+		I2C_BOARD_INFO("tca6416", 0x21),
+		.platform_data = &da850_evm_baseboard_expander_info,
 	},
 };
 
-- 
1.7.0.4


  parent reply	other threads:[~2010-11-16 19:39 UTC|newest]

Thread overview: 104+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <cover.1289835508.git.bengardiner@nanometrics.ca>
     [not found] ` <8891d088e9a16122c780f737b1b1ec35f9517c36.1289835508.git.bengardiner@nanometrics.ca>
2010-11-16  9:36   ` [PATCH 1/4] input: gpio_keys: polling mode support Paul Mundt
2010-11-16 18:28     ` Ben Gardiner
2010-11-16 19:39 ` [PATCH v2 0/4] da850-evm: add gpio-{keys,leds} for UI and BB expanders Ben Gardiner
2010-11-16 19:39   ` [PATCH v2 0/4] da850-evm: add gpio-{keys, leds} " Ben Gardiner
2010-11-16 19:39   ` [PATCH v2 1/4] input: gpio_keys: polling mode support Ben Gardiner
2010-11-16 19:39   ` [PATCH v2 2/4] da850-evm: add UI Expander pushbuttons Ben Gardiner
2010-11-19  9:58     ` Nori, Sekhar
2010-11-19  9:58       ` Nori, Sekhar
2010-11-19 15:38       ` Ben Gardiner
2010-11-19 15:38         ` Ben Gardiner
2010-11-22 11:49         ` Nori, Sekhar
2010-11-22 11:49           ` Nori, Sekhar
2010-11-22 13:50           ` Ben Gardiner
2010-11-22 13:50             ` Ben Gardiner
2010-11-23 12:38             ` Nori, Sekhar
2010-11-23 12:38               ` Nori, Sekhar
2010-11-23 13:29               ` Ben Gardiner
2010-11-23 13:29                 ` Ben Gardiner
2010-11-23 15:48               ` Kevin Hilman
2010-11-23 15:48                 ` Kevin Hilman
2010-11-23 17:58                 ` Ben Gardiner
2010-11-23 17:58                   ` Ben Gardiner
2010-11-24  6:09                 ` Paul Mundt
2010-11-24  6:09                   ` Paul Mundt
2010-11-24 17:17                   ` Ben Gardiner
2010-11-24 17:17                     ` Ben Gardiner
2010-11-16 19:39   ` [PATCH v2 3/4] da850-evm: extract defines for SEL{A,B,C} pins in UI expander Ben Gardiner
2010-11-16 19:39     ` [PATCH v2 3/4] da850-evm: extract defines for SEL{A, B, C} " Ben Gardiner
2010-11-19 11:19     ` Nori, Sekhar
2010-11-19 11:19       ` Nori, Sekhar
2010-11-19 15:38       ` Ben Gardiner
2010-11-19 15:38         ` Ben Gardiner
2010-11-16 19:39   ` Ben Gardiner [this message]
2010-11-19 12:14     ` [PATCH v2 4/4] da850-evm: add baseboard UI expander buttons, switches and LEDs Nori, Sekhar
2010-11-19 12:14       ` Nori, Sekhar
2010-11-19 15:40       ` Ben Gardiner
2010-11-19 15:40         ` Ben Gardiner
2010-11-19 17:02         ` Dmitry Torokhov
2010-11-19 17:02           ` Dmitry Torokhov
2010-11-19 17:15           ` Ben Gardiner
2010-11-19 17:15             ` Ben Gardiner
2010-11-22 12:00         ` Nori, Sekhar
2010-11-22 12:00           ` Nori, Sekhar
2010-11-22 14:15           ` Ben Gardiner
2010-11-22 14:15             ` Ben Gardiner
2010-11-23 12:42             ` Nori, Sekhar
2010-11-23 12:42               ` Nori, Sekhar
2010-11-23 13:32               ` Ben Gardiner
2010-11-23 13:32                 ` Ben Gardiner
2010-11-19 21:37   ` [PATCH v3 0/4] da850-evm: add gpio-{keys,leds} for UI and BB expanders Ben Gardiner
2010-11-19 21:37     ` [PATCH v3 1/4] input: gpio_keys: polling mode support Ben Gardiner
2010-11-19 21:37     ` [PATCH v3 2/4] da850-evm: add UI Expander pushbuttons Ben Gardiner
2010-11-19 21:37     ` [PATCH v3 3/4] da850-evm: extract defines for SEL{A,B,C} pins in UI expander Ben Gardiner
2010-11-19 21:41       ` [PATCH v3 3/4] da850-evm: extract defines for SEL{A, B, C} " Victor Rodriguez
2010-11-19 21:41         ` Victor Rodriguez
2010-11-19 22:25         ` Ben Gardiner
2010-11-19 22:25           ` Ben Gardiner
2010-11-19 21:37     ` [PATCH v3 4/4] da850-evm: add baseboard GPIO expander buttons, switches and LEDs Ben Gardiner
2010-11-23 19:40     ` [PATCH v4 0/5] da850-evm: add gpio-{keys,leds} for UI and BB expanders Ben Gardiner
2010-11-23 19:40       ` [PATCH v4 1/5] input: gpio_keys: polling mode support Ben Gardiner
2010-11-23 19:40         ` Ben Gardiner
2010-11-23 19:40       ` [PATCH v4 2/5] da850-evm: add UI Expander pushbuttons Ben Gardiner
2010-11-23 19:40         ` Ben Gardiner
2010-11-24 13:16         ` Nori, Sekhar
2010-11-24 13:16           ` Nori, Sekhar
2010-11-24 17:16           ` Ben Gardiner
2010-11-24 17:16             ` Ben Gardiner
2010-11-23 19:40       ` [PATCH v4 3/5] da850-evm: extract defines for SEL{A,B,C} pins in UI expander Ben Gardiner
2010-11-23 19:40       ` [PATCH v4 4/5] da850-evm: add baseboard GPIO expander buttons, switches and LEDs Ben Gardiner
2010-11-23 19:41       ` [PATCH v4 5/5] da850-evm: KEYBOARD_GPIO and INPUT_POLLDEV Kconfig conditionals Ben Gardiner
2010-11-23 19:41         ` Ben Gardiner
2010-11-24 21:59       ` [PATCH v5 0/5] da850-evm: add gpio-{keys,leds} for UI and BB expanders Ben Gardiner
2010-11-24 21:59         ` [PATCH v5 1/5] [WIP] input: add input driver for polled GPIO buttons Ben Gardiner
2010-11-24 21:59           ` Ben Gardiner
2010-11-24 21:59         ` [PATCH v5 2/5] da850-evm: add UI Expander pushbuttons Ben Gardiner
2010-11-24 21:59           ` Ben Gardiner
2010-11-24 21:59         ` [PATCH v5 3/5] da850-evm: extract defines for SEL{A,B,C} pins in UI expander Ben Gardiner
2010-11-24 21:59         ` [PATCH v5 4/5] da850-evm: add baseboard GPIO expander buttons, switches and LEDs Ben Gardiner
2010-11-24 21:59         ` [PATCH v5 5/5] da850-evm: KEYBOARD_GPIO_POLLED Kconfig conditional Ben Gardiner
2010-11-24 21:59           ` Ben Gardiner
2010-12-09 21:51         ` [PATCH v6 0/5] da850-evm: add gpio-{keys,leds} for UI and BB expanders Ben Gardiner
2010-12-09 21:51           ` [PATCH v6 1/5] Input: add input driver for polled GPIO buttons Ben Gardiner
2010-12-09 21:51             ` Ben Gardiner
2010-12-10 15:50             ` Kevin Hilman
2010-12-09 21:51           ` [PATCH v6 2/5] da850-evm: add UI Expander pushbuttons Ben Gardiner
2010-12-09 21:51             ` Ben Gardiner
2010-12-09 21:51           ` [PATCH v6 3/5] da850-evm: extract defines for SEL{A,B,C} pins in UI expander Ben Gardiner
2010-12-09 21:51           ` [PATCH v6 4/5] da850-evm: add baseboard GPIO expander buttons, switches and LEDs Ben Gardiner
2010-12-09 21:51           ` [PATCH v6 5/5] da850-evm: KEYBOARD_GPIO_POLLED Kconfig conditional Ben Gardiner
2010-12-09 21:51             ` Ben Gardiner
2010-12-10 16:16           ` [PATCH v6 0/5] da850-evm: add gpio-{keys,leds} for UI and BB expanders Kevin Hilman
2010-12-10 16:33             ` Ben Gardiner
2010-12-10 16:33               ` Ben Gardiner
2010-12-11  0:04               ` Kevin Hilman
2010-12-11  0:04                 ` Kevin Hilman
2010-12-13 17:02               ` Ben Gardiner
2010-12-13 17:02                 ` Ben Gardiner
2010-12-13 21:53                 ` Kevin Hilman
2010-12-13 21:53                   ` [PATCH v6 0/5] da850-evm: add gpio-{keys, leds} " Kevin Hilman
2010-12-14  4:31                   ` [PATCH v6 0/5] da850-evm: add gpio-{keys,leds} " Ben Gardiner
2010-12-14  4:31                     ` Ben Gardiner
2010-12-14 16:17                   ` Ben Gardiner
2010-12-14 17:10                     ` Kevin Hilman
2010-12-17 15:15                       ` Ben Gardiner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d6d59b4a3c34149008f3681e0d6106efa15f354d.1289935504.git.bengardiner@nanometrics.ca \
    --to=bengardiner@nanometrics.ca \
    --cc=alex@digriz.org.uk \
    --cc=christophercordahi@nanometrics.ca \
    --cc=davinci-linux-open-source@linux.davincidsp.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=khilman@deeprootsystems.com \
    --cc=lethal@linux-sh.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=srk@ti.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.