From patchwork Sat Jan 29 23:00:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 538154 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6DCBBC433FE for ; Sat, 29 Jan 2022 23:00:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353398AbiA2XAu (ORCPT ); Sat, 29 Jan 2022 18:00:50 -0500 Received: from wout2-smtp.messagingengine.com ([64.147.123.25]:59169 "EHLO wout2-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353393AbiA2XAt (ORCPT ); Sat, 29 Jan 2022 18:00:49 -0500 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.west.internal (Postfix) with ESMTP id 9CEE632008FA; Sat, 29 Jan 2022 18:00:48 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Sat, 29 Jan 2022 18:00:49 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sholland.org; h= cc:cc:content-transfer-encoding:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm1; bh=9yxtGa/gxLqBTSBTDmI/ioVNCFPQcS 50q3woH6HVfqY=; b=A7lnOu/cte98W0Yd2LUMJxPM94Rlhx0+a4zBN6c7tT8UKE AM1aQw0YsXIiZxioTqSo9CdBTTk44+0d6U5cjxxVag/VDtxrXM7n/tmjJ9Dq0MrD fwZwLraW3eoyvZ2QmhSZzyiuOBRrNGEfHVmpmvSjEkQge70GNY7L45pkE++UKIh/ CGTp1bMN+V9c5LH/wnWcvJVgIdqLrrS+aUw1vAaDESXcOwIPDrjFXNB8ESfYE6dq mPkiJsYPmOZO0Y+8JiI0NAiXxhP6bJxb9Jd0jdrNqWB37AuabTCSjV1IsPGqXqi1 l9do80xjgp3fMKATDgpeLtqHCYFC8YHI5218kgYg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :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=fm1; bh=9yxtGa /gxLqBTSBTDmI/ioVNCFPQcS50q3woH6HVfqY=; b=FGkMTVPN/kfjGsbtecw77p 4vsDkrS5/JGWG9tZ0NfYQy6PxrADf9XYlplf35KdwShvhs0N3iTirRuTHUX7T4US oUmRq20eJyKA+of36/pH/0MO/pE3nj7MDnnDEGzC3wGQYPOODF8jMy+sz36VL+8K suJtg3DWIRu/tM4NmsPZRAUgkFXPizltwwuglEuQHD8nuZnN2nAh89zsDJ5N/vM8 NZ3dHJNY9OoX+LYuqYzGfQedZvHi7KOFZrOXkDC3ZzWfi6/hsDRtcBFqhizxFxIX YbMg2hxZEITYy4e2TJveSFpA2G+INpChrH81BO42Q3dJGdBzFdBgx7xzfBlVNZbA == X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvvddrfeejgddujedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefurghmuhgv lhcujfholhhlrghnugcuoehsrghmuhgvlhesshhhohhllhgrnhgurdhorhhgqeenucggtf frrghtthgvrhhnpeelueelgeettdfggfeuffevkefhuddtteeigfevhfdtffdtjefgteeg leeggedvudenucffohhmrghinhepuggvvhhitggvthhrvggvrdhorhhgnecuvehluhhsth gvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepshgrmhhuvghlsehshhho lhhlrghnugdrohhrgh X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 29 Jan 2022 18:00:47 -0500 (EST) From: Samuel Holland To: Dmitry Torokhov , linux-input@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Rob Herring , devicetree@vger.kernel.org, linux-i2c@vger.kernel.org, Wolfram Sang , Ondrej Jirman , Samuel Holland Subject: [PATCH 1/5] dt-bindings: input: Add the PinePhone keyboard binding Date: Sat, 29 Jan 2022 17:00:38 -0600 Message-Id: <20220129230043.12422-2-samuel@sholland.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220129230043.12422-1-samuel@sholland.org> References: <20220129230043.12422-1-samuel@sholland.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Add devicetree support for the PinePhone keyboard case, which provides a matrix keyboard interface and a proxied I2C bus. Signed-off-by: Samuel Holland --- .../input/pine64,pinephone-keyboard.yaml | 90 +++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 Documentation/devicetree/bindings/input/pine64,pinephone-keyboard.yaml diff --git a/Documentation/devicetree/bindings/input/pine64,pinephone-keyboard.yaml b/Documentation/devicetree/bindings/input/pine64,pinephone-keyboard.yaml new file mode 100644 index 000000000000..00f084b263f0 --- /dev/null +++ b/Documentation/devicetree/bindings/input/pine64,pinephone-keyboard.yaml @@ -0,0 +1,90 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/input/pine64,pinephone-keyboard.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Pine64 PinePhone keyboard device tree bindings + +maintainers: + - Samuel Holland + +description: + A keyboard accessory is available for the Pine64 PinePhone and PinePhone Pro. + It connects via I2C, providing a raw scan matrix, a flashing interface, and a + subordinate I2C bus for communication with a battery charger IC. + +allOf: + - $ref: /schemas/input/matrix-keymap.yaml# + +properties: + compatible: + const: pine64,pinephone-keyboard + + reg: + const: 0x15 + + interrupts: + maxItems: 1 + + linux,fn-keymap: + $ref: /schemas/input/matrix-keymap.yaml#/properties/linux,keymap + description: keymap used when the Fn key is pressed + + wakeup-source: true + + i2c-bus: + $ref: /schemas/i2c/i2c-controller.yaml# + +dependencies: + linux,fn-keymap: [ 'keypad,num-columns', 'keypad,num-rows' ] + linux,keymap: [ 'keypad,num-columns', 'keypad,num-rows' ] + +required: + - compatible + - reg + - interrupts + +unevaluatedProperties: false + +examples: + - | + #include + #include + + i2c { + #address-cells = <1>; + #size-cells = <0>; + + keyboard@15 { + compatible = "pine64,pinephone-keyboard"; + reg = <0x15>; + interrupt-parent = <&r_pio>; + interrupts = <0 12 IRQ_TYPE_EDGE_FALLING>; /* PL12 */ + keypad,num-rows = <6>; + keypad,num-columns = <12>; + linux,fn-keymap = ; + linux,keymap = ; + + i2c-bus { + #address-cells = <1>; + #size-cells = <0>; + + charger@75 { + reg = <0x75>; + }; + }; + }; + }; From patchwork Sat Jan 29 23:00:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 538602 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A3F53C433EF for ; Sat, 29 Jan 2022 23:00:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353411AbiA2XAy (ORCPT ); Sat, 29 Jan 2022 18:00:54 -0500 Received: from wout2-smtp.messagingengine.com ([64.147.123.25]:33569 "EHLO wout2-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353395AbiA2XAw (ORCPT ); Sat, 29 Jan 2022 18:00:52 -0500 Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id 6687B32008FA; Sat, 29 Jan 2022 18:00:51 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Sat, 29 Jan 2022 18:00:52 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sholland.org; h= cc:cc:content-transfer-encoding:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm1; bh=qeuP9p8C7DpDSoMeAMOELLPEM/JnmC oRFLMB/Sunq8Q=; b=Cp5rrTgQbf5pyeDLEC8v3K6uqzb4DkBJOEoIUqwjN9gCIi B8aNPDAGCiCHHdTK0aJaLUYbRabk9Ce/uE+HBW/ICyAajebKPTS6MNffxMAsi2kV zagc6V1OhDKoVdyVXaOvzvE0wAz6Sbjn1tgxG+ye+ktP0Xrl1TQZ7FSlj8B9L2ld ryWheru5uvRHjLAF5H8LoF9LB+7px9wuTBhKIO7yMZgWcPl+TW3mv2R7ywb/zHca 2IpA+hXhYvyrd63iKRvQNiKKx1F4LrDs6aBYwRV8ouj/G9/TmG9B/zfBK8iWnfGf OPvcivwKcd8djblbDGHgRsdqirTLTVyMJC4/0jtw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :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=fm1; bh=qeuP9p 8C7DpDSoMeAMOELLPEM/JnmCoRFLMB/Sunq8Q=; b=Zho7irXdRYZA7T3DPrr/Xb TSMZFjyBPRCX9kalT/XV36nz+HPBU45/eCBiHA3DQj1y/FZduY99Y+IIHkfT+X5Z w7ALWeSoItKtwIDNANWAyoxxsuJP3nmwuEyQPOs0R5K4mIA59zQE6YEbyjseWQUh mhoc4mBlz1AxrojED2Z4/mj5VftGplUh7JzBkKGR3SS3LUi2lws/jn2dIbGrxFMG uYhHELmIDDxQsKzcSpwXIN0ast2oR7DE4oH+EvHGBnC12W8+yzIMsiFP/mC2pdKi kTbBlB7cXKPfDqydSKWsmkN8vGnKlQfHCBQbIAut6WDyCRj9P7S+T3hTZjPug3Eg == X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvvddrfeejgdduieelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefurghmuhgv lhcujfholhhlrghnugcuoehsrghmuhgvlhesshhhohhllhgrnhgurdhorhhgqeenucggtf frrghtthgvrhhnpeeffedtveduheefueejgeeuledtkeektdffjeefkedvieeuteefhfet hedtfeelvdenucffohhmrghinhepmhgvghhouhhsrdgtohhmnecuvehluhhsthgvrhfuih iivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepshgrmhhuvghlsehshhholhhlrghn ugdrohhrgh X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 29 Jan 2022 18:00:50 -0500 (EST) From: Samuel Holland To: Dmitry Torokhov , linux-input@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Rob Herring , devicetree@vger.kernel.org, linux-i2c@vger.kernel.org, Wolfram Sang , Ondrej Jirman , Samuel Holland Subject: [PATCH 2/5] Input: pinephone-keyboard - Add PinePhone keyboard driver Date: Sat, 29 Jan 2022 17:00:39 -0600 Message-Id: <20220129230043.12422-3-samuel@sholland.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220129230043.12422-1-samuel@sholland.org> References: <20220129230043.12422-1-samuel@sholland.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org The official Pine64 PinePhone keyboard case contains a matrix keypad and a MCU which runs a libre firmware. Add support for its I2C interface. Signed-off-by: Samuel Holland --- MAINTAINERS | 6 + drivers/input/keyboard/Kconfig | 10 + drivers/input/keyboard/Makefile | 1 + drivers/input/keyboard/pinephone-keyboard.c | 258 ++++++++++++++++++++ 4 files changed, 275 insertions(+) create mode 100644 drivers/input/keyboard/pinephone-keyboard.c diff --git a/MAINTAINERS b/MAINTAINERS index f41088418aae..85428a707e67 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -15320,6 +15320,12 @@ S: Maintained F: Documentation/devicetree/bindings/iio/chemical/plantower,pms7003.yaml F: drivers/iio/chemical/pms7003.c +PINE64 PINEPHONE KEYBOARD DRIVER +M: Samuel Holland +S: Supported +F: Documentation/devicetree/bindings/input/pine64,pinephone-keyboard.yaml +F: drivers/input/keyboard/pinephone-keyboard.c + PLDMFW LIBRARY M: Jacob Keller S: Maintained diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig index 0c607da9ee10..f9978da1c916 100644 --- a/drivers/input/keyboard/Kconfig +++ b/drivers/input/keyboard/Kconfig @@ -523,6 +523,16 @@ config KEYBOARD_OPENCORES To compile this driver as a module, choose M here; the module will be called opencores-kbd. +config KEYBOARD_PINEPHONE + tristate "Pine64 PinePhone Keyboard" + depends on I2C + select CRC8 + select INPUT_MATRIXKMAP + help + Say Y here to enable support for the keyboard in the Pine64 PinePhone + keyboard case. This driver supports the FLOSS firmware available at + https://megous.com/git/pinephone-keyboard/ + config KEYBOARD_PXA27x tristate "PXA27x/PXA3xx keypad support" depends on PXA27x || PXA3xx || ARCH_MMP diff --git a/drivers/input/keyboard/Makefile b/drivers/input/keyboard/Makefile index e3c8648f834e..84da37e3a2f5 100644 --- a/drivers/input/keyboard/Makefile +++ b/drivers/input/keyboard/Makefile @@ -51,6 +51,7 @@ obj-$(CONFIG_KEYBOARD_NSPIRE) += nspire-keypad.o obj-$(CONFIG_KEYBOARD_OMAP) += omap-keypad.o obj-$(CONFIG_KEYBOARD_OMAP4) += omap4-keypad.o obj-$(CONFIG_KEYBOARD_OPENCORES) += opencores-kbd.o +obj-$(CONFIG_KEYBOARD_PINEPHONE) += pinephone-keyboard.o obj-$(CONFIG_KEYBOARD_PMIC8XXX) += pmic8xxx-keypad.o obj-$(CONFIG_KEYBOARD_PXA27x) += pxa27x_keypad.o obj-$(CONFIG_KEYBOARD_PXA930_ROTARY) += pxa930_rotary.o diff --git a/drivers/input/keyboard/pinephone-keyboard.c b/drivers/input/keyboard/pinephone-keyboard.c new file mode 100644 index 000000000000..9a071753fd91 --- /dev/null +++ b/drivers/input/keyboard/pinephone-keyboard.c @@ -0,0 +1,258 @@ +// SPDX-License-Identifier: GPL-2.0-only +// +// Copyright (C) 2021-2022 Samuel Holland + +#include +#include +#include +#include +#include + +#define DRV_NAME "pinephone-keyboard" + +#define PPKB_CRC8_POLYNOMIAL 0x07 + +#define PPKB_DEVICE_ID_HI 0x00 +#define PPKB_DEVICE_ID_HI_VALUE 0x4b +#define PPKB_DEVICE_ID_LO 0x01 +#define PPKB_DEVICE_ID_LO_VALUE 0x42 +#define PPKB_FW_REVISION 0x02 +#define PPKB_FW_FEATURES 0x03 +#define PPKB_MATRIX_SIZE 0x06 +#define PPKB_SCAN_CRC 0x07 +#define PPKB_SCAN_DATA 0x08 +#define PPKB_SYS_CONFIG 0x20 +#define PPKB_SYS_CONFIG_DISABLE_SCAN BIT(0) + +struct pinephone_keyboard { + struct input_dev *input; + unsigned short *fn_keymap; + u8 crc_table[CRC8_TABLE_SIZE]; + u8 row_shift; + u8 rows; + u8 cols; + u8 fn_state; + u8 buf_swap; + u8 buf[]; +}; + +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; +} + +static void ppkb_update(struct i2c_client *client) +{ + struct pinephone_keyboard *ppkb = i2c_get_clientdata(client); + struct device *dev = &client->dev; + size_t buf_len = ppkb->cols + 1; + u8 *old_buf = ppkb->buf; + u8 *new_buf = ppkb->buf; + unsigned short *keymap; + int col, crc, ret, row; + + if (ppkb->buf_swap) + old_buf += buf_len; + else + new_buf += buf_len; + + ret = i2c_smbus_read_i2c_block_data(client, PPKB_SCAN_CRC, + buf_len, new_buf); + if (ret != buf_len) { + dev_err(dev, "Failed to read scan data: %d\n", ret); + return; + } + + crc = crc8(ppkb->crc_table, new_buf + 1, ppkb->cols, CRC8_INIT_VALUE); + if (crc != new_buf[0]) { + dev_err(dev, "Bad scan data (%02x != %02x)\n", crc, new_buf[0]); + return; + } + + ppkb->buf_swap = !ppkb->buf_swap; + + keymap = ppkb->fn_state ? ppkb->fn_keymap : ppkb->input->keycode; + for (col = 0; col < ppkb->cols; ++col) { + u8 old = *(++old_buf); + u8 new = *(++new_buf); + u8 changed = old ^ new; + + for (row = 0; row < ppkb->rows; ++row) { + int code = MATRIX_SCAN_CODE(row, col, ppkb->row_shift); + int value = new & BIT(row); + + if (!(changed & BIT(row))) + continue; + + dev_dbg(dev, "row %u col %u %sed\n", + row, col, value ? "press" : "releas"); + if (keymap[code] == KEY_FN) { + dev_dbg(dev, "FN is now %sed\n", + value ? "press" : "releas"); + keymap = value ? ppkb->fn_keymap + : ppkb->input->keycode; + ppkb->fn_state = value; + } + input_event(ppkb->input, EV_MSC, MSC_SCAN, code); + input_report_key(ppkb->input, keymap[code], value); + } + } + input_sync(ppkb->input); +} + +static int ppkb_open(struct input_dev *input) +{ + struct i2c_client *client = input_get_drvdata(input); + int ret; + + ret = ppkb_set_scan(client, true); + if (ret) + return ret; + + ppkb_update(client); + + return 0; +} + +static void ppkb_close(struct input_dev *input) +{ + struct i2c_client *client = input_get_drvdata(input); + + ppkb_set_scan(client, false); +} + +static irqreturn_t ppkb_irq_thread(int irq, void *data) +{ + struct i2c_client *client = data; + + ppkb_update(client); + + return IRQ_HANDLED; +} + +static int ppkb_probe(struct i2c_client *client) +{ + struct device *dev = &client->dev; + unsigned int phys_rows, phys_cols; + unsigned int map_rows, map_cols; + struct pinephone_keyboard *ppkb; + u8 info[PPKB_MATRIX_SIZE + 1]; + int ret; + + ret = i2c_smbus_read_i2c_block_data(client, 0, sizeof(info), info); + if (ret != sizeof(info)) + return dev_err_probe(dev, ret, "Failed to read device ID\n"); + + if (info[PPKB_DEVICE_ID_HI] != PPKB_DEVICE_ID_HI_VALUE || + info[PPKB_DEVICE_ID_LO] != PPKB_DEVICE_ID_LO_VALUE) + return dev_err_probe(dev, -ENODEV, "Unexpected device ID\n"); + + dev_info(dev, "Found keyboard firmware version %d.%d features %#x\n", + info[PPKB_FW_REVISION] >> 4, + info[PPKB_FW_REVISION] & 0xf, + info[PPKB_FW_FEATURES]); + + /* Disable scan by default to save power. */ + ret = ppkb_set_scan(client, false); + if (ret) + return ret; + + ret = matrix_keypad_parse_properties(dev, &map_rows, &map_cols); + if (ret) + return ret; + + phys_rows = info[PPKB_MATRIX_SIZE] & 0xf; + phys_cols = info[PPKB_MATRIX_SIZE] >> 4; + if (map_rows != phys_rows || map_cols != phys_cols) + return dev_err_probe(dev, -EINVAL, + "Keyboard size is %ux%u, but keymap is %ux%u\n", + phys_rows, phys_cols, map_rows, map_cols); + + /* Allocate two buffers, and include space for reading the CRC. */ + ppkb = devm_kzalloc(dev, struct_size(ppkb, buf, 2 * (phys_cols + 1)), GFP_KERNEL); + if (!ppkb) + return -ENOMEM; + + i2c_set_clientdata(client, ppkb); + + crc8_populate_msb(ppkb->crc_table, PPKB_CRC8_POLYNOMIAL); + ppkb->row_shift = get_count_order(map_cols); + ppkb->rows = map_rows; + ppkb->cols = map_cols; + + ppkb->input = devm_input_allocate_device(dev); + if (!ppkb->input) + return -ENOMEM; + + input_set_drvdata(ppkb->input, client); + + ppkb->input->name = "PinePhone Keyboard"; + ppkb->input->phys = DRV_NAME "/input0"; + ppkb->input->id.bustype = BUS_I2C; + ppkb->input->open = ppkb_open; + ppkb->input->close = ppkb_close; + + __set_bit(EV_MSC, ppkb->input->evbit); + __set_bit(EV_REP, ppkb->input->evbit); + + ret = matrix_keypad_build_keymap(NULL, "linux,fn-keymap", + map_rows, map_cols, NULL, ppkb->input); + if (ret) + return dev_err_probe(dev, ret, "Failed to build FN keymap\n"); + + ppkb->fn_keymap = ppkb->input->keycode; + + ret = matrix_keypad_build_keymap(NULL, "linux,keymap", + map_rows, map_cols, NULL, ppkb->input); + if (ret) + return dev_err_probe(dev, ret, "Failed to build keymap\n"); + + ret = input_register_device(ppkb->input); + if (ret) + return dev_err_probe(dev, ret, "Failed to register input\n"); + + ret = devm_request_threaded_irq(dev, client->irq, NULL, ppkb_irq_thread, + IRQF_ONESHOT, client->name, client); + if (ret) + return dev_err_probe(dev, ret, "Failed to request IRQ\n"); + + return 0; +} + +static const struct of_device_id ppkb_of_match[] = { + { .compatible = "pine64,pinephone-keyboard" }, + { } +}; +MODULE_DEVICE_TABLE(of, ppkb_of_match); + +static struct i2c_driver ppkb_driver = { + .probe_new = ppkb_probe, + .driver = { + .name = DRV_NAME, + .of_match_table = ppkb_of_match, + }, +}; +module_i2c_driver(ppkb_driver); + +MODULE_AUTHOR("Samuel Holland "); +MODULE_DESCRIPTION("Pine64 PinePhone keyboard driver"); +MODULE_LICENSE("GPL"); From patchwork Sat Jan 29 23:00:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 538153 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D3635C43217 for ; Sat, 29 Jan 2022 23:00:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353422AbiA2XA4 (ORCPT ); Sat, 29 Jan 2022 18:00:56 -0500 Received: from wout2-smtp.messagingengine.com ([64.147.123.25]:37521 "EHLO wout2-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353415AbiA2XAz (ORCPT ); Sat, 29 Jan 2022 18:00:55 -0500 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.west.internal (Postfix) with ESMTP id 5B2993200AB0; Sat, 29 Jan 2022 18:00:54 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Sat, 29 Jan 2022 18:00:55 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sholland.org; h= cc:cc:content-transfer-encoding:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm1; bh=OsXd9TOTU6tLC0fedQdL43FzE/5I2M M29uh21O4gXeM=; b=Vez7aT2ZeyVJzI2wzQCiL6PFdJ7cxsv3ZlbXlQSDpsGdK5 M3Ed/bXtsmoaSBW3gDc2wtwfVAEC78PWVyiNnRj5Y6t0Gkxe55dYODPS7Zvriz6Q 1K+9xnZSIWTpPDXw1DftyQKoYf2tQUqJqmWtr4OOPhz5pJLkEhV5ECJCSEsP1jKv 0/cwsieLn5JqEweXIwxQSsk57vplgXACXNLRO9U/iKzzT/ETjWPxXeIVgYyTCE/L rENXkBispQGNukb/ev6yTRphXucxtvRSXYRSgTqFw0Cocee9K/5zXChTtc+2mdTw vLZkmIoui+3jX93PNFRmXovErkxmbMW1yPl0V/MA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :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=fm1; bh=OsXd9T OTU6tLC0fedQdL43FzE/5I2MM29uh21O4gXeM=; b=c8FoUTA3Eb0b2H3N8ajBeZ T3zSY+MF1XGfT9oT8Z64oXxdt8KzLvERPSUDbpR6OjjpjmlyHwgn/YEU7GVhN4mw sJGGDYUTJVXsd4nYKUBw8hX/FGl6o7+CXSjUmmuELEXArXat8m4zQ10D0t2JCB/g yiiBpmVo7notUlY2/adDf9qbUY30kRELhnhUT3bNDM1CIzm3VOmHhz4L9TIz5fMJ Z5H4PSl1JNiOGOE8RePTkMaNE0zuwb+sZETcVVu8RemqW90S/1GJbvkg67M2dcMm HKV9dr00q6QVD2ES8Ld6Pc2cBU5fLY4WjZG2GKRB6io0G7LGbKcrjjZkpmlqa7Dw == X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvvddrfeejgddujedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefurghmuhgv lhcujfholhhlrghnugcuoehsrghmuhgvlhesshhhohhllhgrnhgurdhorhhgqeenucggtf frrghtthgvrhhnpeduhfejfedvhffgfeehtefghfeiiefgfeehgfdvvdevfeegjeehjedv gfejheeuieenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhroh hmpehsrghmuhgvlhesshhhohhllhgrnhgurdhorhhg X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 29 Jan 2022 18:00:53 -0500 (EST) From: Samuel Holland To: Dmitry Torokhov , linux-input@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Rob Herring , devicetree@vger.kernel.org, linux-i2c@vger.kernel.org, Wolfram Sang , Ondrej Jirman , Samuel Holland Subject: [PATCH 3/5] Input: pinephone-keyboard - Build in the default keymap Date: Sat, 29 Jan 2022 17:00:40 -0600 Message-Id: <20220129230043.12422-4-samuel@sholland.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220129230043.12422-1-samuel@sholland.org> References: <20220129230043.12422-1-samuel@sholland.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org The PinePhone keyboard comes with removable keys, but there is a default layout labeled from the factory. Use this keymap if none is provided in the devicetree. Suggested-by: Ondrej Jirman Signed-off-by: Samuel Holland --- drivers/input/keyboard/pinephone-keyboard.c | 128 +++++++++++++++++++- 1 file changed, 123 insertions(+), 5 deletions(-) diff --git a/drivers/input/keyboard/pinephone-keyboard.c b/drivers/input/keyboard/pinephone-keyboard.c index 9a071753fd91..8065bc3e101a 100644 --- a/drivers/input/keyboard/pinephone-keyboard.c +++ b/drivers/input/keyboard/pinephone-keyboard.c @@ -24,6 +24,113 @@ #define PPKB_SYS_CONFIG 0x20 #define PPKB_SYS_CONFIG_DISABLE_SCAN BIT(0) +#define PPKB_DEFAULT_KEYMAP_ROWS 6 +#define PPKB_DEFAULT_KEYMAP_COLS 12 + +static const uint32_t ppkb_default_fn_keymap[] = { + KEY(0, 0, KEY_FN_ESC), + KEY(0, 1, KEY_F1), + KEY(0, 2, KEY_F2), + KEY(0, 3, KEY_F3), + KEY(0, 4, KEY_F4), + KEY(0, 5, KEY_F5), + KEY(0, 6, KEY_F6), + KEY(0, 7, KEY_F7), + KEY(0, 8, KEY_F8), + KEY(0, 9, KEY_F9), + KEY(0, 10, KEY_F10), + KEY(0, 11, KEY_DELETE), + + KEY(2, 0, KEY_SYSRQ), + KEY(2, 10, KEY_INSERT), + + KEY(3, 0, KEY_LEFTSHIFT), + KEY(3, 8, KEY_HOME), + KEY(3, 9, KEY_UP), + KEY(3, 10, KEY_END), + + KEY(4, 1, KEY_LEFTCTRL), + KEY(4, 6, KEY_LEFT), + KEY(4, 8, KEY_RIGHT), + KEY(4, 9, KEY_DOWN), + + KEY(5, 2, KEY_FN), + KEY(5, 3, KEY_LEFTALT), + KEY(5, 5, KEY_RIGHTALT), +}; + +static const struct matrix_keymap_data ppkb_default_fn_keymap_data = { + .keymap = ppkb_default_fn_keymap, + .keymap_size = ARRAY_SIZE(ppkb_default_fn_keymap), +}; + +static const uint32_t ppkb_default_keymap[] = { + KEY(0, 0, KEY_ESC), + KEY(0, 1, KEY_1), + KEY(0, 2, KEY_2), + KEY(0, 3, KEY_3), + KEY(0, 4, KEY_4), + KEY(0, 5, KEY_5), + KEY(0, 6, KEY_6), + KEY(0, 7, KEY_7), + KEY(0, 8, KEY_8), + KEY(0, 9, KEY_9), + KEY(0, 10, KEY_0), + KEY(0, 11, KEY_BACKSPACE), + + KEY(1, 0, KEY_TAB), + KEY(1, 1, KEY_Q), + KEY(1, 2, KEY_W), + KEY(1, 3, KEY_E), + KEY(1, 4, KEY_R), + KEY(1, 5, KEY_T), + KEY(1, 6, KEY_Y), + KEY(1, 7, KEY_U), + KEY(1, 8, KEY_I), + KEY(1, 9, KEY_O), + KEY(1, 10, KEY_P), + KEY(1, 11, KEY_ENTER), + + KEY(2, 0, KEY_LEFTMETA), + KEY(2, 1, KEY_A), + KEY(2, 2, KEY_S), + KEY(2, 3, KEY_D), + KEY(2, 4, KEY_F), + KEY(2, 5, KEY_G), + KEY(2, 6, KEY_H), + KEY(2, 7, KEY_J), + KEY(2, 8, KEY_K), + KEY(2, 9, KEY_L), + KEY(2, 10, KEY_SEMICOLON), + + KEY(3, 0, KEY_LEFTSHIFT), + KEY(3, 1, KEY_Z), + KEY(3, 2, KEY_X), + KEY(3, 3, KEY_C), + KEY(3, 4, KEY_V), + KEY(3, 5, KEY_B), + KEY(3, 6, KEY_N), + KEY(3, 7, KEY_M), + KEY(3, 8, KEY_COMMA), + KEY(3, 9, KEY_DOT), + KEY(3, 10, KEY_SLASH), + + KEY(4, 1, KEY_LEFTCTRL), + KEY(4, 4, KEY_SPACE), + KEY(4, 6, KEY_APOSTROPHE), + KEY(4, 8, KEY_RIGHTBRACE), + KEY(4, 9, KEY_LEFTBRACE), + + KEY(5, 2, KEY_FN), + KEY(5, 3, KEY_LEFTALT), + KEY(5, 5, KEY_RIGHTALT), +}; + +static const struct matrix_keymap_data ppkb_default_keymap_data = { + .keymap = ppkb_default_keymap, + .keymap_size = ARRAY_SIZE(ppkb_default_keymap), +}; + struct pinephone_keyboard { struct input_dev *input; unsigned short *fn_keymap; @@ -151,6 +258,8 @@ static irqreturn_t ppkb_irq_thread(int irq, void *data) static int ppkb_probe(struct i2c_client *client) { + const struct matrix_keymap_data *fn_keymap_data = &ppkb_default_fn_keymap_data; + const struct matrix_keymap_data *keymap_data = &ppkb_default_keymap_data; struct device *dev = &client->dev; unsigned int phys_rows, phys_cols; unsigned int map_rows, map_cols; @@ -176,9 +285,18 @@ static int ppkb_probe(struct i2c_client *client) if (ret) return ret; - ret = matrix_keypad_parse_properties(dev, &map_rows, &map_cols); - if (ret) - return ret; + /* Allow the devicetree to override the default keymaps. */ + if (of_property_read_bool(dev->of_node, "linux,fn-keymap") || + of_property_read_bool(dev->of_node, "linux,keymap")) { + ret = matrix_keypad_parse_properties(dev, &map_rows, &map_cols); + if (ret) + return ret; + + fn_keymap_data = keymap_data = NULL; + } else { + map_rows = PPKB_DEFAULT_KEYMAP_ROWS; + map_cols = PPKB_DEFAULT_KEYMAP_COLS; + } phys_rows = info[PPKB_MATRIX_SIZE] & 0xf; phys_cols = info[PPKB_MATRIX_SIZE] >> 4; @@ -214,14 +332,14 @@ static int ppkb_probe(struct i2c_client *client) __set_bit(EV_MSC, ppkb->input->evbit); __set_bit(EV_REP, ppkb->input->evbit); - ret = matrix_keypad_build_keymap(NULL, "linux,fn-keymap", + ret = matrix_keypad_build_keymap(fn_keymap_data, "linux,fn-keymap", map_rows, map_cols, NULL, ppkb->input); if (ret) return dev_err_probe(dev, ret, "Failed to build FN keymap\n"); ppkb->fn_keymap = ppkb->input->keycode; - ret = matrix_keypad_build_keymap(NULL, "linux,keymap", + ret = matrix_keypad_build_keymap(keymap_data, "linux,keymap", map_rows, map_cols, NULL, ppkb->input); if (ret) return dev_err_probe(dev, ret, "Failed to build keymap\n"); From patchwork Sat Jan 29 23:00:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 538601 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EB2A4C433F5 for ; Sat, 29 Jan 2022 23:01:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353434AbiA2XBH (ORCPT ); Sat, 29 Jan 2022 18:01:07 -0500 Received: from wout2-smtp.messagingengine.com ([64.147.123.25]:37149 "EHLO wout2-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353408AbiA2XA6 (ORCPT ); Sat, 29 Jan 2022 18:00:58 -0500 Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id 1AFA63200AB0; Sat, 29 Jan 2022 18:00:57 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Sat, 29 Jan 2022 18:00:57 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sholland.org; h= cc:cc:content-transfer-encoding:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm1; bh=vrBXDS1ojZa8egDi/tODkXvIJSt4wA 5hxeMg5uTMGVc=; b=dqBoh0rGN3lCWXQoPNMje0UEEIjL02b6ctRVPl/QpcWO/X SUjW4f7bz0ZG6iAYCfce4LhZcqbhI95NkJUyTuNtsw7r+VjrlgUZPTswZVBK02He Jv04cBcuaXKixmiMjrPXHUYxtC/lOmpCFPUOjjo3CYAxB1UDQXMLRfEhDln5wjxS aIze9ekuhUa3xnrPNa7o/j5cLN5h1H/9pUDmBhHbm1lpGs2/l93GZPTOGaCy+PGr Ql8+TR4FyOUEOiwrx27L36FgmftJBlVIeJHgyXcufW9LlNkBiQ17zwjlEwXj/W8U astzxdNeSvWr/oKPmGVw837wsA1yEdt0mMZFGLtQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :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=fm1; bh=vrBXDS 1ojZa8egDi/tODkXvIJSt4wA5hxeMg5uTMGVc=; b=W++CoLDg/b5GV0OtwvlAhg 3fLX+x7Hk/mzIVM3Gyk4SNmTu6Sm7/PkMjXdoNQd0HKdr903uzpfU4H9sJrFg5/R A84jTlMvwDWSc5dnDtC+zS/9fDS5vUp17s3YxRAukD6BCZefEgeVJ8+OABoYQIwP /WfF6eeZMU2hQz6Zk7X9b1jDsIx4Z5Ku69M+oMcaDUlUJApRvM21ycjKhe9vriMZ VLgqWhiIUUfnQslYA3MpHsJsRYz6oXF3jkGcecZPnWSrcxp6VuKXPurTo8WeVUF1 7aFo3ais4d/lINh6XdGWTQOYtFG5+dyBBYC+HMbPniW9uLjUr4xA0Uf12F+OiHOA == X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvvddrfeejgdduieelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefurghmuhgv lhcujfholhhlrghnugcuoehsrghmuhgvlhesshhhohhllhgrnhgurdhorhhgqeenucggtf frrghtthgvrhhnpeduhfejfedvhffgfeehtefghfeiiefgfeehgfdvvdevfeegjeehjedv gfejheeuieenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhroh hmpehsrghmuhgvlhesshhhohhllhgrnhgurdhorhhg X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 29 Jan 2022 18:00:56 -0500 (EST) From: Samuel Holland To: Dmitry Torokhov , linux-input@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Rob Herring , devicetree@vger.kernel.org, linux-i2c@vger.kernel.org, Wolfram Sang , Ondrej Jirman , Samuel Holland Subject: [PATCH 4/5] Input: pinephone-keyboard - Support the proxied I2C bus Date: Sat, 29 Jan 2022 17:00:41 -0600 Message-Id: <20220129230043.12422-5-samuel@sholland.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220129230043.12422-1-samuel@sholland.org> References: <20220129230043.12422-1-samuel@sholland.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org The PinePhone keyboard case contains a battery managed by an integrated power bank IC. The power bank IC communicates over I2C, and the keyboard MCU firmware provides an interface to read and write its registers. Let's use this interface to implement a SMBus adapter, so we can reuse the driver for the power bank IC. Signed-off-by: Samuel Holland --- drivers/input/keyboard/pinephone-keyboard.c | 73 +++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/drivers/input/keyboard/pinephone-keyboard.c b/drivers/input/keyboard/pinephone-keyboard.c index 8065bc3e101a..7d2e16e588a0 100644 --- a/drivers/input/keyboard/pinephone-keyboard.c +++ b/drivers/input/keyboard/pinephone-keyboard.c @@ -3,6 +3,7 @@ // Copyright (C) 2021-2022 Samuel Holland #include +#include #include #include #include @@ -23,6 +24,11 @@ #define PPKB_SCAN_DATA 0x08 #define PPKB_SYS_CONFIG 0x20 #define PPKB_SYS_CONFIG_DISABLE_SCAN BIT(0) +#define PPKB_SYS_SMBUS_COMMAND 0x21 +#define PPKB_SYS_SMBUS_DATA 0x22 +#define PPKB_SYS_COMMAND 0x23 +#define PPKB_SYS_COMMAND_SMBUS_READ 0x91 +#define PPKB_SYS_COMMAND_SMBUS_WRITE 0xa1 #define PPKB_DEFAULT_KEYMAP_ROWS 6 #define PPKB_DEFAULT_KEYMAP_COLS 12 @@ -132,6 +138,7 @@ static const struct matrix_keymap_data ppkb_default_keymap_data = { }; struct pinephone_keyboard { + struct i2c_adapter adapter; struct input_dev *input; unsigned short *fn_keymap; u8 crc_table[CRC8_TABLE_SIZE]; @@ -143,6 +150,57 @@ struct pinephone_keyboard { u8 buf[]; }; +static int ppkb_adap_smbus_xfer(struct i2c_adapter *adap, u16 addr, + unsigned short flags, char read_write, + u8 command, int size, + union i2c_smbus_data *data) +{ + struct i2c_client *client = adap->algo_data; + u8 buf[3]; + int ret; + + buf[0] = command; + buf[1] = data->byte; + buf[2] = read_write == I2C_SMBUS_READ ? PPKB_SYS_COMMAND_SMBUS_READ + : PPKB_SYS_COMMAND_SMBUS_WRITE; + + ret = i2c_smbus_write_i2c_block_data(client, PPKB_SYS_SMBUS_COMMAND, + sizeof(buf), buf); + if (ret) + return ret; + + /* Read back the command status until it passes or fails. */ + do { + usleep_range(300, 500); + ret = i2c_smbus_read_byte_data(client, PPKB_SYS_COMMAND); + } while (ret == buf[2]); + if (ret < 0) + return ret; + /* Commands return 0x00 on success and 0xff on failure. */ + if (ret) + return -EIO; + + if (read_write == I2C_SMBUS_READ) { + ret = i2c_smbus_read_byte_data(client, PPKB_SYS_SMBUS_DATA); + if (ret < 0) + return ret; + + data->byte = ret; + } + + return 0; +} + +static u32 ppkg_adap_functionality(struct i2c_adapter *adap) +{ + return I2C_FUNC_SMBUS_BYTE_DATA; +} + +static const struct i2c_algorithm ppkb_adap_algo = { + .smbus_xfer = ppkb_adap_smbus_xfer, + .functionality = ppkg_adap_functionality, +}; + static int ppkb_set_scan(struct i2c_client *client, bool enable) { struct device *dev = &client->dev; @@ -265,6 +323,7 @@ static int ppkb_probe(struct i2c_client *client) unsigned int map_rows, map_cols; struct pinephone_keyboard *ppkb; u8 info[PPKB_MATRIX_SIZE + 1]; + struct device_node *i2c_bus; int ret; ret = i2c_smbus_read_i2c_block_data(client, 0, sizeof(info), info); @@ -312,6 +371,20 @@ static int ppkb_probe(struct i2c_client *client) i2c_set_clientdata(client, ppkb); + i2c_bus = of_get_child_by_name(dev->of_node, "i2c-bus"); + if (i2c_bus) { + ppkb->adapter.owner = THIS_MODULE; + ppkb->adapter.algo = &ppkb_adap_algo; + ppkb->adapter.algo_data = client; + ppkb->adapter.dev.parent = dev; + ppkb->adapter.dev.of_node = i2c_bus; + strscpy(ppkb->adapter.name, DRV_NAME, sizeof(ppkb->adapter.name)); + + ret = devm_i2c_add_adapter(dev, &ppkb->adapter); + if (ret) + return dev_err_probe(dev, ret, "Failed to add I2C adapter\n"); + } + crc8_populate_msb(ppkb->crc_table, PPKB_CRC8_POLYNOMIAL); ppkb->row_shift = get_count_order(map_cols); ppkb->rows = map_rows; From patchwork Sat Jan 29 23:00:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 538152 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AEE60C433EF for ; Sat, 29 Jan 2022 23:01:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353492AbiA2XBJ (ORCPT ); Sat, 29 Jan 2022 18:01:09 -0500 Received: from wout2-smtp.messagingengine.com ([64.147.123.25]:41237 "EHLO wout2-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353449AbiA2XBB (ORCPT ); Sat, 29 Jan 2022 18:01:01 -0500 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id CEDFA3200C6B; Sat, 29 Jan 2022 18:00:59 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Sat, 29 Jan 2022 18:01:00 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sholland.org; h= cc:cc:content-transfer-encoding:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm1; bh=KaJi6i1rcpG62yHLxKEhKW/9uykM7g g7A3y7usLAY7o=; b=oVF8yBuw077qKkvBIeh/qAs4mNm9itM9TlGO/vZrmoU4TU 9twmdPOAGna6DE/QoGOVOzgkN8UHe3R27egreQ27tQJJuK0SDOf+1ZPxaYomaIMQ EcDLYvLFyxFpbQgBESAlCSHfc8Z/vZfjbPYScgmqYxEeDYG8B/xbrRXg1xxmPk3H 2bFQZAROxBkMzTosbWy74aVUISfgrzTCrw0sG0UWEfaXNytWvipwMcXwDqNrJ/Xq FnpyS1Vy18lAaJEPDW2vlNeVsCkqqq97AfomPWIBUNR94FbqlotgUs8e3XFdSdQV qkxiHen9sTgmJfsNMQngzRt2dJbjL1qaSTCuKa5A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :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=fm1; bh=KaJi6i 1rcpG62yHLxKEhKW/9uykM7gg7A3y7usLAY7o=; b=fOo321VpFKHEDGKtZDhAdF itndNBHxmgZ79bb2owxng3DMR2PWDOfYk3ZayN+kxCdcCxjWpBw4ibcdnO7ZsWxI HSKbRVccrugHqUJt8hINAej+sYbmj3TWsX7DiUbcNmis/qgDWB+YP/jCD21J74NE QWUMzeZ0znPUHVbkUierrlTF4pzvbBImuhlEoyhzrZYCRF0+JzCbpd1gP9h/S7J1 hq5hpvyQ6oaBdL/nOa3zHTXPJAOYA0+FaTejQOKIKddnTp3pwF3uTgDuYNIWPOuf I/TAQZQ5C+UlPkefQ6bxgXVbQgGTA4fe0UzB+P8hPnZoXZNdIwkRm3QrcuCB/tUw == X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvvddrfeejgdduieelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefurghmuhgv lhcujfholhhlrghnugcuoehsrghmuhgvlhesshhhohhllhgrnhgurdhorhhgqeenucggtf frrghtthgvrhhnpeduhfejfedvhffgfeehtefghfeiiefgfeehgfdvvdevfeegjeehjedv gfejheeuieenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhroh hmpehsrghmuhgvlhesshhhohhllhgrnhgurdhorhhg X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 29 Jan 2022 18:00:58 -0500 (EST) From: Samuel Holland To: Dmitry Torokhov , linux-input@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Rob Herring , devicetree@vger.kernel.org, linux-i2c@vger.kernel.org, Wolfram Sang , Ondrej Jirman , Samuel Holland Subject: [PATCH 5/5] [DO NOT MERGE] arm64: dts: allwinner: pinephone: Add keyboard Date: Sat, 29 Jan 2022 17:00:42 -0600 Message-Id: <20220129230043.12422-6-samuel@sholland.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220129230043.12422-1-samuel@sholland.org> References: <20220129230043.12422-1-samuel@sholland.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org The official PinePhone keyboard accessory connects to the phone's POGO pins for I2C and interrupts. It has an Injoinic IP5209 power bank IC connected to the keyboard's internal I2C bus. Signed-off-by: Samuel Holland --- .../dts/allwinner/sun50i-a64-pinephone.dtsi | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/arch/arm64/boot/dts/allwinner/sun50i-a64-pinephone.dtsi b/arch/arm64/boot/dts/allwinner/sun50i-a64-pinephone.dtsi index 87847116ab6d..2fa1bdf8aa63 100644 --- a/arch/arm64/boot/dts/allwinner/sun50i-a64-pinephone.dtsi +++ b/arch/arm64/boot/dts/allwinner/sun50i-a64-pinephone.dtsi @@ -208,6 +208,24 @@ accelerometer@68 { /* Connected to pogo pins (external spring based pinheader for user addons) */ &i2c2 { status = "okay"; + + keyboard@15 { + compatible = "pine64,pinephone-keyboard"; + reg = <0x15>; + interrupt-parent = <&r_pio>; + interrupts = <0 12 IRQ_TYPE_EDGE_FALLING>; /* PL12 */ + wakeup-source; + + i2c-bus { + #address-cells = <1>; + #size-cells = <0>; + + charger@75 { + compatible = "injoinic,ip5209"; + reg = <0x75>; + }; + }; + }; }; &lradc {