All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ben Dooks <ben-i2c-elnMNo+KYs3YtjvyW6yDsg@public.gmane.org>
To: "Nayak, Rajendra" <rnayak-l0cyMroinI0@public.gmane.org>
Cc: Ben Dooks <ben-i2c-elnMNo+KYs3YtjvyW6yDsg@public.gmane.org>,
	Paul Walmsley <paul-DWxLp4Yu+b8AvxtiuMwx3w@public.gmane.org>,
	Kevin Hilman
	<khilman-1D3HCaltpLuhEniVeURVKkEOCMrvLtNR@public.gmane.org>,
	"linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org"
	<linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	"ben-linux-elnMNo+KYs3YtjvyW6yDsg@public.gmane.org"
	<ben-linux-elnMNo+KYs3YtjvyW6yDsg@public.gmane.org>,
	"khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org"
	<khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org>,
	"linux-omap-u79uwXL29TY76Z2rM5mHXA@public.gmane.org"
	<linux-omap-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	"linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org"
	<linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org>
Subject: Re: [PATCH v3 5/5] OMAP: I2C: Convert i2c driver to use PM runtime api's
Date: Wed, 29 Sep 2010 00:33:34 +0100	[thread overview]
Message-ID: <20100928233334.GS21564@trinity.fluff.org> (raw)
In-Reply-To: <0680EC522D0CC943BC586913CF3768C003FF05988F-/tLxBxkBPtCIQmiDNMet8wC/G2K4zDHf@public.gmane.org>

On Tue, Sep 28, 2010 at 12:29:01PM +0530, Nayak, Rajendra wrote:
> <snip>...
> > > >
> > > >  static int omap_i2c_init(struct omap_i2c_dev *dev)
> > > > @@ -356,6 +333,7 @@ static int omap_i2c_init(struct omap_i2c_dev *dev)
> > > >  	unsigned long fclk_rate = 12000000;
> > > >  	unsigned long timeout;
> > > >  	unsigned long internal_clk = 0;
> > > > +	struct clk *fclk;
> > > >
> > > >  	if (dev->rev >= OMAP_I2C_REV_2) {
> > > >  		/* Disable I2C controller before soft reset */
> > > > @@ -414,7 +392,8 @@ static int omap_i2c_init(struct omap_i2c_dev *dev)
> > > >  		 * always returns 12MHz for the functional clock, we can
> > > >  		 * do this bit unconditionally.
> > > >  		 */
> > > > -		fclk_rate = clk_get_rate(dev->fclk);
> > > > +		fclk = clk_get(dev->dev, "fck");
> > > > +		fclk_rate = clk_get_rate(fclk);
> > > >
> > > >  		/* TRM for 5912 says the I2C clock must be prescaled to be
> > > >  		 * between 7 - 12 MHz. The XOR input clock is typically
> > > > @@ -443,7 +422,8 @@ static int omap_i2c_init(struct omap_i2c_dev *dev)
> > > >  			internal_clk = 9600;
> > > >  		else
> > > >  			internal_clk = 4000;
> > > > -		fclk_rate = clk_get_rate(dev->fclk) / 1000;
> > > > +		fclk = clk_get(dev->dev, "fck");
> > > > +		fclk_rate = clk_get_rate(fclk) / 1000;
> > >
> > > You don't put the clk after getting it and using it once?
> > 
> > clk_get needs an equivalent clk_put and not clk_get_rate. clk_get_rate
> > is used to merely know the existing rate of the clock.
> 
> Sorry, I guess you did mean the clk_get above the clk_get_rate does not have
> an equivalent clk_put.
> I could put a clk_put for readability, but a clk_put on OMAP actually does map
> to an empty function.
> See arch/arm/plat-omap/include/plat/clkdev.h
> clk_get merely returns a pointer to the clk struct and does not do any usecounting,
> hence a clk_put does not do anything.

clk_get() should have a reference counter, and on many systems does.

This is why we ask people to put clk_put() when they don't need the
clock any more. It may not do anything on your system, but it will
set a good example to anyone copying your driver code.

As such, I should really go and read up all about this new runtime-pm
and hwmod stuff before further commentign on the changes.
 
> > 
> > >
> > > >  		/* Compute prescaler divisor */
> > > >  		psc = fclk_rate / internal_clk;
> > > > @@ -1046,14 +1026,12 @@ omap_i2c_probe(struct platform_device *pdev)
> > > >  	else
> > > >  		dev->reg_shift = 2;
> > > >
> > > > -	if ((r = omap_i2c_get_clocks(dev)) != 0)
> > > > -		goto err_iounmap;
> > > > -
> > > >  	if (cpu_is_omap44xx())
> > > >  		dev->regs = (u8 *) omap4_reg_map;
> > > >  	else
> > > >  		dev->regs = (u8 *) reg_map;
> > > >
> > > > +	pm_runtime_enable(&pdev->dev);
> > > >  	omap_i2c_unidle(dev);
> > > >
> > > >  	dev->rev = omap_i2c_read_reg(dev, OMAP_I2C_REV_REG) & 0xff;
> > > > @@ -1125,8 +1103,6 @@ err_free_irq:
> > > >  err_unuse_clocks:
> > > >  	omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0);
> > > >  	omap_i2c_idle(dev);
> > > > -	omap_i2c_put_clocks(dev);
> > > > -err_iounmap:
> > > >  	iounmap(dev->base);
> > > >  err_free_mem:
> > > >  	platform_set_drvdata(pdev, NULL);
> > > > @@ -1148,7 +1124,6 @@ omap_i2c_remove(struct platform_device *pdev)
> > > >  	free_irq(dev->irq, dev);
> > > >  	i2c_del_adapter(&dev->adapter);
> > > >  	omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0);
> > > > -	omap_i2c_put_clocks(dev);
> > > >  	iounmap(dev->base);
> > > >  	kfree(dev);
> > > >  	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> > > > --
> > > > 1.5.4.7
> > > >
> > > > --
> > > > To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
> > > > the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
> > > > More majordomo info at  http://vger.kernel.org/majordomo-info.html
> > >
> > > --
> > > --
> > > Ben
> > >
> > > Q:      What's a light-year?
> > > A:      One-third less calories than a regular year.
> > 
> > --
> > To unsubscribe from this list: send the line "unsubscribe linux-omap" in
> > the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
> > More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

-- 
-- 
Ben

Q:      What's a light-year?
A:      One-third less calories than a regular year.

WARNING: multiple messages have this Message-ID (diff)
From: ben-i2c@fluff.org (Ben Dooks)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v3 5/5] OMAP: I2C: Convert i2c driver to use PM runtime api's
Date: Wed, 29 Sep 2010 00:33:34 +0100	[thread overview]
Message-ID: <20100928233334.GS21564@trinity.fluff.org> (raw)
In-Reply-To: <0680EC522D0CC943BC586913CF3768C003FF05988F@dbde02.ent.ti.com>

On Tue, Sep 28, 2010 at 12:29:01PM +0530, Nayak, Rajendra wrote:
> <snip>...
> > > >
> > > >  static int omap_i2c_init(struct omap_i2c_dev *dev)
> > > > @@ -356,6 +333,7 @@ static int omap_i2c_init(struct omap_i2c_dev *dev)
> > > >  	unsigned long fclk_rate = 12000000;
> > > >  	unsigned long timeout;
> > > >  	unsigned long internal_clk = 0;
> > > > +	struct clk *fclk;
> > > >
> > > >  	if (dev->rev >= OMAP_I2C_REV_2) {
> > > >  		/* Disable I2C controller before soft reset */
> > > > @@ -414,7 +392,8 @@ static int omap_i2c_init(struct omap_i2c_dev *dev)
> > > >  		 * always returns 12MHz for the functional clock, we can
> > > >  		 * do this bit unconditionally.
> > > >  		 */
> > > > -		fclk_rate = clk_get_rate(dev->fclk);
> > > > +		fclk = clk_get(dev->dev, "fck");
> > > > +		fclk_rate = clk_get_rate(fclk);
> > > >
> > > >  		/* TRM for 5912 says the I2C clock must be prescaled to be
> > > >  		 * between 7 - 12 MHz. The XOR input clock is typically
> > > > @@ -443,7 +422,8 @@ static int omap_i2c_init(struct omap_i2c_dev *dev)
> > > >  			internal_clk = 9600;
> > > >  		else
> > > >  			internal_clk = 4000;
> > > > -		fclk_rate = clk_get_rate(dev->fclk) / 1000;
> > > > +		fclk = clk_get(dev->dev, "fck");
> > > > +		fclk_rate = clk_get_rate(fclk) / 1000;
> > >
> > > You don't put the clk after getting it and using it once?
> > 
> > clk_get needs an equivalent clk_put and not clk_get_rate. clk_get_rate
> > is used to merely know the existing rate of the clock.
> 
> Sorry, I guess you did mean the clk_get above the clk_get_rate does not have
> an equivalent clk_put.
> I could put a clk_put for readability, but a clk_put on OMAP actually does map
> to an empty function.
> See arch/arm/plat-omap/include/plat/clkdev.h
> clk_get merely returns a pointer to the clk struct and does not do any usecounting,
> hence a clk_put does not do anything.

clk_get() should have a reference counter, and on many systems does.

This is why we ask people to put clk_put() when they don't need the
clock any more. It may not do anything on your system, but it will
set a good example to anyone copying your driver code.

As such, I should really go and read up all about this new runtime-pm
and hwmod stuff before further commentign on the changes.
 
> > 
> > >
> > > >  		/* Compute prescaler divisor */
> > > >  		psc = fclk_rate / internal_clk;
> > > > @@ -1046,14 +1026,12 @@ omap_i2c_probe(struct platform_device *pdev)
> > > >  	else
> > > >  		dev->reg_shift = 2;
> > > >
> > > > -	if ((r = omap_i2c_get_clocks(dev)) != 0)
> > > > -		goto err_iounmap;
> > > > -
> > > >  	if (cpu_is_omap44xx())
> > > >  		dev->regs = (u8 *) omap4_reg_map;
> > > >  	else
> > > >  		dev->regs = (u8 *) reg_map;
> > > >
> > > > +	pm_runtime_enable(&pdev->dev);
> > > >  	omap_i2c_unidle(dev);
> > > >
> > > >  	dev->rev = omap_i2c_read_reg(dev, OMAP_I2C_REV_REG) & 0xff;
> > > > @@ -1125,8 +1103,6 @@ err_free_irq:
> > > >  err_unuse_clocks:
> > > >  	omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0);
> > > >  	omap_i2c_idle(dev);
> > > > -	omap_i2c_put_clocks(dev);
> > > > -err_iounmap:
> > > >  	iounmap(dev->base);
> > > >  err_free_mem:
> > > >  	platform_set_drvdata(pdev, NULL);
> > > > @@ -1148,7 +1124,6 @@ omap_i2c_remove(struct platform_device *pdev)
> > > >  	free_irq(dev->irq, dev);
> > > >  	i2c_del_adapter(&dev->adapter);
> > > >  	omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0);
> > > > -	omap_i2c_put_clocks(dev);
> > > >  	iounmap(dev->base);
> > > >  	kfree(dev);
> > > >  	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> > > > --
> > > > 1.5.4.7
> > > >
> > > > --
> > > > To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
> > > > the body of a message to majordomo at vger.kernel.org
> > > > More majordomo info at  http://vger.kernel.org/majordomo-info.html
> > >
> > > --
> > > --
> > > Ben
> > >
> > > Q:      What's a light-year?
> > > A:      One-third less calories than a regular year.
> > 
> > --
> > To unsubscribe from this list: send the line "unsubscribe linux-omap" in
> > the body of a message to majordomo at vger.kernel.org
> > More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

-- 
-- 
Ben

Q:      What's a light-year?
A:      One-third less calories than a regular year.

  parent reply	other threads:[~2010-09-28 23:33 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-21 14:07 [PATCH v3 0/5] Convert I2C driver to use omap_device/runtime PM Rajendra Nayak
2010-09-21 14:07 ` Rajendra Nayak
     [not found] ` <1285078036-12789-1-git-send-email-rnayak-l0cyMroinI0@public.gmane.org>
2010-09-21 14:07   ` [PATCH v3 1/5] OMAP2xxx: hwmod: add I2C hwmods for OMAP2420, 2430 Rajendra Nayak
2010-09-21 14:07     ` Rajendra Nayak
2010-09-21 14:07     ` [PATCH v3 2/5] OMAP3: hwmod: add I2C hwmods for OMAP3430 Rajendra Nayak
2010-09-21 14:07       ` Rajendra Nayak
     [not found]       ` <1285078036-12789-3-git-send-email-rnayak-l0cyMroinI0@public.gmane.org>
2010-09-21 14:07         ` [PATCH v3 3/5] OMAP4: hwmod: add I2C hwmods for OMAP4430 Rajendra Nayak
2010-09-21 14:07           ` Rajendra Nayak
2010-09-21 14:07           ` [PATCH v3 4/5] OMAP: I2C: split device registration and convert OMAP2+ to omap_device Rajendra Nayak
2010-09-21 14:07             ` Rajendra Nayak
2010-09-21 14:07             ` [PATCH v3 5/5] OMAP: I2C: Convert i2c driver to use PM runtime api's Rajendra Nayak
2010-09-21 14:07               ` Rajendra Nayak
     [not found]               ` <1285078036-12789-6-git-send-email-rnayak-l0cyMroinI0@public.gmane.org>
2010-09-27 22:36                 ` Ben Dooks
2010-09-27 22:36                   ` Ben Dooks
     [not found]                   ` <20100927223645.GJ21564-SMNkleLxa3Z6Wcw2j4pizdi2O/JbrIOy@public.gmane.org>
2010-09-28  5:58                     ` Nayak, Rajendra
2010-09-28  5:58                       ` Nayak, Rajendra
     [not found]                       ` <0680EC522D0CC943BC586913CF3768C003FF05981F-/tLxBxkBPtCIQmiDNMet8wC/G2K4zDHf@public.gmane.org>
2010-09-28  6:59                         ` Nayak, Rajendra
2010-09-28  6:59                           ` Nayak, Rajendra
     [not found]                           ` <0680EC522D0CC943BC586913CF3768C003FF05988F-/tLxBxkBPtCIQmiDNMet8wC/G2K4zDHf@public.gmane.org>
2010-09-28  7:48                             ` Russell King - ARM Linux
2010-09-28  7:48                               ` Russell King - ARM Linux
     [not found]                               ` <20100928074840.GA29252-l+eeeJia6m9vn6HldHNs0ANdhmdF6hFW@public.gmane.org>
2010-09-28  8:56                                 ` Nayak, Rajendra
2010-09-28  8:56                                   ` Nayak, Rajendra
2010-09-28 23:33                             ` Ben Dooks [this message]
2010-09-28 23:33                               ` Ben Dooks
     [not found]                               ` <20100928233334.GS21564-SMNkleLxa3Z6Wcw2j4pizdi2O/JbrIOy@public.gmane.org>
2010-09-29  4:00                                 ` Nayak, Rajendra
2010-09-29  4:00                                   ` Nayak, Rajendra
2010-10-07 17:37                                 ` Kevin Hilman
2010-10-07 17:37                                   ` Kevin Hilman
     [not found]                                   ` <87vd5d9a68.fsf-1D3HCaltpLuhEniVeURVKkEOCMrvLtNR@public.gmane.org>
2010-10-27  7:35                                     ` Ben Dooks
2010-10-27  7:35                                       ` Ben Dooks
2010-11-09 17:41                                       ` Kevin Hilman
2010-11-09 17:41                                         ` Kevin Hilman
2010-09-27 20:02 ` [PATCH v3 0/5] Convert I2C driver to use omap_device/runtime PM Kevin Hilman
2010-09-27 20:02   ` Kevin Hilman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100928233334.GS21564@trinity.fluff.org \
    --to=ben-i2c-elnmno+kys3ytjvyw6ydsg@public.gmane.org \
    --cc=ben-linux-elnMNo+KYs3YtjvyW6yDsg@public.gmane.org \
    --cc=khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org \
    --cc=khilman-1D3HCaltpLuhEniVeURVKkEOCMrvLtNR@public.gmane.org \
    --cc=linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
    --cc=linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-omap-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=paul-DWxLp4Yu+b8AvxtiuMwx3w@public.gmane.org \
    --cc=rnayak-l0cyMroinI0@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.