Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp427990pxu; Fri, 11 Dec 2020 05:51:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJwC3BiTcqYVKKn+6GRQ1iW4YM+5crs+y9EvJuL10luxOhUlgNWjMA2Nxh5tAPAGwFtp2iZm X-Received: by 2002:a17:906:b56:: with SMTP id v22mr10966898ejg.145.1607694665910; Fri, 11 Dec 2020 05:51:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607694665; cv=none; d=google.com; s=arc-20160816; b=pdMvjEK7UcIz6dr3vk3zsV7qtaL/UHfW/RLff7L0SB9ZRQgQdmfFLtF+ZNaN/nLCTN NsDvw7Dsz+bdNmxoo5Lxf60Y0z5Dy3DiRYsph3BFwPnM1XaLCLepAx8/yCCuEJpdzCTi ihfXxlPG9CSwlkOq5mC5JNCFlAJGcn044mSOpaNOcimZqZbd4G1HSzJeVyWBOXucrjQe SHW0Zxbo+Orfh/rnq9BV7z7ENIsIhT/YSOoP2Yq0d4bQ2queNtQY054W+Z0e0u7NapCG OllVA3FQMZewIKeaL+f7HeZuvr3e2zdtHxVJzWP5ATS0/Vx91XpDD/pLBRgPrQ9Q/k24 JvNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=UNsVJhf5KGvnAEffaqhrJKmjHrOIIg6Cd/n1ZOHk2xU=; b=s4TTNGPS7XQGTYoO8phX59xf1JFKM3yx/woKFrsEX3Zx7zDlSwH7ULiOdTYIdgAE18 gFVjU4Gb0OwHzGiqlulvwWiCpiA+j0tFdPS9kFwUVtKEKJUqClGVW4elPqyU8pgO66dj TtBqvv8FVAoxKWlzUbqIYR5ESQUf4FdF2hzqXXb4I52Xd1ZkyqfRdDGGtVByg1N9wjlM N0WHW5yUMaz8VTSiWX0+mAG28wy2nRQE/hmZ5+jpzHUn93VM9iCnHFIcR5+Rw3v4gCbs L0xEwS1m/IwU/5ZLi05WSCtuhvR9rWy2YsFm0zKpFbdNUQkRHHcdIspolrIyKdY2D13Q P/kQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n12si4705371eds.188.2020.12.11.05.50.42; Fri, 11 Dec 2020 05:51:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2394777AbgLKL2i (ORCPT + 99 others); Fri, 11 Dec 2020 06:28:38 -0500 Received: from relmlor2.renesas.com ([210.160.252.172]:22276 "EHLO relmlie6.idc.renesas.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2394422AbgLKL23 (ORCPT ); Fri, 11 Dec 2020 06:28:29 -0500 X-IronPort-AV: E=Sophos;i="5.78,411,1599490800"; d="scan'208";a="65422229" Received: from unknown (HELO relmlir6.idc.renesas.com) ([10.200.68.152]) by relmlie6.idc.renesas.com with ESMTP; 11 Dec 2020 20:27:56 +0900 Received: from localhost.localdomain (unknown [10.166.252.89]) by relmlir6.idc.renesas.com (Postfix) with ESMTP id 8D4E542D7EA2; Fri, 11 Dec 2020 20:27:56 +0900 (JST) From: Yoshihiro Shimoda To: marek.vasut+renesas@gmail.com, lee.jones@linaro.org, matti.vaittinen@fi.rohmeurope.com, lgirdwood@gmail.com, broonie@kernel.org, linus.walleij@linaro.org, bgolaszewski@baylibre.com Cc: khiem.nguyen.xt@renesas.com, linux-power@fi.rohmeurope.com, linux-gpio@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org, Yoshihiro Shimoda Subject: [PATCH v2 09/10] mfd: bd9571mwv: Make the driver more generic Date: Fri, 11 Dec 2020 20:27:39 +0900 Message-Id: <1607686060-17448-10-git-send-email-yoshihiro.shimoda.uh@renesas.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1607686060-17448-1-git-send-email-yoshihiro.shimoda.uh@renesas.com> References: <1607686060-17448-1-git-send-email-yoshihiro.shimoda.uh@renesas.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Khiem Nguyen Since the driver supports BD9571MWV PMIC only, this patch makes the functions and data structure become more generic so that it can support other PMIC variants as well. Signed-off-by: Khiem Nguyen [shimoda: rebase and refactor] Signed-off-by: Yoshihiro Shimoda --- drivers/mfd/bd9571mwv.c | 71 +++++++++++++++++++++++++++++++++++-------- include/linux/mfd/bd9571mwv.h | 18 ++--------- 2 files changed, 62 insertions(+), 27 deletions(-) diff --git a/drivers/mfd/bd9571mwv.c b/drivers/mfd/bd9571mwv.c index 80c6ef0..adb9e3d 100644 --- a/drivers/mfd/bd9571mwv.c +++ b/drivers/mfd/bd9571mwv.c @@ -3,6 +3,7 @@ * ROHM BD9571MWV-M MFD driver * * Copyright (C) 2017 Marek Vasut + * Copyright (C) 2020 Renesas Electronics Corporation * * Based on the TPS65086 driver */ @@ -14,6 +15,34 @@ #include +/** + * struct bd957x_data - internal data for the bd957x driver + * + * Internal data to distinguish bd957x variants + */ +struct bd957x_data { + char *part_name; + const struct regmap_config *regmap_config; + const struct regmap_irq_chip *irq_chip; + const struct mfd_cell *cells; + int num_cells; +}; + +/** + * struct bd9571mwv - state holder for the bd9571mwv driver + * + * Device data may be used to access the BD9571MWV chip + */ +struct bd9571mwv { + struct device *dev; + struct regmap *regmap; + const struct bd957x_data *data; + + /* IRQ Data */ + int irq; + struct regmap_irq_chip_data *irq_data; +}; + static const struct mfd_cell bd9571mwv_cells[] = { { .name = "bd9571mwv-regulator", }, { .name = "bd9571mwv-gpio", }, @@ -102,6 +131,14 @@ static struct regmap_irq_chip bd9571mwv_irq_chip = { .num_irqs = ARRAY_SIZE(bd9571mwv_irqs), }; +static const struct bd957x_data bd9571mwv_data = { + .part_name = BD9571MWV_PART_NAME, + .regmap_config = &bd9571mwv_regmap_config, + .irq_chip = &bd9571mwv_irq_chip, + .cells = bd9571mwv_cells, + .num_cells = ARRAY_SIZE(bd9571mwv_cells), +}; + static int bd9571mwv_identify(struct bd9571mwv *bd) { struct device *dev = bd->dev; @@ -127,13 +164,6 @@ static int bd9571mwv_identify(struct bd9571mwv *bd) ret); return ret; } - - if (value != BD9571MWV_PRODUCT_CODE_VAL) { - dev_err(dev, "Invalid product code ID %02x (expected %02x)\n", - value, BD9571MWV_PRODUCT_CODE_VAL); - return -EINVAL; - } - ret = regmap_read(bd->regmap, BD9571MWV_PRODUCT_REVISION, &value); if (ret) { dev_err(dev, "Failed to read revision register (ret=%i)\n", @@ -141,7 +171,8 @@ static int bd9571mwv_identify(struct bd9571mwv *bd) return ret; } - dev_info(dev, "Device: BD9571MWV rev. %d\n", value & 0xff); + dev_info(dev, "Device: %s rev. %d\n", bd->data->part_name, + value & 0xff); return 0; } @@ -160,7 +191,23 @@ static int bd9571mwv_probe(struct i2c_client *client, bd->dev = &client->dev; bd->irq = client->irq; - bd->regmap = devm_regmap_init_i2c(client, &bd9571mwv_regmap_config); + /* Read the PMIC product code */ + ret = i2c_smbus_read_byte_data(client, BD9571MWV_PRODUCT_CODE); + if (ret < 0) { + dev_err(&client->dev, "failed reading at 0x%02x\n", + BD9571MWV_PRODUCT_CODE); + return ret; + } + switch (ret) { + case BD9571MWV_PRODUCT_CODE_VAL: + bd->data = &bd9571mwv_data; + break; + default: + dev_err(bd->dev, "Unsupported device 0x%x\n", ret); + return -ENOENT; + } + + bd->regmap = devm_regmap_init_i2c(client, bd->data->regmap_config); if (IS_ERR(bd->regmap)) { dev_err(bd->dev, "Failed to initialize register map\n"); return PTR_ERR(bd->regmap); @@ -171,14 +218,14 @@ static int bd9571mwv_probe(struct i2c_client *client, return ret; ret = regmap_add_irq_chip(bd->regmap, bd->irq, IRQF_ONESHOT, 0, - &bd9571mwv_irq_chip, &bd->irq_data); + bd->data->irq_chip, &bd->irq_data); if (ret) { dev_err(bd->dev, "Failed to register IRQ chip\n"); return ret; } - ret = mfd_add_devices(bd->dev, PLATFORM_DEVID_AUTO, bd9571mwv_cells, - ARRAY_SIZE(bd9571mwv_cells), NULL, 0, + ret = mfd_add_devices(bd->dev, PLATFORM_DEVID_AUTO, bd->data->cells, + bd->data->num_cells, NULL, 0, regmap_irq_get_domain(bd->irq_data)); if (ret) { regmap_del_irq_chip(bd->irq, bd->irq_data); diff --git a/include/linux/mfd/bd9571mwv.h b/include/linux/mfd/bd9571mwv.h index bcc7092..5ab976a 100644 --- a/include/linux/mfd/bd9571mwv.h +++ b/include/linux/mfd/bd9571mwv.h @@ -3,6 +3,7 @@ * ROHM BD9571MWV-M driver * * Copyright (C) 2017 Marek Vasut + * Copyright (C) 2020 Renesas Electronics Corporation * * Based on the TPS65086 driver */ @@ -83,6 +84,8 @@ #define BD9571MWV_ACCESS_KEY 0xff +#define BD9571MWV_PART_NAME "BD9571MWV" + /* Define the BD9571MWV IRQ numbers */ enum bd9571mwv_irqs { BD9571MWV_IRQ_MD1, @@ -94,19 +97,4 @@ enum bd9571mwv_irqs { BD9571MWV_IRQ_WDT_OF, BD9571MWV_IRQ_BKUP_TRG, }; - -/** - * struct bd9571mwv - state holder for the bd9571mwv driver - * - * Device data may be used to access the BD9571MWV chip - */ -struct bd9571mwv { - struct device *dev; - struct regmap *regmap; - - /* IRQ Data */ - int irq; - struct regmap_irq_chip_data *irq_data; -}; - #endif /* __LINUX_MFD_BD9571MWV_H */ -- 2.7.4