Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp759316rdh; Sun, 24 Sep 2023 10:24:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFSrcCqGrK4poQQ8006PxvfQRwSo6C4KgKGFt0dA17vX1Hs/43lg6+F9hz1urkSyTGMMNvi X-Received: by 2002:a05:6a20:5646:b0:15e:9c50:73ee with SMTP id is6-20020a056a20564600b0015e9c5073eemr1963740pzc.53.1695576259825; Sun, 24 Sep 2023 10:24:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695576259; cv=none; d=google.com; s=arc-20160816; b=j3SfgIkQ1pL4w6dEePO/BEhv1KQGD2WSoSvmPrSo7RpLwn8RGMLY5MYf1uxdL+Y83x KAKZSKnaWyqlv0DM3mkkRHIjlNYK5wx2o6N+hpxqRmjciRO5PTWc/giG8KwqesXeMME/ 0zMgZgCYzV7mOXOnzIP0PTKbJO2HIJQ/rlonqem2Fat45Aj4ZQw/OJvDCQsSxBjm8M0u 87vAO5Rda31xNVY1+AVkmkA5YL6WJZVgmh2rGsaeQPYaOK6TdGLlJ27GQY0Dd37pb+b9 Ossc5tY47TqQmKxavVCCPiAmELtTO7HRSvuutfPyMCYKqQZREjmMe8stj0FL/GnjX5oQ vvfA== 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=bmyogQNq3hcITFPrp4HEgrpHkUegzwHrvW8Yu7H8czs=; fh=xeSrQ7kCdgcCVb2zAn5rBkDAdtmCo24cOODwKpU9NDo=; b=MSUvDyGuz6DxuYCKVb5m/+GWl3SBGJOvjjbiY0P/dHr9yXv1IwgT7ls6ZiIab2ZRXZ 2NG2BHM5IIhfO5rBOj1vNnVu6HLk14BiukxbX5vsrQAKdyuNH1DloMfEJw/jHydMJp/q IT0G/xRKV2Etw7HOsvXMfwqVQPOYyEgaUdq91Jy+DEOdtDgNH77eDi5YngsLyu6iIEPb rzXI4mQAMP4SfBG0oCUvQeP8jFdFRjuIIzYHsCrVxjKPTP/k20cwxigK4Hki4xkjRTEG mQsK/h7IYF5cD4d52q2XUaHxzSIo39jO70OKfsTaX+NKW++/JjG6IFoBuuqxqr2SPMor ZGmw== 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:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=renesas.com Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id x33-20020a634861000000b0057047d68837si8319570pgk.869.2023.09.24.10.23.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Sep 2023 10:24:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (Postfix) with ESMTP id 5BCC180B79F8; Sun, 24 Sep 2023 10:23:53 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230225AbjIXRXs (ORCPT + 99 others); Sun, 24 Sep 2023 13:23:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34762 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230241AbjIXRXn (ORCPT ); Sun, 24 Sep 2023 13:23:43 -0400 Received: from relmlie6.idc.renesas.com (relmlor2.renesas.com [210.160.252.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4ABE510F; Sun, 24 Sep 2023 10:23:35 -0700 (PDT) X-IronPort-AV: E=Sophos;i="6.03,173,1694703600"; d="scan'208";a="180780927" Received: from unknown (HELO relmlir6.idc.renesas.com) ([10.200.68.152]) by relmlie6.idc.renesas.com with ESMTP; 25 Sep 2023 02:23:35 +0900 Received: from localhost.localdomain (unknown [10.226.92.4]) by relmlir6.idc.renesas.com (Postfix) with ESMTP id D2ADC402D0AD; Mon, 25 Sep 2023 02:23:32 +0900 (JST) From: Biju Das To: Linus Walleij Cc: Biju Das , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Biju Das , Andy Shevchenko Subject: [PATCH v3 3/3] pinctrl: mcp23s08: Simplify probe()/mcp23s08_spi_regmap_init() Date: Sun, 24 Sep 2023 18:23:20 +0100 Message-Id: <20230924172320.15165-4-biju.das.jz@bp.renesas.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230924172320.15165-1-biju.das.jz@bp.renesas.com> References: <20230924172320.15165-1-biju.das.jz@bp.renesas.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,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 groat.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 (groat.vger.email [0.0.0.0]); Sun, 24 Sep 2023 10:23:53 -0700 (PDT) Add struct mcp23s08_info and simplify probe()/mcp23s08_spi_regmap_init() by replacing match data 'type' with 'struct mcp23s08_info'. While at it, replace 'dev_err()'->'dev_err_probe()' and drop printing 'type' in error path for i2c_get_match_data(). Signed-off-by: Biju Das --- v2->v3: * Added struct mcp23s08_info in pinctrl-mcp23s08.h and both i2c and spi drivers using same match data structure. v1->v2: * Updated commit description * Dropped printing 'type' in error path for i2c_get_match_data(). --- drivers/pinctrl/pinctrl-mcp23s08.h | 8 +++ drivers/pinctrl/pinctrl-mcp23s08_i2c.c | 93 ++++++++++++-------------- drivers/pinctrl/pinctrl-mcp23s08_spi.c | 88 ++++++++++++------------ 3 files changed, 93 insertions(+), 96 deletions(-) diff --git a/drivers/pinctrl/pinctrl-mcp23s08.h b/drivers/pinctrl/pinctrl-mcp23s08.h index b15516af7783..105bce9e0f50 100644 --- a/drivers/pinctrl/pinctrl-mcp23s08.h +++ b/drivers/pinctrl/pinctrl-mcp23s08.h @@ -22,6 +22,14 @@ struct regmap; struct pinctrl_dev; +struct mcp23s08_info { + const struct regmap_config *regmap; + const char *label; + unsigned int type; + u16 ngpio; + bool reg_shift; +}; + struct mcp23s08 { u8 addr; bool irq_active_high; diff --git a/drivers/pinctrl/pinctrl-mcp23s08_i2c.c b/drivers/pinctrl/pinctrl-mcp23s08_i2c.c index 41ea2650a7e4..70219c0b71c7 100644 --- a/drivers/pinctrl/pinctrl-mcp23s08_i2c.c +++ b/drivers/pinctrl/pinctrl-mcp23s08_i2c.c @@ -10,50 +10,30 @@ static int mcp230xx_probe(struct i2c_client *client) { + const struct mcp23s08_info *info; struct device *dev = &client->dev; struct mcp23s08 *mcp; - unsigned int type; int ret; mcp = devm_kzalloc(dev, sizeof(*mcp), GFP_KERNEL); if (!mcp) return -ENOMEM; - type = (uintptr_t)i2c_get_match_data(client); - switch (type) { - case MCP_TYPE_008: - mcp->regmap = devm_regmap_init_i2c(client, &mcp23x08_regmap); - mcp->reg_shift = 0; - mcp->chip.ngpio = 8; - mcp->chip.label = "mcp23008"; - break; - - case MCP_TYPE_017: - mcp->regmap = devm_regmap_init_i2c(client, &mcp23x17_regmap); - mcp->reg_shift = 1; - mcp->chip.ngpio = 16; - mcp->chip.label = "mcp23017"; - break; - - case MCP_TYPE_018: - mcp->regmap = devm_regmap_init_i2c(client, &mcp23x17_regmap); - mcp->reg_shift = 1; - mcp->chip.ngpio = 16; - mcp->chip.label = "mcp23018"; - break; - - default: - dev_err(dev, "invalid device type (%d)\n", type); - return -EINVAL; - } + info = i2c_get_match_data(client); + if (!info) + return dev_err_probe(dev, -EINVAL, "invalid device type\n"); + mcp->reg_shift = info->reg_shift; + mcp->chip.ngpio = info->ngpio; + mcp->chip.label = info->label; + mcp->regmap = devm_regmap_init_i2c(client, info->regmap); if (IS_ERR(mcp->regmap)) return PTR_ERR(mcp->regmap); mcp->irq = client->irq; mcp->pinctrl_desc.name = "mcp23xxx-pinctrl"; - ret = mcp23s08_probe_one(mcp, dev, client->addr, type, -1); + ret = mcp23s08_probe_one(mcp, dev, client->addr, info->type, -1); if (ret) return ret; @@ -62,36 +42,45 @@ static int mcp230xx_probe(struct i2c_client *client) return 0; } +static const struct mcp23s08_info mcp23s08_i2c_0008 = { + .regmap = &mcp23x08_regmap, + .label = "mcp23008", + .type = MCP_TYPE_008, + .ngpio = 8, + .reg_shift = 0, +}; + +static const struct mcp23s08_info mcp23s08_i2c_0017 = { + .regmap = &mcp23x17_regmap, + .label = "mcp23017", + .type = MCP_TYPE_017, + .ngpio = 16, + .reg_shift = 1, +}; + +static const struct mcp23s08_info mcp23s08_i2c_0018 = { + .regmap = &mcp23x17_regmap, + .label = "mcp23018", + .type = MCP_TYPE_018, + .ngpio = 16, + .reg_shift = 1, +}; + static const struct i2c_device_id mcp230xx_id[] = { - { "mcp23008", MCP_TYPE_008 }, - { "mcp23017", MCP_TYPE_017 }, - { "mcp23018", MCP_TYPE_018 }, + { "mcp23008", (kernel_ulong_t)&mcp23s08_i2c_0008 }, + { "mcp23017", (kernel_ulong_t)&mcp23s08_i2c_0017 }, + { "mcp23018", (kernel_ulong_t)&mcp23s08_i2c_0018 }, { } }; MODULE_DEVICE_TABLE(i2c, mcp230xx_id); static const struct of_device_id mcp23s08_i2c_of_match[] = { - { - .compatible = "microchip,mcp23008", - .data = (void *) MCP_TYPE_008, - }, - { - .compatible = "microchip,mcp23017", - .data = (void *) MCP_TYPE_017, - }, - { - .compatible = "microchip,mcp23018", - .data = (void *) MCP_TYPE_018, - }, + { .compatible = "microchip,mcp23008", .data = &mcp23s08_i2c_0008 }, + { .compatible = "microchip,mcp23017", .data = &mcp23s08_i2c_0017 }, + { .compatible = "microchip,mcp23018", .data = &mcp23s08_i2c_0018 }, /* NOTE: The use of the mcp prefix is deprecated and will be removed. */ - { - .compatible = "mcp,mcp23008", - .data = (void *) MCP_TYPE_008, - }, - { - .compatible = "mcp,mcp23017", - .data = (void *) MCP_TYPE_017, - }, + { .compatible = "mcp,mcp23008", .data = &mcp23s08_i2c_0008 }, + { .compatible = "mcp,mcp23017", .data = &mcp23s08_i2c_0017 }, { } }; MODULE_DEVICE_TABLE(of, mcp23s08_i2c_of_match); diff --git a/drivers/pinctrl/pinctrl-mcp23s08_spi.c b/drivers/pinctrl/pinctrl-mcp23s08_spi.c index caf528284d07..323391bda76f 100644 --- a/drivers/pinctrl/pinctrl-mcp23s08_spi.c +++ b/drivers/pinctrl/pinctrl-mcp23s08_spi.c @@ -80,21 +80,18 @@ static const struct regmap_bus mcp23sxx_spi_regmap = { }; static int mcp23s08_spi_regmap_init(struct mcp23s08 *mcp, struct device *dev, - unsigned int addr, unsigned int type) + unsigned int addr, + const struct mcp23s08_info *info) { - const struct regmap_config *config; struct regmap_config *copy; const char *name; - switch (type) { + switch (info->type) { case MCP_TYPE_S08: - mcp->reg_shift = 0; - mcp->chip.ngpio = 8; mcp->chip.label = devm_kasprintf(dev, GFP_KERNEL, "mcp23s08.%d", addr); if (!mcp->chip.label) return -ENOMEM; - config = &mcp23x08_regmap; name = devm_kasprintf(dev, GFP_KERNEL, "%d", addr); if (!name) return -ENOMEM; @@ -102,13 +99,10 @@ static int mcp23s08_spi_regmap_init(struct mcp23s08 *mcp, struct device *dev, break; case MCP_TYPE_S17: - mcp->reg_shift = 1; - mcp->chip.ngpio = 16; mcp->chip.label = devm_kasprintf(dev, GFP_KERNEL, "mcp23s17.%d", addr); if (!mcp->chip.label) return -ENOMEM; - config = &mcp23x17_regmap; name = devm_kasprintf(dev, GFP_KERNEL, "%d", addr); if (!name) return -ENOMEM; @@ -116,20 +110,18 @@ static int mcp23s08_spi_regmap_init(struct mcp23s08 *mcp, struct device *dev, break; case MCP_TYPE_S18: - mcp->reg_shift = 1; - mcp->chip.ngpio = 16; - mcp->chip.label = "mcp23s18"; - - config = &mcp23x17_regmap; - name = config->name; + mcp->chip.label = info->label; + name = info->regmap->name; break; default: - dev_err(dev, "invalid device type (%d)\n", type); + dev_err(dev, "invalid device type (%d)\n", info->type); return -EINVAL; } - copy = devm_kmemdup(dev, config, sizeof(*config), GFP_KERNEL); + mcp->reg_shift = info->reg_shift; + mcp->chip.ngpio = info->ngpio; + copy = devm_kmemdup(dev, info->regmap, sizeof(*info->regmap), GFP_KERNEL); if (!copy) return -ENOMEM; @@ -144,16 +136,16 @@ static int mcp23s08_spi_regmap_init(struct mcp23s08 *mcp, struct device *dev, static int mcp23s08_probe(struct spi_device *spi) { struct mcp23s08_driver_data *data; + const struct mcp23s08_info *info; struct device *dev = &spi->dev; unsigned long spi_present_mask; unsigned int ngpio = 0; - unsigned int type; unsigned int addr; int chips; int ret; u32 v; - type = (uintptr_t)spi_get_device_match_data(spi); + info = spi_get_device_match_data(spi); ret = device_property_read_u32(dev, "microchip,spi-present-mask", &v); if (ret) { @@ -182,7 +174,7 @@ static int mcp23s08_probe(struct spi_device *spi) data->mcp[addr] = &data->chip[--chips]; data->mcp[addr]->irq = spi->irq; - ret = mcp23s08_spi_regmap_init(data->mcp[addr], dev, addr, type); + ret = mcp23s08_spi_regmap_init(data->mcp[addr], dev, addr, info); if (ret) return ret; @@ -192,7 +184,8 @@ static int mcp23s08_probe(struct spi_device *spi) if (!data->mcp[addr]->pinctrl_desc.name) return -ENOMEM; - ret = mcp23s08_probe_one(data->mcp[addr], dev, 0x40 | (addr << 1), type, -1); + ret = mcp23s08_probe_one(data->mcp[addr], dev, 0x40 | (addr << 1), + info->type, -1); if (ret < 0) return ret; @@ -203,36 +196,43 @@ static int mcp23s08_probe(struct spi_device *spi) return 0; } +static const struct mcp23s08_info mcp23s08_spi_s08 = { + .regmap = &mcp23x08_regmap, + .type = MCP_TYPE_S08, + .ngpio = 8, + .reg_shift = 0, +}; + +static const struct mcp23s08_info mcp23s08_spi_s17 = { + .regmap = &mcp23x17_regmap, + .type = MCP_TYPE_S17, + .ngpio = 16, + .reg_shift = 1, +}; + +static const struct mcp23s08_info mcp23s08_spi_s18 = { + .regmap = &mcp23x17_regmap, + .label = "mcp23s18", + .type = MCP_TYPE_S18, + .ngpio = 16, + .reg_shift = 1, +}; + static const struct spi_device_id mcp23s08_ids[] = { - { "mcp23s08", MCP_TYPE_S08 }, - { "mcp23s17", MCP_TYPE_S17 }, - { "mcp23s18", MCP_TYPE_S18 }, + { "mcp23s08", (kernel_ulong_t)&mcp23s08_spi_s08 }, + { "mcp23s17", (kernel_ulong_t)&mcp23s08_spi_s17 }, + { "mcp23s18", (kernel_ulong_t)&mcp23s08_spi_s18 }, { } }; MODULE_DEVICE_TABLE(spi, mcp23s08_ids); static const struct of_device_id mcp23s08_spi_of_match[] = { - { - .compatible = "microchip,mcp23s08", - .data = (void *) MCP_TYPE_S08, - }, - { - .compatible = "microchip,mcp23s17", - .data = (void *) MCP_TYPE_S17, - }, - { - .compatible = "microchip,mcp23s18", - .data = (void *) MCP_TYPE_S18, - }, + { .compatible = "microchip,mcp23s08", .data = &mcp23s08_spi_s08 }, + { .compatible = "microchip,mcp23s17", .data = &mcp23s08_spi_s17 }, + { .compatible = "microchip,mcp23s18", .data = &mcp23s08_spi_s18 }, /* NOTE: The use of the mcp prefix is deprecated and will be removed. */ - { - .compatible = "mcp,mcp23s08", - .data = (void *) MCP_TYPE_S08, - }, - { - .compatible = "mcp,mcp23s17", - .data = (void *) MCP_TYPE_S17, - }, + { .compatible = "mcp,mcp23s08", .data = &mcp23s08_spi_s08 }, + { .compatible = "mcp,mcp23s17", .data = &mcp23s08_spi_s17 }, { } }; MODULE_DEVICE_TABLE(of, mcp23s08_spi_of_match); -- 2.25.1