* [PATCH 2/7] marvell-ccic: add clock tree support for marvell-ccic driver
@ 2013-06-04 5:42 lbyang
2013-06-21 17:02 ` Jonathan Corbet
0 siblings, 1 reply; 3+ messages in thread
From: lbyang @ 2013-06-04 5:42 UTC (permalink / raw)
To: corbet, g.liakhovetski, mchehab; +Cc: linux-media, lbyang, albert.v.wang
From: Libin Yang <lbyang@marvell.com>
This patch adds the clock tree support for marvell-ccic.
Signed-off-by: Libin Yang <lbyang@marvell.com>
Signed-off-by: Albert Wang <twang13@marvell.com>
Acked-by: Jonathan Corbet <corbet@lwn.net>
---
drivers/media/platform/marvell-ccic/mcam-core.h | 5 +++
drivers/media/platform/marvell-ccic/mmp-driver.c | 48 ++++++++++++++++++++++
2 files changed, 53 insertions(+)
diff --git a/drivers/media/platform/marvell-ccic/mcam-core.h b/drivers/media/platform/marvell-ccic/mcam-core.h
index be271b3..c506cd3 100644
--- a/drivers/media/platform/marvell-ccic/mcam-core.h
+++ b/drivers/media/platform/marvell-ccic/mcam-core.h
@@ -83,6 +83,8 @@ struct mcam_frame_state {
unsigned int delivered;
};
+#define NR_MCAM_CLK 3
+
/*
* A description of one of our devices.
* Locking: controlled by s_mutex. Certain fields, however, require
@@ -113,6 +115,9 @@ struct mcam_camera {
bool mipi_enabled;
int lane; /* lane number */
+ /* clock tree support */
+ struct clk *clk[NR_MCAM_CLK];
+
/*
* Callbacks from the core to the platform code.
*/
diff --git a/drivers/media/platform/marvell-ccic/mmp-driver.c b/drivers/media/platform/marvell-ccic/mmp-driver.c
index 3dad182..233d0ff 100644
--- a/drivers/media/platform/marvell-ccic/mmp-driver.c
+++ b/drivers/media/platform/marvell-ccic/mmp-driver.c
@@ -35,6 +35,8 @@ MODULE_ALIAS("platform:mmp-camera");
MODULE_AUTHOR("Jonathan Corbet <corbet@lwn.net>");
MODULE_LICENSE("GPL");
+static char *mcam_clks[] = {"CCICAXICLK", "CCICFUNCLK", "CCICPHYCLK"};
+
struct mmp_camera {
void *power_regs;
struct platform_device *pdev;
@@ -105,6 +107,26 @@ static struct mmp_camera *mmpcam_find_device(struct platform_device *pdev)
#define REG_CCIC_DCGCR 0x28 /* CCIC dyn clock gate ctrl reg */
#define REG_CCIC_CRCR 0x50 /* CCIC clk reset ctrl reg */
+static void mcam_clk_enable(struct mcam_camera *mcam)
+{
+ unsigned int i;
+
+ for (i = 0; i < NR_MCAM_CLK; i++) {
+ if (!IS_ERR_OR_NULL(mcam->clk[i]))
+ clk_prepare_enable(mcam->clk[i]);
+ }
+}
+
+static void mcam_clk_disable(struct mcam_camera *mcam)
+{
+ int i;
+
+ for (i = NR_MCAM_CLK - 1; i >= 0; i--) {
+ if (!IS_ERR_OR_NULL(mcam->clk[i]))
+ clk_disable_unprepare(mcam->clk[i]);
+ }
+}
+
/*
* Power control.
*/
@@ -135,11 +157,15 @@ static int mmpcam_power_up(struct mcam_camera *mcam)
mdelay(5);
gpio_set_value(pdata->sensor_reset_gpio, 1); /* reset is active low */
mdelay(5);
+
+ mcam_clk_enable(mcam);
+
if (mcam->bus_type == V4L2_MBUS_CSI2 && IS_ERR(cam->mipi_clk)) {
cam->mipi_clk = devm_clk_get(mcam->dev, "mipi");
if ((IS_ERR(cam->mipi_clk) && mcam->dphy[2] == 0))
return PTR_ERR(cam->mipi_clk);
}
+
return 0;
}
@@ -163,6 +189,8 @@ static void mmpcam_power_down(struct mcam_camera *mcam)
devm_clk_put(mcam->dev, cam->mipi_clk);
cam->mipi_clk = ERR_PTR(-EINVAL);
}
+
+ mcam_clk_disable(mcam);
}
/*
@@ -271,6 +299,23 @@ static irqreturn_t mmpcam_irq(int irq, void *data)
return IRQ_RETVAL(handled);
}
+static int mcam_init_clk(struct mcam_camera *mcam,
+ struct mmp_camera_platform_data *pdata)
+{
+ unsigned int i;
+
+ for (i = 0; i < NR_MCAM_CLK; i++) {
+ if (mcam_clks[i] != NULL) {
+ mcam->clk[i] = devm_clk_get(mcam->dev, mcam_clks[i]);
+ if (IS_ERR(mcam->clk[i])) {
+ dev_err(mcam->dev, "Could not get clk: %s\n",
+ mcam_clks[i]);
+ return PTR_ERR(mcam->clk[i]);
+ }
+ }
+ }
+ return 0;
+}
static int mmpcam_probe(struct platform_device *pdev)
{
@@ -338,6 +383,9 @@ static int mmpcam_probe(struct platform_device *pdev)
ret = -ENODEV;
goto out_unmap1;
}
+
+ mcam_init_clk(mcam, pdata);
+
/*
* Find the i2c adapter. This assumes, of course, that the
* i2c bus is already up and functioning.
--
1.7.9.5
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 2/7] marvell-ccic: add clock tree support for marvell-ccic driver
2013-06-04 5:42 [PATCH 2/7] marvell-ccic: add clock tree support for marvell-ccic driver lbyang
@ 2013-06-21 17:02 ` Jonathan Corbet
2013-06-25 7:33 ` Libin Yang
0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Corbet @ 2013-06-21 17:02 UTC (permalink / raw)
To: lbyang; +Cc: g.liakhovetski, mchehab, linux-media, albert.v.wang
On Tue, 4 Jun 2013 13:42:44 +0800
lbyang <lbyang@marvell.com> wrote:
> +static void mcam_clk_enable(struct mcam_camera *mcam)
> +{
> + unsigned int i;
> +
> + for (i = 0; i < NR_MCAM_CLK; i++) {
> + if (!IS_ERR_OR_NULL(mcam->clk[i]))
> + clk_prepare_enable(mcam->clk[i]);
> + }
> +}
It seems I already acked this patch, and I won't take that back. I
will point out, though, that IS_ERR_OR_NULL has become a sort of
lightning rod and that its use is probably best avoided.
http://lists.infradead.org/pipermail/linux-arm-kernel/2013-January/140543.html
This relates to the use of ERR_PTR with that particular pointer value;
I still think just using NULL is better, but maybe I'm missing
something.
jon
^ permalink raw reply [flat|nested] 3+ messages in thread
* RE: [PATCH 2/7] marvell-ccic: add clock tree support for marvell-ccic driver
2013-06-21 17:02 ` Jonathan Corbet
@ 2013-06-25 7:33 ` Libin Yang
0 siblings, 0 replies; 3+ messages in thread
From: Libin Yang @ 2013-06-25 7:33 UTC (permalink / raw)
To: Jonathan Corbet; +Cc: g.liakhovetski, mchehab, linux-media, albert.v.wang
Hi Jonathan,
Do you mean using IS_ERR() here directly? I think it should be OK. I will change to IS_ERR() in next version.
Regards,
Libin
>-----Original Message-----
>From: Jonathan Corbet [mailto:corbet@lwn.net]
>Sent: Saturday, June 22, 2013 1:02 AM
>To: Libin Yang
>Cc: g.liakhovetski@gmx.de; mchehab@redhat.com;
>linux-media@vger.kernel.org; albert.v.wang@gmail.com
>Subject: Re: [PATCH 2/7] marvell-ccic: add clock tree support
>for marvell-ccic driver
>
>On Tue, 4 Jun 2013 13:42:44 +0800
>lbyang <lbyang@marvell.com> wrote:
>
>> +static void mcam_clk_enable(struct mcam_camera *mcam) {
>> + unsigned int i;
>> +
>> + for (i = 0; i < NR_MCAM_CLK; i++) {
>> + if (!IS_ERR_OR_NULL(mcam->clk[i]))
>> + clk_prepare_enable(mcam->clk[i]);
>> + }
>> +}
>
>It seems I already acked this patch, and I won't take that
>back. I will point out, though, that IS_ERR_OR_NULL has
>become a sort of lightning rod and that its use is probably
>best avoided.
>
>
>http://lists.infradead.org/pipermail/linux-arm-kernel/2013-Janu
>ary/140543.html
>
>This relates to the use of ERR_PTR with that particular
>pointer value; I still think just using NULL is better, but
>maybe I'm missing something.
>
>jon
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-06-25 7:36 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-04 5:42 [PATCH 2/7] marvell-ccic: add clock tree support for marvell-ccic driver lbyang
2013-06-21 17:02 ` Jonathan Corbet
2013-06-25 7:33 ` Libin Yang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).