From patchwork Fri May 25 12:52:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 10427357 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 74B5A602D6 for ; Fri, 25 May 2018 12:53:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 60FB328D72 for ; Fri, 25 May 2018 12:53:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 553062918A; Fri, 25 May 2018 12:53:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C48F628D72 for ; Fri, 25 May 2018 12:53:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935432AbeEYMxl (ORCPT ); Fri, 25 May 2018 08:53:41 -0400 Received: from mail-wr0-f195.google.com ([209.85.128.195]:44646 "EHLO mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752217AbeEYMxi (ORCPT ); Fri, 25 May 2018 08:53:38 -0400 Received: by mail-wr0-f195.google.com with SMTP id y15-v6so9064051wrg.11; Fri, 25 May 2018 05:53:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=Sv1w9ubjhHRMTidC0ixz0/kebj8cFwQRmd72vn3YoRI=; b=KYzJE7vsIE7c386+7I7pRechuTHcOawcJq7Ct5erLokLZyA2kKwNGrIlGN8tKV+lIz KWEV3nGyJwACVUcULE5mzP1j/I4mamqh98bI8GOsMsZHikrFaQ/cNu7wg6mzRrlnXa1N Va5tTfb+n8btK3+ZMonQR2ATW9Cu51NWG8fE0UMxxquUow2/jT4f52/NcXOllRaaDh/z G+HwofCwWvjG9TtWJlLW1dGgDIs7Am6jC0q8+W4/NuPAW8ci3oo1cA3iBV7c0iA1jopy ir5H1c1NnE6ijaKngiN0iKalZr7ndx+nZykara1DE+SUTBKDZFxhzBPYaeH5OePrdd8X ByZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=Sv1w9ubjhHRMTidC0ixz0/kebj8cFwQRmd72vn3YoRI=; b=FQjXNPTKipTKE2AtFocX6Q8pnRzLjtNi6fFEImdN0A5Q1SVtCMt2G3AADj1ojoCNZH ElNYBk1HwnOWI9eepMe8rJboyjhef9MtsqKJ1vuDAgUiGwxQ/D3Oj0RtQJxao11pM382 6BuazkRgbgxMdiZbYKoXnK8H1Sve6nVgOKAV/EZpYKgnzzKgS1yD/buP41z1VoKuWlSl fOS76qjMKvsn5Gd6vAv6LUpsNLfq4402PNj6m1P52b71rMVTfpwNCoNpUaQIgdhCyWLc w5fV46Sqy5751I+LM0tE3xxP+tWEqEzmR93znmU0eppYkOvGsIM3UVxJPoEx5qo0oDao 4ydg== X-Gm-Message-State: ALKqPwckth2h0/WGQURtUoFFJJzHiblYMNXBBZkTQjmSrTSUw2W12jBG 6iK8qTl5o0yViinyXRBfdIQ= X-Google-Smtp-Source: ADUXVKJ+Pj80Eg25Gd/EYIwqMKtUQvp3+R53BcjkcbRwaHdkpL6P+YM/oYrybG0ebA2CH1gDRNSGsw== X-Received: by 2002:a19:9358:: with SMTP id v85-v6mr1465159lfd.83.1527252816592; Fri, 25 May 2018 05:53:36 -0700 (PDT) Received: from xi.terra (c-8bb2e655.07-184-6d6c6d4.bbcust.telenor.se. [85.230.178.139]) by smtp.gmail.com with ESMTPSA id i29-v6sm5514100lfb.89.2018.05.25.05.53.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 25 May 2018 05:53:35 -0700 (PDT) Received: from johan by xi.terra with local (Exim 4.90_1) (envelope-from ) id 1fMCDo-0007aZ-Ci; Fri, 25 May 2018 14:53:28 +0200 From: Johan Hovold To: Rob Herring Cc: Mark Rutland , Johan Hovold , Greg Kroah-Hartman , Ricardo Ribalda Delgado , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, linux-serial@vger.kernel.org Subject: [RFC PATCH 1/3] USB: serial: add device-tree support Date: Fri, 25 May 2018 14:52:55 +0200 Message-Id: <20180525125257.29124-2-johan@kernel.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180525125257.29124-1-johan@kernel.org> References: <20180525125257.29124-1-johan@kernel.org> Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Lookup and associate serial-port device-tree nodes given a parent USB-interface node during probe. Note that a serial-port node must be named "serial" and have a "reg" property so that ports on multi-port interfaces can be distinguished. &usb_interface { #address-cells = <1>; #size-cells = <0>; serial@0 { reg = <0>; }; }; FIXME: binding doc Not-signed-off-by: Johan Hovold --- drivers/usb/serial/usb-serial.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c index 44ecf0e2be9d..5a7ebe1e9fd6 100644 --- a/drivers/usb/serial/usb-serial.c +++ b/drivers/usb/serial/usb-serial.c @@ -35,6 +35,7 @@ #include #include #include +#include #define DRIVER_AUTHOR "Greg Kroah-Hartman " #define DRIVER_DESC "USB Serial Driver core" @@ -97,7 +98,6 @@ static int allocate_minors(struct usb_serial *serial, int num_ports) if (minor < 0) goto error; port->minor = minor; - port->port_number = i; } serial->minors_reserved = 1; mutex_unlock(&table_lock); @@ -589,6 +589,7 @@ static void usb_serial_port_release(struct device *dev) kfifo_free(&port->write_fifo); kfree(port->interrupt_in_buffer); kfree(port->interrupt_out_buffer); + of_node_put(dev->of_node); tty_port_destroy(&port->port); kfree(port); } @@ -857,6 +858,29 @@ static int setup_port_interrupt_out(struct usb_serial_port *port, return 0; } +/* FIXME: move to separate compilation unit? */ +static struct device_node *find_port_node(struct usb_interface *intf, int port) +{ + struct device_node *node; + u32 reg; + + for_each_child_of_node(intf->dev.of_node, node) { + if (!node->name || of_node_cmp(node->name, "serial") != 0) + continue; + + if (of_property_read_u32(node, "reg", ®)) + continue; + + if (reg == port) + break; + } + + dev_dbg(&intf->dev, "node %pOF, port %d: %pOFP\n", intf->dev.of_node, + port, node); + + return node; +} + static int usb_serial_probe(struct usb_interface *interface, const struct usb_device_id *id) { @@ -963,6 +987,7 @@ static int usb_serial_probe(struct usb_interface *interface, retval = -ENOMEM; goto err_free_epds; } + port->port_number = i; tty_port_init(&port->port); port->port.ops = &serial_port_ops; port->serial = serial; @@ -976,6 +1001,7 @@ static int usb_serial_probe(struct usb_interface *interface, port->dev.bus = &usb_serial_bus_type; port->dev.release = &usb_serial_port_release; port->dev.groups = usb_serial_port_groups; + port->dev.of_node = find_port_node(interface, port->port_number); device_initialize(&port->dev); }