From patchwork Mon Apr 16 02:51:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akinobu Mita X-Patchwork-Id: 10342059 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 F00216053B for ; Mon, 16 Apr 2018 02:52:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E0E94223B2 for ; Mon, 16 Apr 2018 02:52:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D51CD24B48; Mon, 16 Apr 2018 02:52:21 +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 6F48A2465D for ; Mon, 16 Apr 2018 02:52:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752654AbeDPCwR (ORCPT ); Sun, 15 Apr 2018 22:52:17 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:39386 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752630AbeDPCwQ (ORCPT ); Sun, 15 Apr 2018 22:52:16 -0400 Received: by mail-pf0-f196.google.com with SMTP id z9so3011803pfe.6; Sun, 15 Apr 2018 19:52:16 -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=Acz8OnCzJXg8/y3ojBKKtnKYPLGkmM6sBj2wodWgXPw=; b=nhrahV1dgQNDyzqVBTilW0BocTBbgOlT5GJXQTCYuVUllyCXBWbi7698z19Q9TDRLM WFmTIC5cgQRatd+8Cx2X3q1KgAtpO7RD5zvihhb/cG+YldfypHkSv84hzbeBKXqsnUzY A9x6dnwRlzAgVXuuk36T+STbHVSzUMiK0zlUSEP9cXd88wKM16afmvVHv5L1uFjemiXW LkXQzdix4KdPqP0/Esd4g1DT/sFYg+uF7VZhGEl599iVa/3YL0qRZcpQHvQh5RIK3nyZ 9IN6kKLNFR4Sh9uDvyeCI9x5fmcIw26/tkyscgwgLskPeaCFvirqoR1XTujNtfIiiaEa OUzA== 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=Acz8OnCzJXg8/y3ojBKKtnKYPLGkmM6sBj2wodWgXPw=; b=nqzYmWPD+KW9LMz8nlAtkESJ6XhdgcWkWVUKMEU6P4dvYaqyyw9CXT3/cddavy1ddB dYaRibRa9PKZcpsmGFrM7//gyFCwibDjBpd1RP5jcqjnvre09m8t4pYVprr6umP4KoDA kJxrk8KJxgqRwcUYHvL3+OScbSGyb3Hsb7FbiwPSlYG3Tw63jXzC7tk5dlx4E4HEPydM NDIYxvPii+3JYarp/dLGUA8FjFycT+cPeSdwbwIioixkO5tmo+vjqgbFwQ1qjIBvUDsJ kmKHm2zJAGc2R+TUpmcc7UJsBweca/8nWg9pROVTuY43dL1By3jkJn4G6wfQCL4paPWC hJ7A== X-Gm-Message-State: ALQs6tBq0cNYjKDDBuF1WcAcaY+87HDOF+BWDVPgn/RMlJpH/hTNv2wB lXbRwxDSLqI3LsnmL9HdEECVeQ== X-Google-Smtp-Source: AIpwx4+DGdFmpdIRQRpyazpHO/ystOBnZhre5a4PRe/DfzG3XXhuMaEWUsCd8rPOyDGucO2Wmhb97A== X-Received: by 10.98.216.129 with SMTP id e123mr7555547pfg.222.1523847135727; Sun, 15 Apr 2018 19:52:15 -0700 (PDT) Received: from localhost.localdomain ([240f:4:c2bc:1:3df1:9c88:51ad:c027]) by smtp.gmail.com with ESMTPSA id e1sm3694274pgt.49.2018.04.15.19.52.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 15 Apr 2018 19:52:15 -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 v2 01/10] media: ov772x: allow i2c controllers without I2C_FUNC_PROTOCOL_MANGLING Date: Mon, 16 Apr 2018 11:51:42 +0900 Message-Id: <1523847111-12986-2-git-send-email-akinobu.mita@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1523847111-12986-1-git-send-email-akinobu.mita@gmail.com> References: <1523847111-12986-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 --- * v2 - Replace the implementation of ov772x_read() instead of adding an alternative method drivers/media/i2c/ov772x.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/drivers/media/i2c/ov772x.c b/drivers/media/i2c/ov772x.c index b62860c..7e79da0 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,10 +1265,9 @@ 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;