[media] atmel-isi: add code to enable/disable ISI_MCK clock
authorJosh Wu <josh.wu@atmel.com>
Thu, 8 Dec 2011 10:18:49 +0000 (07:18 -0300)
committerMauro Carvalho Chehab <mchehab@redhat.com>
Fri, 6 Jan 2012 13:01:11 +0000 (11:01 -0200)
This patch
- add ISI_MCK clock enable/disable code.
- change field name in isi_platform_data structure

Signed-off-by: Josh Wu <josh.wu@atmel.com>
[g.liakhovetski@gmx.de: fix label names]
Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
Acked-by: Nicolas Ferre <nicolas.ferre@atmel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
drivers/media/video/atmel-isi.c
include/media/atmel-isi.h

index b25bd7bb01db802935a2fe9dd029739d1eb701cf..9fe4519176a4850ceecda1d29fb961eeb7b03fb2 100644 (file)
@@ -90,7 +90,10 @@ struct atmel_isi {
        struct isi_dma_desc             dma_desc[MAX_BUFFER_NUM];
 
        struct completion               complete;
+       /* ISI peripherial clock */
        struct clk                      *pclk;
+       /* ISI_MCK, feed to camera sensor to generate pixel clock */
+       struct clk                      *mck;
        unsigned int                    irq;
 
        struct isi_platform_data        *pdata;
@@ -766,6 +769,12 @@ static int isi_camera_add_device(struct soc_camera_device *icd)
        if (ret)
                return ret;
 
+       ret = clk_enable(isi->mck);
+       if (ret) {
+               clk_disable(isi->pclk);
+               return ret;
+       }
+
        isi->icd = icd;
        dev_dbg(icd->parent, "Atmel ISI Camera driver attached to camera %d\n",
                 icd->devnum);
@@ -779,6 +788,7 @@ static void isi_camera_remove_device(struct soc_camera_device *icd)
 
        BUG_ON(icd != isi->icd);
 
+       clk_disable(isi->mck);
        clk_disable(isi->pclk);
        isi->icd = NULL;
 
@@ -874,7 +884,7 @@ static int isi_camera_set_bus_param(struct soc_camera_device *icd)
 
        if (isi->pdata->has_emb_sync)
                cfg1 |= ISI_CFG1_EMB_SYNC;
-       if (isi->pdata->isi_full_mode)
+       if (isi->pdata->full_mode)
                cfg1 |= ISI_CFG1_FULL_MODE;
 
        isi_writel(isi, ISI_CTRL, ISI_CTRL_DIS);
@@ -912,6 +922,7 @@ static int __devexit atmel_isi_remove(struct platform_device *pdev)
                        isi->fb_descriptors_phys);
 
        iounmap(isi->regs);
+       clk_put(isi->mck);
        clk_put(isi->pclk);
        kfree(isi);
 
@@ -930,7 +941,7 @@ static int __devinit atmel_isi_probe(struct platform_device *pdev)
        struct isi_platform_data *pdata;
 
        pdata = dev->platform_data;
-       if (!pdata || !pdata->data_width_flags) {
+       if (!pdata || !pdata->data_width_flags || !pdata->mck_hz) {
                dev_err(&pdev->dev,
                        "No config available for Atmel ISI\n");
                return -EINVAL;
@@ -959,6 +970,19 @@ static int __devinit atmel_isi_probe(struct platform_device *pdev)
        INIT_LIST_HEAD(&isi->video_buffer_list);
        INIT_LIST_HEAD(&isi->dma_desc_head);
 
+       /* Get ISI_MCK, provided by programmable clock or external clock */
+       isi->mck = clk_get(dev, "isi_mck");
+       if (IS_ERR(isi->mck)) {
+               dev_err(dev, "Failed to get isi_mck\n");
+               ret = PTR_ERR(isi->mck);
+               goto err_clk_get;
+       }
+
+       /* Set ISI_MCK's frequency, it should be faster than pixel clock */
+       ret = clk_set_rate(isi->mck, pdata->mck_hz);
+       if (ret < 0)
+               goto err_set_mck_rate;
+
        isi->p_fb_descriptors = dma_alloc_coherent(&pdev->dev,
                                sizeof(struct fbd) * MAX_BUFFER_NUM,
                                &isi->fb_descriptors_phys,
@@ -1034,6 +1058,9 @@ err_alloc_ctx:
                        isi->p_fb_descriptors,
                        isi->fb_descriptors_phys);
 err_alloc_descriptors:
+err_set_mck_rate:
+       clk_put(isi->mck);
+err_clk_get:
        kfree(isi);
 err_alloc_isi:
        clk_put(pclk);
index 26cece5951218072e249327561ba5289c60575d7..656823075709d6728cc2b2ec182e4827d5b319f1 100644 (file)
@@ -110,10 +110,12 @@ struct isi_platform_data {
        u8 hsync_act_low;
        u8 vsync_act_low;
        u8 pclk_act_falling;
-       u8 isi_full_mode;
+       u8 full_mode;
        u32 data_width_flags;
        /* Using for ISI_CFG1 */
        u32 frate;
+       /* Using for ISI_MCK */
+       u32 mck_hz;
 };
 
 #endif /* __ATMEL_ISI_H__ */