From patchwork Mon Aug 19 04:58:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13767903 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 635EEC52D7C for ; Mon, 19 Aug 2024 05:03:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=GbiMwPq3Y/nPoKn5NoCTFyPZoEyShBkGNc/6+CRLeBY=; b=joqolLmDMCdYTyU5ZjseYvcYMx ht7LeLkb4aegb/Oy/0IvZvWrloIIEQWLIub3aWiCngrjYJ13ojIuUWYd5sQ/TFHVEjvASNlO7n/9x 3A/Id2uqDVVXPWMG120y0NnRHAaKQkZtb9g1Vh1CxcCCiQwhpqi9iiH9fEPImg1KwJg+kebMhTFHC uXCTKDQoipsvTkPZg7nmb3as86wK5EFiUA9xkrbA5wz+FLA8XlCwxfoFYowaSxc4uClunRgP+DGN7 Uvd9mNJkGHk20jCAed48OXEb0j+Z2EIP/n4G/8D/VwbjhbUv81u4c5AlAY8+9umz1LqxBSpPD6Qy/ GwPrRwZQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sfuYW-00000000Mu6-3awJ; Mon, 19 Aug 2024 05:03:48 +0000 Received: from mail-pg1-x52f.google.com ([2607:f8b0:4864:20::52f]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sfuTS-00000000LXw-37bl for linux-arm-kernel@lists.infradead.org; Mon, 19 Aug 2024 04:58:36 +0000 Received: by mail-pg1-x52f.google.com with SMTP id 41be03b00d2f7-6e7b121be30so2565094a12.1 for ; Sun, 18 Aug 2024 21:58:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724043514; x=1724648314; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=GbiMwPq3Y/nPoKn5NoCTFyPZoEyShBkGNc/6+CRLeBY=; b=FOAwheCOeZg0AhOh0g6s/tu2RU5suWecimiEbd2fdHFKcZ6oraJ9HVfDH1MxqhFljO ++2ieR4ZSa8Uru5MzxrPdYjwta+fxvDscXTwyg28hy+eEM5VQ1Z6BcZsDt3sWGlAf35C AySgyRqX6x6edOqtTHS0v4EfxgvU83yO69mcciaRLCpTo1PZH4dCtatPhl1Rpx2TWzDI yideKC4LMMnd4fRfTUKk79JJ6VdEFXBAbHUUmlTQ8NzYu3coyi1LfVQpaZWLxeBEkKau YIg21erdhOUT1kbTIaeTtyyermGgxPXIrC9ojUiX6y+OTo4/1N65DjZIUDIWufjTsyYQ YOMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724043514; x=1724648314; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GbiMwPq3Y/nPoKn5NoCTFyPZoEyShBkGNc/6+CRLeBY=; b=hWEPYqojAnt2J3QNUbO/Ao78fbe9iEqGt7mhdsQpK2lTkrpeEseKawnW11nAz3QQLf ntoIzi+PnSPxmoz5OTMvd7XlcrCbmbrqAqQYGND7T+JI4BKMXQfKOhczz9706ZG40jfI 4crpk1DIIQSKW3O6HZDcZLL1JZhKuHhlisgByoaSG+6vGeKLRJyvBXpX3BeGQTiYuY8g rftpk6iwDnnKpImZLAIVMPDlfAei32OQA4avUP9ct7kF4ZwJIidgVsQHIh6izluA81Pr axpjCeJxsFGsxOEMZvdaipBg+gBMtsarSKKwTfEQISMqaQd6Lob/dKJw6gXM9rWxKoMy mNUA== X-Forwarded-Encrypted: i=1; AJvYcCWq4hwTckKsds12eTx3pSQ/Pg3BWlof2e0w3mBfZSlDE3dLSxGKgbtCyXsB98DxJ23ZT1qHEWoFNq4zIjCeLjrxZP1ZziblS0wjefxQTF0KBQBx5Fk= X-Gm-Message-State: AOJu0YwG0MoM0usA5QGsxhs9ahAgOl7tVJ26wyopL6HkxDUVEpCII+Ij pboVCoR0NEdULcaHns4AdANPfr8oPpSI9HfvQa/tKulDlhH9p/Mf X-Google-Smtp-Source: AGHT+IFp6g7gj1q9g/hAQPH/hWIvrIWdD8isSKVV2meWPkpCAa22AHAmY/T8N9X055w0cjPiBY+Frw== X-Received: by 2002:a05:6a20:2d29:b0:1c6:ac08:8dd2 with SMTP id adf61e73a8af0-1c904f913aemr10517941637.15.1724043513929; Sun, 18 Aug 2024 21:58:33 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:4eb5:4500:6efc:6c24]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-202068497b4sm43483445ad.269.2024.08.18.21.58.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Aug 2024 21:58:33 -0700 (PDT) From: Dmitry Torokhov To: Arnd Bergmann , Mark Brown , Krzysztof Kozlowski Cc: linux-input@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, patches@opensource.cirrus.com Subject: [PATCH 07/14] Input: samsung-keypad - use per-chip parameters Date: Sun, 18 Aug 2024 21:58:04 -0700 Message-ID: <20240819045813.2154642-8-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.46.0.184.g6999bdac58-goog In-Reply-To: <20240819045813.2154642-1-dmitry.torokhov@gmail.com> References: <20240819045813.2154642-1-dmitry.torokhov@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240818_215834_803707_0192664F X-CRM114-Status: GOOD ( 19.37 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Instead of doing conditional logic based on the chip type, define per-chip parameter structure, and reference it in the match data (either of_device_id or platform_device_id). Signed-off-by: Dmitry Torokhov Reviewed-by: Krzysztof Kozlowski --- drivers/input/keyboard/samsung-keypad.c | 61 +++++++++++++++---------- 1 file changed, 37 insertions(+), 24 deletions(-) diff --git a/drivers/input/keyboard/samsung-keypad.c b/drivers/input/keyboard/samsung-keypad.c index 71f5b85b02bd..ccc1186e43b6 100644 --- a/drivers/input/keyboard/samsung-keypad.c +++ b/drivers/input/keyboard/samsung-keypad.c @@ -44,8 +44,7 @@ #define S5PV210_KEYIFSTSCLR_R_INT_OFFSET 16 /* SAMSUNG_KEYIFCOL */ -#define SAMSUNG_KEYIFCOL_MASK (0xff << 0) -#define S5PV210_KEYIFCOLEN_MASK (0xff << 8) +#define SAMSUNG_KEYIFCOL_MASK 0xff /* SAMSUNG_KEYIFROW */ #define SAMSUNG_KEYIFROW_MASK (0xff << 0) @@ -54,12 +53,12 @@ /* SAMSUNG_KEYIFFC */ #define SAMSUNG_KEYIFFC_MASK (0x3ff << 0) -enum samsung_keypad_type { - KEYPAD_TYPE_SAMSUNG, - KEYPAD_TYPE_S5PV210, +struct samsung_chip_info { + unsigned int column_shift; }; struct samsung_keypad { + const struct samsung_chip_info *chip; struct input_dev *input_dev; struct platform_device *pdev; struct clk *clk; @@ -68,7 +67,6 @@ struct samsung_keypad { bool stopped; bool wake_enabled; int irq; - enum samsung_keypad_type type; unsigned int row_shift; unsigned int rows; unsigned int cols; @@ -83,13 +81,8 @@ static void samsung_keypad_scan(struct samsung_keypad *keypad, unsigned int val; for (col = 0; col < keypad->cols; col++) { - if (keypad->type == KEYPAD_TYPE_S5PV210) { - val = S5PV210_KEYIFCOLEN_MASK; - val &= ~(1 << col) << 8; - } else { - val = SAMSUNG_KEYIFCOL_MASK; - val &= ~(1 << col); - } + val = SAMSUNG_KEYIFCOL_MASK & ~(1 << col); + val <<= keypad->chip->column_shift; writel(val, keypad->base + SAMSUNG_KEYIFCOL); mdelay(1); @@ -321,6 +314,7 @@ static int samsung_keypad_probe(struct platform_device *pdev) { const struct samsung_keypad_platdata *pdata; const struct matrix_keymap_data *keymap_data; + const struct platform_device_id *id; struct samsung_keypad *keypad; struct resource *res; struct input_dev *input_dev; @@ -385,11 +379,17 @@ static int samsung_keypad_probe(struct platform_device *pdev) keypad->stopped = true; init_waitqueue_head(&keypad->wait); - if (pdev->dev.of_node) - keypad->type = of_device_is_compatible(pdev->dev.of_node, - "samsung,s5pv210-keypad"); - else - keypad->type = platform_get_device_id(pdev)->driver_data; + keypad->chip = device_get_match_data(&pdev->dev); + if (!keypad->chip) { + id = platform_get_device_id(pdev); + if (id) + keypad->chip = (const void *)id->driver_data; + } + + if (!keypad->chip) { + dev_err(&pdev->dev, "Unable to determine chip type"); + return -EINVAL; + } input_dev->name = pdev->name; input_dev->id.bustype = BUS_HOST; @@ -551,11 +551,24 @@ static const struct dev_pm_ops samsung_keypad_pm_ops = { samsung_keypad_runtime_resume, NULL) }; +static const struct samsung_chip_info samsung_s3c6410_chip_info = { + .column_shift = 0, +}; + +static const struct samsung_chip_info samsung_s5pv210_chip_info = { + .column_shift = 8, +}; + #ifdef CONFIG_OF static const struct of_device_id samsung_keypad_dt_match[] = { - { .compatible = "samsung,s3c6410-keypad" }, - { .compatible = "samsung,s5pv210-keypad" }, - {}, + { + .compatible = "samsung,s3c6410-keypad", + .data = &samsung_s3c6410_chip_info, + }, { + .compatible = "samsung,s5pv210-keypad", + .data = &samsung_s5pv210_chip_info, + }, + { } }; MODULE_DEVICE_TABLE(of, samsung_keypad_dt_match); #endif @@ -563,12 +576,12 @@ MODULE_DEVICE_TABLE(of, samsung_keypad_dt_match); static const struct platform_device_id samsung_keypad_driver_ids[] = { { .name = "samsung-keypad", - .driver_data = KEYPAD_TYPE_SAMSUNG, + .driver_data = (kernel_ulong_t)&samsung_s3c6410_chip_info, }, { .name = "s5pv210-keypad", - .driver_data = KEYPAD_TYPE_S5PV210, + .driver_data = (kernel_ulong_t)&samsung_s5pv210_chip_info, }, - { }, + { } }; MODULE_DEVICE_TABLE(platform, samsung_keypad_driver_ids);