From patchwork Thu Mar 28 16:11:10 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 15730 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 419B023E10 for ; Thu, 28 Mar 2013 16:12:14 +0000 (UTC) Received: from mail-ve0-f177.google.com (mail-ve0-f177.google.com [209.85.128.177]) by fiordland.canonical.com (Postfix) with ESMTP id DC52BA18890 for ; Thu, 28 Mar 2013 16:12:13 +0000 (UTC) Received: by mail-ve0-f177.google.com with SMTP id jw11so4091404veb.8 for ; Thu, 28 Mar 2013 09:12:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:x-forwarded-to:x-forwarded-for:delivered-to:x-received :received-spf:x-received:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:x-gm-message-state; bh=oaqeuXGSCYzf5eSMQFEgkBOlKf/j1qWotE7UtecwHDg=; b=b2ThfsAL+cwhJyPF29uYTopLfdg/YxPkmAS/e/ER7yz/0yFxeOt5mgvu0bXNWgUqwj ZL4EWCDFlFCRl8w7kw40Z30skovvyiMwsYXKzVSDjT54ovrE5FlVaOMSd861UdtwMkF+ SIT9M4CbJaMp1cwAakaLK31WJeCIM9XcdH35jf4G7DnZnmj4HvkUUzSd0c5SxxqjXcbl 7WDwpS0Pf1jaLtjb9tXbEGYRH98JCdgGFgNwinRiDMjIUtv7oxMBdSr4FN/o4FN2jNpy MoAht7Jzg1IcZHKqqCYewFV3Ns+E45KOxST63yDDMLF2HW40QJx95jVrUeXb032doj2i bQpA== X-Received: by 10.59.3.9 with SMTP id bs9mr27790097ved.38.1364487133269; Thu, 28 Mar 2013 09:12:13 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.59.4.204 with SMTP id cg12csp22402ved; Thu, 28 Mar 2013 09:12:12 -0700 (PDT) X-Received: by 10.194.93.68 with SMTP id cs4mr39563055wjb.17.1364487132231; Thu, 28 Mar 2013 09:12:12 -0700 (PDT) Received: from mail-wi0-x229.google.com ([2a00:1450:400c:c05::229]) by mx.google.com with ESMTPS id f4si4314266wiw.99.2013.03.28.09.12.11 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 28 Mar 2013 09:12:12 -0700 (PDT) Received-SPF: neutral (google.com: 2a00:1450:400c:c05::229 is neither permitted nor denied by best guess record for domain of lee.jones@linaro.org) client-ip=2a00:1450:400c:c05::229; Authentication-Results: mx.google.com; spf=neutral (google.com: 2a00:1450:400c:c05::229 is neither permitted nor denied by best guess record for domain of lee.jones@linaro.org) smtp.mail=lee.jones@linaro.org Received: by mail-wi0-f169.google.com with SMTP id c10so3561426wiw.4 for ; Thu, 28 Mar 2013 09:12:11 -0700 (PDT) X-Received: by 10.180.77.66 with SMTP id q2mr17328943wiw.13.1364487130016; Thu, 28 Mar 2013 09:12:10 -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 o5sm16765926wix.3.2013.03.28.09.12.08 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 28 Mar 2013 09:12:08 -0700 (PDT) From: Lee Jones To: linux-kernel@vger.kernel.org, broonie@opensource.wolfsonmicro.com Cc: Lee Jones Subject: [PATCH 10/33] regulator: ab8500: Prepare the driver for additional platforms Date: Thu, 28 Mar 2013 16:11:10 +0000 Message-Id: <1364487093-19551-11-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1364487093-19551-1-git-send-email-lee.jones@linaro.org> References: <1364487093-19551-1-git-send-email-lee.jones@linaro.org> X-Gm-Message-State: ALoCoQkeT5efGCbdi8Giw7fZaG9USLqHF15iW5tXBdcEQYpQrxSRLg/+MVPPNTvLPGyMc90w4LFA 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 bf34c4c..f323fba 100644 --- a/drivers/regulator/ab8500.c +++ b/drivers/regulator/ab8500.c @@ -763,46 +763,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; @@ -828,7 +829,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; @@ -837,7 +838,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, }, @@ -851,14 +852,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; } @@ -870,21 +875,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; } @@ -906,7 +922,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; } @@ -927,7 +943,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; } @@ -938,8 +954,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; } @@ -950,10 +967,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);