Commit 48d16220 authored by Klaus Pedersen's avatar Klaus Pedersen Committed by Tony Lindgren

I2C: TWL4030 keyboard driver enhancements

While getting trying to get the keyboard driver to accept my
keyboard layout I found and fixed a few bugs.

- Fixed the driver to respect the matrix size and .rep
  fields from "struct omap_kp_platform_data"

- Fixed misc. configuration problems.

- Fixed some problems with the interrupt/polling code by
  implementing 100% event driven scan handling (there
  was a race between the timer and interrupt initiated
  calls to twl_4030_kp_scan()).

- Too many interrupts was delivered -> enable "PENDING_DISABLE".

- The controller would hang with keys stuck on -> program
  KEYP_TIMEOUT so sensible timeout.

Other enhancements:

- Simple ghost key suppression.
- Support for non-matrix switches. That is switches connected
  between GND and a row.

To configure the driver for the non-matrix switches you add the
key as you normally would, but the col-index will have to be the
same value as the col-size.

For example with .cols = 2 and you will use the value "2" for
COL for the two non-matrix switches:

static int rocket_control_keymap[] = {
	/* COL ROW */
	KEY(0,  0, KEY_3),
	KEY(0,  1, KEY_2),
	KEY(1,  0, KEY_1),
	KEY(1,  1, KEY_LAUNCH),
	KEY(2,  0, KEY_ABORT),
	KEY(2,  1, KEY_SD),
	0
}

Cleanup:

I might have gone too far when fixing the twl4030-keypad.h file,
but I was loosing breath and attention spelling my way through
these 32+ letter identifiers with names like:

    BIT_KEYP_CTRL_REG_TOLE_EN_MASK

which is a bit in the register:

   REG_KEYP_CTRL_REG

leading to statements like:

   twl4030_kpwrite_u8(TWL4030_MODULE_KEYPAD,
           BIT_KEYP_CTRL_REG_TOLE_EN_MASK, REG_KEYP_CTRL_REG);

What I did was to take out all the redundant stuff like BIT, REG
and MASK, making reading a little easier:

   twl4030_kpwrite_u8(TWL4030_MODULE_KEYPAD,
                      KEYP_CTRL_TOLE_EN, KEYP_CTRL);

There was a lot of configuration stuff in header file that wasn't
really needed. I think I even found a joke:

.h had this line:
   #define BIT_PTV_REG_PTV4                       (0x4)

.c had this:
       /* Set Pre Scalar Field PTV to 4 */
       reg = BIT_LK_PTV_REG_PTV_MASK & (BIT_PTV_REG_PTV4 << BIT_LK_PTV_REG_PTV);
Signed-off-by: default avatarKlaus Pedersen <klaus.k.pedersen@nokia.com>
Signed-off-by: default avatarTony Lindgren <tony@atomide.com>
parent 7d414b71
This diff is collapsed.
......@@ -24,53 +24,59 @@
#define __TWL4030_KEYPAD_H__
/* Register Definitions */
#define REG_KEYP_CTRL_REG (0x0)
#define REG_KEY_DEB_REG (0x1)
#define REG_LK_PTV_REG (0x3)
#define REG_FULL_CODE_7_0 (0x9)
#define REG_KEYP_ISR1 (0x11)
#define REG_KEYP_IMR1 (0x12)
#define REG_KEYP_EDR (0x16)
#define REG_KEYP_SIH_CTRL (0x17)
#define KEYP_CTRL 0x00
#define KEYP_DEB 0x01
#define KEYP_LONG_KEY 0x02
#define KEYP_LK_PTV 0x03
#define KEYP_TIMEOUT_L 0x04
#define KEYP_TIMEOUT_H 0x05
#define KEYP_FULL_CODE_7_0 0x09
#define KEYP_ISR1 0x11
#define KEYP_IMR1 0x12
#define KEYP_EDR 0x16
#define KEYP_SIH_CTRL 0x17
/* KEYP_CTRL_REG Fields */
#define BIT_KEYP_CTRL_REG_SOFT_NRST_MASK (0x00000001)
#define BIT_KEYP_CTRL_REG_SOFTMODEN_MASK (0x00000002)
#define BIT_KEYP_CTRL_REG_LK_EN_MASK (0x00000004)
#define BIT_KEYP_CTRL_REG_TOE_EN_MASK (0x00000008)
#define BIT_KEYP_CTRL_REG_TOLE_EN_MASK (0x00000010)
#define BIT_KEYP_CTRL_REG_RP_EN_MASK (0x00000020)
#define BIT_KEYP_CTRL_REG_KBD_ON_MASK (0x00000040)
#define KEYP_CTRL_SOFT_NRST 0x01
#define KEYP_CTRL_SOFTMODEN 0x02
#define KEYP_CTRL_LK_EN 0x04
#define KEYP_CTRL_TOE_EN 0x08
#define KEYP_CTRL_TOLE_EN 0x10
#define KEYP_CTRL_RP_EN 0x20
#define KEYP_CTRL_KBD_ON 0x40
#define KEYP_CTRL_REG_MASK_NOAUTORPT BIT_KEYP_CTRL_REG_SOFT_NRST_MASK |\
BIT_KEYP_CTRL_REG_SOFTMODEN_MASK |\
BIT_KEYP_CTRL_REG_KBD_ON_MASK
#define KEYP_CTRL_NOAUTORPT (KEYP_CTRL_SOFT_NRST | \
KEYP_CTRL_SOFTMODEN | \
KEYP_CTRL_TOE_EN | \
KEYP_CTRL_KBD_ON)
/* LK_PTV_REG Fields */
#define BIT_LK_PTV_REG_PTV (0x005)
#define BIT_LK_PTV_REG_PTV_MASK (0x000000E0)
#define BIT_PTV_REG_PTV4 (0x4)
/* KEYP_DEB, KEYP_LONG_KEY, KEYP_TIMEOUT_x*/
#define KEYP_PERIOD_US(T, prescale) (T / (31 << (prescale + 1)) - 1)
/* KEYP_LK_PTV_REG Fields */
#define KEYP_LK_PTV_PTV_SHIFT 5
/* KEYP_IMR1 Fields */
#define KEYP_IMR1_MASK (0x0F)
#define KEYP_IMR1_UNMASK (0x00)
#define KEYP_IMR1_MIS 0x08
#define KEYP_IMR1_TO 0x04
#define KEYP_IMR1_LK 0x02
#define KEYP_IMR1_KP 0x01
/* KEYP_EDR Fields */
#define BIT_KEYP_EDR_ITKPFALLING_MASK (0x00000001)
#define BIT_KEYP_EDR_ITKPRISING_MASK (0x00000002)
#define BIT_KEYP_EDR_ITLKFALLING_MASK (0x00000004)
#define BIT_KEYP_EDR_ITLKRISING_MASK (0x00000008)
#define BIT_KEYP_EDR_ITTOFALLING_MASK (0x00000010)
#define BIT_KEYP_EDR_ITTORISING_MASK (0x00000020)
#define BIT_KEYP_EDR_ITMISFALLING_MASK (0x00000040)
#define BIT_KEYP_EDR_ITMISRISING_MASK (0x00000080)
#define KEYP_EDR_KP_FALLING 0x01
#define KEYP_EDR_KP_RISING 0x02
#define KEYP_EDR_KP_BOTH 0x03
#define KEYP_EDR_LK_FALLING 0x04
#define KEYP_EDR_LK_RISING 0x08
#define KEYP_EDR_TO_FALLING 0x10
#define KEYP_EDR_TO_RISING 0x20
#define KEYP_EDR_MIS_FALLING 0x40
#define KEYP_EDR_MIS_RISING 0x80
#define KEYP_EDR_MASK BIT_KEYP_EDR_ITKPFALLING_MASK |\
BIT_KEYP_EDR_ITLKFALLING_MASK |\
BIT_KEYP_EDR_ITTOFALLING_MASK |\
BIT_KEYP_EDR_ITMISFALLING_MASK
/* KEYP_SIH_CTRL Fields */
#define KEYP_SIH_CTRL_MASK (0x04)
#define KEYP_SIH_CTRL_COR 0x04
#define KEYP_SIH_CTRL_PEND_DIS 0x02
#define KEYP_SIH_CTRL_EXCL_EN 0x01
#endif /* End of __TWL4030-KEYPAD_H__ */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment