Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp6255647rwb; Wed, 18 Jan 2023 03:09:55 -0800 (PST) X-Google-Smtp-Source: AMrXdXv+2JWgax2v/w8a/HHJE+jQ7VgEZnNktZ1N9p58M6Ltd2ak8KIVe2tELiIycvkkX3dy+n8a X-Received: by 2002:aa7:9467:0:b0:58b:aaaa:82a9 with SMTP id t7-20020aa79467000000b0058baaaa82a9mr6423567pfq.25.1674040194916; Wed, 18 Jan 2023 03:09:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674040194; cv=none; d=google.com; s=arc-20160816; b=msVmkeptSsEefc9RUZQ8Avjs3ZeUFH54e5mnfn5id/7Io4k0/QKiV0/taTyU04IYVz KMrpG5dDHgFaXH9bfjQDMppm31BhQMgvKNQkwKIDJPO3gyVgKvLBwP5tGy56SZl/lvbQ nbl8w88kDJqXCpHiT+ZcbWrjr4R1q5TOsAUTA28Z7TNDXR1/qF1YDmd0UozBmZhJtDYW W7FNDHlDjo3n3qBeVZvbPfnvVNd4B+BP7eqsIyQsvSLBTIUOvPSII7EB6sX/WqLw5g9a Kr9Akgsl/xmyAW0AZ6EvZyNwnyWt6RVn60H4dvSuYGoTLrRYe9AOxEdXygfXG4sXY5bE N1aw== 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 :organization:references:cc:to:content-language:subject:reply-to :from:user-agent:mime-version:date:message-id:dkim-signature; bh=lrUX/Kg3NoRa31wbbje+S4lImexuDVGCZWRb0tomIAI=; b=QFbrG/VOwbnN8BfXyR3Z4jz0BVsDLoU1ZmeJ5kgLkzl243wO1LPGKzR1wTsC0oJruI dF6c1Dg+Un0WqccRu8kuDQuujBUnqWvGEcoIBUrCP+MpfQWsZRtOxLh1qI0sFXQnECEn lKCZ8BwO2LDEIjY1dTaIzBphFOC2mpDLAzELoFzv641swbhAY0CQz79hPEcJk/hV3B2c Hve0Qcbkp7wKGv4y5JCO+yzqR0rmCLGRwRyGDNSMs1tYxX0o14S6OodGrjZg7iZPgqiz 7/XOhbhOT8m+6VzoiXqPdtPMpmmFWmmfSUC7uJCKje3HdxcBgtPBEbK/wXSJ5r3HTnzv S7QA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WaxyMTsW; 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=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f15-20020a056a001acf00b0058286279c89si5535396pfv.309.2023.01.18.03.09.48; Wed, 18 Jan 2023 03:09:54 -0800 (PST) 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=@linaro.org header.s=google header.b=WaxyMTsW; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230003AbjARKna (ORCPT + 45 others); Wed, 18 Jan 2023 05:43:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230053AbjARKlT (ORCPT ); Wed, 18 Jan 2023 05:41:19 -0500 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7FB2C79E6 for ; Wed, 18 Jan 2023 01:45:31 -0800 (PST) Received: by mail-wm1-x331.google.com with SMTP id k16so3571978wms.2 for ; Wed, 18 Jan 2023 01:45:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:in-reply-to:organization:references:cc:to :content-language:subject:reply-to:from:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=lrUX/Kg3NoRa31wbbje+S4lImexuDVGCZWRb0tomIAI=; b=WaxyMTsW9kQE/WMVU5QzULSg1HN1MRAKgs7H+p7OxdWLUnVeFKFlLxyFECHcGSSI8c 7hDI5QRqG0YTCodSKm8TNbpLwPmrAfQls3J55zYi0PA+v/1rl6JprxkeeDo+Q+xImLTy ZNBkn8UZXqt/DpvunTAh7eIOC0ArdAPSotFC2xRbG5eTk9/4Sm/hS0vLzxYZK2LQynT6 V8L2VOq1Ao8oHChHiMv4IGvjY0OoOnJSh3iGhFpwIUQ7ZpkAibyjl6CR3YkXaBvlDp1H cZxEw27IbEvJHtHu6ukQAnoJHDy1evACP4xC5H8G2h9JU8lf7a1lNux2mqh15y3ueXFr Y0JQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:organization:references:cc:to :content-language:subject:reply-to:from:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=lrUX/Kg3NoRa31wbbje+S4lImexuDVGCZWRb0tomIAI=; b=lpMeaJoyu3DLwd5H2pYf3NbefwckuVw/V02LDy34bDEykVmUGrzjhCTL4w0BHQzdnf zBVhvMdjoaRTBBfkHgPyxUzjd7sWwdn5a227kMOmfG6oX5rLZR7OQN45hIgnvBy5Rs5v OO/ZCV/cL+1Fq+E6s8TZqoXfmy7xekzeOWwU9xpRVPxmV1scYSVImLpFQuLUrqb1O251 6pGI7lFv8YmnEKusjSQeknAY3deqFINyVdXkuXBpi78iSvHnu/GTFn6EruxlM+IpC1hP nFXVkc2lf93mlbMx07x6BL2FEHlkx4YDdUFPb2nm8WkM0t/EmUJODzWqa3BDDjQkG0GV QQVw== X-Gm-Message-State: AFqh2krU9sa5uLup//uyMkICANFpkwbP52MB+nAbg9SajLlrCH6uGWiX 0d2NmTgvxSH+6zzYCNDqpXL4iQ== X-Received: by 2002:a05:600c:3b07:b0:3d9:c6f5:c643 with SMTP id m7-20020a05600c3b0700b003d9c6f5c643mr6046833wms.29.1674035127968; Wed, 18 Jan 2023 01:45:27 -0800 (PST) Received: from ?IPV6:2a01:e0a:982:cbb0:37dc:5071:959c:93e4? ([2a01:e0a:982:cbb0:37dc:5071:959c:93e4]) by smtp.gmail.com with ESMTPSA id fm11-20020a05600c0c0b00b003c21ba7d7d6sm1392944wmb.44.2023.01.18.01.45.26 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 18 Jan 2023 01:45:27 -0800 (PST) Message-ID: Date: Wed, 18 Jan 2023 10:45:26 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.0 From: Neil Armstrong Reply-To: neil.armstrong@linaro.org Subject: Re: [RFC PATCH v3 1/3] drm/mipi-dsi: Fix byte order of 16-bit DCS set/get brightness Content-Language: en-US To: Richard Acayan , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Thierry Reding , Sam Ravnborg , Emil Velikov , Vinay Simha BN , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Cc: Daniel Mentz , Caleb Connolly References: <20230116224909.23884-1-mailingradian@gmail.com> <20230116224909.23884-2-mailingradian@gmail.com> Organization: Linaro Developer Services In-Reply-To: <20230116224909.23884-2-mailingradian@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS 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 On 16/01/2023 23:49, Richard Acayan wrote: > From: Daniel Mentz > > The MIPI DCS specification demands that brightness values are sent in > big endian byte order. It also states that one parameter (i.e. one byte) > shall be sent/received for 8 bit wide values, and two parameters shall > be used for values that are between 9 and 16 bits wide. > > Add new functions to properly handle 16-bit brightness in big endian, > since the two 8- and 16-bit cases are distinct from each other. > > Fixes: 1a9d759331b8 ("drm/dsi: Implement DCS set/get display brightness") > Signed-off-by: Daniel Mentz > Link: https://android.googlesource.com/kernel/msm/+/754affd62d0ee268c686c53169b1dbb7deac8550 > [richard: fix 16-bit brightness_get] > [richard: use separate functions instead of switch/case] > [richard: split into 16-bit component] > Signed-off-by: Richard Acayan > Tested-by: Caleb Connolly > --- > drivers/gpu/drm/drm_mipi_dsi.c | 52 ++++++++++++++++++++++++++++++++++ > include/drm/drm_mipi_dsi.h | 4 +++ > 2 files changed, 56 insertions(+) > > diff --git a/drivers/gpu/drm/drm_mipi_dsi.c b/drivers/gpu/drm/drm_mipi_dsi.c > index 497ef4b6a90a..4bc15fbd009d 100644 > --- a/drivers/gpu/drm/drm_mipi_dsi.c > +++ b/drivers/gpu/drm/drm_mipi_dsi.c > @@ -1224,6 +1224,58 @@ int mipi_dsi_dcs_get_display_brightness(struct mipi_dsi_device *dsi, > } > EXPORT_SYMBOL(mipi_dsi_dcs_get_display_brightness); > > +/** > + * mipi_dsi_dcs_set_display_brightness_large() - sets the 16-bit brightness value > + * of the display > + * @dsi: DSI peripheral device > + * @brightness: brightness value > + * > + * Return: 0 on success or a negative error code on failure. > + */ > +int mipi_dsi_dcs_set_display_brightness_large(struct mipi_dsi_device *dsi, > + u16 brightness) > +{ > + u8 payload[2] = { brightness >> 8, brightness & 0xff }; > + ssize_t err; > + > + err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_DISPLAY_BRIGHTNESS, > + payload, sizeof(payload)); > + if (err < 0) > + return err; > + > + return 0; > +} > +EXPORT_SYMBOL(mipi_dsi_dcs_set_display_brightness_large); > + > +/** > + * mipi_dsi_dcs_get_display_brightness_large() - gets the current 16-bit > + * brightness value of the display > + * @dsi: DSI peripheral device > + * @brightness: brightness value > + * > + * Return: 0 on success or a negative error code on failure. > + */ > +int mipi_dsi_dcs_get_display_brightness_large(struct mipi_dsi_device *dsi, > + u16 *brightness) > +{ > + u8 brightness_be[2]; > + ssize_t err; > + > + err = mipi_dsi_dcs_read(dsi, MIPI_DCS_GET_DISPLAY_BRIGHTNESS, > + brightness_be, sizeof(brightness_be)); > + if (err <= 0) { > + if (err == 0) > + err = -ENODATA; > + > + return err; > + } > + > + *brightness = (brightness_be[0] << 8) | brightness_be[1]; > + > + return 0; > +} > +EXPORT_SYMBOL(mipi_dsi_dcs_get_display_brightness_large); > + > static int mipi_dsi_drv_probe(struct device *dev) > { > struct mipi_dsi_driver *drv = to_mipi_dsi_driver(dev->driver); > diff --git a/include/drm/drm_mipi_dsi.h b/include/drm/drm_mipi_dsi.h > index 4f503d99f668..16f30975b22b 100644 > --- a/include/drm/drm_mipi_dsi.h > +++ b/include/drm/drm_mipi_dsi.h > @@ -296,6 +296,10 @@ int mipi_dsi_dcs_set_display_brightness(struct mipi_dsi_device *dsi, > u16 brightness); > int mipi_dsi_dcs_get_display_brightness(struct mipi_dsi_device *dsi, > u16 *brightness); > +int mipi_dsi_dcs_set_display_brightness_large(struct mipi_dsi_device *dsi, > + u16 brightness); > +int mipi_dsi_dcs_get_display_brightness_large(struct mipi_dsi_device *dsi, > + u16 *brightness); > > /** > * mipi_dsi_generic_write_seq - transmit data using a generic write packet Reviewed-by: Neil Armstrong