Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp859450rwe; Wed, 31 Aug 2022 12:19:31 -0700 (PDT) X-Google-Smtp-Source: AA6agR4aFL6EUmaO6f1akOEqzsegOAvWluJMUYjMZiMmbWKO6+Qu/GCJu3qIx+QKr5yC0uCT37gM X-Received: by 2002:a17:902:9b85:b0:16e:cc02:b9b2 with SMTP id y5-20020a1709029b8500b0016ecc02b9b2mr27275483plp.74.1661973571332; Wed, 31 Aug 2022 12:19:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661973571; cv=none; d=google.com; s=arc-20160816; b=p+ZZ24nufXq696Bb49NOPbQxPmnZIc2dKwNYlk0HfvoVZjkbVGaSFbL/jKDTyXGN26 qvR8VW6aCrErkoYmc8jSoX3g8pK0QdCOt1KsgFwXkwJ4YJDL4bpJC/DzBRKZXt9J0ZFU 5OsaHyyB6AXb74ImIxyubqvfC9mzDBVKVeiewnrsFrmqqfAIRU3zB5EMrQBXtTXWTjk2 aiNP7e5/1HpQNyDoCOOcj3GypY0vqwwMOsFugnCioISVBqtZncwtsLWaFubekH3s2KOP pQZms9dLwk8OzjmTSpT+IQs+iO/E6qvFodHXt29yCSyY4QV4Sr/McR4whEIwPIL+5M6D Y0uA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:subject:user-agent:mime-version:date:message-id :dkim-signature; bh=lFykXXuh414AMHOUrkjMCmREYuLQabBQPnrg6lAfPPY=; b=zijF0UfPUge5yf4bYJyLbJecASn4+enPyXbuojwGOjUGBrqpNm1RvKDmYJOLDX+F+P dLxQ0drSzYAzV8g4E0Jp0zn146e3RM/jKddmEw5lL2aPZaMUGSNj5K6Fd+XNUEkrI3FE MNA7bqv7e0jyAot8EkvHDWutF65tXeaMU5DVoEAryKsYvep7yGL4SgU/7FlBI70rE0gM lV5g1nAg/de7iPgPC3tFJuVrId6Nn/xIiuTh+wE8ejqP6ZarZta9+JKO0ibIaGYc8SCP OL9fJhSjIONYerv1lt7I1rp4ZIa9vDzSogjD9xfCZFh4sVeHWhV0WFl9xs69OW8fvQ+H lZvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@tronnes.org header.s=ds202112 header.b=ZZ198Xf6; 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=fail (p=NONE sp=NONE dis=NONE) header.from=tronnes.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bk8-20020a056a02028800b00429e0a469c9si6020172pgb.378.2022.08.31.12.19.19; Wed, 31 Aug 2022 12:19:31 -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=fail header.i=@tronnes.org header.s=ds202112 header.b=ZZ198Xf6; 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=fail (p=NONE sp=NONE dis=NONE) header.from=tronnes.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230377AbiHaTPB (ORCPT + 99 others); Wed, 31 Aug 2022 15:15:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41636 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231768AbiHaTO4 (ORCPT ); Wed, 31 Aug 2022 15:14:56 -0400 Received: from smtp.domeneshop.no (smtp.domeneshop.no [IPv6:2a01:5b40:0:3005::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA77B5F6D for ; Wed, 31 Aug 2022 12:14:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tronnes.org ; s=ds202112; h=Content-Transfer-Encoding:Content-Type:In-Reply-To:From: References:Cc:To:Subject:MIME-Version:Date:Message-ID:Sender:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=lFykXXuh414AMHOUrkjMCmREYuLQabBQPnrg6lAfPPY=; b=ZZ198Xf6PPUp/l53rhljFuGMcF 4zuRseMWeZpoj311RIFnjrUYtADjn9wuJNnEsMO5CjZC+xEdH2c5qjeG0ILG3eq0DkS+/UAuBjtmA lj9MawJD7bAGX1645naLEYPOhTdWjb1DKDqwDt5sCid+4EKbwJJ+m1nntHZqZTCOwtH2m0Y9w0pvq ypgdce4iD49nSDTQOHr/OQAfe1DigWSkskMg6tndHXcqQjah9nFLMqXz3YF7rBpOLW1ZK9v7rG2Lt fwCHewKIgkfbPSZuTdFO+kk9VvsODXV4OOvjxUHa5qpzXfN6R8L2vlOWdmejD3IUudqW/Bg3YIvS9 NvG7WR9A==; Received: from [2a01:799:961:d200:cca0:57ac:c55d:a485] (port=57178) by smtp.domeneshop.no with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oTTAj-0002O5-TA; Wed, 31 Aug 2022 21:14:45 +0200 Message-ID: Date: Wed, 31 Aug 2022 21:14:36 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.13.0 Subject: Re: [PATCH v2 18/41] drm/connector: Add a function to lookup a TV mode by its name To: Maxime Ripard , Maxime Ripard , Ben Skeggs , David Airlie , Chen-Yu Tsai , Thomas Zimmermann , Jani Nikula , Lyude Paul , Philipp Zabel , Maarten Lankhorst , Rodrigo Vivi , Tvrtko Ursulin , Jernej Skrabec , Samuel Holland , Karol Herbst , Emma Anholt , Daniel Vetter , Joonas Lahtinen Cc: Hans de Goede , linux-arm-kernel@lists.infradead.org, Phil Elwell , intel-gfx@lists.freedesktop.org, Dave Stevenson , dri-devel@lists.freedesktop.org, Dom Cobley , linux-kernel@vger.kernel.org, nouveau@lists.freedesktop.org, linux-sunxi@lists.linux.dev, Mateusz Kwiatkowski , Geert Uytterhoeven , =?UTF-8?Q?Noralf_Tr=c3=b8nnes?= References: <20220728-rpi-analog-tv-properties-v2-0-459522d653a7@cerno.tech> <20220728-rpi-analog-tv-properties-v2-18-459522d653a7@cerno.tech> From: =?UTF-8?Q?Noralf_Tr=c3=b8nnes?= In-Reply-To: <20220728-rpi-analog-tv-properties-v2-18-459522d653a7@cerno.tech> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_PASS,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 Den 29.08.2022 15.11, skrev Maxime Ripard: > As part of the command line parsing rework coming in the next patches, > > we'll need to lookup drm_connector_tv_mode values by their name, already > > defined in drm_tv_mode_enum_list. > > > > In order to avoid any code duplication, let's do a function that will > > perform a lookup of a TV mode name and return its value. > > > > Signed-off-by: Maxime Ripard > > > > diff --git a/drivers/gpu/drm/drm_connector.c b/drivers/gpu/drm/drm_connector.c > > index b1fcacd150e8..0fe01a1c20ad 100644 > > --- a/drivers/gpu/drm/drm_connector.c > > +++ b/drivers/gpu/drm/drm_connector.c > > @@ -1003,6 +1003,30 @@ static const struct drm_prop_enum_list drm_tv_mode_enum_list[] = { > > }; > > DRM_ENUM_NAME_FN(drm_get_tv_mode_name, drm_tv_mode_enum_list) > > > > +/** > > + * drm_get_tv_mode_from_name - Translates a TV mode name into its enum value > > + * @name: TV Mode name we want to convert > > + * @len: Length of @name > > + * > > + * Translates @name into an enum drm_connector_tv_mode. > > + * > > + * Returns: the enum value on success, a negative errno otherwise. > > + */ > > +int drm_get_tv_mode_from_name(const char *name, size_t len) > > +{ > > + unsigned int i; > > + > > + for (i = 0; i < ARRAY_SIZE(drm_tv_mode_enum_list); i++) { > > + const struct drm_prop_enum_list *item = &drm_tv_mode_enum_list[i]; > > + > > + if (strlen(item->name) == len && !strncmp(item->name, name, len)) > > + return item->type; > > + } > > + > > + return -EINVAL; > > +} > > +EXPORT_SYMBOL(drm_get_tv_mode_from_name) Missing semicolon. Noralf. > > + > > static const struct drm_prop_enum_list drm_tv_select_enum_list[] = { > > { DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */ > > { DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */ > > diff --git a/include/drm/drm_connector.h b/include/drm/drm_connector.h > > index bb39d2bb806e..49d261977d4e 100644 > > --- a/include/drm/drm_connector.h > > +++ b/include/drm/drm_connector.h > > @@ -1943,6 +1943,8 @@ const char *drm_get_dp_subconnector_name(int val); > > const char *drm_get_content_protection_name(int val); > > const char *drm_get_hdcp_content_type_name(int val); > > > > +int drm_get_tv_mode_from_name(const char *name, size_t len); > > + > > int drm_mode_create_dvi_i_properties(struct drm_device *dev); > > void drm_connector_attach_dp_subconnector_property(struct drm_connector *connector); > > > > >