Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef _MATRIX_KEYPAD_H
0003 #define _MATRIX_KEYPAD_H
0004 
0005 #include <linux/types.h>
0006 #include <linux/input.h>
0007 #include <linux/of.h>
0008 
0009 #define MATRIX_MAX_ROWS     32
0010 #define MATRIX_MAX_COLS     32
0011 
0012 #define KEY(row, col, val)  ((((row) & (MATRIX_MAX_ROWS - 1)) << 24) |\
0013                  (((col) & (MATRIX_MAX_COLS - 1)) << 16) |\
0014                  ((val) & 0xffff))
0015 
0016 #define KEY_ROW(k)      (((k) >> 24) & 0xff)
0017 #define KEY_COL(k)      (((k) >> 16) & 0xff)
0018 #define KEY_VAL(k)      ((k) & 0xffff)
0019 
0020 #define MATRIX_SCAN_CODE(row, col, row_shift)   (((row) << (row_shift)) + (col))
0021 
0022 /**
0023  * struct matrix_keymap_data - keymap for matrix keyboards
0024  * @keymap: pointer to array of uint32 values encoded with KEY() macro
0025  *  representing keymap
0026  * @keymap_size: number of entries (initialized) in this keymap
0027  *
0028  * This structure is supposed to be used by platform code to supply
0029  * keymaps to drivers that implement matrix-like keypads/keyboards.
0030  */
0031 struct matrix_keymap_data {
0032     const uint32_t *keymap;
0033     unsigned int    keymap_size;
0034 };
0035 
0036 /**
0037  * struct matrix_keypad_platform_data - platform-dependent keypad data
0038  * @keymap_data: pointer to &matrix_keymap_data
0039  * @row_gpios: pointer to array of gpio numbers representing rows
0040  * @col_gpios: pointer to array of gpio numbers reporesenting colums
0041  * @num_row_gpios: actual number of row gpios used by device
0042  * @num_col_gpios: actual number of col gpios used by device
0043  * @col_scan_delay_us: delay, measured in microseconds, that is
0044  *  needed before we can keypad after activating column gpio
0045  * @debounce_ms: debounce interval in milliseconds
0046  * @clustered_irq: may be specified if interrupts of all row/column GPIOs
0047  *  are bundled to one single irq
0048  * @clustered_irq_flags: flags that are needed for the clustered irq
0049  * @active_low: gpio polarity
0050  * @wakeup: controls whether the device should be set up as wakeup
0051  *  source
0052  * @no_autorepeat: disable key autorepeat
0053  * @drive_inactive_cols: drive inactive columns during scan, rather than
0054  *  making them inputs.
0055  *
0056  * This structure represents platform-specific data that use used by
0057  * matrix_keypad driver to perform proper initialization.
0058  */
0059 struct matrix_keypad_platform_data {
0060     const struct matrix_keymap_data *keymap_data;
0061 
0062     const unsigned int *row_gpios;
0063     const unsigned int *col_gpios;
0064 
0065     unsigned int    num_row_gpios;
0066     unsigned int    num_col_gpios;
0067 
0068     unsigned int    col_scan_delay_us;
0069 
0070     /* key debounce interval in milli-second */
0071     unsigned int    debounce_ms;
0072 
0073     unsigned int    clustered_irq;
0074     unsigned int    clustered_irq_flags;
0075 
0076     bool        active_low;
0077     bool        wakeup;
0078     bool        no_autorepeat;
0079     bool        drive_inactive_cols;
0080 };
0081 
0082 int matrix_keypad_build_keymap(const struct matrix_keymap_data *keymap_data,
0083                    const char *keymap_name,
0084                    unsigned int rows, unsigned int cols,
0085                    unsigned short *keymap,
0086                    struct input_dev *input_dev);
0087 int matrix_keypad_parse_properties(struct device *dev,
0088                    unsigned int *rows, unsigned int *cols);
0089 
0090 #define matrix_keypad_parse_of_params matrix_keypad_parse_properties
0091 
0092 #endif /* _MATRIX_KEYPAD_H */