aboutsummaryrefslogtreecommitdiffstats
path: root/features/minnow-io/0003-minnowboard-gpio-Export-MinnowBoard-expansion-GPIO.patch
blob: 331de981098035bf13d3258f602c5e8555397b6c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
From 5d8dc9ea4644423ea4b8c57495ccf93efc1c51e1 Mon Sep 17 00:00:00 2001
Message-Id: <5d8dc9ea4644423ea4b8c57495ccf93efc1c51e1.1383605156.git.darren@dvhart.com>
In-Reply-To: <c018204ed1246c0c2129cc2d48f444d89e926034.1383605156.git.darren@dvhart.com>
References: <c018204ed1246c0c2129cc2d48f444d89e926034.1383605156.git.darren@dvhart.com>
From: Darren Hart <dvhart@linux.intel.com>
Date: Sat, 18 May 2013 14:45:58 -0700
Subject: [PATCH 3/4] minnowboard-gpio: Export MinnowBoard expansion GPIO

Request and export the user-configurable GPIO lines to sysfs. This provides a
label readable in /debugfs/gpio and a simple interface for experimenting with
GPIO on the MinnowBoard.

This is separate from the minnowboard driver to provide users with the
flexibility to write kernel drivers for their own devices using these GPIO
lines.

Signed-off-by: Darren Hart <dvhart@linux.intel.com>
---
 drivers/platform/x86/Kconfig            |  18 ++++++
 drivers/platform/x86/Makefile           |   1 +
 drivers/platform/x86/minnowboard-gpio.c | 108 ++++++++++++++++++++++++++++++++
 3 files changed, 127 insertions(+)
 create mode 100644 drivers/platform/x86/minnowboard-gpio.c

diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig
index 154dbf6..c8755cb 100644
--- a/drivers/platform/x86/Kconfig
+++ b/drivers/platform/x86/Kconfig
@@ -35,6 +35,24 @@ config MINNOWBOARD
 
 	  If you have a MinnowBoard, say Y or M here.
 
+if MINNOWBOARD
+config MINNOWBOARD_GPIO
+	tristate "MinnowBoard Expansion GPIO"
+	depends on MINNOWBOARD
+	default n
+	---help---
+	  Export the EG20T (gpio-pch) lines on the expansion connector to sysfs
+	  for easy manipulation from userspace. These will be named
+	  "minnow_gpio_pch[0-7]". If LVDS is not in use, export the E6XX
+	  (gpio-sch) lines on the expansion connector to sysfs, these will be
+	  named "minnow_gpio_aux[0-4]".
+
+	  If you have a MinnowBoard, and want to experiment with the GPIO,
+	  say Y or M here.
+
+endif # MINNOWBOARD
+
+
 config ACER_WMI
 	tristate "Acer WMI Laptop Extras"
 	depends on ACPI
diff --git a/drivers/platform/x86/Makefile b/drivers/platform/x86/Makefile
index 45ede1c..4dac9f0 100644
--- a/drivers/platform/x86/Makefile
+++ b/drivers/platform/x86/Makefile
@@ -3,6 +3,7 @@
 # x86 Platform-Specific Drivers
 #
 obj-$(CONFIG_MINNOWBOARD)	+= minnowboard.o
+obj-$(CONFIG_MINNOWBOARD_GPIO)	+= minnowboard-gpio.o
 obj-$(CONFIG_ASUS_LAPTOP)	+= asus-laptop.o
 obj-$(CONFIG_ASUS_WMI)		+= asus-wmi.o
 obj-$(CONFIG_ASUS_NB_WMI)	+= asus-nb-wmi.o
diff --git a/drivers/platform/x86/minnowboard-gpio.c b/drivers/platform/x86/minnowboard-gpio.c
new file mode 100644
index 0000000..0c6ff85
--- /dev/null
+++ b/drivers/platform/x86/minnowboard-gpio.c
@@ -0,0 +1,108 @@
+/*
+ * MinnowBoard Linux platform driver
+ * Copyright (c) 2013, Intel Corporation.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Author: Darren Hart <dvhart@linux.intel.com>
+ */
+
+#include <linux/platform_device.h>
+#include <linux/module.h>
+#include <linux/gpio.h>
+#include <linux/gpio_keys.h>
+#include <linux/input.h>
+#include <linux/minnowboard.h>
+#include "minnowboard-gpio.h"
+
+static struct gpio expansion_gpios[] = {
+	{ GPIO_PCH0, GPIOF_DIR_IN | GPIOF_EXPORT | GPIOF_EXPORT_CHANGEABLE,
+	  "minnow_gpio_pch0" },
+	{ GPIO_PCH1, GPIOF_DIR_IN | GPIOF_EXPORT | GPIOF_EXPORT_CHANGEABLE,
+	  "minnow_gpio_pch1" },
+	{ GPIO_PCH2, GPIOF_DIR_IN | GPIOF_EXPORT | GPIOF_EXPORT_CHANGEABLE,
+	  "minnow_gpio_pch2" },
+	{ GPIO_PCH3, GPIOF_DIR_IN | GPIOF_EXPORT | GPIOF_EXPORT_CHANGEABLE,
+	  "minnow_gpio_pch3" },
+	{ GPIO_PCH4, GPIOF_DIR_IN | GPIOF_EXPORT | GPIOF_EXPORT_CHANGEABLE,
+	  "minnow_gpio_pch4" },
+	{ GPIO_PCH5, GPIOF_DIR_IN | GPIOF_EXPORT | GPIOF_EXPORT_CHANGEABLE,
+	  "minnow_gpio_pch5" },
+	{ GPIO_PCH6, GPIOF_DIR_IN | GPIOF_EXPORT | GPIOF_EXPORT_CHANGEABLE,
+	  "minnow_gpio_pch6" },
+	{ GPIO_PCH7, GPIOF_DIR_IN | GPIOF_EXPORT | GPIOF_EXPORT_CHANGEABLE,
+	  "minnow_gpio_pch7" },
+};
+
+static struct gpio expansion_aux_gpios[] = {
+	{ GPIO_AUX0, GPIOF_DIR_IN | GPIOF_EXPORT | GPIOF_EXPORT_CHANGEABLE,
+	  "minnow_gpio_aux0" },
+	{ GPIO_AUX1, GPIOF_DIR_IN | GPIOF_EXPORT | GPIOF_EXPORT_CHANGEABLE,
+	  "minnow_gpio_aux1" },
+	{ GPIO_AUX2, GPIOF_DIR_IN | GPIOF_EXPORT | GPIOF_EXPORT_CHANGEABLE,
+	  "minnow_gpio_aux2" },
+	{ GPIO_AUX3, GPIOF_DIR_IN | GPIOF_EXPORT | GPIOF_EXPORT_CHANGEABLE,
+	  "minnow_gpio_aux3" },
+	{ GPIO_AUX4, GPIOF_DIR_IN | GPIOF_EXPORT | GPIOF_EXPORT_CHANGEABLE,
+	  "minnow_gpio_aux4" },
+};
+
+static int __init minnow_gpio_module_init(void)
+{
+	int err;
+
+	err = -ENODEV;
+	if (!minnow_detect())
+		goto out;
+
+	/* Auxillary Expansion GPIOs */
+	if (!minnow_lvds_detect()) {
+		pr_debug("LVDS_DETECT not asserted, configuring Aux GPIO lines\n");
+		err = gpio_request_array(expansion_aux_gpios,
+					 ARRAY_SIZE(expansion_aux_gpios));
+		if (err) {
+			pr_err("Failed to request expansion aux GPIO lines\n");
+			goto out;
+		}
+	} else {
+		pr_debug("LVDS_DETECT asserted, ignoring aux GPIO lines\n");
+	}
+
+	/* Expansion GPIOs */
+	err = gpio_request_array(expansion_gpios, ARRAY_SIZE(expansion_gpios));
+	if (err) {
+		pr_err("Failed to request expansion GPIO lines\n");
+		if (minnow_lvds_detect())
+			gpio_free_array(expansion_aux_gpios,
+					ARRAY_SIZE(expansion_aux_gpios));
+		goto out;
+	}
+
+ out:
+	return err;
+}
+
+static void __exit minnow_gpio_module_exit(void)
+{
+	if (minnow_lvds_detect())
+		gpio_free_array(expansion_aux_gpios,
+				ARRAY_SIZE(expansion_aux_gpios));
+	gpio_free_array(expansion_gpios, ARRAY_SIZE(expansion_gpios));
+}
+
+module_init(minnow_gpio_module_init);
+module_exit(minnow_gpio_module_exit);
+
+MODULE_LICENSE("GPL");
-- 
1.8.3.1