From patchwork Fri Oct 19 15:50:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marco Felsch X-Patchwork-Id: 10649697 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 59B0C181D for ; Fri, 19 Oct 2018 15:50:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 48AB72849D for ; Fri, 19 Oct 2018 15:50:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 370F22624B; Fri, 19 Oct 2018 15:50:45 +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.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 89AD12624B for ; Fri, 19 Oct 2018 15:50:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727734AbeJSX5X (ORCPT ); Fri, 19 Oct 2018 19:57:23 -0400 Received: from metis.ext.pengutronix.de ([85.220.165.71]:36965 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727719AbeJSX5W (ORCPT ); Fri, 19 Oct 2018 19:57:22 -0400 Received: from dude.hi.pengutronix.de ([2001:67c:670:100:1d::7]) by metis.ext.pengutronix.de with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gDX2r-0005Fc-MG; Fri, 19 Oct 2018 17:50:37 +0200 Received: from mfe by dude.hi.pengutronix.de with local (Exim 4.91) (envelope-from ) id 1gDX2p-0000at-SL; Fri, 19 Oct 2018 17:50:35 +0200 From: Marco Felsch To: mchehab@kernel.org, sakari.ailus@linux.intel.com Cc: akinobu.mita@gmail.com, enrico.scholz@sigma-chemnitz.de, linux-media@vger.kernel.org, kernel@pengutronix.de, Michael Grzeschik Subject: [PATCH 4/4] media: mt9m111: allow to setup pixclk polarity Date: Fri, 19 Oct 2018 17:50:27 +0200 Message-Id: <20181019155027.28682-5-m.felsch@pengutronix.de> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181019155027.28682-1-m.felsch@pengutronix.de> References: <20181019155027.28682-1-m.felsch@pengutronix.de> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::7 X-SA-Exim-Mail-From: mfe@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-media@vger.kernel.org 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 From: Enrico Scholz The chip can be configured to output data transitions on the rising or falling edge of PIXCLK (Datasheet R58:1[9]), default is on the falling edge. Parsing the fw-node is made in a subfunction to bundle all (future) dt-parsing / fw-parsing stuff. Signed-off-by: Enrico Scholz (m.grzeschik@pengutronix.de: Fix inverting clock. INV_PIX_CLOCK bit is set per default. Set bit to 0 (enable mask bit without value) to enable falling edge sampling.) Signed-off-by: Michael Grzeschik (m.felsch@pengutronix.de: use fwnode helpers) (m.felsch@pengutronix.de: mv of parsing into own function) (m.felsch@pengutronix.de: adapt commit msg) Signed-off-by: Marco Felsch Reviewed-by: Philipp Zabel --- drivers/media/i2c/mt9m111.c | 52 ++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/drivers/media/i2c/mt9m111.c b/drivers/media/i2c/mt9m111.c index 13080c6c1ba3..5d45bc9ea0cb 100644 --- a/drivers/media/i2c/mt9m111.c +++ b/drivers/media/i2c/mt9m111.c @@ -15,12 +15,14 @@ #include #include #include +#include #include #include #include #include #include +#include /* * MT9M111, MT9M112 and MT9M131: @@ -236,6 +238,8 @@ struct mt9m111 { const struct mt9m111_datafmt *fmt; int lastpage; /* PageMap cache value */ bool is_streaming; + /* user point of view - 0: falling 1: rising edge */ + unsigned int pclk_sample:1; #ifdef CONFIG_MEDIA_CONTROLLER struct media_pad pad; #endif @@ -586,6 +590,10 @@ static int mt9m111_set_pixfmt(struct mt9m111 *mt9m111, return -EINVAL; } + /* receiver samples on falling edge, chip-hw default is rising */ + if (mt9m111->pclk_sample == 0) + mask_outfmt2 |= MT9M111_OUTFMT_INV_PIX_CLOCK; + ret = mt9m111_reg_mask(client, context_a.output_fmt_ctrl2, data_outfmt2, mask_outfmt2); if (!ret) @@ -1045,9 +1053,15 @@ static int mt9m111_s_stream(struct v4l2_subdev *sd, int enable) static int mt9m111_g_mbus_config(struct v4l2_subdev *sd, struct v4l2_mbus_config *cfg) { - cfg->flags = V4L2_MBUS_MASTER | V4L2_MBUS_PCLK_SAMPLE_RISING | + struct mt9m111 *mt9m111 = container_of(sd, struct mt9m111, subdev); + + cfg->flags = V4L2_MBUS_MASTER | V4L2_MBUS_HSYNC_ACTIVE_HIGH | V4L2_MBUS_VSYNC_ACTIVE_HIGH | V4L2_MBUS_DATA_ACTIVE_HIGH; + + cfg->flags |= mt9m111->pclk_sample ? V4L2_MBUS_PCLK_SAMPLE_FALLING : + V4L2_MBUS_PCLK_SAMPLE_RISING; + cfg->type = V4L2_MBUS_PARALLEL; return 0; @@ -1117,6 +1131,33 @@ static int mt9m111_video_probe(struct i2c_client *client) return ret; } +#ifdef CONFIG_OF +static int mt9m111_probe_of(struct i2c_client *client, struct mt9m111 *mt9m111) +{ + struct v4l2_fwnode_endpoint *bus_cfg; + struct device_node *np; + int ret = 0; + + np = of_graph_get_next_endpoint(client->dev.of_node, NULL); + if (!np) + return -EINVAL; + + bus_cfg = v4l2_fwnode_endpoint_alloc_parse(of_fwnode_handle(np)); + if (IS_ERR(bus_cfg)) { + ret = PTR_ERR(bus_cfg); + goto out_of_put; + } + + mt9m111->pclk_sample = !!(bus_cfg->bus.parallel.flags & + V4L2_MBUS_PCLK_SAMPLE_RISING); + + v4l2_fwnode_endpoint_free(bus_cfg); +out_of_put: + of_node_put(np); + return ret; +} +#endif + static int mt9m111_probe(struct i2c_client *client, const struct i2c_device_id *did) { @@ -1141,6 +1182,15 @@ static int mt9m111_probe(struct i2c_client *client, /* Default HIGHPOWER context */ mt9m111->ctx = &context_b; + if (IS_ENABLED(CONFIG_OF)) { + ret = mt9m111_probe_of(client, mt9m111); + if (ret) + return ret; + } else { + /* use default chip hardware values */ + mt9m111->pclk_sample = 1; + } + v4l2_i2c_subdev_init(&mt9m111->subdev, client, &mt9m111_subdev_ops); mt9m111->subdev.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;