From patchwork Thu May 17 13:45:14 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 8746 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 51A2E23E23 for ; Thu, 17 May 2012 13:46:46 +0000 (UTC) Received: from mail-qa0-f45.google.com (mail-qa0-f45.google.com [209.85.216.45]) by fiordland.canonical.com (Postfix) with ESMTP id 10205A18B60 for ; Thu, 17 May 2012 13:46:45 +0000 (UTC) Received: by qaeb19 with SMTP id b19so6267473qae.11 for ; Thu, 17 May 2012 06:46:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:from:to:cc :subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=Z86TjEHW26y+yuZ6rFhq7RpmCCK5Uteqd1tgWJsABCk=; b=BPJJjXXYPGL6ZUIkK1KOgbqb1nVldqOT6FIbTbNsoEFdeU2V7+I7lUeOJswSdA7Fs7 o/NGKcU1As4Q+DFWNyVpKKHGJWy6gtDmAqPk3YyaFT7MVIw9JnuGDbdZvB6ztXyGTdMb h8iY8NW3wgSmNrrMlB2Wqu6dcpe00DGnD86tA2zr8qiI1hf5GRRmiwMByS27EYhr8oGn 0vixVx7QZt06TtC8TqVI44+ZRRupQUXZkRMCf5iGpIPSkbO9gQlaq+CikiVjpX++6HZ1 qV6kTuHcVrifxjfDA0YMI/XyyocyzvKQQQrVOlClwhFGDA0vmNSBS57G6PZvcn4h9nCi q2NA== Received: by 10.50.222.202 with SMTP id qo10mr13610262igc.0.1337262405135; Thu, 17 May 2012 06:46:45 -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.231.35.72 with SMTP id o8csp29038ibd; Thu, 17 May 2012 06:46:44 -0700 (PDT) Received: by 10.14.189.7 with SMTP id b7mr1483874een.126.1337262403725; Thu, 17 May 2012 06:46:43 -0700 (PDT) Received: from mail-we0-f178.google.com (mail-we0-f178.google.com [74.125.82.178]) by mx.google.com with ESMTPS id d3si7393850wed.115.2012.05.17.06.46.43 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 17 May 2012 06:46:43 -0700 (PDT) Received-SPF: neutral (google.com: 74.125.82.178 is neither permitted nor denied by best guess record for domain of lee.jones@linaro.org) client-ip=74.125.82.178; Authentication-Results: mx.google.com; spf=neutral (google.com: 74.125.82.178 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-we0-f178.google.com with SMTP id e53so1560530wer.37 for ; Thu, 17 May 2012 06:46:43 -0700 (PDT) Received: by 10.216.136.72 with SMTP id v50mr4735966wei.73.1337262403111; Thu, 17 May 2012 06:46:43 -0700 (PDT) Received: from localhost.localdomain (cpc1-aztw13-0-0-cust473.18-1.cable.virginmedia.com. [77.102.241.218]) by mx.google.com with ESMTPS id h8sm21166277wix.4.2012.05.17.06.46.41 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 17 May 2012 06:46:42 -0700 (PDT) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, arnd@arndb.de, linus.walleij@stericsson.com, grant.likely@secretlab.ca, cjb@laptop.org, broonie@opensource.wolfsonmicro.com, sameo@linux.intel.com Cc: Lee Jones , linux-kernel@vger.kernel.org Subject: [PATCH 09/18] regulator: ab8500: Split up probe() into manageable pieces Date: Thu, 17 May 2012 14:45:14 +0100 Message-Id: <1337262323-27692-10-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1337262323-27692-1-git-send-email-lee.jones@linaro.org> References: <1337262323-27692-1-git-send-email-lee.jones@linaro.org> X-Gm-Message-State: ALoCoQkpR1L+kpkemAIPL7HZzUusB0HpJe4ivMbQVbkzHcNcii0up3IQYRu2X86ObYb8tiDAHvOO ab8500's probe() function is becoming quite large, so in the lead up to Device Tree enablement which will fork the thread of execution this patch splits it into 3 main areas; basic error checking will remain in probe(), but regulator register initialisation and regulator registration have been moved to their own functions which will be called in sequence by probe() and the DT equivalent. Cc: linux-kernel@vger.kernel.org Signed-off-by: Lee Jones --- drivers/regulator/ab8500.c | 150 +++++++++++++++++++++++++------------------- 1 file changed, 87 insertions(+), 63 deletions(-) diff --git a/drivers/regulator/ab8500.c b/drivers/regulator/ab8500.c index d156390..3571b54 100644 --- a/drivers/regulator/ab8500.c +++ b/drivers/regulator/ab8500.c @@ -708,11 +708,92 @@ static struct ab8500_reg_init ab8500_reg_init[] = { REG_INIT(AB8500_REGUCTRLDISCH2, 0x04, 0x44, 0x16), }; +static __devinit int +ab8500_regulator_init_registers(struct platform_device *pdev, int id, int value) +{ + int err; + + if (value & ~ab8500_reg_init[id].mask) { + dev_err(&pdev->dev, + "Configuration error: value outside mask.\n"); + return -EINVAL; + } + + err = abx500_mask_and_set_register_interruptible( + &pdev->dev, + ab8500_reg_init[id].bank, + ab8500_reg_init[id].addr, + ab8500_reg_init[id].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); + 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, + ab8500_reg_init[id].mask, + value); + + return 0; +} + +static __devinit int ab8500_regulator_register(struct platform_device *pdev, + struct regulator_init_data *init_data, + 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->dev = &pdev->dev; + + config.dev = &pdev->dev; + config.init_data = init_data; + config.driver_data = info; + config.of_node = np; + + /* fix for hardware before ab8500v2.0 */ + if (abx500_get_chip_id(info->dev) < 0x20) { + if (info->desc.id == AB8500_LDO_AUX3) { + info->desc.n_voltages = + ARRAY_SIZE(ldo_vauxn_voltages); + info->voltages = ldo_vauxn_voltages; + info->voltages_len = + ARRAY_SIZE(ldo_vauxn_voltages); + info->voltage_mask = 0xf; + } + } + + /* register regulator with framework */ + info->regulator = regulator_register(&info->desc, &config); + if (IS_ERR(info->regulator)) { + err = PTR_ERR(info->regulator); + dev_err(&pdev->dev, "failed to register regulator %s\n", + info->desc.name); + /* when we fail, un-register all earlier regulators */ + while (--id >= 0) { + info = &ab8500_regulator_info[id]; + regulator_unregister(info->regulator); + } + return err; + } + + return 0; +} + static __devinit int ab8500_regulator_probe(struct platform_device *pdev) { struct ab8500 *ab8500 = dev_get_drvdata(pdev->dev.parent); struct ab8500_platform_data *pdata; - struct regulator_config config = { }; int i, err; if (!ab8500) { @@ -733,8 +814,7 @@ static __devinit int ab8500_regulator_probe(struct platform_device *pdev) /* initialize registers */ for (i = 0; i < pdata->num_regulator_reg_init; i++) { - int id; - u8 value; + int id, value; id = pdata->regulator_reg_init[i].id; value = pdata->regulator_reg_init[i].value; @@ -745,73 +825,17 @@ static __devinit int ab8500_regulator_probe(struct platform_device *pdev) "Configuration error: id outside range.\n"); return -EINVAL; } - if (value & ~ab8500_reg_init[id].mask) { - dev_err(&pdev->dev, - "Configuration error: value outside mask.\n"); - return -EINVAL; - } - /* initialize register */ - err = abx500_mask_and_set_register_interruptible(&pdev->dev, - ab8500_reg_init[id].bank, - ab8500_reg_init[id].addr, - ab8500_reg_init[id].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); + err = ab8500_regulator_init_registers(pdev, id, value); + if (err < 0) 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, - ab8500_reg_init[id].mask, - value); } /* register all regulators */ for (i = 0; i < ARRAY_SIZE(ab8500_regulator_info); i++) { - struct ab8500_regulator_info *info = NULL; - - /* assign per-regulator data */ - info = &ab8500_regulator_info[i]; - info->dev = &pdev->dev; - - config.dev = &pdev->dev; - config.init_data = &pdata->regulator[i]; - config.driver_data = info; - - /* fix for hardware before ab8500v2.0 */ - if (abx500_get_chip_id(info->dev) < 0x20) { - if (info->desc.id == AB8500_LDO_AUX3) { - info->desc.n_voltages = - ARRAY_SIZE(ldo_vauxn_voltages); - info->voltages = ldo_vauxn_voltages; - info->voltages_len = - ARRAY_SIZE(ldo_vauxn_voltages); - info->voltage_mask = 0xf; - } - } - - /* register regulator with framework */ - info->regulator = regulator_register(&info->desc, &config); - if (IS_ERR(info->regulator)) { - err = PTR_ERR(info->regulator); - dev_err(&pdev->dev, "failed to register regulator %s\n", - info->desc.name); - /* when we fail, un-register all earlier regulators */ - while (--i >= 0) { - info = &ab8500_regulator_info[i]; - regulator_unregister(info->regulator); - } + err = ab8500_regulator_register(pdev, &pdata->regulator[i], i, NULL); + if (err < 0) return err; - } - - dev_vdbg(rdev_get_dev(info->regulator), - "%s-probed\n", info->desc.name); } return 0;