From patchwork Mon Jul 9 15:41:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akinobu Mita X-Patchwork-Id: 10514955 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 CF2F7600CA for ; Mon, 9 Jul 2018 15:41:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BD75D28DF7 for ; Mon, 9 Jul 2018 15:41:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B08FA28E00; Mon, 9 Jul 2018 15:41:37 +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 3C77A28DF7 for ; Mon, 9 Jul 2018 15:41:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933380AbeGIPlf (ORCPT ); Mon, 9 Jul 2018 11:41:35 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:43747 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932699AbeGIPle (ORCPT ); Mon, 9 Jul 2018 11:41:34 -0400 Received: by mail-pf0-f195.google.com with SMTP id y8-v6so13937607pfm.10; Mon, 09 Jul 2018 08:41:33 -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=5BP8k/kLZyb2NPMNIXyJrYI+EKQf5OxxzpisrTeCJAo=; b=MDwPzLorgskxRfUAOvQF6sZWZlvebM8XHR53ozI9vE+bH9dGedSAY34MShmq6UoT8R 8ohOcn+I/+YOuQIGxliKzbbAhqSl3ixT7TsIMP+J1uWZKl2srfys2DUKkr5gjSCpJkJ4 X3KmVrjTOlme8wwntLRIN+LhKl4hZEZQbgITgnZnPKo7sje/6mPkUCbvBiN5bdkS7lF/ BbtlYf+3cXDySXoyFJItzQWwdOSCMVEZVBvEELeX62xGdk5T2jyJ8+PJ+TRsXK+oUG8v BxwqgWkzuqK5/P4IZP3de+PvF+KJrPPJiK/pGRl/uLmXYkxTHq6DDxBuwrFNaaHjMSYF Fgcg== 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=5BP8k/kLZyb2NPMNIXyJrYI+EKQf5OxxzpisrTeCJAo=; b=cypy18QJEKL1WmpfBrfDzej6z7gPEr/tmDIXrtZxUlV5BbvMfk0YjS9M41ruGzEmEy zdRmmuboRSEXie12rnOCCeIgK5joLWamLVQvOzMFuLDvrp9gJvTxxLmPdSifJbveIqEJ yPpSKfdlqIh0nBe3fYdQy//gO3csjCMoRAYfACxigCywGUgZ0WK2tkpxfNYcrSTKS+kg tlBoLSMnQSOBeWJ4HKUF/pcwNdKeYjbGl8hIOXmfAIv6xWedYvZ+vQeJpiPqytyew3+M RKigBB+BdPhV7Ccs4XQZ+IadDDuqZ5VEsjHf/W8Vz8NUvQZOS7hgwS/Lq3av9cfNVZMy IPZQ== X-Gm-Message-State: APt69E1lpaWaWntnRoxsng8MibVhbON8LvW5cjT9TQ/gXkvIr8Sv38Gb ygTz+5IJy4wflBNLrAFDOQWbvg== X-Google-Smtp-Source: AAOMgpfXa/i3SL/AVMDYQkQ9MaANjPma3/zVuzQupohP3/L1fCdZSdVCGOyhX3I5olZEHgN9qewO3w== X-Received: by 2002:a63:fc0a:: with SMTP id j10-v6mr19236859pgi.1.1531150893495; Mon, 09 Jul 2018 08:41:33 -0700 (PDT) Received: from localhost.localdomain ([240f:34:212d:1:3963:3c46:f9cd:fcc]) by smtp.gmail.com with ESMTPSA id g124-v6sm24980981pfb.5.2018.07.09.08.41.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 09 Jul 2018 08:41:32 -0700 (PDT) From: Akinobu Mita To: linux-media@vger.kernel.org, linux-i2c@vger.kernel.org Cc: Akinobu Mita , Peter Rosin , Sebastian Reichel , Wolfram Sang , Jacopo Mondi , Laurent Pinchart , Hans Verkuil , Sakari Ailus , Mauro Carvalho Chehab Subject: [PATCH -next v3 1/2] i2c: add SCCB helpers Date: Tue, 10 Jul 2018 00:41:13 +0900 Message-Id: <1531150874-4595-2-git-send-email-akinobu.mita@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1531150874-4595-1-git-send-email-akinobu.mita@gmail.com> References: <1531150874-4595-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 This adds Serial Camera Control Bus (SCCB) helpers (sccb_is_available, sccb_read_byte, and sccb_write_byte) that are intended to be used by some of Omnivision sensor drivers. The ov772x driver is going to use these helpers. It was previously only worked with the i2c controller drivers that support I2C_FUNC_PROTOCOL_MANGLING, because the ov772x device doesn't support repeated starts. After commit 0b964d183cbf ("media: ov772x: allow i2c controllers without I2C_FUNC_PROTOCOL_MANGLING"), reading ov772x register is replaced with issuing two separated i2c messages in order to avoid repeated start. Using SCCB helpers hides the implementation detail. Cc: Peter Rosin Cc: Sebastian Reichel Cc: Wolfram Sang Cc: Jacopo Mondi Cc: Laurent Pinchart Cc: Hans Verkuil Cc: Sakari Ailus Cc: Mauro Carvalho Chehab Signed-off-by: Akinobu Mita --- include/linux/i2c-sccb.h | 77 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 include/linux/i2c-sccb.h diff --git a/include/linux/i2c-sccb.h b/include/linux/i2c-sccb.h new file mode 100644 index 0000000..61dece9 --- /dev/null +++ b/include/linux/i2c-sccb.h @@ -0,0 +1,77 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Serial Camera Control Bus (SCCB) helper functions + */ + +#ifndef _LINUX_I2C_SCCB_H +#define _LINUX_I2C_SCCB_H + +#include + +/** + * sccb_is_available - Check if the adapter supports SCCB protocol + * @adap: I2C adapter + * + * Return true if the I2C adapter is capable of using SCCB helper functions, + * false otherwise. + */ +static inline bool sccb_is_available(struct i2c_adapter *adap) +{ + u32 needed_funcs = I2C_FUNC_SMBUS_BYTE | I2C_FUNC_SMBUS_WRITE_BYTE_DATA; + +#if 0 + /* + * sccb_xfer not needed yet, since there is no driver support currently. + * Just showing how it should be done if we ever need it. + */ + if (adap->algo->sccb_xfer) + return true; +#endif + + return (i2c_get_functionality(adap) & needed_funcs) == needed_funcs; +} + +/** + * sccb_read_byte - Read data from SCCB slave device + * @client: Handle to slave device + * @addr: Register to be read from + * + * This executes the 2-phase write transmission cycle that is followed by a + * 2-phase read transmission cycle, returning negative errno else a data byte + * received from the device. + */ +static inline int sccb_read_byte(struct i2c_client *client, u8 addr) +{ + int ret; + union i2c_smbus_data data; + + i2c_lock_bus(client->adapter, I2C_LOCK_SEGMENT); + + ret = __i2c_smbus_xfer(client->adapter, client->addr, client->flags, + I2C_SMBUS_WRITE, addr, I2C_SMBUS_BYTE, NULL); + if (ret < 0) + goto out; + + ret = __i2c_smbus_xfer(client->adapter, client->addr, client->flags, + I2C_SMBUS_READ, 0, I2C_SMBUS_BYTE, &data); +out: + i2c_unlock_bus(client->adapter, I2C_LOCK_SEGMENT); + + return ret < 0 ? ret : data.byte; +} + +/** + * sccb_write_byte - Write data to SCCB slave device + * @client: Handle to slave device + * @addr: Register to write to + * @data: Value to be written + * + * This executes the SCCB 3-phase write transmission cycle, returning negative + * errno else zero on success. + */ +static inline int sccb_write_byte(struct i2c_client *client, u8 addr, u8 data) +{ + return i2c_smbus_write_byte_data(client, addr, data); +} + +#endif /* _LINUX_I2C_SCCB_H */