From patchwork Wed Mar 28 17:03:28 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karol Lewandowski X-Patchwork-Id: 7512 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 3A4FC23E0C for ; Wed, 28 Mar 2012 17:03:33 +0000 (UTC) Received: from mail-iy0-f180.google.com (mail-iy0-f180.google.com [209.85.210.180]) by fiordland.canonical.com (Postfix) with ESMTP id D18ACA184C4 for ; Wed, 28 Mar 2012 17:03:32 +0000 (UTC) Received: by iage36 with SMTP id e36so2292236iag.11 for ; Wed, 28 Mar 2012 10:03:32 -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:date:from :subject:in-reply-to:to:cc:message-id:mime-version:user-agent :references:x-gm-message-state:content-type :content-transfer-encoding; bh=hoi2TG96Dr/iBJydar2Mntiy8776ttyLlrISKvQLvYI=; b=ibu8grZrnCBcw8OL/fsdfWRzLxq2fx3aJxgRKHIvNshxfqarikFyMxvfVQWGWGu5aK R54TLMX1IMCI/MkVLIdp5hKVnZ3RrPNKEyJyL495J1wjmT42nStjRP/4gH/L96NRLFrk zoXJof8R7Z2gYYo0ZXt6g+0TIMyRxRO8P5fZC8ovjiNfk0CIUO8F6JMPoDBb5XLjRjOx kcB3DwQVRK9oToYDZWrZmtgrAEGvea/GzK/mEErg6wPCbG2X2u+Hf399QXFE837k9YM/ 2Ib1irBrfKSJ/ksYE5v6M11bCm6qgZUbV2Bf4DvBXkk/cJ3o817nYVCqPHw2vCAUKnqi xIMg== Received: by 10.50.46.164 with SMTP id w4mr2823820igm.54.1332954211942; Wed, 28 Mar 2012 10:03:31 -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.5.205 with SMTP id 13csp5822ibw; Wed, 28 Mar 2012 10:03:31 -0700 (PDT) Received: by 10.68.233.135 with SMTP id tw7mr45447980pbc.152.1332954210698; Wed, 28 Mar 2012 10:03:30 -0700 (PDT) Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com. [210.118.77.12]) by mx.google.com with ESMTP id u10si4943365pbv.322.2012.03.28.10.03.30; Wed, 28 Mar 2012 10:03:30 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of k.lewandowsk@samsung.com designates 210.118.77.12 as permitted sender) client-ip=210.118.77.12; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of k.lewandowsk@samsung.com designates 210.118.77.12 as permitted sender) smtp.mail=k.lewandowsk@samsung.com Received: from euspt1 (mailout2.w1.samsung.com [210.118.77.12]) by mailout2.w1.samsung.com (iPlanet Messaging Server 5.2 Patch 2 (built Jul 14 2004)) with ESMTP id <0M1L00AOPU1Q7W@mailout2.w1.samsung.com>; Wed, 28 Mar 2012 18:03:26 +0100 (BST) Received: from linux.samsung.com ([106.116.38.10]) by spt1.w1.samsung.com (iPlanet Messaging Server 5.2 Patch 2 (built Jul 14 2004)) with ESMTPA id <0M1L00MZJU1SLN@spt1.w1.samsung.com>; Wed, 28 Mar 2012 18:03:28 +0100 (BST) Received: from [106.116.48.101] (unknown [106.116.48.101]) by linux.samsung.com (Postfix) with ESMTP id 335C0270054; Wed, 28 Mar 2012 19:06:48 +0200 (CEST) Date: Wed, 28 Mar 2012 19:03:28 +0200 From: Karol Lewandowski Subject: Re: [PATCH v4 2/2] regulator: add device tree support for max8997 In-reply-to: <1332582590-16382-3-git-send-email-thomas.abraham@linaro.org> To: Thomas Abraham Cc: linux-kernel@vger.kernel.org, devicetree-discuss@lists.ozlabs.org, rob.herring@calxeda.com, grant.likely@secretlab.ca, kgene.kim@samsung.com, broonie@opensource.wolfsonmicro.com, myungjoo.ham@samsung.com, kyungmin.park@samsung.com, linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, patches@linaro.org, Rajendra Nayak Message-id: <4F734460.4060605@samsung.com> MIME-version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:8.0) Gecko/20111109 Icedove/8.0 References: <1332582590-16382-1-git-send-email-thomas.abraham@linaro.org> <1332582590-16382-3-git-send-email-thomas.abraham@linaro.org> X-Gm-Message-State: ALoCoQltnblr54elc0WkAKaoe5ywxwrhlgZee5LIAYo8sOv0AEEXcwzy9z96X0Il71y/8AGx9Djc Content-type: text/plain; charset=UTF-8 Content-transfer-encoding: 7BIT On 24.03.2012 10:49, Thomas Abraham wrote: Hi Thomas! > Add device tree based discovery support for max8997. ... > +Regulators: The regulators of max8997 that have to be instantiated should be > +included in a sub-node named 'regulators'. Regulator nodes included in this > +sub-node should be of the format as below. Note: The 'n' in LDOn and BUCKn > +represents the LDO or BUCK number as per the datasheet of max8997. > + > + For LDO's: > + LDOn { > + standard regulator bindings here > + }; > + > + For BUCK's: > + BUCKn { > + standard regulator bindings here > + }; > + Small note - driver supports[1] configuring following regulators by using respective DT node names: - EN32KHz_AP - EN32KHz_CP - ENVICHG - ESAFEOUT1 - ESAFEOUT2 - CHARGER - CHARGER_CV - CHARGER_TOPOFF I wonder if these should be mentioned in documentation too. [1] These are used in e.g. mach-nuri.c > diff --git a/drivers/regulator/max8997.c b/drivers/regulator/max8997.c> index 9657929..dce8aaf 100644 > --- a/drivers/regulator/max8997.c > +++ b/drivers/regulator/max8997.c .. > +static int max8997_pmic_dt_parse_pdata(struct max8997_dev *iodev, > + struct max8997_platform_data *pdata) > +{ > + struct device_node *pmic_np, *regulators_np, *reg_np; > + struct max8997_regulator_data *rdata; > + unsigned int i, dvs_voltage_nr = 1, ret; > + > + pmic_np = iodev->dev->of_node; > + if (!pmic_np) { > + dev_err(iodev->dev, "could not find pmic sub-node\n"); > + return -ENODEV; > + } > + > + regulators_np = of_find_node_by_name(pmic_np, "regulators"); > + if (!regulators_np) { > + dev_err(iodev->dev, "could not find regulators sub-node\n"); > + return -EINVAL; > + } > + > + /* count the number of regulators to be supported in pmic */ > + pdata->num_regulators = 0; > + for_each_child_of_node(regulators_np, reg_np) > + pdata->num_regulators++; > + > + rdata = devm_kzalloc(iodev->dev, sizeof(*rdata) * > + pdata->num_regulators, GFP_KERNEL); > + if (!rdata) { > + dev_err(iodev->dev, "could not allocate memory for " > + "regulator data\n"); > + return -ENOMEM; > + } > + pdata->regulators = rdata; > + for_each_child_of_node(regulators_np, reg_np) { > + for (i = 0; i < ARRAY_SIZE(regulators); i++) > + if (!of_node_cmp(reg_np->name, regulators[i].name)) > + break; > + rdata->id = i; rdata->id will be equal to ARRAY_SIZE(regulators) when one adds DT node name (below "regulators") which is different from what can be found in regulators[] table. On my test machine this results in hard lockup - possibly because something tries to access regulators[ARRAY_SIZE(regulators)] later on. Following patch fixes this on my machine (using DTS with misspelled LDO1 for LDx1): Regards, diff --git a/drivers/regulator/max8997.c b/drivers/regulator/max8997.c index dce8aaf..c20fd72 100644 --- a/drivers/regulator/max8997.c +++ b/drivers/regulator/max8997.c @@ -1011,6 +1011,13 @@ static int max8997_pmic_dt_parse_pdata(struct max8997_dev *iodev, for (i = 0; i < ARRAY_SIZE(regulators); i++) if (!of_node_cmp(reg_np->name, regulators[i].name)) break; + + if (i == ARRAY_SIZE(regulators)) { + dev_warn(iodev->dev, "don't know how to configure regulator %s\n", + reg_np->name); + continue; + } + rdata->id = i; rdata->initdata = of_get_regulator_init_data( iodev->dev, reg_np);