The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/arm/versatile/pl050.c

Version: -  FREEBSD  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-2  -  FREEBSD-11-1  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-4  -  FREEBSD-10-3  -  FREEBSD-10-2  -  FREEBSD-10-1  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-3  -  FREEBSD-9-2  -  FREEBSD-9-1  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-4  -  FREEBSD-8-3  -  FREEBSD-8-2  -  FREEBSD-8-1  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-4  -  FREEBSD-7-3  -  FREEBSD-7-2  -  FREEBSD-7-1  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-4  -  FREEBSD-6-3  -  FREEBSD-6-2  -  FREEBSD-6-1  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-5  -  FREEBSD-5-4  -  FREEBSD-5-3  -  FREEBSD-5-2  -  FREEBSD-5-1  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  linux-2.6  -  linux-2.4.22  -  MK83  -  MK84  -  PLAN9  -  DFBSD  -  NETBSD  -  NETBSD5  -  NETBSD4  -  NETBSD3  -  NETBSD20  -  OPENBSD  -  xnu-517  -  xnu-792  -  xnu-792.6.70  -  xnu-1228  -  xnu-1456.1.26  -  xnu-1699.24.8  -  xnu-2050.18.24  -  OPENSOLARIS  -  minix-3-1-1 
SearchContext: -  none  -  3  -  10 

    1 /*
    2  * Copyright (c) 2012 Oleksandr Tymoshenko <gonzo@freebsd.org>
    3  * All rights reserved.
    4  *
    5  * Based on dev/usb/input/ukbd.c  
    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  * 1. Redistributions of source code must retain the above copyright
   11  *    notice, this list of conditions and the following disclaimer.
   12  * 2. Redistributions in binary form must reproduce the above copyright
   13  *    notice, this list of conditions and the following disclaimer in the
   14  *    documentation and/or other materials provided with the distribution.
   15  *
   16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
   17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
   20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   26  * SUCH DAMAGE.
   27  */
   28 
   29 #include <sys/cdefs.h>
   30 __FBSDID("$FreeBSD: releng/10.1/sys/arm/versatile/pl050.c 266152 2014-05-15 16:11:06Z ian $");
   31 
   32 #include <sys/param.h>
   33 #include <sys/systm.h>
   34 #include <sys/bus.h>
   35 #include <sys/kernel.h>
   36 #include <sys/module.h>
   37 #include <sys/malloc.h>
   38 #include <sys/rman.h>
   39 #include <sys/proc.h>
   40 #include <sys/sched.h>
   41 #include <sys/kdb.h>
   42 
   43 #include <machine/bus.h>
   44 #include <machine/cpu.h>
   45 #include <machine/intr.h>
   46 
   47 #include <dev/fdt/fdt_common.h>
   48 #include <dev/ofw/openfirm.h>
   49 #include <dev/ofw/ofw_bus.h>
   50 #include <dev/ofw/ofw_bus_subr.h>
   51 
   52 #include <sys/ioccom.h>
   53 #include <sys/filio.h>
   54 #include <sys/tty.h>
   55 #include <sys/kbio.h>
   56 
   57 #include <dev/kbd/kbdreg.h>
   58 
   59 #include <machine/bus.h>
   60 #include <machine/fdt.h>
   61 
   62 #include <dev/kbd/kbdtables.h>
   63 
   64 #define KMI_LOCK()      mtx_lock(&Giant)
   65 #define KMI_UNLOCK()    mtx_unlock(&Giant)
   66 
   67 #ifdef  INVARIANTS
   68 /*
   69  * Assert that the lock is held in all contexts
   70  * where the code can be executed.
   71  */
   72 #define KMI_LOCK_ASSERT()       mtx_assert(&Giant, MA_OWNED)
   73 /*
   74  * Assert that the lock is held in the contexts
   75  * where it really has to be so.
   76  */
   77 #define KMI_CTX_LOCK_ASSERT()                           \
   78         do {                                            \
   79                 if (!kdb_active && panicstr == NULL)    \
   80                         mtx_assert(&Giant, MA_OWNED);   \
   81         } while (0)
   82 #else
   83 #define KMI_LOCK_ASSERT()       (void)0
   84 #define KMI_CTX_LOCK_ASSERT()   (void)0
   85 #endif
   86 
   87 #define KMICR           0x00
   88 #define         KMICR_TYPE_NONPS2       (1 << 5)
   89 #define         KMICR_RXINTREN          (1 << 4)
   90 #define         KMICR_TXINTREN          (1 << 3)
   91 #define         KMICR_EN                (1 << 2)
   92 #define         KMICR_FKMID             (1 << 1)
   93 #define         KMICR_FKMIC             (1 << 0)
   94 #define KMISTAT         0x04
   95 #define         KMISTAT_TXEMPTY         (1 << 6)
   96 #define         KMISTAT_TXBUSY          (1 << 5)
   97 #define         KMISTAT_RXFULL          (1 << 4)
   98 #define         KMISTAT_RXBUSY          (1 << 3)
   99 #define         KMISTAT_RXPARITY        (1 << 2)
  100 #define         KMISTAT_KMIC            (1 << 1)
  101 #define         KMISTAT_KMID            (1 << 0)
  102 #define KMIDATA         0x08
  103 #define KMICLKDIV       0x0C
  104 #define KMIIR           0x10
  105 #define         KMIIR_TXINTR            (1 << 1)
  106 #define         KMIIR_RXINTR            (1 << 0)
  107 
  108 #define KMI_DRIVER_NAME          "kmi"
  109 #define KMI_NFKEY        (sizeof(fkey_tab)/sizeof(fkey_tab[0])) /* units */
  110 
  111 struct kmi_softc {
  112         keyboard_t sc_kbd;
  113         keymap_t sc_keymap;
  114         accentmap_t sc_accmap;
  115         fkeytab_t sc_fkeymap[KMI_NFKEY];
  116 
  117         struct resource*        sc_mem_res;
  118         struct resource*        sc_irq_res;
  119         void*                   sc_intr_hl;
  120 
  121         int                     sc_mode;                /* input mode (K_XLATE,K_RAW,K_CODE) */
  122         int                     sc_state;               /* shift/lock key state */
  123         int                     sc_accents;             /* accent key index (> 0) */
  124         uint32_t                sc_flags;               /* flags */
  125 #define KMI_FLAG_COMPOSE        0x00000001
  126 #define KMI_FLAG_POLLING        0x00000002
  127 
  128         struct                  thread *sc_poll_thread;
  129 };
  130 
  131 /* Read/Write macros for Timer used as timecounter */
  132 #define pl050_kmi_read_4(sc, reg)               \
  133         bus_read_4((sc)->sc_mem_res, (reg))
  134 
  135 #define pl050_kmi_write_4(sc, reg, val) \
  136         bus_write_4((sc)->sc_mem_res, (reg), (val))
  137 
  138 /* prototypes */
  139 static void     kmi_set_leds(struct kmi_softc *, uint8_t);
  140 static int      kmi_set_typematic(keyboard_t *, int);
  141 static uint32_t kmi_read_char(keyboard_t *, int);
  142 static void     kmi_clear_state(keyboard_t *);
  143 static int      kmi_ioctl(keyboard_t *, u_long, caddr_t);
  144 static int      kmi_enable(keyboard_t *);
  145 static int      kmi_disable(keyboard_t *);
  146 
  147 /* early keyboard probe, not supported */
  148 static int
  149 kmi_configure(int flags)
  150 {
  151         return (0);
  152 }
  153 
  154 /* detect a keyboard, not used */
  155 static int
  156 kmi_probe(int unit, void *arg, int flags)
  157 {
  158         return (ENXIO);
  159 }
  160 
  161 /* reset and initialize the device, not used */
  162 static int
  163 kmi_init(int unit, keyboard_t **kbdp, void *arg, int flags)
  164 {
  165         return (ENXIO);
  166 }
  167 
  168 /* test the interface to the device, not used */
  169 static int
  170 kmi_test_if(keyboard_t *kbd)
  171 {
  172         return (0);
  173 }
  174 
  175 /* finish using this keyboard, not used */
  176 static int
  177 kmi_term(keyboard_t *kbd)
  178 {
  179         return (ENXIO);
  180 }
  181 
  182 /* keyboard interrupt routine, not used */
  183 static int
  184 kmi_intr(keyboard_t *kbd, void *arg)
  185 {
  186 
  187         return (0);
  188 }
  189 
  190 /* lock the access to the keyboard, not used */
  191 static int
  192 kmi_lock(keyboard_t *kbd, int lock)
  193 {
  194         return (1);
  195 }
  196 
  197 /*
  198  * Enable the access to the device; until this function is called,
  199  * the client cannot read from the keyboard.
  200  */
  201 static int
  202 kmi_enable(keyboard_t *kbd)
  203 {
  204 
  205         KMI_LOCK();
  206         KBD_ACTIVATE(kbd);
  207         KMI_UNLOCK();
  208 
  209         return (0);
  210 }
  211 
  212 /* disallow the access to the device */
  213 static int
  214 kmi_disable(keyboard_t *kbd)
  215 {
  216 
  217         KMI_LOCK();
  218         KBD_DEACTIVATE(kbd);
  219         KMI_UNLOCK();
  220 
  221         return (0);
  222 }
  223 
  224 /* check if data is waiting */
  225 static int
  226 kmi_check(keyboard_t *kbd)
  227 {
  228         struct kmi_softc *sc = kbd->kb_data;
  229         uint32_t reg;
  230 
  231         KMI_CTX_LOCK_ASSERT();
  232 
  233         if (!KBD_IS_ACTIVE(kbd))
  234                 return (0);
  235 
  236         reg = pl050_kmi_read_4(sc, KMIIR);
  237         return (reg & KMIIR_RXINTR);
  238 }
  239 
  240 /* check if char is waiting */
  241 static int
  242 kmi_check_char_locked(keyboard_t *kbd)
  243 {
  244         KMI_CTX_LOCK_ASSERT();
  245 
  246         if (!KBD_IS_ACTIVE(kbd))
  247                 return (0);
  248 
  249         return (kmi_check(kbd));
  250 }
  251 
  252 static int
  253 kmi_check_char(keyboard_t *kbd)
  254 {
  255         int result;
  256 
  257         KMI_LOCK();
  258         result = kmi_check_char_locked(kbd);
  259         KMI_UNLOCK();
  260 
  261         return (result);
  262 }
  263 
  264 /* read one byte from the keyboard if it's allowed */
  265 /* Currently unused. */
  266 static int
  267 kmi_read(keyboard_t *kbd, int wait)
  268 {
  269         KMI_CTX_LOCK_ASSERT();
  270 
  271         if (!KBD_IS_ACTIVE(kbd))
  272                 return (-1);
  273 
  274         ++(kbd->kb_count);
  275         printf("Implement ME: %s\n", __func__);
  276         return (0);
  277 }
  278 
  279 /* read char from the keyboard */
  280 static uint32_t
  281 kmi_read_char_locked(keyboard_t *kbd, int wait)
  282 {
  283         struct kmi_softc *sc = kbd->kb_data;
  284         uint32_t reg, data;
  285 
  286         KMI_CTX_LOCK_ASSERT();
  287 
  288         if (!KBD_IS_ACTIVE(kbd))
  289                 return (NOKEY);
  290 
  291         reg = pl050_kmi_read_4(sc, KMIIR);
  292         if (reg & KMIIR_RXINTR) {
  293                 data = pl050_kmi_read_4(sc, KMIDATA);
  294                 return (data);
  295         }
  296 
  297         ++kbd->kb_count;
  298         return (NOKEY);
  299 }
  300 
  301 /* Currently wait is always false. */
  302 static uint32_t
  303 kmi_read_char(keyboard_t *kbd, int wait)
  304 {
  305         uint32_t keycode;
  306 
  307         KMI_LOCK();
  308         keycode = kmi_read_char_locked(kbd, wait);
  309         KMI_UNLOCK();
  310 
  311         return (keycode);
  312 }
  313 
  314 /* some useful control functions */
  315 static int
  316 kmi_ioctl_locked(keyboard_t *kbd, u_long cmd, caddr_t arg)
  317 {
  318         struct kmi_softc *sc = kbd->kb_data;
  319         int i;
  320 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
  321     defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
  322         int ival;
  323 
  324 #endif
  325 
  326         KMI_LOCK_ASSERT();
  327 
  328         switch (cmd) {
  329         case KDGKBMODE:         /* get keyboard mode */
  330                 *(int *)arg = sc->sc_mode;
  331                 break;
  332 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
  333     defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
  334         case _IO('K', 7):
  335                 ival = IOCPARM_IVAL(arg);
  336                 arg = (caddr_t)&ival;
  337                 /* FALLTHROUGH */
  338 #endif
  339         case KDSKBMODE:         /* set keyboard mode */
  340                 switch (*(int *)arg) {
  341                 case K_XLATE:
  342                         if (sc->sc_mode != K_XLATE) {
  343                                 /* make lock key state and LED state match */
  344                                 sc->sc_state &= ~LOCK_MASK;
  345                                 sc->sc_state |= KBD_LED_VAL(kbd);
  346                         }
  347                         /* FALLTHROUGH */
  348                 case K_RAW:
  349                 case K_CODE:
  350                         if (sc->sc_mode != *(int *)arg) {
  351                                 if ((sc->sc_flags & KMI_FLAG_POLLING) == 0)
  352                                         kmi_clear_state(kbd);
  353                                 sc->sc_mode = *(int *)arg;
  354                         }
  355                         break;
  356                 default:
  357                         return (EINVAL);
  358                 }
  359                 break;
  360 
  361         case KDGETLED:                  /* get keyboard LED */
  362                 *(int *)arg = KBD_LED_VAL(kbd);
  363                 break;
  364 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
  365     defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
  366         case _IO('K', 66):
  367                 ival = IOCPARM_IVAL(arg);
  368                 arg = (caddr_t)&ival;
  369                 /* FALLTHROUGH */
  370 #endif
  371         case KDSETLED:                  /* set keyboard LED */
  372                 /* NOTE: lock key state in "sc_state" won't be changed */
  373                 if (*(int *)arg & ~LOCK_MASK)
  374                         return (EINVAL);
  375 
  376                 i = *(int *)arg;
  377 
  378                 /* replace CAPS LED with ALTGR LED for ALTGR keyboards */
  379                 if (sc->sc_mode == K_XLATE &&
  380                     kbd->kb_keymap->n_keys > ALTGR_OFFSET) {
  381                         if (i & ALKED)
  382                                 i |= CLKED;
  383                         else
  384                                 i &= ~CLKED;
  385                 }
  386                 if (KBD_HAS_DEVICE(kbd))
  387                         kmi_set_leds(sc, i);
  388 
  389                 KBD_LED_VAL(kbd) = *(int *)arg;
  390                 break;
  391         case KDGKBSTATE:                /* get lock key state */
  392                 *(int *)arg = sc->sc_state & LOCK_MASK;
  393                 break;
  394 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
  395     defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
  396         case _IO('K', 20):
  397                 ival = IOCPARM_IVAL(arg);
  398                 arg = (caddr_t)&ival;
  399                 /* FALLTHROUGH */
  400 #endif
  401         case KDSKBSTATE:                /* set lock key state */
  402                 if (*(int *)arg & ~LOCK_MASK) {
  403                         return (EINVAL);
  404                 }
  405                 sc->sc_state &= ~LOCK_MASK;
  406                 sc->sc_state |= *(int *)arg;
  407 
  408                 /* set LEDs and quit */
  409                 return (kmi_ioctl(kbd, KDSETLED, arg));
  410 
  411         case KDSETREPEAT:               /* set keyboard repeat rate (new
  412                                          * interface) */
  413                 if (!KBD_HAS_DEVICE(kbd)) {
  414                         return (0);
  415                 }
  416                 if (((int *)arg)[1] < 0) {
  417                         return (EINVAL);
  418                 }
  419                 if (((int *)arg)[0] < 0) {
  420                         return (EINVAL);
  421                 }
  422                 if (((int *)arg)[0] < 200)      /* fastest possible value */
  423                         kbd->kb_delay1 = 200;
  424                 else
  425                         kbd->kb_delay1 = ((int *)arg)[0];
  426                 kbd->kb_delay2 = ((int *)arg)[1];
  427                 return (0);
  428 
  429 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
  430     defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
  431         case _IO('K', 67):
  432                 ival = IOCPARM_IVAL(arg);
  433                 arg = (caddr_t)&ival;
  434                 /* FALLTHROUGH */
  435 #endif
  436         case KDSETRAD:                  /* set keyboard repeat rate (old
  437                                          * interface) */
  438                 return (kmi_set_typematic(kbd, *(int *)arg));
  439 
  440         case PIO_KEYMAP:                /* set keyboard translation table */
  441         case OPIO_KEYMAP:               /* set keyboard translation table
  442                                          * (compat) */
  443         case PIO_KEYMAPENT:             /* set keyboard translation table
  444                                          * entry */
  445         case PIO_DEADKEYMAP:            /* set accent key translation table */
  446                 sc->sc_accents = 0;
  447                 /* FALLTHROUGH */
  448         default:
  449                 return (genkbd_commonioctl(kbd, cmd, arg));
  450         }
  451 
  452         return (0);
  453 }
  454 
  455 static int
  456 kmi_ioctl(keyboard_t *kbd, u_long cmd, caddr_t arg)
  457 {
  458         int result;
  459 
  460         /*
  461          * XXX KDGKBSTATE, KDSKBSTATE and KDSETLED can be called from any
  462          * context where printf(9) can be called, which among other things
  463          * includes interrupt filters and threads with any kinds of locks
  464          * already held.  For this reason it would be dangerous to acquire
  465          * the Giant here unconditionally.  On the other hand we have to
  466          * have it to handle the ioctl.
  467          * So we make our best effort to auto-detect whether we can grab
  468          * the Giant or not.  Blame syscons(4) for this.
  469          */
  470         switch (cmd) {
  471         case KDGKBSTATE:
  472         case KDSKBSTATE:
  473         case KDSETLED:
  474                 if (!mtx_owned(&Giant) && !SCHEDULER_STOPPED())
  475                         return (EDEADLK);       /* best I could come up with */
  476                 /* FALLTHROUGH */
  477         default:
  478                 KMI_LOCK();
  479                 result = kmi_ioctl_locked(kbd, cmd, arg);
  480                 KMI_UNLOCK();
  481                 return (result);
  482         }
  483 }
  484 
  485 
  486 /* clear the internal state of the keyboard */
  487 static void
  488 kmi_clear_state(keyboard_t *kbd)
  489 {
  490         struct kmi_softc *sc = kbd->kb_data;
  491 
  492         KMI_CTX_LOCK_ASSERT();
  493 
  494         sc->sc_flags &= ~(KMI_FLAG_COMPOSE | KMI_FLAG_POLLING);
  495         sc->sc_state &= LOCK_MASK;      /* preserve locking key state */
  496         sc->sc_accents = 0;
  497 }
  498 
  499 /* save the internal state, not used */
  500 static int
  501 kmi_get_state(keyboard_t *kbd, void *buf, size_t len)
  502 {
  503         return (len == 0) ? 1 : -1;
  504 }
  505 
  506 /* set the internal state, not used */
  507 static int
  508 kmi_set_state(keyboard_t *kbd, void *buf, size_t len)
  509 {
  510         return (EINVAL);
  511 }
  512 
  513 static int
  514 kmi_poll(keyboard_t *kbd, int on)
  515 {
  516         struct kmi_softc *sc = kbd->kb_data;
  517 
  518         KMI_LOCK();
  519         if (on) {
  520                 sc->sc_flags |= KMI_FLAG_POLLING;
  521                 sc->sc_poll_thread = curthread;
  522         } else {
  523                 sc->sc_flags &= ~KMI_FLAG_POLLING;
  524         }
  525         KMI_UNLOCK();
  526 
  527         return (0);
  528 }
  529 
  530 /* local functions */
  531 
  532 static void
  533 kmi_set_leds(struct kmi_softc *sc, uint8_t leds)
  534 {
  535 
  536         KMI_LOCK_ASSERT();
  537 
  538         /* start transfer, if not already started */
  539         printf("Implement me: %s\n", __func__);
  540 }
  541 
  542 static int
  543 kmi_set_typematic(keyboard_t *kbd, int code)
  544 {
  545         static const int delays[] = {250, 500, 750, 1000};
  546         static const int rates[] = {34, 38, 42, 46, 50, 55, 59, 63,
  547                 68, 76, 84, 92, 100, 110, 118, 126,
  548                 136, 152, 168, 184, 200, 220, 236, 252,
  549         272, 304, 336, 368, 400, 440, 472, 504};
  550 
  551         if (code & ~0x7f) {
  552                 return (EINVAL);
  553         }
  554         kbd->kb_delay1 = delays[(code >> 5) & 3];
  555         kbd->kb_delay2 = rates[code & 0x1f];
  556         return (0);
  557 }
  558 
  559 static keyboard_switch_t kmisw = {
  560         .probe = &kmi_probe,
  561         .init = &kmi_init,
  562         .term = &kmi_term,
  563         .intr = &kmi_intr,
  564         .test_if = &kmi_test_if,
  565         .enable = &kmi_enable,
  566         .disable = &kmi_disable,
  567         .read = &kmi_read,
  568         .check = &kmi_check,
  569         .read_char = &kmi_read_char,
  570         .check_char = &kmi_check_char,
  571         .ioctl = &kmi_ioctl,
  572         .lock = &kmi_lock,
  573         .clear_state = &kmi_clear_state,
  574         .get_state = &kmi_get_state,
  575         .set_state = &kmi_set_state,
  576         .get_fkeystr = &genkbd_get_fkeystr,
  577         .poll = &kmi_poll,
  578         .diag = &genkbd_diag,
  579 };
  580 
  581 KEYBOARD_DRIVER(kmi, kmisw, kmi_configure);
  582 
  583 static void
  584 pl050_kmi_intr(void *arg)
  585 {
  586         struct kmi_softc *sc = arg;
  587         uint32_t c;
  588 
  589         KMI_CTX_LOCK_ASSERT();
  590 
  591         if ((sc->sc_flags & KMI_FLAG_POLLING) != 0)
  592                 return;
  593 
  594         if (KBD_IS_ACTIVE(&sc->sc_kbd) &&
  595             KBD_IS_BUSY(&sc->sc_kbd)) {
  596                 /* let the callback function process the input */
  597                 (sc->sc_kbd.kb_callback.kc_func) (&sc->sc_kbd, KBDIO_KEYINPUT,
  598                     sc->sc_kbd.kb_callback.kc_arg);
  599         } else {
  600                 /* read and discard the input, no one is waiting for it */
  601                 do {
  602                         c = kmi_read_char_locked(&sc->sc_kbd, 0);
  603                 } while (c != NOKEY);
  604         }
  605 
  606 }
  607 
  608 static int
  609 pl050_kmi_probe(device_t dev)
  610 {
  611 
  612         if (!ofw_bus_status_okay(dev))
  613                 return (ENXIO);
  614 
  615         if (ofw_bus_is_compatible(dev, "arm,pl050")) {
  616                 device_set_desc(dev, "PL050 Keyboard/Mouse Interface");
  617                 return (BUS_PROBE_DEFAULT);
  618         }
  619 
  620         return (ENXIO);
  621 }
  622 
  623 static int
  624 pl050_kmi_attach(device_t dev)
  625 {
  626         struct kmi_softc *sc = device_get_softc(dev);
  627         keyboard_t *kbd;
  628         int rid;
  629         int i;
  630 
  631         kbd = &sc->sc_kbd;
  632         rid = 0;
  633 
  634         sc->sc_mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE);
  635         if (sc->sc_mem_res == NULL) {
  636                 device_printf(dev, "could not allocate memory resource\n");
  637                 return (ENXIO);
  638         }
  639 
  640         /* Request the IRQ resources */
  641         sc->sc_irq_res =  bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, RF_ACTIVE);
  642         if (sc->sc_irq_res == NULL) {
  643                 device_printf(dev, "Error: could not allocate irq resources\n");
  644                 return (ENXIO);
  645         }
  646 
  647         /* Setup and enable the timer */
  648         if (bus_setup_intr(dev, sc->sc_irq_res, INTR_TYPE_CLK,
  649                         NULL, pl050_kmi_intr, sc,
  650                         &sc->sc_intr_hl) != 0) {
  651                 bus_release_resource(dev, SYS_RES_IRQ, rid,
  652                         sc->sc_irq_res);
  653                 device_printf(dev, "Unable to setup the clock irq handler.\n");
  654                 return (ENXIO);
  655         }
  656 
  657         /* TODO: clock & divisor */
  658 
  659         pl050_kmi_write_4(sc, KMICR, KMICR_EN | KMICR_RXINTREN);
  660 
  661         kbd_init_struct(kbd, KMI_DRIVER_NAME, KB_OTHER, 
  662                         device_get_unit(dev), 0, 0, 0);
  663         kbd->kb_data = (void *)sc;
  664 
  665         sc->sc_keymap = key_map;
  666         sc->sc_accmap = accent_map;
  667         for (i = 0; i < KMI_NFKEY; i++) {
  668                 sc->sc_fkeymap[i] = fkey_tab[i];
  669         }
  670 
  671         kbd_set_maps(kbd, &sc->sc_keymap, &sc->sc_accmap,
  672             sc->sc_fkeymap, KMI_NFKEY);
  673 
  674         KBD_FOUND_DEVICE(kbd);
  675         kmi_clear_state(kbd);
  676         KBD_PROBE_DONE(kbd);
  677 
  678         KBD_INIT_DONE(kbd);
  679 
  680         if (kbd_register(kbd) < 0) {
  681                 goto detach;
  682         }
  683         KBD_CONFIG_DONE(kbd);
  684 
  685 #ifdef KBD_INSTALL_CDEV
  686         if (kbd_attach(kbd)) {
  687                 goto detach;
  688         }
  689 #endif
  690 
  691         if (bootverbose) {
  692                 genkbd_diag(kbd, bootverbose);
  693         }
  694         return (0);
  695 
  696 detach:
  697         return (ENXIO);
  698 
  699 }
  700 
  701 static device_method_t pl050_kmi_methods[] = {
  702         DEVMETHOD(device_probe,         pl050_kmi_probe),
  703         DEVMETHOD(device_attach,        pl050_kmi_attach),
  704         { 0, 0 }
  705 };
  706 
  707 static driver_t pl050_kmi_driver = {
  708         "kmi",
  709         pl050_kmi_methods,
  710         sizeof(struct kmi_softc),
  711 };
  712 
  713 static devclass_t pl050_kmi_devclass;
  714 
  715 DRIVER_MODULE(pl050_kmi, simplebus, pl050_kmi_driver, pl050_kmi_devclass, 0, 0);

Cache object: 5758e41dd09f5ec6b26462e52262e531


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.