Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp910291pxf; Thu, 1 Apr 2021 17:48:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzC5BsdJOHEU59/lmyu5Y8ByjBZ6EVU4eLro9F1ht9u22ehbL7fREOTJJSo6ArECFGJ4bPa X-Received: by 2002:a5e:8e49:: with SMTP id r9mr8947474ioo.91.1617324503267; Thu, 01 Apr 2021 17:48:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617324503; cv=none; d=google.com; s=arc-20160816; b=Ui7brPt1w5sdY+sn4BTjyrt17Ff5wE7YUSH4+gx9LE+mTHxpjEBGD1VHlDJI409vD4 8MdkuTr6Eawa4kmFw7FGn9kMvv7+K3bgugZf8QOQySaxCrQw5gluSuObxyCtumyt+qzk mvqaaSQ8i9raYgOioJsonJPF0B1BP78YF+Jy4fjXrYSEcHLb2QZ+rUGbQooq1JwGyiko Gjm/OBvyx6/4AnzqXvxRgLCFbuGQJIs6RbXWZno8QRWkM78Wh1ybd5/dorxMQvuLUfzS Su5102qFUUgeoo0PfenZ1jtotFiyaIOJb4ojgJrJjNcH3i+5Tz3GyUciJrDF0vqAPFi4 hrRQ== 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:cc:to:from :dkim-signature; bh=dkNOm/h1qSphcHi2Oe/aIN2quBfOKYQTuInyf8XmA4o=; b=MXPcQRecmGqk1alJWpZp8bsts8jRwAY/sCABbSRDz45QEISpGDsdZtDMVM0+ZXG9T9 KL0pJQNWFsfH9j/zA36vtGFlhbLZvlc3Uv1969z+Fb1s/Bu4aQsuk/ur6f9mU+123XQb +mimjJ8AEUaZ3EPc/aeWTCynmFYRWcVAUzJYkSKGP9Xqbk4OtyPzUo9SKI/2/YonaQTA rWLyEDNO/O3LfD17tvtuvtb5oLXqDqy2xDSsSb3CtkJpieKdPXqRTk6mxrTMcbOBW0kX Ap9qdbvJlYfaiD17Mg2Vy2BPI1EPbxgt1Nbddbe0Q3t4dUuaoghMrU+/8z5RATiB8CVs ZKJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bewilderbeest.net header.s=thorn header.b="i1nIN/xH"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=bewilderbeest.net Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g25si6222405jar.93.2021.04.01.17.48.09; Thu, 01 Apr 2021 17:48:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@bewilderbeest.net header.s=thorn header.b="i1nIN/xH"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=bewilderbeest.net Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234065AbhDBArg (ORCPT + 99 others); Thu, 1 Apr 2021 20:47:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38284 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233974AbhDBAre (ORCPT ); Thu, 1 Apr 2021 20:47:34 -0400 Received: from thorn.bewilderbeest.net (thorn.bewilderbeest.net [IPv6:2605:2700:0:5::4713:9cab]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 602EBC0613E6; Thu, 1 Apr 2021 17:47:32 -0700 (PDT) Received: from hatter.bewilderbeest.net (unknown [IPv6:2600:6c44:7f:ba20::7c6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: zev) by thorn.bewilderbeest.net (Postfix) with ESMTPSA id B6F3B671; Thu, 1 Apr 2021 17:47:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bewilderbeest.net; s=thorn; t=1617324452; bh=dkNOm/h1qSphcHi2Oe/aIN2quBfOKYQTuInyf8XmA4o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=i1nIN/xH2+t6MgkBClw9veB0szgRwXne3kNEL/Ponb+rVphEwO3xCLvDZQDejow1r IABoeslNa6AeKju7X+5/cZI06EGlmHcJEKivjwe7BMu8qDnNV3siNHo6Tmsre76l/X 6f/GNhSuEjNa7W5PkbjPyoaZrpWiVa0cjCrPKRhY= From: Zev Weiss To: Joel Stanley Cc: openbmc@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org, linux-aspeed@lists.ozlabs.org, linux-kernel@vger.kernel.org, Andrew Jeffery , Zev Weiss , Greg Kroah-Hartman , Jiri Slaby , linux-serial@vger.kernel.org Subject: [PATCH v3 2/4] drivers/tty/serial/8250: refactor sirq and lpc address setting code Date: Thu, 1 Apr 2021 19:47:14 -0500 Message-Id: <20210402004716.15961-3-zev@bewilderbeest.net> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210402004716.15961-1-zev@bewilderbeest.net> References: <20210402004716.15961-1-zev@bewilderbeest.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This splits dedicated aspeed_vuart_set_{sirq,lpc_address}() functions out of the sysfs store functions in preparation for adding DT properties that will be poking the same registers. While we're at it, these functions now provide some basic bounds-checking on their arguments. Signed-off-by: Zev Weiss --- drivers/tty/serial/8250/8250_aspeed_vuart.c | 51 ++++++++++++++------- 1 file changed, 35 insertions(+), 16 deletions(-) diff --git a/drivers/tty/serial/8250/8250_aspeed_vuart.c b/drivers/tty/serial/8250/8250_aspeed_vuart.c index c33e02cbde93..8433f8dbb186 100644 --- a/drivers/tty/serial/8250/8250_aspeed_vuart.c +++ b/drivers/tty/serial/8250/8250_aspeed_vuart.c @@ -72,22 +72,31 @@ static ssize_t lpc_address_show(struct device *dev, return snprintf(buf, PAGE_SIZE - 1, "0x%x\n", addr); } +static int aspeed_vuart_set_lpc_address(struct aspeed_vuart *vuart, u32 addr) +{ + if (addr > U16_MAX) + return -EINVAL; + + writeb(addr >> 8, vuart->regs + ASPEED_VUART_ADDRH); + writeb(addr >> 0, vuart->regs + ASPEED_VUART_ADDRL); + + return 0; +} + static ssize_t lpc_address_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct aspeed_vuart *vuart = dev_get_drvdata(dev); - unsigned long val; + u32 val; int err; - err = kstrtoul(buf, 0, &val); + err = kstrtou32(buf, 0, &val); if (err) return err; - writeb(val >> 8, vuart->regs + ASPEED_VUART_ADDRH); - writeb(val >> 0, vuart->regs + ASPEED_VUART_ADDRL); - - return count; + err = aspeed_vuart_set_lpc_address(vuart, val); + return err ? : count; } static DEVICE_ATTR_RW(lpc_address); @@ -105,27 +114,37 @@ static ssize_t sirq_show(struct device *dev, return snprintf(buf, PAGE_SIZE - 1, "%u\n", reg); } +static int aspeed_vuart_set_sirq(struct aspeed_vuart *vuart, u32 sirq) +{ + u8 reg; + + if (sirq > (ASPEED_VUART_GCRB_HOST_SIRQ_MASK >> ASPEED_VUART_GCRB_HOST_SIRQ_SHIFT)) + return -EINVAL; + + sirq <<= ASPEED_VUART_GCRB_HOST_SIRQ_SHIFT; + sirq &= ASPEED_VUART_GCRB_HOST_SIRQ_MASK; + + reg = readb(vuart->regs + ASPEED_VUART_GCRB); + reg &= ~ASPEED_VUART_GCRB_HOST_SIRQ_MASK; + reg |= sirq; + writeb(reg, vuart->regs + ASPEED_VUART_GCRB); + + return 0; +} + static ssize_t sirq_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct aspeed_vuart *vuart = dev_get_drvdata(dev); unsigned long val; int err; - u8 reg; err = kstrtoul(buf, 0, &val); if (err) return err; - val <<= ASPEED_VUART_GCRB_HOST_SIRQ_SHIFT; - val &= ASPEED_VUART_GCRB_HOST_SIRQ_MASK; - - reg = readb(vuart->regs + ASPEED_VUART_GCRB); - reg &= ~ASPEED_VUART_GCRB_HOST_SIRQ_MASK; - reg |= val; - writeb(reg, vuart->regs + ASPEED_VUART_GCRB); - - return count; + err = aspeed_vuart_set_sirq(vuart, val); + return err ? : count; } static DEVICE_ATTR_RW(sirq); -- 2.31.1