Skip to content

Commit 88f6a77

Browse files
committed
MFC r316370-r316371
r316370: [versatilepb] Convert VERSATILEPB kernel to INTRNG and switch to upstream DTB Scope of this change is somewhat larger than just converting to INTRNG. The reason for this is that INTRNG support required switching from custom to upstream DTS because custom DTS didn't have interrup routing information. This switch caused rewrite of PCI and CLCD drivers and adding SCM module. List of changes in this commit: - Enable INTRNG and switch to versatile-pb.dts - Add SCM driver that controls various peripheral devices like LCD or PCI controller. Previously registers required for power-up and configuring peripherals were part of their respective nodes. Upstream DTS has dedicated node for SCM - Convert PL190 driver to INTRNG - Convert Versatile SIC (secondary interrupt controller) to INTRNG - Refactor CLCD driver to use SCM API to power up and configuration - Refactor PCI driver to use SCM API to enable controller - Refactor PCI driver to use interrupt map provided in DTS for interrupt routing. As a result it fixes broken IRQ routing and it's no longer required to run QEMU with "-global versatile_pci.broken-irq-mapping=1" command-line arguments r316371: [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
1 parent d8cded4 commit 88f6a77

File tree

7 files changed

+296
-67
lines changed

7 files changed

+296
-67
lines changed

sys/arm/conf/VERSATILEPB

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ makeoptions SC_DFLT_FONT=cp437
6868
device md
6969
device random # Entropy device
7070

71+
options INTRNG
72+
7173
# Flattened Device Tree
7274
options FDT # Configure using FDT/DTB data
7375
options FDT_DTB_STATIC
74-
makeoptions FDT_DTS_FILE=versatilepb.dts
76+
makeoptions FDT_DTS_FILE=versatile-pb.dts

sys/arm/versatile/files.versatile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ arm/versatile/versatile_machdep.c standard
66
arm/versatile/versatile_clcd.c optional sc
77
arm/versatile/versatile_common.c standard
88
arm/versatile/versatile_pci.c optional pci
9+
arm/versatile/versatile_scm.c standard
910
arm/versatile/versatile_sic.c standard
1011
arm/versatile/versatile_timer.c standard
1112

sys/arm/versatile/pl050.c

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,10 @@ __FBSDID("$FreeBSD$");
109109
#define KMI_DRIVER_NAME "kmi"
110110
#define KMI_NFKEY (sizeof(fkey_tab)/sizeof(fkey_tab[0])) /* units */
111111

112+
#define SET_SCANCODE_SET 0xf0
113+
112114
struct kmi_softc {
115+
device_t sc_dev;
113116
keyboard_t sc_kbd;
114117
keymap_t sc_keymap;
115118
accentmap_t sc_accmap;
@@ -145,6 +148,8 @@ static int kmi_ioctl(keyboard_t *, u_long, caddr_t);
145148
static int kmi_enable(keyboard_t *);
146149
static int kmi_disable(keyboard_t *);
147150

151+
static int kmi_attached = 0;
152+
148153
/* early keyboard probe, not supported */
149154
static int
150155
kmi_configure(int flags)
@@ -483,7 +488,6 @@ kmi_ioctl(keyboard_t *kbd, u_long cmd, caddr_t arg)
483488
}
484489
}
485490

486-
487491
/* clear the internal state of the keyboard */
488492
static void
489493
kmi_clear_state(keyboard_t *kbd)
@@ -613,6 +617,17 @@ pl050_kmi_probe(device_t dev)
613617
if (!ofw_bus_status_okay(dev))
614618
return (ENXIO);
615619

620+
/*
621+
* PL050 is plain PS2 port that pushes bytes to/from computer
622+
* VersatilePB has two such ports and QEMU simulates keyboard
623+
* connected to port #0 and mouse connected to port #1. This
624+
* information can't be obtained from device tree so we just
625+
* hardcode this knowledge here. We attach keyboard driver to
626+
* port #0 and ignore port #1
627+
*/
628+
if (kmi_attached)
629+
return (ENXIO);
630+
616631
if (ofw_bus_is_compatible(dev, "arm,pl050")) {
617632
device_set_desc(dev, "PL050 Keyboard/Mouse Interface");
618633
return (BUS_PROBE_DEFAULT);
@@ -628,7 +643,9 @@ pl050_kmi_attach(device_t dev)
628643
keyboard_t *kbd;
629644
int rid;
630645
int i;
646+
uint32_t ack;
631647

648+
sc->sc_dev = dev;
632649
kbd = &sc->sc_kbd;
633650
rid = 0;
634651

@@ -657,6 +674,16 @@ pl050_kmi_attach(device_t dev)
657674

658675
/* TODO: clock & divisor */
659676

677+
pl050_kmi_write_4(sc, KMICR, KMICR_EN);
678+
679+
pl050_kmi_write_4(sc, KMIDATA, SET_SCANCODE_SET);
680+
/* read out ACK */
681+
ack = pl050_kmi_read_4(sc, KMIDATA);
682+
/* Set Scan Code set 1 (XT) */
683+
pl050_kmi_write_4(sc, KMIDATA, 1);
684+
/* read out ACK */
685+
ack = pl050_kmi_read_4(sc, KMIDATA);
686+
660687
pl050_kmi_write_4(sc, KMICR, KMICR_EN | KMICR_RXINTREN);
661688

662689
kbd_init_struct(kbd, KMI_DRIVER_NAME, KB_OTHER,
@@ -692,6 +719,7 @@ pl050_kmi_attach(device_t dev)
692719
if (bootverbose) {
693720
genkbd_diag(kbd, bootverbose);
694721
}
722+
kmi_attached = 1;
695723
return (0);
696724

697725
detach:

sys/arm/versatile/versatile_clcd.c

Lines changed: 24 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*-
22
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
33
*
4-
* Copyright (c) 2012 Oleksandr Tymoshenko <[email protected]>
4+
* Copyright (c) 2012-2017 Oleksandr Tymoshenko <[email protected]>
55
* All rights reserved.
66
*
77
* Redistribution and use in source and binary forms, with or without
@@ -52,22 +52,12 @@ __FBSDID("$FreeBSD$");
5252
#include <dev/fb/fbreg.h>
5353
#include <dev/syscons/syscons.h>
5454

55+
#include <arm/versatile/versatile_scm.h>
56+
5557
#include <machine/bus.h>
5658

5759
#define PL110_VENDOR_ARM926PXP 1
5860

59-
#define MEM_SYS 0
60-
#define MEM_CLCD 1
61-
#define MEM_REGIONS 2
62-
63-
#define SYS_CLCD 0x00
64-
#define SYS_CLCD_CLCDID_SHIFT 0x08
65-
#define SYS_CLCD_CLCDID_MASK 0x1f
66-
#define SYS_CLCD_PWR3V5VSWITCH (1 << 4)
67-
#define SYS_CLCD_VDDPOSSWITCH (1 << 3)
68-
#define SYS_CLCD_NLCDIOON (1 << 2)
69-
#define SYS_CLCD_LCD_MODE_MASK 0x03
70-
7161
#define CLCD_MODE_RGB888 0x0
7262
#define CLCD_MODE_RGB555 0x01
7363
#define CLCD_MODE_RBG565 0x02
@@ -122,18 +112,13 @@ __FBSDID("$FreeBSD$");
122112
#define dprintf(fmt, args...)
123113
#endif
124114

125-
#define versatile_clcdc_sys_read_4(sc, reg) \
126-
bus_read_4((sc)->mem_res[MEM_SYS], (reg))
127-
#define versatile_clcdc_sys_write_4(sc, reg, val) \
128-
bus_write_4((sc)->mem_res[MEM_SYS], (reg), (val))
129-
130115
#define versatile_clcdc_read_4(sc, reg) \
131-
bus_read_4((sc)->mem_res[MEM_CLCD], (reg))
116+
bus_read_4((sc)->mem_res, (reg))
132117
#define versatile_clcdc_write_4(sc, reg, val) \
133-
bus_write_4((sc)->mem_res[MEM_CLCD], (reg), (val))
118+
bus_write_4((sc)->mem_res, (reg), (val))
134119

135120
struct versatile_clcdc_softc {
136-
struct resource* mem_res[MEM_REGIONS];
121+
struct resource* mem_res;
137122

138123
struct mtx mtx;
139124

@@ -208,12 +193,6 @@ static u_char mouse_pointer[16] = {
208193

209194
static struct video_adapter_softc va_softc;
210195

211-
static struct resource_spec versatile_clcdc_mem_spec[] = {
212-
{ SYS_RES_MEMORY, 0, RF_ACTIVE },
213-
{ SYS_RES_MEMORY, 1, RF_ACTIVE },
214-
{ -1, 0, 0 }
215-
};
216-
217196
static int versatilefb_configure(int);
218197
static void versatilefb_update_margins(video_adapter_t *adp);
219198

@@ -249,21 +228,25 @@ versatile_clcdc_attach(device_t dev)
249228
{
250229
struct versatile_clcdc_softc *sc = device_get_softc(dev);
251230
struct video_adapter_softc *va_sc = &va_softc;
252-
int err;
231+
int err, rid;
253232
uint32_t reg;
254233
int clcdid;
255234
int dma_size;
256235

257236
/* Request memory resources */
258-
err = bus_alloc_resources(dev, versatile_clcdc_mem_spec,
259-
sc->mem_res);
260-
if (err) {
261-
device_printf(dev, "Error: could not allocate memory resources\n");
237+
rid = 0;
238+
sc->mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE);
239+
if (sc->mem_res == NULL) {
240+
device_printf(dev, "could not allocate memory resources\n");
262241
return (ENXIO);
263242
}
264243

265-
reg = versatile_clcdc_sys_read_4(sc, SYS_CLCD);
266-
clcdid = (reg >> SYS_CLCD_CLCDID_SHIFT) & SYS_CLCD_CLCDID_MASK;
244+
err = versatile_scm_reg_read_4(SCM_CLCD, &reg);
245+
if (err) {
246+
device_printf(dev, "failed to read SCM register\n");
247+
goto fail;
248+
}
249+
clcdid = (reg >> SCM_CLCD_CLCDID_SHIFT) & SCM_CLCD_CLCDID_MASK;
267250
switch (clcdid) {
268251
case 31:
269252
device_printf(dev, "QEMU VGA 640x480\n");
@@ -275,17 +258,17 @@ versatile_clcdc_attach(device_t dev)
275258
goto fail;
276259
}
277260

278-
reg &= ~SYS_CLCD_LCD_MODE_MASK;
261+
reg &= ~SCM_CLCD_LCD_MODE_MASK;
279262
reg |= CLCD_MODE_RGB565;
280263
sc->mode = CLCD_MODE_RGB565;
281-
versatile_clcdc_sys_write_4(sc, SYS_CLCD, reg);
282-
dma_size = sc->width*sc->height*2;
283-
284-
/*
264+
versatile_scm_reg_write_4(SCM_CLCD, reg);
265+
dma_size = sc->width*sc->height*2;
266+
267+
/*
285268
* Power on LCD
286269
*/
287-
reg |= SYS_CLCD_PWR3V5VSWITCH | SYS_CLCD_NLCDIOON;
288-
versatile_clcdc_sys_write_4(sc, SYS_CLCD, reg);
270+
reg |= SCM_CLCD_PWR3V5VSWITCH | SCM_CLCD_NLCDIOON;
271+
versatile_scm_reg_write_4(SCM_CLCD, reg);
289272

290273
/*
291274
* XXX: hardcoded timing for VGA. For other modes/panels
@@ -658,7 +641,6 @@ versatilefb_init(int unit, video_adapter_t *adp, int flags)
658641
sc->xmargin = (sc->width - (vi->vi_width * vi->vi_cwidth)) / 2;
659642
sc->ymargin = (sc->height - (vi->vi_height * vi->vi_cheight))/2;
660643

661-
662644
adp->va_window = (vm_offset_t) versatilefb_static_window;
663645
adp->va_flags |= V_ADP_FONT /* | V_ADP_COLOR | V_ADP_MODECHANGE */;
664646

0 commit comments

Comments
 (0)