From patchwork Thu Mar 21 15:59:16 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 2314801 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork2.kernel.org (Postfix) with ESMTP id A3E8ADF264 for ; Thu, 21 Mar 2013 16:20:46 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1UIiB4-0001DI-4F; Thu, 21 Mar 2013 16:17:19 +0000 Received: from mail-wg0-f43.google.com ([74.125.82.43]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1UIhv2-0001Cz-AZ for linux-arm-kernel@lists.infradead.org; Thu, 21 Mar 2013 16:00:45 +0000 Received: by mail-wg0-f43.google.com with SMTP id e12so2395278wge.10 for ; Thu, 21 Mar 2013 09:00:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:x-gm-message-state; bh=M5w3MH+/baIWXct6o5d7MT02QSuzJRKRuW3tYj1/niI=; b=BsVf+6vBVhQdwJNYn0jbbqpw8N6pp88nZy0SH0b7kmlXJl88zhiLBkiPrFjy1fQhD4 o8c3d14UZXZQYnU1SxhOwaNdcRiVf3gFHm3dXMYb1XD68s/Iye3MpyCZUewzcqMqHgG+ rpkWKnrtpJ6qXgXVhrtmiryA7bLFZ9ZcbN5iMBBovnkQfIeUsxwzjewDkCgliiBobC6l 24G8EGh5Y1i50doFQqgHN+SsmRFwsOuerUs+92lu2nzCVocFXMDAOmt5oSegFtTmAf7s I1YRTQm2nGNElWMrcwl2Sju5Cv9jkEKpgs3Z7RZbyDxY3Jr04pm93hfFOrg4t5PiDkic Iz8Q== X-Received: by 10.180.72.148 with SMTP id d20mr5797755wiv.31.1363881640579; Thu, 21 Mar 2013 09:00:40 -0700 (PDT) Received: from localhost.localdomain (cpc34-aztw25-2-0-cust250.18-1.cable.virginmedia.com. [86.16.136.251]) by mx.google.com with ESMTPS id h10sm6110847wic.8.2013.03.21.09.00.38 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 21 Mar 2013 09:00:39 -0700 (PDT) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, broonie@opensource.wolfsonmicro.com Subject: [PATCH 19/46] regulator: ab8500: Prepare the driver for additional platforms Date: Thu, 21 Mar 2013 15:59:16 +0000 Message-Id: <1363881583-15234-20-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1363881583-15234-1-git-send-email-lee.jones@linaro.org> References: <1363881583-15234-1-git-send-email-lee.jones@linaro.org> X-Gm-Message-State: ALoCoQkdt4pk90Xmsb0l5XCXlIT0GpIPERziefODQi86d4lIpjO0GWcp0TJX5TxoOgzZkdo8JjBM X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130321_120044_660399_37595BA9 X-CRM114-Status: GOOD ( 18.41 ) X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [74.125.82.43 listed in list.dnswl.org] -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: Lee Jones , linus.walleij@stericsson.com, arnd@arndb.de 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 More platforms are to be supported by the AB8500 regulator driver, so in this patch we prepare for their arrival. Instead of using the AB8500 settings blindly, we provide an infrastructure where adding a new platform is as easy as providing a couple of platform specific data structures. Signed-off-by: Lee Jones --- drivers/regulator/ab8500.c | 76 ++++++++++++++++++++++++++++---------------- 1 file changed, 49 insertions(+), 27 deletions(-) diff --git a/drivers/regulator/ab8500.c b/drivers/regulator/ab8500.c index 8c5276d..953be4c 100644 --- a/drivers/regulator/ab8500.c +++ b/drivers/regulator/ab8500.c @@ -764,46 +764,47 @@ static struct ab8500_reg_init ab8500_reg_init[] = { }; static int ab8500_regulator_init_registers(struct platform_device *pdev, + struct ab8500_reg_init *reg_init, int id, int mask, int value) { int err; BUG_ON(value & ~mask); - BUG_ON(mask & ~ab8500_reg_init[id].mask); + BUG_ON(mask & ~reg_init[id].mask); /* initialize register */ err = abx500_mask_and_set_register_interruptible( &pdev->dev, - ab8500_reg_init[id].bank, - ab8500_reg_init[id].addr, + reg_init[id].bank, + reg_init[id].addr, mask, value); if (err < 0) { dev_err(&pdev->dev, "Failed to initialize 0x%02x, 0x%02x.\n", - ab8500_reg_init[id].bank, - ab8500_reg_init[id].addr); + reg_init[id].bank, + reg_init[id].addr); return err; } dev_vdbg(&pdev->dev, " init: 0x%02x, 0x%02x, 0x%02x, 0x%02x\n", - ab8500_reg_init[id].bank, - ab8500_reg_init[id].addr, + reg_init[id].bank, + reg_init[id].addr, mask, value); return 0; } static int ab8500_regulator_register(struct platform_device *pdev, - struct regulator_init_data *init_data, - int id, - struct device_node *np) + struct regulator_init_data *init_data, + struct ab8500_regulator_info *regulator_info, + int id, struct device_node *np) { struct ab8500_regulator_info *info = NULL; struct regulator_config config = { }; int err; /* assign per-regulator data */ - info = &ab8500_regulator_info[id]; + info = ®ulator_info[id]; info->dev = &pdev->dev; config.dev = &pdev->dev; @@ -829,7 +830,7 @@ static int ab8500_regulator_register(struct platform_device *pdev, info->desc.name); /* when we fail, un-register all earlier regulators */ while (--id >= 0) { - info = &ab8500_regulator_info[id]; + info = ®ulator_info[id]; regulator_unregister(info->regulator); } return err; @@ -838,7 +839,7 @@ static int ab8500_regulator_register(struct platform_device *pdev, return 0; } -static struct of_regulator_match ab8500_regulator_matches[] = { +static struct of_regulator_match ab8500_regulator_match[] = { { .name = "ab8500_ldo_aux1", .driver_data = (void *) AB8500_LDO_AUX1, }, { .name = "ab8500_ldo_aux2", .driver_data = (void *) AB8500_LDO_AUX2, }, { .name = "ab8500_ldo_aux3", .driver_data = (void *) AB8500_LDO_AUX3, }, @@ -852,14 +853,18 @@ static struct of_regulator_match ab8500_regulator_matches[] = { }; static int -ab8500_regulator_of_probe(struct platform_device *pdev, struct device_node *np) +ab8500_regulator_of_probe(struct platform_device *pdev, + struct ab8500_regulator_info *regulator_info, + int regulator_info_size, + struct of_regulator_match *match, + struct device_node *np) { int err, i; - for (i = 0; i < ARRAY_SIZE(ab8500_regulator_info); i++) { + for (i = 0; i < regulator_info_size; i++) { err = ab8500_regulator_register( - pdev, ab8500_regulator_matches[i].init_data, - i, ab8500_regulator_matches[i].of_node); + pdev, match[i].init_data, regulator_info, + i, match[i].of_node); if (err) return err; } @@ -871,21 +876,32 @@ static int ab8500_regulator_probe(struct platform_device *pdev) { struct ab8500 *ab8500 = dev_get_drvdata(pdev->dev.parent); struct device_node *np = pdev->dev.of_node; + struct of_regulator_match *match; struct ab8500_platform_data *ppdata; struct ab8500_regulator_platform_data *pdata; int i, err; + struct ab8500_regulator_info *regulator_info; + int regulator_info_size; + struct ab8500_reg_init *reg_init; + int reg_init_size; + + regulator_info = ab8500_regulator_info; + regulator_info_size = ARRAY_SIZE(ab8500_regulator_info); + reg_init = ab8500_reg_init; + reg_init_size = AB8500_NUM_REGULATOR_REGISTERS; + match = ab8500_regulator_match; + match_size = ARRAY_SIZE(ab8500_regulator_match) if (np) { - err = of_regulator_match(&pdev->dev, np, - ab8500_regulator_matches, - ARRAY_SIZE(ab8500_regulator_matches)); + err = of_regulator_match(&pdev->dev, np, match, match_size); if (err < 0) { dev_err(&pdev->dev, "Error parsing regulator init data: %d\n", err); return err; } - err = ab8500_regulator_of_probe(pdev, np); + err = ab8500_regulator_of_probe(pdev, regulator_info, + regulator_info_size, match, np); return err; } @@ -907,7 +923,7 @@ static int ab8500_regulator_probe(struct platform_device *pdev) } /* make sure the platform data has the correct size */ - if (pdata->num_regulator != ARRAY_SIZE(ab8500_regulator_info)) { + if (pdata->num_regulator != regulator_info_size) { dev_err(&pdev->dev, "Configuration error: size mismatch.\n"); return -EINVAL; } @@ -928,7 +944,7 @@ static int ab8500_regulator_probe(struct platform_device *pdev) /* check for configuration errors */ BUG_ON(id >= AB8500_NUM_REGULATOR_REGISTERS); - err = ab8500_regulator_init_registers(pdev, id, mask, value); + err = ab8500_regulator_init_registers(pdev, reg_init, id, mask, value); if (err < 0) return err; } @@ -939,8 +955,9 @@ static int ab8500_regulator_probe(struct platform_device *pdev) return err; /* register all regulators */ - for (i = 0; i < ARRAY_SIZE(ab8500_regulator_info); i++) { - err = ab8500_regulator_register(pdev, &pdata->regulator[i], i, NULL); + for (i = 0; i < regulator_info_size; i++) { + err = ab8500_regulator_register(pdev, &pdata->regulator[i], + regulator_info, i, NULL); if (err < 0) return err; } @@ -951,10 +968,15 @@ static int ab8500_regulator_probe(struct platform_device *pdev) static int ab8500_regulator_remove(struct platform_device *pdev) { int i, err; + struct ab8500_regulator_info *regulator_info; + int regulator_info_size; - for (i = 0; i < ARRAY_SIZE(ab8500_regulator_info); i++) { + regulator_info = ab8500_regulator_info; + regulator_info_size = ARRAY_SIZE(ab8500_regulator_info); + + for (i = 0; i < regulator_info_size; i++) { struct ab8500_regulator_info *info = NULL; - info = &ab8500_regulator_info[i]; + info = ®ulator_info[i]; dev_vdbg(rdev_get_dev(info->regulator), "%s-remove\n", info->desc.name);