Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp1149553ybh; Sat, 3 Aug 2019 19:11:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqxUUhg7FeWn+oud7cB2Ory40xZ5SqrL17oCdYNwdCuIKXVvtb0F2PcGVGIwBJeS9It7ibyE X-Received: by 2002:a62:b411:: with SMTP id h17mr64012414pfn.99.1564884694363; Sat, 03 Aug 2019 19:11:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564884694; cv=none; d=google.com; s=arc-20160816; b=p6ENqvVTeeR3cngET/xYUQTYoi4a/mFCEkR5JbhUUxPUG39+Zz4OCqsbSowwcFYan1 c2VdpEU18rF2/I87vUMhO6SZELPa7uyKHlOWQmOgk5Sl5sAXgBtOqN3WP59qczf91w5c EcNZ2SZPAuygQnATl9YPxREid4U7FM9doLoKBzZ4bhzQIxy0TT0uxGwZlRoBO0bSv7Wc RaOBq9gL8CVzdJ6OJ4zpa9ksY2XadCjHHm5ReWvHjUweRIYjQy+4rfOjiOnbM23oYrEA vYUPg3J/EO6pgJqPWJBgu2SoR75inghaQqaomkXjINVLm7MxqgjuEXTTVqWeH+D4xzWo njag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:autocrypt:openpgp:from:references:cc:to:subject :dkim-signature; bh=eb4swWHH3LXxdKG0OgqKABMWblY7CnFPZGTwHwDtgc4=; b=VxkvqTk7Tq4f4VOK1QKyGH+Kj+gpom8FiyTysJrRvet8545S5jDMH3Yjr6fvelgDtk dZEKlMy+k0MT6i40naJT8KSvmOsmDbfK+IMOrHeQv4aHaRE80qtxoXVG+q1/PuxYHD3O EVN4KLeQo4WaSbp3N2l29IXnS/kmvDO15rKVzFlRbQDH3Xsc9a9L2D+09Bw3XA22ExZV 7qyhUixoZqLWjI+le0+wOPbXOUGPm1YEDDRg0DOvEjC0hnQ/JQ4xCE4epueST1LHqGZX YoKwdgD8iVsQFz5jydJt3UOCYJoTZGa2NAb8/6DT9ZizMah24aVgZ82XNPHy2bXUeAH0 cTFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=L2Rn0f62; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y187si39689260pgd.66.2019.08.03.19.11.19; Sat, 03 Aug 2019 19:11:34 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=L2Rn0f62; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2405564AbfHBT1n (ORCPT + 99 others); Fri, 2 Aug 2019 15:27:43 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:33682 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405450AbfHBT1n (ORCPT ); Fri, 2 Aug 2019 15:27:43 -0400 Received: by mail-wr1-f68.google.com with SMTP id n9so78380397wru.0; Fri, 02 Aug 2019 12:27:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:openpgp:autocrypt:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=eb4swWHH3LXxdKG0OgqKABMWblY7CnFPZGTwHwDtgc4=; b=L2Rn0f620LmPgfMz/QNmgC3WfMH09xGeufGieN1SgeSxYU1uh5imAFGub021j7BNft PwL8O+kA9E3bAoWqMwdoaUaQaFoewkVsbUxpmzqG41pD1PMZww/gsIeoFKsuQ5+065w/ 0UHukEsU5H0fhDEBT2p5B0qWLDVSlrkFeLsJ4HP/4JSqzHoYefRnpBJzAyz/dQ4Oc+SK jZRHP3itc2dkUthaP5znSQY1fl3b8YZwGlA2xnGe9KG2uAeK/7pjixBpoN1IhVh7dSun BBwelvsaplyf+b3H8D2Ee5uqqPuHq/Ju+kXA+W/KeERDn/cZ9ZSPIYdpXgyQyKbNISge ogag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:openpgp:autocrypt :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=eb4swWHH3LXxdKG0OgqKABMWblY7CnFPZGTwHwDtgc4=; b=P705Xku+F2D+vRgTt93HdhiY8T3E1N3hevHIJZ1OjYdp35jH7eMfP5f7B82JP+MFR/ z9dHp0yr7y2adNuivdnzvHlrRZVQtB3NEbyFaTsZnYgqiDndVMIEv6NTI23PozSRdFyd Vk/JVVgZabihc/T4NxDL8omZGgCow+hyIRz7UIA8wUX1/s2hGWYH/dR3HQaFRSIKmjuE C2ewbCwn8ZYuiXCmeIA1B40y+iX/JlDZx4KbBHuuVnwattrfMP5EVlmKqYdoIzSM9WYz 01m73Ok5UBwz+GGwER03itlzWpK19p3l+JuTT7J5HvpkiMHQQl9sV6B50C+/RzxN5ow8 egkw== X-Gm-Message-State: APjAAAUm12bgi8/Z5SR1YZJsANPRlJ7I7yPNoQA/UKs4bWUFQ3xLLOcK zeyOau7M468DlkyeG3cyx5lo4gTM X-Received: by 2002:adf:f812:: with SMTP id s18mr11588153wrp.32.1564774059380; Fri, 02 Aug 2019 12:27:39 -0700 (PDT) Received: from [192.168.1.19] (chr175.neoplus.adsl.tpnet.pl. [83.31.15.175]) by smtp.gmail.com with ESMTPSA id 5sm63412936wmg.42.2019.08.02.12.27.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Aug 2019 12:27:38 -0700 (PDT) Subject: Re: [PATCH v4 6/9] leds: multicolor: Introduce a multicolor class definition To: Dan Murphy , pavel@ucw.cz Cc: linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org References: <20190725182818.29556-1-dmurphy@ti.com> <20190725182818.29556-7-dmurphy@ti.com> From: Jacek Anaszewski Openpgp: preference=signencrypt Autocrypt: addr=jacek.anaszewski@gmail.com; prefer-encrypt=mutual; keydata= mQINBFWjfaEBEADd66EQbd6yd8YjG0kbEDT2QIkx8C7BqMXR8AdmA1OMApbfSvEZFT1D/ECR eWFBS8XtApKQx1xAs1j5z70k3zebk2eeNs5ahxi6vM4Qh89vBM46biSKeeX5fLcv7asmGb/a FnHPAfQaKFyG/Bj9V+//ef67hpjJWR3s74C6LZCFLcbZM0z/wTH+baA5Jwcnqr4h/ygosvhP X3gkRzJLSFYekmEv+WHieeKXLrJdsUPUvPJTZtvi3ELUxHNOZwX2oRJStWpmL2QGMwPokRNQ 29GvnueQdQrIl2ylhul6TSrClMrKZqOajDFng7TLgvNfyVZE8WQwmrkTrdzBLfu3kScjE14Q Volq8OtQpTsw5570D4plVKh2ahlhrwXdneSot0STk9Dh1grEB/Jfw8dknvqkdjALUrrM45eF FM4FSMxIlNV8WxueHDss9vXRbCUxzGw37Ck9JWYo0EpcpcvwPf33yntYCbnt+RQRjv7vy3w5 osVwRR4hpbL/fWt1AnZ+RvbP4kYSptOCPQ+Pp1tCw16BOaPjtlqSTcrlD2fo2IbaB5D21SUa IsdZ/XkD+V2S9jCrN1yyK2iKgxtDoUkWiqlfRgH2Ep1tZtb4NLF/S0oCr7rNLO7WbqLZQh1q ShfZR16h7YW//1/NFwnyCVaG1CP/L/io719dPWgEd/sVSKT2TwARA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Gqo2MvMdRJ54YaIR Message-ID: <07583843-b91e-3028-2661-7d8f4395a0fa@gmail.com> Date: Fri, 2 Aug 2019 21:27:37 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Dan, On 8/2/19 4:14 PM, Dan Murphy wrote: > Jacek > > On 7/31/19 3:44 PM, Jacek Anaszewski wrote: >> Dan, >> > [...] >> +    for (i = 0; i < mcled_cdev->num_leds; i++) { >> +        ret = sscanf(buf + offset, "%i%n", &value[i], &nrchars); >> +        if (ret != 1) >> +            break; >> + >> +        offset += nrchars; >> +    } >> + >> +    if (i != mcled_cdev->num_leds) { >>>> Shouldn't we return error if i != mcled_cdev->num_leds - 1 ? >>>> How can we know which color the value will be for if there is less >>>> values passed than the total number of colors in the cluster? >>> Ok so during my testing if I had the monochrome array as >>> >>> When I wrote only and no blue I was getting random values in the >>> array for the >>> >>> remaining indexes and the blue LED would randomly turn on/off at >>> different levels. >>> >>> So if the user passes in less then expected only ids with data will be >>> written and the other colors will be turned off by the for loop below. >>  From what I see it will lead to wrong mapping of given color to the >> value array element in the following case: >> >> echo " " > color_mix >> >> Then green intensity will be assigned to value[0] (expects red) and blue >> to value[1] (expects green). Unless I don't get something. >> Your ABI documentation doesn't mention any way to redefine the color_id >> returned by /color_id file. And that is good. >> > This is exactly the issue I had previously brought up.  The user would > need to > > write all leading colors with a value, even if 0, to correctly set the > target LEDs. > > We can protect against the trailing colors but not leading colors. > > The expectation is that the user space would read the color_id from the > file and align > > the array accordingly.  This is also why I exposed the intensity under > the color so if the > > user wanted to not use color_mix file they can update the intensity per > LED color. > I can't see the problem. Just require user to _always_ pass the number of values equal to the number of colors under LED multicolor class device. No more, no less. And fail it this condition is not met. >>>>> +        for (; i < LED_COLOR_ID_MAX; i++) >>>>> +            value[i] = 0; >>>> What use case is it for? >>> See above but this should be >>> >>> for (; i < mcled_cdev->num_leds; i++) >>> > I might be able to eliminate this loop by initializing the array to 0. > > >>>>> +    } >>>>> + >>>>> +    list_for_each_entry(priv, &data->color_list, list) { >>>>> +        if (data->cluster_brightness) { >>>>> +            adj_brightness = >>>>> calculate_brightness(data->cluster_brightness, >>>>> +                                  value[priv->color_index], >>>>> +                                 priv->max_intensity); >>>>> +            ret = ops->set_color_brightness(priv->mcled_cdev, >>>>> +                            priv->color_id, >>>>> +                            adj_brightness); >>>>> +            if (ret < 0) >>>>> +                goto done; >>>>> +        } >>>>> + >>>>> +        priv->intensity = value[priv->color_index]; >>>>> +    } >>>> Here we could use just brightness_set op as a single call. We should >>>> always write all colors as a result of write to color_mix anyway. >>> I guess what is gained by just passing the array down to the device >>> driver and having it >>> >>> parse the array and do the peripheral call? >> Those array values would not be directly written to the device, >> but used for calculating the actual iout intensities. Driver >> will just have to call calculate_brightness() (sticking to the naming >> from this patch) and write the results calculated basing on brightness >> and max_brightness. > > I would expect that we would do the same behavior for the color_mix file > then. Yes, this is what I meant while mentioning use of brightness_set op for that. The final effect will be always the same - write of the altered iout intensity registers. What will differ will be factors of the equation that calculates iout intensity: for the call originating from color_mix file the changing factor will be color intensity and for the call originating from brightness file it will be brightness. In both cases on the driver side we need to call the same function to calculate iout values using the same equation. > >> [...] >>>>> + >>>>> +    priv->new_intensity = value; >>>>> + >>>>> +    if (data->cluster_brightness) { >>>>> +        adj_value = calculate_brightness(data->cluster_brightness, >>>>> +                    priv->new_intensity, >>>>> +                    priv->max_intensity); >>>>> +        ret = ops->set_color_brightness(priv->mcled_cdev, >>>>> +                        priv->color_id, adj_value); >>>>> +        if (ret < 0) { >>>>> +            priv->new_intensity = priv->intensity; >>>> This is unnecessary complication. Just write the calculated iout >>>> intensity. >>> Not sure what complication you are referring to. >> The whole need for new_intensity and cluster_brightness, and then >> bringing back old intensity value on set_color_brightness() failure. > > OK > >> >>>> We need to highlight it in the documentation that exact requested color >>>> intensity values are written to the hardware only when >>>> brightness == max_brightness. >>> But that is not a true statement.  Thats not really how it was designed. >> But it probably should be. It would simplify the design. >> >> So my idea is like I previously described the way I had first understood >> this design: >> >> The colors set under colors directory don't reflect the iout >> intensities, but are only used for calculating them, basing on the >> brightness and max_intensity values. >> >> Effectively, after changing the colors//intensity the global >> (legacy monochrome) brightness value will be still valid, since iout >> color will be recalculated basing on it and the new color intensity. >> > OK.  This this would remove the ops from the driver as it is no longer > needed. > > The color_mix file will work the same way. I've been pondering over the need for color_set, but it should be indeed not needed too. Write to /intensity file will also call brightness_set - it will be comparing anyway old intensities and new ones and will write only the affected register. > What is the trigger then to update the LEDs? > > We cannot write the same brightness value to trigger as the class blocks > calling down > > to the driver if brightness_in == brightness_current. All files (intensity, color_mix and brightness) will use the same brightness_set op for changing the iout values. -- Best regards, Jacek Anaszewski