Subversion Repositories HelenOS

Rev

Rev 4632 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * Copyright (c) 2001-2004 Jakub Jermar
  3.  * Copyright (c) 2006 Josef Cejka
  4.  * Copyright (c) 2009 Vineeth Pillai
  5.  * All rights reserved.
  6.  *
  7.  * Redistribution and use in source and binary forms, with or without
  8.  * modification, are permitted provided that the following conditions
  9.  * are met:
  10.  *
  11.  * - Redistributions of source code must retain the above copyright
  12.  *   notice, this list of conditions and the following disclaimer.
  13.  * - Redistributions in binary form must reproduce the above copyright
  14.  *   notice, this list of conditions and the following disclaimer in the
  15.  *   documentation and/or other materials provided with the distribution.
  16.  * - The name of the author may not be used to endorse or promote products
  17.  *   derived from this software without specific prior written permission.
  18.  *
  19.  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  20.  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  21.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  22.  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  23.  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  24.  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  28.  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29.  */
  30.  
  31. /** @addtogroup kbdarm32 arm32
  32.  * @brief   HelenOS arm32/integratorcp arch dependent parts of uspace keyboard handler.
  33.  * @ingroup  kbd
  34.  * @{
  35.  */
  36. /** @file
  37.  * @ingroup kbdarm32
  38.  */
  39. #include <stdio.h>
  40. #include <arch/kbd.h>
  41. #include <ipc/ipc.h>
  42. #include <unistd.h>
  43. #include <kbd.h>
  44. #include <arch/pl050.h>
  45. #include <keys.h>
  46. #include <genarch/kbd.h>
  47. #include <sysinfo.h>
  48. #include <as.h>
  49. #include <ipc/ipc.h>
  50. #include <ipc/ns.h>
  51. #include <ipc/services.h>
  52. #include <ddi.h>
  53. #include <align.h>
  54.  
  55. #define PL050_KEY_RELEASE 0xF0
  56. #define PL050_ESC_KEY   0xE0
  57. #define PL050_CAPS_SCAN_CODE   0x58
  58.  
  59. irq_cmd_t pl050_cmds[] = {
  60.     { CMD_MEM_READ_1, (void *) 0, 0, 1 },
  61.     { CMD_MEM_READ_1, (void *) 0, 0, 2}
  62. };
  63.  
  64. irq_code_t pl050_kbd = {
  65.     2,
  66.     pl050_cmds
  67. };
  68.  
  69.  
  70. static  void *kbd_physaddr;
  71. static  void *kbd_addr;
  72.  
  73. /** Register uspace irq handler
  74.  * @return
  75.  */
  76. int kbd_arch_init(void)
  77. {
  78.     kbd_physaddr = (void *)sysinfo_value("kbd.pbase");
  79.  
  80.     kbd_addr = (void*)sysinfo_value("kbd.vbase");
  81.  
  82.     pl050_cmds[0].addr = (void *)(kbd_addr+PL050_DATA);
  83.     pl050_cmds[1].addr = (void *)(kbd_addr+PL050_STAT);
  84.  
  85.     /* Enable kbd */
  86.     ipc_register_irq(sysinfo_value("kbd.inr"), sysinfo_value("kbd.devno"), 0, &pl050_kbd);
  87.  
  88.     return 0;
  89. }
  90.  
  91. /** Process keyboard & mouse events */
  92. int kbd_arch_process(keybuffer_t *keybuffer, ipc_call_t *call)
  93. {
  94.     static int key_released_flag = 0;
  95.     static int caps_locked = 0;
  96.     int scan_code = IPC_GET_ARG1(*call);
  97.  
  98.     if (scan_code == PL050_KEY_RELEASE) {
  99.         key_released_flag = 1;
  100.     } else {
  101.         if (key_released_flag) {
  102.             key_released_flag = 0;
  103.             if (scan_code == PL050_CAPS_SCAN_CODE) {
  104.                 if (caps_locked) {
  105.                     caps_locked = 0;
  106.                     return 1;
  107.                 } else
  108.                     caps_locked = 1;
  109.             }
  110.             key_released(keybuffer, scan_code);
  111.         } else {
  112.             if (scan_code == PL050_CAPS_SCAN_CODE && caps_locked)
  113.                 return 1;
  114.             key_pressed(keybuffer, scan_code);
  115.         }
  116.     }
  117.  
  118.     return  1;
  119. }
  120.  
  121. /**
  122.  * @}
  123.  */
  124.