From patchwork Thu Jun 15 22:52:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janusz Krzysztofik X-Patchwork-Id: 9790367 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1AFAB60325 for ; Thu, 15 Jun 2017 22:55:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 02D2928066 for ; Thu, 15 Jun 2017 22:55:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EA129283E8; Thu, 15 Jun 2017 22:55:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5ADCD28066 for ; Thu, 15 Jun 2017 22:55:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751901AbdFOWzr (ORCPT ); Thu, 15 Jun 2017 18:55:47 -0400 Received: from mail-lf0-f67.google.com ([209.85.215.67]:35387 "EHLO mail-lf0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751883AbdFOWzq (ORCPT ); Thu, 15 Jun 2017 18:55:46 -0400 Received: by mail-lf0-f67.google.com with SMTP id v20so2450309lfa.2 for ; Thu, 15 Jun 2017 15:55:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=YpLAr2jT+Ho+i9DJ5kCB+t02nNET2bJ3cOiv3lFwvlE=; b=I+UoBAVe4CJHj+RoohvI5jYQmiET1Muo7XfW6+AdnbjJ2QnaZWJSeF4QjNyx+rHuxX 1EtipJxfAXVOAEkujZ48GoHwHjtiJi2GukpXN7JwEWEcLs4ZIuZNAQPA1uYcyAQ8eaTw 8Sw7R8uEIWQIrmdFHgCxN+DGzXHVXV0Cau5RTj+qU5rxqiRND+beG1mj+ZhL8HUfEMfA 4L9VZSFbddv1jXkVFvYs30zHx8DvDidmETrSWzobR80gMmVf/oHlL5vyvspVLfUFfQrr EZ/dKSANNrSNUzuSHpodE3e2j2yf6v2QkPvj4fmBqDKBz/mi/qE6OvP24sVSkEPhRZ6J Rkbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=YpLAr2jT+Ho+i9DJ5kCB+t02nNET2bJ3cOiv3lFwvlE=; b=dZUCWaPi3Rv8x1WV6hncp85a0coqJbrY/6DcUluF7VzbkTQRVaL4olYOleYfF8jEmP YZtf00xeNoLk5Fb6rZkQz7auLdNpiB5roeqy0qI/nDzEksAM4iuVR0kvejdFvl/EOECz uTdppSqibwIsvfWfm60QlrjK7C/cilyTZPM/BK0x3UwbqGCGMM7V2z6M7Z7tX0cVclNT IPQj7XyFarfri0uH3Vkd6ffdRTN63eC5YYf3USQFQ9Razv82drchlBbJEL1rI8L3Dy7g ihFcPqoDZTy1DAdM+k7YVlP17CCFgi8KfsrRLB+DQikUadCTK3S9xLy4RaFAP388r0c2 Ku+A== X-Gm-Message-State: AKS2vOw2RsK7KNLz8Gw6B6iWTM1n4njOY7PxB49w/oE3k6ZNECh09bCN CyWjKy1CeJO9PD1YmlM= X-Received: by 10.25.158.78 with SMTP id h75mr2241758lfe.178.1497567344539; Thu, 15 Jun 2017 15:55:44 -0700 (PDT) Received: from localhost.localdomain (apn-31-0-42-105.dynamic.gprs.plus.pl. [31.0.42.105]) by smtp.gmail.com with ESMTPSA id f83sm126715lfk.52.2017.06.15.15.55.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 15 Jun 2017 15:55:43 -0700 (PDT) From: Janusz Krzysztofik To: Guennadi Liakhovetski Cc: Mauro Carvalho Chehab , Hans Verkuil , linux-media@vger.kernel.org, Janusz Krzysztofik Subject: [PATCH] [media] ov6650: convert to standalone v4l2 subdevice Date: Fri, 16 Jun 2017 00:52:43 +0200 Message-Id: <20170615225243.12528-1-jmkrzyszt@gmail.com> X-Mailer: git-send-email 2.10.2 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Remove the soc_camera dependencies. Lost features, fortunately not used or not critical on test platform: - soc_camera power on/off callback - replaced with clock enable/disable only, no support for platform provided regulators nor power callback, - soc_camera sense request - replaced with arbitrarily selected default master clock rate and pixel clock limit, no support for platform requested values, - soc_camera board flags - no support for platform requested mbus config tweaks. Created against linux-4.12-rc2. Tested on Amstrad Delta with now out of tree but still locally maintained omap1_camera host driver. Signed-off-by: Janusz Krzysztofik --- drivers/media/i2c/soc_camera/ov6650.c | 75 ++++++++++------------------------- 1 file changed, 22 insertions(+), 53 deletions(-) diff --git a/drivers/media/i2c/soc_camera/ov6650.c b/drivers/media/i2c/soc_camera/ov6650.c index dbd6d92..20defcb88 100644 --- a/drivers/media/i2c/soc_camera/ov6650.c +++ b/drivers/media/i2c/soc_camera/ov6650.c @@ -31,9 +31,9 @@ #include #include -#include #include #include +#include /* Register definitions */ #define REG_GAIN 0x00 /* range 00 - 3F */ @@ -426,10 +426,15 @@ static int ov6650_set_register(struct v4l2_subdev *sd, static int ov6650_s_power(struct v4l2_subdev *sd, int on) { struct i2c_client *client = v4l2_get_subdevdata(sd); - struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client); struct ov6650 *priv = to_ov6650(client); + int ret = 0; - return soc_camera_set_power(&client->dev, ssdd, priv->clk, on); + if (on) + ret = v4l2_clk_enable(priv->clk); + else + v4l2_clk_disable(priv->clk); + + return ret; } static int ov6650_get_selection(struct v4l2_subdev *sd, @@ -471,14 +476,13 @@ static int ov6650_set_selection(struct v4l2_subdev *sd, sel->target != V4L2_SEL_TGT_CROP) return -EINVAL; - rect.left = ALIGN(rect.left, 2); - rect.width = ALIGN(rect.width, 2); - rect.top = ALIGN(rect.top, 2); - rect.height = ALIGN(rect.height, 2); - soc_camera_limit_side(&rect.left, &rect.width, - DEF_HSTRT << 1, 2, W_CIF); - soc_camera_limit_side(&rect.top, &rect.height, - DEF_VSTRT << 1, 2, H_CIF); + v4l_bound_align_image(&rect.width, 2, W_CIF, 1, + &rect.height, 2, H_CIF, 1, 0); + v4l_bound_align_image(&rect.left, DEF_HSTRT << 1, + (DEF_HSTRT << 1) + W_CIF - (__s32)rect.width, 1, + &rect.top, DEF_VSTRT << 1, + (DEF_VSTRT << 1) + H_CIF - (__s32)rect.height, 1, + 0); ret = ov6650_reg_write(client, REG_HSTRT, rect.left >> 1); if (!ret) { @@ -547,8 +551,6 @@ static u8 to_clkrc(struct v4l2_fract *timeperframe, static int ov6650_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf) { struct i2c_client *client = v4l2_get_subdevdata(sd); - struct soc_camera_device *icd = v4l2_get_subdev_hostdata(sd); - struct soc_camera_sense *sense = icd->sense; struct ov6650 *priv = to_ov6650(client); bool half_scale = !is_unscaled_ok(mf->width, mf->height, &priv->rect); struct v4l2_subdev_selection sel = { @@ -640,32 +642,10 @@ static int ov6650_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf) } priv->half_scale = half_scale; - if (sense) { - if (sense->master_clock == 8000000) { - dev_dbg(&client->dev, "8MHz input clock\n"); - clkrc = CLKRC_6MHz; - } else if (sense->master_clock == 12000000) { - dev_dbg(&client->dev, "12MHz input clock\n"); - clkrc = CLKRC_12MHz; - } else if (sense->master_clock == 16000000) { - dev_dbg(&client->dev, "16MHz input clock\n"); - clkrc = CLKRC_16MHz; - } else if (sense->master_clock == 24000000) { - dev_dbg(&client->dev, "24MHz input clock\n"); - clkrc = CLKRC_24MHz; - } else { - dev_err(&client->dev, - "unsupported input clock, check platform data\n"); - return -EINVAL; - } - mclk = sense->master_clock; - priv->pclk_limit = sense->pixel_clock_max; - } else { - clkrc = CLKRC_24MHz; - mclk = 24000000; - priv->pclk_limit = 0; - dev_dbg(&client->dev, "using default 24MHz input clock\n"); - } + clkrc = CLKRC_12MHz; + mclk = 12000000; + priv->pclk_limit = 1334000; + dev_dbg(&client->dev, "using 12MHz input clock\n"); clkrc |= to_clkrc(&priv->tpf, priv->pclk_limit, priv->pclk_max); @@ -897,8 +877,6 @@ static const struct v4l2_subdev_core_ops ov6650_core_ops = { static int ov6650_g_mbus_config(struct v4l2_subdev *sd, struct v4l2_mbus_config *cfg) { - struct i2c_client *client = v4l2_get_subdevdata(sd); - struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client); cfg->flags = V4L2_MBUS_MASTER | V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_PCLK_SAMPLE_FALLING | @@ -906,7 +884,6 @@ static int ov6650_g_mbus_config(struct v4l2_subdev *sd, V4L2_MBUS_VSYNC_ACTIVE_HIGH | V4L2_MBUS_VSYNC_ACTIVE_LOW | V4L2_MBUS_DATA_ACTIVE_HIGH; cfg->type = V4L2_MBUS_PARALLEL; - cfg->flags = soc_camera_apply_board_flags(ssdd, cfg); return 0; } @@ -916,25 +893,23 @@ static int ov6650_s_mbus_config(struct v4l2_subdev *sd, const struct v4l2_mbus_config *cfg) { struct i2c_client *client = v4l2_get_subdevdata(sd); - struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client); - unsigned long flags = soc_camera_apply_board_flags(ssdd, cfg); int ret; - if (flags & V4L2_MBUS_PCLK_SAMPLE_RISING) + if (cfg->flags & V4L2_MBUS_PCLK_SAMPLE_RISING) ret = ov6650_reg_rmw(client, REG_COMJ, COMJ_PCLK_RISING, 0); else ret = ov6650_reg_rmw(client, REG_COMJ, 0, COMJ_PCLK_RISING); if (ret) return ret; - if (flags & V4L2_MBUS_HSYNC_ACTIVE_LOW) + if (cfg->flags & V4L2_MBUS_HSYNC_ACTIVE_LOW) ret = ov6650_reg_rmw(client, REG_COMF, COMF_HREF_LOW, 0); else ret = ov6650_reg_rmw(client, REG_COMF, 0, COMF_HREF_LOW); if (ret) return ret; - if (flags & V4L2_MBUS_VSYNC_ACTIVE_HIGH) + if (cfg->flags & V4L2_MBUS_VSYNC_ACTIVE_HIGH) ret = ov6650_reg_rmw(client, REG_COMJ, COMJ_VSYNC_HIGH, 0); else ret = ov6650_reg_rmw(client, REG_COMJ, 0, COMJ_VSYNC_HIGH); @@ -971,14 +946,8 @@ static int ov6650_probe(struct i2c_client *client, const struct i2c_device_id *did) { struct ov6650 *priv; - struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client); int ret; - if (!ssdd) { - dev_err(&client->dev, "Missing platform_data for driver\n"); - return -EINVAL; - } - priv = devm_kzalloc(&client->dev, sizeof(*priv), GFP_KERNEL); if (!priv) { dev_err(&client->dev,