[U-Boot] [PATCH 5/8] input: Add support for MPR121 touch controller

dietho at gmx.de dietho at gmx.de
Thu May 15 16:34:47 CEST 2014


From: Thomas Diener <dietho at gmx.de>

Signed-off-by: Thomas Diener <dietho at gmx.de>
---
 drivers/input/Makefile |    3 +-
 drivers/input/mpr121.c |   67 ++++++++++++++++++++
 include/mpr121.h       |  158 ++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 227 insertions(+), 1 deletion(-)
 create mode 100644 drivers/input/mpr121.c
 create mode 100644 include/mpr121.h

diff --git a/drivers/input/Makefile b/drivers/input/Makefile
index 203a311..a9fe157 100644
--- a/drivers/input/Makefile
+++ b/drivers/input/Makefile
@@ -15,4 +15,5 @@ endif
 obj-y += input.o
 obj-$(CONFIG_OF_CONTROL) += key_matrix.o
 obj-$(CONFIG_POLYTOUCH) += polytouch.o
-obj-$(CONFIG_FMA1125) += fma1125.o
\ No newline at end of file
+obj-$(CONFIG_FMA1125) += fma1125.o
+obj-$(CONFIG_MPR121) += mpr121.o
diff --git a/drivers/input/mpr121.c b/drivers/input/mpr121.c
new file mode 100644
index 0000000..66fcb2e
--- /dev/null
+++ b/drivers/input/mpr121.c
@@ -0,0 +1,67 @@
+/*
+ * (c) 2012 Graf-Syteco, Matthias Weisser
+ * <weisserm at arcor.de>
+ *
+ * mpr121.c - Freescale Semiconductor capacitive touch sensor controller
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ *
+ */
+
+#include <common.h>
+#include <i2c.h>
+#include <mpr121.h>
+
+int mpr121_init(const struct mpr121_register_tbl *lu, uint16_t num)
+{
+	int addr = 0;
+
+	if (NULL == lu)
+		return 0;
+
+	if (!i2c_probe(MPR121_SA_0))
+		addr = MPR121_SA_0;
+	else if (!i2c_probe(MPR121_SA_1))
+		addr = MPR121_SA_1;
+
+	if (addr == MPR121_SA_0 || addr == MPR121_SA_1) {
+		const struct mpr121_register_tbl *p;
+		int i;
+
+		p = lu;
+
+		for (i = 0; i < num; i++) {
+			i2c_reg_write(addr, p->addr, p->value);
+			p++;
+		}
+
+		return addr;
+	}
+	return 0;
+}
+
+int mpr121_get_touch_bits(u8 sa)
+{
+	int res;
+
+	res = i2c_reg_read(sa, MPR121_ELE0_7_TOUCH);
+	res += i2c_reg_read(sa, MPR121_ELE8_11_TOUCH) * 256;
+
+	return res;
+}
+
+void mpr121_set_leds_on(void)
+{
+	i2c_reg_write(0x62, 0x00 | 0x80, 0x00);
+
+	i2c_reg_write(0x62, 0x1C | 0x80, 0xFF);
+
+	i2c_reg_write(0x62, 0x14 | 0x80, 0xaa);
+	i2c_reg_write(0x62, 0x15 | 0x80, 0xaa);
+	i2c_reg_write(0x62, 0x16 | 0x80, 0xaa);
+	i2c_reg_write(0x62, 0x17 | 0x80, 0xaa);
+
+	i2c_reg_write(0x62, 0x02 | 0x80, 0xff);
+	i2c_reg_write(0x62, 0x06 | 0x80, 0xff);
+}
+
diff --git a/include/mpr121.h b/include/mpr121.h
new file mode 100644
index 0000000..1dadf00
--- /dev/null
+++ b/include/mpr121.h
@@ -0,0 +1,158 @@
+/*
+ * (c) 2012 Graf-Syteco, Matthias Weisser
+ * <weisserm at arcor.de>
+ *
+ * mpr121.h - Freescale Semiconductor capacitive touch sensor controller
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ *
+ */
+
+#ifndef __MPR121_H
+#define __MPR121_H
+
+#define MPR121_SA_0	0x5a
+#define MPR121_SA_1	0x5b
+#define MPR121_SA_2	0x5c
+#define MPR121_SA_3	0x5d
+
+#define MPR121_ELE0_7_TOUCH		0x00 /* Touch Status */
+#define MPR121_ELE8_11_TOUCH		0x01 /* ELEPROX Touch Status */
+#define MPR121_ELE0_7_OOR		0x02 /* OOR Status */
+#define MPR121_ELE8_11_OOR		0x03 /* ELEPROX OOR Status */
+#define MPR121_ELE0_L			0x04 /* Electrode Filtered Data LSB */
+#define MPR121_ELE0_H			0x05 /* Electrode Filtered Data MSB */
+#define MPR121_ELE1_L			0x06 /* Electrode Filtered Data LSB */
+#define MPR121_ELE1_H			0x07 /* Electrode Filtered Data MSB */
+#define MPR121_ELE2_L			0x08 /* Electrode Filtered Data LSB */
+#define MPR121_ELE2_H			0x09 /* Electrode Filtered Data MSB */
+#define MPR121_ELE3_L			0x0A /* Electrode Filtered Data LSB */
+#define MPR121_ELE3_H			0x0B /* Electrode Filtered Data MSB */
+#define MPR121_ELE4_L			0x0C /* Electrode Filtered Data LSB */
+#define MPR121_ELE4_H			0x0D /* Electrode Filtered Data MSB */
+#define MPR121_ELE5_L			0x0E /* Electrode Filtered Data LSB */
+#define MPR121_ELE5_H			0x0F /* Electrode Filtered Data MSB */
+#define MPR121_ELE6_L			0x10 /* Electrode Filtered Data LSB */
+#define MPR121_ELE6_H			0x11 /* Electrode Filtered Data MSB */
+#define MPR121_ELE7_L			0x12 /* Electrode Filtered Data LSB */
+#define MPR121_ELE7_H			0x13 /* Electrode Filtered Data MSB */
+#define MPR121_ELE8_L			0x14 /* Electrode Filtered Data LSB */
+#define MPR121_ELE8_H			0x15 /* Electrode Filtered Data MSB */
+#define MPR121_ELE9_L			0x16 /* Electrode Filtered Data LSB */
+#define MPR121_ELE9_H			0x17 /* Electrode Filtered Data MSB */
+#define MPR121_ELE10_L			0x18 /* Electrode Filtered Data LSB */
+#define MPR121_ELE10_H			0x19 /* Electrode Filtered Data MSB */
+#define MPR121_ELE11_L			0x1A /* Electrode Filtered Data LSB */
+#define MPR121_ELE11_H			0x1B /* Electrode Filtered Data MSB */
+#define MPR121_ELEPROX_L		0x1C /* Electrode Filtered Data LSB */
+#define MPR121_ELEPROX_H		0x1D /* Electrode Filtered Data MSB */
+#define MPR121_ELE0_BASELINE		0x1E /* Baseline Value */
+#define MPR121_ELE1_BASELINE		0x1F /* Baseline Value */
+#define MPR121_ELE2_BASELINE		0x20 /* Baseline Value */
+#define MPR121_ELE3_BASELINE		0x21 /* Baseline Value */
+#define MPR121_ELE4_BASELINE		0x22 /* Baseline Value */
+#define MPR121_ELE5_BASELINE		0x23 /* Baseline Value */
+#define MPR121_ELE6_BASELINE		0x24 /* Baseline Value */
+#define MPR121_ELE7_BASELINE		0x25 /* Baseline Value */
+#define MPR121_ELE8_BASELINE		0x26 /* Baseline Value */
+#define MPR121_ELE9_BASELINE		0x27 /* Baseline Value */
+#define MPR121_ELE10_BASELINE		0x28 /* Baseline Value */
+#define MPR121_ELE11_BASELINE		0x29 /* Baseline Value */
+#define MPR121_ELEPROX			0x2A /* Baseline Value */
+#define MPR121_MHD_RIS			0x2B /* Rising */
+#define MPR121_NHD_RIS			0x2C /* Amount Rising */
+#define MPR121_NCL_RIS			0x2D /* Rising */
+#define MPR121_FDL_RIS			0x2E /* Rising */
+#define MPR121_MHD_FALL			0x2F /* Falling */
+#define MPR121_NHD_FALL			0x30 /* Amount Falling */
+#define MPR121_NCL_FALL			0x31 /* Falling */
+#define MPR121_FDL_FALL			0x32 /* Falling */
+#define MPR121_NHD_TOUCH		0x33 /* Amount Touched */
+#define MPR121_NCL_TOUCH		0x34 /* Touched */
+#define MPR121_FDL_TOUCH		0x35 /* Touched */
+#define MPR121_ELEPROX_MHD_RIS		0x36 /* Rising */
+#define MPR121_ELEPROX_NHD_RIS		0x37 /* Amount Rising */
+#define MPR121_ELEPROX_NCL_RIS		0x38 /* Rising */
+#define MPR121_ELEPROX_FDL_RIS		0x39 /* Rising */
+#define MPR121_ELEPROX_MHD_FALL		0x3A /* Falling */
+#define MPR121_ELEPROX_NHD_FALL		0x3B /* Amount Falling */
+#define MPR121_ELEPROX_NCL_FALL		0x3C /* Falling */
+#define MPR121_ELEPROX_FDL_FALL		0x3D /* Falling */
+#define MPR121_ELEPROX_NHD_TOUCH	0x3E /* Amount Touched */
+#define MPR121_ELEPROX_NCL_TOUCH	0x3F /* Touched */
+#define MPR121_ELEPROX_FDL_TOUCH	0x40 /* Touched */
+#define MPR121_ELE0_THRESH_TOUCH	0x41 /* Touch Threshold */
+#define MPR121_ELE0_THRESH_REL		0x42 /* Release Threshold */
+#define MPR121_ELE1_THRESH_TOUCH	0x43 /* Touch Threshold */
+#define MPR121_ELE1_THRESH_REL		0x44 /* Release Threshold */
+#define MPR121_ELE2_THRESH_TOUCH	0x45 /* Touch Threshold */
+#define MPR121_ELE2_THRESH_REL		0x46 /* Release Threshold */
+#define MPR121_ELE3_THRESH_TOUCH	0x47 /* Touch Threshold */
+#define MPR121_ELE3_THRESH_REL		0x48 /* Release Threshold */
+#define MPR121_ELE4_THRESH_TOUCH	0x49 /* Touch Threshold */
+#define MPR121_ELE4_THRESH_REL		0x4A /* Release Threshold */
+#define MPR121_ELE5_THRESH_TOUCH	0x4B /* Touch Threshold */
+#define MPR121_ELE5_THRESH_REL		0x4C /* Release Threshold */
+#define MPR121_ELE6_THRESH_TOUCH	0x4D /* Touch Threshold */
+#define MPR121_ELE6_THRESH_REL		0x4E /* Release Threshold */
+#define MPR121_ELE7_THRESH_TOUCH	0x4F /* Touch Threshold */
+#define MPR121_ELE7_THRESH_REL		0x50 /* Release Threshold */
+#define MPR121_ELE8_THRESH_TOUCH	0x51 /* Touch Threshold */
+#define MPR121_ELE8_THRESH_REL		0x52 /* Release Threshold */
+#define MPR121_ELE9_THRESH_TOUCH	0x53 /* Touch Threshold */
+#define MPR121_ELE9_THRESH_REL		0x54 /* Release Threshold */
+#define MPR121_ELE10_THRESH_TOUCH	0x55 /* Touch Threshold */
+#define MPR121_ELE10_THRESH_REL		0x56 /* Release Threshold */
+#define MPR121_ELE11_THRESH_TOUCH	0x57 /* Touch Threshold */
+#define MPR121_ELE11_THRESH_REL		0x58 /* Release Threshold */
+#define MPR121_ELEPROX_THRESH_TOUCH	0x59 /* Touch Threshold */
+#define MPR121_ELEPROX_THRESH_REL	0x5A /* Release Threshold */
+#define MPR121_DBC			0x5B /* Debounce Touch & Release */
+#define MPR121_FILT_CDC			0x5C /* Filter CDC Configuration */
+#define MPR121_FILT_CDT			0x5D /* Filter CDT Configuration */
+#define MPR121_ECR			0x5E /* Electrode Configuration */
+#define MPR121_ELE0_CURRENT		0x5F /* Electrode Current */
+#define MPR121_ELE1_CURRENT		0x60 /* Electrode Current */
+#define MPR121_ELE2_CURRENT		0x61 /* Electrode Current */
+#define MPR121_ELE3_CURRENT		0x62 /* Electrode Current */
+#define MPR121_ELE4_CURRENT		0x63 /* Electrode Current */
+#define MPR121_ELE5_CURRENT		0x64 /* Electrode Current */
+#define MPR121_ELE6_CURRENT		0x65 /* Electrode Current */
+#define MPR121_ELE7_CURRENT		0x66 /* Electrode Current */
+#define MPR121_ELE8_CURRENT		0x67 /* Electrode Current */
+#define MPR121_ELE9_CURRENT		0x68 /* Electrode Current */
+#define MPR121_ELE10_CURRENT		0x69 /* Electrode Current */
+#define MPR121_ELE11_CURRENT		0x6A /* Electrode Current */
+#define MPR121_ELEPROX_CURRENT		0x6B /* Electrode Current */
+#define MPR121_ELE0_1_CHARGE		0x6C /* Charge Time */
+#define MPR121_ELE2_3_CHARGE		0x6D /* Charge Time */
+#define MPR121_ELE4_5_CHARGE		0x6E /* Charge Time */
+#define MPR121_ELE6_7_CHARGE		0x6F /* Charge Time */
+#define MPR121_ELE8_9_CHARGE		0x70 /* Charge Time */
+#define MPR121_ELE10_11_CHARGE		0x71 /* Charge Time */
+#define MPR121_ELEPROX_CHARGE		0x72 /* Charge Time */
+#define MPR121_GPIO_CTRL0		0x73 /* Control Register 0 */
+#define MPR121_GPIO_CTRL1		0x74 /* Control Register 1 */
+#define MPR121_GPIO_DATA		0x75 /* Data Register */
+#define MPR121_GPIO_DIR			0x76 /* Direction Register */
+#define MPR121_GPIO_EN			0x77 /* Enable Register */
+#define MPR121_GPIO_SET			0x78 /* Data Set Register */
+#define MPR121_GPIO_CLR			0x79 /* Data Clear Register */
+#define MPR121_GPIO_TOG			0x7A /* Data Toggle Register */
+#define MPR121_AUTO_CONFIG_CTRL0	0x7B /* Control Register 0 */
+#define MPR121_AUTO_CONFIG_CTRL1	0x7C /* Control Register 1 */
+#define MPR121_AUTO_CONFIG_USL		0x7D /* USL Register */
+#define MPR121_AUTO_CONFIG_LSL		0x7E /* LSL Register */
+#define MPR121_AUTO_CONFIG_TLR		0x7F /* Target Level Register */
+#define MPR121_SRST			0x80 /* Soft Reset Register */
+
+struct mpr121_register_tbl {
+	uint8_t addr;
+	uint8_t value;
+};
+
+int mpr121_init(const struct mpr121_register_tbl *lu, uint16_t num);
+int mpr121_get_touch_bits(u8 sa);
+void mpr121_set_leds_on(void);
+
+#endif
-- 
1.7.9.5



More information about the U-Boot mailing list