Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp3913057pxb; Mon, 4 Oct 2021 12:28:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxL5fOTuCRWqbyNTtIb4ch0ZI9hRYmaJ5NDE8QUVi0NQzNYY4gkJ6Ewpnk9ApaN2WeCCF+3 X-Received: by 2002:a17:90b:1102:: with SMTP id gi2mr31973299pjb.43.1633375731094; Mon, 04 Oct 2021 12:28:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633375731; cv=none; d=google.com; s=arc-20160816; b=NIHndHbk+boMcw+Y7tkeWggZVm5FBy+IkXfNDoWUsMaKbrRKtRxRB+h/a7TVr++C7B +cAtDydEM9g7I6xJOYx9JKN7wzObY/PTOpIHcmn1uB6An28btxCzcYkAgfcjjOz3WGHL 7ExuIgfoUHdGlbVuUIxkUvu2d2kt5jXuLkUAABs5xI68GVW7MAqLxp8twaNJ76lDhHeN zP6/9ST0Ct3miTI8qek5Voz+oOKDkZYgtl8Ea7iccp94ySryN+Gh2WJ8NecTk9LVJahD mFBK3R2OEpdC4rbQHkcRFD0i1sx15qwDCpXytl4egl4rTjm67Ow9AFe6t+4NZQvnr7vq +15Q== 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; bh=4h92EE9CtbHzJHFOzenx0i0HT6P7Jb2LTNbWCIDn7No=; b=op2KyqI82q1GLKwoioejTVanKt7d8Hf+Avbmmgn6IPdLZMFi3IO6sB3NLtAOorILcb fGgi7xIUVe1wleAqfskrXMw7BGtrXB9qzdF8vRldBhRJ9XHJNMy7Kbfl9zRUB7liaW4i STVxRp/W0mTdGy2RnGAjYB6A0Ckj1HZ+H1vRfJaA5BjO7pIuZehtRqW3Onk6H8dNGI1t de7bCPRaAax2L+q05OJ7DAb6XXG5Yn8JumctFIe1clCNqgi40uZZg1j+mlwTb9U9g+sI rqx/ycHy03YHqNBMXxHwPDN1D2/of8aFcRmHqxu/XRpCg1/kjVtP+u27p1FCWhWAaHZM LRNg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x7si17196922pgr.92.2021.10.04.12.28.38; Mon, 04 Oct 2021 12:28:51 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238907AbhJDT3h (ORCPT + 99 others); Mon, 4 Oct 2021 15:29:37 -0400 Received: from relay02.th.seeweb.it ([5.144.164.163]:54859 "EHLO relay02.th.seeweb.it" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238897AbhJDT3g (ORCPT ); Mon, 4 Oct 2021 15:29:36 -0400 Received: from Marijn-Arch-PC.localdomain (94-209-165-62.cable.dynamic.v4.ziggo.nl [94.209.165.62]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by m-r1.th.seeweb.it (Postfix) with ESMTPSA id D1AE81F68F; Mon, 4 Oct 2021 21:27:44 +0200 (CEST) From: Marijn Suijten To: phone-devel@vger.kernel.org, Andy Gross , Bjorn Andersson , Lee Jones , Daniel Thompson , Jingoo Han Cc: ~postmarketos/upstreaming@lists.sr.ht, AngeloGioacchino Del Regno , Konrad Dybcio , Martin Botka , Jami Kettunen , Pavel Dubrova , Marijn Suijten , Kiran Gunda , Courtney Cavin , Bryan Wu , linux-arm-msm@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 02/10] backlight: qcom-wled: Use cpu_to_le16 macro to perform conversion Date: Mon, 4 Oct 2021 21:27:33 +0200 Message-Id: <20211004192741.621870-3-marijn.suijten@somainline.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211004192741.621870-1-marijn.suijten@somainline.org> References: <20211004192741.621870-1-marijn.suijten@somainline.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The kernel already provides appropriate primitives to perform endianness conversion which should be used in favour of manual bit-wrangling. Signed-off-by: Marijn Suijten Reviewed-by: AngeloGioacchino Del Regno --- drivers/video/backlight/qcom-wled.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/drivers/video/backlight/qcom-wled.c b/drivers/video/backlight/qcom-wled.c index 6af808af2328..9927ed98944a 100644 --- a/drivers/video/backlight/qcom-wled.c +++ b/drivers/video/backlight/qcom-wled.c @@ -231,14 +231,14 @@ struct wled { static int wled3_set_brightness(struct wled *wled, u16 brightness) { int rc, i; - u8 v[2]; + u16 v; - v[0] = brightness & 0xff; - v[1] = (brightness >> 8) & 0xf; + v = cpu_to_le16(brightness & WLED3_SINK_REG_BRIGHT_MAX); for (i = 0; i < wled->cfg.num_strings; ++i) { rc = regmap_bulk_write(wled->regmap, wled->ctrl_addr + - WLED3_SINK_REG_BRIGHT(i), v, 2); + WLED3_SINK_REG_BRIGHT(i), + &v, sizeof(v)); if (rc < 0) return rc; } @@ -249,19 +249,18 @@ static int wled3_set_brightness(struct wled *wled, u16 brightness) static int wled4_set_brightness(struct wled *wled, u16 brightness) { int rc, i; - u16 low_limit = wled->max_brightness * 4 / 1000; - u8 v[2]; + u16 v, low_limit = wled->max_brightness * 4 / 1000; /* WLED4's lower limit of operation is 0.4% */ if (brightness > 0 && brightness < low_limit) brightness = low_limit; - v[0] = brightness & 0xff; - v[1] = (brightness >> 8) & 0xf; + v = cpu_to_le16(brightness & WLED3_SINK_REG_BRIGHT_MAX); for (i = 0; i < wled->cfg.num_strings; ++i) { rc = regmap_bulk_write(wled->regmap, wled->sink_addr + - WLED4_SINK_REG_BRIGHT(i), v, 2); + WLED4_SINK_REG_BRIGHT(i), + &v, sizeof(v)); if (rc < 0) return rc; } @@ -272,22 +271,20 @@ static int wled4_set_brightness(struct wled *wled, u16 brightness) static int wled5_set_brightness(struct wled *wled, u16 brightness) { int rc, offset; - u16 low_limit = wled->max_brightness * 1 / 1000; - u8 v[2]; + u16 v, low_limit = wled->max_brightness * 1 / 1000; /* WLED5's lower limit is 0.1% */ if (brightness < low_limit) brightness = low_limit; - v[0] = brightness & 0xff; - v[1] = (brightness >> 8) & 0x7f; + v = cpu_to_le16(brightness & WLED5_SINK_REG_BRIGHT_MAX_15B); offset = (wled->cfg.mod_sel == MOD_A) ? WLED5_SINK_REG_MOD_A_BRIGHTNESS_LSB : WLED5_SINK_REG_MOD_B_BRIGHTNESS_LSB; rc = regmap_bulk_write(wled->regmap, wled->sink_addr + offset, - v, 2); + &v, sizeof(v)); return rc; } -- 2.33.0