From: Sandeep Paulraj <[email protected]> Patch adds support for the Keypad on the DM365 EVM. At present the driver comes up fine and the device gets registered.
For the keypad to work, we need to enable with the help of the CPLD on the DM365 EVM. David Brownell has a patch ready(Thanks for sending me the patch David) The CPLD patch adds on top of my DM365 patches and also re arranges a lot of my code that i submitted. I'll wait for the all the patches to be reviewed/accepted In the mean while i'd like comments on the driver itself. Since it is DM365 EVM specific, i add all the structures in the board specific file rather than the DM365 SOC file Signed-off-by: Sandeep Paulraj <[email protected]> --- arch/arm/mach-davinci/board-dm365-evm.c | 53 ++++ arch/arm/mach-davinci/include/mach/dm365_keypad.h | 81 ++++++ drivers/input/keyboard/Kconfig | 6 + drivers/input/keyboard/Makefile | 1 + drivers/input/keyboard/dm365evm_keypad.c | 279 +++++++++++++++++++++ 5 files changed, 420 insertions(+), 0 deletions(-) create mode 100644 arch/arm/mach-davinci/include/mach/dm365_keypad.h create mode 100755 drivers/input/keyboard/dm365evm_keypad.c diff --git a/arch/arm/mach-davinci/board-dm365-evm.c b/arch/arm/mach-davinci/board-dm365-evm.c index 71cb53d..c9168c8 100644 --- a/arch/arm/mach-davinci/board-dm365-evm.c +++ b/arch/arm/mach-davinci/board-dm365-evm.c @@ -38,6 +38,7 @@ #include <mach/common.h> #include <mach/mmc.h> #include <mach/nand.h> +#include <mach/dm365_keypad.h> #define DM365_ASYNC_EMIF_CONTROL_BASE 0x01d10000 #define DM365_ASYNC_EMIF_DATA_CE0_BASE 0x02000000 @@ -115,6 +116,57 @@ static struct platform_device davinci_nand_device = { }, }; +static int dm365evm_keymap[] = { + KEY_DM365_KEY2, + KEY_DM365_LEFT, + KEY_DM365_EXIT, + KEY_DM365_DOWN, + KEY_DM365_ENTER, + KEY_DM365_UP, + KEY_DM365_KEY1, + KEY_DM365_RIGHT, + KEY_DM365_MENU, + KEY_DM365_REC, + KEY_DM365_REW, + KEY_DM365_SKIPMINUS, + KEY_DM365_STOP, + KEY_DM365_FF, + KEY_DM365_SKIPPLUL, + KEY_DM365_PLAYPAUSE, + 0 +}; + +static struct resource keypad_resources[] = { + [0] = { + /* registers */ + .start = DM365_KEYSCAN_BASE, + .end = DM365_KEYSCAN_BASE + SZ_1K - 1, + .flags = IORESOURCE_MEM, + }, + [1] = { + /* interrupt */ + .start = IRQ_DM365_KEYINT, + .end = IRQ_DM365_KEYINT, + .flags = IORESOURCE_IRQ, + }, +}; + +static struct dm365_kp_platform_data dm365evm_kp_data = { + .keymap = dm365evm_keymap, + .keymapsize = ARRAY_SIZE(dm365evm_keymap), + .rep = 1, +}; + +static struct platform_device dm365_kp_device = { + .name = "dm365_keypad", + .id = 0, + .dev = { + .platform_data = &dm365evm_kp_data, + }, + .num_resources = ARRAY_SIZE(keypad_resources), + .resource = keypad_resources, +}; + static struct at24_platform_data eeprom_info = { .byte_len = (256*1024) / 8, .page_size = 64, @@ -215,6 +267,7 @@ static void __init evm_init_i2c(void) static struct platform_device *dm365_evm_devices[] __initdata = { &davinci_nand_device, + &dm365_kp_device, }; static struct davinci_uart_config uart_config __initdata = { diff --git a/arch/arm/mach-davinci/include/mach/dm365_keypad.h b/arch/arm/mach-davinci/include/mach/dm365_keypad.h new file mode 100644 index 0000000..3d0b348 --- /dev/null +++ b/arch/arm/mach-davinci/include/mach/dm365_keypad.h @@ -0,0 +1,81 @@ +/* + * + * Copyright (C) 2009 Texas Instruments, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef __DM365_KEYPAD_H__ +#define __DM365_KEYPAD_H__ + +struct dm365_kp_platform_data { + int *keymap; + unsigned int keymapsize; + unsigned int rep:1; +}; + +/* Keypad registers */ +#define DM365_KEYSCAN_BASE 0x01C69400 +#define KEYPAD_BASE DM365_KEYSCAN_BASE +#define DM365_KEYPAD_KEYCTRL (0x0000) +#define DM365_KEYPAD_INTENA (0x0004) +#define DM365_KEYPAD_INTFLAG (0x0008) +#define DM365_KEYPAD_INTCLR (0x000c) +#define DM365_KEYPAD_STRBWIDTH (0x0010) +#define DM365_KEYPAD_INTERVAL (0x0014) +#define DM365_KEYPAD_CONTTIME (0x0018) +#define DM365_KEYPAD_CURRENTST (0x001c) +#define DM365_KEYPAD_PREVSTATE (0x0020) +#define DM365_KEYPAD_EMUCTRL (0x0024) +#define DM365_KEYPAD_IODFTCTRL (0x002c) + +/*Key Control Register (KEYCTRL)*/ + +#define DM365_KEYPAD_KEYEN 0x00000001 +#define DM365_KEYPAD_PREVMODE 0x00000002 +#define DM365_KEYPAD_CHATOFF 0x00000004 +#define DM365_KEYPAD_AUTODET 0x00000008 +#define DM365_KEYPAD_SCANMODE 0x00000010 +#define DM365_KEYPAD_OUTTYPE 0x00000020 +#define DM365_KEYPAD_4X4 0x00000040 + +/*Masks for the interrupts*/ + +#define DM365_KEYPAD_INT_CONT 0x00000008 +#define DM365_KEYPAD_INT_OFF 0x00000004 +#define DM365_KEYPAD_INT_ON 0x00000002 +#define DM365_KEYPAD_INT_CHANGE 0x00000001 +#define DM365_KEYPAD_INT_ALL 0x0000000f + +/*Masks for the various keys on the DM365*/ + +#define KEY_DM365_KEY2 0 +#define KEY_DM365_LEFT 1 +#define KEY_DM365_EXIT 2 +#define KEY_DM365_DOWN 3 +#define KEY_DM365_ENTER 4 +#define KEY_DM365_UP 5 +#define KEY_DM365_KEY1 6 +#define KEY_DM365_RIGHT 7 +#define KEY_DM365_MENU 8 +#define KEY_DM365_REC 9 +#define KEY_DM365_REW 10 +#define KEY_DM365_SKIPMINUS 11 +#define KEY_DM365_STOP 12 +#define KEY_DM365_FF 13 +#define KEY_DM365_SKIPPLUL 14 +#define KEY_DM365_PLAYPAUSE 15 + +#endif diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig index 5f09663..aee1790 100644 --- a/drivers/input/keyboard/Kconfig +++ b/drivers/input/keyboard/Kconfig @@ -340,4 +340,10 @@ config KEYBOARD_DM355EVM Supports the pushbuttons and IR remote used with the DM355 EVM board. +config KEYBOARD_DM365EVM + tristate "TI DaVinci DM365 EVM Keypad" + depends on ARCH_DAVINCI_DM365 + help + Supports only the keypad Module on the DM365 EVM + endif diff --git a/drivers/input/keyboard/Makefile b/drivers/input/keyboard/Makefile index a698caa..77d547d 100644 --- a/drivers/input/keyboard/Makefile +++ b/drivers/input/keyboard/Makefile @@ -29,3 +29,4 @@ obj-$(CONFIG_KEYBOARD_MAPLE) += maple_keyb.o obj-$(CONFIG_KEYBOARD_BFIN) += bf54x-keys.o obj-$(CONFIG_KEYBOARD_SH_KEYSC) += sh_keysc.o obj-$(CONFIG_KEYBOARD_DM355EVM) += dm355evm_keys.o +obj-$(CONFIG_KEYBOARD_DM365EVM) += dm365evm_keypad.o diff --git a/drivers/input/keyboard/dm365evm_keypad.c b/drivers/input/keyboard/dm365evm_keypad.c new file mode 100755 index 0000000..99b12e2 --- /dev/null +++ b/drivers/input/keyboard/dm365evm_keypad.c @@ -0,0 +1,279 @@ +/* + * + * Copyright (C) 2009 Texas Instruments, Inc + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#include <linux/module.h> +#include <linux/init.h> +#include <linux/interrupt.h> +#include <linux/types.h> +#include <linux/input.h> +#include <linux/kernel.h> +#include <linux/delay.h> +#include <linux/platform_device.h> +#include <linux/errno.h> +#include <linux/mutex.h> +#include <linux/io.h> +#include <asm/irq.h> +#include <mach/dm365_keypad.h> +#include <mach/hardware.h> +#include <mach/irqs.h> +#include <mach/mux.h> + +#define dm365_keypad_write(val, addr) __raw_writel(val, \ + (unsigned int *)((u32)dm365_kp_base + (u32)(addr))) +#define dm365_keypad_read(addr) __raw_readl(\ + (unsigned int *)((u32)dm365_kp_base + (u32)(addr))) + +struct davinci_kp { + struct input_dev *input; + int irq; +}; + +static void __iomem *dm365_kp_base; +static resource_size_t dm365_kp_pbase; +static size_t dm365_kp_base_size; +static int *keymap; + +void dm365_keypad_initialize(void) +{ + /*Initializing the Keypad Module */ + + /* Enable all interrupts */ + dm365_keypad_write(DM365_KEYPAD_INT_ALL, DM365_KEYPAD_INTENA); + + /* Clear interrupts if any */ + dm365_keypad_write(DM365_KEYPAD_INT_ALL, DM365_KEYPAD_INTCLR); + + /* Setup the scan period */ + dm365_keypad_write(0x05, DM365_KEYPAD_STRBWIDTH); + dm365_keypad_write(0x02, DM365_KEYPAD_INTERVAL); + dm365_keypad_write(0x01, DM365_KEYPAD_CONTTIME); + + /* Enable Keyscan module and enable */ + dm365_keypad_write(DM365_KEYPAD_AUTODET | DM365_KEYPAD_KEYEN, + DM365_KEYPAD_KEYCTRL); +} + +static irqreturn_t dm365_kp_interrupt(int irq, void *dev_id) +{ + int i; + unsigned int status, temp, temp1; + int keycode = KEY_UNKNOWN; + struct davinci_kp *dm365_kp = dev_id; + + /* Reading the status of the Keypad */ + status = dm365_keypad_read(DM365_KEYPAD_PREVSTATE); + + temp = ~status; + + for (i = 0; i < 16; i++) { + temp1 = temp >> i; + if (temp1 & 0x1) { + keycode = keymap[i]; + + /* report press + release */ + input_report_key(dm365_kp->input, keycode, 1); + input_sync(dm365_kp->input); + input_report_key(dm365_kp->input, keycode, 0); + input_sync(dm365_kp->input); + } + } + + /* clearing interrupts */ + dm365_keypad_write(DM365_KEYPAD_INT_ALL, DM365_KEYPAD_INTCLR); + + return IRQ_HANDLED; +} + +/* + * Registers keypad device with input sub system + * and configures DM365 keypad registers + */ +static int dm365_kp_probe(struct platform_device *pdev) +{ + struct davinci_kp *dm365_kp; + struct input_dev *key_dev; + struct resource *res, *mem; + int ret, i; + unsigned int val; + struct dm365_kp_platform_data *pdata = pdev->dev.platform_data; + + /* Enabling pins for Keypad */ + davinci_cfg_reg(DM365_KEYPAD); + + /* TODO + * Enable the Keypad Module by writing appropriate value + * to CPLD Register 3 + * Will wait for David Brownell's CPLD patch + */ + + if (!pdata->keymap) { + printk(KERN_ERR "No keymap from pdata\n"); + return -EINVAL; + } + + dm365_kp = kzalloc(sizeof *dm365_kp, GFP_KERNEL); + key_dev = input_allocate_device(); + + if (!dm365_kp || !key_dev) { + printk(KERN_ERR "Could not allocate input device\n"); + return -EINVAL; + } + + platform_set_drvdata(pdev, dm365_kp); + + dm365_kp->input = key_dev; + + dm365_kp->irq = platform_get_irq(pdev, 0); + if (dm365_kp->irq <= 0) { + pr_debug("%s: No DM365 Keypad irq\n", pdev->name); + goto fail1; + } + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + + dm365_kp_pbase = res->start; + dm365_kp_base_size = res->end - res->start + 1; + + if (res) + mem = request_mem_region(res->start, + dm365_kp_base_size, pdev->name); + else + mem = NULL; + + if (!mem) { + pr_debug("%s: KEYSCAN registers at %08x are not free\n", + pdev->name, DM365_KEYSCAN_BASE); + goto fail1; + } + + dm365_kp_base = ioremap(res->start, dm365_kp_base_size); + if (dm365_kp_base == NULL) { + pr_debug("%s: Can't ioremap MEM resource.\n", pdev->name); + goto fail2; + } + + /* Enable auto repeat feature of Linux input subsystem */ + if (pdata->rep) + set_bit(EV_REP, key_dev->evbit); + + /* setup input device */ + set_bit(EV_KEY, key_dev->evbit); + + /* Setup the keymap */ + keymap = pdata->keymap; + + for (i = 0; i < 16; i++) + set_bit(keymap[i], key_dev->keybit); + + key_dev->name = "dm365_keypad"; + key_dev->phys = "dm365_keypad/input0"; + key_dev->dev.parent = &pdev->dev; + + key_dev->id.bustype = BUS_HOST; + key_dev->id.vendor = 0x0001; + key_dev->id.product = 0x0365; + key_dev->id.version = 0x0001; + + key_dev->keycode = keymap; + key_dev->keycodesize = sizeof(unsigned int); + key_dev->keycodemax = pdata->keymapsize; + + ret = input_register_device(dm365_kp->input); + if (ret < 0) { + printk(KERN_ERR + "Unable to register DaVinci DM365 keypad device\n"); + goto fail3; + } + + ret = request_irq(dm365_kp->irq, dm365_kp_interrupt, IRQF_DISABLED, + "dm365_keypad", dm365_kp); + if (ret < 0) { + printk(KERN_ERR + "Unable to register DaVinci DM365 keypad Interrupt\n"); + goto fail4; + } + + dm365_keypad_initialize(); + + return 0; +fail4: + input_unregister_device(dm365_kp->input); +fail3: + iounmap(dm365_kp_base); +fail2: + release_mem_region(dm365_kp_pbase, dm365_kp_base_size); +fail1: + kfree(dm365_kp); + input_free_device(key_dev); + + /* TODO + * Re enabling other modules by doing a CPLD write + * Will wait for David Brownell's patch + */ + + return -EINVAL; +} + +static int __devexit dm365_kp_remove(struct platform_device *pdev) +{ + struct davinci_kp *dm365_kp = platform_get_drvdata(pdev); + + input_unregister_device(dm365_kp->input); + free_irq(dm365_kp->irq, dm365_kp); + kfree(dm365_kp); + + iounmap(dm365_kp_base); + release_mem_region(dm365_kp_pbase, dm365_kp_base_size); + + platform_set_drvdata(pdev, NULL); + + /* TODO + * Re enabling other modules by doing a CPLD write + * Will wait for David Brownell's patch + */ + + return 0; +} + +static struct platform_driver dm365_kp_driver = { + .probe = dm365_kp_probe, + .remove = __devexit_p(dm365_kp_remove), + .driver = { + .name = "dm365_keypad", + .owner = THIS_MODULE, + }, +}; + +static int __init dm365_kp_init(void) +{ + printk(KERN_INFO "DaVinci DM365 Keypad Driver\n"); + + return platform_driver_register(&dm365_kp_driver); +} + +static void __exit dm365_kp_exit(void) +{ + platform_driver_unregister(&dm365_kp_driver); +} + +module_init(dm365_kp_init); +module_exit(dm365_kp_exit); + +MODULE_AUTHOR("Sandeep Paulraj"); +MODULE_DESCRIPTION("Texas Instruments DaVinci DM365 EVM Keypad Driver"); +MODULE_LICENSE("GPL"); -- 1.6.0.4 _______________________________________________ Davinci-linux-open-source mailing list [email protected] http://linux.davincidsp.com/mailman/listinfo/davinci-linux-open-source
