From patchwork Sat Apr 7 15:48:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akinobu Mita X-Patchwork-Id: 10327887 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 875AB600CB for ; Sat, 7 Apr 2018 15:48:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 77BE42951C for ; Sat, 7 Apr 2018 15:48:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6C29529529; Sat, 7 Apr 2018 15:48:48 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, 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 03F5729528 for ; Sat, 7 Apr 2018 15:48:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751607AbeDGPsn (ORCPT ); Sat, 7 Apr 2018 11:48:43 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:37448 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751579AbeDGPsm (ORCPT ); Sat, 7 Apr 2018 11:48:42 -0400 Received: by mail-pf0-f196.google.com with SMTP id x16so2874910pfm.4; Sat, 07 Apr 2018 08:48:42 -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:in-reply-to:references; bh=dn6ihNJkjMoSeFAfxUK8l3U+JE2kg2zDzVdceQUD/lk=; b=lYDmSJKQEjmdlYKP/1G+Gxp6BKBiZyfFaEk1CpEByye7ZCyrmZfnqkiErOIEE/L4fS yVngOHr1iU6khnAC/JcqLKnDL2TwfJCxW5W2GGguSLwDIp7pEnJ5l5QNO5Lznh821acv zbDOaIUZROx/Hnf/FJyopyxVu9BVKhw+23TJ0RGAn+uoEIJqLP9w4zRFmciPUiaQDRAL ZTmoG6Bo3EVbKq3C5O5i2Sa/z6ZR+nCyf6HRGo9VZPKPdUT2vkxB9HHbKouAm1Jbczpt mJhtHNGKsoSOe5aFXCZ3uKzbH0xtPkoArL1vOX/vCZeZlgDs3BxD0Awb1EhLndpijIVt QXDw== 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:in-reply-to :references; bh=dn6ihNJkjMoSeFAfxUK8l3U+JE2kg2zDzVdceQUD/lk=; b=ic1EzELUYhE3x+SpsPQNtwmwaS1X35c52aYywWQu/AU2ePmEcb8RWSqlC2415lVRlJ 1ovf5wzJ9r7SF3bSj8xiw7pr561ZJG+WKBKOHI292YIvdopPJ7OOVwa7VPztRqe/i556 zwyeLDqGVtwvw5DG8nMs3aiYsVA0FkJnFnuzsJoKGN30rHiNh/CBrD99fEyMoZvSQzxM LkD+IfTVBNNsrLwOutc5vAxI5kiR3Yxb4csgphpW0Ku+0ibCBMq5oyVLsBjNbuNtBHN7 mL1sEEC90o297uM6sjestgdFktDL83jq6/GvE4uG0cfz5JPIleL0FapBo73N9yCWAkal 8a4Q== X-Gm-Message-State: AElRT7HEY9nGE/rGRpALucTXtzvnrGWk6rP1YZQjEVOZFppkJVU0QPEn UX9RY9h8fxUBcPY0Psf7rMLyqQ== X-Google-Smtp-Source: AIpwx4/GViPltr1bf6aEBFG5sY8Vwqd9u/QzRmC4vN+5VRJXEYIA8mS4rOTn3CyHdKmalJQPSXONmg== X-Received: by 10.99.111.6 with SMTP id k6mr20608598pgc.444.1523116121805; Sat, 07 Apr 2018 08:48:41 -0700 (PDT) Received: from localhost.localdomain ([240f:4:c2bc:1:3c69:7d24:eba0:888]) by smtp.gmail.com with ESMTPSA id x14sm23536871pgo.82.2018.04.07.08.48.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 07 Apr 2018 08:48:41 -0700 (PDT) From: Akinobu Mita To: linux-media@vger.kernel.org, devicetree@vger.kernel.org Cc: Akinobu Mita , Jacopo Mondi , Laurent Pinchart , Hans Verkuil , Sakari Ailus , Mauro Carvalho Chehab Subject: [PATCH 1/6] media: ov772x: allow i2c controllers without I2C_FUNC_PROTOCOL_MANGLING Date: Sun, 8 Apr 2018 00:48:05 +0900 Message-Id: <1523116090-13101-2-git-send-email-akinobu.mita@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1523116090-13101-1-git-send-email-akinobu.mita@gmail.com> References: <1523116090-13101-1-git-send-email-akinobu.mita@gmail.com> 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 The ov772x driver only works when the i2c controller have I2C_FUNC_PROTOCOL_MANGLING. However, many i2c controller drivers don't support it. The reason that the ov772x requires I2C_FUNC_PROTOCOL_MANGLING is that it doesn't support repeated starts. This change adds an alternative method for reading from ov772x register which uses two separated i2c messages for the i2c controllers without I2C_FUNC_PROTOCOL_MANGLING. Cc: Jacopo Mondi Cc: Laurent Pinchart Cc: Hans Verkuil Cc: Sakari Ailus Cc: Mauro Carvalho Chehab Signed-off-by: Akinobu Mita --- drivers/media/i2c/ov772x.c | 42 +++++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/drivers/media/i2c/ov772x.c b/drivers/media/i2c/ov772x.c index b62860c..283ae2c 100644 --- a/drivers/media/i2c/ov772x.c +++ b/drivers/media/i2c/ov772x.c @@ -424,6 +424,7 @@ struct ov772x_priv { /* band_filter = COM8[5] ? 256 - BDBASE : 0 */ unsigned short band_filter; unsigned int fps; + int (*reg_read)(struct i2c_client *client, u8 addr); }; /* @@ -542,11 +543,34 @@ static struct ov772x_priv *to_ov772x(struct v4l2_subdev *sd) return container_of(sd, struct ov772x_priv, subdev); } -static inline int ov772x_read(struct i2c_client *client, u8 addr) +static int ov772x_read(struct i2c_client *client, u8 addr) +{ + struct v4l2_subdev *sd = i2c_get_clientdata(client); + struct ov772x_priv *priv = to_ov772x(sd); + + return priv->reg_read(client, addr); +} + +static int ov772x_reg_read(struct i2c_client *client, u8 addr) { return i2c_smbus_read_byte_data(client, addr); } +static int ov772x_reg_read_fallback(struct i2c_client *client, u8 addr) +{ + int ret; + u8 val; + + ret = i2c_master_send(client, &addr, 1); + if (ret < 0) + return ret; + ret = i2c_master_recv(client, &val, 1); + if (ret < 0) + return ret; + + return val; +} + static inline int ov772x_write(struct i2c_client *client, u8 addr, u8 value) { return i2c_smbus_write_byte_data(client, addr, value); @@ -1255,20 +1279,20 @@ static int ov772x_probe(struct i2c_client *client, return -EINVAL; } - if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA | - I2C_FUNC_PROTOCOL_MANGLING)) { - dev_err(&adapter->dev, - "I2C-Adapter doesn't support SMBUS_BYTE_DATA or PROTOCOL_MANGLING\n"); - return -EIO; - } - client->flags |= I2C_CLIENT_SCCB; - priv = devm_kzalloc(&client->dev, sizeof(*priv), GFP_KERNEL); if (!priv) return -ENOMEM; priv->info = client->dev.platform_data; + if (i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA | + I2C_FUNC_PROTOCOL_MANGLING)) + priv->reg_read = ov772x_reg_read; + else + priv->reg_read = ov772x_reg_read_fallback; + + client->flags |= I2C_CLIENT_SCCB; + v4l2_i2c_subdev_init(&priv->subdev, client, &ov772x_subdev_ops); v4l2_ctrl_handler_init(&priv->hdl, 3); v4l2_ctrl_new_std(&priv->hdl, &ov772x_ctrl_ops,