Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp3988602iog; Tue, 28 Jun 2022 06:57:20 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sqvfb7WhgOHBvyl50k2dn8L5mAx0vH5kShReH9ZAMk0twiGWhnD5dMvg49RmtnEQeHoxlw X-Received: by 2002:a17:902:e84f:b0:16b:8a74:d572 with SMTP id t15-20020a170902e84f00b0016b8a74d572mr5158410plg.146.1656424639947; Tue, 28 Jun 2022 06:57:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656424639; cv=none; d=google.com; s=arc-20160816; b=cBLEexySHiCuI93FgdADODX6iG6BWq7FohAIg2zYwqxFTessESjipY8nhrzqDrFfHg hMOQypajIP/ePPKXty7wdSLz2RaINmkZcofiGWQ7+D4nwQRS9xLV59dg/kOAsO11yr/q iujdSL3BPWUAEFecaykParB+OeacFHsDOVsmNJs9nIdplSIAlcZIEXS1vw5Rcy3zh0kJ CiW7orkzGpl6p/qSh+W+VgV1sTkJmY8IUmQnuBxz71ROP0S7EcZQYnlm185DFA34HUz1 jfxwsa8YmRAvsyNEhv3tg5j2m/cTXxw+uY1zlxUFb7cDvqvw9GnELSm/LIU0QD8xfB8r 8V/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=vERE+Cne4avUyomVtCNTTj5GZhTVFU1+c2zn8Xu1iAQ=; b=ul+0WeRDrygASV4NazOxsE6HQzisPsF5PVx+XUnhXJmB/9SRGdx//oDwiVH6kqBTf9 W28B+nalwEbiWmY9nXdY/aJ+1HtUmxfnHoVm36q2YH++yE2hn3szwxC5pFrDBS9lG+lK qjBgllMSuYqR41zfu3NCZ5xzMPzHnTF3rq6JHwqtMMlPDiATvViKeVl/5jybS+BEgTi7 taPmUfLlUWHOtf0EVFTZX0zgYP6OOVv59MPzGBcVmIXvPaTHGKD0Ok9g1e3PEOgnvqJu QftT4m6pRvcr7/mo7axJfm3COyUVpUqtQq70mAhEmY6wOWMvs5P5EO8dKo3AwQC2J3ld 75Lw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=aHBY6B36; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k6-20020a6568c6000000b0040caf6c326csi18971814pgt.132.2022.06.28.06.57.07; Tue, 28 Jun 2022 06:57:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=aHBY6B36; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346825AbiF1NnB (ORCPT + 99 others); Tue, 28 Jun 2022 09:43:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346781AbiF1Nm4 (ORCPT ); Tue, 28 Jun 2022 09:42:56 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CBFE32AC43; Tue, 28 Jun 2022 06:42:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1656423774; x=1687959774; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=Y0QXjOizetyX3Soq97gP2p3KCAQsLgAHEtiVVB0k/s0=; b=aHBY6B36K2yO8Rn/rM4a8BR8R8FOOVTTatDd5dggoa7T/Fz5ed9dAhHA Ban6o7t/sVgbYooQ8eGtcnOMhZUnyubnmEVGw7tuM1swgVI+1Ucj/R/Zw Cgl9spsglik8re52TD5bCqa5zm9rrz7bNb3oEP4OSOJ79t6OBa4XCCHwW zNlUqfwrQgeCovo4jZy7ztLT26F2OIVAiOlmgWj/mfu6jjVhFWRk8HR10 FuNjEj3yLN+hF2Gy6MBm+Un5v8zhkDNuUpkPSXBbCzFUNLQqluvG+1Ejs xUmkss+MGwgh/fDNcNSAPTx1YnjfEU3jKU/BWHSFNxuxOzhnZpoucGsQ+ A==; X-IronPort-AV: E=McAfee;i="6400,9594,10391"; a="281780646" X-IronPort-AV: E=Sophos;i="5.92,227,1650956400"; d="scan'208";a="281780646" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jun 2022 06:42:54 -0700 X-IronPort-AV: E=Sophos;i="5.92,227,1650956400"; d="scan'208";a="646918031" Received: from iannetti-mobl.ger.corp.intel.com (HELO ijarvine-MOBL2.ger.corp.intel.com) ([10.251.216.215]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jun 2022 06:42:52 -0700 From: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= To: linux-serial@vger.kernel.org, Greg KH , Jiri Slaby , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , Andy Shevchenko , linux-kernel@vger.kernel.org Subject: [PATCH 3/4] serial: 8250_dw: Move 16550 compatible & LCR checks to dw8250_verify_write() Date: Tue, 28 Jun 2022 16:42:33 +0300 Message-Id: <20220628134234.53771-4-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220628134234.53771-1-ilpo.jarvinen@linux.intel.com> References: <20220628134234.53771-1-ilpo.jarvinen@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_HI,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Rename dw8250_check_lcr() -> dw8250_verify_write() and add comment. Move LCR and 16550_compatible checks there. As offset is now passed and dw8250_verify_write() ensures it's UART_LCR, offset can use used instead of explicit UART_LCR. Signed-off-by: Ilpo Järvinen --- drivers/tty/serial/8250/8250_dw.c | 35 +++++++++++++++---------------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/drivers/tty/serial/8250/8250_dw.c b/drivers/tty/serial/8250/8250_dw.c index f18975b4d2c7..fc367d44f86d 100644 --- a/drivers/tty/serial/8250/8250_dw.c +++ b/drivers/tty/serial/8250/8250_dw.c @@ -87,14 +87,24 @@ static void dw8250_force_idle(struct uart_port *p) (void)p->serial_in(p, UART_RX); } -static void dw8250_check_lcr(struct uart_port *p, int value) +/* + * DW UART can be configured to indicate BUSY in USR (with + * UART_16550_COMPATIBLE=NO or version prior to introducing that option). + * If BUSY is set while writing to LCR register, the write is ignored and + * needs to be retries. + */ +static void dw8250_verify_write(struct uart_port *p, int offset, int value) { - void __iomem *reg_offset = p->membase + (UART_LCR << p->regshift); + void __iomem *reg_offset = p->membase + (offset << p->regshift); + struct dw8250_data *d = to_dw8250_data(p->private_data); int tries = 1000; + if ((offset != UART_LCR) || !d->uart_16550_compatible) + return; + /* Make sure LCR write wasn't ignored */ while (tries--) { - unsigned int lcr = p->serial_in(p, UART_LCR); + unsigned int lcr = p->serial_in(p, offset); if ((value & ~UART_LCR_SPAR) == (lcr & ~UART_LCR_SPAR)) return; @@ -145,12 +155,9 @@ static void dw8250_tx_wait_empty(struct uart_port *p) static void dw8250_serial_out(struct uart_port *p, int offset, int value) { - struct dw8250_data *d = to_dw8250_data(p->private_data); - writeb(value, p->membase + (offset << p->regshift)); - if (offset == UART_LCR && !d->uart_16550_compatible) - dw8250_check_lcr(p, value); + dw8250_verify_write(p, offset, value); } static void dw8250_serial_out38x(struct uart_port *p, int offset, int value) @@ -181,26 +188,20 @@ static unsigned int dw8250_serial_inq(struct uart_port *p, int offset) static void dw8250_serial_outq(struct uart_port *p, int offset, int value) { - struct dw8250_data *d = to_dw8250_data(p->private_data); - value &= 0xff; __raw_writeq(value, p->membase + (offset << p->regshift)); /* Read back to ensure register write ordering. */ __raw_readq(p->membase + (UART_LCR << p->regshift)); - if (offset == UART_LCR && !d->uart_16550_compatible) - dw8250_check_lcr(p, value); + dw8250_verify_write(p, offset, value); } #endif /* CONFIG_64BIT */ static void dw8250_serial_out32(struct uart_port *p, int offset, int value) { - struct dw8250_data *d = to_dw8250_data(p->private_data); - writel(value, p->membase + (offset << p->regshift)); - if (offset == UART_LCR && !d->uart_16550_compatible) - dw8250_check_lcr(p, value); + dw8250_verify_write(p, offset, value); } static unsigned int dw8250_serial_in32(struct uart_port *p, int offset) @@ -212,12 +213,10 @@ static unsigned int dw8250_serial_in32(struct uart_port *p, int offset) static void dw8250_serial_out32be(struct uart_port *p, int offset, int value) { - struct dw8250_data *d = to_dw8250_data(p->private_data); iowrite32be(value, p->membase + (offset << p->regshift)); - if (offset == UART_LCR && !d->uart_16550_compatible) - dw8250_check_lcr(p, value); + dw8250_verify_write(p, offset, value); } static unsigned int dw8250_serial_in32be(struct uart_port *p, int offset) -- 2.30.2