5

I have been working on making my own keyboard driver for linux. So I came accross these two links: usbkbd.c and atkbd.c.

Now I am confused which of these is the actual code driving my keyboard at the present. As I see it atkbd.c is quite gory and there is a conversion of scancodes to keycodes. So it should be the code, though I am not sure.

If atkbd.c is the code, then what is the other code for?

paramvir
  • 276
  • 4
  • 22

1 Answers1

2

This is easy to check. Let's take usbkbd.c.

The corresponding Kconfig (http://lxr.free-electrons.com/source/drivers/hid/usbhid/Kconfig#L50) says:

Say Y here only if you are absolutely sure that you don't want to use the generic HID driver for your USB keyboard and prefer to use the keyboard in its limited Boot Protocol mode instead.

This is almost certainly not what you want. This is mostly useful for embedded applications or simple keyboards.

So it looks unlikely to be the keyboard driver we are looking for. Also check current kernel config for USB_KBD. The config can be found under /boot directory or by running zcat /proc/config.gz. If USB_KBD is not there, you're not using it. If usbkbd.c is built as module, then will be worth checking if it is actually loaded. Makefile (http://lxr.free-electrons.com/source/drivers/hid/usbhid/Makefile#L10) gives the target as usbkbd. We can check if it is loaded by grepping for it in output of lsmod.

In contrast, Kconfig (http://lxr.free-electrons.com/source/drivers/input/keyboard/Kconfig#L69) for atkbd.c seem much more likely:

Say Y here if you want to use a standard AT or PS/2 keyboard. Usually you'll need this, unless you have a different type keyboard (USB, ADB or other). This also works for AT and PS/2 keyboards connected over a PS/2 to serial converter. If unsure, say Y.

Also check kernel config for KEYBOARD_ATKBD. If it is Y, you know it is being used. If it's M, check output of lsmod for atkbd.

bytefire
  • 4,156
  • 2
  • 27
  • 36
  • thanks for the answer... So I noted that usb_kbd is 'M' while atkbd is 'Y'. So it's clear that my current driver is atkbd. But you didn't answer my 2nd question. Please elaborate on that part too. – paramvir Oct 07 '16 at 10:51
  • As it says, it's used for boot protocol. It connects keyboard with minimum initialisation, ie without usb HID – bytefire Oct 07 '16 at 11:03
  • so I did digging myself, and turns out that usbkbd module is loaded when I insert the external keyboard using usb cable. I disabled the usbhid module and no longer the external keyboard was working. But still the laptop keyboard was working. So usbkbd drives the external keyboards and atkbd drives the laptop keyboard. Please rephrase as you like this comment and add it to your answer. Then I will accept your answer. – paramvir Oct 07 '16 at 15:00
  • Good work. usbkdb is gets loaded because it is a _dependency_. The Kconfig quite clear when it reads, "Say Y here only if you are absolutely sure that you _don't_ want to use the generic HID driver for your USB keyboard". The external keyboard uses USB HID to communicate with OS which is why unloading usbhid prevents keyboard from working. It will be worth finding out what's the dependency on usbkbd - `/lib/modules/{kernel-version}/modules.dep` will shed more light on this. – bytefire Oct 07 '16 at 15:19