From patchwork Mon Apr 22 09:57:14 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 16301 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-vc0-f197.google.com (mail-vc0-f197.google.com [209.85.220.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 8400125DEE for ; Mon, 22 Apr 2013 09:58:21 +0000 (UTC) Received: by mail-vc0-f197.google.com with SMTP id hf12sf11914950vcb.0 for ; Mon, 22 Apr 2013 02:57:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:x-beenthere:x-received:received-spf:x-received :x-forwarded-to:x-forwarded-for:delivered-to:x-received:received-spf :from:to:cc:subject:date:message-id:x-mailer:mime-version :x-gm-message-state:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-google-group-id:list-post:list-help:list-archive:list-unsubscribe :content-type; bh=jDhuF94OX2sjMY1ffOz6aHxlBDIHXFARqTNavoqOKfY=; b=dOccu+Br2u8dV2uOQ39WpXpFy3A6LzIlTDY68+qe4DsREkWXXCa+DhrpFGNRuBCllk f980CksVv8JWwh6m1HhtHiYTjaB2BfSbK2d8TADV5kLEg6DM5cnEzJhUpJDHYdEyTZfU gMR+ImuQNeiLKWaKueFGN8ZbDFvJMXhfe/pENWJYnRjU5XzhkdHJ7NltaiGAxvt1xaT3 0vylEFEYYQJY2sagFkNnZLmvnicBMUS0YnI4Ou3oC5CtC1Flq+XvHynRxQiTLriPzE2I llLDbdMgtPrJf4qciFPL4EtbVE+q3BbHsrG/yTUmKvtda76xfzZFRqhDa2f1V7c+155f 0JhQ== X-Received: by 10.236.199.198 with SMTP id x46mr729673yhn.41.1366624655427; Mon, 22 Apr 2013 02:57:35 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.118.161 with SMTP id kn1ls2854151qeb.33.gmail; Mon, 22 Apr 2013 02:57:35 -0700 (PDT) X-Received: by 10.52.176.1 with SMTP id ce1mr10899138vdc.68.1366624655327; Mon, 22 Apr 2013 02:57:35 -0700 (PDT) Received: from mail-vc0-f172.google.com (mail-vc0-f172.google.com [209.85.220.172]) by mx.google.com with ESMTPS id sx2si15548853vdc.84.2013.04.22.02.57.35 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 22 Apr 2013 02:57:35 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.172 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.172; Received: by mail-vc0-f172.google.com with SMTP id hx10so632800vcb.17 for ; Mon, 22 Apr 2013 02:57:35 -0700 (PDT) X-Received: by 10.52.163.231 with SMTP id yl7mr15704255vdb.57.1366624655163; Mon, 22 Apr 2013 02:57:35 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.58.127.98 with SMTP id nf2csp68855veb; Mon, 22 Apr 2013 02:57:34 -0700 (PDT) X-Received: by 10.194.5.196 with SMTP id u4mr50757970wju.54.1366624653949; Mon, 22 Apr 2013 02:57:33 -0700 (PDT) Received: from eu1sys200aog121.obsmtp.com (eu1sys200aog121.obsmtp.com [207.126.144.151]) by mx.google.com with SMTP id f43si38628786eev.44.2013.04.22.02.57.25 (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 22 Apr 2013 02:57:33 -0700 (PDT) Received-SPF: neutral (google.com: 207.126.144.151 is neither permitted nor denied by best guess record for domain of linus.walleij@stericsson.com) client-ip=207.126.144.151; Received: from beta.dmz-eu.st.com ([164.129.1.35]) (using TLSv1) by eu1sys200aob121.postini.com ([207.126.147.11]) with SMTP ID DSNKUXUJghQiIWp1h4S2GHStqWtgmxA2aPfn@postini.com; Mon, 22 Apr 2013 09:57:33 UTC Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id A307514F; Mon, 22 Apr 2013 09:57:21 +0000 (GMT) Received: from relay1.stm.gmessaging.net (unknown [10.230.100.17]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 73CCB487F; Mon, 22 Apr 2013 09:57:15 +0000 (GMT) Received: from exdcvycastm022.EQ1STM.local (alteon-source-exch [10.230.100.61]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (Client CN "exdcvycastm022", Issuer "exdcvycastm022" (not verified)) by relay1.stm.gmessaging.net (Postfix) with ESMTPS id 776DF24C07C; Mon, 22 Apr 2013 11:57:15 +0200 (CEST) Received: from steludxu4075.lud.stericsson.com (10.230.100.153) by smtp.stericsson.com (10.230.100.30) with Microsoft SMTP Server (TLS) id 8.3.279.5; Mon, 22 Apr 2013 11:57:20 +0200 From: Linus Walleij To: , Liam Girdwood , Mark Brown Cc: Arnd Bergmann , , Linus Walleij Subject: [PATCH 13/23] regulator: ab3100: refactor probe to use IDs Date: Mon, 22 Apr 2013 11:57:14 +0200 Message-ID: <1366624634-6579-1-git-send-email-linus.walleij@stericsson.com> X-Mailer: git-send-email 1.7.11.3 MIME-Version: 1.0 X-Gm-Message-State: ALoCoQn/xRzcl291jbTKQDA+bylvS2E6/6c+JKRrCFWDSaOLazB/GJRJKRNCvK5SWxZNqZw/HseR X-Original-Sender: linus.walleij@stericsson.com X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.172 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Linus Walleij This refactors the AB3100 regulator probe to use regulator IDs and pass this to a separate registration function. This works much smoother when migrating to device tree, as we can use a match table with this regulator ID encoded in the .driver_data. Cc: Mark Brown Signed-off-by: Linus Walleij --- Hi Mark, seeking an ACK on this to take it through the ARM SoC tree. --- drivers/regulator/ab3100.c | 90 ++++++++++++++++++++++++++++------------------ 1 file changed, 55 insertions(+), 35 deletions(-) diff --git a/drivers/regulator/ab3100.c b/drivers/regulator/ab3100.c index 111ec69..740735d 100644 --- a/drivers/regulator/ab3100.c +++ b/drivers/regulator/ab3100.c @@ -488,6 +488,58 @@ ab3100_regulator_desc[AB3100_NUM_REGULATORS] = { }, }; +static int ab3100_regulator_register(struct platform_device *pdev, + struct ab3100_platform_data *plfdata, + int id) +{ + struct regulator_desc *desc; + struct ab3100_regulator *reg; + struct regulator_dev *rdev; + struct regulator_config config = { }; + int err, i; + + for (i = 0; i < AB3100_NUM_REGULATORS; i++) { + desc = &ab3100_regulator_desc[i]; + if (desc->id == id) + break; + } + if (desc->id != id) + return -ENODEV; + + /* Same index used for this array */ + reg = &ab3100_regulators[i]; + + /* + * Initialize per-regulator struct. + * Inherit platform data, this comes down from the + * i2c boarddata, from the machine. So if you want to + * see what it looks like for a certain machine, go + * into the machine I2C setup. + */ + reg->dev = &pdev->dev; + if (plfdata) { + /* This will be replaced by device tree data */ + reg->plfdata = plfdata; + config.init_data = &plfdata->reg_constraints[i]; + } + config.dev = &pdev->dev; + config.driver_data = reg; + + rdev = regulator_register(desc, &config); + if (IS_ERR(rdev)) { + err = PTR_ERR(rdev); + dev_err(&pdev->dev, + "%s: failed to register regulator %s err %d\n", + __func__, desc->name, + err); + return err; + } + + /* Then set a pointer back to the registered regulator */ + reg->rdev = rdev; + return 0; +} + /* * NOTE: the following functions are regulators pluralis - it is the * binding to the AB3100 core driver and the parent platform device @@ -497,7 +549,6 @@ ab3100_regulator_desc[AB3100_NUM_REGULATORS] = { static int ab3100_regulators_probe(struct platform_device *pdev) { struct ab3100_platform_data *plfdata = pdev->dev.platform_data; - struct regulator_config config = { }; int err = 0; u8 data; int i; @@ -530,42 +581,11 @@ static int ab3100_regulators_probe(struct platform_device *pdev) /* Register the regulators */ for (i = 0; i < AB3100_NUM_REGULATORS; i++) { - struct ab3100_regulator *reg = &ab3100_regulators[i]; - struct regulator_dev *rdev; - - /* - * Initialize per-regulator struct. - * Inherit platform data, this comes down from the - * i2c boarddata, from the machine. So if you want to - * see what it looks like for a certain machine, go - * into the machine I2C setup. - */ - reg->dev = &pdev->dev; - reg->plfdata = plfdata; - - config.dev = &pdev->dev; - config.driver_data = reg; - config.init_data = &plfdata->reg_constraints[i]; + struct regulator_desc *desc = &ab3100_regulator_desc[i]; - /* - * Register the regulator, pass around - * the ab3100_regulator struct - */ - rdev = regulator_register(&ab3100_regulator_desc[i], &config); - if (IS_ERR(rdev)) { - err = PTR_ERR(rdev); - dev_err(&pdev->dev, - "%s: failed to register regulator %s err %d\n", - __func__, ab3100_regulator_desc[i].name, - err); - /* remove the already registered regulators */ - while (--i >= 0) - regulator_unregister(ab3100_regulators[i].rdev); + err = ab3100_regulator_register(pdev, plfdata, desc->id); + if (err) return err; - } - - /* Then set a pointer back to the registered regulator */ - reg->rdev = rdev; } return 0;