PNX4008 patchset (updated with Vitaly's acks, plus a few more patches)
Subsystems (5)
cover PNX4008 patchset (updated with Vitaly's acks, plus a few more patches)
As the subject line says.
PATCH 1/18 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
@@ -552,6 +552,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/18 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/18 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/18 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 5/18 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 6/18 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/18 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 8/18 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
@@ -658,11 +676,13 @@ static int __devinit i2c_pnx_probe(struct platform_device *pdev) out_irq:free_irq (alg_data->irq, i2c_pnx->adapter); 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:
@@ -677,9 +697,10 @@ static int __devexit i2c_pnx_remove(struct platform_device *pdev)free_irq (alg_data->irq, i2c_pnx->adapter);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/18 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);
@@ -676,7 +676,7 @@ static int __devinit i2c_pnx_probe(struct platform_device *pdev) out_irq:free_irq (alg_data->irq, i2c_pnx->adapter); out_clock: -clk_set_rate (alg_data->clk,0 ); +clk_disable (alg_data->clk); out_unmap:iounmap ((void *)alg_data->ioaddr); out_release:
@@ -697,7 +697,7 @@ static int __devexit i2c_pnx_remove(struct platform_device *pdev)free_irq (alg_data->irq, i2c_pnx->adapter);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/18 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
PATCH 11/18 ARM: PNX4008: remove platform definitions from mach/timex.h
In reply to Russell King - ARM Linuxmach/timex.h is only supposed to contain a definition for CLOCK_TICK_RATE. Remove additional includes, and move private definitions to a private header file.
--- arch/arm/mach-pnx4008/include/mach/timex.h | 54 --------------------- arch/arm/mach-pnx4008/pm.c | 2 + arch/arm/mach-pnx4008/time.c | 2 + arch/arm/mach-pnx4008/time.h | 70 ++++++++++++++++++++++++++++ 4 files changed, 74 insertions(+), 54 deletions(-) create mode 100644 arch/arm/mach-pnx4008/time.h
arch/arm/mach-pnx4008/include/mach/timex.h +0 -54
@@ -14,60 +14,6 @@#ifndef __PNX4008_TIMEX_H#define __PNX4008_TIMEX_H -#include <linux/io.h> -#include <mach/hardware.h> -#define CLOCK_TICK_RATE 1000000 -#define TICKS2USECS (x) (x) - -/* MilliSecond Timer - Chapter 21 Page 202 */ - -#define MSTIM_INT IO_ADDRESS((PNX4008_MSTIMER_BASE + 0x0)) -#define MSTIM_CTRL IO_ADDRESS((PNX4008_MSTIMER_BASE + 0x4)) -#define MSTIM_COUNTER IO_ADDRESS((PNX4008_MSTIMER_BASE + 0x8)) -#define MSTIM_MCTRL IO_ADDRESS((PNX4008_MSTIMER_BASE + 0x14)) -#define MSTIM_MATCH0 IO_ADDRESS((PNX4008_MSTIMER_BASE + 0x18)) -#define MSTIM_MATCH1 IO_ADDRESS((PNX4008_MSTIMER_BASE + 0x1c)) - -/* High Speed Timer - Chpater 22, Page 205 */ - -#define HSTIM_INT IO_ADDRESS((PNX4008_HSTIMER_BASE + 0x0)) -#define HSTIM_CTRL IO_ADDRESS((PNX4008_HSTIMER_BASE + 0x4)) -#define HSTIM_COUNTER IO_ADDRESS((PNX4008_HSTIMER_BASE + 0x8)) -#define HSTIM_PMATCH IO_ADDRESS((PNX4008_HSTIMER_BASE + 0xC)) -#define HSTIM_PCOUNT IO_ADDRESS((PNX4008_HSTIMER_BASE + 0x10)) -#define HSTIM_MCTRL IO_ADDRESS((PNX4008_HSTIMER_BASE + 0x14)) -#define HSTIM_MATCH0 IO_ADDRESS((PNX4008_HSTIMER_BASE + 0x18)) -#define HSTIM_MATCH1 IO_ADDRESS((PNX4008_HSTIMER_BASE + 0x1c)) -#define HSTIM_MATCH2 IO_ADDRESS((PNX4008_HSTIMER_BASE + 0x20)) -#define HSTIM_CCR IO_ADDRESS((PNX4008_HSTIMER_BASE + 0x28)) -#define HSTIM_CR0 IO_ADDRESS((PNX4008_HSTIMER_BASE + 0x2C)) -#define HSTIM_CR1 IO_ADDRESS((PNX4008_HSTIMER_BASE + 0x30)) - -/* IMPORTANT: both timers are UPCOUNTING */ - -/* xSTIM_MCTRL bit definitions */ -#define MR0_INT 1 -#define RESET_COUNT0 (1<<1) -#define STOP_COUNT0 (1<<2) -#define MR1_INT (1<<3) -#define RESET_COUNT1 (1<<4) -#define STOP_COUNT1 (1<<5) -#define MR2_INT (1<<6) -#define RESET_COUNT2 (1<<7) -#define STOP_COUNT2 (1<<8) - -/* xSTIM_CTRL bit definitions */ -#define COUNT_ENAB 1 -#define RESET_COUNT (1<<1) -#define DEBUG_EN (1<<2) - -/* xSTIM_INT bit definitions */ -#define MATCH0_INT 1 -#define MATCH1_INT (1<<1) -#define MATCH2_INT (1<<2) -#define RTC_TICK0 (1<<4) -#define RTC_TICK1 (1<<5) -#endif
arch/arm/mach-pnx4008/pm.c +2 -0
@@ -21,6 +21,8 @@#include <linux/io.h> #include <asm/cacheflush.h> + +#include <mach/hardware.h> #include <mach/pm.h> #include <mach/clock.h>
arch/arm/mach-pnx4008/time.c +2 -0
@@ -30,6 +30,8 @@#include <asm/mach/time.h> #include <asm/errno.h> +#include "time.h" +/*! Note: all timers are UPCOUNTING */ /*!
arch/arm/mach-pnx4008/time.h new file +70 -0
70 lines not on this page · raw message
Signature · 1 line
1.6.2.5
PATCH 12/18 ARM: PNX4008: Make ioaddr 'void __iomem *' rather than 'u32'
In reply to Russell King - ARM LinuxThis avoids unnecessary casting.
--- drivers/i2c/busses/i2c-pnx.c | 8 ++++---- include/linux/i2c-pnx.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-)
drivers/i2c/busses/i2c-pnx.c +4 -4
@@ -612,8 +612,8 @@ static int __devinit i2c_pnx_probe(struct platform_device *pdev) goto out_clkget; } -if (!(alg_data->ioaddr = - (u32 )ioremap (alg_data->base,I2C_PNX_REGION_SIZE ))) { + alg_data->ioaddr =ioremap (alg_data->base,I2C_PNX_REGION_SIZE ); +if (!alg_data->ioaddr) {dev_err (&pdev->dev,"Couldn't ioremap I2C I/O region\n" ); ret = -ENOMEM ; goto out_release;
@@ -671,7 +671,7 @@ out_irq: out_clock:clk_disable (alg_data->clk); out_unmap: -iounmap ((void *)alg_data->ioaddr); +iounmap (alg_data->ioaddr); out_release:release_mem_region (alg_data->base,I2C_PNX_REGION_SIZE ); out_clkget:
@@ -691,7 +691,7 @@ static int __devexit i2c_pnx_remove(struct platform_device *pdev)free_irq (alg_data->irq, i2c_pnx->adapter);i2c_del_adapter (adap);clk_disable (alg_data->clk); -iounmap ((void *)alg_data->ioaddr); +iounmap (alg_data->ioaddr);release_mem_region (alg_data->base,I2C_PNX_REGION_SIZE );clk_put (alg_data->clk);platform_set_drvdata (pdev,NULL );
include/linux/i2c-pnx.h +1 -1
@@ -26,7 +26,7 @@ struct i2c_pnx_mif {struct i2c_pnx_algo_data {u32 base; -u32 ioaddr; +void __iomem *ioaddr;int irq;struct i2c_pnx_mif mif;int last;
Signature · 1 line
1.6.2.5
PATCH 13/18 ARM: PNX4008: kzalloc i2c drivers internal data
In reply to Russell King - ARM Linux--- arch/arm/mach-pnx4008/i2c.c | 25 +++++++------------------ drivers/i2c/busses/i2c-pnx.c | 29 +++++++++++++++++++---------- include/linux/i2c-pnx.h | 4 ++-- 3 files changed, 28 insertions(+), 30 deletions(-)
arch/arm/mach-pnx4008/i2c.c +7 -18
@@ -18,45 +18,34 @@#include <mach/irqs.h> #include <mach/i2c.h> -static struct i2c_pnx_algo_data pnx_algo_data0 = { - .base =PNX4008_I2C1_BASE , - .irq =I2C_1_INT , -}; - -static struct i2c_pnx_algo_data pnx_algo_data1 = { - .base =PNX4008_I2C2_BASE , - .irq =I2C_2_INT , -}; - -static struct i2c_pnx_algo_data pnx_algo_data2 = { - .base = (PNX4008_USB_CONFIG_BASE +0x300 ), - .irq =USB_I2C_INT , -}; -static struct i2c_adapter pnx_adapter0 = { .name =I2C_CHIP_NAME "0" , - .algo_data = &pnx_algo_data0, }; +static struct i2c_adapter pnx_adapter1 = { .name =I2C_CHIP_NAME "1" , - .algo_data = &pnx_algo_data1, };static struct i2c_adapter pnx_adapter2 = { .name ="USB-I2C" , - .algo_data = &pnx_algo_data2, };static struct i2c_pnx_data i2c0_data = { .adapter = &pnx_adapter0, + .base =PNX4008_I2C1_BASE , + .irq =I2C_1_INT , };static struct i2c_pnx_data i2c1_data = { .adapter = &pnx_adapter1, + .base =PNX4008_I2C2_BASE , + .irq =I2C_2_INT , };static struct i2c_pnx_data i2c2_data = { .adapter = &pnx_adapter2, + .base = (PNX4008_USB_CONFIG_BASE +0x300 ), + .irq =USB_I2C_INT , };static struct platform_device i2c0_device = {
drivers/i2c/busses/i2c-pnx.c +19 -10
@@ -587,10 +587,16 @@ static int __devinit i2c_pnx_probe(struct platform_device *pdev) goto out; } + alg_data =kzalloc (sizeof (*alg_data),GFP_KERNEL ); +if (!alg_data) { + ret = -ENOMEM ; + goto err_kzalloc; + } +platform_set_drvdata (pdev, i2c_pnx); i2c_pnx->adapter->algo = &pnx_algorithm; - alg_data = i2c_pnx->adapter->algo_data; + i2c_pnx->adapter->algo_data = alg_data; alg_data->clk =clk_get (&pdev->dev,NULL );if (IS_ERR (alg_data->clk)) {
@@ -603,16 +609,16 @@ static int __devinit i2c_pnx_probe(struct platform_device *pdev) alg_data->mif.timer.data = (unsigned long )i2c_pnx->adapter;/* Register I/O resource */ -if (!request_mem_region (alg_data->base,I2C_PNX_REGION_SIZE , +if (!request_mem_region (i2c_pnx->base,I2C_PNX_REGION_SIZE , pdev->name)) {dev_err (&pdev->dev,"I/O region 0x%08x for I2C already in use.\n" , - alg_data->base); + i2c_pnx->base); ret = -ENODEV ; goto out_clkget; } - alg_data->ioaddr =ioremap (alg_data->base,I2C_PNX_REGION_SIZE ); + alg_data->ioaddr =ioremap (i2c_pnx->base,I2C_PNX_REGION_SIZE );if (!alg_data->ioaddr) {dev_err (&pdev->dev,"Couldn't ioremap I2C I/O region\n" ); ret = -ENOMEM ;
@@ -647,7 +653,7 @@ static int __devinit i2c_pnx_probe(struct platform_device *pdev) }init_completion (&alg_data->mif.complete); - ret =request_irq (alg_data->irq, i2c_pnx_interrupt, + ret =request_irq (i2c_pnx->irq, i2c_pnx_interrupt,0 , pdev->name, i2c_pnx->adapter);if (ret) goto out_clock;
@@ -662,21 +668,23 @@ static int __devinit i2c_pnx_probe(struct platform_device *pdev) }dev_dbg (&pdev->dev,"%s: Master at %#8x, irq %d.\n" , - i2c_pnx->adapter->name, alg_data->base, alg_data->irq); + i2c_pnx->adapter->name, i2c_pnx->base, i2c_pnx->irq);return 0 ; out_irq: -free_irq (alg_data->irq, i2c_pnx->adapter); +free_irq (i2c_pnx->irq, i2c_pnx->adapter); out_clock:clk_disable (alg_data->clk); out_unmap:iounmap (alg_data->ioaddr); out_release: -release_mem_region (alg_data->base,I2C_PNX_REGION_SIZE ); +release_mem_region (i2c_pnx->base,I2C_PNX_REGION_SIZE ); out_clkget:clk_put (alg_data->clk); out_drvdata: +kfree (alg_data); +err_kzalloc:platform_set_drvdata (pdev,NULL ); out:return ret;
@@ -688,12 +696,13 @@ static int __devexit i2c_pnx_remove(struct platform_device *pdev)struct i2c_adapter *adap = i2c_pnx->adapter;struct i2c_pnx_algo_data *alg_data = adap->algo_data; -free_irq (alg_data->irq, i2c_pnx->adapter); +free_irq (i2c_pnx->irq, i2c_pnx->adapter);i2c_del_adapter (adap);clk_disable (alg_data->clk);iounmap (alg_data->ioaddr); -release_mem_region (alg_data->base,I2C_PNX_REGION_SIZE ); +release_mem_region (i2c_pnx->base,I2C_PNX_REGION_SIZE );clk_put (alg_data->clk); +kfree (alg_data);platform_set_drvdata (pdev,NULL );return 0 ;
include/linux/i2c-pnx.h +2 -2
@@ -25,9 +25,7 @@ struct i2c_pnx_mif { };struct i2c_pnx_algo_data { -u32 base;void __iomem *ioaddr; -int irq;struct i2c_pnx_mif mif;int last;struct clk *clk;
@@ -35,6 +33,8 @@ struct i2c_pnx_algo_data {struct i2c_pnx_data {struct i2c_adapter *adapter; +u32 base; +int irq; };#endif /* __I2C_PNX_H__ */
Signature · 1 line
1.6.2.5
PATCH 14/18 ARM: PNX4008: move i2c_adapter structure inside the drivers private data
In reply to Russell King - ARM Linux--- arch/arm/mach-pnx4008/i2c.c | 18 +++--------------- drivers/i2c/busses/i2c-pnx.c | 40 ++++++++++++++++++++-------------------- include/linux/i2c-pnx.h | 4 +++- 3 files changed, 26 insertions(+), 36 deletions(-)
arch/arm/mach-pnx4008/i2c.c +3 -15
@@ -18,32 +18,20 @@#include <mach/irqs.h> #include <mach/i2c.h> -static struct i2c_adapter pnx_adapter0 = { - .name =I2C_CHIP_NAME "0" , -}; - -static struct i2c_adapter pnx_adapter1 = { - .name =I2C_CHIP_NAME "1" , -}; - -static struct i2c_adapter pnx_adapter2 = { - .name ="USB-I2C" , -}; -static struct i2c_pnx_data i2c0_data = { - .adapter = &pnx_adapter0, + .name =I2C_CHIP_NAME "0" , .base =PNX4008_I2C1_BASE , .irq =I2C_1_INT , };static struct i2c_pnx_data i2c1_data = { - .adapter = &pnx_adapter1, + .name =I2C_CHIP_NAME "1" , .base =PNX4008_I2C2_BASE , .irq =I2C_2_INT , };static struct i2c_pnx_data i2c2_data = { - .adapter = &pnx_adapter2, + .name ="USB-I2C" , .base = (PNX4008_USB_CONFIG_BASE +0x300 ), .irq =USB_I2C_INT , };
drivers/i2c/busses/i2c-pnx.c +20 -20
@@ -551,8 +551,7 @@ static struct i2c_algorithm pnx_algorithm = {static int i2c_pnx_controller_suspend (struct platform_device *pdev,pm_message_t state) { -struct i2c_pnx_data *i2c_pnx =platform_get_drvdata (pdev); -struct i2c_pnx_algo_data *alg_data = i2c_pnx->adapter->algo_data; +struct i2c_pnx_algo_data *alg_data =platform_get_drvdata (pdev);/* FIXME: shouldn't this be clk_disable? */ clk_enable (alg_data->clk);
@@ -562,8 +561,7 @@ static int i2c_pnx_controller_suspend(struct platform_device *pdev,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; +struct i2c_pnx_algo_data *alg_data =platform_get_drvdata (pdev);return clk_enable (alg_data->clk); }
@@ -580,7 +578,7 @@ static int __devinit i2c_pnx_probe(struct platform_device *pdev)unsigned long freq;struct i2c_pnx_data *i2c_pnx = pdev->dev.platform_data; -if (!i2c_pnx || !i2c_pnx->adapter) { +if (!i2c_pnx || !i2c_pnx->name) {dev_err (&pdev->dev,"%s: no platform data supplied\n" , __func__); ret = -EINVAL ;
@@ -593,10 +591,15 @@ static int __devinit i2c_pnx_probe(struct platform_device *pdev) goto err_kzalloc; } -platform_set_drvdata (pdev, i2c_pnx); +platform_set_drvdata (pdev, alg_data); - i2c_pnx->adapter->algo = &pnx_algorithm; - i2c_pnx->adapter->algo_data = alg_data; +strlcpy (alg_data->adapter.name, i2c_pnx->name, +sizeof (alg_data->adapter.name)); + alg_data->adapter.dev.parent = &pdev->dev; + alg_data->adapter.algo = &pnx_algorithm; + alg_data->adapter.algo_data = alg_data; + alg_data->adapter.nr = pdev->id; + alg_data->i2c_pnx = i2c_pnx; alg_data->clk =clk_get (&pdev->dev,NULL );if (IS_ERR (alg_data->clk)) {
@@ -606,7 +609,7 @@ static int __devinit i2c_pnx_probe(struct platform_device *pdev)init_timer (&alg_data->mif.timer); alg_data->mif.timer.function = i2c_pnx_timeout; - alg_data->mif.timer.data = (unsigned long )i2c_pnx->adapter; + alg_data->mif.timer.data = (unsigned long )&alg_data->adapter;/* Register I/O resource */ if (!request_mem_region(i2c_pnx->base, I2C_PNX_REGION_SIZE,
@@ -654,26 +657,24 @@ static int __devinit i2c_pnx_probe(struct platform_device *pdev)init_completion (&alg_data->mif.complete); ret =request_irq (i2c_pnx->irq, i2c_pnx_interrupt, -0 , pdev->name, i2c_pnx->adapter); +0 , pdev->name, &alg_data->adapter);if (ret) goto out_clock;/* Register this adapter with the I2C subsystem */ - i2c_pnx->adapter->dev.parent = &pdev->dev; - i2c_pnx->adapter->nr = pdev->id; - ret =i2c_add_numbered_adapter (i2c_pnx->adapter); + ret =i2c_add_adapter (&alg_data->adapter);if (ret <0 ) {dev_err (&pdev->dev,"I2C: Failed to add bus\n" ); goto out_irq; }dev_dbg (&pdev->dev,"%s: Master at %#8x, irq %d.\n" , - i2c_pnx->adapter->name, i2c_pnx->base, i2c_pnx->irq); + alg_data->adapter.name, i2c_pnx->base, i2c_pnx->irq);return 0 ; out_irq: -free_irq (i2c_pnx->irq, i2c_pnx->adapter); +free_irq (i2c_pnx->irq, &alg_data->adapter); out_clock:clk_disable (alg_data->clk); out_unmap:
@@ -692,12 +693,11 @@ out: static int __devexit i2c_pnx_remove(struct platform_device *pdev) { -struct i2c_pnx_data *i2c_pnx =platform_get_drvdata (pdev); -struct i2c_adapter *adap = i2c_pnx->adapter; -struct i2c_pnx_algo_data *alg_data = adap->algo_data; +struct i2c_pnx_algo_data *alg_data =platform_get_drvdata (pdev); +struct i2c_pnx_data *i2c_pnx = alg_data->i2c_pnx; -free_irq (i2c_pnx->irq, i2c_pnx->adapter); -i2c_del_adapter (adap); +free_irq (i2c_pnx->irq, &alg_data->adapter); +i2c_del_adapter (&alg_data->adapter);clk_disable (alg_data->clk);iounmap (alg_data->ioaddr);release_mem_region (i2c_pnx->base,I2C_PNX_REGION_SIZE );
include/linux/i2c-pnx.h +3 -1
@@ -29,10 +29,12 @@ struct i2c_pnx_algo_data {struct i2c_pnx_mif mif;int last;struct clk *clk; +struct i2c_pnx_data *i2c_pnx; +struct i2c_adapter adapter; };struct i2c_pnx_data { -struct i2c_adapter *adapter; +const char *name;u32 base;int irq; };
Signature · 1 line
1.6.2.5
PATCH 15/18 ARM: PNX4008: Use i2c driver data for passing between internal functions
In reply to Russell King - ARM LinuxSince the drivers data now contains the i2c adapter structure, we can pass around the drivers data between internal functions (which is what they want) rather than using the i2c adapter structure and having an additional pointer dereference each time.
--- drivers/i2c/busses/i2c-pnx.c | 132 ++++++++++++++++++++---------------------- 1 files changed, 62 insertions(+), 70 deletions(-)
drivers/i2c/busses/i2c-pnx.c +62 -70
@@ -52,10 +52,9 @@ static inline int wait_reset(long timeout, struct i2c_pnx_algo_data *data)return (timeout <=0 ); } -static inline void i2c_pnx_arm_timer (struct i2c_adapter *adap) +static inline void i2c_pnx_arm_timer (struct i2c_pnx_algo_data *alg_data) { -struct i2c_pnx_algo_data *data = adap->algo_data; -struct timer_list *timer = &data->mif.timer; +struct timer_list *timer = &alg_data->mif.timer;int expires =I2C_PNX_TIMEOUT / (1000 /HZ );if (expires <=1 )
@@ -63,11 +62,11 @@ static inline void i2c_pnx_arm_timer(struct i2c_adapter *adap)del_timer_sync (timer); -dev_dbg (&adap->dev,"Timer armed at %lu plus %u jiffies.\n" , +dev_dbg (&alg_data->adapter.dev,"Timer armed at %lu plus %u jiffies.\n" , jiffies, expires); timer->expires = jiffies + expires; - timer->data = (unsigned long )adap; + timer->data = (unsigned long )&alg_data;add_timer (timer); }
@@ -79,34 +78,33 @@ static inline void i2c_pnx_arm_timer(struct i2c_adapter *adap)* * Generate a START signal in the desired mode. */ -static int i2c_pnx_start (unsigned char slave_addr,struct i2c_adapter *adap) +static int i2c_pnx_start (unsigned char slave_addr, +struct i2c_pnx_algo_data *alg_data) { -struct i2c_pnx_algo_data *alg_data = adap->algo_data; - -dev_dbg (&adap->dev,"%s(): addr 0x%x mode %d\n" , __func__, +dev_dbg (&alg_data->adapter.dev,"%s(): addr 0x%x mode %d\n" , __func__, slave_addr, alg_data->mif.mode);/* Check for 7 bit slave addresses only */ if (slave_addr & ~0x7f ) { -dev_err (&adap->dev,"%s: Invalid slave address %x. " +dev_err (&alg_data->adapter.dev,"%s: Invalid slave address %x. " "Only 7-bit addresses are supported\n" , - adap->name, slave_addr); + alg_data->adapter.name, slave_addr);return -EINVAL ; }/* First, make sure bus is idle */ if (wait_timeout (I2C_PNX_TIMEOUT , alg_data)) {/* Somebody else is monopolizing the bus */ -dev_err (&adap->dev,"%s: Bus busy. Slave addr = %02x, " +dev_err (&alg_data->adapter.dev,"%s: Bus busy. Slave addr = %02x, " "cntrl = %x, stat = %x\n" , - adap->name, slave_addr, + alg_data->adapter.name, slave_addr,ioread32 (I2C_REG_CTL (alg_data)),ioread32 (I2C_REG_STS (alg_data)));return -EBUSY ; }else if (ioread32 (I2C_REG_STS (alg_data)) & mstatus_afi) {/* Sorry, we lost the bus */ -dev_err (&adap->dev,"%s: Arbitration failure. " -"Slave addr = %02x\n" , adap->name, slave_addr); +dev_err (&alg_data->adapter.dev,"%s: Arbitration failure. " +"Slave addr = %02x\n" , alg_data->adapter.name, slave_addr);return -EIO ; }
@@ -117,14 +115,14 @@ static int i2c_pnx_start(unsigned char slave_addr, struct i2c_adapter *adap)iowrite32 (ioread32 (I2C_REG_STS (alg_data)) | mstatus_tdi | mstatus_afi,I2C_REG_STS (alg_data)); -dev_dbg (&adap->dev,"%s(): sending %#x\n" , __func__, +dev_dbg (&alg_data->adapter.dev,"%s(): sending %#x\n" , __func__, (slave_addr <<1 ) | start_bit | alg_data->mif.mode);/* Write the slave address, START bit and R/W bit */ iowrite32 ((slave_addr <<1 ) | start_bit | alg_data->mif.mode,I2C_REG_TX (alg_data)); -dev_dbg (&adap->dev,"%s(): exit\n" , __func__); +dev_dbg (&alg_data->adapter.dev,"%s(): exit\n" , __func__);return 0 ; }
@@ -135,13 +133,12 @@ static int i2c_pnx_start(unsigned char slave_addr, struct i2c_adapter *adap)* * Generate a STOP signal to terminate the master transaction. */ -static void i2c_pnx_stop (struct i2c_adapter *adap) +static void i2c_pnx_stop (struct i2c_pnx_algo_data *alg_data) { -struct i2c_pnx_algo_data *alg_data = adap->algo_data;/* Only 1 msec max timeout due to interrupt context */ long timeout =1000 ; -dev_dbg (&adap->dev,"%s(): entering: stat = %04x.\n" , +dev_dbg (&alg_data->adapter.dev,"%s(): entering: stat = %04x.\n" , __func__,ioread32 (I2C_REG_STS (alg_data)));/* Write a STOP bit to TX FIFO */
@@ -155,7 +152,7 @@ static void i2c_pnx_stop(struct i2c_adapter *adap) timeout--; } -dev_dbg (&adap->dev,"%s(): exiting: stat = %04x.\n" , +dev_dbg (&alg_data->adapter.dev,"%s(): exiting: stat = %04x.\n" , __func__,ioread32 (I2C_REG_STS (alg_data))); }
@@ -165,12 +162,11 @@ static void i2c_pnx_stop(struct i2c_adapter *adap)* * Sends one byte of data to the slave */ -static int i2c_pnx_master_xmit (struct i2c_adapter *adap) +static int i2c_pnx_master_xmit (struct i2c_pnx_algo_data *alg_data) { -struct i2c_pnx_algo_data *alg_data = adap->algo_data;u32 val; -dev_dbg (&adap->dev,"%s(): entering: stat = %04x.\n" , +dev_dbg (&alg_data->adapter.dev,"%s(): entering: stat = %04x.\n" , __func__,ioread32 (I2C_REG_STS (alg_data)));if (alg_data->mif.len >0 ) {
@@ -186,14 +182,14 @@ static int i2c_pnx_master_xmit(struct i2c_adapter *adap) alg_data->mif.len--;iowrite32 (val,I2C_REG_TX (alg_data)); -dev_dbg (&adap->dev,"%s(): xmit %#x [%d]\n" , __func__, +dev_dbg (&alg_data->adapter.dev,"%s(): xmit %#x [%d]\n" , __func__, val, alg_data->mif.len +1 );if (alg_data->mif.len ==0 ) {if (alg_data->last) {/* Wait until the STOP is seen. */ if (wait_timeout (I2C_PNX_TIMEOUT , alg_data)) -dev_err (&adap->dev,"The bus is still " +dev_err (&alg_data->adapter.dev,"The bus is still " "active after timeout\n" ); }/* Disable master interrupts */
@@ -203,14 +199,14 @@ static int i2c_pnx_master_xmit(struct i2c_adapter *adap)del_timer_sync (&alg_data->mif.timer); -dev_dbg (&adap->dev,"%s(): Waking up xfer routine.\n" , +dev_dbg (&alg_data->adapter.dev,"%s(): Waking up xfer routine.\n" , __func__);complete (&alg_data->mif.complete); } }else if (alg_data->mif.len ==0 ) {/* zero-sized transfer */ -i2c_pnx_stop (adap); +i2c_pnx_stop (alg_data);/* Disable master interrupts. */ iowrite32(ioread32(I2C_REG_CTL(alg_data)) &
@@ -219,13 +215,13 @@ static int i2c_pnx_master_xmit(struct i2c_adapter *adap)/* Stop timer. */ del_timer_sync (&alg_data->mif.timer); -dev_dbg (&adap->dev,"%s(): Waking up xfer routine after " +dev_dbg (&alg_data->adapter.dev,"%s(): Waking up xfer routine after " "zero-xfer.\n" , __func__);complete (&alg_data->mif.complete); } -dev_dbg (&adap->dev,"%s(): exiting: stat = %04x.\n" , +dev_dbg (&alg_data->adapter.dev,"%s(): exiting: stat = %04x.\n" , __func__,ioread32 (I2C_REG_STS (alg_data)));return 0 ;
@@ -237,20 +233,19 @@ static int i2c_pnx_master_xmit(struct i2c_adapter *adap)* * Reads one byte data from the slave */ -static int i2c_pnx_master_rcv (struct i2c_adapter *adap) +static int i2c_pnx_master_rcv (struct i2c_pnx_algo_data *alg_data) { -struct i2c_pnx_algo_data *alg_data = adap->algo_data;unsigned int val =0 ;u32 ctl =0 ; -dev_dbg (&adap->dev,"%s(): entering: stat = %04x.\n" , +dev_dbg (&alg_data->adapter.dev,"%s(): entering: stat = %04x.\n" , __func__,ioread32 (I2C_REG_STS (alg_data)));/* Check, whether there is already data, * or we didn't 'ask' for it yet. */ if (ioread32 (I2C_REG_STS (alg_data)) & mstatus_rfe) { -dev_dbg (&adap->dev,"%s(): Write dummy data to fill " +dev_dbg (&alg_data->adapter.dev,"%s(): Write dummy data to fill " "Rx-fifo...\n" , __func__);if (alg_data->mif.len ==1 ) {
@@ -283,7 +278,7 @@ static int i2c_pnx_master_rcv(struct i2c_adapter *adap)if (alg_data->mif.len >0 ) { val =ioread32 (I2C_REG_RX (alg_data)); *alg_data->mif.buf++ = (u8) (val &0xff ); -dev_dbg (&adap->dev,"%s(): rcv 0x%x [%d]\n" , __func__, val, +dev_dbg (&alg_data->adapter.dev,"%s(): rcv 0x%x [%d]\n" , __func__, val, alg_data->mif.len); alg_data->mif.len--;
@@ -291,7 +286,7 @@ static int i2c_pnx_master_rcv(struct i2c_adapter *adap)if (alg_data->last)/* Wait until the STOP is seen. */ if (wait_timeout (I2C_PNX_TIMEOUT , alg_data)) -dev_err (&adap->dev,"The bus is still " +dev_err (&alg_data->adapter.dev,"The bus is still " "active after timeout\n" );/* Disable master interrupts */
@@ -306,7 +301,7 @@ static int i2c_pnx_master_rcv(struct i2c_adapter *adap) } } -dev_dbg (&adap->dev,"%s(): exiting: stat = %04x.\n" , +dev_dbg (&alg_data->adapter.dev,"%s(): exiting: stat = %04x.\n" , __func__,ioread32 (I2C_REG_STS (alg_data)));return 0 ;
@@ -314,11 +309,10 @@ static int i2c_pnx_master_rcv(struct i2c_adapter *adap)static irqreturn_t i2c_pnx_interrupt (int irq,void *dev_id) { +struct i2c_pnx_algo_data *alg_data = dev_id;u32 stat, ctl; -struct i2c_adapter *adap = dev_id; -struct i2c_pnx_algo_data *alg_data = adap->algo_data; - dev_dbg(&adap->dev, "%s(): mstat = %x mctrl = %x, mode = %d\n", + dev_dbg(&alg_data->adapter.dev, "%s(): mstat = %x mctrl = %x, mode = %d\n", __func__, ioread32(I2C_REG_STS(alg_data)), ioread32(I2C_REG_CTL(alg_data)),
@@ -341,10 +335,10 @@ static irqreturn_t i2c_pnx_interrupt(int irq, void *dev_id)complete (&alg_data->mif.complete); }else if (stat & mstatus_nai) {/* Slave did not acknowledge, generate a STOP */ -dev_dbg (&adap->dev,"%s(): " +dev_dbg (&alg_data->adapter.dev,"%s(): " "Slave did not acknowledge, generating a STOP.\n" , __func__); -i2c_pnx_stop (adap); +i2c_pnx_stop (alg_data);/* Disable master interrupts. */ ctl =ioread32 (I2C_REG_CTL (alg_data));
@@ -370,9 +364,9 @@ static irqreturn_t i2c_pnx_interrupt(int irq, void *dev_id)*/ if ((stat & mstatus_drmi) || !(stat & mstatus_rfe)) {if (alg_data->mif.mode ==I2C_SMBUS_WRITE ) { -i2c_pnx_master_xmit (adap); +i2c_pnx_master_xmit (alg_data); }else if (alg_data->mif.mode ==I2C_SMBUS_READ ) { -i2c_pnx_master_rcv (adap); +i2c_pnx_master_rcv (alg_data); } } }
@@ -381,7 +375,7 @@ static irqreturn_t i2c_pnx_interrupt(int irq, void *dev_id) stat =ioread32 (I2C_REG_STS (alg_data));iowrite32 (stat | mstatus_tdi | mstatus_afi,I2C_REG_STS (alg_data)); -dev_dbg (&adap->dev,"%s(): exiting, stat = %x ctrl = %x.\n" , +dev_dbg (&alg_data->adapter.dev,"%s(): exiting, stat = %x ctrl = %x.\n" , __func__,ioread32 (I2C_REG_STS (alg_data)),ioread32 (I2C_REG_CTL (alg_data)));
@@ -390,11 +384,10 @@ static irqreturn_t i2c_pnx_interrupt(int irq, void *dev_id)static void i2c_pnx_timeout (unsigned long data) { -struct i2c_adapter *adap = (struct i2c_adapter *)data; -struct i2c_pnx_algo_data *alg_data = adap->algo_data; +struct i2c_pnx_algo_data *alg_data = (struct i2c_pnx_algo_data *)data;u32 ctl; -dev_err (&adap->dev,"Master timed out. stat = %04x, cntrl = %04x. " +dev_err (&alg_data->adapter.dev,"Master timed out. stat = %04x, cntrl = %04x. " "Resetting master...\n" ,ioread32 (I2C_REG_STS (alg_data)),ioread32 (I2C_REG_CTL (alg_data)));
@@ -411,15 +404,14 @@ static void i2c_pnx_timeout(unsigned long data)complete (&alg_data->mif.complete); } -static inline void bus_reset_if_active (struct i2c_adapter *adap) +static inline void bus_reset_if_active (struct i2c_pnx_algo_data *alg_data) { -struct i2c_pnx_algo_data *alg_data = adap->algo_data;u32 stat;if ((stat =ioread32 (I2C_REG_STS (alg_data))) & mstatus_active) { -dev_err (&adap->dev, +dev_err (&alg_data->adapter.dev,"%s: Bus is still active after xfer. Reset it...\n" , - adap->name); + alg_data->adapter.name);iowrite32 (ioread32 (I2C_REG_CTL (alg_data)) | mcntrl_reset,I2C_REG_CTL (alg_data));wait_reset (I2C_PNX_TIMEOUT , alg_data);
@@ -453,10 +445,10 @@ i2c_pnx_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)struct i2c_pnx_algo_data *alg_data = adap->algo_data;u32 stat =ioread32 (I2C_REG_STS (alg_data)); -dev_dbg (&adap->dev,"%s(): entering: %d messages, stat = %04x.\n" , +dev_dbg (&alg_data->adapter.dev,"%s(): entering: %d messages, stat = %04x.\n" , __func__, num,ioread32 (I2C_REG_STS (alg_data))); -bus_reset_if_active (adap); +bus_reset_if_active (alg_data);/* Process transactions in a loop. */ for (i =0 ; rc >=0 && i < num; i++) {
@@ -466,9 +458,9 @@ i2c_pnx_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) addr = pmsg->addr;if (pmsg->flags &I2C_M_TEN ) { -dev_err (&adap->dev, +dev_err (&alg_data->adapter.dev,"%s: 10 bits addr not supported!\n" , - adap->name); + alg_data->adapter.name); rc = -EINVAL ;break ; }
@@ -480,11 +472,11 @@ i2c_pnx_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) alg_data->mif.ret =0 ; alg_data->last = (i == num -1 ); -dev_dbg (&adap->dev,"%s(): mode %d, %d bytes\n" , __func__, +dev_dbg (&alg_data->adapter.dev,"%s(): mode %d, %d bytes\n" , __func__, alg_data->mif.mode, alg_data->mif.len); -i2c_pnx_arm_timer (adap); +i2c_pnx_arm_timer (alg_data);/* initialize the completion var */ init_completion (&alg_data->mif.complete);
@@ -495,7 +487,7 @@ i2c_pnx_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) I2C_REG_CTL(alg_data));/* Put start-code and slave-address on the bus. */ - rc =i2c_pnx_start (addr, adap); + rc =i2c_pnx_start (addr, alg_data);if (rc <0 )break ;
@@ -504,31 +496,31 @@ i2c_pnx_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)if (!(rc = alg_data->mif.ret)) completed++; -dev_dbg (&adap->dev,"%s(): Complete, return code = %d.\n" , +dev_dbg (&alg_data->adapter.dev,"%s(): Complete, return code = %d.\n" , __func__, rc);/* Clear TDI and AFI bits in case they are set. */ if ((stat =ioread32 (I2C_REG_STS (alg_data))) & mstatus_tdi) { -dev_dbg (&adap->dev, +dev_dbg (&alg_data->adapter.dev,"%s: TDI still set... clearing now.\n" , - adap->name); + alg_data->adapter.name);iowrite32 (stat,I2C_REG_STS (alg_data)); }if ((stat =ioread32 (I2C_REG_STS (alg_data))) & mstatus_afi) { -dev_dbg (&adap->dev, +dev_dbg (&alg_data->adapter.dev,"%s: AFI still set... clearing now.\n" , - adap->name); + alg_data->adapter.name);iowrite32 (stat,I2C_REG_STS (alg_data)); } } -bus_reset_if_active (adap); +bus_reset_if_active (alg_data);/* Cleanup to be sure... */ alg_data->mif.buf =NULL ; alg_data->mif.len =0 ; -dev_dbg (&adap->dev,"%s(): exiting, stat = %x\n" , +dev_dbg (&alg_data->adapter.dev,"%s(): exiting, stat = %x\n" , __func__,ioread32 (I2C_REG_STS (alg_data)));if (completed != num)
@@ -609,7 +601,7 @@ static int __devinit i2c_pnx_probe(struct platform_device *pdev)init_timer (&alg_data->mif.timer); alg_data->mif.timer.function = i2c_pnx_timeout; - alg_data->mif.timer.data = (unsigned long )&alg_data->adapter; + alg_data->mif.timer.data = (unsigned long )alg_data;/* Register I/O resource */ if (!request_mem_region(i2c_pnx->base, I2C_PNX_REGION_SIZE,
@@ -657,7 +649,7 @@ static int __devinit i2c_pnx_probe(struct platform_device *pdev)init_completion (&alg_data->mif.complete); ret =request_irq (i2c_pnx->irq, i2c_pnx_interrupt, -0 , pdev->name, &alg_data->adapter); +0 , pdev->name, alg_data);if (ret) goto out_clock;
@@ -674,7 +666,7 @@ static int __devinit i2c_pnx_probe(struct platform_device *pdev)return 0 ; out_irq: -free_irq (i2c_pnx->irq, &alg_data->adapter); +free_irq (i2c_pnx->irq, alg_data); out_clock:clk_disable (alg_data->clk); out_unmap:
@@ -696,7 +688,7 @@ static int __devexit i2c_pnx_remove(struct platform_device *pdev)struct i2c_pnx_algo_data *alg_data =platform_get_drvdata (pdev);struct i2c_pnx_data *i2c_pnx = alg_data->i2c_pnx; -free_irq (i2c_pnx->irq, &alg_data->adapter); +free_irq (i2c_pnx->irq, alg_data);i2c_del_adapter (&alg_data->adapter);clk_disable (alg_data->clk);iounmap (alg_data->ioaddr);
Signature · 1 line
1.6.2.5
PATCH 16/18 ARM: PNX4008: i2c-pnx: don't split messages across several lines
In reply to Russell King - ARM LinuxIt makes them harder to grep for.
--- drivers/i2c/busses/i2c-pnx.c | 81 +++++++++++++++++++++++------------------- 1 files changed, 44 insertions(+), 37 deletions(-)
drivers/i2c/busses/i2c-pnx.c +44 -37
@@ -86,25 +86,26 @@ static int i2c_pnx_start(unsigned char slave_addr,/* Check for 7 bit slave addresses only */ if (slave_addr & ~0x7f ) { -dev_err (&alg_data->adapter.dev,"%s: Invalid slave address %x. " -"Only 7-bit addresses are supported\n" , - alg_data->adapter.name, slave_addr); +dev_err (&alg_data->adapter.dev, +"%s: Invalid slave address %x. Only 7-bit addresses are supported\n" , + alg_data->adapter.name, slave_addr);return -EINVAL ; }/* First, make sure bus is idle */ if (wait_timeout (I2C_PNX_TIMEOUT , alg_data)) {/* Somebody else is monopolizing the bus */ -dev_err (&alg_data->adapter.dev,"%s: Bus busy. Slave addr = %02x, " -"cntrl = %x, stat = %x\n" , - alg_data->adapter.name, slave_addr, -ioread32 (I2C_REG_CTL (alg_data)), -ioread32 (I2C_REG_STS (alg_data))); +dev_err (&alg_data->adapter.dev, +"%s: Bus busy. Slave addr = %02x, cntrl = %x, stat = %x\n" , + alg_data->adapter.name, slave_addr, +ioread32 (I2C_REG_CTL (alg_data)), +ioread32 (I2C_REG_STS (alg_data)));return -EBUSY ; }else if (ioread32 (I2C_REG_STS (alg_data)) & mstatus_afi) {/* Sorry, we lost the bus */ -dev_err (&alg_data->adapter.dev,"%s: Arbitration failure. " -"Slave addr = %02x\n" , alg_data->adapter.name, slave_addr); +dev_err (&alg_data->adapter.dev, +"%s: Arbitration failure. Slave addr = %02x\n" , + alg_data->adapter.name, slave_addr);return -EIO ; }
@@ -182,15 +183,15 @@ static int i2c_pnx_master_xmit(struct i2c_pnx_algo_data *alg_data) alg_data->mif.len--;iowrite32 (val,I2C_REG_TX (alg_data)); -dev_dbg (&alg_data->adapter.dev,"%s(): xmit %#x [%d]\n" , __func__, - val, alg_data->mif.len +1 ); +dev_dbg (&alg_data->adapter.dev,"%s(): xmit %#x [%d]\n" , + __func__, val, alg_data->mif.len +1 );if (alg_data->mif.len ==0 ) {if (alg_data->last) {/* Wait until the STOP is seen. */ if (wait_timeout (I2C_PNX_TIMEOUT , alg_data)) -dev_err (&alg_data->adapter.dev,"The bus is still " -"active after timeout\n" ); +dev_err (&alg_data->adapter.dev, +"The bus is still active after timeout\n" ); }/* Disable master interrupts */ iowrite32(ioread32(I2C_REG_CTL(alg_data)) &
@@ -199,7 +200,8 @@ static int i2c_pnx_master_xmit(struct i2c_pnx_algo_data *alg_data)del_timer_sync (&alg_data->mif.timer); -dev_dbg (&alg_data->adapter.dev,"%s(): Waking up xfer routine.\n" , +dev_dbg (&alg_data->adapter.dev, +"%s(): Waking up xfer routine.\n" , __func__);complete (&alg_data->mif.complete);
@@ -215,8 +217,9 @@ static int i2c_pnx_master_xmit(struct i2c_pnx_algo_data *alg_data)/* Stop timer. */ del_timer_sync (&alg_data->mif.timer); -dev_dbg (&alg_data->adapter.dev,"%s(): Waking up xfer routine after " -"zero-xfer.\n" , __func__); +dev_dbg (&alg_data->adapter.dev, +"%s(): Waking up xfer routine after zero-xfer.\n" , + __func__);complete (&alg_data->mif.complete); }
@@ -245,8 +248,9 @@ static int i2c_pnx_master_rcv(struct i2c_pnx_algo_data *alg_data)* or we didn't 'ask' for it yet. */ if (ioread32 (I2C_REG_STS (alg_data)) & mstatus_rfe) { -dev_dbg (&alg_data->adapter.dev,"%s(): Write dummy data to fill " -"Rx-fifo...\n" , __func__); +dev_dbg (&alg_data->adapter.dev, +"%s(): Write dummy data to fill Rx-fifo...\n" , + __func__);if (alg_data->mif.len ==1 ) {/* Last byte, do not acknowledge next rcv. */
@@ -278,16 +282,16 @@ static int i2c_pnx_master_rcv(struct i2c_pnx_algo_data *alg_data)if (alg_data->mif.len >0 ) { val =ioread32 (I2C_REG_RX (alg_data)); *alg_data->mif.buf++ = (u8) (val &0xff ); -dev_dbg (&alg_data->adapter.dev,"%s(): rcv 0x%x [%d]\n" , __func__, val, - alg_data->mif.len); +dev_dbg (&alg_data->adapter.dev,"%s(): rcv 0x%x [%d]\n" , + __func__, val, alg_data->mif.len); alg_data->mif.len--;if (alg_data->mif.len ==0 ) {if (alg_data->last)/* Wait until the STOP is seen. */ if (wait_timeout (I2C_PNX_TIMEOUT , alg_data)) -dev_err (&alg_data->adapter.dev,"The bus is still " -"active after timeout\n" ); +dev_err (&alg_data->adapter.dev, +"The bus is still active after timeout\n" );/* Disable master interrupts */ ctl =ioread32 (I2C_REG_CTL (alg_data));
@@ -312,7 +316,8 @@ static irqreturn_t i2c_pnx_interrupt(int irq, void *dev_id)struct i2c_pnx_algo_data *alg_data = dev_id;u32 stat, ctl; - dev_dbg(&alg_data->adapter.dev, "%s(): mstat = %x mctrl = %x, mode = %d\n", + dev_dbg(&alg_data->adapter.dev, + "%s(): mstat = %x mctrl = %x, mode = %d\n", __func__, ioread32(I2C_REG_STS(alg_data)), ioread32(I2C_REG_CTL(alg_data)),
@@ -335,8 +340,8 @@ static irqreturn_t i2c_pnx_interrupt(int irq, void *dev_id)complete (&alg_data->mif.complete); }else if (stat & mstatus_nai) {/* Slave did not acknowledge, generate a STOP */ -dev_dbg (&alg_data->adapter.dev,"%s(): " -"Slave did not acknowledge, generating a STOP.\n" , +dev_dbg (&alg_data->adapter.dev, +"%s(): Slave did not acknowledge, generating a STOP.\n" , __func__);i2c_pnx_stop (alg_data);
@@ -375,7 +380,8 @@ static irqreturn_t i2c_pnx_interrupt(int irq, void *dev_id) stat =ioread32 (I2C_REG_STS (alg_data));iowrite32 (stat | mstatus_tdi | mstatus_afi,I2C_REG_STS (alg_data)); -dev_dbg (&alg_data->adapter.dev,"%s(): exiting, stat = %x ctrl = %x.\n" , +dev_dbg (&alg_data->adapter.dev, +"%s(): exiting, stat = %x ctrl = %x.\n" , __func__,ioread32 (I2C_REG_STS (alg_data)),ioread32 (I2C_REG_CTL (alg_data)));
@@ -387,10 +393,10 @@ static void i2c_pnx_timeout(unsigned long data)struct i2c_pnx_algo_data *alg_data = (struct i2c_pnx_algo_data *)data;u32 ctl; -dev_err (&alg_data->adapter.dev,"Master timed out. stat = %04x, cntrl = %04x. " -"Resetting master...\n" , -ioread32 (I2C_REG_STS (alg_data)), -ioread32 (I2C_REG_CTL (alg_data))); +dev_err (&alg_data->adapter.dev, +"Master timed out. stat = %04x, cntrl = %04x. Resetting master...\n" , +ioread32 (I2C_REG_STS (alg_data)), +ioread32 (I2C_REG_CTL (alg_data)));/* Reset master and disable interrupts */ ctl =ioread32 (I2C_REG_CTL (alg_data));
@@ -411,7 +417,7 @@ static inline void bus_reset_if_active(struct i2c_pnx_algo_data *alg_data)if ((stat =ioread32 (I2C_REG_STS (alg_data))) & mstatus_active) {dev_err (&alg_data->adapter.dev,"%s: Bus is still active after xfer. Reset it...\n" , - alg_data->adapter.name); + alg_data->adapter.name);iowrite32 (ioread32 (I2C_REG_CTL (alg_data)) | mcntrl_reset,I2C_REG_CTL (alg_data));wait_reset (I2C_PNX_TIMEOUT , alg_data);
@@ -445,7 +451,8 @@ i2c_pnx_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)struct i2c_pnx_algo_data *alg_data = adap->algo_data;u32 stat =ioread32 (I2C_REG_STS (alg_data)); -dev_dbg (&alg_data->adapter.dev,"%s(): entering: %d messages, stat = %04x.\n" , +dev_dbg (&alg_data->adapter.dev, +"%s(): entering: %d messages, stat = %04x.\n" , __func__, num,ioread32 (I2C_REG_STS (alg_data)));bus_reset_if_active (alg_data);
@@ -472,9 +479,8 @@ i2c_pnx_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) alg_data->mif.ret =0 ; alg_data->last = (i == num -1 ); -dev_dbg (&alg_data->adapter.dev,"%s(): mode %d, %d bytes\n" , __func__, - alg_data->mif.mode, - alg_data->mif.len); +dev_dbg (&alg_data->adapter.dev,"%s(): mode %d, %d bytes\n" , + __func__, alg_data->mif.mode, alg_data->mif.len);i2c_pnx_arm_timer (alg_data);
@@ -496,7 +502,8 @@ i2c_pnx_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)if (!(rc = alg_data->mif.ret)) completed++; -dev_dbg (&alg_data->adapter.dev,"%s(): Complete, return code = %d.\n" , +dev_dbg (&alg_data->adapter.dev, +"%s(): Complete, return code = %d.\n" , __func__, rc);/* Clear TDI and AFI bits in case they are set. */
Signature · 1 line
1.6.2.5
PATCH 17/18 ARM: PNX4008: i2c-pnx makes no use of asm/uaccess.h nor asm/irq.h
In reply to Russell King - ARM LinuxRemove unnecessary includes
--- drivers/i2c/busses/i2c-pnx.c | 2 -- 1 files changed, 0 insertions(+), 2 deletions(-)
drivers/i2c/busses/i2c-pnx.c +0 -2
@@ -25,8 +25,6 @@#include <mach/hardware.h> #include <mach/i2c.h> -#include <asm/irq.h> -#include <asm/uaccess.h> #define I2C_PNX_TIMEOUT 10/* msec */ #define I2C_PNX_SPEED_KHZ 100
Signature · 1 line
1.6.2.5
PATCH 18/18 ARM: PNX4008: use msecs_to_jiffies() rather than open-coding it
In reply to Russell King - ARM Linux--- drivers/i2c/busses/i2c-pnx.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/i2c/busses/i2c-pnx.c +2 -2
@@ -53,14 +53,14 @@ static inline int wait_reset(long timeout, struct i2c_pnx_algo_data *data)static inline void i2c_pnx_arm_timer (struct i2c_pnx_algo_data *alg_data) {struct timer_list *timer = &alg_data->mif.timer; -int expires =I2C_PNX_TIMEOUT / (1000 /HZ ); +unsigned long expires =msecs_to_jiffies (I2C_PNX_TIMEOUT );if (expires <=1 ) expires =2 ;del_timer_sync (timer); -dev_dbg (&alg_data->adapter.dev,"Timer armed at %lu plus %u jiffies.\n" , +dev_dbg (&alg_data->adapter.dev,"Timer armed at %lu plus %lu jiffies.\n" , jiffies, expires); timer->expires = jiffies + expires;
Signature · 1 line
1.6.2.5
PATCH 14/18 ARM: PNX4008: move i2c_adapter structure inside the drivers private data
In reply to Russell King - ARM LinuxAll these changes in the patch series work on my hardware. A few comments below, but these can be updated once these changes are accepted.
Quoted 3 lines
arch/arm/mach-pnx4008/i2c.c +0
-0
...
...
...
Quoted 10 lines
static struct
i2c_pnx_datai2c0_data= {arch/arm/mach-pnx4008/i2c.c +2
-2- .adapter = &pnx_adapter0, + .name = I2C_CHIP_NAME "0", .base = PNX4008_I2C1_BASE, .irq = I2C_1_INT, };static struct i2c_pnx_data i2c1_data = { - .adapter = &pnx_adapter1, + .name =I2C_CHIP_NAME "1" ,
arch/arm/mach-pnx4008/i2c.c line 37
Quoted 10 lines
arch/arm/mach-pnx4008/i2c.c +1
-1.base = PNX4008_I2C2_BASE, .irq = I2C_2_INT, };static struct i2c_pnx_data i2c2_data = { - .adapter = &pnx_adapter2, + .name ="USB-I2C" , .base = (PNX4008_USB_CONFIG_BASE +0x300 ), .irq =USB_I2C_INT , };
This looks good. 'struct resource' can be used instead of the specialized i2c_pnx_data structure. The name field can be removed and the adapter name generically assigned in the driver based on the .id field in the platform_device structure. (The i2c2 interface won't have then "USB-I2C" name anymore, but thats really just another I2C interface, not specific to USB). This would simplify the platform code and driver a little more and bring it inline with how all the other platform drivers handle platform data. The REGION_SIZE macro in the i2c-pnx driver could be swapped out with the platform data size field instead.
Quoted 2 lines
drivers/i2c/busses/i2c-pnx.c +0
-0
...
...
...
drivers/i2c/busses/i2c-pnx.c static int __devinit i2c_pnx_probe(struct platform_device *pdev) · line 601
Quoted 7 lines
drivers/i2c/busses/i2c-pnx.c +6
-1- i2c_pnx->adapter->algo_data = alg_data; +strlcpy (alg_data->adapter.name, i2c_pnx->name, +sizeof (alg_data->adapter.name)); + alg_data->adapter.dev.parent = &pdev->dev; + alg_data->adapter.algo = &pnx_algorithm; + alg_data->adapter.algo_data = alg_data; + alg_data->adapter.nr = pdev->id;
See my comment below about alg_data->adapter.nr
drivers/i2c/busses/i2c-pnx.c static int __devinit i2c_pnx_probe(struct platform_device *pdev) · line 666
Quoted 6 lines
drivers/i2c/busses/i2c-pnx.c +1
-3/* Register this adapter with the I2C subsystem */ - i2c_pnx->adapter->dev.parent = &pdev->dev; - i2c_pnx->adapter->nr = pdev->id; - ret =i2c_add_numbered_adapter (i2c_pnx->adapter); + ret =i2c_add_adapter (&alg_data->adapter);if (ret <0 ) {
If i2c_add_numbered_adapter isn't used, the alg_data->adapter.nr value will be re-assigned in the i2c-core driver. The assigned pdev->id value would get overwritten by something else, possibly not the same value. The i2c_register_board_info() function in the platform code would have to be tweaked for each platform, possibly based on the number of I2C adapters registered in the system (up to 3 can be used, but 3 aren't always used).
PATCH 14/18 ARM: PNX4008: move i2c_adapter structure inside the drivers private data
Quoted 13 lines · Kevin Wells
All these changes in the patch series work on my hardware. A few comments below, but these can be updated once these changes are accepted.
arch/arm/mach-pnx4008/i2c.c line 37
Quoted 6 lines
static struct
i2c_pnx_datai2c2_data= {arch/arm/mach-pnx4008/i2c.c +1
-1- .adapter = &pnx_adapter2, + .name = "USB-I2C", .base = (PNX4008_USB_CONFIG_BASE + 0x300), .irq = USB_I2C_INT, };This looks good. 'struct resource' can be used instead of the specialized
i2c_pnx_datastructure. The name field can be removed
Quoted 8 lines
and the adapter name generically assigned in the driver based on the .id field in the
platform_devicestructure. (The i2c2 interface won't have then "USB-I2C" name anymore, but thats really just another I2C interface, not specific to USB). This would simplify the platform code and driver a little more and bring it inline with how all the other platform drivers handle platform data. TheREGION_SIZEmacro in the i2c-pnx driver could be swapped out with the platform data size field instead.
I thought about that, but because of the naming differences, I decided to leave alone. This can be the subject of a separate patch.
Quoted 9 lines
drivers/i2c/busses/i2c-pnx.c static int __devinit i2c_pnx_probe(struct platform_device *pdev) · line 666
Quoted 6 lines
drivers/i2c/busses/i2c-pnx.c +1
-3/* Register this adapter with the I2C subsystem */ - i2c_pnx->adapter->dev.parent = &pdev->dev; - i2c_pnx->adapter->nr = pdev->id; - ret =i2c_add_numbered_adapter (i2c_pnx->adapter); + ret =i2c_add_adapter (&alg_data->adapter);if (ret <0 ) {If
i2c_add_numbered_adapterisn't used, thealg_data->adapter.nrvalue will be re-assigned in the i2c-core driver.
This is the result of fixing the merge between my changes and your 155a493 change.
It highlights the problem of merge conflicts - it's very difficult with the cvs/git conflict marking to work out what the right fixes for any conflict is, especially when you aren't the author of both sets of changes. The problem is that you're given the original version and your version to look at, and the problem comes when the right resolution is to take a subset of lines from both versions.
I continue to absolutely detest git conflicts, and I suspect that's never going to change.
Fixed now to use i2c_add_numbered_adapter() again.
cover PNX4008 patchset (updated with Vitaly's acks, plus a few more patches)
In reply to Russell King - ARM LinuxQuoted 1 line · Russell King - ARM Linux
As the subject line says.
Right, as of now, I'm queuing this patchset for the next merge window and casting it in stone - there are now other cross-platform patches which depend on this set.