From patchwork Thu Apr 26 16:13:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akinobu Mita X-Patchwork-Id: 905192 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="P0pb11R1"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 40X2Dz3Kbqz9s06 for ; Fri, 27 Apr 2018 02:13:55 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755871AbeDZQNx (ORCPT ); Thu, 26 Apr 2018 12:13:53 -0400 Received: from mail-pg0-f68.google.com ([74.125.83.68]:34127 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756431AbeDZQNw (ORCPT ); Thu, 26 Apr 2018 12:13:52 -0400 Received: by mail-pg0-f68.google.com with SMTP id p10so16272437pgn.1; Thu, 26 Apr 2018 09:13:52 -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; bh=LAeOuIGaS+kjklG45ziNrJogFoK0LE5i22ykY5LAKus=; b=P0pb11R14K/nqrq9zZOKTGAVqEtavGAJVD/SW+lSD5Tczdd3jHK/WmAxWG1SfasRdh qcz9Ok02oklNmX0ksbCp9ESsgankvc5zgrEx+PcFBFRQYGxa3N38/gI+Qdu3svHjMVHH tkaT0sB4RjiB0C9mu16yS8vevEbNeOfqPDo3YCAoq04no3bHSIbL15UWk5lOuHCv5x52 VQxfiHak2GYFbpg1tIWWQ9bixb8+WSjWz4CwfgSa098xAmuedH+ylVqOjfJ78YSH9lSO hLXPe12NcAUDZnSRptKxxAfLUrpMQq/FwARZlX1EicVZ5xeBO8oK8oZ2/dJ4VqdGB9ti WLcw== 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; bh=LAeOuIGaS+kjklG45ziNrJogFoK0LE5i22ykY5LAKus=; b=iK6CqY//mgxXJl8EMukirnRqL7x1BCe97kR13ALoJptNzDkWbuUizeIe1ljSi2wHAp oXMfiZ+fI/3TnlNZD8n4JrJ7zJNXbt7SELZh9ffEn+iQkE7DFxpFG1almqMXlznIhLTc dz1VmxRNLmXi3J1d4So0s1tMUbgJV7y4eoAuOtrPZRl042F7W7S2WVhFV0Dk85yho385 ug6n8VrL6bM456puHHbLpXgmrF8trdVh12rL2ui3A6mF5S7+LPYLLR5Q2tMA3vxZHSTu VKfHqHFFQmLqGZYH9GK3nDwwyK1PQbFr5VGY9AoQ14t8sp3bGICPHykl5UE3m5AJNv1Z pNWg== X-Gm-Message-State: ALQs6tA/cZ/VWJE3UFcJgOEXYirkEa7GZ2VgOWqtLnVHxa/qC2l2mfiI iaqTNGLgAXjK5AGFFIo1iPjLVA== X-Google-Smtp-Source: AIpwx4/YmrvKzGQuTB/ZXyHzuLpe3rLu6wR3CEshe4AASqKSJgqX98Pyz91WaLZ56MmPqils15RaXg== X-Received: by 10.98.2.72 with SMTP id 69mr33121579pfc.12.1524759232218; Thu, 26 Apr 2018 09:13:52 -0700 (PDT) Received: from localhost.localdomain ([240f:4:c2bc:1:3926:8c3e:ece4:e80a]) by smtp.gmail.com with ESMTPSA id r82sm65949659pfk.187.2018.04.26.09.13.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 26 Apr 2018 09:13:51 -0700 (PDT) From: Akinobu Mita To: linux-media@vger.kernel.org, linux-i2c@vger.kernel.org Cc: Akinobu Mita , Wolfram Sang , Jacopo Mondi , Laurent Pinchart , Hans Verkuil , Sakari Ailus , Mauro Carvalho Chehab Subject: [RFC PATCH] media: i2c: add SCCB helpers Date: Fri, 27 Apr 2018 01:13:32 +0900 Message-Id: <1524759212-10941-1-git-send-email-akinobu.mita@gmail.com> X-Mailer: git-send-email 2.7.4 Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org (This patch is in prototype stage) This adds SCCB helper functions (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 functions in order to make it work with most i2c controllers. As the ov772x device doesn't support repeated starts, this driver currently requires I2C_FUNC_PROTOCOL_MANGLING that is not supported by many i2c controller drivers. With the sccb_read_byte() that issues two separated requests in order to avoid repeated start, the driver doesn't require I2C_FUNC_PROTOCOL_MANGLING. Cc: Wolfram Sang Cc: Jacopo Mondi Cc: Laurent Pinchart Cc: Hans Verkuil Cc: Sakari Ailus Cc: Mauro Carvalho Chehab Signed-off-by: Akinobu Mita --- drivers/media/i2c/Kconfig | 4 ++++ drivers/media/i2c/Makefile | 1 + drivers/media/i2c/sccb.c | 35 +++++++++++++++++++++++++++++++++++ drivers/media/i2c/sccb.h | 14 ++++++++++++++ 4 files changed, 54 insertions(+) create mode 100644 drivers/media/i2c/sccb.c create mode 100644 drivers/media/i2c/sccb.h diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig index 541f0d28..19e5601 100644 --- a/drivers/media/i2c/Kconfig +++ b/drivers/media/i2c/Kconfig @@ -569,6 +569,9 @@ config VIDEO_THS8200 comment "Camera sensor devices" +config SCCB + bool + config VIDEO_APTINA_PLL tristate @@ -692,6 +695,7 @@ config VIDEO_OV772X tristate "OmniVision OV772x sensor support" depends on I2C && VIDEO_V4L2 depends on MEDIA_CAMERA_SUPPORT + select SCCB ---help--- This is a Video4Linux2 sensor-level driver for the OmniVision OV772x camera. diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile index ea34aee..82fbd78 100644 --- a/drivers/media/i2c/Makefile +++ b/drivers/media/i2c/Makefile @@ -62,6 +62,7 @@ obj-$(CONFIG_VIDEO_VP27SMPX) += vp27smpx.o obj-$(CONFIG_VIDEO_SONY_BTF_MPX) += sony-btf-mpx.o obj-$(CONFIG_VIDEO_UPD64031A) += upd64031a.o obj-$(CONFIG_VIDEO_UPD64083) += upd64083.o +obj-$(CONFIG_SCCB) += sccb.o obj-$(CONFIG_VIDEO_OV2640) += ov2640.o obj-$(CONFIG_VIDEO_OV2685) += ov2685.o obj-$(CONFIG_VIDEO_OV5640) += ov5640.o diff --git a/drivers/media/i2c/sccb.c b/drivers/media/i2c/sccb.c new file mode 100644 index 0000000..80a3fb7 --- /dev/null +++ b/drivers/media/i2c/sccb.c @@ -0,0 +1,35 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include + +int sccb_read_byte(struct i2c_client *client, u8 addr) +{ + int ret; + u8 val; + + /* Issue two separated requests in order to avoid repeated start */ + + 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; +} +EXPORT_SYMBOL_GPL(sccb_read_byte); + +int sccb_write_byte(struct i2c_client *client, u8 addr, u8 data) +{ + int ret; + unsigned char msgbuf[] = { addr, data }; + + ret = i2c_master_send(client, msgbuf, 2); + if (ret < 0) + return ret; + + return 0; +} +EXPORT_SYMBOL_GPL(sccb_write_byte); diff --git a/drivers/media/i2c/sccb.h b/drivers/media/i2c/sccb.h new file mode 100644 index 0000000..68da0e9 --- /dev/null +++ b/drivers/media/i2c/sccb.h @@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * SCCB helper functions + */ + +#ifndef __SCCB_H__ +#define __SCCB_H__ + +#include + +int sccb_read_byte(struct i2c_client *client, u8 addr); +int sccb_write_byte(struct i2c_client *client, u8 addr, u8 data); + +#endif /* __SCCB_H__ */