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

Cache object: fd27771d6405b0137571c7b29578ae93


[ 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.