ch9102x芯片的旧版驱动程序用在ubuntu22.04时,编译时会产生如下错误:
make[1]: Entering directory '/usr/src/linux-headers-5.16.15-76051615-generic'
CC [M] /home/maz/driver/ch343.o
/home/maz/driver/ch343.c:1684:33: error: initialization of ‘unsigned int (*)(struct tty_struct *)’ from incompatible pointer type ‘int (*)(struct tty_struct *)’ [-Werror=incompatible-pointer-types]
1684 | .write_room = ch343_tty_write_room,
| ^~~~~~~~~~~~~~~~~~~~
/home/maz/driver/ch343.c:1684:33: note: (near initialization for ‘ch343_ops.write_room’)
/home/maz/driver/ch343.c:1686:33: error: initialization of ‘unsigned int (*)(struct tty_struct *)’ from incompatible pointer type ‘int (*)(struct tty_struct *)’ [-Werror=incompatible-pointer-types]
1686 | .chars_in_buffer = ch343_tty_chars_in_buffer,
| ^~~~~~~~~~~~~~~~~~~~~~~~~
/home/maz/driver/ch343.c:1686:33: note: (near initialization for ‘ch343_ops.chars_in_buffer’)
/home/maz/driver/ch343.c: In function ‘ch343_init’:
/home/maz/driver/ch343.c:1699:28: error: implicit declaration of function ‘alloc_tty_driver’ [-Werror=implicit-function-declaration]
1699 | ch343_tty_driver = alloc_tty_driver(CH343_TTY_MINORS);
| ^~~~~~~~~~~~~~~~
/home/maz/driver/ch343.c:1699:26: warning: assignment to ‘struct tty_driver *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion]
1699 | ch343_tty_driver = alloc_tty_driver(CH343_TTY_MINORS);
| ^
/home/maz/driver/ch343.c:1716:17: error: implicit declaration of function ‘put_tty_driver’ [-Werror=implicit-function-declaration]
1716 | put_tty_driver(ch343_tty_driver);
| ^~~~~~~~~~~~~~
cc1: some warnings being treated as errors
GreatestCapacity 修改了代码,使其与新的Linux内核兼容。如果设备工作正常,驱动程序将在/dev目录下创建tty设备,命名为“ttyCH343USBx”。驱动代码如下: