From patchwork Fri Feb 26 10:15:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Romain Izard X-Patchwork-Id: 8434201 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 28D56C0553 for ; Fri, 26 Feb 2016 10:17:14 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4271120265 for ; Fri, 26 Feb 2016 10:17:13 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6642B201D3 for ; Fri, 26 Feb 2016 10:17:12 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1aZFR5-0003g5-Tr; Fri, 26 Feb 2016 10:15:47 +0000 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1aZFR2-0003Yb-NP for linux-arm-kernel@lists.infradead.org; Fri, 26 Feb 2016 10:15:45 +0000 Received: by mail-wm0-x242.google.com with SMTP id b205so8249345wmb.1 for ; Fri, 26 Feb 2016 02:15:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=Ms790+CsL+XjXPeh/Wi5ZDksauqSw1g/qs92CXsfxt4=; b=ZECH1nwepIf3xEOrQxyOQ/DcFOGLU8AFDjYZInAZ3Y3UWGywrEoENdo3liG9F65iaE ZHjqxOPiJ43L+F0dRF9+fn5lrUG+9BAvY+ZDBPsQnuxEtb9oXMB/QMGjeHIbBvXwx9IT u9qGRzAPd+kJSjFCw0cXOCj4+Qxb6gO9nkRWWdsQgixhviIXMwrlGx8K7aINk/7/Sg4m 5rr2wtrnWG9DMO1NGvPaoQJhjufLQ7Wwky9XkQYWVE5fmNMRC9y9mUD/07QMPbRpqHHc 56yHMRiArBeRbw+GkRXF/mZPk7YJgQvA4Jh88d450tqrmPNQfssQIZfCp+GpQsh2dsv9 kamw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=Ms790+CsL+XjXPeh/Wi5ZDksauqSw1g/qs92CXsfxt4=; b=Aor3VJ/a21tjg5/1xq4XJbqBbDzK92MNR2xw0og2mOYe2rUNXPtqmCMGf33FVTYVf6 Pl+dAPM9hvElaAlQBLcpNb9lbvegi2caNpiZPzPiqKfNCeJpFJw8p+crBKnGw9buYg+T cX8Pgm+9gemPnbEMbekUmtEvXHqkxHmkAy8aGnUtix90P8g6xJUlefpTHXHYRiJ7Tjbv +b9904V8bAAVAJ2/2FEWGLCx+WtCTXnaLvBVMInM3PCukptw/jfrT5Zu7xkgKf/mHeP8 dAanzhN/hE5djsXGRgfUtWOwYToykAly4K1AilafZtu1yx/3AKEhmQW6ekIxZdC/yj/q PPFg== X-Gm-Message-State: AD7BkJINJTM/cpTbmGrHEysyRUCIhaiB3g0BWqm6rf6Wn8oD0+TXtjhNeVIoahjVhvOurw== X-Received: by 10.28.73.66 with SMTP id w63mr2319658wma.53.1456481722784; Fri, 26 Feb 2016 02:15:22 -0800 (PST) Received: from localhost.localdomain (146.187.3.109.rev.sfr.net. [109.3.187.146]) by smtp.gmail.com with ESMTPSA id h132sm2206784wmf.9.2016.02.26.02.15.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 26 Feb 2016 02:15:21 -0800 (PST) From: Romain Izard To: linux-serial@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Nicolas Ferre Subject: [PATCH v3] tty/serial: at91: restore dynamic driver binding Date: Fri, 26 Feb 2016 11:15:04 +0100 Message-Id: <1456481704-18997-1-git-send-email-romain.izard.pro@gmail.com> X-Mailer: git-send-email 2.5.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160226_021544_967476_175EAAB3 X-CRM114-Status: GOOD ( 18.34 ) X-Spam-Score: -2.0 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paul Gortmaker , Romain Izard , Jiri Slaby MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In commit c39dfebc7798956fd2140ae6321786ff35da30c3, the modular support code for atmel_serial was removed, as the driver cannot be built as a module. Because no use case was proposed, the dynamic driver binding support was removed as well. The atmel_serial driver can manage up to 7 serial controllers, which are multiplexed with other functions. For example, in the Atmel SAMA5D2, the Flexcom controllers can work as USART, SPI or I2C controllers, and on all Atmel devices serial lines can be reconfigured as GPIOs. My use case uses GPIOs to transfer a firmware update using a custom protocol on the lines used as a serial port during the normal life of the device. If it is not possible to unbind the atmel_serial driver, the GPIO lines remain reserved and prevent this case from working. This patch reinstates the atmel_serial_remove function, and fixes it as it failed to clear the "clk" field on removal, triggering an oops when a device was bound again after being unbound. Acked-by: Nicolas Ferre Signed-off-by: Romain Izard --- Changelog: v2: Add the rationale for keeping the "remove" function as a comment. v3: Do not cleanup the spaces in the driver initializer, as requested by the maintainer drivers/tty/serial/atmel_serial.c | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c index 1c0884d8ef32..969084455f94 100644 --- a/drivers/tty/serial/atmel_serial.c +++ b/drivers/tty/serial/atmel_serial.c @@ -2759,14 +2759,47 @@ err: return ret; } +/* + * Even if the driver is not modular, it makes sense to be able to + * unbind a device: there can be many bound devices, and there are + * situations where dynamic binding and unbinding can be useful. + * + * For example, a connected device can require a specific firmware update + * protocol that needs bitbanging on IO lines, but use the regular serial + * port in the normal case. + */ +static int atmel_serial_remove(struct platform_device *pdev) +{ + struct uart_port *port = platform_get_drvdata(pdev); + struct atmel_uart_port *atmel_port = to_atmel_uart_port(port); + int ret = 0; + + tasklet_kill(&atmel_port->tasklet); + + device_init_wakeup(&pdev->dev, 0); + + ret = uart_remove_one_port(&atmel_uart, port); + + kfree(atmel_port->rx_ring.buf); + + /* "port" is allocated statically, so we shouldn't free it */ + + clear_bit(port->line, atmel_ports_in_use); + + clk_put(atmel_port->clk); + atmel_port->clk = NULL; + + return ret; +} + static struct platform_driver atmel_serial_driver = { .probe = atmel_serial_probe, + .remove = atmel_serial_remove, .suspend = atmel_serial_suspend, .resume = atmel_serial_resume, .driver = { .name = "atmel_usart", .of_match_table = of_match_ptr(atmel_serial_dt_ids), - .suppress_bind_attrs = true, }, };