Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1211117pxb; Fri, 26 Feb 2021 05:32:46 -0800 (PST) X-Google-Smtp-Source: ABdhPJxFiVR/Husi5lT1xZWwZielTTSJy4ZgGzx0UDauvg2fK+9YzmqHIgB9lzMGP4NJOYzbQ43B X-Received: by 2002:a17:906:4fc8:: with SMTP id i8mr3316583ejw.228.1614346365766; Fri, 26 Feb 2021 05:32:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614346365; cv=none; d=google.com; s=arc-20160816; b=ZOwUxMyPPbZBjXCUzQ+ueejMgwBU1OJWPYV7nlOaqF/V57aSI5SFdiWYuZg+xTQBAh 0EyhK8JRXJ0+Vhj0Hd2/CRDzwPKzh2raAfLurhyXVeLvdiGRTobGqqqhDz2rctHEmvlE ZMReWQpMUiUgD7O3hRG4Mh+724tE7qbVLzffQvWVueYGM937Y3/vbjNIGx9/tmGWiaOp inkGv0nT8DvP6ZYcAULnLokodINC4cxeW/NRXZnG1PggxeIpdyqn4sjavWbNFk2RSJIi TeBss98sLR+82A2vuoghIhZHXjT+YLouqO39xb7sHcMIJyGfGSkA8GZqAwWMiPqzsPiU yZtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=dFfz1G0WaWAXvmcgfEZwLahXG7Ae9sPTB4poVvaDrCw=; b=n6RIQ7rBWuSy/F3thGuUd9+0iiISo/d9AgB2gPlS//tR4ZXKNqpnmwXiCn3ga0Cev3 5UFRgvjYcvZDbU1bJeIyy3r+auqYtul8hjn4vylOT9pz+kPsium4wYYdtSIIgbMIonDQ 5QLMVhclQF8aHO4ktXKNiDDv+UVQB5rEUgnsG19OzK1/1F1D72ioIEsZatkhI6YYT4vA tyoXEpmTUducoZjKirvFQaBN3izw0jzxXWem+Iqi4YyJanc6PndxyMbu4AqXhhQF4J6E ssIhstPZ7mLmM5zOXyyCxn6lhaO9SoruDcMceeRnHA2/7/l7xav5C7bHVzzH+OIilGuO jEbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=IKsU0M9H; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hr35si5611743ejc.48.2021.02.26.05.32.22; Fri, 26 Feb 2021 05:32:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=IKsU0M9H; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229845AbhBZNah (ORCPT + 99 others); Fri, 26 Feb 2021 08:30:37 -0500 Received: from mail.kernel.org ([198.145.29.99]:53078 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230096AbhBZN33 (ORCPT ); Fri, 26 Feb 2021 08:29:29 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5302164E4B; Fri, 26 Feb 2021 13:28:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1614346117; bh=Pg3E5k5m+ARqGfXGqBRXxYZr5F2MSDKqzC+TkVPCxJM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IKsU0M9H5Q3qz1+WfzNXDAdw0Oa3Pf5LsJA3kgKgpV3SVAdftjDFCziGFeFrGJeG0 CWRdpJ3/loui8Zwu+Yv6r9orvsEKh05GmC+hCbfktr5A/Mvrdx4v3vg8s4TcUlW+wP eu9x1uu3w/VGCCEOzHsFOOtLKlwfIwidUnRHFnIqBiPJGP+Qflt62mKzV/IoMwd5DG 5Kyhrk5I+GEmawJflUo0nk+NUN2dn+aSVeP3bd51ccQihsCDkgjCA0X/Fs336bmf8t IeC1oSgBsnucvvHawpFAIG+VD7xIq6k+2y0H/A3oEi+Vkt3ONWp61sY9Nue95MORBq eKmaB8RQVXxjw== Received: by mail.kernel.org with local (Exim 4.94) (envelope-from ) id 1lFdAY-002nbu-KM; Fri, 26 Feb 2021 14:28:34 +0100 From: Mauro Carvalho Chehab To: Johan Hovold Cc: Mauro Carvalho Chehab , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH 3/7] USB: serial: xr: add support for multi-port XR21V141X variants Date: Fri, 26 Feb 2021 14:28:29 +0100 Message-Id: <1552a1f9d20d5e8241aea4cfa247b0e549cd66d7.1614345081.git.mchehab+huawei@kernel.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: Mauro Carvalho Chehab Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org XR21V1412 and XR21V1414 have exactly the same interface, but they support multiple 2 and 4 ports, respectively. On such devices, the "CDC Union" field shows how they're grouped, as can be seen on those lsusb -v outputs: https://linux-usb.vger.kernel.narkive.com/YaTYwHkM/usb-uart-device-from-exar-co-not-working-with-cdc-acm-but-usbserial https://jquery.developreference.com/article/22043997/udev+rule+with+bInterfaceNumber+doesn't+work+%5bclosed%5d So, for instance, on XR21V1414, (0x04e2:0x1414), the 3rd port is: CDC Union: bMasterInterface 4 bSlaveInterface 5 CDC Call Management: bmCapabilities 0x01 call management bDataInterface 5 In other words, the control interface is an even number, and the data interface is the next odd number. The logic to get the proper register for an specific channel came from this patch: https://lore.kernel.org/linux-usb/20180404070634.nhspvmxcjwfgjkcv@advantechmxl-desktop Add support for them. Signed-off-by: Mauro Carvalho Chehab --- drivers/usb/serial/xr_serial.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/drivers/usb/serial/xr_serial.c b/drivers/usb/serial/xr_serial.c index 10f7fb40d9ae..1d4d67e64a21 100644 --- a/drivers/usb/serial/xr_serial.c +++ b/drivers/usb/serial/xr_serial.c @@ -145,6 +145,7 @@ static const int xr_hal_table[MAX_XR_MODELS][MAX_XR_HAL_TYPE] = { struct xr_port_private { enum xr_model model; + unsigned int channel; }; static int xr_set_reg(struct usb_serial_port *port, u8 block, u8 reg, u8 val) @@ -153,6 +154,14 @@ static int xr_set_reg(struct usb_serial_port *port, u8 block, u8 reg, u8 val) struct usb_serial *serial = port->serial; int ret; + switch (port_priv->model) { + case XR21V141X: + if (port_priv->channel) + reg |= (port_priv->channel - 1) << 8; + break; + default: + return -EINVAL; + }; ret = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), xr_hal_table[port_priv->model][REQ_SET], @@ -178,6 +187,14 @@ static int xr_get_reg(struct usb_serial_port *port, u8 block, u8 reg, u8 *val) if (!dmabuf) return -ENOMEM; + switch (port_priv->model) { + case XR21V141X: + if (port_priv->channel) + reg |= (port_priv->channel - 1) << 8; + break; + default: + return -EINVAL; + }; ret = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), xr_hal_table[port_priv->model][REQ_GET], @@ -601,17 +618,24 @@ static void xr_close(struct usb_serial_port *port) static int xr_probe(struct usb_serial *serial, const struct usb_device_id *id) { + struct usb_interface *intf = serial->interface; + struct usb_endpoint_descriptor *data_ep; struct xr_port_private *port_priv; + int ifnum; - /* Don't bind to control interface */ - if (serial->interface->cur_altsetting->desc.bInterfaceNumber == 0) + /* Attach only data interfaces */ + ifnum = intf->cur_altsetting->desc.bInterfaceNumber; + if (!(ifnum % 2)) return -ENODEV; port_priv = kzalloc(sizeof(*port_priv), GFP_KERNEL); if (!port_priv) return -ENOMEM; + data_ep = &intf->cur_altsetting->endpoint[0].desc; + port_priv->model = id->driver_info; + port_priv->channel = data_ep->bEndpointAddress; usb_set_serial_data(serial, port_priv); @@ -628,6 +652,8 @@ static void xr_disconnect(struct usb_serial *serial) static const struct usb_device_id id_table[] = { { USB_DEVICE(0x04e2, 0x1410), .driver_info = XR21V141X}, + { USB_DEVICE(0x04e2, 0x1412), .driver_info = XR21V141X}, + { USB_DEVICE(0x04e2, 0x1414), .driver_info = XR21V141X}, { } }; MODULE_DEVICE_TABLE(usb, id_table); -- 2.29.2