From patchwork Wed Jul 23 17:17:24 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guennadi Liakhovetski X-Patchwork-Id: 4612231 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 408FFC0514 for ; Wed, 23 Jul 2014 17:17:33 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 49FD7201C7 for ; Wed, 23 Jul 2014 17:17:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5FDFA201BB for ; Wed, 23 Jul 2014 17:17:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932798AbaGWRR3 (ORCPT ); Wed, 23 Jul 2014 13:17:29 -0400 Received: from mout.kundenserver.de ([212.227.126.187]:50519 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932580AbaGWRR2 (ORCPT ); Wed, 23 Jul 2014 13:17:28 -0400 Received: from axis700.grange (xdsl-85-197-61-39.netcologne.de [85.197.61.39]) by mrelayeu.kundenserver.de (node=mreue006) with ESMTP (Nemesis) id 0MLVSQ-1X9Rw70JFK-000f53; Wed, 23 Jul 2014 19:17:25 +0200 Received: by axis700.grange (Postfix, from userid 1000) id A913440BDB; Wed, 23 Jul 2014 19:17:24 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by axis700.grange (Postfix) with ESMTP id 9A85B40BD9; Wed, 23 Jul 2014 19:17:24 +0200 (CEST) Date: Wed, 23 Jul 2014 19:17:24 +0200 (CEST) From: Guennadi Liakhovetski X-X-Sender: lyakh@axis700.grange To: Robert Jarzmik cc: devicetree@vger.kernel.org, Mark Rutland , linux-media@vger.kernel.org Subject: [PATCH v4 1/2] media: soc_camera: pxa_camera device-tree support In-Reply-To: Message-ID: References: <1404051600-20838-1-git-send-email-robert.jarzmik@free.fr> MIME-Version: 1.0 X-Provags-ID: V02:K0:rxxVTbr0/E5+rcxXVy7S8Gje93GqsNfpXkudAhd/ZuW 4hVBSu3BZCPNdDs5kmL9Nibn5yN2WONSnCHczrPGepkJukVHNt szHqx0Y/ZyfSx1qBEY6CVK3Jw7Sv51lq8dqMQZyVIu6uBMacD6 Tg9F3eZ+NMFa8yHA3LxywkdWUPVghwz2bw5dh3CRUADxNeo0Uq lsj6cbf+WB+ECg18BF5e/Z5bOwgYTE9UkLyGcY9pzQY8XnwlvZ 84KWGIh0yyhaNR0pZ+vnO8t5gm6QtbQyEJCyE+m1senR/d191P au5uKigCR26hKRDJIXPvt7OO0eTZZs85D3LlYtSteU+3iFdQ4v GiDCsduXl+w5+g0csp4oUc54QOoJIB5LF5D59adlC/j2mrrDVx c/rg+sN0gZHZA== Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add device-tree support to pxa_camera host driver. Signed-off-by: Robert Jarzmik [g.liakhovetski@gmx.de: added of_node_put()] Signed-off-by: Guennadi Liakhovetski Tested-by: Robert Jarzmik --- Robert, could you review and test this version, please? Thanks Guennadi drivers/media/platform/soc_camera/pxa_camera.c | 81 +++++++++++++++++++++++++- 1 file changed, 79 insertions(+), 2 deletions(-) diff --git a/drivers/media/platform/soc_camera/pxa_camera.c b/drivers/media/platform/soc_camera/pxa_camera.c index d4df305..64dc80c 100644 --- a/drivers/media/platform/soc_camera/pxa_camera.c +++ b/drivers/media/platform/soc_camera/pxa_camera.c @@ -34,6 +34,7 @@ #include #include #include +#include #include @@ -1650,6 +1651,68 @@ static struct soc_camera_host_ops pxa_soc_camera_host_ops = { .set_bus_param = pxa_camera_set_bus_param, }; +static int pxa_camera_pdata_from_dt(struct device *dev, + struct pxa_camera_dev *pcdev) +{ + u32 mclk_rate; + struct device_node *np = dev->of_node; + struct v4l2_of_endpoint ep; + int err = of_property_read_u32(np, "clock-frequency", + &mclk_rate); + if (!err) { + pcdev->platform_flags |= PXA_CAMERA_MCLK_EN; + pcdev->mclk = mclk_rate; + } + + np = of_graph_get_next_endpoint(np, NULL); + if (!np) { + dev_err(dev, "could not find endpoint\n"); + return -EINVAL; + } + + err = v4l2_of_parse_endpoint(np, &ep); + if (err) { + dev_err(dev, "could not parse endpoint\n"); + goto out; + } + + switch (ep.bus.parallel.bus_width) { + case 4: + pcdev->platform_flags |= PXA_CAMERA_DATAWIDTH_4; + break; + case 5: + pcdev->platform_flags |= PXA_CAMERA_DATAWIDTH_5; + break; + case 8: + pcdev->platform_flags |= PXA_CAMERA_DATAWIDTH_8; + break; + case 9: + pcdev->platform_flags |= PXA_CAMERA_DATAWIDTH_9; + break; + case 10: + pcdev->platform_flags |= PXA_CAMERA_DATAWIDTH_10; + break; + default: + break; + }; + + if (ep.bus.parallel.flags & V4L2_MBUS_MASTER) + pcdev->platform_flags |= PXA_CAMERA_MASTER; + if (ep.bus.parallel.flags & V4L2_MBUS_HSYNC_ACTIVE_HIGH) + pcdev->platform_flags |= PXA_CAMERA_HSP; + if (ep.bus.parallel.flags & V4L2_MBUS_VSYNC_ACTIVE_HIGH) + pcdev->platform_flags |= PXA_CAMERA_VSP; + if (ep.bus.parallel.flags & V4L2_MBUS_PCLK_SAMPLE_RISING) + pcdev->platform_flags |= PXA_CAMERA_PCLK_EN | PXA_CAMERA_PCP; + if (ep.bus.parallel.flags & V4L2_MBUS_PCLK_SAMPLE_FALLING) + pcdev->platform_flags |= PXA_CAMERA_PCLK_EN; + +out: + of_node_put(np); + + return err; +} + static int pxa_camera_probe(struct platform_device *pdev) { struct pxa_camera_dev *pcdev; @@ -1676,7 +1739,15 @@ static int pxa_camera_probe(struct platform_device *pdev) pcdev->res = res; pcdev->pdata = pdev->dev.platform_data; - pcdev->platform_flags = pcdev->pdata->flags; + if (&pdev->dev.of_node && !pcdev->pdata) { + err = pxa_camera_pdata_from_dt(&pdev->dev, pcdev); + } else { + pcdev->platform_flags = pcdev->pdata->flags; + pcdev->mclk = pcdev->pdata->mclk_10khz * 10000; + } + if (err < 0) + return err; + if (!(pcdev->platform_flags & (PXA_CAMERA_DATAWIDTH_8 | PXA_CAMERA_DATAWIDTH_9 | PXA_CAMERA_DATAWIDTH_10))) { /* @@ -1693,7 +1764,6 @@ static int pxa_camera_probe(struct platform_device *pdev) pcdev->width_flags |= 1 << 8; if (pcdev->platform_flags & PXA_CAMERA_DATAWIDTH_10) pcdev->width_flags |= 1 << 9; - pcdev->mclk = pcdev->pdata->mclk_10khz * 10000; if (!pcdev->mclk) { dev_warn(&pdev->dev, "mclk == 0! Please, fix your platform data. " @@ -1799,10 +1869,17 @@ static const struct dev_pm_ops pxa_camera_pm = { .resume = pxa_camera_resume, }; +static const struct of_device_id pxa_camera_of_match[] = { + { .compatible = "marvell,pxa270-qci", }, + {}, +}; +MODULE_DEVICE_TABLE(of, pxa_camera_of_match); + static struct platform_driver pxa_camera_driver = { .driver = { .name = PXA_CAM_DRV_NAME, .pm = &pxa_camera_pm, + .of_match_table = of_match_ptr(pxa_camera_of_match), }, .probe = pxa_camera_probe, .remove = pxa_camera_remove,