Herramientas de usuario

Herramientas del sitio


wiki2:linux_drivers

Diferencias

Muestra las diferencias entre dos versiones de la página.

Enlace a la vista de comparación

Ambos lados, revisión anterior Revisión previa
Próxima revisión
Revisión previa
wiki2:linux_drivers [2019/09/22 07:53]
alfred [Helper functions]
wiki2:linux_drivers [2020/09/11 20:57] (actual)
Línea 100: Línea 100:
  
 ===== Useful functions and interfaces in Kernel ===== ===== Useful functions and interfaces in Kernel =====
 +==== Helper functions ====
  
 +  * ''​printk()''​ is the equivalent of printf() for kernel modules.
 +
 +''​pr_*()''​ functions are the same as plain printk(), but with the KERN_xxx log level already included.
 +
 +''​dev_*()''​ functions (like ''​dev_alert''​ or ''​dev_info''​) are the same as the corresponding pr_*() functions, but also print identifying information about the struct device.
 +<​code>​
 +dev_info(&​hdev->​dev,​ "VEIKK A15 has been attached\n"​);​
 +dev_alert(&​hdev->​dev,​ "It failed on allockating memory for the VEIKK A15\n"​);​
 +</​code>​
 ==== Allocating memory ==== ==== Allocating memory ====
  
Línea 107: Línea 117:
  
 The memory allocated with ''​kzalloc()''​ should be freed with ''​kfree()''​. The memory allocated with ''​devm_kzalloc()''​ is freed automatically. It can be freed with ''​devm_kfree()''​. The memory allocated with ''​kzalloc()''​ should be freed with ''​kfree()''​. The memory allocated with ''​devm_kzalloc()''​ is freed automatically. It can be freed with ''​devm_kfree()''​.
 +
 +''​hid_set_drvdata''​ \\
 +Will set on the data property from the hdev the passed value.
 +
 +''​hid_parse(hdev)''​ \\ 
 +Required to be called after setting up the device. It parses a report description of the device and populate fields of the HID device struct (necessary for hid_hw_start()).
 +
 +For device memory allocations there is also a "​group"​ concept. Groups can be thought of as markers in the stream of allocations associated with a given device. The allocations performed within a specific group can be rolled back without affecting any others. In brief, the group API is:
 +<​code>​
 +    void *devres_open_group(struct device *dev, void *id, gfp_t gfp);
 +    void devres_close_group(struct device *dev, void *id);
 +    void devres_remove_group(struct device *dev, void *id);
 +    int devres_release_group(struct device *dev, void *id);
 +</​code>​
 ===== USB ===== ===== USB =====
  
Línea 134: Línea 158:
  
 Tutorial for creating a driver for a virtual char device. It creates that device using ''​mknod'' ​ command and accesses it using the driver. \\  Tutorial for creating a driver for a virtual char device. It creates that device using ''​mknod'' ​ command and accesses it using the driver. \\ 
-https://​s3.wasabisys.com/​public-files/​tutorial-DD.pdf+https://​s3.wasabisys.com/​my-files/public/​tutorial-DD.pdf
  
  
 +----
 +
 +===== How to... Graphic tablet =====
 +To see all registered inputs:
 +<​code>​
 +xinput
 +</​code>​
 +To map a xinput with a display (''​xrandr''​ will give you the display id):
 +<​code>​
 + ​xinput map-to-output <​registered input id> <display id>
 + ​xinput map-to-output 22 HDMI-1-1
 +</​code>​
 +
 +
 +==== List USB devices ====
 +
 +To detect your USB device, in a terminal, you can try:
 +<​code>​
 +lsusb , example:
 +$ lsusb
 +Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
 +Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
 +Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
 +Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
 +Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
 +Bus 001 Device 002: ID 046d:0809 Logitech, Inc. Webcam Pro 9000
 +Bus 003 Device 002: ID 046d:c016 Logitech, Inc. Optical Wheel Mouse
 +</​code>​
 +or this powerful tool, lsinput , 1st install it, and then try it, it lists all input devices including your USB device :
 +<​code>​
 +$ sudo apt-get install input-utils
 +$ lsinput
 +/​dev/​input/​event0
 +...
 +
 +/​dev/​input/​event1
 +...
 +
 +/​dev/​input/​event2
 +...
 +
 +/​dev/​input/​event3
 +bustype : BUS_USB
 +vendor ​ : 0x46d
 +product : 0xc016
 +version : 272
 +name    : "​Logitech Optical USB Mouse"
 +phys    : "​usb-0000:​00:​1d.1-2/​input0"​
 +uniq    : ""​
 +bits ev : EV_SYN EV_KEY EV_REL EV_MSC
 +</​code>​
 +udevadm , with this command line, you need to unplug the device before using the command and then plug it to see it:
 +<​code>​
 +$ udevadm monitor --udev
 +monitor will print the received events for:
 +UDEV - the event which udev sends out after rule processing
 +UDEV  [1915.787445] add      /​devices/​pci0000:​00/​0000:​00:​1d.3/​usb5/​5-2 (usb)
 +UDEV  [1915.796226] add      /​devices/​pci0000:​00/​0000:​00:​1d.3/​usb5/​5-2/​5-2:​1.0 (usb)
 +</​code>​
wiki2/linux_drivers.1569138834.txt.gz · Última modificación: 2020/05/09 09:24 (editor externo)