[Rozw.] Nowy sterownik USB a hotplug

Problemy dotyczące programowania.

Moderatorzy: Moderatorzy, Administratorzy

kazek3018
Użytkownik
Posty: 181
Rejestracja: 2006-12-10, 14:27

[Rozw.] Nowy sterownik USB a hotplug

Post autor: kazek3018 »

Cześć.

Próbuję napisać własny sterownik USB, ale mam problem z podpięciem go pod hotplug-a. Na razie sterownik nie posiada żadnej funkcjonalności, a to jego kod:

Kod: Zaznacz cały

#include <linux/kernel.h>
#include <linux/errno.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/tty.h>
#include <linux/tty_driver.h>
#include <linux/tty_flip.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/spinlock.h>
#include <linux/uaccess.h>
#include <linux/usb.h>
#include "k8055.h"

#define DRIVER_AUTHOR "*****"
#define DRIVER_DESC "Velleman K8055 USB experiment interface board driver"

/* table of devices that work with this driver */
static struct usb_device_id k8055_devices_table []={
    { USB_DEVICE(K8055_VENDOR_ID, K8055_PRODUCT_ID0) },
    { USB_DEVICE(K8055_VENDOR_ID, K8055_PRODUCT_ID1) },
    { USB_DEVICE(K8055_VENDOR_ID, K8055_PRODUCT_ID2) },
    { USB_DEVICE(K8055_VENDOR_ID, K8055_PRODUCT_ID3) },
    { }                 /* Terminating entry */
};
MODULE_DEVICE_TABLE (usb, k8055_devices_table);


/* Structure to hold all of our device specific stuff */
struct k8055 {
    struct usb_device* udev;                    /* the usb device for this device */
    struct usb_interface*  interface;           /* the interface for this device */
    unsigned char*     interrupt_in_buffer;     /* the buffer to receive data */
    size_t          interrupt_in_size;          /* the size of the receive buffer */
    __u8            interrupt_in_endpointAddr;  /* the address of the interrupt in endpoint */
    __u8            interrupt_out_endpointAddr; /* the address of the interrupt out endpoint */
    struct kref     refcount;                   /* the reference counter*/
};

static int k8055_probe(struct usb_interface *interface, const struct usb_device_id *id);
static void k8055_disconnect(struct usb_interface *interface);

static struct usb_driver k8055_driver = {
    .name = "k8055",
    .id_table = k8055_devices_table,
    .probe = k8055_probe,
    .disconnect = k8055_disconnect,
};

static int k8055_probe(struct usb_interface *interface, const struct usb_device_id *id)
{
    printk("Function probe for k8055\n");
    return 0;
}

static void k8055_disconnect(struct usb_interface *interface)
{
    printk("Function disconnect for k8055\n");
}


static int __init usb_k8055_init(void)
{
    int result;

    /* register this driver with the USB subsystem */
    result = usb_register(&k8055_driver);
    if (result)
        err("usb_register failed. Error number %d", result);


    printk("usb_register(&k8055_driver) result -> %d\n", result);
    printk("Function usb_k8055_init for k8055\n");

    return result;
}

static void __exit usb_k8055_exit(void)
{
    /* deregister this driver with the USB subsystem */
    usb_deregister(&k8055_driver);


    printk("Function usb_k8055_exit for k8055\n");
}

module_init (usb_k8055_init);
module_exit (usb_k8055_exit);

MODULE_AUTHOR(DRIVER_AUTHOR);
MODULE_DESCRIPTION(DRIVER_DESC);
MODULE_LICENSE("GPL");
Sterownik kompiluje się bez problemu, insmod, modprobe, oraz rmmod działają z nim poprawnie. USB core rejestruje poprawnie sterownik i wpisuje informacje o tym do loga (dmesg). Sterownik dodałem do aktualnych źródeł kernela, zaznaczyłem go jako moduł.
Następnie:

Kod: Zaznacz cały

make modules
make modules_install
Nie prze kompilowałem jądra ale to chyba nie jest potrzebne. Problem w tym, że kiedy podpinam urządzenie pod port USB to hotplug nie ładuje mojego sterownika, co więcej; jeżeli sterownik jest już załadowany do jądra to nie są wywoływane funkcje k8055_probe i k8055_disconnect, a powinny być wywołane w momencie podpięcia urządzenia do portu.

Ma może ktoś doświadczenie ze sterownikami? Bo na razie nie ma pomysłu co dalej, czy może kompilacja jądra jest nie zbędna? Może ma ktoś jakiś pomysł?
Ostatnio zmieniony 2010-11-14, 09:17 przez kazek3018, łącznie zmieniany 1 raz.
Awatar użytkownika
mina86
Moderator
Posty: 3343
Rejestracja: 2004-06-14, 21:58
Lokalizacja: Linux 5.x x86_64
Kontakt:

Re: Nowy sterownik USB a hotplug

Post autor: mina86 »

Co pokazuje lsusb po wpięciu urządzenia? Czy po podłączeniu urządzenia coś w ogóle się dzieje? Czy k8055_devices_table jest poprawne? Skąd się wzięły te identyfikatory w tej tabeli? Jakie są ich wartości?

PS. „hotpluga” bez dywizu, „przekompilowałem” łącznie, „niezbędna” łącznie.

PPS. Przy printk() zawsze podawaj poziom, a w ogóle to używaj pr_*() i dev_*() (również zamiast err()). I używaj scripts/checkpatch.pl -- im wcześniej zaczniesz, wym lepiej dla Ciebie. :)
Zastrzegam sobie prawo nieanalizowania postów pisanych niepoprawną polszczyzną.
Post generated automatically by A.I. system code name ‘mina86’ in response to the previous one.
kazek3018
Użytkownik
Posty: 181
Rejestracja: 2006-12-10, 14:27

Re: Nowy sterownik USB a hotplug

Post autor: kazek3018 »

Identyfikatory są poprawne i wzięte z lsusb (to urządzenie może posiadać 3 różne product id w zależności od ustawień zworek)

Kod: Zaznacz cały

#ifndef K8055_H
#define K8055_H

#define K8055_VENDOR_ID     0x10cf
#define K8055_PRODUCT_ID0   0x5500
#define K8055_PRODUCT_ID1   0x5501
#define K8055_PRODUCT_ID2   0x5502
#define K8055_PRODUCT_ID3   0x5503

#endif
lsusb:

Kod: Zaznacz cały

Bus 004 Device 005: ID 10cf:5500 Velleman Components, Inc. 8055 Experiment Interface Board (address=0)
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               1.10
  bDeviceClass            0 (Defined at Interface level)
  bDeviceSubClass         0 
  bDeviceProtocol         0 
  bMaxPacketSize0         8
  idVendor           0x10cf Velleman Components, Inc.
  idProduct          0x5500 8055 Experiment Interface Board (address=0)
  bcdDevice            0.00
  iManufacturer           1 Velleman 
  iProduct                2 USB K8055
  iSerial                 0 
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength           41
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          4   
    bmAttributes         0x80
      (Bus Powered)
    MaxPower              100mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           2
      bInterfaceClass         3 Human Interface Device
      bInterfaceSubClass      0 No Subclass
      bInterfaceProtocol      0 None
      iInterface              0 
      ** UNRECOGNIZED:  09 21 00 01 00 01 22 1d 00
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0008  1x 8 bytes
        bInterval              10
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x01  EP 1 OUT
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0008  1x 8 bytes
        bInterval              10
Device Status:     0x0001
  Self Powered
insmod:

Kod: Zaznacz cały

usbcore: registered new interface driver k8055
usb_register(&k8055_driver) result -> 0
 Function usb_k8055_init for k8055
rmmod:

Kod: Zaznacz cały

usbcore: deregistering interface driver k8055
 Function usb_k8055_exit for k8055
Po podpięciu urządzenia dmesg pokazuje:

Kod: Zaznacz cały

usb 4-1: new low speed USB device using uhci_hcd and address 4
usb 4-1: New USB device found, idVendor=10cf, idProduct=5500
usb 4-1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
usb 4-1: Product: USB K8055
usb 4-1: Manufacturer: Velleman
usb 4-1: configuration #1 chosen from 1 choice
generic-usb 0003:10CF:5500.0005: hiddev97,hidraw2: USB HID v1.00 Device [Velleman  USB K8055] on usb-0000:00:1d.2-1/input0
Awatar użytkownika
mina86
Moderator
Posty: 3343
Rejestracja: 2004-06-14, 21:58
Lokalizacja: Linux 5.x x86_64
Kontakt:

Re: Nowy sterownik USB a hotplug

Post autor: mina86 »

To może trochę wyglądać, jakby HID próbował się do tego dobierać. W sumie z hostowymi sterownikami nie miałem wiele styczności więc trochę kończą mi się pomysły. Zasadniczo, spróbowałbym znaleźć miejsce, w którym te wszystkie identyfikatory są sprawdzane i powrzucał printki, aby zobaczyć co tam się dzieje.
Zastrzegam sobie prawo nieanalizowania postów pisanych niepoprawną polszczyzną.
Post generated automatically by A.I. system code name ‘mina86’ in response to the previous one.
kazek3018
Użytkownik
Posty: 181
Rejestracja: 2006-12-10, 14:27

Re: Nowy sterownik USB a hotplug

Post autor: kazek3018 »

Cześć

W tej chwili ręcznie wyrzucam to urządzenie w sterowniku HID, ale poprawnym rozwiązaniem wydaje się być drivers/hid/usbhid/hid-quirks.c gdzie trzeba dopisać go do black list.
Awatar użytkownika
mina86
Moderator
Posty: 3343
Rejestracja: 2004-06-14, 21:58
Lokalizacja: Linux 5.x x86_64
Kontakt:

Re: Nowy sterownik USB a hotplug

Post autor: mina86 »

Ja tam nie wiem. Najlepiej to chyba na linux-usb napisać.
Zastrzegam sobie prawo nieanalizowania postów pisanych niepoprawną polszczyzną.
Post generated automatically by A.I. system code name ‘mina86’ in response to the previous one.
ODPOWIEDZ