PNX clock API fixes
Subsystems (5)
cover PNX clock API fixes
Following on from the previous set of patches...
The PNX4008 clock API usage is extremely poor. Nothing works as it was intended to - clk_set_rate() is used to turn clocks on and off, or set dividers. I certainly doesn't take the desired clock rate in Hz. clk_get_rate() doesn't report the clock rate in Hz either - it doesn't even report any kind of rate.
clk_enable and clk_disable seem to be very weird too.
This patch set fixes the I2C and watchdog drivers so that they can be used with clk API implementations which do actually conform with the clk API.
As per the previous set, selective cc's. Full set will be on linux-arm-kernel.
PATCH 1/10 ARM: PNX4008: convert to clkdev
--- arch/arm/Kconfig | 1 + arch/arm/mach-pnx4008/clock.c | 69 +++++++++++++++------------ arch/arm/mach-pnx4008/clock.h | 2 - arch/arm/mach-pnx4008/include/mach/clkdev.h | 7 +++ 4 files changed, 46 insertions(+), 33 deletions(-) create mode 100644 arch/arm/mach-pnx4008/include/mach/clkdev.h
arch/arm/Kconfig +1 -0
@@ -541,6 +541,7 @@ config ARCH_PNX4008 bool "Philips Nexperia PNX4008 Mobile" select CPU_ARM926T select HAVE_CLK + select COMMON_CLKDEV help This enables support for Philips PNX4008 mobile platform.
arch/arm/mach-pnx4008/clock.c +38 -31
106 lines not on this page · raw message
arch/arm/mach-pnx4008/clock.h +0 -2
@@ -14,8 +14,6 @@#define __ARCH_ARM_PNX4008_CLOCK_H__struct clk { -struct list_head node; -struct module *owner;const char *name;struct clk *parent;struct clk *propagate_next;
arch/arm/mach-pnx4008/include/mach/clkdev.h new file +7 -0
@@ -0,0 +1,7 @@ +#ifndef __ASM_MACH_CLKDEV_H +#define __ASM_MACH_CLKDEV_H + +#define __clk_get (clk) ({ 1; }) +#define __clk_put (clk) do { } while (0) + +#endif
Signature · 1 line
1.6.2.5
PATCH 2/10 ARM: PNX4008: simplify clk enable/disable paths
In reply to Russell King - ARM Linux--- arch/arm/mach-pnx4008/clock.c | 55 +++++++++++++++++----------------------- 1 files changed, 23 insertions(+), 32 deletions(-)
arch/arm/mach-pnx4008/clock.c +23 -32
@@ -808,49 +808,40 @@ static struct clk_lookup onchip_clkreg[] = { { .clk = &wdt_ck, .con_id = "wdt_ck" }, }; -static int local_clk_enable (struct clk *clk) -{ -int ret =0 ; - -if (!(clk->flags &FIXED_RATE ) && !clk->rate && clk->set_rate - && clk->user_rate) - ret = clk->set_rate (clk, clk->user_rate); -return ret; -} -static void local_clk_disable (struct clk *clk) { -if (!(clk->flags &FIXED_RATE ) && clk->rate && clk->set_rate) - clk->set_rate (clk,0 ); -} +if (WARN_ON (clk->usecount ==0 )) +return ; -static void local_clk_unuse (struct clk *clk) -{ -if (clk->usecount >0 && !(--clk->usecount)) { -local_clk_disable (clk); +if (!(--clk->usecount)) { +if (!(clk->flags &FIXED_RATE ) && clk->rate && clk->set_rate) + clk->set_rate (clk,0 );if (clk->parent) -local_clk_unuse (clk->parent); +local_clk_disable (clk->parent); } } -static int local_clk_use (struct clk *clk) +static int local_clk_enable (struct clk *clk) {int ret =0 ; -if (clk->usecount++ ==0 ) { -if (clk->parent) - ret =local_clk_use (clk->parent); -if (ret !=0 ) { - clk->usecount--; - goto out; +if (clk->usecount ==0 ) { +if (clk->parent) { + ret =local_clk_enable (clk->parent); +if (ret !=0 ) + goto out; } - ret =local_clk_enable (clk); +if (!(clk->flags &FIXED_RATE ) && !clk->rate && clk->set_rate + && clk->user_rate) + ret = clk->set_rate (clk, clk->user_rate);if (ret !=0 && clk->parent) { -local_clk_unuse (clk->parent); - clk->usecount--; +local_clk_disable (clk->parent); + goto out; } + + clk->usecount++; } out:return ret;
@@ -909,10 +900,10 @@ EXPORT_SYMBOL(clk_get_rate);int clk_enable (struct clk *clk) { -int ret =0 ; +int ret;clock_lock (); - ret =local_clk_use (clk); + ret =local_clk_enable (clk);clock_unlock ();return ret; }
@@ -922,7 +913,7 @@ EXPORT_SYMBOL(clk_enable);void clk_disable (struct clk *clk) {clock_lock (); -local_clk_unuse (clk); +local_clk_disable (clk);clock_unlock (); }
@@ -981,7 +972,7 @@ static int __init clk_init(void) __func__, (*clkp)->name, (*clkp)->rate); } -local_clk_use (&ck_pll4); +local_clk_enable (&ck_pll4);/* if ck_13MHz is not used, disable it. */ if (ck_13MHz.usecount ==0 )
Signature · 1 line
1.6.2.5
PATCH 3/10 ARM: PNX4008: provide clock enable/disable methods and initialization
In reply to Russell King - ARM Linux--- arch/arm/mach-pnx4008/clock.c | 35 +++++++++++++++++++++++------------ arch/arm/mach-pnx4008/clock.h | 4 +++- 2 files changed, 26 insertions(+), 13 deletions(-)
arch/arm/mach-pnx4008/clock.c +23 -12
@@ -57,18 +57,19 @@ static void propagate_rate(struct clk *clk) } } -static inline void clk_reg_disable (struct clk *clk) +static void clk_reg_disable (struct clk *clk) {if (clk->enable_reg)__raw_writel (__raw_readl (clk->enable_reg) & ~(1 << clk->enable_shift), clk->enable_reg); } -static inline void clk_reg_enable (struct clk *clk) +static int clk_reg_enable (struct clk *clk) {if (clk->enable_reg)__raw_writel (__raw_readl (clk->enable_reg) | (1 << clk->enable_shift), clk->enable_reg); +return 0 ; }static inline void clk_reg_disable1 (struct clk *clk)
@@ -814,7 +815,9 @@ static void local_clk_disable(struct clk *clk)return ;if (!(--clk->usecount)) { -if (!(clk->flags &FIXED_RATE ) && clk->rate && clk->set_rate) +if (clk->disable) + clk->disable (clk); +else if (!(clk->flags &FIXED_RATE ) && clk->rate && clk->set_rate) clk->set_rate (clk,0 );if (clk->parent)local_clk_disable (clk->parent);
@@ -832,8 +835,10 @@ static int local_clk_enable(struct clk *clk) goto out; } -if (!(clk->flags &FIXED_RATE ) && !clk->rate && clk->set_rate - && clk->user_rate) +if (clk->enable) + ret = clk->enable (clk); +else if (!(clk->flags &FIXED_RATE ) && !clk->rate && clk->set_rate + && clk->user_rate) ret = clk->set_rate (clk, clk->user_rate);if (ret !=0 && clk->parent) {
@@ -961,15 +966,21 @@ static int __init clk_init(void)for (clkp = onchip_clks; clkp < onchip_clks +ARRAY_SIZE (onchip_clks); clkp++) { -if (((*clkp)->flags &NEEDS_INITIALIZATION ) - && ((*clkp)->set_rate)) { - (*clkp)->user_rate = (*clkp)->rate; -local_set_rate ((*clkp), (*clkp)->user_rate); -if ((*clkp)->set_parent) - (*clkp)->set_parent ((*clkp), (*clkp)->parent); +struct clk *clk = *clkp; +if (clk->flags &NEEDS_INITIALIZATION ) { +if (clk->set_rate) { + clk->user_rate = clk->rate; +local_set_rate (clk, clk->user_rate); +if (clk->set_parent) + clk->set_parent (clk, clk->parent); + } +if (clk->enable && clk->usecount) + clk->enable (clk); +if (clk->disable && !clk->usecount) + clk->disable (clk); }pr_debug ("%s: clock %s, rate %ld\n" , - __func__, (*clkp)->name, (*clkp)->rate); + __func__, clk->name, clk->rate); }local_clk_enable (&ck_pll4);
arch/arm/mach-pnx4008/clock.h +3 -1
@@ -27,9 +27,11 @@ struct clk {u8 enable_shift1;u32 enable_reg1;u32 parent_switch_reg; -u32 (*round_rate) (struct clk *,u32 ); +u32 (*round_rate) (struct clk *,u32 );int (*set_rate) (struct clk *,u32 );int (*set_parent) (struct clk * clk,struct clk * parent); +int (*enable)(struct clk *); +void (*disable)(struct clk *); };/* Flags */
Signature · 1 line
1.6.2.5
PATCH 4/10 ARM: PNX4008: convert watchdog clocks to match by device only
In reply to Russell King - ARM Linux--- arch/arm/mach-pnx4008/clock.c | 2 +- drivers/watchdog/pnx4008_wdt.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
arch/arm/mach-pnx4008/clock.c +1 -1
@@ -806,7 +806,7 @@ static struct clk_lookup onchip_clkreg[] = { { .clk = &uart4_ck, .con_id = "uart4_ck" }, { .clk = &uart5_ck, .con_id = "uart5_ck" }, { .clk = &uart6_ck, .con_id = "uart6_ck" }, - { .clk = &wdt_ck, .con_id = "wdt_ck" }, + { .clk = &wdt_ck, .dev_id = "pnx4008-watchdog" }, };static void local_clk_disable (struct clk *clk)
drivers/watchdog/pnx4008_wdt.c +1 -1
@@ -273,7 +273,7 @@ static int __devinit pnx4008_wdt_probe(struct platform_device *pdev) } wdt_base = (void __iomem *)IO_ADDRESS (res->start); - wdt_clk =clk_get (&pdev->dev,"wdt_ck" ); + wdt_clk =clk_get (&pdev->dev,NULL );if (IS_ERR (wdt_clk)) { ret =PTR_ERR (wdt_clk);release_resource (wdt_mem);
Signature · 1 line
1.6.2.5
PATCH 4/10 ARM: PNX4008: convert watchdog clocks to match by device only
Quoted 35 lines
Signed-off-by Russell King <[email protected]>--- arch/arm/mach-pnx4008/clock.c | 2 +- drivers/watchdog/pnx4008_wdt.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)arch/arm/mach-pnx4008/clock.c +1
-1@@ -806,7 +806,7 @@ static struct clk_lookup onchip_clkreg[] = { { .clk = &uart4_ck, .con_id = "uart4_ck" }, { .clk = &uart5_ck, .con_id = "uart5_ck" }, { .clk = &uart6_ck, .con_id = "uart6_ck" }, - { .clk = &wdt_ck, .con_id = "wdt_ck" }, + { .clk = &wdt_ck, .dev_id = "pnx4008-watchdog" }, };static void local_clk_disable (struct clk *clk)drivers/watchdog/pnx4008_wdt.c +1
-1@@ -273,7 +273,7 @@ static int __devinit pnx4008_wdt_probe(struct platform_device *pdev) } wdt_base = (void __iomem *)IO_ADDRESS (res->start); - wdt_clk =clk_get (&pdev->dev,"wdt_ck" ); + wdt_clk =clk_get (&pdev->dev,NULL );if (IS_ERR (wdt_clk)) { ret =PTR_ERR (wdt_clk);release_resource (wdt_mem);Signature · 1 line
1.6.2.5
PATCH 4/10 ARM: PNX4008: convert watchdog clocks to match by device only
Quoted 1 line · Wim Van Sebroeck
Acked-by Wim Van Sebroeck <[email protected]>
Thanks for both those acks.
PATCH 5/10 ARM: PNX4008: convert watchdog to use clk API enable/disable calls
In reply to Russell King - ARM Linuxclk_set_rate() is not supposed to be used to turn clocks on and off. That's what clk_enable/clk_disable is for.
--- arch/arm/mach-pnx4008/clock.c | 4 ++-- drivers/watchdog/pnx4008_wdt.c | 37 ++++++++++++++++++++++++------------- 2 files changed, 26 insertions(+), 15 deletions(-)
arch/arm/mach-pnx4008/clock.c +2 -2
@@ -740,10 +740,10 @@ static struct clk wdt_ck = { .name = "wdt_ck", .parent = &per_ck, .flags = NEEDS_INITIALIZATION, - .round_rate = &on_off_round_rate, - .set_rate = &on_off_set_rate, .enable_shift = 0, .enable_reg = TIMCLKCTRL_REG, + .enable = clk_reg_enable, + .disable = clk_reg_disable, };/* These clocks are visible outside this module
drivers/watchdog/pnx4008_wdt.c +24 -13
@@ -96,9 +96,6 @@ static void wdt_enable(void) {spin_lock (&io_lock); -if (wdt_clk) -clk_set_rate (wdt_clk,1 ); -/* stop counter, initiate counter reset */ __raw_writel (RESET_COUNT ,WDTIM_CTRL (wdt_base));/*wait for reset to complete. 100% guarantee event */
@@ -125,19 +122,25 @@ static void wdt_disable(void)spin_lock (&io_lock);__raw_writel (0 ,WDTIM_CTRL (wdt_base));/*stop counter */ -if (wdt_clk) -clk_set_rate (wdt_clk,0 );spin_unlock (&io_lock); }static int pnx4008_wdt_open (struct inode *inode,struct file *file) { +int ret; +if (test_and_set_bit (WDT_IN_USE , &wdt_status))return -EBUSY ;clear_bit (WDT_OK_TO_CLOSE , &wdt_status); + ret =clk_enable (wdt_clk); +if (ret) { +clear_bit (WDT_IN_USE , &wdt_status); +return ret; + } +wdt_enable ();return nonseekable_open (inode, file);
@@ -225,6 +228,7 @@ static int pnx4008_wdt_release(struct inode *inode, struct file *file)printk (KERN_WARNING "WATCHDOG: Device closed unexpectdly\n" );wdt_disable (); +clk_disable (wdt_clk);clear_bit (WDT_IN_USE , &wdt_status);clear_bit (WDT_OK_TO_CLOSE , &wdt_status);
@@ -279,19 +283,27 @@ static int __devinit pnx4008_wdt_probe(struct platform_device *pdev)release_resource (wdt_mem);kfree (wdt_mem); goto out; - }else -clk_set_rate (wdt_clk,1 ); + } + + ret =clk_enable (wdt_clk); +if (ret) { +release_resource (wdt_mem); +kfree (wdt_mem); + goto out; + } ret =misc_register (&pnx4008_wdt_miscdev);if (ret <0 ) { printk(KERN_ERR MODULE_NAME "cannot register misc device\n");release_resource (wdt_mem);kfree (wdt_mem); -clk_set_rate (wdt_clk,0 ); +clk_disable (wdt_clk); +clk_put (wdt_clk); }else { boot_status = (__raw_readl (WDTIM_RES (wdt_base)) &WDOG_RESET ) ?WDIOF_CARDRESET :0 ;wdt_disable ();/*disable for now */ +clk_disable (wdt_clk);set_bit (WDT_DEVICE_INITED , &wdt_status); }
@@ -302,11 +314,10 @@ out: static int __devexit pnx4008_wdt_remove(struct platform_device *pdev) {misc_deregister (&pnx4008_wdt_miscdev); -if (wdt_clk) { -clk_set_rate (wdt_clk,0 ); -clk_put (wdt_clk); - wdt_clk =NULL ; - } + +clk_disable (wdt_clk); +clk_put (wdt_clk); +if (wdt_mem) {release_resource (wdt_mem);kfree (wdt_mem);
Signature · 1 line
1.6.2.5
PATCH 5/10 ARM: PNX4008: convert watchdog to use clk API enable/disable calls
Quoted 126 lines
clk_set_rate()is not supposed to be used to turn clocks on and off. That's what clk_enable/clk_disable is for.Signed-off-by Russell King <[email protected]>--- arch/arm/mach-pnx4008/clock.c | 4 ++-- drivers/watchdog/pnx4008_wdt.c | 37 ++++++++++++++++++++++++------------- 2 files changed, 26 insertions(+), 15 deletions(-)arch/arm/mach-pnx4008/clock.c +2
-2@@ -740,10 +740,10 @@ static struct clk wdt_ck = { .name = "wdt_ck", .parent = &per_ck, .flags = NEEDS_INITIALIZATION, - .round_rate = &on_off_round_rate, - .set_rate = &on_off_set_rate, .enable_shift = 0, .enable_reg = TIMCLKCTRL_REG, + .enable = clk_reg_enable, + .disable = clk_reg_disable, };/* These clocks are visible outside this module drivers/watchdog/pnx4008_wdt.c +24
-13@@ -96,9 +96,6 @@ static void wdt_enable(void) {spin_lock (&io_lock); -if (wdt_clk) -clk_set_rate (wdt_clk,1 ); -/* stop counter, initiate counter reset */ __raw_writel (RESET_COUNT ,WDTIM_CTRL (wdt_base));/*wait for reset to complete. 100% guarantee event */ @@ -125,19 +122,25 @@ static void wdt_disable(void)spin_lock (&io_lock);__raw_writel (0 ,WDTIM_CTRL (wdt_base));/*stop counter */ -if (wdt_clk) -clk_set_rate (wdt_clk,0 );spin_unlock (&io_lock); }static int pnx4008_wdt_open (struct inode *inode,struct file *file) { +int ret; +if (test_and_set_bit (WDT_IN_USE , &wdt_status))return -EBUSY ;clear_bit (WDT_OK_TO_CLOSE , &wdt_status); + ret =clk_enable (wdt_clk); +if (ret) { +clear_bit (WDT_IN_USE , &wdt_status); +return ret; + } +wdt_enable ();return nonseekable_open (inode, file);@@ -225,6 +228,7 @@ static int pnx4008_wdt_release(struct inode *inode, struct file *file)printk (KERN_WARNING "WATCHDOG: Device closed unexpectdly\n" );wdt_disable (); +clk_disable (wdt_clk);clear_bit (WDT_IN_USE , &wdt_status);clear_bit (WDT_OK_TO_CLOSE , &wdt_status);@@ -279,19 +283,27 @@ static int __devinit pnx4008_wdt_probe(struct platform_device *pdev)release_resource (wdt_mem);kfree (wdt_mem); goto out; - }else -clk_set_rate (wdt_clk,1 ); + } + + ret =clk_enable (wdt_clk); +if (ret) { +release_resource (wdt_mem); +kfree (wdt_mem); + goto out; + } ret =misc_register (&pnx4008_wdt_miscdev);if (ret <0 ) { printk(KERN_ERR MODULE_NAME "cannot register misc device\n");release_resource (wdt_mem);kfree (wdt_mem); -clk_set_rate (wdt_clk,0 ); +clk_disable (wdt_clk); +clk_put (wdt_clk); }else { boot_status = (__raw_readl (WDTIM_RES (wdt_base)) &WDOG_RESET ) ?WDIOF_CARDRESET :0 ;wdt_disable ();/*disable for now */ +clk_disable (wdt_clk);set_bit (WDT_DEVICE_INITED , &wdt_status); }@@ -302,11 +314,10 @@ out: static int __devexit pnx4008_wdt_remove(struct platform_device *pdev) {misc_deregister (&pnx4008_wdt_miscdev); -if (wdt_clk) { -clk_set_rate (wdt_clk,0 ); -clk_put (wdt_clk); - wdt_clk =NULL ; - } + +clk_disable (wdt_clk); +clk_put (wdt_clk); +if (wdt_mem) {release_resource (wdt_mem);kfree (wdt_mem);Signature · 1 line
1.6.2.5
PATCH 5/10 ARM: PNX4008: convert watchdog to use clk API enable/disable calls
Quoted 45 lines
-----Original Message-----
Subject: Re: [PATCH 05/10] ARM: PNX4008: convert watchdog to use clk API enable/disable callsAcked-by Wim Van Sebroeck <[email protected]>Quoted 7 lines
clk_set_rate()is not supposed to be used to turn clocks on and off. That's what clk_enable/clk_disable is for.Signed-off-by Russell King <[email protected]>--- arch/arm/mach-pnx4008/clock.c | 4 ++-- drivers/watchdog/pnx4008_wdt.c | 37 ++++++++++++++++++++++++-------------
arch/arm/mach-
Quoted 3 lines
2 files changed, 26 insertions(+), 15 deletions(-)arch/arm/mach- renamed from arch/arm/mach-pnx4008/clock.c +0
-0
pnx4008/clock.cReview
Quoted 17 lines
index d12e0b1..270c254 100644
arch/arm/mach-pnx4008/clock.c +2
-2@@ -740,10 +740,10 @@ static struct clk wdt_ck = { .name = "wdt_ck", .parent = &per_ck, .flags = NEEDS_INITIALIZATION, - .round_rate = &on_off_round_rate, - .set_rate = &on_off_set_rate, .enable_shift = 0, .enable_reg = TIMCLKCTRL_REG, + .enable = clk_reg_enable, + .disable = clk_reg_disable, };/* These clocks are visible outside this module (quoted diff) +0
-0
b/drivers/watchdog/pnx4008_wdt.cQuoted 7 lines
index 9add3a8..e274f42 100644
drivers/watchdog/pnx4008_wdt.c +0
-0@@ -96,9 +96,6 @@ static void wdt_enable(void) {spin_lock (&io_lock);
Quoted 6 lines
drivers/watchdog/pnx4008_wdt.c static void wdt_enable(void) · line 101
Quoted 6 lines
drivers/watchdog/pnx4008_wdt.c +0
-3-if (wdt_clk) -clk_set_rate (wdt_clk,1 ); -/* stop counter, initiate counter reset */ __raw_writel (RESET_COUNT ,WDTIM_CTRL (wdt_base));/*wait for reset to complete. 100% guarantee event */
The wdt_enable() functions also assumes a wdt counter rate of 13MHz with the WDOG_COUNTER_RATE macro. I think this was ok for the original PNX part, but the LPC32XX platform's rate will vary based on the system clock rate of the device. The nominal rate is 13.325MHz.
I've checked the previous 3 WDT patches and made the necessary changes to my clock driver and everything still works on the LPC32xx platforms, but can't check changes on the PNX4008 platform (have no hardware).
I'll submit a patch to use clk_get_rate instead of the macro..
Quoted 89 lines
drivers/watchdog/pnx4008_wdt.c static int pnx4008_wdt_release(struct inode *inode,
Quoted 29 lines
drivers/watchdog/pnx4008_wdt.c +8
-2@@ -125,19 +122,25 @@ static void wdt_disable(void)spin_lock (&io_lock);__raw_writel (0 ,WDTIM_CTRL (wdt_base));/*stop counter */ -if (wdt_clk) -clk_set_rate (wdt_clk,0 );spin_unlock (&io_lock); }static int pnx4008_wdt_open (struct inode *inode,struct file *file) { +int ret; +if (test_and_set_bit (WDT_IN_USE , &wdt_status))return -EBUSY ;clear_bit (WDT_OK_TO_CLOSE , &wdt_status); + ret =clk_enable (wdt_clk); +if (ret) { +clear_bit (WDT_IN_USE , &wdt_status); +return ret; + } +wdt_enable ();return nonseekable_open (inode, file);@@ -225,6 +228,7 @@ static int pnx4008_wdt_release(struct inode *inode,struct file *file)
drivers/watchdog/pnx4008_wdt.c static int __devinit pnx4008_wdt_probe(struct
Quoted 8 lines
drivers/watchdog/pnx4008_wdt.c +1
-0printk (KERN_WARNING "WATCHDOG: Device closed unexpectdly\n" );wdt_disable (); +clk_disable (wdt_clk);clear_bit (WDT_IN_USE , &wdt_status);clear_bit (WDT_OK_TO_CLOSE , &wdt_status);@@ -279,19 +283,27 @@ static int __devinit pnx4008_wdt_probe(struct
platform_device*pdev)Quoted 14 lines
drivers/watchdog/pnx4008_wdt.c +8
-2release_resource (wdt_mem);kfree (wdt_mem); goto out; - }else -clk_set_rate (wdt_clk,1 ); + } + + ret =clk_enable (wdt_clk); +if (ret) { +release_resource (wdt_mem); +kfree (wdt_mem); + goto out; + }drivers/watchdog/pnx4008_wdt.c static int __devinit pnx4008_wdt_probe(struct platform_device *pdev)
Quoted 10 lines
drivers/watchdog/pnx4008_wdt.c +2
-1ret =misc_register (&pnx4008_wdt_miscdev);if (ret <0 ) { printk(KERN_ERR MODULE_NAME "cannot register misc device\n");release_resource (wdt_mem);kfree (wdt_mem); -clk_set_rate (wdt_clk,0 ); +clk_disable (wdt_clk); +clk_put (wdt_clk); }else { boot_status = (__raw_readl (WDTIM_RES (wdt_base)) &WDOG_RESET )?
Quoted 25 lines
drivers/watchdog/pnx4008_wdt.c +5
-6WDIOF_CARDRESET :0 ;wdt_disable ();/*disable for now */ +clk_disable (wdt_clk);set_bit (WDT_DEVICE_INITED , &wdt_status); }@@ -302,11 +314,10 @@ out: static int __devexit pnx4008_wdt_remove(struct platform_device *pdev) {misc_deregister (&pnx4008_wdt_miscdev); -if (wdt_clk) { -clk_set_rate (wdt_clk,0 ); -clk_put (wdt_clk); - wdt_clk =NULL ; - } + +clk_disable (wdt_clk); +clk_put (wdt_clk); +if (wdt_mem) {release_resource (wdt_mem);kfree (wdt_mem); --1.6.2.5
PATCH 5/10 ARM: PNX4008: convert watchdog to use clk API enable/disable calls
Quoted 10 lines · Kevin Wells
The
wdt_enable()functions also assumes a wdt counter rate of 13MHz with theWDOG_COUNTER_RATEmacro. I think this was ok for the original PNX part, but the LPC32XX platform's rate will vary based on the system clock rate of the device. The nominal rate is 13.325MHz.I've checked the previous 3 WDT patches and made the necessary changes to my clock driver and everything still works on the LPC32xx platforms, but can't check changes on the PNX4008 platform (have no hardware).
I'll submit a patch to use
clk_get_rateinstead of the macro..
Great. As far as switching to clk_get_rate, the PNX4008 code is not nice in that regard, but it will be made to return the desired 13MHz value. ;)
Out of interest, the PNX4008 code hasn't been seriously touched since December 2006 - does anyone care about it? I've not had any reply from Vitaly, so I suspect he doesn't have anything to do with it anymore.
If the answer is no, it might be a good idea to declare the code dead and schedule it for removal in maybe six months time.
PATCH 6/10 ARM: PNX4008: convert i2c clocks to match by device only
In reply to Russell King - ARM Linux--- arch/arm/mach-pnx4008/clock.c | 6 +++--- arch/arm/mach-pnx4008/i2c.c | 8 ++------ 2 files changed, 5 insertions(+), 9 deletions(-)
arch/arm/mach-pnx4008/clock.c +3 -3
@@ -797,9 +797,9 @@ static struct clk_lookup onchip_clkreg[] = { { .clk = &jpeg_ck, .con_id = "jpeg_ck" }, { .clk = &ms_ck, .con_id = "ms_ck" }, { .clk = &touch_ck, .con_id = "touch_ck" }, - { .clk = &i2c0_ck, .con_id = "i2c0_ck" }, - { .clk = &i2c1_ck, .con_id = "i2c1_ck" }, - { .clk = &i2c2_ck, .con_id = "i2c2_ck" }, + { .clk = &i2c0_ck, .dev_id = "pnx-i2c.0" }, + { .clk = &i2c1_ck, .dev_id = "pnx-i2c.1" }, + { .clk = &i2c2_ck, .dev_id = "pnx-i2c.2" }, { .clk = &spi0_ck, .con_id = "spi0_ck" }, { .clk = &spi1_ck, .con_id = "spi1_ck" }, { .clk = &uart3_ck, .con_id = "uart3_ck" },
arch/arm/mach-pnx4008/i2c.c +2 -6
@@ -21,11 +21,9 @@static int set_clock_run (struct platform_device *pdev) {struct clk *clk; -char name[10 ];int retval =0 ; -snprintf (name,10 ,"i2c%d_ck" , pdev->id); - clk =clk_get (&pdev->dev, name); + clk =clk_get (&pdev->dev,NULL );if (!IS_ERR (clk)) {clk_set_rate (clk,1 );clk_put (clk);
@@ -38,11 +36,9 @@ static int set_clock_run(struct platform_device *pdev)static int set_clock_stop (struct platform_device *pdev) {struct clk *clk; -char name[10 ];int retval =0 ; -snprintf (name,10 ,"i2c%d_ck" , pdev->id); - clk =clk_get (&pdev->dev, name); + clk =clk_get (&pdev->dev,NULL );if (!IS_ERR (clk)) {clk_set_rate (clk,0 );clk_put (clk);
Signature · 1 line
1.6.2.5
PATCH 7/10 ARM: PNX4008: move i2c suspend/resume callbacks into driver
In reply to Russell King - ARM Linux--- arch/arm/mach-pnx4008/i2c.c | 24 ------------------------ drivers/i2c/busses/i2c-pnx.c | 9 +++++++-- include/linux/i2c-pnx.h | 4 ---- 3 files changed, 7 insertions(+), 30 deletions(-)
arch/arm/mach-pnx4008/i2c.c +0 -24
@@ -48,24 +48,6 @@ static int set_clock_stop(struct platform_device *pdev)return retval; } -static int i2c_pnx_suspend (struct platform_device *pdev,pm_message_t state) -{ -int retval =0 ; -#ifdef CONFIG_PM - retval =set_clock_run (pdev); -#endif -return retval; -} - -static int i2c_pnx_resume (struct platform_device *pdev) -{ -int retval =0 ; -#ifdef CONFIG_PM - retval =set_clock_run (pdev); -#endif -return retval; -} -static u32 calculate_input_freq (struct platform_device *pdev) {return HCLK_MHZ ;
@@ -102,8 +84,6 @@ static struct i2c_adapter pnx_adapter2 = { };static struct i2c_pnx_data i2c0_data = { - .suspend = i2c_pnx_suspend, - .resume = i2c_pnx_resume, .calculate_input_freq = calculate_input_freq, .set_clock_run = set_clock_run, .set_clock_stop = set_clock_stop,
@@ -111,8 +91,6 @@ static struct i2c_pnx_data i2c0_data = { };static struct i2c_pnx_data i2c1_data = { - .suspend = i2c_pnx_suspend, - .resume = i2c_pnx_resume, .calculate_input_freq = calculate_input_freq, .set_clock_run = set_clock_run, .set_clock_stop = set_clock_stop,
@@ -120,8 +98,6 @@ static struct i2c_pnx_data i2c1_data = { };static struct i2c_pnx_data i2c2_data = { - .suspend = i2c_pnx_suspend, - .resume = i2c_pnx_resume, .calculate_input_freq = calculate_input_freq, .set_clock_run = set_clock_run, .set_clock_stop = set_clock_stop,
drivers/i2c/busses/i2c-pnx.c +7 -2
@@ -545,18 +545,23 @@ static struct i2c_algorithm pnx_algorithm = { .functionality = i2c_pnx_func, }; +#ifdef CONFIG_PM static int i2c_pnx_controller_suspend (struct platform_device *pdev,pm_message_t state) {struct i2c_pnx_data *i2c_pnx =platform_get_drvdata (pdev); -return i2c_pnx->suspend (pdev, state); +return i2c_pnx->set_clock_run (pdev); }static int i2c_pnx_controller_resume (struct platform_device *pdev) {struct i2c_pnx_data *i2c_pnx =platform_get_drvdata (pdev); -return i2c_pnx->resume (pdev); +return i2c_pnx->set_clock_run (pdev); } +#else +#define i2c_pnx_controller_suspend NULL +#define i2c_pnx_controller_resume NULL +#endif static int __devinit i2c_pnx_probe (struct platform_device *pdev) {
include/linux/i2c-pnx.h +0 -4
@@ -12,8 +12,6 @@#ifndef __I2C_PNX_H__#define __I2C_PNX_H__ -#include <linux/pm.h> -struct platform_device ; struct i2c_pnx_mif {
@@ -34,8 +32,6 @@ struct i2c_pnx_algo_data { };struct i2c_pnx_data { -int (*suspend) (struct platform_device *pdev,pm_message_t state); -int (*resume) (struct platform_device *pdev);u32 (*calculate_input_freq) (struct platform_device *pdev);int (*set_clock_run) (struct platform_device *pdev);int (*set_clock_stop) (struct platform_device *pdev);
Signature · 1 line
1.6.2.5
PATCH 7/10 ARM: PNX4008: move i2c suspend/resume callbacks into driver
arch/arm/mach-pnx4008/i2c.c static int set_clock_stop(struct platform_device *pdev) · line 56
Quoted 6 lines · Russell King - ARM Linux
arch/arm/mach-pnx4008/i2c.c +0
-6-static int i2c_pnx_suspend (struct platform_device *pdev,pm_message_t state) -{ -int retval =0 ; -#ifdef CONFIG_PM - retval =set_clock_run (pdev); -#endif
BTW, a comment from PNX folk (Vitaly/Kevin) would be appreciated. Why does PNX enable the clock when going into suspend? Should I assume that this should actually be disabling the clock?
Also, if Vitaly doesn't have anything to do with PNX4008 anymore, it would be a good idea to update the MAINTAINERS file.
PATCH 7/10 ARM: PNX4008: move i2c suspend/resume callbacks into driver
Quoted 13 lines · Russell King - ARM Linux
Quoted 1 line · Russell King - ARM Linux
-static int i2c_pnx_suspend(struct
platform_device*pdev,pm_message_tstate)
arch/arm/mach-pnx4008/i2c.c static int set_clock_stop(struct platform_device *pdev) · line 56
Quoted 5 lines
arch/arm/mach-pnx4008/i2c.c +0
-5-{ -int retval =0 ; -#ifdef CONFIG_PM - retval =set_clock_run (pdev); -#endif BTW, a comment from PNX folk (Vitaly/Kevin) would be appreciated. Why does PNX enable the clock when going into suspend? Should I assume that this should actually be disabling the clock?
As far as I recall, at some point there was a function that was taking the second boolean parameter (enable or disable the clock). So now it is, yes, not making much sense.
Quoted 3 lines
Also, if Vitaly doesn't have anything to do with PNX4008 anymore, it would be a good idea to update the
MAINTAINERSfile.
I'd like to keep maintaining this platform, but it's also up to NXP because I don't have the actual working hardware now so there's not much I can do.
Vitaly
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20091123/e92db2c0/attachment-0001.htm>
PATCH 7/10 ARM: PNX4008: move i2c suspend/resume callbacks into driver
In reply to Russell King - ARM LinuxIf you have this up for testing anyway, would it be advisable to take this opportunity to also switch i2c-pnx over to using struct dev_pm_ops?
i2c-pxa, i2c-s3c2410 and i2c-sh_mobile are already using the new PM primitives.
Yours,
Linus Walleij
PATCH 7/10 ARM: PNX4008: move i2c suspend/resume callbacks into driver
Quoted 2 lines · Linus Walleij
If you have this up for testing anyway, would it be advisable to take this opportunity to also switch i2c-pnx over to using struct
dev_pm_ops?
These patches are only compile-tested, and that's partly why there's soo many of them - each one does one transformation, which makes it easy to review for correctness.
I'm also hoping that Kevin will test them on later PNX hardware so that they can be submitted.
PATCH 7/10 ARM: PNX4008: move i2c suspend/resume callbacks into driver
Quoted 8 lines
Subject: Re: [PATCH 07/10] ARM: PNX4008: move i2c suspend/resume callbacks into driver
Quoted 1 line · Linus Walleij
If you have this up for testing anyway, would it be advisable to take
this
Quoted 8 lines
Quoted 1 line
opportunity to also switch i2c-pnx over to using struct
dev_pm_ops?These patches are only compile-tested, and that's partly why there's soo many of them - each one does one transformation, which makes it easy to review for correctness.
I'm also hoping that Kevin will test them on later PNX hardware so that they can be submitted.
I'll test the changes later today and look at the other identified issues related to this driver.
PATCH 7/10 ARM: PNX4008: move i2c suspend/resume callbacks into driver
In reply to Russell King - ARM LinuxQuoted 8 lines
Subject: Re: [PATCH 07/10] ARM: PNX4008: move i2c suspend/resume callbacks into driver
Quoted 1 line · Linus Walleij
If you have this up for testing anyway, would it be advisable to take
this
Quoted 1 line
opportunity to also switch i2c-pnx over to using struct
dev_pm_ops?
With the clock change below, suspend and resume won't be needed anymore.
Quoted 6 lines
These patches are only compile-tested, and that's partly why there's soo many of them - each one does one transformation, which makes it easy to review for correctness.
I'm also hoping that Kevin will test them on later PNX hardware so that they can be submitted.
All the I2C patches work fine. In regards to the clock being enabled on suspend, I think that's a bug - it should be disabled. It only uses extra power keeping the clock gated on when an I2C transaction isn't in progress. The clock can be gated on prior to an I2C transaction starting and then gated off at the end of it. This will save a small trickle of power.
I'll send over patch with these changes.
Kevin
PATCH 7/10 ARM: PNX4008: move i2c suspend/resume callbacks into driver
Quoted 18 lines · Kevin Wells
Quoted 8 lines
Subject: Re: [PATCH 07/10] ARM: PNX4008: move i2c suspend/resume callbacks into driver
Quoted 1 line · Linus Walleij
If you have this up for testing anyway, would it be advisable to take
this
Quoted 1 line
opportunity to also switch i2c-pnx over to using struct
dev_pm_ops?With the clock change below, suspend and resume won't be needed anymore.
Quoted 6 lines
These patches are only compile-tested, and that's partly why there's soo many of them - each one does one transformation, which makes it easy to review for correctness.
I'm also hoping that Kevin will test them on later PNX hardware so that they can be submitted.
Quoted 7 lines
All the I2C patches work fine. In regards to the clock being enabled on suspend, I think that's a bug - it should be disabled. It only uses extra power keeping the clock gated on when an I2C transaction isn't in progress. The clock can be gated on prior to an I2C transaction starting and then gated off at the end of it. This will save a small trickle of power.
I'll send over patch with these changes.
I didn't hear any response, so the PNX4008 patches are still hanging around unmerged, and now have rejects.
I'm not attached to these patches so I'm not going to be putting any additional effort into them (which means I'm not going to be putting any effort into fixing those rejects or trying to get them merged) especially as it means that they're now going to have to be maintained by someone for three months...
PATCH 7/10 ARM: PNX4008: move i2c suspend/resume callbacks into driver
Quoted 32 lines
Subject: Re: [PATCH 07/10] ARM: PNX4008: move i2c suspend/resume callbacks into driver
Quoted 1 line · Kevin Wells
Quoted 1 line
Subject: Re: [PATCH 07/10] ARM: PNX4008: move i2c suspend/resume
callbacks
Quoted 4 lines
Quoted 4 lines
into driver
Quoted 1 line · Linus Walleij
If you have this up for testing anyway, would it be advisable to
take
Quoted 7 lines
Quoted 3 lines
this
Quoted 1 line
opportunity to also switch i2c-pnx over to using struct
dev_pm_ops?With the clock change below, suspend and resume won't be needed anymore.
Quoted 1 line
These patches are only compile-tested, and that's partly why there's
soo
Quoted 1 line
Quoted 1 line
many of them - each one does one transformation, which makes it easy
to
Quoted 3 lines
Quoted 3 lines
review for correctness.
I'm also hoping that Kevin will test them on later PNX hardware so
that
Quoted 4 lines
Quoted 1 line
they can be submitted.
All the I2C patches work fine. In regards to the clock being enabled on suspend, I think that's a bug - it should be disabled. It only uses
extra
Quoted 1 line
power keeping the clock gated on when an I2C transaction isn't in
progress.
Quoted 9 lines
Quoted 2 lines
The clock can be gated on prior to an I2C transaction starting and then gated off at the end of it. This will save a small trickle of
power.
Quoted 2 lines
I'll send over patch with these changes.
I didn't hear any response, so the PNX4008 patches are still hanging around unmerged, and now have rejects.
I tested the patches and they worked fine. I thought I sent another message saying that...
Quoted 5 lines
I'm not attached to these patches so I'm not going to be putting any additional effort into them (which means I'm not going to be putting any effort into fixing those rejects or trying to get them merged) especially as it means that they're now going to have to be maintained by someone for three months...
We use these drivers on several other devices and many variants, I'll work on getting the code into mainline and getting everything cleaned up. I think the changes made the driver better and made our clock support in the mach- area less complex (and much more generic). I've actually updated and tested my local 32xx arch files with these changes and would like to submit those initial files based on those changes, so I do have a very strong interest to get them included....
PATCH 8/10 ARM: PNX4008: move i2c clock start/stop into driver
In reply to Russell King - ARM Linux--- arch/arm/mach-pnx4008/i2c.c | 36 ------------------------------------ drivers/i2c/busses/i2c-pnx.c | 39 ++++++++++++++++++++++++++++++--------- include/linux/i2c-pnx.h | 4 ++-- 3 files changed, 32 insertions(+), 47 deletions(-)
arch/arm/mach-pnx4008/i2c.c +0 -36
@@ -18,36 +18,6 @@#include <mach/irqs.h> #include <mach/i2c.h> -static int set_clock_run (struct platform_device *pdev) -{ -struct clk *clk; -int retval =0 ; - - clk =clk_get (&pdev->dev,NULL ); -if (!IS_ERR (clk)) { -clk_set_rate (clk,1 ); -clk_put (clk); - }else - retval = -ENOENT ; - -return retval; -} - -static int set_clock_stop (struct platform_device *pdev) -{ -struct clk *clk; -int retval =0 ; - - clk =clk_get (&pdev->dev,NULL ); -if (!IS_ERR (clk)) { -clk_set_rate (clk,0 ); -clk_put (clk); - }else - retval = -ENOENT ; - -return retval; -} -static u32 calculate_input_freq (struct platform_device *pdev) {return HCLK_MHZ ;
@@ -85,22 +55,16 @@ static struct i2c_adapter pnx_adapter2 = {static struct i2c_pnx_data i2c0_data = { .calculate_input_freq = calculate_input_freq, - .set_clock_run = set_clock_run, - .set_clock_stop = set_clock_stop, .adapter = &pnx_adapter0, };static struct i2c_pnx_data i2c1_data = { .calculate_input_freq = calculate_input_freq, - .set_clock_run = set_clock_run, - .set_clock_stop = set_clock_stop, .adapter = &pnx_adapter1, };static struct i2c_pnx_data i2c2_data = { .calculate_input_freq = calculate_input_freq, - .set_clock_run = set_clock_run, - .set_clock_stop = set_clock_stop, .adapter = &pnx_adapter2, };
drivers/i2c/busses/i2c-pnx.c +30 -9
@@ -20,6 +20,9 @@#include <linux/platform_device.h> #include <linux/i2c-pnx.h> #include <linux/io.h> +#include <linux/err.h> +#include <linux/clk.h> +#include <mach/hardware.h> #include <mach/i2c.h> #include <asm/irq.h>
@@ -550,13 +553,22 @@ static int i2c_pnx_controller_suspend(struct platform_device *pdev, pm_message_t state) {struct i2c_pnx_data *i2c_pnx =platform_get_drvdata (pdev); -return i2c_pnx->set_clock_run (pdev); +struct i2c_pnx_algo_data *alg_data = i2c_pnx->adapter->algo_data; + +/* FIXME: disable clock? */ +clk_set_rate (alg_data->clk,1 ); + +return 0 ; }static int i2c_pnx_controller_resume (struct platform_device *pdev) {struct i2c_pnx_data *i2c_pnx =platform_get_drvdata (pdev); -return i2c_pnx->set_clock_run (pdev); +struct i2c_pnx_algo_data *alg_data = i2c_pnx->adapter->algo_data; + +clk_set_rate (alg_data->clk,1 ); + +return 0 ; }#else #define i2c_pnx_controller_suspend NULL
@@ -580,6 +592,15 @@ static int __devinit i2c_pnx_probe(struct platform_device *pdev)platform_set_drvdata (pdev, i2c_pnx); + i2c_pnx->adapter->algo = &pnx_algorithm; + alg_data = i2c_pnx->adapter->algo_data; + + alg_data->clk =clk_get (&pdev->dev,NULL ); +if (IS_ERR (alg_data->clk)) { + ret =PTR_ERR (alg_data->clk); + goto out_drvdata; + } +if (i2c_pnx->calculate_input_freq) freq_mhz = i2c_pnx->calculate_input_freq (pdev);else {
@@ -588,9 +609,6 @@ static int __devinit i2c_pnx_probe(struct platform_device *pdev) "%d MHz\n", freq_mhz); } - i2c_pnx->adapter->algo = &pnx_algorithm; - - alg_data = i2c_pnx->adapter->algo_data;init_timer (&alg_data->mif.timer); alg_data->mif.timer.function = i2c_pnx_timeout; alg_data->mif.timer.data = (unsigned long )i2c_pnx->adapter;
@@ -602,7 +620,7 @@ static int __devinit i2c_pnx_probe(struct platform_device *pdev)"I/O region 0x%08x for I2C already in use.\n" , alg_data->base); ret = -ENODEV ; - goto out_drvdata; + goto out_clkget; } if (!(alg_data->ioaddr =
@@ -612,7 +630,7 @@ static int __devinit i2c_pnx_probe(struct platform_device *pdev) goto out_release; } - i2c_pnx->set_clock_run (pdev); +clk_set_rate (alg_data->clk,1 );/* * Clock Divisor High This value is the number of system clocks
@@ -657,11 +675,13 @@ static int __devinit i2c_pnx_probe(struct platform_device *pdev) out_irq:free_irq (alg_data->irq, alg_data); out_clock: - i2c_pnx->set_clock_stop (pdev); +clk_set_rate (alg_data->clk,0 ); out_unmap:iounmap ((void *)alg_data->ioaddr); out_release:release_mem_region (alg_data->base,I2C_PNX_REGION_SIZE ); +out_clkget: +clk_put (alg_data->clk); out_drvdata:platform_set_drvdata (pdev,NULL ); out:
@@ -676,9 +696,10 @@ static int __devexit i2c_pnx_remove(struct platform_device *pdev)free_irq (alg_data->irq, alg_data);i2c_del_adapter (adap); - i2c_pnx->set_clock_stop (pdev); +clk_set_rate (alg_data->clk,0 );iounmap ((void *)alg_data->ioaddr);release_mem_region (alg_data->base,I2C_PNX_REGION_SIZE ); +clk_put (alg_data->clk);platform_set_drvdata (pdev,NULL );return 0 ;
include/linux/i2c-pnx.h +2 -2
@@ -13,6 +13,7 @@#define __I2C_PNX_H__struct platform_device ; +struct clk ;struct i2c_pnx_mif {int ret;/* Return value */
@@ -29,12 +30,11 @@ struct i2c_pnx_algo_data {int irq;struct i2c_pnx_mif mif;int last; +struct clk *clk; };struct i2c_pnx_data {u32 (*calculate_input_freq) (struct platform_device *pdev); -int (*set_clock_run) (struct platform_device *pdev); -int (*set_clock_stop) (struct platform_device *pdev);struct i2c_adapter *adapter; };
Signature · 1 line
1.6.2.5
PATCH 9/10 ARM: PNX4008: convert i2c-pnx to use clk API enable/disable calls
In reply to Russell King - ARM Linuxclk_set_rate() is not supposed to be used to turn clocks on and off. That's what clk_enable/clk_disable is for.
--- arch/arm/mach-pnx4008/clock.c | 12 ++++++------ drivers/i2c/busses/i2c-pnx.c | 18 +++++++++--------- 2 files changed, 15 insertions(+), 15 deletions(-)
arch/arm/mach-pnx4008/clock.c +6 -6
@@ -639,30 +639,30 @@ static struct clk i2c0_ck = { .name = "i2c0_ck", .parent = &per_ck, .flags = NEEDS_INITIALIZATION, - .round_rate = &on_off_round_rate, - .set_rate = &on_off_set_rate, .enable_shift = 0, .enable_reg = I2CCLKCTRL_REG, + .enable = clk_reg_enable, + .disable = clk_reg_disable, };static struct clk i2c1_ck = { .name ="i2c1_ck" , .parent = &per_ck, .flags =NEEDS_INITIALIZATION , - .round_rate = &on_off_round_rate, - .set_rate = &on_off_set_rate, .enable_shift =1 , .enable_reg =I2CCLKCTRL_REG , + .enable = clk_reg_enable, + .disable = clk_reg_disable, };static struct clk i2c2_ck = { .name ="i2c2_ck" , .parent = &per_ck, .flags =NEEDS_INITIALIZATION , - .round_rate = &on_off_round_rate, - .set_rate = &on_off_set_rate, .enable_shift =2 , .enable_reg =USB_OTG_CLKCTRL_REG , + .enable = clk_reg_enable, + .disable = clk_reg_disable, };static struct clk spi0_ck = {
drivers/i2c/busses/i2c-pnx.c +9 -9
@@ -555,8 +555,8 @@ static int i2c_pnx_controller_suspend(struct platform_device *pdev,struct i2c_pnx_data *i2c_pnx =platform_get_drvdata (pdev);struct i2c_pnx_algo_data *alg_data = i2c_pnx->adapter->algo_data; -/* FIXME: disable clock? */ -clk_set_rate (alg_data->clk,1 ); +/* FIXME: shouldn't this be clk_disable? */ +clk_enable (alg_data->clk);return 0 ; }
@@ -566,9 +566,7 @@ static int i2c_pnx_controller_resume(struct platform_device *pdev)struct i2c_pnx_data *i2c_pnx =platform_get_drvdata (pdev);struct i2c_pnx_algo_data *alg_data = i2c_pnx->adapter->algo_data; -clk_set_rate (alg_data->clk,1 ); - - return 0; + return clk_enable(alg_data->clk); }#else #define i2c_pnx_controller_suspend NULL
@@ -630,7 +628,9 @@ static int __devinit i2c_pnx_probe(struct platform_device *pdev) goto out_release; } -clk_set_rate (alg_data->clk,1 ); + ret =clk_enable (alg_data->clk); +if (ret) + goto out_unmap;/* * Clock Divisor High This value is the number of system clocks
@@ -650,7 +650,7 @@ static int __devinit i2c_pnx_probe(struct platform_device *pdev)iowrite32 (mcntrl_reset,I2C_REG_CTL (alg_data));if (wait_reset (I2C_PNX_TIMEOUT , alg_data)) { ret = -ENODEV ; - goto out_unmap; + goto out_clock; }init_completion (&alg_data->mif.complete);
@@ -675,7 +675,7 @@ static int __devinit i2c_pnx_probe(struct platform_device *pdev) out_irq:free_irq (alg_data->irq, alg_data); out_clock: -clk_set_rate (alg_data->clk,0 ); +clk_disable (alg_data->clk); out_unmap:iounmap ((void *)alg_data->ioaddr); out_release:
@@ -696,7 +696,7 @@ static int __devexit i2c_pnx_remove(struct platform_device *pdev)free_irq (alg_data->irq, alg_data);i2c_del_adapter (adap); -clk_set_rate (alg_data->clk,0 ); +clk_disable (alg_data->clk);iounmap ((void *)alg_data->ioaddr);release_mem_region (alg_data->base,I2C_PNX_REGION_SIZE );clk_put (alg_data->clk);
Signature · 1 line
1.6.2.5
PATCH 10/10 ARM: PNX4008: get i2c clock rate from clk API
In reply to Russell King - ARM Linux--- arch/arm/mach-pnx4008/clock.c | 9 ++++++--- arch/arm/mach-pnx4008/i2c.c | 9 --------- drivers/i2c/busses/i2c-pnx.c | 15 ++++----------- include/linux/i2c-pnx.h | 1 - 4 files changed, 10 insertions(+), 24 deletions(-)
arch/arm/mach-pnx4008/clock.c +6 -3
@@ -638,9 +638,10 @@ static struct clk flash_ck = {static struct clk i2c0_ck = { .name ="i2c0_ck" , .parent = &per_ck, - .flags =NEEDS_INITIALIZATION , + .flags =NEEDS_INITIALIZATION |FIXED_RATE , .enable_shift =0 , .enable_reg =I2CCLKCTRL_REG , + .rate =13000000 , .enable = clk_reg_enable, .disable = clk_reg_disable, };
@@ -648,9 +649,10 @@ static struct clk i2c0_ck = {static struct clk i2c1_ck = { .name ="i2c1_ck" , .parent = &per_ck, - .flags =NEEDS_INITIALIZATION , + .flags =NEEDS_INITIALIZATION |FIXED_RATE , .enable_shift =1 , .enable_reg =I2CCLKCTRL_REG , + .rate =13000000 , .enable = clk_reg_enable, .disable = clk_reg_disable, };
@@ -658,9 +660,10 @@ static struct clk i2c1_ck = {static struct clk i2c2_ck = { .name ="i2c2_ck" , .parent = &per_ck, - .flags =NEEDS_INITIALIZATION , + .flags =NEEDS_INITIALIZATION |FIXED_RATE , .enable_shift =2 , .enable_reg =USB_OTG_CLKCTRL_REG , + .rate =13000000 , .enable = clk_reg_enable, .disable = clk_reg_disable, };
arch/arm/mach-pnx4008/i2c.c +0 -9
@@ -18,12 +18,6 @@#include <mach/irqs.h> #include <mach/i2c.h> -static u32 calculate_input_freq (struct platform_device *pdev) -{ -return HCLK_MHZ ; -} - -static struct i2c_pnx_algo_data pnx_algo_data0 = { .base =PNX4008_I2C1_BASE , .irq =I2C_1_INT ,
@@ -54,17 +48,14 @@ static struct i2c_adapter pnx_adapter2 = { };static struct i2c_pnx_data i2c0_data = { - .calculate_input_freq = calculate_input_freq, .adapter = &pnx_adapter0, };static struct i2c_pnx_data i2c1_data = { - .calculate_input_freq = calculate_input_freq, .adapter = &pnx_adapter1, };static struct i2c_pnx_data i2c2_data = { - .calculate_input_freq = calculate_input_freq, .adapter = &pnx_adapter2, };
drivers/i2c/busses/i2c-pnx.c +4 -11
@@ -31,7 +31,6 @@#define I2C_PNX_TIMEOUT 10/* msec */ #define I2C_PNX_SPEED_KHZ 100#define I2C_PNX_REGION_SIZE 0x100 -#define PNX_DEFAULT_FREQ 13/* MHz */ static inline int wait_timeout (long timeout,struct i2c_pnx_algo_data *data) {
@@ -578,7 +577,7 @@ static int __devinit i2c_pnx_probe(struct platform_device *pdev)unsigned long tmp;int ret =0 ;struct i2c_pnx_algo_data *alg_data; -int freq_mhz; +unsigned long freq;struct i2c_pnx_data *i2c_pnx = pdev->dev.platform_data;if (!i2c_pnx || !i2c_pnx->adapter) {
@@ -599,14 +598,6 @@ static int __devinit i2c_pnx_probe(struct platform_device *pdev) goto out_drvdata; } -if (i2c_pnx->calculate_input_freq) - freq_mhz = i2c_pnx->calculate_input_freq (pdev); -else { - freq_mhz =PNX_DEFAULT_FREQ ; -dev_info (&pdev->dev,"Setting bus frequency to default value: " -"%d MHz\n" , freq_mhz); - } -init_timer (&alg_data->mif.timer); alg_data->mif.timer.function = i2c_pnx_timeout; alg_data->mif.timer.data = (unsigned long )i2c_pnx->adapter;
@@ -632,6 +623,8 @@ static int __devinit i2c_pnx_probe(struct platform_device *pdev)if (ret) goto out_unmap; + freq =clk_get_rate (alg_data->clk); +/* * Clock Divisor High This value is the number of system clocks * the serial clock (SCL) will be high.
@@ -643,7 +636,7 @@ static int __devinit i2c_pnx_probe(struct platform_device *pdev)* the deglitching filter length. */ - tmp = ((freq_mhz *1000 ) /I2C_PNX_SPEED_KHZ ) /2 -2 ; + tmp = ((freq /1000 ) /I2C_PNX_SPEED_KHZ ) /2 -2 ;iowrite32 (tmp,I2C_REG_CKH (alg_data));iowrite32 (tmp,I2C_REG_CKL (alg_data));
include/linux/i2c-pnx.h +0 -1
@@ -34,7 +34,6 @@ struct i2c_pnx_algo_data { };struct i2c_pnx_data { -u32 (*calculate_input_freq) (struct platform_device *pdev);struct i2c_adapter *adapter; };
Signature · 1 line
1.6.2.5