From patchwork Sun Apr 22 15:56:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akinobu Mita X-Patchwork-Id: 10355625 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 2DC8960388 for ; Sun, 22 Apr 2018 15:56:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1DE2A2893D for ; Sun, 22 Apr 2018 15:56:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 12C652897A; Sun, 22 Apr 2018 15:56:59 +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=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, URIBL_RHS_DOB 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 88DF92893D for ; Sun, 22 Apr 2018 15:56:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754667AbeDVP44 (ORCPT ); Sun, 22 Apr 2018 11:56:56 -0400 Received: from mail-pg0-f67.google.com ([74.125.83.67]:37936 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754289AbeDVP4o (ORCPT ); Sun, 22 Apr 2018 11:56:44 -0400 Received: by mail-pg0-f67.google.com with SMTP id b5so6662061pgv.5; Sun, 22 Apr 2018 08:56:43 -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=eEfaHAPepxOk2uPaS035K9oH56+bE3h3deXTaHaJLp8=; b=nVDjk1vNH1U4kNQ0hlRujGpG0Sl1pqE8hT0MTnB6b3S5Za6/tfTNvbGuu8mK/BOlHw gZEra8CmKyDENTySSy67jev9YEJmQgSFJpGMCJBU1GFF/X+S3RPF9lLZ8jqhUAgsU/Qy KU4mlQ8dzauIBmm8LUF2DfO+qYgsSiqJVkOPizL70HQPZCp5xueynXjl/4s+WVIl2EHr bIqS4YSeSnEeS8NFOb44PX5m//h38P9uJUdvA/mjqPrrBe4tdeNncIifVgmZgD83jMOo 3js8HRhbE22K4ebKbJ6ZHucMTXXGY55DymXwvmCu/YpPi8NYkRo4+fJvqimNO3UqGoOP yXew== 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=eEfaHAPepxOk2uPaS035K9oH56+bE3h3deXTaHaJLp8=; b=JxH/X3BGphswlq1acLqARTdHX05p1EQdn2K9kX934txP0rBGoNAatU1b1A+2ip5O8X qnRbJOw4rpEGWsc6jgbKDpyCzq7DEvYUt7FJn6So1hokOLHAij3kfeGB/d3G60tET63+ O6ftj3mfx/SsK2smdppxNyL5PyYUPMTuQc9hxi+c5xHmsDcVvCZ/bE/KHvRQdtMpOisD SzE91+BVlIJ5f3uLarlDXrGT4oe3yYJOoluz6O1wjYiDtRViJKmmwgZyRyMIKqoDaGHs IH3dCIn1xAXq7it7U5UEdugp3pheApM+id39UiTeAYgfjFecJZf3JAsZG95woFECWypl yodw== X-Gm-Message-State: ALQs6tBoXWwym8jB8PEeKANm7QO03VrqcMEOM5gF1FLJoEZ1zEDb8mdl jLUUuGhCBu2ayxgLgWL25GcRKA== X-Google-Smtp-Source: AIpwx49FkZTKeShbm8lI7/HmExikUqzh357oaKLCCSSbS/inXBe9MvdVgdaGZ6e0rQgZhPLZodYLDQ== X-Received: by 2002:a17:902:227:: with SMTP id 36-v6mr17890114plc.134.1524412603274; Sun, 22 Apr 2018 08:56:43 -0700 (PDT) Received: from localhost.localdomain ([240f:4:c2bc:1:a9a1:96f3:29de:6e47]) by smtp.gmail.com with ESMTPSA id y29sm255461pff.42.2018.04.22.08.56.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 22 Apr 2018 08:56:42 -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 v3 02/11] media: ov772x: allow i2c controllers without I2C_FUNC_PROTOCOL_MANGLING Date: Mon, 23 Apr 2018 00:56:08 +0900 Message-Id: <1524412577-14419-3-git-send-email-akinobu.mita@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1524412577-14419-1-git-send-email-akinobu.mita@gmail.com> References: <1524412577-14419-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 changes the reading ov772x register method so that it doesn't require I2C_FUNC_PROTOCOL_MANGLING by calling two separated i2c messages. Cc: Jacopo Mondi Cc: Laurent Pinchart Cc: Hans Verkuil Cc: Sakari Ailus Cc: Mauro Carvalho Chehab Signed-off-by: Akinobu Mita --- * v3 - Remove I2C_CLIENT_SCCB flag set as it isn't needed anymore drivers/media/i2c/ov772x.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/drivers/media/i2c/ov772x.c b/drivers/media/i2c/ov772x.c index b62860c..2ae730f 100644 --- a/drivers/media/i2c/ov772x.c +++ b/drivers/media/i2c/ov772x.c @@ -542,9 +542,19 @@ 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) { - return i2c_smbus_read_byte_data(client, 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) @@ -1255,13 +1265,11 @@ static int ov772x_probe(struct i2c_client *client, return -EINVAL; } - if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA | - I2C_FUNC_PROTOCOL_MANGLING)) { + if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { dev_err(&adapter->dev, - "I2C-Adapter doesn't support SMBUS_BYTE_DATA or PROTOCOL_MANGLING\n"); + "I2C-Adapter doesn't support SMBUS_BYTE_DATA\n"); return -EIO; } - client->flags |= I2C_CLIENT_SCCB; priv = devm_kzalloc(&client->dev, sizeof(*priv), GFP_KERNEL); if (!priv)