From patchwork Sun May 6 14:19:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akinobu Mita X-Patchwork-Id: 10382813 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 A4CE16037F for ; Sun, 6 May 2018 14:19:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 92F9E2892B for ; Sun, 6 May 2018 14:19:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8774828970; Sun, 6 May 2018 14:19:57 +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 2752F2892B for ; Sun, 6 May 2018 14:19:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751769AbeEFOT4 (ORCPT ); Sun, 6 May 2018 10:19:56 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:37474 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751625AbeEFOTy (ORCPT ); Sun, 6 May 2018 10:19:54 -0400 Received: by mail-pf0-f196.google.com with SMTP id e9so16829783pfi.4; Sun, 06 May 2018 07:19:53 -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=/eh441Z2PMj3nAPS48UV16mEYawETjn6Ij4C4V8Fd0w=; b=QWqRsBlCMLPS3yEaJNxEIZjCpx7q17qLxgkhXgwPRSXGvTcU16JVNr5tKPoD75IJuJ nr2vPbPmraNfY31fu6G8cOV5LXlFyTqq4ib6wrBs+lakSUTKQzIhaspCowaR3bablKGR b6C2DJbrpNppuYhnS+x2aQMocsbINeFMcpBcVCsagZLvKysyLK3dulkiP9FQicq/V+Ds d+Q8E2Ndwvq2O1BjaBMbV4frDyby1hbPWKUUj1OiiaITWBFQYT/u2R5mGREUdSFYJuzd lWUGasqpbA0jkfCVHIUQQiPq7lFeOmeb9b+D6E8Whtq2oEeIFuMdy8GcKlOT9shRoVND 3qOQ== 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=/eh441Z2PMj3nAPS48UV16mEYawETjn6Ij4C4V8Fd0w=; b=AH8RTQBsD/2VUstqXTOBEibH18NeZP8HHu36YeNdVBfrCFYFkXuR1VcsWP/Cr5Qqg/ llyi5O1VMOeOd+m2Bv4sn/03wOy1iruRa8Myzz1whzcDOczIiU3CljkJuUneWvxY4twU 0Ih+Ku4yW/pcH0iWpajiYCKXhDloUA+5Zh8AENS/09k8x+l/5Y4iYVip2mgT2INHeG30 EZyM9xYRr0ufAx9RTZa8X8m6VPgkx4KvQWZNG4mguO5hkYz2RIHqs4gRzM7bYEH1zB5y tfTmuklkcGpXFzGvWW+3cCsm8kpzVxiZWhwflXFUJmGszAzbT8HYHxtaqT9Mq709Skjo AWNQ== X-Gm-Message-State: ALQs6tBA2HhBltn9oLwbWOpaRhHlbabE3BExCE1dAbZP/Jqg7Ube2C5/ z+7GT9delAwjwTkdBY3oe2vK8g== X-Google-Smtp-Source: AB8JxZr70nemLcLDj++cIDAGJavEV6si/+w//OtH8xr7JvbKaR/um0EiCnEuGb4Rp/JZ+wfU3kSntg== X-Received: by 2002:a17:902:9a04:: with SMTP id v4-v6mr34834295plp.21.1525616393539; Sun, 06 May 2018 07:19:53 -0700 (PDT) Received: from localhost.localdomain ([240f:4:c2bc:1:141a:15e1:5268:11ce]) by smtp.gmail.com with ESMTPSA id s88sm58766771pfe.43.2018.05.06.07.19.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 06 May 2018 07:19:53 -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 v5 03/14] media: ov772x: allow i2c controllers without I2C_FUNC_PROTOCOL_MANGLING Date: Sun, 6 May 2018 23:19:18 +0900 Message-Id: <1525616369-8843-4-git-send-email-akinobu.mita@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1525616369-8843-1-git-send-email-akinobu.mita@gmail.com> References: <1525616369-8843-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 Reviewed-by: Jacopo Mondi Signed-off-by: Akinobu Mita --- * v5 - Add Reviewed-by: line 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)