Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp3477931iog; Mon, 20 Jun 2022 22:18:17 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tB0BLzGNTL9M/UW/U1N1HYl20fATwvy/63AZgigb8yKFvNGQpGTQvR5tMK96bAvAU0df7u X-Received: by 2002:a63:9701:0:b0:40c:a588:b488 with SMTP id n1-20020a639701000000b0040ca588b488mr9064903pge.303.1655788697651; Mon, 20 Jun 2022 22:18:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655788697; cv=none; d=google.com; s=arc-20160816; b=oSPxeXRqGv1Xwbp5O1f9R0W4Z76Pph/jJwrKsUhvukuiLn12/V3YbKZKH0jZVZzsnP N9sQuhMS7GbuIt3cbSHwt2wDFI4LTVr+YeFcdI0Sws4NQLn2t/sKxh7A+nFDr4quRrXz HjQObJ27TK9FlEVeNxV/CW0q3KQq4o8ovjdTVRfnPJ+BgxaM3KRO3++EQACZY+OG2jnn xHK77BTLeyBC9ybmfPwAkBhTXIDbjQGhGrwK0zUquLZsUNtsj3Jb3eyBaA797NqyU1cH zUdCm2vyi510FiO7FEQCc+C0fWZ9hPtTmdrQo3PzLmwYavxl78Irp/Eoc0IJQqdTclYn co2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:feedback-id:dkim-signature:dkim-signature; bh=YFC9enACBq9N/iDDvL+ELyNOFTG6bJu/nZay/ScaEg4=; b=YhFs60SChk+z3da0mcVIw4hIxXG5ul07ilLdAzHE2kjy+2x/jw7KkAhM9iyQ7KB9Fk iydn1jVi8fWXg9IVQcyj+mz9FsDKSnmRuPEUttR9bbj4ABB253PaKwyX/kcUopzK3/Rt /oUjeY+PDqOYQa699PuCvWGWSdSAHlelRyjXapH277/A9l6peiFZRxxX4sEHM8ccUBUx 0J+iu9VxaHccJtd64Zt+12m5byRb4CxiwqUlNVuPNEfMVxcA3MHDbOcmH46Z759om/q5 Cp8ojKKuTAKFBbAEhUZ4Z6trJc4aSajcg4klfEByn0Rw6IeRDaOYemSBeQHXIMYKYrdU cwLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sholland.org header.s=fm3 header.b=C1M85zd3; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b="Oeb/c7KA"; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 2-20020a630302000000b003fa7e315240si20247656pgd.249.2022.06.20.22.18.05; Mon, 20 Jun 2022 22:18:17 -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=pass header.i=@sholland.org header.s=fm3 header.b=C1M85zd3; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b="Oeb/c7KA"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234718AbiFUEMy (ORCPT + 99 others); Tue, 21 Jun 2022 00:12:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230358AbiFUEMw (ORCPT ); Tue, 21 Jun 2022 00:12:52 -0400 Received: from wout4-smtp.messagingengine.com (wout4-smtp.messagingengine.com [64.147.123.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C35D19019; Mon, 20 Jun 2022 21:12:50 -0700 (PDT) Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.west.internal (Postfix) with ESMTP id CB03632004F8; Tue, 21 Jun 2022 00:12:48 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Tue, 21 Jun 2022 00:12:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sholland.org; h= cc:cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm3; t=1655784768; x= 1655871168; bh=YFC9enACBq9N/iDDvL+ELyNOFTG6bJu/nZay/ScaEg4=; b=C 1M85zd3eSzPbPbrqJLqJf9XGPjCp5qspTW0Pb2G5upYU2zzPTmqd1H/GkSDF4R2h jTVkPgJvlPCbUT6D66cr5MOagfZp8/qJ7gT7m6CH/IPz1QgwP5kmuhn2pcMJ+Bjq wF3m6DwBEx8ZkjB9ljR1S07Y371FLj2Rk4NejXkBpjEyR1qdIpmSmNNV/St6FPaX Axq3ihYYd9b+xHhWwlk4BM9Ze4n+fNrYaOeJYCXxsgDruW8N2Niew1cwoZ7I6oOe ZmRbDc5CSGn+GXqrjbz/U4POJ0yx9yl+FXAEafjH5TgkODpPrvBLIzxVO3B5T9mK mnzQnlTfPmlOth79Drw5A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1655784768; x= 1655871168; bh=YFC9enACBq9N/iDDvL+ELyNOFTG6bJu/nZay/ScaEg4=; b=O eb/c7KAsWiuQnepLqcYmFDJjhF1toXYwtArej8zdAYFOE4m6yXPYTKUgH8DFUAXT CBCYQPUEnqhlY9h1iOeG4lFU8VqoZAYJxlU7Jwkwkangi5r3GhyuXcvc3bhvgydU mEodnq47L0sIIQoNhDYj9+sLqkfddMBdepKvDioqFEr/DwquVHV9bQr55sUgy3YQ d7U/L0jmpEC4IUz0LR/iiWEp+ZahM5L7hGyFEk1uB6mC4kkJPZ0fC4MUanPnu48s TROyoixs26PBdxrFpylGlkzEiwvXMr0HmCLvWfVor5suPMHuhfpg/NFBxmvb0SUu hnuE4vdC8TYCbD8YSqzXA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrudefvddgjeeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepuffvvehfhffkffgfgggjtgfgsehtjeertddtfeejnecuhfhrohhmpefurghm uhgvlhcujfholhhlrghnugcuoehsrghmuhgvlhesshhhohhllhgrnhgurdhorhhgqeenuc ggtffrrghtthgvrhhnpefftdevkedvgeekueeutefgteffieelvedukeeuhfehledvhfei tdehudfhudehhfenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfh hrohhmpehsrghmuhgvlhesshhhohhllhgrnhgurdhorhhg X-ME-Proxy: Feedback-ID: i0ad843c9:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 21 Jun 2022 00:12:47 -0400 (EDT) Subject: Re: [PATCH v4 2/4] Input: pinephone-keyboard - Add PinePhone keyboard driver To: Andy Shevchenko Cc: Dmitry Torokhov , linux-input , Linux Kernel Mailing List , Ondrej Jirman , Andy Shevchenko , Chen-Yu Tsai , Jernej Skrabec , linux-arm Mailing List , linux-sunxi@lists.linux.dev References: <20220618165747.55709-1-samuel@sholland.org> <20220618165747.55709-3-samuel@sholland.org> From: Samuel Holland Message-ID: <2e6499b8-d8f4-b63a-689b-1e93aca7c210@sholland.org> Date: Mon, 20 Jun 2022 23:12:46 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US 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_PASS,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 On 6/19/22 6:43 AM, Andy Shevchenko wrote: > On Sat, Jun 18, 2022 at 7:10 PM Samuel Holland wrote: >> >> The official Pine64 PinePhone keyboard case contains a matrix keypad and >> a MCU which runs a libre firmware. Add support for its I2C interface. > > ... > >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include > > Missed > types.h > > ... > >> +#define PPKB_ROWS 6 >> +#define PPKB_COLS 12 > > ... > >> + for (col = 0; col < PPKB_COLS; ++col) { >> + u8 old = old_buf[1 + col]; >> + u8 new = new_buf[1 + col]; >> + u8 changed = old ^ new; >> + >> + if (!changed) >> + continue; >> + >> + for (row = 0; row < PPKB_ROWS; ++row) { >> + u8 mask = BIT(row); >> + u8 value = new & mask; >> + unsigned short code; >> + bool fn_state; >> + >> + if (!(changed & mask)) >> + continue; >> + >> + /* >> + * Save off the FN key state when the key was pressed, >> + * and use that to determine the code during a release. >> + */ >> + fn_state = value ? ppkb->fn_pressed : ppkb->fn_state[col] & mask; >> + if (fn_state) >> + ppkb->fn_state[col] ^= mask; > > Can't it be converted to use bitmap APIs? This is a 2D matrix, with one byte per column, and one bit per row. There are only 6 rows, so two bits per byte are unused. Converting this to the bitmap API would unnecessarily complicate things. >> + } >> + } > > ... > >> +static int ppkb_set_scan(struct i2c_client *client, bool enable) >> +{ >> + struct device *dev = &client->dev; >> + int ret, val; >> + >> + ret = i2c_smbus_read_byte_data(client, PPKB_SYS_CONFIG); >> + if (ret < 0) { >> + dev_err(dev, "Failed to read config: %d\n", ret); >> + return ret; >> + } >> + >> + if (enable) >> + val = ret & ~PPKB_SYS_CONFIG_DISABLE_SCAN; >> + else >> + val = ret | PPKB_SYS_CONFIG_DISABLE_SCAN; >> + ret = i2c_smbus_write_byte_data(client, PPKB_SYS_CONFIG, val); >> + if (ret) { >> + dev_err(dev, "Failed to write config: %d\n", ret); > >> + return ret; >> + } >> + >> + return 0; > > return ret; The "return 0" pattern is idiomatic, and more diff-friendly when adding error handling or more operations. But I don't have that strong of an opinion on it. Regards, Samuel