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/dev/dec/lk201_ws.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /* $NetBSD: lk201_ws.c,v 1.10 2016/07/11 10:55:35 skrll Exp $ */
    2 
    3 /*
    4  * Copyright (c) 1998
    5  *      Matthias Drochner.  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  * 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 ``AS IS'' AND ANY EXPRESS OR
   17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
   19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
   20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
   22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
   23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
   24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
   25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   26  *
   27  */
   28 
   29 #include <sys/cdefs.h>
   30 __KERNEL_RCSID(0, "$NetBSD: lk201_ws.c,v 1.10 2016/07/11 10:55:35 skrll Exp $");
   31 
   32 #include <sys/param.h>
   33 #include <sys/systm.h>
   34 #include <sys/callout.h>
   35 
   36 #include <dev/wscons/wsconsio.h>
   37 
   38 #include <dev/dec/lk201reg.h>
   39 #include <dev/dec/lk201var.h>
   40 #include <dev/dec/wskbdmap_lk201.h> /* for {MIN,MAX}_LK201_KEY */
   41 
   42 #define send(lks, c) ((*((lks)->attmt.sendchar))((lks)->attmt.cookie, c))
   43 
   44 void lk201_identify(void *);
   45 
   46 static const char *lkkbd_descr[] = {
   47         "no keyboard",
   48         "LK-201 keyboard",
   49         "LK-401 keyboard",
   50 };
   51 
   52 int
   53 lk201_init(struct lk201_state *lks)
   54 {
   55         int i;
   56 
   57         lks->waitack = 0;
   58 
   59         send(lks, LK_LED_ENABLE);
   60         send(lks, LK_LED_ALL);
   61 
   62         /*
   63          * set all keys to updown mode; autorepeat is
   64          * done by wskbd software
   65          */
   66         for (i = 1; i <= 14; i++)
   67                 send(lks, LK_CMD_MODE(LK_UPDOWN, i));
   68 
   69         send(lks, LK_CL_ENABLE);
   70         send(lks, LK_PARAM_VOLUME(3));
   71         lks->kcvol = (8 - 3) * 100 / 8;
   72 
   73         lks->bellvol = -1; /* not yet set */
   74 
   75         for (i = 0; i < LK_KLL; i++)
   76                 lks->down_keys_list[i] = -1;
   77         send(lks, LK_KBD_ENABLE);
   78 
   79         send(lks, LK_LED_DISABLE);
   80         send(lks, LK_LED_ALL);
   81         lks->leds_state = 0;
   82 
   83         /*
   84          * Swallow all the keyboard acknowledges from lk201_init().
   85          * There should be 14 of them - one per LK_CMD_MODE command.
   86          */
   87         for(;;) {
   88                 lks->waitack = 1;
   89                 for (i = 100; i != 0; i--) {
   90                         DELAY(1000);
   91                         if (lks->waitack == 0)
   92                                 break;
   93                 }
   94                 if (i == 0)
   95                         break;
   96         }
   97 
   98         /*
   99          * Try to set the keyboard in LK-401 mode.
  100          * If we receive an error, this is an LK-201 keyboard.
  101          */
  102         lks->waitack = 1;
  103         send(lks, LK_ENABLE_401);
  104         for (i = 100; i != 0; i--) {
  105                 DELAY(1000);
  106                 if (lks->waitack == 0)
  107                         break;
  108         }
  109         if (lks->waitack != 0)
  110                 lks->kbdtype = KBD_NONE;
  111         else {
  112                 if (lks->ackdata == LK_INPUT_ERROR)
  113                         lks->kbdtype = KBD_LK201;
  114                 else
  115                         lks->kbdtype = KBD_LK401;
  116         }
  117         lks->waitack = 0;
  118 
  119         printf("lkkbd0: %s\n", lkkbd_descr[lks->kbdtype]);
  120 
  121         return 0;
  122 }
  123 
  124 int
  125 lk201_decode(struct lk201_state *lks, int wantmulti, int datain, u_int *type, int *dataout)
  126 {
  127         int i, freeslot;
  128 
  129         if (lks->waitack != 0) {
  130                 lks->ackdata = datain;
  131                 lks->waitack = 0;
  132                 return LKD_NODATA;
  133         }
  134 
  135         switch (datain) {
  136 #if 0
  137             case LK_KEY_UP:
  138                 for (i = 0; i < LK_KLL; i++)
  139                         lks->down_keys_list[i] = -1;
  140                 *type = WSCONS_EVENT_ALL_KEYS_UP;
  141                 return (1);
  142 #endif
  143             case LK_POWER_UP:
  144                 printf("lk201_decode: powerup detected\n");
  145                 lk201_init(lks);
  146                 return (0);
  147             case LK_KDOWN_ERROR:
  148             case LK_POWER_ERROR:
  149             case LK_OUTPUT_ERROR:
  150             case LK_INPUT_ERROR:
  151                 printf("lk201_decode: error %x\n", datain);
  152                 /* FALLTHRU */
  153             case LK_KEY_REPEAT: /* autorepeat handled by wskbd */
  154             case LK_MODE_CHANGE: /* ignore silently */
  155                 return (0);
  156         }
  157 
  158 
  159         if (datain == LK_KEY_UP) {
  160                 if (wantmulti) {
  161                         for (i = 0; i < LK_KLL; i++)
  162                                 if (lks->down_keys_list[i] != -1) {
  163                                         *type = WSCONS_EVENT_KEY_UP;
  164                                         *dataout = lks->down_keys_list[i] -
  165                                             MIN_LK201_KEY;
  166                                         lks->down_keys_list[i] = -1;
  167                                         return (LKD_MORE);
  168                                 }
  169                         return (LKD_NODATA);
  170                 } else {
  171                         for (i = 0; i < LK_KLL; i++)
  172                                 lks->down_keys_list[i] = -1;
  173                         *type = WSCONS_EVENT_ALL_KEYS_UP;
  174                         return (LKD_COMPLETE);
  175                 }
  176         } else if (datain < MIN_LK201_KEY || datain > MAX_LK201_KEY) {
  177                 printf("lk201_decode: %x\n", datain);
  178                 return (0);
  179         }
  180 
  181         *dataout = datain - MIN_LK201_KEY;
  182 
  183         freeslot = -1;
  184         for (i = 0; i < LK_KLL; i++) {
  185                 if (lks->down_keys_list[i] == datain) {
  186                         *type = WSCONS_EVENT_KEY_UP;
  187                         lks->down_keys_list[i] = -1;
  188                         return (1);
  189                 }
  190                 if (lks->down_keys_list[i] == -1 && freeslot == -1)
  191                         freeslot = i;
  192         }
  193 
  194         if (freeslot == -1) {
  195                 printf("lk201_decode: down(%d) no free slot\n", datain);
  196                 return (0);
  197         }
  198 
  199         *type = WSCONS_EVENT_KEY_DOWN;
  200         lks->down_keys_list[freeslot] = datain;
  201         return (1);
  202 }
  203 
  204 void
  205 lk201_bell(struct lk201_state *lks, struct wskbd_bell_data *bell)
  206 {
  207         unsigned int vol;
  208 
  209         if (bell->which & WSKBD_BELL_DOVOLUME) {
  210                 vol = 8 - bell->volume * 8 / 100;
  211                 if (vol > 7)
  212                         vol = 7;
  213         } else
  214                 vol = 3;
  215 
  216         if (vol != lks->bellvol) {
  217                 send(lks, LK_BELL_ENABLE);
  218                 send(lks, LK_PARAM_VOLUME(vol));
  219                 lks->bellvol = vol;
  220         }
  221         send(lks, LK_RING_BELL);
  222 }
  223 
  224 void
  225 lk201_set_leds(struct lk201_state *lks, int leds)
  226 {
  227         int newleds;
  228 
  229         newleds = 0;
  230         if (leds & WSKBD_LED_SCROLL)
  231                 newleds |= LK_LED_WAIT;
  232         if (leds & WSKBD_LED_CAPS)
  233                 newleds |= LK_LED_LOCK;
  234 
  235         send(lks, LK_LED_DISABLE);
  236         send(lks, (0x80 | (~newleds & 0x0f)));
  237 
  238         send(lks, LK_LED_ENABLE);
  239         send(lks, (0x80 | (newleds & 0x0f)));
  240 
  241         lks->leds_state = leds;
  242 }
  243 
  244 void
  245 lk201_set_keyclick(struct lk201_state *lks, int vol)
  246 {
  247         unsigned int newvol;
  248 
  249         if (vol == 0)
  250                 send(lks, LK_CL_DISABLE);
  251         else {
  252                 newvol = 8 - vol * 8 / 100;
  253                 if (newvol > 7)
  254                         newvol = 7;
  255 
  256                 send(lks, LK_CL_ENABLE);
  257                 send(lks, LK_PARAM_VOLUME(newvol));
  258         }
  259 
  260         lks->kcvol = vol;
  261 }

Cache object: 8340d40fd0fec1501d05e05a3b4aa2af


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