From owner-svn-src-all@freebsd.org Sat Apr 1 20:38:13 2017 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id AA6E6D2710A; Sat, 1 Apr 2017 20:38:13 +0000 (UTC) (envelope-from gonzo@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 85B7A6E4; Sat, 1 Apr 2017 20:38:13 +0000 (UTC) (envelope-from gonzo@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v31KcCVe064004; Sat, 1 Apr 2017 20:38:12 GMT (envelope-from gonzo@FreeBSD.org) Received: (from gonzo@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v31KcCR3064003; Sat, 1 Apr 2017 20:38:12 GMT (envelope-from gonzo@FreeBSD.org) Message-Id: <201704012038.v31KcCR3064003@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: gonzo set sender to gonzo@FreeBSD.org using -f From: Oleksandr Tymoshenko Date: Sat, 1 Apr 2017 20:38:12 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r316371 - head/sys/arm/versatile X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 01 Apr 2017 20:38:13 -0000 Author: gonzo Date: Sat Apr 1 20:38:12 2017 New Revision: 316371 URL: https://svnweb.freebsd.org/changeset/base/316371 Log: [versatilepb] Fix keyboard driver after switching to upstream DTS FreeBSD's DTS contained only one PL050 node and driver considered it to be PS/2 keyboard. In reality PL050 is a PS/2 port that pushes bytes to/from the periphers connected to it. New DTS contains two nodes and QEMU emulates keyboard connected to port #0 and mouse connected to port #1. Since there is no way to say what's connected to port by checking DTS we hardcode this knowledge in the driver: it assumes keyboard on port #0 and ignores port #1 altogether. Also QEMU defaults emulated keyboard to scan code set 2 while driver used to work with scan code set 1 so when initializing driver make sure keyboard is switched to scan code set 1 Modified: head/sys/arm/versatile/pl050.c Modified: head/sys/arm/versatile/pl050.c ============================================================================== --- head/sys/arm/versatile/pl050.c Sat Apr 1 20:10:08 2017 (r316370) +++ head/sys/arm/versatile/pl050.c Sat Apr 1 20:38:12 2017 (r316371) @@ -106,7 +106,10 @@ __FBSDID("$FreeBSD$"); #define KMI_DRIVER_NAME "kmi" #define KMI_NFKEY (sizeof(fkey_tab)/sizeof(fkey_tab[0])) /* units */ +#define SET_SCANCODE_SET 0xf0 + struct kmi_softc { + device_t sc_dev; keyboard_t sc_kbd; keymap_t sc_keymap; accentmap_t sc_accmap; @@ -142,6 +145,8 @@ static int kmi_ioctl(keyboard_t *, u_lon static int kmi_enable(keyboard_t *); static int kmi_disable(keyboard_t *); +static int kmi_attached = 0; + /* early keyboard probe, not supported */ static int kmi_configure(int flags) @@ -480,7 +485,6 @@ kmi_ioctl(keyboard_t *kbd, u_long cmd, c } } - /* clear the internal state of the keyboard */ static void kmi_clear_state(keyboard_t *kbd) @@ -610,6 +614,17 @@ pl050_kmi_probe(device_t dev) if (!ofw_bus_status_okay(dev)) return (ENXIO); + /* + * PL050 is plain PS2 port that pushes bytes to/from computer + * VersatilePB has two such ports and QEMU simulates keyboard + * connected to port #0 and mouse connected to port #1. This + * information can't be obtained from device tree so we just + * hardcode this knowledge here. We attach keyboard driver to + * port #0 and ignore port #1 + */ + if (kmi_attached) + return (ENXIO); + if (ofw_bus_is_compatible(dev, "arm,pl050")) { device_set_desc(dev, "PL050 Keyboard/Mouse Interface"); return (BUS_PROBE_DEFAULT); @@ -625,7 +640,9 @@ pl050_kmi_attach(device_t dev) keyboard_t *kbd; int rid; int i; + uint32_t ack; + sc->sc_dev = dev; kbd = &sc->sc_kbd; rid = 0; @@ -654,6 +671,16 @@ pl050_kmi_attach(device_t dev) /* TODO: clock & divisor */ + pl050_kmi_write_4(sc, KMICR, KMICR_EN); + + pl050_kmi_write_4(sc, KMIDATA, SET_SCANCODE_SET); + /* read out ACK */ + ack = pl050_kmi_read_4(sc, KMIDATA); + /* Set Scan Code set 1 (XT) */ + pl050_kmi_write_4(sc, KMIDATA, 1); + /* read out ACK */ + ack = pl050_kmi_read_4(sc, KMIDATA); + pl050_kmi_write_4(sc, KMICR, KMICR_EN | KMICR_RXINTREN); kbd_init_struct(kbd, KMI_DRIVER_NAME, KB_OTHER, @@ -689,6 +716,7 @@ pl050_kmi_attach(device_t dev) if (bootverbose) { genkbd_diag(kbd, bootverbose); } + kmi_attached = 1; return (0); detach: