Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp5543036rdb; Sun, 17 Sep 2023 01:06:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGIqPsOvpHCA29MA2R7Og3IM8mN8VTgkBSFbZBv/fv9JLqARMsNEzxAFXaAwYmEOtZkfssM X-Received: by 2002:a05:6a20:3c9e:b0:153:73ec:fe70 with SMTP id b30-20020a056a203c9e00b0015373ecfe70mr6911122pzj.13.1694937979132; Sun, 17 Sep 2023 01:06:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694937979; cv=none; d=google.com; s=arc-20160816; b=SuHkQKtXN0cWsjz+sX4PucML4nL41HvIT4HZqR+jCYCwx6kY5VVsYqjiaYrkTrggbc UCv4pJwN33F3G1A5sJBybAVnWNnxikpwzsc2GxrXiU3qGoBaRXXGkhCiGGdgAh4fOfxt ZLhVnCC0F9J2hYTZMPYcn6nSMJIbn+2LjXXvW2upCO/xjM0SfvqhhYIK6FZkTz5J+ClA xHDI+AKKIL603KceThwskKTI+/xVU+fxcUBcakWpysJjFjiUnfmjQJYCdrnvziFVN3Wj KZxswBZ1coQ3AE4iwegG+MBrHRmsH4nRCM9b1+PvnRayTAYeTFmAKqspCTjvRG7cGKaL 6h4w== 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 :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=L+fucrYvHZGTDZtgpuMyh0kVP9Gh8YSk+kaR8DcFbLY=; fh=8NcnhXONQXF7cEEF3XzLfgJz3IHIa+ILVHN+5ZLqIYg=; b=GzM1TCq451Dubu7BzcR6B3VBgKtvViC7fHrNkSgQ6wZqz/XUGWKkdMhRp5Cr/Dujbi lNoTOqgWeEBEakUEUDLX+qwgO4/3D2ZFFMnDMhtuVSAwbLapQqlDsLl0rjzjoJfYfual IuZZgHYLjtPe93AP+hfBqRDe3vdjBfiZRygXF3jMXM8IGOiuvTOVp0PK4yboUXAOtBwU QscUqXNWY3K88T9NLyJQZ/BjKK+0cbDn3c7h0GnwJ7ODPksPAcZPIjIIPOQbN7XYf6x4 Afz59Q+lI7gjsGm974DMv0lNPl7zg2yI7u/2azf252F8+uVmZ+v4qT9qLe83EIR9Kyz2 Aa0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=tREb9eM0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=wanadoo.fr Return-Path: Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id d10-20020a170902654a00b001b9e36ed387si5869920pln.525.2023.09.17.01.05.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Sep 2023 01:06:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=tREb9eM0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=wanadoo.fr Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id BF62783AE631; Sat, 16 Sep 2023 23:12:30 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230222AbjIQGEc (ORCPT + 99 others); Sun, 17 Sep 2023 02:04:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232132AbjIQGD7 (ORCPT ); Sun, 17 Sep 2023 02:03:59 -0400 Received: from smtp.smtpout.orange.fr (smtp-29.smtpout.orange.fr [80.12.242.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B5979185 for ; Sat, 16 Sep 2023 23:03:52 -0700 (PDT) Received: from [192.168.1.18] ([86.243.2.178]) by smtp.orange.fr with ESMTPA id hksmq6IsMiBkuhksnqfNaI; Sun, 17 Sep 2023 08:03:50 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1694930630; bh=L+fucrYvHZGTDZtgpuMyh0kVP9Gh8YSk+kaR8DcFbLY=; h=Date:Subject:To:Cc:References:From:In-Reply-To; b=tREb9eM0fmJ8o3fwVwse+LA5/+eLq2t/DibFtMaWoB1iAMG43iuPjkKXfvKBYciAr wwSiZSIukVV8mDWI8974rTf+CKt+zyz4K1yFaMilj0DaNaFMoJJAiKyU7Qr7Gj0dio PA/Lv5tgGSPg3uQYPRAXRXt+NWC41pfDhV4AZELnob2rRcWQOJWdCJPCUs+SkvAvlA K9B87jq2dsuHhSGP3o83q3Fno9ba5nLmjtQJhdUftrQ7Y3v873PFT9mrWapjKNZ2Q2 EsjyPukbByZmAhf4Vm8NteT7EFsQvEr2KGCv2zcf1P0rUOOJU8WDrR+n9OdV2j7JDD EhXsWUgAMkiiA== X-ME-Helo: [192.168.1.18] X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Sun, 17 Sep 2023 08:03:50 +0200 X-ME-IP: 86.243.2.178 Message-ID: Date: Sun, 17 Sep 2023 08:03:48 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: Re: [PATCH 2/2] Input: add Himax HX852x(ES) touchscreen driver To: stephan@gerhold.net Cc: conor+dt@kernel.org, devicetree@vger.kernel.org, dmitry.torokhov@gmail.com, jeff@labundy.com, jonathan.albrieux@gmail.com, krzysztof.kozlowski+dt@linaro.org, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, robh+dt@kernel.org, rydberg@bitmath.org References: <20230913-hx852x-v1-0-9c1ebff536eb@gerhold.net> <20230913-hx852x-v1-2-9c1ebff536eb@gerhold.net> Content-Language: fr From: Christophe JAILLET In-Reply-To: <20230913-hx852x-v1-2-9c1ebff536eb@gerhold.net> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Sat, 16 Sep 2023 23:12:30 -0700 (PDT) Le 13/09/2023 à 15:25, Stephan Gerhold a écrit : > From: Jonathan Albrieux > > Add a simple driver for the Himax HX852x(ES) touch panel controller, > with support for multi-touch and capacitive touch keys. > > The driver is somewhat based on sample code from Himax. However, that > code was so extremely confusing that we spent a significant amount of > time just trying to understand the packet format and register commands. > In this driver they are described with clean structs and defines rather > than lots of magic numbers and offset calculations. > > Signed-off-by: Jonathan Albrieux > Co-developed-by: Stephan Gerhold > Signed-off-by: Stephan Gerhold > --- ... > +static irqreturn_t hx852x_interrupt(int irq, void *ptr) > +{ > + struct hx852x *hx = ptr; > + int error; > + > + error = hx852x_handle_events(hx); > + if (error) { > + dev_err(&hx->client->dev, "failed to handle events: %d\n", error); Should dev_err_ratelimited() be preferred? > + return IRQ_NONE; > + } > + > + return IRQ_HANDLED; > +} ... > +static int hx852x_probe(struct i2c_client *client) > +{ > + struct device *dev = &client->dev; > + struct hx852x *hx; > + int error, i; Nit: err or ret is shorter and maybe more "standard". > + > + if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C | > + I2C_FUNC_SMBUS_WRITE_BYTE | > + I2C_FUNC_SMBUS_WRITE_BYTE_DATA | > + I2C_FUNC_SMBUS_WRITE_WORD_DATA)) { > + dev_err(dev, "not all i2c functionality supported\n"); > + return -ENXIO; > + } > + > + hx = devm_kzalloc(dev, sizeof(*hx), GFP_KERNEL); > + if (!hx) > + return -ENOMEM; > + > + hx->client = client; > + hx->input_dev = devm_input_allocate_device(dev); > + if (!hx->input_dev) > + return -ENOMEM; > + > + hx->input_dev->name = "Himax HX852x"; > + hx->input_dev->id.bustype = BUS_I2C; > + hx->input_dev->open = hx852x_input_open; > + hx->input_dev->close = hx852x_input_close; > + > + i2c_set_clientdata(client, hx); > + input_set_drvdata(hx->input_dev, hx); > + > + hx->supplies[0].supply = "vcca"; > + hx->supplies[1].supply = "vccd"; > + error = devm_regulator_bulk_get(dev, ARRAY_SIZE(hx->supplies), hx->supplies); > + if (error < 0) > + return dev_err_probe(dev, error, "failed to get regulators"); > + > + hx->reset_gpiod = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH); > + if (IS_ERR(hx->reset_gpiod)) > + return dev_err_probe(dev, error, "failed to get reset gpio"); > + > + error = devm_request_threaded_irq(dev, client->irq, NULL, hx852x_interrupt, > + IRQF_ONESHOT | IRQF_NO_AUTOEN, NULL, hx); > + if (error) { > + dev_err(dev, "failed to request irq %d: %d\n", client->irq, error); dev_err_probe() could be used to be consistent with above code. Same for below dev_err() calls. > + return error; > + } > + > + error = hx852x_read_config(hx); > + if (error) > + return error; > + > + input_set_capability(hx->input_dev, EV_ABS, ABS_MT_POSITION_X); > + input_set_capability(hx->input_dev, EV_ABS, ABS_MT_POSITION_Y); > + input_set_abs_params(hx->input_dev, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0); > + > + touchscreen_parse_properties(hx->input_dev, true, &hx->props); > + error = hx852x_parse_properties(hx); > + if (error) > + return error; > + > + hx->input_dev->keycode = hx->keycodes; > + hx->input_dev->keycodemax = hx->keycount; > + hx->input_dev->keycodesize = sizeof(hx->keycodes[0]); > + for (i = 0; i < hx->keycount; i++) > + input_set_capability(hx->input_dev, EV_KEY, hx->keycodes[i]); > + > + error = input_mt_init_slots(hx->input_dev, hx->max_fingers, > + INPUT_MT_DIRECT | INPUT_MT_DROP_UNUSED); > + if (error) { > + dev_err(dev, "failed to init MT slots: %d\n", error); > + return error; > + } > + > + error = input_register_device(hx->input_dev); > + if (error) { input_mt_destroy_slots() should be called here, or in an error handling path below, or via a devm_add_action_or_reset(). It should also be called in a .remove function (unless devm_add_action_or_reset is prefered) CJ > + dev_err(dev, "failed to register input device: %d\n", error); > + return error; > + } > + > + return 0; > +} ...