Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/khorben-n900]: src/sys Added keyboard support for the TPS65950 companion...



details:   https://anonhg.NetBSD.org/src/rev/617eccacca36
branches:  khorben-n900
changeset: 786707:617eccacca36
user:      khorben <khorben%NetBSD.org@localhost>
date:      Sun May 12 01:49:44 2013 +0000

description:
Added keyboard support for the TPS65950 companion chip.

Tested on the Nokia N900 (multi-user)

diffstat:

 sys/arch/evbarm/conf/N900 |    5 +-
 sys/conf/files            |   23 +-
 sys/dev/i2c/files.i2c     |    4 +-
 sys/dev/i2c/tps65950.c    |  343 +++++++++++++++++++++++++++++++++++++++++++++-
 sys/dev/i2c/tps65950reg.h |   34 ++++-
 5 files changed, 389 insertions(+), 20 deletions(-)

diffs (truncated from 546 to 300 lines):

diff -r cbc7447a6579 -r 617eccacca36 sys/arch/evbarm/conf/N900
--- a/sys/arch/evbarm/conf/N900 Sun May 12 01:19:54 2013 +0000
+++ b/sys/arch/evbarm/conf/N900 Sun May 12 01:49:44 2013 +0000
@@ -1,5 +1,5 @@
 #
-#      $NetBSD: N900,v 1.13.2.4 2013/05/12 00:42:50 khorben Exp $
+#      $NetBSD: N900,v 1.13.2.5 2013/05/12 01:49:44 khorben Exp $
 #
 #      N900 -- Nokia N900 Kernel
 #
@@ -255,6 +255,9 @@
 
 gpio*          at tps65950pm1
 
+# Integrated keyboard
+wskbd*         at tps65950pm2 mux 1
+
 # SPI devices
 omapspi0       at obio0 addr 0x48098000 size 0x1000 intr 65
 omapspi1       at obio0 addr 0x4809a000 size 0x1000 intr 66
diff -r cbc7447a6579 -r 617eccacca36 sys/conf/files
--- a/sys/conf/files    Sun May 12 01:19:54 2013 +0000
+++ b/sys/conf/files    Sun May 12 01:49:44 2013 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files,v 1.1070 2013/04/28 03:11:32 christos Exp $
+#      $NetBSD: files,v 1.1070.2.1 2013/05/12 01:49:44 khorben Exp $
 #      @(#)files.newconf       7.5 (Berkeley) 5/10/93
 
 version        20100430
@@ -323,6 +323,17 @@
 #
 define audiobell
 
+# display attributes, display with emulator, keyboard, and mouse
+#
+define wsdisplaydev            {[kbdmux = 1]}
+define wsemuldisplaydev        {[console = -1], [kbdmux = 1]}
+define wskbddev                {[console = -1], [mux = 1]}
+define wsmousedev              {[mux = 0]}
+define vcons
+# attribute to pull in raster support
+#
+define wsrasteremulops
+
 # video devices, attaches to video hardware driver
 #
 device video
@@ -1100,16 +1111,6 @@
 
 
 # Definitions for wscons
-# device attributes: display, display with emulator, keyboard, and mouse
-#
-define wsdisplaydev            {[kbdmux = 1]}
-define wsemuldisplaydev        {[console = -1], [kbdmux = 1]}
-define wskbddev                {[console = -1], [mux = 1]}
-define wsmousedev              {[mux = 0]}
-define vcons
-# attribute to pull in raster support
-#
-define wsrasteremulops
 # common PC display functions
 #
 defflag        opt_pcdisplay.h         PCDISPLAY_SOFTCURSOR
diff -r cbc7447a6579 -r 617eccacca36 sys/dev/i2c/files.i2c
--- a/sys/dev/i2c/files.i2c     Sun May 12 01:19:54 2013 +0000
+++ b/sys/dev/i2c/files.i2c     Sun May 12 01:49:44 2013 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.i2c,v 1.49.2.2 2013/05/12 00:56:28 khorben Exp $
+#      $NetBSD: files.i2c,v 1.49.2.3 2013/05/12 01:49:44 khorben Exp $
 
 obsolete defflag       opt_i2cbus.h            I2C_SCAN
 define i2cbus { }
@@ -173,7 +173,7 @@
 file   dev/i2c/ibmhawk.c               ibmhawk
 
 # TI TPS65950 OMAP Power Management and System Companion Device
-device tps65950pm: gpiobus, sysmon_wdog
+device tps65950pm: gpiobus, sysmon_wdog, wskbddev
 attach tps65950pm at iic
 file   dev/i2c/tps65950.c              tps65950pm
 
diff -r cbc7447a6579 -r 617eccacca36 sys/dev/i2c/tps65950.c
--- a/sys/dev/i2c/tps65950.c    Sun May 12 01:19:54 2013 +0000
+++ b/sys/dev/i2c/tps65950.c    Sun May 12 01:49:44 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: tps65950.c,v 1.3.10.3 2013/05/12 00:42:50 khorben Exp $ */
+/* $NetBSD: tps65950.c,v 1.3.10.4 2013/05/12 01:49:44 khorben Exp $ */
 
 /*-
  * Copyright (c) 2012 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tps65950.c,v 1.3.10.3 2013/05/12 00:42:50 khorben Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tps65950.c,v 1.3.10.4 2013/05/12 01:49:44 khorben Exp $");
 
 #define _INTR_PRIVATE
 
@@ -55,6 +55,13 @@
 #include <dev/gpio/gpiovar.h>
 #endif /* NGPIO > 0 */
 
+#if defined(OMAP_3430)
+#include <dev/wscons/wsconsio.h>
+#include <dev/wscons/wskbdvar.h>
+#include <dev/wscons/wsksymdef.h>
+#include <dev/wscons/wsksymvar.h>
+#endif
+
 #include <dev/clock_subr.h>
 #include <dev/sysmon/sysmonvar.h>
 
@@ -89,17 +96,29 @@
                offsetof(struct tps65950_softc, sc_gpio_pic)))
 #endif /* NGPIO > 0 */
 
+#if defined(OMAP_3430)
+       /* KEYPAD */
+       device_t                sc_wskbddev;
+       uint8_t                 sc_keycodes[8];
+#endif
+
        /* WATCHDOG */
        struct sysmon_wdog sc_smw;
        struct todr_chip_handle sc_todr;
 };
 
-
 /* XXX global workqueue to re-enable interrupts once handled */
 static struct workqueue                *tps65950_pih_workqueue;
 static struct work             tps65950_pih_workqueue_work;
 static bool                    tps65950_pih_workqueue_available;
 
+#if defined(OMAP_3430)
+/* XXX global workqueue to handle keyboard events on the right address */
+static struct workqueue                *tps65950_kbd_workqueue;
+static struct work             tps65950_kbd_workqueue_work;
+static bool                    tps65950_kbd_workqueue_available;
+#endif
+
 static int     tps65950_match(device_t, cfdata_t, void *);
 static void    tps65950_attach(device_t, device_t, void *);
 
@@ -139,6 +158,92 @@
 };
 #endif /* NGPIO > 0 */
 
+#if defined(OMAP_3430)
+static void    tps65950_kbd_attach(struct tps65950_softc *);
+
+static void    tps65950_kbd_intr(struct tps65950_softc *);
+static void    tps65950_kbd_intr_work(struct work *, void *);
+
+static int     tps65950_kbd_enable(void *, int);
+static void    tps65950_kbd_set_leds(void *, int);
+static int     tps65950_kbd_ioctl(void *, u_long, void *, int, struct lwp *);
+
+#define KC(n)          KS_KEYCODE(n)
+static const keysym_t n900_keydesc_us[] = {
+       KC(0),                  KS_q,
+       KC(1),                  KS_o,
+       KC(2),                  KS_p,
+       KC(3),                  KS_comma,
+       KC(4),                  KS_BackSpace,
+       KC(6),                  KS_a,
+       KC(7),                  KS_s,
+       KC(8),                  KS_w,
+       KC(9),                  KS_d,
+       KC(10),                 KS_f,
+       KC(11),                 KS_g,
+       KC(12),                 KS_h,
+       KC(13),                 KS_j,
+       KC(14),                 KS_k,
+       KC(15),                 KS_l,
+       KC(16),                 KS_e,
+       KC(17),                 KS_period,
+       KC(18),                 KS_Up,
+       KC(19),                 KS_Return,
+       KC(21),                 KS_z,
+       KC(22),                 KS_x,
+       KC(23),                 KS_c,
+       KC(24),                 KS_r,
+       KC(25),                 KS_v,
+       KC(26),                 KS_b,
+       KC(27),                 KS_n,
+       KC(28),                 KS_m,
+       KC(29),                 KS_space,
+       KC(30),                 KS_space,
+       KC(31),                 KS_Left,
+       KC(32),                 KS_t,
+       KC(33),                 KS_Down,
+       KC(35),                 KS_Right,
+       KC(36),                 KS_Control_L,
+       KC(37),                 KS_Alt_R,
+       KC(38),                 KS_Shift_L,
+       KC(40),                 KS_y,
+       KC(48),                 KS_u,
+       KC(56),                 KS_i,
+       /* XXX report these differently according to the current profile? */
+       KC(57),                 KS_f7,
+       KC(58),                 KS_f8
+};
+
+#define KBD_MAP(name, base, map) \
+                       { name, base, sizeof(map)/sizeof(keysym_t), map }
+const struct wscons_keydesc tps65950_kbd_keydesctab[] =
+{
+       KBD_MAP(KB_US,                  0,      n900_keydesc_us),
+       {0, 0, 0, 0}
+};
+#undef KBD_MAP
+
+const struct wskbd_mapdata tps65950_kbd_keymapdata = {
+       tps65950_kbd_keydesctab,
+       KB_US
+};
+
+static struct wskbd_accessops tps65950_kbd_accessops = {
+       tps65950_kbd_enable,
+       tps65950_kbd_set_leds,
+       tps65950_kbd_ioctl
+};
+
+static void    tps65950_kbd_cngetc(void *, u_int *, int *);
+static void    tps65950_kbd_cnpollc(void *, int);
+
+static const struct wskbd_consops tps65950_kbd_consops = {
+       tps65950_kbd_cngetc,
+       tps65950_kbd_cnpollc,
+       NULL
+};
+#endif
+
 static void    tps65950_rtc_attach(struct tps65950_softc *);
 static int     tps65950_rtc_enable(struct tps65950_softc *, bool);
 static int     tps65950_rtc_gettime(todr_chip_handle_t, struct clock_ymdhms *);
@@ -210,6 +315,13 @@
        case TPS65950_ADDR_ID3:
                aprint_normal(": LED\n");
                tps65950_sysctl_attach(sc);
+
+#if defined(OMAP_3430)
+               aprint_normal(", KEYPAD\n");
+               tps65950_kbd_attach(sc);
+#else
+               aprint_normal("\n");
+#endif
                break;
        case TPS65950_ADDR_ID4:
                aprint_normal(": RTC, WATCHDOG\n");
@@ -370,6 +482,10 @@
        if (u8 & TPS65950_PIH_REG_ISR_P1_ISR0)
                tps65950_gpio_intr(sc);
 #endif /* NGPIO > 0 */
+#ifdef OMAP_3430
+       if (u8 & TPS65950_PIH_REG_ISR_P1_ISR1)
+               tps65950_kbd_intr(sc);
+#endif
 
        iic_release_bus(sc->sc_i2c, 0);
 
@@ -652,7 +768,6 @@
        tps65950_read_1(sc, TPS65950_GPIO_GPIO_ISR3A, &u8);
        pending |= ((u8 & 0x3) << 16);
        iic_release_bus(sc->sc_i2c, 0);
-       aprint_normal_dev(sc->sc_dev, "%s() 0x%08x\n", __func__, pending);
        return pending;
 }
 
@@ -699,6 +814,226 @@
 }
 #endif /* NGPIO > 0 */
 
+#if defined(OMAP_3430)
+static void
+tps65950_kbd_attach(struct tps65950_softc *sc)
+{
+       uint8_t u8;
+       struct wskbddev_attach_args a;
+       int error;
+
+       iic_acquire_bus(sc->sc_i2c, 0);
+
+       /* reset the keyboard */
+       tps65950_write_1(sc, TPS65950_KEYPAD_REG_CTRL_REG, 0);
+
+       /* configure the keyboard */
+       u8 = TPS65950_KEYPAD_REG_CTRL_REG_KBD_ON
+               | TPS65950_KEYPAD_REG_CTRL_REG_SOFTMODEN
+               | TPS65950_KEYPAD_REG_CTRL_REG_SOFT_NRST;
+       tps65950_write_1(sc, TPS65950_KEYPAD_REG_CTRL_REG, u8);
+       u8 = 0 /* TPS65950_KEYPAD_REG_SIH_CTRL_COR */
+               | TPS65950_KEYPAD_REG_SIH_CTRL_EXCLEN;
+       tps65950_write_1(sc, TPS65950_KEYPAD_REG_SIH_CTRL, u8);
+
+       iic_release_bus(sc->sc_i2c, 0);
+
+       wskbd_cnattach(&tps65950_kbd_consops, sc, &tps65950_kbd_keymapdata);



Home | Main Index | Thread Index | Old Index