Re: [PATCH 2/3] i2c-mpc: add support for the MPC512x processors from Freescale
On Mon, Jan 25, 2010 at 04:15:09PM +0100, Wolfram Sang wrote: -static void __devinit mpc_i2c_setclock_52xx(struct device_node *node, -struct mpc_i2c *i2c, -u32 clock, u32 prescaler) +static void __devinit mpc_i2c_setup_52xx(struct device_node *node, + struct mpc_i2c *i2c, + u32 clock, u32 prescaler) { int ret, fdr; +if (clock == -1) { Could we use 0 for 'no_clock'? This would make the above statement simply 0 is already used to maintain backward compatibility setting a safe divider. Ah, now I see: 'clock == -1' means 'preserve clocks' (and is checked here in mpc_i2c_setup_52xx()) 'clock == 0' means 'safe divider' (and is checked in mpc_i2c_get_fdr_52xx()) hmm, sounds like a job for a #define or similar. This is not a beauty ;) What about adding a flags variable to the setup-functions? Regards, Wolfram -- Pengutronix e.K. | Wolfram Sang| Industrial Linux Solutions | http://www.pengutronix.de/ | -- Ben (b...@fluff.org, http://www.fluff.org/) 'a smiley only costs 4 bytes' ___ Linuxppc-dev mailing list Linuxppc-dev@lists.ozlabs.org https://lists.ozlabs.org/listinfo/linuxppc-dev
Re: [PATCH 2/3] i2c-mpc: add support for the MPC512x processors from Freescale
Ben Dooks wrote: On Mon, Jan 25, 2010 at 04:15:09PM +0100, Wolfram Sang wrote: -static void __devinit mpc_i2c_setclock_52xx(struct device_node *node, - struct mpc_i2c *i2c, - u32 clock, u32 prescaler) +static void __devinit mpc_i2c_setup_52xx(struct device_node *node, + struct mpc_i2c *i2c, + u32 clock, u32 prescaler) { int ret, fdr; + if (clock == -1) { Could we use 0 for 'no_clock'? This would make the above statement simply 0 is already used to maintain backward compatibility setting a safe divider. Ah, now I see: 'clock == -1' means 'preserve clocks' (and is checked here in mpc_i2c_setup_52xx()) 'clock == 0' means 'safe divider' (and is checked in mpc_i2c_get_fdr_52xx()) hmm, sounds like a job for a #define or similar. See v2 of this patch. Wolfgang. ___ Linuxppc-dev mailing list Linuxppc-dev@lists.ozlabs.org https://lists.ozlabs.org/listinfo/linuxppc-dev
[PATCH 2/3] i2c-mpc: add support for the MPC512x processors from Freescale
From: Wolfgang Grandegger w...@denx.de The setclock initialization functions have been renamed to setup because I2C interrupts must be enabled for the MPC512x. This requires to handle fsl,preserve-clocking in a slighly different way. Also, the old settings are now reported calling dev_dbg(). For the MPC512x the clock setup function of the MPC52xx can be re-used. Signed-off-by: Wolfgang Grandegger w...@denx.de --- drivers/i2c/busses/Kconfig |9 ++-- drivers/i2c/busses/i2c-mpc.c | 122 ++ 2 files changed, 93 insertions(+), 38 deletions(-) diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig index 5f318ce..f481f30 100644 --- a/drivers/i2c/busses/Kconfig +++ b/drivers/i2c/busses/Kconfig @@ -418,13 +418,14 @@ config I2C_IXP2000 instead. config I2C_MPC - tristate MPC107/824x/85xx/52xx/86xx + tristate MPC107/824x/85xx/512x/52xx/86xx depends on PPC32 help If you say yes to this option, support will be included for the - built-in I2C interface on the MPC107/Tsi107/MPC8240/MPC8245 and - MPC85xx/MPC8641 family processors. The driver may also work on 52xx - family processors, though interrupts are known not to work. + built-in I2C interface on the MPC107/Tsi107/MPC8240/MPC8245, + MPC85xx/MPC8641 and MPC512x family processors. The driver may + also work on 52xx family processors, though interrupts are known + not to work. This driver can also be built as a module. If so, the module will be called i2c-mpc. diff --git a/drivers/i2c/busses/i2c-mpc.c b/drivers/i2c/busses/i2c-mpc.c index 2cb864e..70c3e5d 100644 --- a/drivers/i2c/busses/i2c-mpc.c +++ b/drivers/i2c/busses/i2c-mpc.c @@ -67,9 +67,8 @@ struct mpc_i2c_divider { }; struct mpc_i2c_data { - void (*setclock)(struct device_node *node, -struct mpc_i2c *i2c, -u32 clock, u32 prescaler); + void (*setup)(struct device_node *node, struct mpc_i2c *i2c, + u32 clock, u32 prescaler); u32 prescaler; }; @@ -164,7 +163,7 @@ static int i2c_wait(struct mpc_i2c *i2c, unsigned timeout, int writing) return 0; } -#ifdef CONFIG_PPC_MPC52xx +#if defined(CONFIG_PPC_MPC52xx) || defined(CONFIG_PPC_MPC512x) static const struct __devinitdata mpc_i2c_divider mpc_i2c_dividers_52xx[] = { {20, 0x20}, {22, 0x21}, {24, 0x22}, {26, 0x23}, {28, 0x24}, {30, 0x01}, {32, 0x25}, {34, 0x02}, @@ -216,12 +215,18 @@ static int __devinit mpc_i2c_get_fdr_52xx(struct device_node *node, u32 clock, return div ? (int)div-fdr : -EINVAL; } -static void __devinit mpc_i2c_setclock_52xx(struct device_node *node, - struct mpc_i2c *i2c, - u32 clock, u32 prescaler) +static void __devinit mpc_i2c_setup_52xx(struct device_node *node, +struct mpc_i2c *i2c, +u32 clock, u32 prescaler) { int ret, fdr; + if (clock == -1) { + dev_dbg(i2c-dev, using fdr %d\n, + readb(i2c-base + MPC_I2C_FDR)); + return; /* preserve clocking */ + } + ret = mpc_i2c_get_fdr_52xx(node, clock, prescaler); fdr = (ret = 0) ? ret : 0x3f; /* backward compatibility */ @@ -230,13 +235,50 @@ static void __devinit mpc_i2c_setclock_52xx(struct device_node *node, if (ret = 0) dev_info(i2c-dev, clock %d Hz (fdr=%d)\n, clock, fdr); } -#else /* !CONFIG_PPC_MPC52xx */ -static void __devinit mpc_i2c_setclock_52xx(struct device_node *node, - struct mpc_i2c *i2c, - u32 clock, u32 prescaler) +#else /* !(CONFIG_PPC_MPC52xx || CONFIG_PPC_MPC512x) */ +static void __devinit mpc_i2c_setup_52xx(struct device_node *node, +struct mpc_i2c *i2c, +u32 clock, u32 prescaler) +{ +} +#endif /* CONFIG_PPC_MPC52xx || CONFIG_PPC_MPC512x */ + +#ifdef CONFIG_PPC_MPC512x +static void __devinit mpc_i2c_setup_512x(struct device_node *node, +struct mpc_i2c *i2c, +u32 clock, u32 prescaler) +{ + struct device_node *node_ctrl; + void __iomem *ctrl; + const u32 *pval; + u32 idx; + + /* Enable I2C interrupts for mpc5121 */ + node_ctrl = of_find_compatible_node(NULL, NULL, + fsl,mpc5121-i2c-ctrl); + if (node_ctrl) { + ctrl = of_iomap(node_ctrl, 0); + if (ctrl) { + + /* Interrupt enable bits for i2c-0/1/2: bit 24/26/28 */ + pval = of_get_property(node, reg, NULL); + idx = (*pval 0xff)
Re: [PATCH 2/3] i2c-mpc: add support for the MPC512x processors from Freescale
Hi Wolfgang, On Mon, Jan 25, 2010 at 09:27:08AM +0100, Wolfgang Grandegger wrote: From: Wolfgang Grandegger w...@denx.de The setclock initialization functions have been renamed to setup because I2C interrupts must be enabled for the MPC512x. This requires to handle fsl,preserve-clocking in a slighly different way. Also, the old settings are now reported calling dev_dbg(). For the MPC512x the clock setup function of the MPC52xx can be re-used. Signed-off-by: Wolfgang Grandegger w...@denx.de --- drivers/i2c/busses/Kconfig |9 ++-- drivers/i2c/busses/i2c-mpc.c | 122 ++ 2 files changed, 93 insertions(+), 38 deletions(-) diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig index 5f318ce..f481f30 100644 --- a/drivers/i2c/busses/Kconfig +++ b/drivers/i2c/busses/Kconfig @@ -418,13 +418,14 @@ config I2C_IXP2000 instead. config I2C_MPC - tristate MPC107/824x/85xx/52xx/86xx + tristate MPC107/824x/85xx/512x/52xx/86xx depends on PPC32 help If you say yes to this option, support will be included for the - built-in I2C interface on the MPC107/Tsi107/MPC8240/MPC8245 and - MPC85xx/MPC8641 family processors. The driver may also work on 52xx - family processors, though interrupts are known not to work. + built-in I2C interface on the MPC107/Tsi107/MPC8240/MPC8245, + MPC85xx/MPC8641 and MPC512x family processors. The driver may + also work on 52xx family processors, though interrupts are known + not to work. Opinion poll: Can we remove the may work sentence while we are here? It has worked fine for years. BTW, which interrupts are meant here (from I2C slaves? interrupts of the controller?)? This driver can also be built as a module. If so, the module will be called i2c-mpc. diff --git a/drivers/i2c/busses/i2c-mpc.c b/drivers/i2c/busses/i2c-mpc.c index 2cb864e..70c3e5d 100644 --- a/drivers/i2c/busses/i2c-mpc.c +++ b/drivers/i2c/busses/i2c-mpc.c @@ -67,9 +67,8 @@ struct mpc_i2c_divider { }; struct mpc_i2c_data { - void (*setclock)(struct device_node *node, - struct mpc_i2c *i2c, - u32 clock, u32 prescaler); + void (*setup)(struct device_node *node, struct mpc_i2c *i2c, + u32 clock, u32 prescaler); u32 prescaler; }; @@ -164,7 +163,7 @@ static int i2c_wait(struct mpc_i2c *i2c, unsigned timeout, int writing) return 0; } -#ifdef CONFIG_PPC_MPC52xx +#if defined(CONFIG_PPC_MPC52xx) || defined(CONFIG_PPC_MPC512x) static const struct __devinitdata mpc_i2c_divider mpc_i2c_dividers_52xx[] = { {20, 0x20}, {22, 0x21}, {24, 0x22}, {26, 0x23}, {28, 0x24}, {30, 0x01}, {32, 0x25}, {34, 0x02}, @@ -216,12 +215,18 @@ static int __devinit mpc_i2c_get_fdr_52xx(struct device_node *node, u32 clock, return div ? (int)div-fdr : -EINVAL; } -static void __devinit mpc_i2c_setclock_52xx(struct device_node *node, - struct mpc_i2c *i2c, - u32 clock, u32 prescaler) +static void __devinit mpc_i2c_setup_52xx(struct device_node *node, + struct mpc_i2c *i2c, + u32 clock, u32 prescaler) { int ret, fdr; + if (clock == -1) { Could we use 0 for 'no_clock'? This would make the above statement simply if (!clock) and saves us using -1 with a u32. + dev_dbg(i2c-dev, using fdr %d\n, + readb(i2c-base + MPC_I2C_FDR)); + return; /* preserve clocking */ + } + ret = mpc_i2c_get_fdr_52xx(node, clock, prescaler); fdr = (ret = 0) ? ret : 0x3f; /* backward compatibility */ @@ -230,13 +235,50 @@ static void __devinit mpc_i2c_setclock_52xx(struct device_node *node, if (ret = 0) dev_info(i2c-dev, clock %d Hz (fdr=%d)\n, clock, fdr); } -#else /* !CONFIG_PPC_MPC52xx */ -static void __devinit mpc_i2c_setclock_52xx(struct device_node *node, - struct mpc_i2c *i2c, - u32 clock, u32 prescaler) +#else /* !(CONFIG_PPC_MPC52xx || CONFIG_PPC_MPC512x) */ +static void __devinit mpc_i2c_setup_52xx(struct device_node *node, + struct mpc_i2c *i2c, + u32 clock, u32 prescaler) +{ +} +#endif /* CONFIG_PPC_MPC52xx || CONFIG_PPC_MPC512x */ + +#ifdef CONFIG_PPC_MPC512x +static void __devinit mpc_i2c_setup_512x(struct device_node *node, + struct mpc_i2c *i2c, + u32 clock, u32 prescaler) +{ + struct device_node *node_ctrl; + void __iomem *ctrl; + const u32 *pval; + u32 idx; + + /* Enable I2C interrupts for
Re: [PATCH 2/3] i2c-mpc: add support for the MPC512x processors from Freescale
Hi Wolfram, Wolfram Sang wrote: Hi Wolfgang, On Mon, Jan 25, 2010 at 09:27:08AM +0100, Wolfgang Grandegger wrote: From: Wolfgang Grandegger w...@denx.de The setclock initialization functions have been renamed to setup because I2C interrupts must be enabled for the MPC512x. This requires to handle fsl,preserve-clocking in a slighly different way. Also, the old settings are now reported calling dev_dbg(). For the MPC512x the clock setup function of the MPC52xx can be re-used. Signed-off-by: Wolfgang Grandegger w...@denx.de --- drivers/i2c/busses/Kconfig |9 ++-- drivers/i2c/busses/i2c-mpc.c | 122 ++ 2 files changed, 93 insertions(+), 38 deletions(-) diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig index 5f318ce..f481f30 100644 --- a/drivers/i2c/busses/Kconfig +++ b/drivers/i2c/busses/Kconfig @@ -418,13 +418,14 @@ config I2C_IXP2000 instead. config I2C_MPC -tristate MPC107/824x/85xx/52xx/86xx +tristate MPC107/824x/85xx/512x/52xx/86xx depends on PPC32 help If you say yes to this option, support will be included for the - built-in I2C interface on the MPC107/Tsi107/MPC8240/MPC8245 and - MPC85xx/MPC8641 family processors. The driver may also work on 52xx - family processors, though interrupts are known not to work. + built-in I2C interface on the MPC107/Tsi107/MPC8240/MPC8245, + MPC85xx/MPC8641 and MPC512x family processors. The driver may + also work on 52xx family processors, though interrupts are known + not to work. Opinion poll: Can we remove the may work sentence while we are here? It has worked fine for years. BTW, which interrupts are meant here (from I2C slaves? interrupts of the controller?)? I first wanted to remove this sentence but as I was not sure what it's exact meaning... Anyway, it's confusing and I would remove it. This driver can also be built as a module. If so, the module will be called i2c-mpc. diff --git a/drivers/i2c/busses/i2c-mpc.c b/drivers/i2c/busses/i2c-mpc.c index 2cb864e..70c3e5d 100644 --- a/drivers/i2c/busses/i2c-mpc.c +++ b/drivers/i2c/busses/i2c-mpc.c @@ -67,9 +67,8 @@ struct mpc_i2c_divider { }; struct mpc_i2c_data { -void (*setclock)(struct device_node *node, - struct mpc_i2c *i2c, - u32 clock, u32 prescaler); +void (*setup)(struct device_node *node, struct mpc_i2c *i2c, + u32 clock, u32 prescaler); u32 prescaler; }; @@ -164,7 +163,7 @@ static int i2c_wait(struct mpc_i2c *i2c, unsigned timeout, int writing) return 0; } -#ifdef CONFIG_PPC_MPC52xx +#if defined(CONFIG_PPC_MPC52xx) || defined(CONFIG_PPC_MPC512x) static const struct __devinitdata mpc_i2c_divider mpc_i2c_dividers_52xx[] = { {20, 0x20}, {22, 0x21}, {24, 0x22}, {26, 0x23}, {28, 0x24}, {30, 0x01}, {32, 0x25}, {34, 0x02}, @@ -216,12 +215,18 @@ static int __devinit mpc_i2c_get_fdr_52xx(struct device_node *node, u32 clock, return div ? (int)div-fdr : -EINVAL; } -static void __devinit mpc_i2c_setclock_52xx(struct device_node *node, -struct mpc_i2c *i2c, -u32 clock, u32 prescaler) +static void __devinit mpc_i2c_setup_52xx(struct device_node *node, + struct mpc_i2c *i2c, + u32 clock, u32 prescaler) { int ret, fdr; +if (clock == -1) { Could we use 0 for 'no_clock'? This would make the above statement simply 0 is already used to maintain backward compatibility setting a safe divider. if (!clock) and saves us using -1 with a u32. +dev_dbg(i2c-dev, using fdr %d\n, +readb(i2c-base + MPC_I2C_FDR)); +return; /* preserve clocking */ +} + ret = mpc_i2c_get_fdr_52xx(node, clock, prescaler); fdr = (ret = 0) ? ret : 0x3f; /* backward compatibility */ @@ -230,13 +235,50 @@ static void __devinit mpc_i2c_setclock_52xx(struct device_node *node, if (ret = 0) dev_info(i2c-dev, clock %d Hz (fdr=%d)\n, clock, fdr); } -#else /* !CONFIG_PPC_MPC52xx */ -static void __devinit mpc_i2c_setclock_52xx(struct device_node *node, -struct mpc_i2c *i2c, -u32 clock, u32 prescaler) +#else /* !(CONFIG_PPC_MPC52xx || CONFIG_PPC_MPC512x) */ +static void __devinit mpc_i2c_setup_52xx(struct device_node *node, + struct mpc_i2c *i2c, + u32 clock, u32 prescaler) +{ +} +#endif /* CONFIG_PPC_MPC52xx || CONFIG_PPC_MPC512x */ + +#ifdef CONFIG_PPC_MPC512x +static void __devinit mpc_i2c_setup_512x(struct device_node *node, + struct mpc_i2c *i2c, +
Re: [PATCH 2/3] i2c-mpc: add support for the MPC512x processors from Freescale
-static void __devinit mpc_i2c_setclock_52xx(struct device_node *node, - struct mpc_i2c *i2c, - u32 clock, u32 prescaler) +static void __devinit mpc_i2c_setup_52xx(struct device_node *node, + struct mpc_i2c *i2c, + u32 clock, u32 prescaler) { int ret, fdr; + if (clock == -1) { Could we use 0 for 'no_clock'? This would make the above statement simply 0 is already used to maintain backward compatibility setting a safe divider. Ah, now I see: 'clock == -1' means 'preserve clocks' (and is checked here in mpc_i2c_setup_52xx()) 'clock == 0' means 'safe divider' (and is checked in mpc_i2c_get_fdr_52xx()) This is not a beauty ;) What about adding a flags variable to the setup-functions? Regards, Wolfram -- Pengutronix e.K. | Wolfram Sang| Industrial Linux Solutions | http://www.pengutronix.de/ | signature.asc Description: Digital signature ___ Linuxppc-dev mailing list Linuxppc-dev@lists.ozlabs.org https://lists.ozlabs.org/listinfo/linuxppc-dev
Re: [PATCH 2/3] i2c-mpc: add support for the MPC512x processors from Freescale
Wolfram Sang wrote: -static void __devinit mpc_i2c_setclock_52xx(struct device_node *node, - struct mpc_i2c *i2c, - u32 clock, u32 prescaler) +static void __devinit mpc_i2c_setup_52xx(struct device_node *node, + struct mpc_i2c *i2c, + u32 clock, u32 prescaler) { int ret, fdr; + if (clock == -1) { Could we use 0 for 'no_clock'? This would make the above statement simply 0 is already used to maintain backward compatibility setting a safe divider. Ah, now I see: 'clock == -1' means 'preserve clocks' (and is checked here in mpc_i2c_setup_52xx()) Yes, this is now necessary because setup does not just do clock settings. 'clock == 0' means 'safe divider' (and is checked in mpc_i2c_get_fdr_52xx()) This is for compatibility with old DTS files and last time it was tricky to get that right and therefore... This is not a beauty ;) What about adding a flags variable to the setup-functions? .. I hesitate to make bigger changes to the code flow, which the introduction of a flags variable would required. Also it seems to be overkill to me. I will have a closer look, though. At a minimum I will replace -1 with MPC_I2C_PRESERVE_CLOCK. Wolfgang. ___ Linuxppc-dev mailing list Linuxppc-dev@lists.ozlabs.org https://lists.ozlabs.org/listinfo/linuxppc-dev
Re: [PATCH 2/3] i2c-mpc: add support for the MPC512x processors from Freescale
overkill to me. I will have a closer look, though. At a minimum I will replace -1 with MPC_I2C_PRESERVE_CLOCK. Might be also an idea to define it with ~0 (clock is still unsigned). If possible, the code checking for those two cases (0 and -1) should be close together. That could be a compromise until more quirks are needed ;) -- Pengutronix e.K. | Wolfram Sang| Industrial Linux Solutions | http://www.pengutronix.de/ | signature.asc Description: Digital signature ___ Linuxppc-dev mailing list Linuxppc-dev@lists.ozlabs.org https://lists.ozlabs.org/listinfo/linuxppc-dev
Re: [PATCH 2/3] i2c-mpc: add support for the MPC512x processors from Freescale
Wolfram Sang wrote: overkill to me. I will have a closer look, though. At a minimum I will replace -1 with MPC_I2C_PRESERVE_CLOCK. Might be also an idea to define it with ~0 (clock is still unsigned). If possible, the code checking for those two cases (0 and -1) should be close together. That could be a compromise until more quirks are needed ;) I just sent v2. Hope it's OK now. Wolfgang. ___ Linuxppc-dev mailing list Linuxppc-dev@lists.ozlabs.org https://lists.ozlabs.org/listinfo/linuxppc-dev
Re: [PATCH 2/3] i2c-mpc: add support for the MPC512x processors from Freescale
I just sent v2. Hope it's OK now. Thanks, will check tomorrow. -- Pengutronix e.K. | Wolfram Sang| Industrial Linux Solutions | http://www.pengutronix.de/ | signature.asc Description: Digital signature ___ Linuxppc-dev mailing list Linuxppc-dev@lists.ozlabs.org https://lists.ozlabs.org/listinfo/linuxppc-dev