From e258acfc999e2a8a615c26ba43c5ec09b079e4d2 Mon Sep 17 00:00:00 2001 From: Imre Deak Date: Wed, 14 Jun 2006 20:42:47 +0300 Subject: [PATCH] ARM: OMAP: McSPI: handle clock enable / disable in omap2_mcspi Enable / disable the mcspi_ick and mcspi_fck clocks in omap2_mcspi_probe and omap2_mcspi_remove respectively. Drop the ref count on the class device in omap2_mcspi_remove. Change the clock names for mcspi_ick[123] and mcspi_fck[123] to mcspi_ick and mcspi_fck, use instead the clk.id field for the bus id. Signed-off-by: Imre Deak Signed-off-by: Juha Yrjola --- arch/arm/mach-omap2/clock.h | 18 ++++++++++------ drivers/spi/omap2_mcspi.c | 42 ++++++++++++++++++++++++++++++++----- 2 files changed, 49 insertions(+), 11 deletions(-) diff --git a/arch/arm/mach-omap2/clock.h b/arch/arm/mach-omap2/clock.h index 2781dfbc516..971743a090a 100644 --- a/arch/arm/mach-omap2/clock.h +++ b/arch/arm/mach-omap2/clock.h @@ -1368,7 +1368,8 @@ static struct clk mcbsp5_fck = { }; static struct clk mcspi1_ick = { - .name = "mcspi1_ick", + .name = "mcspi_ick", + .id = 1, .parent = &l4_ck, .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X, .enable_reg = (void __iomem *)&CM_ICLKEN1_CORE, @@ -1377,7 +1378,8 @@ static struct clk mcspi1_ick = { }; static struct clk mcspi1_fck = { - .name = "mcspi1_fck", + .name = "mcspi_fck", + .id = 1, .parent = &func_48m_ck, .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X, .enable_reg = (void __iomem *)&CM_FCLKEN1_CORE, @@ -1386,7 +1388,8 @@ static struct clk mcspi1_fck = { }; static struct clk mcspi2_ick = { - .name = "mcspi2_ick", + .name = "mcspi_ick", + .id = 2, .parent = &l4_ck, .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X, .enable_reg = (void __iomem *)&CM_ICLKEN1_CORE, @@ -1395,7 +1398,8 @@ static struct clk mcspi2_ick = { }; static struct clk mcspi2_fck = { - .name = "mcspi2_fck", + .name = "mcspi_fck", + .id = 2, .parent = &func_48m_ck, .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X, .enable_reg = (void __iomem *)&CM_FCLKEN1_CORE, @@ -1404,7 +1408,8 @@ static struct clk mcspi2_fck = { }; static struct clk mcspi3_ick = { - .name = "mcspi3_ick", + .name = "mcspi_ick", + .id = 3, .parent = &l4_ck, .flags = CLOCK_IN_OMAP243X, .enable_reg = (void __iomem *)&CM_ICLKEN2_CORE, @@ -1413,7 +1418,8 @@ static struct clk mcspi3_ick = { }; static struct clk mcspi3_fck = { - .name = "mcspi3_fck", + .name = "mcspi_fck", + .id = 3, .parent = &func_48m_ck, .flags = CLOCK_IN_OMAP243X, .enable_reg = (void __iomem *)&CM_FCLKEN2_CORE, diff --git a/drivers/spi/omap2_mcspi.c b/drivers/spi/omap2_mcspi.c index 8b70d3821fa..336f5c58a56 100644 --- a/drivers/spi/omap2_mcspi.c +++ b/drivers/spi/omap2_mcspi.c @@ -28,6 +28,8 @@ #include #include #include +#include +#include #include @@ -84,6 +86,8 @@ struct omap2_mcspi { spinlock_t lock; struct list_head msg_queue; struct spi_master *master; + struct clk *ick; + struct clk *fck; }; struct omap2_mcspi_cs { @@ -456,7 +460,7 @@ static int __devinit omap2_mcspi_probe(struct platform_device *pdev) return -EINVAL; master = spi_alloc_master(&pdev->dev, sizeof *mcspi); - if (!master) { + if (master == NULL) { dev_err(&pdev->dev, "master allocation failed\n"); return -ENOMEM; } @@ -485,28 +489,56 @@ static int __devinit omap2_mcspi_probe(struct platform_device *pdev) spin_lock_init(&mcspi->lock); INIT_LIST_HEAD(&mcspi->msg_queue); + mcspi->ick = clk_get(&pdev->dev, "mcspi_ick"); + if (IS_ERR(mcspi->ick)) { + dev_err(&pdev->dev, "can't get mcspi_ick\n"); + status = PTR_ERR(mcspi->ick); + goto err1; + } + clk_enable(mcspi->ick); + mcspi->fck = clk_get(&pdev->dev, "mcspi_fck"); + if (IS_ERR(mcspi->fck)) { + dev_err(&pdev->dev, "can't get mcspi_fck\n"); + status = PTR_ERR(mcspi->fck); + goto err2; + } + clk_enable(mcspi->fck); + if (omap2_mcspi_reset(master) < 0) - goto err1; + goto err3; status = spi_register_master(master); if (status < 0) - goto err1; + goto err3; return status; - err1: +err3: + clk_disable(mcspi->fck); + clk_put(mcspi->fck); +err2: + clk_disable(mcspi->ick); + clk_put(mcspi->ick); +err1: class_device_put(&master->cdev); - err0: +err0: return status; } static int __devexit omap2_mcspi_remove(struct platform_device *pdev) { struct spi_master *master; + struct omap2_mcspi *mcspi; master = dev_get_drvdata(&pdev->dev); spi_unregister_master(master); + mcspi = class_get_devdata(&master->cdev); + clk_disable(mcspi->fck); + clk_put(mcspi->fck); + clk_disable(mcspi->ick); + clk_put(mcspi->ick); + class_device_put(&master->cdev); return 0; } -- 2.41.1