From patchwork Sun Apr 29 17:13:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akinobu Mita X-Patchwork-Id: 10370607 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 6AD1860116 for ; Sun, 29 Apr 2018 17:13:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5B6E228A18 for ; Sun, 29 Apr 2018 17:13:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5049B28A1C; Sun, 29 Apr 2018 17:13:47 +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 1AFC528A21 for ; Sun, 29 Apr 2018 17:13:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753954AbeD2RNn (ORCPT ); Sun, 29 Apr 2018 13:13:43 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:42280 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753910AbeD2RNl (ORCPT ); Sun, 29 Apr 2018 13:13:41 -0400 Received: by mail-pf0-f195.google.com with SMTP id a11so4991524pfn.9; Sun, 29 Apr 2018 10:13:41 -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=2VqXY4NpsneGOaWUAKn32K/ekKYHG3WI9fJIZ7RXEBQ=; b=BdEqsz3nmFFf93j481HZH1rdZtoyq2o02NQ/drgkKFAVSU4TxYV9hffTbPwyGZJ/uu zPTMiuBelidz1wavJMDEn9XINMPPpdtu7cBGt06akPvWhG/QniQPZE3jatr0LSA5p4fR hetfTaNdfZeZ/GNqJ5Ypkxz5lH/1o2VCsQpjk5A0ZwsRxwL78BXV3Xti6N2tJJ6fjGHp FpjOd6cFF6RyDsFetDkpCzr0e+bMJZihvJqIaGT7Rbee2/QBNWQ7CPr/OHf0JAY89JpP e0BAXg/2DI5vsPc60nejY00rsi/3wnV+cKItsu2Skc4onaf/24KZ4AyneSYt/Vh9NGM8 pJMQ== 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=2VqXY4NpsneGOaWUAKn32K/ekKYHG3WI9fJIZ7RXEBQ=; b=I3k3svxT0iwyJGSEu8Msmj66lMlsFLveaYYxn7Z3LijcHo5CqVgOikXWcbdbd+oJDM VlXinvjWIoeeYvXqlVJ9e/khf7l5fjogYz0L7KD8h8MQefGtk0ZLO/o2IBd4FClNJ2bU g06y/a4mbmcEbh4Wer0RBLcbdsbagmYK53lciV6w2R7DDkth/slwDQ2UPIFtPcOKD65L 3cnGAcNba5b1imbvjOKakh4x94eeDuUIGkrSlvzujbpNLuCIYhA+s5LHwSbQHfVMAQyj +muIv1uhgtvg0aSizY81b4ctC8ueC+WEHXJYv95Um2Jp4UGDFzZ9PJMFXO4TDI2Z5iua EjMQ== X-Gm-Message-State: ALQs6tARTyowOOiNCuguwvobqus7G8gW93Q7PvO8HLaxIfBGSE7SyHk2 eaxshPKvd+eX5AWiKsQNgqSo2A== X-Google-Smtp-Source: AB8JxZrV4TCsXraKXk7Sa3nrMLjktfFYBXnCzkK5vFpLmxGUliG6lY4J53N7Li2SLmBkhRcaREn7AA== X-Received: by 2002:a17:902:3281:: with SMTP id z1-v6mr9585013plb.226.1525022021289; Sun, 29 Apr 2018 10:13:41 -0700 (PDT) Received: from localhost.localdomain ([240f:4:c2bc:1:754e:5a21:c35f:52a1]) by smtp.gmail.com with ESMTPSA id e10sm10168022pfn.67.2018.04.29.10.13.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 29 Apr 2018 10:13:40 -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 , Wolfram Sang Subject: [PATCH v4 03/14] media: ov772x: allow i2c controllers without I2C_FUNC_PROTOCOL_MANGLING Date: Mon, 30 Apr 2018 02:13:02 +0900 Message-Id: <1525021993-17789-4-git-send-email-akinobu.mita@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1525021993-17789-1-git-send-email-akinobu.mita@gmail.com> References: <1525021993-17789-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 Cc: Wolfram Sang Signed-off-by: Akinobu Mita Reviewed-by: Jacopo Mondi --- * v4 - No changes 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 e255070..b6223bf 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)