From patchwork Tue May 27 09:38:51 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris BREZILLON X-Patchwork-Id: 4248231 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 3D472BF90B for ; Tue, 27 May 2014 09:43:00 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 52BE720254 for ; Tue, 27 May 2014 09:42:59 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 674D5201DE for ; Tue, 27 May 2014 09:42:58 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WpDrb-0007wR-K2; Tue, 27 May 2014 09:40:07 +0000 Received: from top.free-electrons.com ([176.31.233.9] helo=mail.free-electrons.com) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WpDrV-00070u-HK for linux-arm-kernel@lists.infradead.org; Tue, 27 May 2014 09:40:03 +0000 Received: by mail.free-electrons.com (Postfix, from userid 106) id D58F05C55; Tue, 27 May 2014 11:39:43 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from localhost.localdomain (col31-4-88-188-83-94.fbx.proxad.net [88.188.83.94]) by mail.free-electrons.com (Postfix) with ESMTPSA id 0E9621613; Tue, 27 May 2014 11:38:58 +0200 (CEST) From: Boris BREZILLON To: Samuel Ortiz , Lee Jones , Liam Girdwood , Mark Brown Subject: [PATCH v3 2/6] regulator: axp20x: prepare support for multiple AXP chip families Date: Tue, 27 May 2014 11:38:51 +0200 Message-Id: <1401183535-31003-3-git-send-email-boris.brezillon@free-electrons.com> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1401183535-31003-1-git-send-email-boris.brezillon@free-electrons.com> References: <1401183535-31003-1-git-send-email-boris.brezillon@free-electrons.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140527_024002_002264_043D0276 X-CRM114-Status: GOOD ( 13.50 ) X-Spam-Score: 0.3 (/) Cc: Boris BREZILLON , dev@linux-sunxi.org, linux-kernel@vger.kernel.org, Shuge , Carlo Caione , Maxime Ripard , kevin@allwinnertech.com, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Rework the AXP20X_ macros to support the several chip families, so that each family can define it's own set of regulators, and regulator matches. Pass a match table to the axp20x_regulator_parse_dt function instead of statically using the axp20x match table. Signed-off-by: Boris BREZILLON --- drivers/regulator/axp20x-regulator.c | 74 +++++++++++++++++++----------------- 1 file changed, 39 insertions(+), 35 deletions(-) diff --git a/drivers/regulator/axp20x-regulator.c b/drivers/regulator/axp20x-regulator.c index 61ae4d4..5a59982 100644 --- a/drivers/regulator/axp20x-regulator.c +++ b/drivers/regulator/axp20x-regulator.c @@ -32,13 +32,13 @@ #define AXP20X_FREQ_DCDC_MASK 0x0f -#define AXP20X_DESC_IO(_id, _supply, _min, _max, _step, _vreg, _vmask, _ereg, \ - _emask, _enable_val, _disable_val) \ - [AXP20X_##_id] = { \ +#define AXP_DESC_IO(_family, _id, _supply, _min, _max, _step, _vreg, _vmask, \ + _ereg, _emask, _enable_val, _disable_val) \ + [_family##_##_id] = { \ .name = #_id, \ .supply_name = (_supply), \ .type = REGULATOR_VOLTAGE, \ - .id = AXP20X_##_id, \ + .id = _family##_##_id, \ .n_voltages = (((_max) - (_min)) / (_step) + 1), \ .owner = THIS_MODULE, \ .min_uV = (_min) * 1000, \ @@ -52,13 +52,13 @@ .ops = &axp20x_ops, \ } -#define AXP20X_DESC(_id, _supply, _min, _max, _step, _vreg, _vmask, _ereg, \ - _emask) \ - [AXP20X_##_id] = { \ +#define AXP_DESC(_family, _id, _supply, _min, _max, _step, _vreg, _vmask, \ + _ereg, _emask) \ + [_family##_##_id] = { \ .name = #_id, \ .supply_name = (_supply), \ .type = REGULATOR_VOLTAGE, \ - .id = AXP20X_##_id, \ + .id = _family##_##_id, \ .n_voltages = (((_max) - (_min)) / (_step) + 1), \ .owner = THIS_MODULE, \ .min_uV = (_min) * 1000, \ @@ -70,24 +70,25 @@ .ops = &axp20x_ops, \ } -#define AXP20X_DESC_FIXED(_id, _supply, _volt) \ - [AXP20X_##_id] = { \ +#define AXP_DESC_FIXED(_family, _id, _supply, _volt) \ + [_family##_##_id] = { \ .name = #_id, \ .supply_name = (_supply), \ .type = REGULATOR_VOLTAGE, \ - .id = AXP20X_##_id, \ + .id = _family##_##_id, \ .n_voltages = 1, \ .owner = THIS_MODULE, \ .min_uV = (_volt) * 1000, \ .ops = &axp20x_ops_fixed \ } -#define AXP20X_DESC_TABLE(_id, _supply, _table, _vreg, _vmask, _ereg, _emask) \ - [AXP20X_##_id] = { \ +#define AXP_DESC_TABLE(_family, _id, _supply, _table, _vreg, _vmask, _ereg, \ + _emask) \ + [_family##_##_id] = { \ .name = #_id, \ .supply_name = (_supply), \ .type = REGULATOR_VOLTAGE, \ - .id = AXP20X_##_id, \ + .id = _family##_##_id, \ .n_voltages = ARRAY_SIZE(_table), \ .owner = THIS_MODULE, \ .vsel_reg = (_vreg), \ @@ -126,36 +127,36 @@ static struct regulator_ops axp20x_ops = { }; static const struct regulator_desc axp20x_regulators[] = { - AXP20X_DESC(DCDC2, "vin2", 700, 2275, 25, AXP20X_DCDC2_V_OUT, 0x3f, + AXP_DESC(AXP20X, DCDC2, "vin2", 700, 2275, 25, AXP20X_DCDC2_V_OUT, 0x3f, AXP20X_PWR_OUT_CTRL, 0x10), - AXP20X_DESC(DCDC3, "vin3", 700, 3500, 25, AXP20X_DCDC3_V_OUT, 0x7f, + AXP_DESC(AXP20X, DCDC3, "vin3", 700, 3500, 25, AXP20X_DCDC3_V_OUT, 0x7f, AXP20X_PWR_OUT_CTRL, 0x02), - AXP20X_DESC_FIXED(LDO1, "acin", 1300), - AXP20X_DESC(LDO2, "ldo24in", 1800, 3300, 100, AXP20X_LDO24_V_OUT, 0xf0, + AXP_DESC_FIXED(AXP20X, LDO1, "acin", 1300), + AXP_DESC(AXP20X, LDO2, "ldo24in", 1800, 3300, 100, AXP20X_LDO24_V_OUT, 0xf0, AXP20X_PWR_OUT_CTRL, 0x04), - AXP20X_DESC(LDO3, "ldo3in", 700, 3500, 25, AXP20X_LDO3_V_OUT, 0x7f, + AXP_DESC(AXP20X, LDO3, "ldo3in", 700, 3500, 25, AXP20X_LDO3_V_OUT, 0x7f, AXP20X_PWR_OUT_CTRL, 0x40), - AXP20X_DESC_TABLE(LDO4, "ldo24in", axp20x_ldo4_data, AXP20X_LDO24_V_OUT, 0x0f, + AXP_DESC_TABLE(AXP20X, LDO4, "ldo24in", axp20x_ldo4_data, AXP20X_LDO24_V_OUT, 0x0f, AXP20X_PWR_OUT_CTRL, 0x08), - AXP20X_DESC_IO(LDO5, "ldo5in", 1800, 3300, 100, AXP20X_LDO5_V_OUT, 0xf0, + AXP_DESC_IO(AXP20X, LDO5, "ldo5in", 1800, 3300, 100, AXP20X_LDO5_V_OUT, 0xf0, AXP20X_GPIO0_CTRL, 0x07, AXP20X_IO_ENABLED, AXP20X_IO_DISABLED), }; -#define AXP_MATCH(_name, _id) \ - [AXP20X_##_id] = { \ +#define AXP_MATCH(_family, _name, _id) \ + [_family##_##_id] = { \ .name = #_name, \ - .driver_data = (void *) &axp20x_regulators[AXP20X_##_id], \ + .driver_data = (void *) &axp20x_regulators[_family##_##_id], \ } static struct of_regulator_match axp20x_matches[] = { - AXP_MATCH(dcdc2, DCDC2), - AXP_MATCH(dcdc3, DCDC3), - AXP_MATCH(ldo1, LDO1), - AXP_MATCH(ldo2, LDO2), - AXP_MATCH(ldo3, LDO3), - AXP_MATCH(ldo4, LDO4), - AXP_MATCH(ldo5, LDO5), + AXP_MATCH(AXP20X, dcdc2, DCDC2), + AXP_MATCH(AXP20X, dcdc3, DCDC3), + AXP_MATCH(AXP20X, ldo1, LDO1), + AXP_MATCH(AXP20X, ldo2, LDO2), + AXP_MATCH(AXP20X, ldo3, LDO3), + AXP_MATCH(AXP20X, ldo4, LDO4), + AXP_MATCH(AXP20X, ldo5, LDO5), }; static int axp20x_set_dcdc_freq(struct platform_device *pdev, u32 dcdcfreq) @@ -178,7 +179,9 @@ static int axp20x_set_dcdc_freq(struct platform_device *pdev, u32 dcdcfreq) AXP20X_FREQ_DCDC_MASK, dcdcfreq); } -static int axp20x_regulator_parse_dt(struct platform_device *pdev) +static int axp20x_regulator_parse_dt(struct platform_device *pdev, + struct of_regulator_match *matches, + int nmatches) { struct device_node *np, *regulators; int ret; @@ -192,8 +195,8 @@ static int axp20x_regulator_parse_dt(struct platform_device *pdev) if (!regulators) { dev_warn(&pdev->dev, "regulators node not found\n"); } else { - ret = of_regulator_match(&pdev->dev, regulators, axp20x_matches, - ARRAY_SIZE(axp20x_matches)); + ret = of_regulator_match(&pdev->dev, regulators, matches, + nmatches); if (ret < 0) { dev_err(&pdev->dev, "Error parsing regulator init data: %d\n", ret); return ret; @@ -237,7 +240,8 @@ static int axp20x_regulator_probe(struct platform_device *pdev) int ret, i; u32 workmode; - ret = axp20x_regulator_parse_dt(pdev); + ret = axp20x_regulator_parse_dt(pdev, axp20x_matches, + ARRAY_SIZE(axp20x_matches)); if (ret) return ret;