From patchwork Thu Feb 15 14:50:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 201670 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:c619:b0:108:e6aa:91d0 with SMTP id hn25csp854dyb; Thu, 15 Feb 2024 09:30:26 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWcYLQTKre7R6HBBJeKYBwBuh63CNL+t1ljCck31I8hKIf+lxOId174OrP3lMhbZTFaivYZmcutNi4Z2/BZAoTRrxIeFw== X-Google-Smtp-Source: AGHT+IGwNrWQQ6Dcg/BQKy6L9MCZmyYOI+IbUz8FrXv67iLitcWxUxEdeAMj0Zwh2ejlO/KGQ4ko X-Received: by 2002:a05:6214:2503:b0:68c:8667:f77f with SMTP id gf3-20020a056214250300b0068c8667f77fmr3643163qvb.18.1708018226088; Thu, 15 Feb 2024 09:30:26 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708018226; cv=pass; d=google.com; s=arc-20160816; b=W0889dZy01hCZhcTdPiOo2Ub2SqoqvFoUVUkJm8Ww5QGszQ5DfKocuaIaWTHIGaRrH sQCEZvGa1xMgYzG4vzgS1iXoY9jjTGAUFZVk0qBwanY2akfS7bG2Px5aOGMsJx7gfHf+ F+efpBf1hTTxuSZZyNOSRKGe2QgNPqNxMkoOdCSBvqCUqzI+Fd9Gov8dZkc+xkUJ7XcN 0IcuOFVHTDN1ARFrY/h6GR3vcQ3OKIHFIx0H+5kNn3bXhIthIa+dDWvb50NwYC0F0UWf oyiUaEqrtZuW+s6W3F7iN9/bCTPfQ/ZuW+9xhuM+ElHyAs98VI1hfPEd1qeMnuMc0F4Z 6BMw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=4M8gTZMFtN1itm6CxRcKMHcTY6FR/a5yZ7W6q4f1wOA=; fh=G+kXbXZ7X6Rrw4sqwu0pPJ5LnQ6m545XsQoac6catcE=; b=VEJAXzCdjVme1v0k7Hpf7l/onQv9vuID/lEZgmczlb18YVdSm8T0yFWxYVUicGh+wU lPhQ+uXlhr7HefgJxAIQUJRJhqlaqy+cq6PElNqEYHNJPaBZJt6DCn1PwjHYwixJCdxB 720x0Yx9zqSnkmMXHHfrDLbnZU3TvoC4lGJgxVFnlxigsG4aZaaX1Z+c5Jm5X+Y+m0L6 vpkU3caKrkB9KyRcF14Kqpe1APn7Y0SpMfY1tYBFuMI/qDWcOHtnwY2BrJvYt5JNiC29 ZKPxyPIP5Ws+QrqStcaPEy3Q1z9ZYoHVec1/jjVCWAHaXxnxFJTXUDer0Kq58fVYVCFe oQlg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="JCTZ/IsK"; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-67107-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-67107-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id pt19-20020a056214049300b0068efe13d06esi1864896qvb.361.2024.02.15.09.30.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 09:30:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-67107-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="JCTZ/IsK"; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-67107-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-67107-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 75D891C22B27 for ; Thu, 15 Feb 2024 14:50:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4C38813249C; Thu, 15 Feb 2024 14:50:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="JCTZ/IsK" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 447BB132484; Thu, 15 Feb 2024 14:50:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.20 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708008637; cv=none; b=UfNT8xo5O4NSEwpEVajYRjvlMlc43/8I6lIPSXuSHsrg2kkHikv4kkvJugaG+uk7ATF0pUBksDJE8S9gV2yKy3gqTf2V04xVf3g9hxYKrZcKcMYYwkh0wVovglTUr4I35SC57ccEX7puw0G4+PWEhQYKhiO3hF+EOvH42Jdnmf8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708008637; c=relaxed/simple; bh=2UTMt4kij+AbeHSuCqQx7s5uiRsL4iwwHL/UJl/dr60=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=dw7eIuqT3kXXD9qQsWNtJvFwDTPhVdQuz73rd9vosX9KoPzGJqDXFxpoA3fbiHyUxDbitBtF9UrCIcY4GZcCXBXkWbbCUMI4QbHxBew2eJ7TCahxGB52pzazsPau3nRMJnhzSzQyFBJrNykchLFpkHWn+CCEJUD6UYmlqt80LzY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=JCTZ/IsK; arc=none smtp.client-ip=198.175.65.20 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1708008635; x=1739544635; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=2UTMt4kij+AbeHSuCqQx7s5uiRsL4iwwHL/UJl/dr60=; b=JCTZ/IsKvKi+wN3+DTz3Rgijnbh+AP+wbcDsRhjfFMYc1rx3gGSJ0sTr Wm8EX4kBL9D7pZWXIc5aftC27yPL8kyQzbKV1jf9psvCtLWjV2ZjwRA8L 385fiTGlAop+irGkxfdA9Y82tUXfZHGhBQk9OBdzU/AuHfOQite5Gn1jz 87rWBS3gfszbMOkHHnuEXHhDOltZty+K29NyEw8dCRfI6hhndlplrmaik cyjIZU5KT7nYMtoascjZrIuSJx4SMf9VlZc0nYB920RoGSdqMp1RilGbL g3gb2+kEOKAUwuA/pPPJnWwVJrOQVznPU7WTGz4CV+pjIGaDR2zVD6FUj g==; X-IronPort-AV: E=McAfee;i="6600,9927,10984"; a="1968850" X-IronPort-AV: E=Sophos;i="6.06,161,1705392000"; d="scan'208";a="1968850" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orvoesa112.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Feb 2024 06:50:34 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10984"; a="935676901" X-IronPort-AV: E=Sophos;i="6.06,161,1705392000"; d="scan'208";a="935676901" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 15 Feb 2024 06:50:32 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id 706C620B; Thu, 15 Feb 2024 16:50:31 +0200 (EET) From: Andy Shevchenko To: Greg Kroah-Hartman , Andy Shevchenko , linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org Cc: Jiri Slaby Subject: [PATCH v2 1/1] serial: 8250_of: Drop quirk fot NPCM from 8250_port Date: Thu, 15 Feb 2024 16:50:08 +0200 Message-ID: <20240215145029.581389-1-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.43.0.rc1.1.gbec44491f096 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790983968084991234 X-GMAIL-MSGID: 1790986919419465284 We are not supposed to spread quirks in 8250_port module especially when we have a separate driver for the hardware in question. Move quirk from generic module to the driver that uses it. Signed-off-by: Andy Shevchenko Reviewed-by: Ilpo Järvinen --- v2: added missing bits.h, reworked error handling in a switch-case drivers/tty/serial/8250/8250_of.c | 44 +++++++++++++++++++++++++++-- drivers/tty/serial/8250/8250_port.c | 24 ---------------- 2 files changed, 42 insertions(+), 26 deletions(-) diff --git a/drivers/tty/serial/8250/8250_of.c b/drivers/tty/serial/8250/8250_of.c index 34f17a9785e7..9dcc17e33269 100644 --- a/drivers/tty/serial/8250/8250_of.c +++ b/drivers/tty/serial/8250/8250_of.c @@ -4,7 +4,10 @@ * * Copyright (C) 2006 Arnd Bergmann , IBM Corp. */ + +#include #include +#include #include #include #include @@ -25,6 +28,36 @@ struct of_serial_info { int line; }; +/* Nuvoton NPCM timeout register */ +#define UART_NPCM_TOR 7 +#define UART_NPCM_TOIE BIT(7) /* Timeout Interrupt Enable */ + +static int npcm_startup(struct uart_port *port) +{ + /* + * Nuvoton calls the scratch register 'UART_TOR' (timeout + * register). Enable it, and set TIOC (timeout interrupt + * comparator) to be 0x20 for correct operation. + */ + serial_port_out(port, UART_NPCM_TOR, UART_NPCM_TOIE | 0x20); + + return serial8250_do_startup(port); +} + +/* Nuvoton NPCM UARTs have a custom divisor calculation */ +static unsigned int npcm_get_divisor(struct uart_port *port, unsigned int baud, + unsigned int *frac) +{ + return DIV_ROUND_CLOSEST(port->uartclk, 16 * baud + 2) - 2; +} + +static int npcm_setup(struct uart_port *port) +{ + port->get_divisor = npcm_get_divisor; + port->startup = npcm_startup; + return 0; +} + /* * Fill a struct uart_port for a given device node */ @@ -164,10 +197,17 @@ static int of_platform_serial_setup(struct platform_device *ofdev, switch (type) { case PORT_RT2880: ret = rt288x_setup(port); - if (ret) - goto err_pmruntime; + break; + case PORT_NPCM: + ret = npcm_setup(port); + break; + default: + /* Nothing to do */ + ret = 0; break; } + if (ret) + goto err_pmruntime; if (IS_REACHABLE(CONFIG_SERIAL_8250_FSL) && (of_device_is_compatible(np, "fsl,ns16550") || diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c index 175a0b07589c..2699ccf5bfce 100644 --- a/drivers/tty/serial/8250/8250_port.c +++ b/drivers/tty/serial/8250/8250_port.c @@ -38,10 +38,6 @@ #include "8250.h" -/* Nuvoton NPCM timeout register */ -#define UART_NPCM_TOR 7 -#define UART_NPCM_TOIE BIT(7) /* Timeout Interrupt Enable */ - /* * Debugging. */ @@ -2206,15 +2202,6 @@ int serial8250_do_startup(struct uart_port *port) UART_DA830_PWREMU_MGMT_FREE); } - if (port->type == PORT_NPCM) { - /* - * Nuvoton calls the scratch register 'UART_TOR' (timeout - * register). Enable it, and set TIOC (timeout interrupt - * comparator) to be 0x20 for correct operation. - */ - serial_port_out(port, UART_NPCM_TOR, UART_NPCM_TOIE | 0x20); - } - #ifdef CONFIG_SERIAL_8250_RSA /* * If this is an RSA port, see if we can kick it up to the @@ -2508,15 +2495,6 @@ static void serial8250_shutdown(struct uart_port *port) serial8250_do_shutdown(port); } -/* Nuvoton NPCM UARTs have a custom divisor calculation */ -static unsigned int npcm_get_divisor(struct uart_8250_port *up, - unsigned int baud) -{ - struct uart_port *port = &up->port; - - return DIV_ROUND_CLOSEST(port->uartclk, 16 * baud + 2) - 2; -} - static unsigned int serial8250_do_get_divisor(struct uart_port *port, unsigned int baud, unsigned int *frac) @@ -2561,8 +2539,6 @@ static unsigned int serial8250_do_get_divisor(struct uart_port *port, quot = 0x8001; else if (magic_multiplier && baud >= port->uartclk / 12) quot = 0x8002; - else if (up->port.type == PORT_NPCM) - quot = npcm_get_divisor(up, baud); else quot = uart_get_divisor(port, baud);