4x4 Matrix keypad Interfacing with i-MX6

I want to interface 4x4 matrix keypad with i-MX6 for that I have selected the pins KEY_COL0 - KEY_COL3 and KEY_ROW0 - KEY_ROW3 .But I am confused about how to modify the driver imx_keypad.c for that and how to modify the device tree file. If any one has done this plz. help me

Are you referring to the keypad driver here?

If yes, then did you have a look at the device tree binding documentation here?

Thanks Sanchayan.
I have seen that document but I am unable to understand that should I make changes to below lines in driver code:

#define MAX_MATRIX_KEY_ROWS	8 (Line 45)
#define MAX_MATRIX_KEY_COLS	        8 (Line 46)
reg_val |= keypad->rows_en_mask & 0xff;		/* rows */  (Line 325)
reg_val |= (keypad->cols_en_mask & 0xff) << 8;	/* cols */    (Line 326)
reg_val &= 0x00ff; (Line 331)

like these more lines are there…
In device tree binding I am unable to understand these addresses:

linux,keymap = <0x00000067	/* KEY_UP */
			0x0001006c	/* KEY_DOWN */
			0x00020072	/* KEY_VOLUMEDOWN */
			0x00030066	/* KEY_HOME */
			0x0100006a	/* KEY_RIGHT */
			0x01010069	/* KEY_LEFT */
			0x0102001c	/* KEY_ENTER */
			0x01030073	/* KEY_VOLUMEUP */
			0x02000040	/* KEY_F6 */
			0x02010042	/* KEY_F8 */
			0x02020043	/* KEY_F9 */
			0x02030044	/* KEY_F10 */
			0x0300003b	/* KEY_F1 */
			0x0301003c	/* KEY_F2 */
			0x0302003d	/* KEY_F3 */
			0x03030074>;	/* KEY_POWER */ 

Now, my question is can I use same driver for 4X4 matrix keypad or else I need to change the driver code.
If I need to modify the driver code,which part of the code I need to modify?
Thanks in Advance

Have a look here for an example of how one could define it in the device tree. Appropriate pinctrl definitions would be required for pin multiplexing as an example here.

These changes can be added in the Colibri Evaluation Board device tree file. For the pinctrl definitions, you can have a look in this file. You would need to specify the pinctrl definitions as per your required pin multiplexing and make sure it does not conflict with existing pin multiplexing configuration. Please have a look at Section 4.4 Function List of the Colibri iMX6 datasheet.

In addition you would also need to add

compatible = "fsl,imx6qdl-kpp", "fsl,imx21-kpp";
clocks = <&clks IMX6QDL_CLK_DUMMY>;

as the main keypad device tree definition does not specify these which would be required to bind to the driver. To clarify we never tested this but perhaps it might work by changing it to 4 here for a 4 x 4 keypad.

Also to add, the linux,keymap basically specifies what key events already known by Linux would be generated. For example, with this, a key press would generate an Enter key press event being reported by Linux kernel to userspace.

Thank Yo Very much.
I will try with these settings.
Also, I am unable to find the Board.c file for colibri i-MX6 in U-boot source code,can you plz. send me a link for that.

Unless related, for a different topic we would recommend opening new post.

colibri_imx6 board file can be found here.

Thank You.

@sanchayan.tx Do I have to connect exactly the GPIOs for Row and Column or can I connect to any GPIOs?

pinctrl_kpp: kppgrp {
			fsl,pins = <
				MX6QDL_PAD_EIM_CS0__GPIO2_IO23     0x1b010 /* ROW0 */
				MX6QDL_PAD_EIM_CS1__GPIO2_IO24     0x1b010 /* ROW1 */
				MX6QDL_PAD_SD2_DAT1__GPIO1_IO14    0x1b0b0 /* ROW2 */
				MX6QDL_PAD_NANDF_D2__GPIO2_IO02    0x1b0b0 /* ROW3 */
				MX6QDL_PAD_GPIO_6__GPIO1_IO06      0x110b0 /* COL0 */
				MX6QDL_PAD_GPIO_3__GPIO1_IO03      0x110b0 /* COL1 */

To use the i.MX keypad controller you need to connect to pads which can be muxed for KEY_COL/KEY_ROW functionality. Refer also to the Colibri iMX6 datasheet chapter 5.24 Keypad and 4.4.1.

However, if you want to use single GPIOs as keys you can use the GPIO key driver.

If you need further discussion please create a new topic with complete information about your environment (BSP version/Module etc.).

Hi @hrushi,

How do I calculate the value in the register keymap , reg_val |= keypad->rows_en_mask & 0xff; ?
I do not have any keypad driver code made, and I have to program 5 keypad buttons into it?