blob: 6174733a57ebc60b68fe674d1c271bb8af6d9d51 [file] [log] [blame]
Eric Miaobab76142009-06-29 00:20:52 -07001#ifndef _MATRIX_KEYPAD_H
2#define _MATRIX_KEYPAD_H
3
4#include <linux/types.h>
5#include <linux/input.h>
Olof Johansson2cd36872012-03-13 21:35:51 -07006#include <linux/of.h>
Eric Miaobab76142009-06-29 00:20:52 -07007
Trilok Sonicfaea562011-02-11 00:44:41 -08008#define MATRIX_MAX_ROWS 32
9#define MATRIX_MAX_COLS 32
Eric Miaobab76142009-06-29 00:20:52 -070010
11#define KEY(row, col, val) ((((row) & (MATRIX_MAX_ROWS - 1)) << 24) |\
12 (((col) & (MATRIX_MAX_COLS - 1)) << 16) |\
Janusz Krzysztofikda1f0262010-12-20 21:09:22 +000013 ((val) & 0xffff))
Eric Miaobab76142009-06-29 00:20:52 -070014
15#define KEY_ROW(k) (((k) >> 24) & 0xff)
16#define KEY_COL(k) (((k) >> 16) & 0xff)
17#define KEY_VAL(k) ((k) & 0xffff)
18
Eric Miaod82f1c32009-08-05 01:24:41 -070019#define MATRIX_SCAN_CODE(row, col, row_shift) (((row) << (row_shift)) + (col))
20
Eric Miaobab76142009-06-29 00:20:52 -070021/**
22 * struct matrix_keymap_data - keymap for matrix keyboards
23 * @keymap: pointer to array of uint32 values encoded with KEY() macro
24 * representing keymap
25 * @keymap_size: number of entries (initialized) in this keymap
Eric Miaobab76142009-06-29 00:20:52 -070026 *
27 * This structure is supposed to be used by platform code to supply
28 * keymaps to drivers that implement matrix-like keypads/keyboards.
29 */
30struct matrix_keymap_data {
31 const uint32_t *keymap;
32 unsigned int keymap_size;
Eric Miaobab76142009-06-29 00:20:52 -070033};
34
35/**
36 * struct matrix_keypad_platform_data - platform-dependent keypad data
37 * @keymap_data: pointer to &matrix_keymap_data
Eric Miaod82f1c32009-08-05 01:24:41 -070038 * @row_gpios: pointer to array of gpio numbers representing rows
39 * @col_gpios: pointer to array of gpio numbers reporesenting colums
Eric Miaobab76142009-06-29 00:20:52 -070040 * @num_row_gpios: actual number of row gpios used by device
41 * @num_col_gpios: actual number of col gpios used by device
42 * @col_scan_delay_us: delay, measured in microseconds, that is
43 * needed before we can keypad after activating column gpio
44 * @debounce_ms: debounce interval in milliseconds
Luotao Fufb76dd12010-06-10 12:05:23 -070045 * @clustered_irq: may be specified if interrupts of all row/column GPIOs
46 * are bundled to one single irq
47 * @clustered_irq_flags: flags that are needed for the clustered irq
Dmitry Torokhovd69249f2009-11-16 22:12:20 -080048 * @active_low: gpio polarity
49 * @wakeup: controls whether the device should be set up as wakeup
50 * source
H Hartley Sweeten9d32c302010-04-05 22:29:09 -070051 * @no_autorepeat: disable key autorepeat
David Rivshinaa0e26b2017-03-29 00:14:16 -070052 * @drive_inactive_cols: drive inactive columns during scan, rather than
53 * making them inputs.
Eric Miaobab76142009-06-29 00:20:52 -070054 *
55 * This structure represents platform-specific data that use used by
56 * matrix_keypad driver to perform proper initialization.
57 */
58struct matrix_keypad_platform_data {
59 const struct matrix_keymap_data *keymap_data;
60
Eric Miaod82f1c32009-08-05 01:24:41 -070061 const unsigned int *row_gpios;
62 const unsigned int *col_gpios;
63
Eric Miaobab76142009-06-29 00:20:52 -070064 unsigned int num_row_gpios;
65 unsigned int num_col_gpios;
66
67 unsigned int col_scan_delay_us;
68
69 /* key debounce interval in milli-second */
70 unsigned int debounce_ms;
71
Luotao Fufb76dd12010-06-10 12:05:23 -070072 unsigned int clustered_irq;
73 unsigned int clustered_irq_flags;
74
Eric Miaobab76142009-06-29 00:20:52 -070075 bool active_low;
76 bool wakeup;
H Hartley Sweeten9d32c302010-04-05 22:29:09 -070077 bool no_autorepeat;
David Rivshinaa0e26b2017-03-29 00:14:16 -070078 bool drive_inactive_cols;
Eric Miaobab76142009-06-29 00:20:52 -070079};
80
Dmitry Torokhov19328112012-05-10 22:37:08 -070081int matrix_keypad_build_keymap(const struct matrix_keymap_data *keymap_data,
82 const char *keymap_name,
83 unsigned int rows, unsigned int cols,
84 unsigned short *keymap,
85 struct input_dev *input_dev);
Dmitry Torokhovaef01aa2016-11-11 12:43:12 -080086int matrix_keypad_parse_properties(struct device *dev,
87 unsigned int *rows, unsigned int *cols);
Dmitry Torokhov77a53fd2009-08-25 19:24:13 -070088
Dmitry Torokhovaef01aa2016-11-11 12:43:12 -080089#define matrix_keypad_parse_of_params matrix_keypad_parse_properties
Simon Glass43840412013-02-25 14:08:40 -080090
Eric Miaobab76142009-06-29 00:20:52 -070091#endif /* _MATRIX_KEYPAD_H */