From patchwork Tue Nov 30 02:27:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Protsenko X-Patchwork-Id: 12694060 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5EFA6C433EF for ; Tue, 30 Nov 2021 02:29:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=/W8FowpLKFPfoLERYCTg11mx9Pic/nVXDDeSC5sU4x0=; b=K6HgC6fM4jfuro TrQ8Ccp9wZKEj09EngD+QiRdV4XnnLoY6qr2DBhfIVyfxCr72QUwyjICq0KF4GBBeZ8jx/fcVNS+S YrD4l4Si4wpzlxRUlqkl6Bzu8Tg9HgT/Okn51w9k6qJ9mfKjknOJvnT0XbOkca8isdx6ItZY5Pt4U jVg9+G+GmBoSBFXqAxwRh64pKP1Z9UIzunhi4TueG+0YC4PpS4YMhf7Oy3MKEZSsFmNjpPcmEW4rD LWBJQpNAnW+/X9GOVy69JI8Vcj7dzKHVZ5e1f9THBhahh0UwReNIfW5Dy50rGZvHnFFuQnkpOsVYg AUNYxOB8fV3pbpAwJ5hA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mrssF-003L0i-Pi; Tue, 30 Nov 2021 02:28:03 +0000 Received: from mail-lf1-x134.google.com ([2a00:1450:4864:20::134]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mrsrw-003Kuz-Uy for linux-arm-kernel@lists.infradead.org; Tue, 30 Nov 2021 02:27:47 +0000 Received: by mail-lf1-x134.google.com with SMTP id b40so49751178lfv.10 for ; Mon, 29 Nov 2021 18:27:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DjrKmm2WgaX87gIsGbMuz72ppQb8wewAQBmcfjqw3Gs=; b=XGILT3CfcE4kMyANq7bSTdH0QFSDL/+tG5w+aovYWrSS4otjinc/EsS9TlLwk5cl+t VFnMbpdVAO7wD+86m/f1wYIvqsy/a8PECHUAdvUcDJ76oCA/ftNSF4DeRTTt0E3Jx9x9 MRn8p/ZRLeeWMx6zmw8InMcAGJDDYrxoARd22ioEktvQIxrfOZP+qCE8DvOQjKpOO2X9 JAIEzphDwYqvi8j1eRXAcUjGKGEOKmMwlF992uml4GC8bO1gLu0yMj6V4uXmg6+KEphl XB0AFHGTMLIGf4XwkEDY99GE3xyk6t+6/LWB3FVjVg+5og/6zgmuRdahlWqJP1tyMgKo guEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DjrKmm2WgaX87gIsGbMuz72ppQb8wewAQBmcfjqw3Gs=; b=BIHsr+0VSQsF85uqWj+KQfk1LFoXNvou+2nnwe7ZVYq+wvcjjGJ/ZKi6SrW8ziXvor AkDN5ER57uH0K8hWmmBB4+tElEHtPiCi+02UsRuZ9bJUr6iRJnFIU8vUdhW4OGvt98It LdgYtXF3s0hqB16PHinK5PTNcXIkPI5V/QsuP5tBY5mYVMv9ZYgpl5zNJi4ss6AepSKd fQhLJ+KaG1GfwKwQOjJiJIfq3E3zaEPkixu9TTrfVoMOrXQbNMl1b9iuxNJ89o7aRfpN +IVM9x/SoD03IXRrzwCP7h8UJihO/fi04kzazxGXvxrHAVHxbwm3oT4nttU44b1Rlnhj s5iQ== X-Gm-Message-State: AOAM531WcnLlIl8G7p7+pHMzoZJ8FrNcufsDvwDBzj4J4lzRQp16vYn5 RtrIVUOdrtBGwGoXp/qRKSngTg== X-Google-Smtp-Source: ABdhPJy9w4OSiM/X9hJPqQvt6CKdaqi12cJt/JRDPlUUHCZMcMVlsYVIHiyuZTcMJKqMeoqst+bNYg== X-Received: by 2002:a05:6512:2350:: with SMTP id p16mr52129668lfu.117.1638239263333; Mon, 29 Nov 2021 18:27:43 -0800 (PST) Received: from localhost ([31.134.121.151]) by smtp.gmail.com with ESMTPSA id i10sm1543136lfv.22.2021.11.29.18.27.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Nov 2021 18:27:42 -0800 (PST) From: Sam Protsenko To: Krzysztof Kozlowski , Rob Herring , Greg Kroah-Hartman Cc: Jiri Slaby , Jaewon Kim , Chanho Park , David Virag , Youngmin Nam , devicetree@vger.kernel.org, linux-serial@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-samsung-soc@vger.kernel.org Subject: [PATCH v2 4/5] tty: serial: samsung: Enable console as module Date: Tue, 30 Nov 2021 04:27:39 +0200 Message-Id: <20211130022740.28784-2-semen.protsenko@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211130022740.28784-1-semen.protsenko@linaro.org> References: <20211130022740.28784-1-semen.protsenko@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211129_182745_020556_6D0B2BF5 X-CRM114-Status: GOOD ( 19.28 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Enable serial driver to be built as a module. To do so, init the console support on driver/module load instead of using console_initcall(). This is needed for proper support of USI driver (which can be built as a module, which in turn makes SERIAL_SAMSUNG be a module too). It also might be useful for Android GKI modularization efforts. Inspired by commit 87a0b9f98ac5 ("tty: serial: meson: enable console as module"). Signed-off-by: Sam Protsenko --- Changes in v2: - Added error path handling in samsung_serial_init() - Added console unregister in samsung_serial_exit() drivers/tty/serial/Kconfig | 2 +- drivers/tty/serial/samsung_tty.c | 36 ++++++++++++++++++++++++++++---- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/drivers/tty/serial/Kconfig b/drivers/tty/serial/Kconfig index fc543ac97c13..0e5ccb25bdb1 100644 --- a/drivers/tty/serial/Kconfig +++ b/drivers/tty/serial/Kconfig @@ -263,7 +263,7 @@ config SERIAL_SAMSUNG_UARTS config SERIAL_SAMSUNG_CONSOLE bool "Support for console on Samsung SoC serial port" - depends on SERIAL_SAMSUNG=y + depends on SERIAL_SAMSUNG select SERIAL_CORE_CONSOLE select SERIAL_EARLYCON help diff --git a/drivers/tty/serial/samsung_tty.c b/drivers/tty/serial/samsung_tty.c index f986a9253dc8..61ccb359620a 100644 --- a/drivers/tty/serial/samsung_tty.c +++ b/drivers/tty/serial/samsung_tty.c @@ -1715,15 +1715,21 @@ s3c24xx_serial_verify_port(struct uart_port *port, struct serial_struct *ser) static struct console s3c24xx_serial_console; -static int __init s3c24xx_serial_console_init(void) +static void __init s3c24xx_serial_register_console(void) { register_console(&s3c24xx_serial_console); - return 0; } -console_initcall(s3c24xx_serial_console_init); + +static void s3c24xx_serial_unregister_console(void) +{ + if (s3c24xx_serial_console.flags & CON_ENABLED) + unregister_console(&s3c24xx_serial_console); +} #define S3C24XX_SERIAL_CONSOLE &s3c24xx_serial_console #else +static inline void s3c24xx_serial_register_console(void) { } +static inline void s3c24xx_serial_unregister_console(void) { } #define S3C24XX_SERIAL_CONSOLE NULL #endif @@ -2898,7 +2904,29 @@ static struct platform_driver samsung_serial_driver = { }, }; -module_platform_driver(samsung_serial_driver); +static int __init samsung_serial_init(void) +{ + int ret; + + s3c24xx_serial_register_console(); + + ret = platform_driver_register(&samsung_serial_driver); + if (ret) { + s3c24xx_serial_unregister_console(); + return ret; + } + + return 0; +} + +static void __exit samsung_serial_exit(void) +{ + platform_driver_unregister(&samsung_serial_driver); + s3c24xx_serial_unregister_console(); +} + +module_init(samsung_serial_init); +module_exit(samsung_serial_exit); #ifdef CONFIG_SERIAL_SAMSUNG_CONSOLE /*