From patchwork Sat May 24 00:53:58 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Turquette X-Patchwork-Id: 4236331 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 337599F32B for ; Sat, 24 May 2014 00:57:54 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 513FD203E3 for ; Sat, 24 May 2014 00:57:53 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 87A2C203E6 for ; Sat, 24 May 2014 00:57:48 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Wo0EM-0000PE-Pp; Sat, 24 May 2014 00:54:34 +0000 Received: from mail-pa0-f41.google.com ([209.85.220.41]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Wo0EK-0000Nd-FV for linux-arm-kernel@lists.infradead.org; Sat, 24 May 2014 00:54:33 +0000 Received: by mail-pa0-f41.google.com with SMTP id lj1so4836924pab.0 for ; Fri, 23 May 2014 17:54:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:content-type:mime-version :content-transfer-encoding:to:from:in-reply-to:cc:references :message-id:user-agent:subject:date; bh=oRKpETZ7tWjDFbddiQnwnkouTHUcMbl8VNAym2JCLbM=; b=PqbXIo3yIe9cC9LL1uZ/Bq83PRmK4PoDxTIbPALcbZGzziLQhi7nvkumjfDs3Q1Qxj xeS0XmFTKG62Vrfj2GWrcvMOnZ8ak0a2/iuBznJo2tsBeInxZlf7S9CuePkfRKZdx9zi 9lweIGP48TNYSU17oq35MKWUT7gd4cTDoGUqTGYb7EOPgBEfJbzMo2XWavpy38SNAq3c Q1IF0n9+Mb5nOIXiD6jvu1C8AB0Ga0BRYMsG0QDv+wmx0qdw3j7n97LSO3TSD6ZT3enV 1k1cCZjm9VCGTAcbAbClOwxpUX98gmnM4xHA6mY7FNrUKcBOh5t/ejI1fbuECyD1zzAm b6Yg== X-Gm-Message-State: ALoCoQk4TPCIqi+0+FPvfiK2yc4kYComJ8kMUvB7pRz2q9xzR9QoVPoIpyxqygzNtWgICO+vKPa7 X-Received: by 10.68.129.99 with SMTP id nv3mr10114400pbb.128.1400892849673; Fri, 23 May 2014 17:54:09 -0700 (PDT) Received: from localhost ([2601:9:5900:1fe:ca60:ff:fe0a:8a36]) by mx.google.com with ESMTPSA id nf5sm6542935pbc.77.2014.05.23.17.54.07 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 23 May 2014 17:54:08 -0700 (PDT) MIME-Version: 1.0 To: Alex Elder , mporter@linaro.org, bcm@fixthebug.org, devicetree@vger.kernel.org From: Mike Turquette In-Reply-To: <1400590362-11177-3-git-send-email-elder@linaro.org> References: <1400590362-11177-1-git-send-email-elder@linaro.org> <1400590362-11177-3-git-send-email-elder@linaro.org> Message-ID: <20140524005358.23136.8918@quantum> User-Agent: alot/0.3.5 Subject: Re: [PATCH v2 2/5] clk: bcm281xx: implement prerequisite clocks Date: Fri, 23 May 2014 17:53:58 -0700 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140523_175432_628913_5FC6E1BD X-CRM114-Status: GOOD ( 16.54 ) X-Spam-Score: -0.7 (/) Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Quoting Alex Elder (2014-05-20 05:52:39) > @@ -743,11 +746,16 @@ struct clk *kona_clk_setup(struct kona_clk *bcm_clk) > clk = clk_register(NULL, &bcm_clk->hw); > if (IS_ERR(clk)) { > pr_err("%s: error registering clock %s (%ld)\n", __func__, > - init_data->name, PTR_ERR(clk)); > + name, PTR_ERR(clk)); > goto out_teardown; > } > BUG_ON(!clk); > > + /* Make it so we can look the clock up using clk_find() */ s/clk_find/clk_get/ ? > + bcm_clk->cl.con_id = name; > + bcm_clk->cl.clk = clk; > + clkdev_add(&bcm_clk->cl); This is not so nice. I'll explain more below. > + > return clk; > out_teardown: > bcm_clk_teardown(bcm_clk); > diff --git a/drivers/clk/bcm/clk-kona.c b/drivers/clk/bcm/clk-kona.c > index d8a7f38..fd070d6 100644 > --- a/drivers/clk/bcm/clk-kona.c > +++ b/drivers/clk/bcm/clk-kona.c > @@ -1195,6 +1195,48 @@ static bool __peri_clk_init(struct kona_clk *bcm_clk) > return true; > } > > +static bool __kona_clk_init(struct kona_clk *bcm_clk); > +static bool __kona_prereq_init(struct kona_clk *bcm_clk) > +{ > + struct clk *clk; > + struct clk_hw *hw; > + struct kona_clk *prereq; > + > + BUG_ON(clk_is_initialized(bcm_clk)); > + > + if (!bcm_clk->p.prereq) > + return true; > + > + clk = clk_get(NULL, bcm_clk->p.prereq); The clkdev global namespace is getting polluted with all of these new prereq clocks. If there was an associated struct device *dev with them then it wouldn't be a problem, but you might get collisions with other clock drivers that also use NULL for the device. It would be a lot nicer for the clocks that require a prereq clock to just use clk_get(dev, "well_known_name"); in the same way that drivers use it, without considering it a special case. > + if (IS_ERR(clk)) { > + pr_err("%s: unable to get prereq clock %s for %s\n", > + __func__, bcm_clk->p.prereq, bcm_clk->init_data.name); > + return false; > + } > + hw = __clk_get_hw(clk); > + if (!hw) { > + pr_err("%s: null hw pointer for clock %s\n", __func__, > + bcm_clk->init_data.name); > + return false; > + } > + prereq = to_kona_clk(hw); > + if (prereq->ccu != bcm_clk->ccu) { > + pr_err("%s: prereq clock %s CCU different for clock %s\n", > + __func__, bcm_clk->p.prereq, bcm_clk->init_data.name); > + return false; > + } > + > + /* Initialize the prerequisite clock first */ > + if (!__kona_clk_init(prereq)) { > + pr_err("%s: failed to init prereq %s for clock %s\n", > + __func__, bcm_clk->p.prereq, bcm_clk->init_data.name); > + return false; > + } > + bcm_clk->p.prereq_clk = clk; The above seems like a lot effort to go to. Why not skip all of this and just implement the prerequisite logic in the .enable & .disable callbacks? E.g. your kona clk .enable callback would look like: I guess it might take some trickery to get clk_get to work like that. Let me know if I've completely lost the plot. Regards, Mike diff --git a/drivers/clk/bcm/clk-kona.c b/drivers/clk/bcm/clk-kona.c index d603c4e..51f35b4 100644 --- a/drivers/clk/bcm/clk-kona.c +++ b/drivers/clk/bcm/clk-kona.c @@ -987,6 +987,12 @@ static int kona_peri_clk_enable(struct clk_hw *hw) { struct kona_clk *bcm_clk = to_kona_clk(hw); struct bcm_clk_gate *gate = &bcm_clk->u.peri->gate; + int ret; + + hw->prereq_bus_clk = clk_get(hw->ccu, hw->prereq); + ret = clk_enable(prereq_bus_clk); + if (ret) + return ret; return clk_gate(bcm_clk->ccu, bcm_clk->init_data.name, gate, true); } @@ -997,6 +1003,9 @@ static void kona_peri_clk_disable(struct clk_hw *hw) struct bcm_clk_gate *gate = &bcm_clk->u.peri->gate; (void)clk_gate(bcm_clk->ccu, bcm_clk->init_data.name, gate, false); + + clk_disable(hw->prereq_bus_clk); + clk_put(hw->prereq_bus_clk); } static int kona_peri_clk_is_enabled(struct clk_hw *hw)