From patchwork Sat Sep 23 17:19:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Biju Das X-Patchwork-Id: 143962 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp291583vqu; Sat, 23 Sep 2023 10:19:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHRdoB9ZrNfeUcUrrZ6jdRxOeV4Jmy9flFiw595Id0ubzoQJvGW1M3ateDTMxykpV57Ecp+ X-Received: by 2002:a17:902:7885:b0:1b8:1bac:3782 with SMTP id q5-20020a170902788500b001b81bac3782mr2470778pll.6.1695489585601; Sat, 23 Sep 2023 10:19:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695489585; cv=none; d=google.com; s=arc-20160816; b=IYpssTaLvX+Azcalw5O00tY9iheNGErbB9n55NSggC4oDpLNhCOj24q9wjTJXtDPys 0wnCB81BlYkDvWnN27F8qSN7mJ7QdH9meKoNhYiEltijokg6mPPS57Omy6ltj7C1TQfR Wl7lbYs8zPPMtXGIxAeyH9IxTOrxPpUoVbQpqGrOa144xw+F6zty+Uap5eMHZ1xm8eMO +fwaBqT+6ZIGSGH1jF4gCOwHLmK/oA/sgML0keJ0yYS+yq78wgtVXnbGHD+ML7zpQ3Pn +E6cqfc5BSvTWQmJf8waCloeMeBKu9f81n5k0HTOwCPVOO/1pM6IILgTV7ZPXzGD46ed EAWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=9YZP+4/HYnJ2f+lPCJLsge1Btdfo3+erLEDqkHkO8zw=; fh=r6Qhp0LT7Kf9zXNJMg+nKK/99bcL/1J+D8BN6ItCqm4=; b=hL0wExbKUVFSui9VeJNBuczdiOLDxWmGQnVXinJg4GT+5Tzh3wVOfT5e10Vl3NPaBZ k0a+tWIBZYRp+jLXFrkZDRxdt/kmhmSgAOd+WZre1ujuYoDqDMAwE2YmTebzW8rRDdQf XrC8epFfYlyPspOnaznnIwXUrgVkpl1DmsXserJurRPLKDvMykBsvsmnvlCvbNeC9pyh p/MpLIdkPwHTY4Kdyo2t72KYrO6EjHdgpcOQ+ioPzmodEjL1qmIe1tDvGGPLxNLMU7gl YX2ivVUy8IaJ2Id5sSe/qNk8SwyjD/hn4tGIKF65+dUCzAfGN0IZZcpylq2TBqsn/lYR g1FQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=renesas.com Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id t4-20020a170902e1c400b001c5bd53fa38si5988504pla.99.2023.09.23.10.19.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Sep 2023 10:19:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=renesas.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 6300C80A64EF; Sat, 23 Sep 2023 10:19:43 -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 S230358AbjIWRTi (ORCPT + 30 others); Sat, 23 Sep 2023 13:19:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49328 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229513AbjIWRTh (ORCPT ); Sat, 23 Sep 2023 13:19:37 -0400 Received: from relmlie5.idc.renesas.com (relmlor1.renesas.com [210.160.252.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 31265AF; Sat, 23 Sep 2023 10:19:31 -0700 (PDT) X-IronPort-AV: E=Sophos;i="6.03,171,1694703600"; d="scan'208";a="176996638" Received: from unknown (HELO relmlir5.idc.renesas.com) ([10.200.68.151]) by relmlie5.idc.renesas.com with ESMTP; 24 Sep 2023 02:19:30 +0900 Received: from localhost.localdomain (unknown [10.226.92.12]) by relmlir5.idc.renesas.com (Postfix) with ESMTP id 42DBA40001D2; Sun, 24 Sep 2023 02:19:27 +0900 (JST) From: Biju Das To: Pavel Machek , Lee Jones Cc: Biju Das , linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org, Biju Das , Andy Shevchenko Subject: [PATCH v2 1/2] leds: pca955x: Convert enum->pointer for data in the match tables Date: Sat, 23 Sep 2023 18:19:20 +0100 Message-Id: <20230923171921.53503-2-biju.das.jz@bp.renesas.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230923171921.53503-1-biju.das.jz@bp.renesas.com> References: <20230923171921.53503-1-biju.das.jz@bp.renesas.com> MIME-Version: 1.0 X-Spam-Status: No, score=2.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no 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, 23 Sep 2023 10:19:43 -0700 (PDT) X-Spam-Level: ** X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777849687608666670 X-GMAIL-MSGID: 1777849687608666670 Convert enum->pointer for data in the match tables, so that device_get_match_data() can do match against OF/ACPI/I2C tables, once i2c bus type match support added to it. Replace enum->struct *pca955x_chipdefs for data in the match table. Simplify the probe() by replacing device_get_match_data() and ID lookup for retrieving data by i2c_get_match_data(). While at it, add const definition to pca955x_chipdefs[]. Signed-off-by: Biju Das Reviewed-by: Lee Jones Reviewed-by: Andy Shevchenko --- v1->v2: * Rebased to leds-next. * Added Rb tag from Lee Jones. --- drivers/leds/leds-pca955x.c | 49 ++++++++++++++----------------------- 1 file changed, 18 insertions(+), 31 deletions(-) diff --git a/drivers/leds/leds-pca955x.c b/drivers/leds/leds-pca955x.c index 1d7fa0cd97bf..891cfc05301d 100644 --- a/drivers/leds/leds-pca955x.c +++ b/drivers/leds/leds-pca955x.c @@ -76,7 +76,7 @@ struct pca955x_chipdef { int slv_addr_shift; /* Number of bits to ignore */ }; -static struct pca955x_chipdef pca955x_chipdefs[] = { +static const struct pca955x_chipdef pca955x_chipdefs[] = { [pca9550] = { .bits = 2, .slv_addr = /* 110000x */ 0x60, @@ -105,11 +105,11 @@ static struct pca955x_chipdef pca955x_chipdefs[] = { }; static const struct i2c_device_id pca955x_id[] = { - { "pca9550", pca9550 }, - { "pca9551", pca9551 }, - { "pca9552", pca9552 }, - { "ibm-pca9552", ibm_pca9552 }, - { "pca9553", pca9553 }, + { "pca9550", (kernel_ulong_t)&pca955x_chipdefs[pca9550] }, + { "pca9551", (kernel_ulong_t)&pca955x_chipdefs[pca9551] }, + { "pca9552", (kernel_ulong_t)&pca955x_chipdefs[pca9552] }, + { "ibm-pca9552", (kernel_ulong_t)&pca955x_chipdefs[ibm_pca9552] }, + { "pca9553", (kernel_ulong_t)&pca955x_chipdefs[pca9553] }, { } }; MODULE_DEVICE_TABLE(i2c, pca955x_id); @@ -117,7 +117,7 @@ MODULE_DEVICE_TABLE(i2c, pca955x_id); struct pca955x { struct mutex lock; struct pca955x_led *leds; - struct pca955x_chipdef *chipdef; + const struct pca955x_chipdef *chipdef; struct i2c_client *client; unsigned long active_pins; #ifdef CONFIG_LEDS_PCA955X_GPIO @@ -415,7 +415,7 @@ static int pca955x_gpio_direction_output(struct gpio_chip *gc, #endif /* CONFIG_LEDS_PCA955X_GPIO */ static struct pca955x_platform_data * -pca955x_get_pdata(struct i2c_client *client, struct pca955x_chipdef *chip) +pca955x_get_pdata(struct i2c_client *client, const struct pca955x_chipdef *chip) { struct pca955x_platform_data *pdata; struct pca955x_led *led; @@ -458,11 +458,11 @@ pca955x_get_pdata(struct i2c_client *client, struct pca955x_chipdef *chip) } static const struct of_device_id of_pca955x_match[] = { - { .compatible = "nxp,pca9550", .data = (void *)pca9550 }, - { .compatible = "nxp,pca9551", .data = (void *)pca9551 }, - { .compatible = "nxp,pca9552", .data = (void *)pca9552 }, - { .compatible = "ibm,pca9552", .data = (void *)ibm_pca9552 }, - { .compatible = "nxp,pca9553", .data = (void *)pca9553 }, + { .compatible = "nxp,pca9550", .data = &pca955x_chipdefs[pca9550] }, + { .compatible = "nxp,pca9551", .data = &pca955x_chipdefs[pca9551] }, + { .compatible = "nxp,pca9552", .data = &pca955x_chipdefs[pca9552] }, + { .compatible = "ibm,pca9552", .data = &pca955x_chipdefs[ibm_pca9552] }, + { .compatible = "nxp,pca9553", .data = &pca955x_chipdefs[pca9553] }, {}, }; MODULE_DEVICE_TABLE(of, of_pca955x_match); @@ -471,7 +471,7 @@ static int pca955x_probe(struct i2c_client *client) { struct pca955x *pca955x; struct pca955x_led *pca955x_led; - struct pca955x_chipdef *chip; + const struct pca955x_chipdef *chip; struct led_classdev *led; struct led_init_data init_data; struct i2c_adapter *adapter; @@ -480,24 +480,11 @@ static int pca955x_probe(struct i2c_client *client) bool set_default_label = false; bool keep_pwm = false; char default_label[8]; - enum pca955x_type chip_type; - const void *md = device_get_match_data(&client->dev); - - if (md) { - chip_type = (enum pca955x_type)(uintptr_t)md; - } else { - const struct i2c_device_id *id = i2c_match_id(pca955x_id, - client); - - if (id) { - chip_type = (enum pca955x_type)id->driver_data; - } else { - dev_err(&client->dev, "unknown chip\n"); - return -ENODEV; - } - } - chip = &pca955x_chipdefs[chip_type]; + chip = i2c_get_match_data(client); + if (!chip) + return dev_err_probe(&client->dev, -ENODEV, "unknown chip\n"); + adapter = client->adapter; pdata = dev_get_platdata(&client->dev); if (!pdata) { From patchwork Sat Sep 23 17:19:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Biju Das X-Patchwork-Id: 143961 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp291562vqu; Sat, 23 Sep 2023 10:19:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFDgbwKkNOWByP6nutdhTuTtWEIC4/F+F7KbLeUtyDwG6evt4JWMEYIJHIHzoWFr7TlH3/P X-Received: by 2002:a05:6e02:1a09:b0:34f:cbc8:389e with SMTP id s9-20020a056e021a0900b0034fcbc8389emr3230454ild.10.1695489584015; Sat, 23 Sep 2023 10:19:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695489583; cv=none; d=google.com; s=arc-20160816; b=br2Vk3aXHgrsc67VeZYt+UpSO2NhodiQk4DSd7KoE/CzuCvpKgry47gCst70dNE9MF g6vdffdHH1QfBPFCQ6/wQTRec8zdDE7NKXbP/6qvps8b+h12gd+kjCzPPHUGDAUPzwjZ WK4Pz6gSlzv8Yy+Y+MDIKFPAungjj8oTkn99ACAt9gQgn4b/Tv86QfSD5YXdEDhioOSj RoaUOCNDEthFI9TFYprlpVuyCo280l0vvaxd3xGYUBtIU2PtJXgOtLQJ+MFRg+DL7gJc q07vBVLyzObTBmB0f75x7yQFM5tw6ofk0v5JULZO+VXq2c1xJCL74kd2YSPchf3w2bPl 2Vng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=By7hXJUe9XV3OJz5Cu+hUEcxHAS+sR3e1yWlSo82QI8=; fh=r6Qhp0LT7Kf9zXNJMg+nKK/99bcL/1J+D8BN6ItCqm4=; b=s8YdhYtIhqQLrq4eT4sA2gx2hC8YYxwI9gwMWNMl50WchfpUH6v+GF9/jxhJ/z2zAL bsYXZMrwlNdUxAvuEXJmpUZf+CWhfxgUQJQTzC4Wewiy9DcV+ALaZpPWeu68pqHlTlbG pvXAsEpWna6HiHRjgZ9REkqLW4xATCrTzonci2YeGMQfFJVh6uDpHwOHhkLOvC0qy70F A3m+HlVQqoTlAgEcl2usJApzHtb/n9raxZfz+iO/ePtYwKx2FFen16/MTbZ2/4bVEof2 fQn67K8CXJlnespY+l/hdUhDaflB/2YsqMQsBOr8I7PaS8qttERaAPqQ59E//i9jkuNb vX8A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=renesas.com Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id r20-20020a6560d4000000b00564f223ef05si6291871pgv.11.2023.09.23.10.19.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Sep 2023 10:19:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=renesas.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 508B0819A6BF; Sat, 23 Sep 2023 10:19:43 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230110AbjIWRTn (ORCPT + 30 others); Sat, 23 Sep 2023 13:19:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230369AbjIWRTj (ORCPT ); Sat, 23 Sep 2023 13:19:39 -0400 Received: from relmlie5.idc.renesas.com (relmlor1.renesas.com [210.160.252.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 91978100; Sat, 23 Sep 2023 10:19:33 -0700 (PDT) X-IronPort-AV: E=Sophos;i="6.03,171,1694703600"; d="scan'208";a="176996641" Received: from unknown (HELO relmlir5.idc.renesas.com) ([10.200.68.151]) by relmlie5.idc.renesas.com with ESMTP; 24 Sep 2023 02:19:33 +0900 Received: from localhost.localdomain (unknown [10.226.92.12]) by relmlir5.idc.renesas.com (Postfix) with ESMTP id 1D53F4000AAE; Sun, 24 Sep 2023 02:19:30 +0900 (JST) From: Biju Das To: Pavel Machek , Lee Jones Cc: Biju Das , linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org, Biju Das , Andy Shevchenko Subject: [PATCH v2 2/2] leds: pca955x: Cleanup OF/ID table terminators Date: Sat, 23 Sep 2023 18:19:21 +0100 Message-Id: <20230923171921.53503-3-biju.das.jz@bp.renesas.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230923171921.53503-1-biju.das.jz@bp.renesas.com> References: <20230923171921.53503-1-biju.das.jz@bp.renesas.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Sat, 23 Sep 2023 10:19:43 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777849685955390642 X-GMAIL-MSGID: 1777849685955390642 Some cleanups: * Remove the trailing comma in the terminator entry for the OF table making code robust against (theoretical) misrebases or other similar things where the new entry goes _after_ the termination without the compiler noticing. * Drop a space from terminator entry for ID table. While at it, move OF/ID table near to the user. Signed-off-by: Biju Das Reviewed-by: Andy Shevchenko --- v2: * New patch. --- drivers/leds/leds-pca955x.c | 40 ++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/drivers/leds/leds-pca955x.c b/drivers/leds/leds-pca955x.c index 891cfc05301d..94a9f8a54b35 100644 --- a/drivers/leds/leds-pca955x.c +++ b/drivers/leds/leds-pca955x.c @@ -104,16 +104,6 @@ static const struct pca955x_chipdef pca955x_chipdefs[] = { }, }; -static const struct i2c_device_id pca955x_id[] = { - { "pca9550", (kernel_ulong_t)&pca955x_chipdefs[pca9550] }, - { "pca9551", (kernel_ulong_t)&pca955x_chipdefs[pca9551] }, - { "pca9552", (kernel_ulong_t)&pca955x_chipdefs[pca9552] }, - { "ibm-pca9552", (kernel_ulong_t)&pca955x_chipdefs[ibm_pca9552] }, - { "pca9553", (kernel_ulong_t)&pca955x_chipdefs[pca9553] }, - { } -}; -MODULE_DEVICE_TABLE(i2c, pca955x_id); - struct pca955x { struct mutex lock; struct pca955x_led *leds; @@ -457,16 +447,6 @@ pca955x_get_pdata(struct i2c_client *client, const struct pca955x_chipdef *chip) return pdata; } -static const struct of_device_id of_pca955x_match[] = { - { .compatible = "nxp,pca9550", .data = &pca955x_chipdefs[pca9550] }, - { .compatible = "nxp,pca9551", .data = &pca955x_chipdefs[pca9551] }, - { .compatible = "nxp,pca9552", .data = &pca955x_chipdefs[pca9552] }, - { .compatible = "ibm,pca9552", .data = &pca955x_chipdefs[ibm_pca9552] }, - { .compatible = "nxp,pca9553", .data = &pca955x_chipdefs[pca9553] }, - {}, -}; -MODULE_DEVICE_TABLE(of, of_pca955x_match); - static int pca955x_probe(struct i2c_client *client) { struct pca955x *pca955x; @@ -650,6 +630,26 @@ static int pca955x_probe(struct i2c_client *client) return 0; } +static const struct i2c_device_id pca955x_id[] = { + { "pca9550", (kernel_ulong_t)&pca955x_chipdefs[pca9550] }, + { "pca9551", (kernel_ulong_t)&pca955x_chipdefs[pca9551] }, + { "pca9552", (kernel_ulong_t)&pca955x_chipdefs[pca9552] }, + { "ibm-pca9552", (kernel_ulong_t)&pca955x_chipdefs[ibm_pca9552] }, + { "pca9553", (kernel_ulong_t)&pca955x_chipdefs[pca9553] }, + {} +}; +MODULE_DEVICE_TABLE(i2c, pca955x_id); + +static const struct of_device_id of_pca955x_match[] = { + { .compatible = "nxp,pca9550", .data = &pca955x_chipdefs[pca9550] }, + { .compatible = "nxp,pca9551", .data = &pca955x_chipdefs[pca9551] }, + { .compatible = "nxp,pca9552", .data = &pca955x_chipdefs[pca9552] }, + { .compatible = "ibm,pca9552", .data = &pca955x_chipdefs[ibm_pca9552] }, + { .compatible = "nxp,pca9553", .data = &pca955x_chipdefs[pca9553] }, + {} +}; +MODULE_DEVICE_TABLE(of, of_pca955x_match); + static struct i2c_driver pca955x_driver = { .driver = { .name = "leds-pca955x",