Skip to content

Commit

Permalink
kernel: tty usb serial index specified by dts
Browse files Browse the repository at this point in the history
  • Loading branch information
srdgame committed Sep 25, 2023
1 parent 14a4fc1 commit e21f1d3
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 39 deletions.
1 change: 1 addition & 0 deletions .config_tlink_k2x_symlink
Original file line number Diff line number Diff line change
Expand Up @@ -2608,6 +2608,7 @@ CONFIG_PACKAGE_kmod-usb-serial-option=y
CONFIG_PACKAGE_kmod-usb-serial-qualcomm=y
# CONFIG_PACKAGE_kmod-usb-serial-sierrawireless is not set
# CONFIG_PACKAGE_kmod-usb-serial-simple is not set
# CONFIG_PACKAGE_kmod-usb-serial-sprdu2s is not set
# CONFIG_PACKAGE_kmod-usb-serial-ti-usb is not set
# CONFIG_PACKAGE_kmod-usb-serial-visor is not set
CONFIG_PACKAGE_kmod-usb-serial-wwan=y
Expand Down
2 changes: 1 addition & 1 deletion package/base-files/files/etc/build_version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
23.09.21
23.09.25
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,22 @@ static int xr_usb_serial_alloc_minor(struct xr_usb_serial *xr_usb_serial)
return minor;
}

/*
* Try to bind minor number associate it with 'xr_usb_serial'.
*/
static int xr_usb_serial_set_minor(struct xr_usb_serial *xr_usb_serial, int minor)
{
mutex_lock(&xr_usb_serial_table_lock);
if (!xr_usb_serial_table[minor]) {
xr_usb_serial_table[minor] = xr_usb_serial;
mutex_unlock(&xr_usb_serial_table_lock);
return minor;
}
mutex_unlock(&xr_usb_serial_table_lock);

return XR_USB_SERIAL_TTY_MINORS;
}

/* Release the minor number associated with 'xr_usb_serial'. */
static void xr_usb_serial_release_minor(struct xr_usb_serial *xr_usb_serial)
{
Expand Down Expand Up @@ -1524,7 +1540,17 @@ static int xr_usb_serial_probe(struct usb_interface *intf,
goto alloc_fail;
}

minor = xr_usb_serial_alloc_minor(xr_usb_serial);
if (intf->dev.of_node) {
if (of_property_read_s32(intf->dev.of_node, "xr_tty_minor", &minor)) {
minor = xr_usb_serial_alloc_minor(xr_usb_serial);
} else {
dev_info(&intf->dev, "of_node:%pOF got minor:%d\n", intf->dev.of_node, minor);
minor = xr_usb_serial_set_minor(xr_usb_serial, minor);
}
} else {
minor = xr_usb_serial_alloc_minor(xr_usb_serial);
}

if (minor == XR_USB_SERIAL_TTY_MINORS) {
dev_err(&intf->dev, "no more free xr_usb_serial devices\n");
kfree(xr_usb_serial);
Expand Down Expand Up @@ -1704,12 +1730,12 @@ static int xr_usb_serial_probe(struct usb_interface *intf,
dev_info(&intf->dev, "ttyXR_USB_SERIAL%d: USB XR_USB_SERIAL device\n", minor);

xr_usb_serial->rs485mode = 0;
if (usb_dev->dev.of_node) {
if (of_property_read_bool(usb_dev->dev.of_node, "xr_485_mode")) {
if (intf->dev.of_node) {
if (of_property_read_bool(intf->dev.of_node, "xr_485_mode")) {
xr_usb_serial->rs485mode = 1;
dev_info(&usb_dev->dev, "of_node:%pOF using xr_485_mode\n", usb_dev->dev.of_node);
dev_info(&intf->dev, "of_node:%pOF using xr_485_mode\n", intf->dev.of_node);
} else {
dev_info(&usb_dev->dev, "of_node:%pOF has no xr_485_mode\n", usb_dev->dev.of_node);
dev_info(&intf->dev, "of_node:%pOF has no xr_485_mode\n", intf->dev.of_node);
}
} else {
dev_info(&usb_dev->dev, "no of_mode found\n");
Expand Down
32 changes: 16 additions & 16 deletions target/linux/sunxi/base-files/etc/hotplug.d/tty/90-tlink
Original file line number Diff line number Diff line change
Expand Up @@ -30,52 +30,52 @@ tlink_m408_xr_usb() {
tlink_m416_xr_usb() {
case "$DEVICENAME" in
ttyXRUSB0)
rm /dev/ttyS9
ln -s /dev/$DEVICENAME /dev/ttyS9
rm /dev/ttyS5
ln -s /dev/$DEVICENAME /dev/ttyS5
;;
ttyXRUSB1)
rm /dev/ttyS10
ln -s /dev/$DEVICENAME /dev/ttyS10
rm /dev/ttyS6
ln -s /dev/$DEVICENAME /dev/ttyS6
;;
ttyXRUSB2)
rm /dev/ttyS11
ln -s /dev/$DEVICENAME /dev/ttyS11
rm /dev/ttyS7
ln -s /dev/$DEVICENAME /dev/ttyS7
;;
ttyXRUSB3)
rm /dev/ttyS12
ln -s /dev/$DEVICENAME /dev/ttyS12
rm /dev/ttyS8
ln -s /dev/$DEVICENAME /dev/ttyS8
;;
ttyXRUSB4)
rm /dev/ttyS13
ln -s /dev/$DEVICENAME /dev/ttyS13
ln -s /dev/$DEVICENAME /dev/ttyS9
;;
ttyXRUSB5)
rm /dev/ttyS14
ln -s /dev/$DEVICENAME /dev/ttyS14
ln -s /dev/$DEVICENAME /dev/ttyS10
;;
ttyXRUSB6)
rm /dev/ttyS15
ln -s /dev/$DEVICENAME /dev/ttyS15
ln -s /dev/$DEVICENAME /dev/ttyS11
;;
ttyXRUSB7)
rm /dev/ttyS16
ln -s /dev/$DEVICENAME /dev/ttyS16
ln -s /dev/$DEVICENAME /dev/ttyS12
;;
ttyXRUSB8)
rm /dev/ttyS5
ln -s /dev/$DEVICENAME /dev/ttyS5
ln -s /dev/$DEVICENAME /dev/ttyS13
;;
ttyXRUSB9)
rm /dev/ttyS6
ln -s /dev/$DEVICENAME /dev/ttyS6
ln -s /dev/$DEVICENAME /dev/ttyS14
;;
ttyXRUSB10)
rm /dev/ttyS7
ln -s /dev/$DEVICENAME /dev/ttyS7
ln -s /dev/$DEVICENAME /dev/ttyS15
;;
ttyXRUSB11)
rm /dev/ttyS8
ln -s /dev/$DEVICENAME /dev/ttyS8
ln -s /dev/$DEVICENAME /dev/ttyS16
;;
esac
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
--- /dev/null
+++ b/arch/arm/boot/dts/sun8i-t3-tlink-dly-t3v2.dtsi
@@ -0,0 +1,514 @@
@@ -0,0 +1,538 @@
+/*
+ * Copyright (C) 2021 Dirk Chang <[email protected]>
+ *
Expand Down Expand Up @@ -217,7 +217,7 @@
+ #address-cells = <1>;
+ #size-cells = <0>;
+
+ xr22800: hub@1 {
+ xr22800: xr22800@1 {
+ compatible = "usb4e2,800";
+ reg = <1>;
+ #address-cells = <1>;
Expand All @@ -235,7 +235,7 @@
+ #address-cells = <1>;
+ #size-cells = <0>;
+
+ xr22804: hub@1 {
+ xr22804: xr22804@1 {
+ compatible = "usb4e2,804";
+ reg = <1>;
+ #address-cells = <1>;
Expand All @@ -245,21 +245,45 @@
+ reg = <1>;
+ local-mac-address = [00 00 00 00 00 00];
+ };
+ uart@2 {
+ xr_uart1: xr-uart1@2 {
+ reg = <2>;
+ xr_485_mode;
+ #address-cells = <2>;
+ #size-cells = <0>;
+ xr-uart1-interface@0 { /* interface 0 of configuration 1 */
+ reg = <0 1>;
+ xr_485_mode;
+ xr_tty_minor=<0>;
+ };
+ };
+ uart@3 {
+ xr_uart2: xr-uart2@3 {
+ reg = <3>;
+ xr_485_mode;
+ #address-cells = <2>;
+ #size-cells = <0>;
+ xr-uart2-interface@0 { /* interface 0 of configuration 1 */
+ reg = <0 1>;
+ xr_485_mode;
+ xr_tty_minor=<1>;
+ };
+ };
+ uart@4 {
+ xr_uart3: xr-uart3@4 {
+ reg = <4>;
+ xr_485_mode;
+ #address-cells = <2>;
+ #size-cells = <0>;
+ xr-uart3-interface@0 { /* interface 0 of configuration 1 */
+ reg = <0 1>;
+ xr_485_mode;
+ xr_tty_minor=<2>;
+ };
+ };
+ uart@5 {
+ xr_uart4: xr-uart4@5 {
+ reg = <5>;
+ xr_485_mode;
+ #address-cells = <2>;
+ #size-cells = <0>;
+ xr-uart4-interface@0 { /* interface 0 of configuration 1 */
+ reg = <0 1>;
+ xr_485_mode;
+ xr_tty_minor=<3>;
+ };
+ };
+ };
+};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
+};
--- /dev/null
+++ b/arch/arm/boot/dts/sun8i-t3-tlink-m416.dts
@@ -0,0 +1,45 @@
@@ -0,0 +1,103 @@
+/*
+ * Copyright (C) 2021 Dirk Chang <[email protected]>
+ *
Expand All @@ -97,22 +97,80 @@
+ #address-cells = <1>;
+ #size-cells = <0>;
+
+ hub2514@1 {
+ xr_uart1414: xr2514@1 {
+ compatible = "usb424,2514";
+ reg = <1>;
+ #address-cells = <1>;
+ #size-cells = <0>;
+
+ uart1414@1 {
+ xr_uart5: xr-uart5@1 {
+ compatible = "usb4e2,1414";
+ reg = <1>;
+ xr_485_mode;
+ #address-cells = <2>;
+ #size-cells = <0>;
+
+ xr-uart5-intf-0@0,1 { /* interface 0 of configuration 1 */
+ compatible = "usb4e2,1414.config1.0";
+ reg = <0 1>;
+ xr_485_mode;
+ xr_tty_minor=<4>;
+ };
+
+ xr-uart5-intf-2@2,1 { /* interface 2 of configuration 1 */
+ compatible = "usb4e2,1414.config1.2";
+ reg = <2 1>;
+ xr_485_mode;
+ xr_tty_minor=<5>;
+ };
+
+ xr-uart5-intf-4@4,1 { /* interface 4 of configuration 1 */
+ compatible = "usb4e2,1414.config1.4";
+ reg = <4 1>;
+ xr_485_mode;
+ xr_tty_minor=<6>;
+ };
+
+ xr-uart5-intf-6@6,1 { /* interface 6 of configuration 1 */
+ compatible = "usb4e2,1414.config1.6";
+ reg = <6 1>;
+ xr_485_mode;
+ xr_tty_minor=<7>;
+ };
+ };
+
+ uart1414@2 {
+ xr_uart6: xr-uart6@2 {
+ compatible = "usb4e2,1414";
+ reg = <2>;
+ xr_485_mode;
+ #address-cells = <2>;
+ #size-cells = <0>;
+
+ xr-uart6-intf-0@0,1 { /* interface 0 of configuration 1 */
+ compatible = "usb4e2,1414.config1.0";
+ reg = <0 1>;
+ xr_485_mode;
+ xr_tty_minor=<8>;
+ };
+
+ xr-uart6-intf-2@2,1 { /* interface 2 of configuration 1 */
+ compatible = "usb4e2,1414.config1.2";
+ reg = <2 1>;
+ xr_485_mode;
+ xr_tty_minor=<9>;
+ };
+
+ xr-uart6-intf-4@4,1 { /* interface 4 of configuration 1 */
+ compatible = "usb4e2,1414.config1.4";
+ reg = <4 1>;
+ xr_485_mode;
+ xr_tty_minor=<10>;
+ };
+
+ xr-uart6-intf-6@6,1 { /* interface 6 of configuration 1 */
+ compatible = "usb4e2,1414.config1.6";
+ reg = <6 1>;
+ xr_485_mode;
+ xr_tty_minor=<11>;
+ };
+ };
+ };
+};

0 comments on commit e21f1d3

Please sign in to comment.