mpc52xx: stop drivers from accessing clock config directly
Subsystems (3)
PATCH 1/2 mpc52xx: add cdm (clock module) helper function for PSCs
In reply to Grant LikelyFrom: Grant Likely <[email protected]>
Device drivers should not access the CDM registers directly to modify the clocking. Instead, provide a helper function for setting the MCLK value so that the registers can be properly protected from concurent access.
---
arch/powerpc/platforms/52xx/efika.c | 2 arch/powerpc/platforms/52xx/lite5200.c | 1 arch/powerpc/platforms/52xx/mpc52xx_common.c | 112 +++++++++++++++++++++++--- include/asm-powerpc/mpc52xx.h | 7 ++ 4 files changed, 107 insertions(+), 15 deletions(-)
arch/powerpc/platforms/52xx/efika.c +2 -0
@@ -180,6 +180,8 @@ static void __init efika_setup_arch(void) {rtas_initialize (); +mpc52xx_setup_clocks (); +efika_pcisetup ();#ifdef CONFIG_PM
arch/powerpc/platforms/52xx/lite5200.c +1 -0
@@ -143,6 +143,7 @@ static void __init lite5200_setup_arch(void)lite5200_fix_port_config ();/* Some mpc5200 & mpc5200b related configuration */ +mpc5200_setup_clocks ();mpc5200_setup_xlb_arbiter ();/* Map wdt for mpc52xx_restart() */
arch/powerpc/platforms/52xx/mpc52xx_common.c +97 -15
138 lines not on this page · raw message
include/asm-powerpc/mpc52xx.h +7 -0
@@ -208,6 +208,7 @@ struct mpc52xx_cdm {u16 fd_counters;/* CDM + 0x12 reg4 byte2,3 */ u32 clk_enables;/* CDM + 0x14 reg5 */ +#define MPC52xx_CDM_CLK_ENABLES_OFF 0x14u8 osc_disable;/* CDM + 0x18 reg6 byte0 */ u8 reserved0[3 ];/* CDM + 0x19 reg6 byte1,2,3 */
@@ -228,15 +229,19 @@ struct mpc52xx_cdm {u16 reserved4;/* CDM + 0x28 reg10 byte0,1 */ u16 mclken_div_psc1;/* CDM + 0x2a reg10 byte2,3 */ +#define MPC52xx_CDM_MCLKEN_DIV_PSC1_OFF 0x2au16 reserved5;/* CDM + 0x2c reg11 byte0,1 */ u16 mclken_div_psc2;/* CDM + 0x2e reg11 byte2,3 */ +#define MPC52xx_CDM_MCLKEN_DIV_PSC2_OFF 0x2eu16 reserved6;/* CDM + 0x30 reg12 byte0,1 */ u16 mclken_div_psc3;/* CDM + 0x32 reg12 byte2,3 */ +#define MPC52xx_CDM_MCLKEN_DIV_PSC3_OFF 0x32u16 reserved7;/* CDM + 0x34 reg13 byte0,1 */ u16 mclken_div_psc6;/* CDM + 0x36 reg13 byte2,3 */ +#define MPC52xx_CDM_MCLKEN_DIV_PSC6_OFF 0x36 };#endif /* __ASSEMBLY__ */
@@ -251,6 +256,8 @@ struct mpc52xx_cdm {extern void __iomem *mpc52xx_find_and_map (const char *);extern void __iomem *mpc52xx_find_and_map_path (const char *path);extern unsigned int mpc52xx_find_ipb_freq (struct device_node *node); +extern int mpc52xx_cdm_set_psc_clk (int psc,u32 freq_hz); +extern void mpc5200_setup_clocks (void );extern void mpc5200_setup_xlb_arbiter (void );extern void mpc52xx_declare_of_platform_devices (void );
PATCH 2/2 mpc5200: psc-spi driver must not touch port_config or cdm registers
In reply to Grant LikelyFrom: Grant Likely <[email protected]>
port_config and the cdm are the responsibility of firmware; and if firmware doesn't set it up correctly, it should be fixed up by platform code on a per-board basis because it's a property of the board.
Drivers should never touch these registers.
---
drivers/spi/mpc52xx_psc_spi.c | 84 ++++------------------------------------- 1 files changed, 8 insertions(+), 76 deletions(-)
drivers/spi/mpc52xx_psc_spi.c +8 -76
@@ -328,77 +328,15 @@ static void mpc52xx_psc_spi_cleanup(struct spi_device *spi)kfree (spi->controller_state); } -static int mpc52xx_psc_spi_port_config (int psc_id,struct mpc52xx_psc_spi *mps) +static int mpc52xx_psc_spi_config (int psc_id,struct mpc52xx_psc_spi *mps) { -struct mpc52xx_cdm __iomem *cdm; -struct mpc52xx_gpio __iomem *gpio;struct mpc52xx_psc __iomem *psc = mps->psc; -u32 ul; -u32 mclken_div; -int ret =0 ; +int rc; -#if defined(CONFIG_PPC_MERGE ) - cdm =mpc52xx_find_and_map ("mpc5200-cdm" ); - gpio =mpc52xx_find_and_map ("mpc5200-gpio" ); -#else - cdm =ioremap (MPC52xx_PA (MPC52xx_CDM_OFFSET), MPC52xx_CDM_SIZE); - gpio =ioremap (MPC52xx_PA (MPC52xx_GPIO_OFFSET), MPC52xx_GPIO_SIZE); -#endif -if (!cdm || !gpio) { -printk (KERN_ERR "Error mapping CDM/GPIO\n" ); - ret = -EFAULT ; - goto unmap_regs; - } - -/* default sysclk is 512MHz */ - mclken_div =0x8000 | - (((mps->sysclk ? mps->sysclk :512000000 ) /MCLK ) &0x1FF ); - -switch (psc_id) { -case 1 : - ul =in_be32 (&gpio->port_config); - ul &=0xFFFFFFF8 ; - ul |=0x00000006 ; -out_be32 (&gpio->port_config, ul); -out_be16 (&cdm->mclken_div_psc1, mclken_div); - ul =in_be32 (&cdm->clk_enables); - ul |=0x00000020 ; -out_be32 (&cdm->clk_enables, ul); -break ; -case 2 : - ul =in_be32 (&gpio->port_config); - ul &=0xFFFFFF8F ; - ul |=0x00000060 ; -out_be32 (&gpio->port_config, ul); -out_be16 (&cdm->mclken_div_psc2, mclken_div); - ul =in_be32 (&cdm->clk_enables); - ul |=0x00000040 ; -out_be32 (&cdm->clk_enables, ul); -break ; -case 3 : - ul =in_be32 (&gpio->port_config); - ul &=0xFFFFF0FF ; - ul |=0x00000600 ; -out_be32 (&gpio->port_config, ul); -out_be16 (&cdm->mclken_div_psc3, mclken_div); - ul =in_be32 (&cdm->clk_enables); - ul |=0x00000080 ; -out_be32 (&cdm->clk_enables, ul); -break ; -case 6 : - ul =in_be32 (&gpio->port_config); - ul &=0xFF8FFFFF ; - ul |=0x00700000 ; -out_be32 (&gpio->port_config, ul); -out_be16 (&cdm->mclken_div_psc6, mclken_div); - ul =in_be32 (&cdm->clk_enables); - ul |=0x00000010 ; -out_be32 (&cdm->clk_enables, ul); -break ; -default : - ret = -EINVAL ; - goto unmap_regs; - } +/* Setup a desirable MCLK */ + rc =mpc52xx_cdm_set_psc_clk (psc_id,MCLK ); +if (rc) +return rc;/* Reset the PSC into a known state */ out_8 (&psc->command, MPC52xx_PSC_RST_RX);
@@ -422,13 +360,7 @@ static int mpc52xx_psc_spi_port_config(int psc_id, struct mpc52xx_psc_spi *mps) mps->bits_per_word =8 ; -unmap_regs: -if (cdm) -iounmap (cdm); -if (gpio) -iounmap (gpio); - -return ret; +return 0 ; }static irqreturn_t mpc52xx_psc_spi_isr (int irq,void *dev_id)
@@ -493,7 +425,7 @@ static int __init mpc52xx_psc_spi_do_probe(struct device *dev, u32 regaddr,if (ret) goto free_master; - ret =mpc52xx_psc_spi_port_config (master->bus_num, mps); + ret =mpc52xx_psc_spi_config (master->bus_num-1 , mps);if (ret <0 ) goto free_irq;
cover mpc52xx: stop drivers from accessing clock config directly
Domen,
Here's a real solution to the problem. I've somewhat tested this on the lite5200b. Can you give it a spin on efika and see if SPI still works for you?
Thanks,
g.
--
Grant Likely, B.Sc. P.Eng.
Secret Lab Technologies Ltd.
Quoted 5 lines · Grant Likely
Domen,
Here's a real solution to the problem. I've somewhat tested this on the lite5200b. Can you give it a spin on efika and see if SPI still works for you?
My test case was lite5200b too, I don't think I ever tried SPI on efika.
(Are even the right pins on irda connector, or is a necessary line missing?)
Domen
Quoted 7 lines
Thanks,
g.--
Grant Likely, B.Sc. P.Eng.
Secret Lab Technologies Ltd.
Signature · 5 lines
Domen Puncer | Research & Development ............................................................................................. Telargo d.o.o. | Zagrebška cesta 20 | 2000 Maribor | Slovenia ............................................................................................. www.telargo.com
Quoted 11 lines · Domen Puncer
Quoted 5 lines · Grant Likely
Domen,
Here's a real solution to the problem. I've somewhat tested this on the lite5200b. Can you give it a spin on efika and see if SPI still works for you?
My test case was lite5200b too, I don't think I ever tried SPI on efika.
(Are even the right pins on irda connector, or is a necessary line missing?)
Hmm, I guess that's right. Can you at least make sure it still boots on Efika? Some of the clock detection stuff has changed so I want to make sure it still boots.
Are you setup to do your SPI test easily on you lite5200b? When I say "somewhat" tested; I mean I probed the driver and it didn't crash. :-) I haven't tried to run traffic over it.
Can you check that on your system? If not, can you email me what setup/programs you used for testing? I know very little about the SPI infrastructure.
Thanks,
g.
Signature · 4 lines
Grant Likely, B.Sc., P.Eng. Secret Lab Technologies Ltd. [email protected] (403) 399-0195
Quoted 8 lines · Grant Likely
Quoted 7 lines · Domen Puncer
Quoted 5 lines · Grant Likely
Domen,
Here's a real solution to the problem. I've somewhat tested this on the lite5200b. Can you give it a spin on efika and see if SPI still works for you?
Quoted 8 lines
Quoted 4 lines
My test case was lite5200b too, I don't think I ever tried SPI on efika.
(Are even the right pins on irda connector, or is a necessary line missing?)Hmm, I guess that's right. Can you at least make sure it still boots on Efika? Some of the clock detection stuff has changed so I want to make sure it still boots.
OK. I'll do that tomorrow.
Quoted 4 lines
Are you setup to do your SPI test easily on you lite5200b? When I say "somewhat" tested; I mean I probed the driver and it didn't crash. :-) I haven't tried to run traffic over it.
Sorry, lite5200b is resting these days. :-(
Quoted 4 lines
Can you check that on your system? If not, can you email me what setup/programs you used for testing? I know very little about the SPI infrastructure.
For userspace part I used something like: Documentation/spi/spidev And for kernel the attached, to fill get binded to spidev driver.
Domen
Quoted 9 lines
Thanks,
g.Signature · 4 lines
Grant Likely, B.Sc., P.Eng. Secret Lab Technologies Ltd. [email protected] (403) 399-0195
Signature · 5 lines
Domen Puncer | Research & Development ............................................................................................. Telargo d.o.o. | Zagrebška cesta 20 | 2000 Maribor | Slovenia ............................................................................................. www.telargo.com
--- drivers/spi/Makefile | 1 + drivers/spi/spi_test_devices.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+)
drivers/spi/Makefile +1 -0
@@ -35,3 +35,4 @@ obj-$(CONFIG_SPI_SPIDEV) += spidev.o # SPI slave drivers (protocol for that link) # ... add above this line ... +obj-m += spi_test_devices.o
drivers/spi/spi_test_devices.c new file +38 -0
@@ -0,0 +1,38 @@ +#include <linux/module.h> +#include <linux/device.h> +#include <linux/spi/spi.h> + +static struct spi_board_info spi_info[7 ]; +static struct spi_device *spidev[7 ]; +static int testdev_init (void ) +{ +struct spi_board_info *info; +int i; + +for (i=0 ; i<7 ; i++) { +struct spi_master *master; + + info = &spi_info[i]; +//info->max_speed_hz = 2*1000000; + info->max_speed_hz =100000 ; +//info->max_speed_hz = 1*1000000; +strcpy (info->modalias,"spidev" ); + + master =spi_busnum_to_master (i); +if (master) + spidev[i] =spi_new_device (master, info); + } +return 0 ; +} + +static void testdev_exit (void ) +{ +/* there is no _remove? */ +/*for (i=0; i<7; i++) { +}*/ +} + +module_init (testdev_init); +module_exit (testdev_exit); + +MODULE_LICENSE ("GPL" );
Re: [PATCH 1/2] mpc52xx: add cdm (clock module) helper function for PSCs
In reply to Grant LikelyQuoted 2 lines · On Wed, 24 Oct 2007 12:24:26 -0600 Grant Likely <[email protected]>…
+static
spinlock_tmpc52xx_cdm_lock=SPIN_LOCK_UNLOCKED;
static DEFINE_SPINLOCK(mpc52xx_cdm_lock);
Signature · 3 lines
Cheers, Stephen Rothwell [email protected] http://www.canb.auug.org.au/~sfr/
Quoted 8 lines · Grant Likely
Quoted 7 lines · Domen Puncer
Quoted 5 lines · Grant Likely
Domen,
Here's a real solution to the problem. I've somewhat tested this on the lite5200b. Can you give it a spin on efika and see if SPI still works for you?
Quoted 8 lines
Quoted 4 lines
My test case was lite5200b too, I don't think I ever tried SPI on efika.
(Are even the right pins on irda connector, or is a necessary line missing?)Hmm, I guess that's right. Can you at least make sure it still boots on Efika? Some of the clock detection stuff has changed so I want to make sure it still boots.
OK, with the following patch it compiles and boots. I don't have any psc configured as spi in device tree though.
--- arch/powerpc/platforms/52xx/efika.c | 2 +- 1 files changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/platforms/52xx/efika.c +1 -1
@@ -180,7 +180,7 @@ static void __init efika_setup_arch(void {rtas_initialize (); -mpc52xx_setup_clocks (); +mpc5200_setup_clocks ();efika_pcisetup ();