From patchwork Fri Aug 6 11:17:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 493144 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 291F3C4320A for ; Fri, 6 Aug 2021 11:24:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 08A7F60EE8 for ; Fri, 6 Aug 2021 11:24:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242774AbhHFLYY (ORCPT ); Fri, 6 Aug 2021 07:24:24 -0400 Received: from mga11.intel.com ([192.55.52.93]:4920 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242343AbhHFLYY (ORCPT ); Fri, 6 Aug 2021 07:24:24 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10067"; a="211249181" X-IronPort-AV: E=Sophos;i="5.84,300,1620716400"; d="scan'208";a="211249181" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Aug 2021 04:24:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.84,300,1620716400"; d="scan'208";a="523425420" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga002.fm.intel.com with ESMTP; 06 Aug 2021 04:24:05 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 5B6DB11C; Fri, 6 Aug 2021 14:17:39 +0300 (EEST) From: Andy Shevchenko To: Hans de Goede , Maximilian Luz , Greg Kroah-Hartman , Lee Jones , Andy Shevchenko , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org Cc: Mark Gross , Rob Herring , Jiri Slaby Subject: [PATCH v3 1/2] serdev: Split and export serdev_acpi_get_uart_resource() Date: Fri, 6 Aug 2021 14:17:35 +0300 Message-Id: <20210806111736.66591-1-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org The same as for I²C Serial Bus resource split and export serdev_acpi_get_uart_resource(). We have already a few users one of which is converted here. Rationale of this is to consolidate parsing UART Serial Bus resource in one place as it's done, e.g., for I²C Serial Bus. Signed-off-by: Andy Shevchenko Reviewed-by: Hans de Goede Acked-by: Hans de Goede --- v3: amended kernel doc to have RETURN section (Jiri) drivers/tty/serdev/core.c | 36 +++++++++++++++++++++++++++++------- include/linux/serdev.h | 14 ++++++++++++++ 2 files changed, 43 insertions(+), 7 deletions(-) diff --git a/drivers/tty/serdev/core.c b/drivers/tty/serdev/core.c index 92498961fd92..f1324fe99378 100644 --- a/drivers/tty/serdev/core.c +++ b/drivers/tty/serdev/core.c @@ -562,23 +562,45 @@ struct acpi_serdev_lookup { int index; }; +/** + * serdev_acpi_get_uart_resource - Gets UARTSerialBus resource if type matches + * @ares: ACPI resource + * @uart: Pointer to UARTSerialBus resource will be returned here + * + * Checks if the given ACPI resource is of type UARTSerialBus. + * In this case, returns a pointer to it to the caller. + * + * Return: True if resource type is of UARTSerialBus, otherwise false. + */ +bool serdev_acpi_get_uart_resource(struct acpi_resource *ares, + struct acpi_resource_uart_serialbus **uart) +{ + struct acpi_resource_uart_serialbus *sb; + + if (ares->type != ACPI_RESOURCE_TYPE_SERIAL_BUS) + return false; + + sb = &ares->data.uart_serial_bus; + if (sb->type != ACPI_RESOURCE_SERIAL_TYPE_UART) + return false; + + *uart = sb; + return true; +} +EXPORT_SYMBOL_GPL(serdev_acpi_get_uart_resource); + static int acpi_serdev_parse_resource(struct acpi_resource *ares, void *data) { struct acpi_serdev_lookup *lookup = data; struct acpi_resource_uart_serialbus *sb; acpi_status status; - if (ares->type != ACPI_RESOURCE_TYPE_SERIAL_BUS) - return 1; - - if (ares->data.common_serial_bus.type != ACPI_RESOURCE_SERIAL_TYPE_UART) + if (!serdev_acpi_get_uart_resource(ares, &sb)) return 1; if (lookup->index != -1 && lookup->n++ != lookup->index) return 1; - sb = &ares->data.uart_serial_bus; - status = acpi_get_handle(lookup->device_handle, sb->resource_source.string_ptr, &lookup->controller_handle); @@ -586,7 +608,7 @@ static int acpi_serdev_parse_resource(struct acpi_resource *ares, void *data) return 1; /* - * NOTE: Ideally, we would also want to retreive other properties here, + * NOTE: Ideally, we would also want to retrieve other properties here, * once setting them before opening the device is supported by serdev. */ diff --git a/include/linux/serdev.h b/include/linux/serdev.h index 9f14f9c12ec4..3368c261ab62 100644 --- a/include/linux/serdev.h +++ b/include/linux/serdev.h @@ -327,4 +327,18 @@ static inline int serdev_tty_port_unregister(struct tty_port *port) } #endif /* CONFIG_SERIAL_DEV_CTRL_TTYPORT */ +struct acpi_resource; +struct acpi_resource_uart_serialbus; + +#ifdef CONFIG_ACPI +bool serdev_acpi_get_uart_resource(struct acpi_resource *ares, + struct acpi_resource_uart_serialbus **uart); +#else +static inline bool serdev_acpi_get_uart_resource(struct acpi_resource *ares, + struct acpi_resource_uart_serialbus **uart) +{ + return false; +} +#endif /* CONFIG_ACPI */ + #endif /*_LINUX_SERDEV_H */ From patchwork Fri Aug 6 11:17:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 493559 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B076EC432BE for ; Fri, 6 Aug 2021 11:24:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 918A860EE8 for ; Fri, 6 Aug 2021 11:24:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245467AbhHFLYZ (ORCPT ); Fri, 6 Aug 2021 07:24:25 -0400 Received: from mga11.intel.com ([192.55.52.93]:4920 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245463AbhHFLYZ (ORCPT ); Fri, 6 Aug 2021 07:24:25 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10067"; a="211249182" X-IronPort-AV: E=Sophos;i="5.84,300,1620716400"; d="scan'208";a="211249182" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Aug 2021 04:24:09 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.84,300,1620716400"; d="scan'208";a="669402149" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga006.fm.intel.com with ESMTP; 06 Aug 2021 04:24:06 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 8172A15E; Fri, 6 Aug 2021 14:17:40 +0300 (EEST) From: Andy Shevchenko To: Hans de Goede , Maximilian Luz , Greg Kroah-Hartman , Lee Jones , Andy Shevchenko , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org Cc: Mark Gross , Rob Herring , Jiri Slaby Subject: [PATCH v3 2/2] platform/surface: aggregator: Use serdev_acpi_get_uart_resource() helper Date: Fri, 6 Aug 2021 14:17:36 +0300 Message-Id: <20210806111736.66591-2-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210806111736.66591-1-andriy.shevchenko@linux.intel.com> References: <20210806111736.66591-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org serdev provides a generic helper to get UART Serial Bus resources. Use it instead of an open coded variant. Signed-off-by: Andy Shevchenko Reviewed-by: Maximilian Luz --- v3: no changes drivers/platform/surface/aggregator/core.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/drivers/platform/surface/aggregator/core.c b/drivers/platform/surface/aggregator/core.c index 279d9df19c01..c61bbeeec2df 100644 --- a/drivers/platform/surface/aggregator/core.c +++ b/drivers/platform/surface/aggregator/core.c @@ -301,20 +301,13 @@ static acpi_status ssam_serdev_setup_via_acpi_crs(struct acpi_resource *rsc, void *ctx) { struct serdev_device *serdev = ctx; - struct acpi_resource_common_serialbus *serial; struct acpi_resource_uart_serialbus *uart; bool flow_control; int status = 0; - if (rsc->type != ACPI_RESOURCE_TYPE_SERIAL_BUS) + if (!serdev_acpi_get_uart_resource(rsc, &uart)) return AE_OK; - serial = &rsc->data.common_serial_bus; - if (serial->type != ACPI_RESOURCE_SERIAL_TYPE_UART) - return AE_OK; - - uart = &rsc->data.uart_serial_bus; - /* Set up serdev device. */ serdev_device_set_baudrate(serdev, uart->default_baud_rate);