Skip to contentSkip to conversation

introduce SCCB regmap

PATCH In review Akinobu Mita 7 participants 19 messages Jul 16, 2018 – Jul 23, 2018

Subsystems (7)
lore
Share & tools
lore

Akinobu Mita

author reviewer
#0 lore raw

v4 cover introduce SCCB regmap

This patchset introduces Serial Camera Control Bus (SCCB) support for regmap API and convert ov772x and ov9650 drivers to use it.

This patchset was previously submitted as "introduce SCCB helpers" that provides three functions (sccb_is_available, sccb_read_byte, and sccb_write_byte). This time, the helpers are replaced by regmap API, but internal code is not much changed from the previous version.

* v4
- Introduce SCCB regmap instead of helper functions, suggested by Sebastian Reichel
- Change ov772x driver to use regmap instead of helper functions
- Add register access conversion for ov9650 driver

* v3
- Rewrite the helpers based on the code provided by Wolfram
- Convert ov772x driver to use SCCB helpers

v2
- Convert all helpers into static inline functions, and remove C source and Kconfig option.
- Acquire i2c adapter lock while issuing two requests for sccb_read_byte

Akinobu Mita (3):
regmap: add SCCB support
media: ov772x: use SCCB regmap
media: ov9650: use SCCB regmap

 drivers/base/regmap/Kconfig       |   4 +
 drivers/base/regmap/Makefile      |   1 +
 drivers/base/regmap/regmap-sccb.c | 128 +++++++++++++++++++++++++
 drivers/media/i2c/Kconfig         |   2 +
 drivers/media/i2c/ov772x.c        | 192 ++++++++++++++++----------------------
 drivers/media/i2c/ov9650.c        | 157 +++++++++++++++----------------
 include/linux/regmap.h            |  35 +++++++
 7 files changed, 326 insertions(+), 193 deletions(-)
 create mode 100644 drivers/base/regmap/regmap-sccb.c
Cc Mark Brown <[email protected]>
Cc Peter Rosin <[email protected]>
Cc Sebastian Reichel <[email protected]>
Cc Wolfram Sang <[email protected]>
Cc Sylwester Nawrocki <[email protected]>
Cc Jacopo Mondi <[email protected]>
Cc Laurent Pinchart <[email protected]>
Cc Hans Verkuil <[email protected]>
Cc Sakari Ailus <[email protected]>
Cc Mauro Carvalho Chehab <[email protected]>
Signature · 1 line
2.7.4
author reviewer
#1 lore raw

PATCH v4 1/3 regmap: add SCCB support

This adds Serial Camera Control Bus (SCCB) support for regmap API that is intended to be used by some of Omnivision sensor drivers.

The ov772x and ov9650 drivers are going to use this SCCB regmap API.

The ov772x driver 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 this SCCB regmap hides the implementation detail.

The ov9650 driver also issues two separated i2c messages to read the registers as the device doesn't support repeated start. So it can make use of this SCCB regmap.

Cc Mark Brown <[email protected]>
Cc Peter Rosin <[email protected]>
Cc Sebastian Reichel <[email protected]>
Cc Wolfram Sang <[email protected]>
Cc Sylwester Nawrocki <[email protected]>
Cc Jacopo Mondi <[email protected]>
Cc Laurent Pinchart <[email protected]>
Cc Hans Verkuil <[email protected]>
Cc Sakari Ailus <[email protected]>
Cc Mauro Carvalho Chehab <[email protected]>
---
 drivers/base/regmap/Kconfig       |   4 ++
 drivers/base/regmap/Makefile      |   1 +
 drivers/base/regmap/regmap-sccb.c | 128 ++++++++++++++++++++++++++++++++++++++
 include/linux/regmap.h            |  35 +++++++++++
 4 files changed, 168 insertions(+)
 create mode 100644 drivers/base/regmap/regmap-sccb.c
drivers/base/regmap/Kconfig +4 -0
index aff34c0..6ad5ef4 100644
@@ -45,3 +45,7 @@ config REGMAP_IRQ
 config REGMAP_SOUNDWIRE
 	tristate
 	depends on SOUNDWIRE_BUS
+
+config REGMAP_SCCB
+	tristate
+	depends on I2C
drivers/base/regmap/Makefile +1 -0
index 5ed0023..f5b4e88 100644
@@ -15,3 +15,4 @@ obj-$(CONFIG_REGMAP_MMIO) += regmap-mmio.o
 obj-$(CONFIG_REGMAP_IRQ) += regmap-irq.o
 obj-$(CONFIG_REGMAP_W1) += regmap-w1.o
 obj-$(CONFIG_REGMAP_SOUNDWIRE) += regmap-sdw.o
+obj-$(CONFIG_REGMAP_SCCB) += regmap-sccb.o
drivers/base/regmap/regmap-sccb.c new file +128 -0

128 lines not on this page · raw message

include/linux/regmap.h +35 -0
index 4f38068..52bf358 100644
@@ -514,6 +514,10 @@ struct regmap *__regmap_init_i2c(struct i2c_client *i2c,
 				 const struct regmap_config *config,
 				 struct lock_class_key *lock_key,
 				 const char *lock_name);
+struct regmap *__regmap_init_sccb(struct i2c_client *i2c,
+				  const struct regmap_config *config,
+				  struct lock_class_key *lock_key,
+				  const char *lock_name);
 struct regmap *__regmap_init_slimbus(struct slim_device *slimbus,
 				 const struct regmap_config *config,
 				 struct lock_class_key *lock_key,
@@ -558,6 +562,10 @@ struct regmap *__devm_regmap_init_i2c(struct i2c_client *i2c,
 				      const struct regmap_config *config,
 				      struct lock_class_key *lock_key,
 				      const char *lock_name);
+struct regmap *__devm_regmap_init_sccb(struct i2c_client *i2c,
+				       const struct regmap_config *config,
+				       struct lock_class_key *lock_key,
+				       const char *lock_name);
 struct regmap *__devm_regmap_init_spi(struct spi_device *dev,
 				      const struct regmap_config *config,
 				      struct lock_class_key *lock_key,
@@ -646,6 +654,19 @@ int regmap_attach_dev(struct device *dev, struct regmap *map,
 				i2c, config)
 
 /**
+ * regmap_init_sccb() - Initialise register map
+ *
+ * @i2c: Device that will be interacted with
+ * @config: Configuration for register map
+ *
+ * The return value will be an ERR_PTR() on error or a valid pointer to
+ * a struct regmap.
+ */
+#define regmap_init_sccb(i2c, config)					\
+	__regmap_lockdep_wrapper(__regmap_init_sccb, #config,		\
+				i2c, config)
+
+/**
  * regmap_init_slimbus() - Initialise register map
  *
  * @slimbus: Device that will be interacted with
@@ -798,6 +819,20 @@ bool regmap_ac97_default_volatile(struct device *dev, unsigned int reg);
 				i2c, config)
 
 /**
+ * devm_regmap_init_sccb() - Initialise managed register map
+ *
+ * @i2c: Device that will be interacted with
+ * @config: Configuration for register map
+ *
+ * The return value will be an ERR_PTR() on error or a valid pointer
+ * to a struct regmap.  The regmap will be automatically freed by the
+ * device management code.
+ */
+#define devm_regmap_init_sccb(i2c, config)				\
+	__regmap_lockdep_wrapper(__devm_regmap_init_sccb, #config,	\
+				i2c, config)
+
+/**
  * devm_regmap_init_spi() - Initialise register map
  *
  * @dev: Device that will be interacted with
Signature · 1 line
2.7.4
maintainer
#2 lore raw

Re: [PATCH -next v4 1/3] regmap: add SCCB support

Quoted 2 lines · Akinobu Mita

This adds Serial Camera Control Bus (SCCB) support for regmap API that is intended to be used by some of Omnivision sensor drivers.

The following changes since commit ce397d215ccd07b8ae3f71db689aedb85d56ab40:

Linux 4.18-rc1 (2018-06-17 08:04:49 +0900)

are available in the Git repository at:

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap.git tags/regmap-sccb

for you to fetch changes up to bcf7eac3d97f49d8400ba52c71bee5934bf20093:

regmap: add SCCB support (2018-07-18 15:45:23 +0100)

----------------------------------------------------------------
regmap: Add support for SCCB

This is an I2C subset.

----------------------------------------------------------------
Akinobu Mita (1):
regmap: add SCCB support

 drivers/base/regmap/Kconfig       |   4 ++
 drivers/base/regmap/Makefile      |   1 +
 drivers/base/regmap/regmap-sccb.c | 128 ++++++++++++++++++++++++++++++++++++++
 include/linux/regmap.h            |  35 +++++++++++
 4 files changed, 168 insertions(+)
 create mode 100644 drivers/base/regmap/regmap-sccb.c
Reviewed-by on v4 1/3
#3 lore raw

Re: [PATCH -next v4 1/3] regmap: add SCCB support

In reply to Akinobu Mita
Quoted 13 lines · Akinobu Mita

This adds Serial Camera Control Bus (SCCB) support for regmap API that is intended to be used by some of Omnivision sensor drivers.

The ov772x and ov9650 drivers are going to use this SCCB regmap API.

The ov772x driver 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 this SCCB regmap hides the implementation detail.

Quoted 3 lines

The ov9650 driver also issues two separated i2c messages to read the registers as the device doesn't support repeated start. So it can make use of this SCCB regmap.

Cool, this series really gets better and better each time. Thank you for keeping at it! And thanks to everyone for their suggestions. I really like how we do not introduce a couple of i2c_sccb_* functions with a need to export them. And given the nature of regmap, I'd think it should be fairly easy to add support for ov2659 somewhen which has 16 bit registers? Only minor nits:

drivers/base/regmap/regmap-sccb.c line 6

Quoted 3 lines
drivers/base/regmap/regmap-sccb.c new file +3 -0
+#include <linux/regmap.h>
+#include <linux/i2c.h>
+#include <linux/module.h>

Sort these?

Quoted 3 lines

+/**
+ * regmap_sccb_read - Read data from SCCB slave device
+ * @context: Device that will be interacted wit

"with"

drivers/base/regmap/regmap-sccb.c line 50

Quoted 2 lines
drivers/base/regmap/regmap-sccb.c new file +2 -0
+	ret = __i2c_smbus_xfer(i2c->adapter, i2c->addr, i2c->flags,
+			       I2C_SMBUS_WRITE, reg, I2C_SMBUS_BYTE, NULL);

Mark: __i2c_smbus_xfer is a dependency on i2c/for-next. Do you want an immutable branch for that?

Quoted 3 lines

+/**
+ * regmap_sccb_write - Write data to SCCB slave device
+ * @context: Device that will be interacted wit

"with"

But in general (especially for the I2C parts):

maintainer
#4 lore raw

Re: [PATCH -next v4 1/3] regmap: add SCCB support

Quoted 7 lines · Wolfram Sang

drivers/base/regmap/regmap-sccb.c line 50

Quoted 2 lines · Akinobu Mita
drivers/base/regmap/regmap-sccb.c new file +2 -0
+	ret = __i2c_smbus_xfer(i2c->adapter, i2c->addr, i2c->flags,
+			       I2C_SMBUS_WRITE, reg, I2C_SMBUS_BYTE, NULL);

Mark: __i2c_smbus_xfer is a dependency on i2c/for-next. Do you want an immutable branch for that?

Oh dear, that dependency wasn't mentioned anywhere I can see in the submissions and I already applied this and created a signed tag :( . I'll need a branch to pull in if I'm going to apply this (which I'd prefer, it tends to make life easier).

#5 lore raw

Re: [PATCH -next v4 1/3] regmap: add SCCB support

Quoted 9 lines · Mark Brown
Quoted 7 lines · Wolfram Sang

drivers/base/regmap/regmap-sccb.c line 50

Quoted 2 lines · Akinobu Mita
drivers/base/regmap/regmap-sccb.c new file +2 -0
+	ret = __i2c_smbus_xfer(i2c->adapter, i2c->addr, i2c->flags,
+			       I2C_SMBUS_WRITE, reg, I2C_SMBUS_BYTE, NULL);

Mark: __i2c_smbus_xfer is a dependency on i2c/for-next. Do you want an immutable branch for that?

Quoted 4 lines

Oh dear, that dependency wasn't mentioned anywhere I can see in the submissions and I already applied this and created a signed tag :( . I'll need a branch to pull in if I'm going to apply this (which I'd prefer, it tends to make life easier).

Here is it:

git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux.git i2c/smbus_xfer_unlock-immutable

maintainer
#6 lore raw

Re: [PATCH -next v4 1/3] regmap: add SCCB support

Quoted 3 lines · Wolfram Sang

Here is it:

git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux.git i2c/smbus_xfer_unlock-immutable

Thanks, pulled in now.

author reviewer
#7 lore raw

Re: [PATCH -next v4 1/3] regmap: add SCCB support

In reply to Wolfram Sang

2018年7月19日(木) 0:28 Wolfram Sang <[email protected]>:

Quoted 19 lines · Akinobu Mita
Quoted 13 lines

This adds Serial Camera Control Bus (SCCB) support for regmap API that is intended to be used by some of Omnivision sensor drivers.

The ov772x and ov9650 drivers are going to use this SCCB regmap API.

The ov772x driver 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 this SCCB regmap hides the implementation detail.

Quoted 3 lines

The ov9650 driver also issues two separated i2c messages to read the registers as the device doesn't support repeated start. So it can make use of this SCCB regmap.

Quoted 6 lines

Cool, this series really gets better and better each time. Thank you for keeping at it! And thanks to everyone for their suggestions. I really like how we do not introduce a couple of i2c_sccb_* functions with a need to export them. And given the nature of regmap, I'd think it should be fairly easy to add support for ov2659 somewhen which has 16 bit registers? Only minor nits:

I have an ov2659 sensor. The ov2659 driver works with i2c adapter that doesn't know I2C_FUNC_PROTOCOL_MANGLING, so it actually supports repeated start.

But ov5645, ov5647, ov7251 drivers may want to use SCCB regmap API for 16-bit register. Because they use i2c_master_send + i2c_master_recv for reading register value.

Quoted 22 lines

drivers/base/regmap/regmap-sccb.c line 6

Quoted 3 lines
drivers/base/regmap/regmap-sccb.c new file +3 -0
+#include <linux/regmap.h>
+#include <linux/i2c.h>
+#include <linux/module.h>

Sort these?

Quoted 3 lines

+/**
+ * regmap_sccb_read - Read data from SCCB slave device
+ * @context: Device that will be interacted wit

"with"

drivers/base/regmap/regmap-sccb.c line 50

Quoted 2 lines
drivers/base/regmap/regmap-sccb.c new file +2 -0
+     ret = __i2c_smbus_xfer(i2c->adapter, i2c->addr, i2c->flags,
+                            I2C_SMBUS_WRITE, reg, I2C_SMBUS_BYTE, NULL);

Mark: __i2c_smbus_xfer is a dependency on i2c/for-next. Do you want an immutable branch for that?

Quoted 3 lines

+/**
+ * regmap_sccb_write - Write data to SCCB slave device
+ * @context: Device that will be interacted wit

Quoted 5 lines

"with"

But in general (especially for the I2C parts):

Thank you for your reviewing.

Reviewed-by on v4 1/3
#8 lore raw

Re: [PATCH -next v4 1/3] regmap: add SCCB support

In reply to Akinobu Mita

Hi,

Quoted 28 lines · Akinobu Mita

This adds Serial Camera Control Bus (SCCB) support for regmap API that is intended to be used by some of Omnivision sensor drivers.

The ov772x and ov9650 drivers are going to use this SCCB regmap API.

The ov772x driver 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 this SCCB regmap hides the implementation detail.

The ov9650 driver also issues two separated i2c messages to read the registers as the device doesn't support repeated start. So it can make use of this SCCB regmap.

Cc Mark Brown <[email protected]>
Cc Peter Rosin <[email protected]>
Cc Sebastian Reichel <[email protected]>
Cc Wolfram Sang <[email protected]>
Cc Sylwester Nawrocki <[email protected]>
Cc Jacopo Mondi <[email protected]>
Cc Laurent Pinchart <[email protected]>
Cc Hans Verkuil <[email protected]>
Cc Sakari Ailus <[email protected]>
Cc Mauro Carvalho Chehab <[email protected]>
Quoted 1 line

---

-- Sebastian

Quoted 232 lines
 drivers/base/regmap/Kconfig       |   4 ++
 drivers/base/regmap/Makefile      |   1 +
 drivers/base/regmap/regmap-sccb.c | 128 ++++++++++++++++++++++++++++++++++++++
 include/linux/regmap.h            |  35 +++++++++++
 4 files changed, 168 insertions(+)
 create mode 100644 drivers/base/regmap/regmap-sccb.c
drivers/base/regmap/Kconfig +4 -0
index aff34c0..6ad5ef4 100644
@@ -45,3 +45,7 @@ config REGMAP_IRQ
 config REGMAP_SOUNDWIRE
 	tristate
 	depends on SOUNDWIRE_BUS
+
+config REGMAP_SCCB
+	tristate
+	depends on I2C
drivers/base/regmap/Makefile +1 -0
index 5ed0023..f5b4e88 100644
@@ -15,3 +15,4 @@ obj-$(CONFIG_REGMAP_MMIO) += regmap-mmio.o
 obj-$(CONFIG_REGMAP_IRQ) += regmap-irq.o
 obj-$(CONFIG_REGMAP_W1) += regmap-w1.o
 obj-$(CONFIG_REGMAP_SOUNDWIRE) += regmap-sdw.o
+obj-$(CONFIG_REGMAP_SCCB) += regmap-sccb.o
drivers/base/regmap/regmap-sccb.c new file +128 -0
new file mode 100644
index 0000000..b6eb876
@@ -0,0 +1,128 @@
+// SPDX-License-Identifier: GPL-2.0
+// Register map access API - SCCB support
+
+#include <linux/regmap.h>
+#include <linux/i2c.h>
+#include <linux/module.h>
+
+#include "internal.h"
+
+/**
+ * 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 bool sccb_is_available(struct i2c_adapter *adap)
+{
+	u32 needed_funcs = I2C_FUNC_SMBUS_BYTE | I2C_FUNC_SMBUS_WRITE_BYTE_DATA;
+
+	/*
+	 * If we ever want support for hardware doing SCCB natively, we will
+	 * introduce a sccb_xfer() callback to struct i2c_algorithm and check
+	 * for it here.
+	 */
+
+	return (i2c_get_functionality(adap) & needed_funcs) == needed_funcs;
+}
+
+/**
+ * regmap_sccb_read - Read data from SCCB slave device
+ * @context: Device that will be interacted wit
+ * @reg: Register to be read from
+ * @val: Pointer to store read value
+ *
+ * This executes the 2-phase write transmission cycle that is followed by a
+ * 2-phase read transmission cycle, returning negative errno else zero on
+ * success.
+ */
+static int regmap_sccb_read(void *context, unsigned int reg, unsigned int *val)
+{
+	struct device *dev = context;
+	struct i2c_client *i2c = to_i2c_client(dev);
+	int ret;
+	union i2c_smbus_data data;
+
+	i2c_lock_bus(i2c->adapter, I2C_LOCK_SEGMENT);
+
+	ret = __i2c_smbus_xfer(i2c->adapter, i2c->addr, i2c->flags,
+			       I2C_SMBUS_WRITE, reg, I2C_SMBUS_BYTE, NULL);
+	if (ret < 0)
+		goto out;
+
+	ret = __i2c_smbus_xfer(i2c->adapter, i2c->addr, i2c->flags,
+			       I2C_SMBUS_READ, 0, I2C_SMBUS_BYTE, &data);
+	if (ret < 0)
+		goto out;
+
+	*val = data.byte;
+out:
+	i2c_unlock_bus(i2c->adapter, I2C_LOCK_SEGMENT);
+
+	return ret;
+}
+
+/**
+ * regmap_sccb_write - Write data to SCCB slave device
+ * @context: Device that will be interacted wit
+ * @reg: Register to write to
+ * @val: Value to be written
+ *
+ * This executes the SCCB 3-phase write transmission cycle, returning negative
+ * errno else zero on success.
+ */
+static int regmap_sccb_write(void *context, unsigned int reg, unsigned int val)
+{
+	struct device *dev = context;
+	struct i2c_client *i2c = to_i2c_client(dev);
+
+	return i2c_smbus_write_byte_data(i2c, reg, val);
+}
+
+static struct regmap_bus regmap_sccb_bus = {
+	.reg_write = regmap_sccb_write,
+	.reg_read = regmap_sccb_read,
+};
+
+static const struct regmap_bus *regmap_get_sccb_bus(struct i2c_client *i2c,
+					const struct regmap_config *config)
+{
+	if (config->val_bits == 8 && config->reg_bits == 8 &&
+			sccb_is_available(i2c->adapter))
+		return &regmap_sccb_bus;
+
+	return ERR_PTR(-ENOTSUPP);
+}
+
+struct regmap *__regmap_init_sccb(struct i2c_client *i2c,
+				  const struct regmap_config *config,
+				  struct lock_class_key *lock_key,
+				  const char *lock_name)
+{
+	const struct regmap_bus *bus = regmap_get_sccb_bus(i2c, config);
+
+	if (IS_ERR(bus))
+		return ERR_CAST(bus);
+
+	return __regmap_init(&i2c->dev, bus, &i2c->dev, config,
+			     lock_key, lock_name);
+}
+EXPORT_SYMBOL_GPL(__regmap_init_sccb);
+
+struct regmap *__devm_regmap_init_sccb(struct i2c_client *i2c,
+				       const struct regmap_config *config,
+				       struct lock_class_key *lock_key,
+				       const char *lock_name)
+{
+	const struct regmap_bus *bus = regmap_get_sccb_bus(i2c, config);
+
+	if (IS_ERR(bus))
+		return ERR_CAST(bus);
+
+	return __devm_regmap_init(&i2c->dev, bus, &i2c->dev, config,
+				  lock_key, lock_name);
+}
+EXPORT_SYMBOL_GPL(__devm_regmap_init_sccb);
+
+MODULE_LICENSE("GPL v2");
include/linux/regmap.h +35 -0
index 4f38068..52bf358 100644
@@ -514,6 +514,10 @@ struct regmap *__regmap_init_i2c(struct i2c_client *i2c,
 				 const struct regmap_config *config,
 				 struct lock_class_key *lock_key,
 				 const char *lock_name);
+struct regmap *__regmap_init_sccb(struct i2c_client *i2c,
+				  const struct regmap_config *config,
+				  struct lock_class_key *lock_key,
+				  const char *lock_name);
 struct regmap *__regmap_init_slimbus(struct slim_device *slimbus,
 				 const struct regmap_config *config,
 				 struct lock_class_key *lock_key,
@@ -558,6 +562,10 @@ struct regmap *__devm_regmap_init_i2c(struct i2c_client *i2c,
 				      const struct regmap_config *config,
 				      struct lock_class_key *lock_key,
 				      const char *lock_name);
+struct regmap *__devm_regmap_init_sccb(struct i2c_client *i2c,
+				       const struct regmap_config *config,
+				       struct lock_class_key *lock_key,
+				       const char *lock_name);
 struct regmap *__devm_regmap_init_spi(struct spi_device *dev,
 				      const struct regmap_config *config,
 				      struct lock_class_key *lock_key,
@@ -646,6 +654,19 @@ int regmap_attach_dev(struct device *dev, struct regmap *map,
 				i2c, config)
 
 /**
+ * regmap_init_sccb() - Initialise register map
+ *
+ * @i2c: Device that will be interacted with
+ * @config: Configuration for register map
+ *
+ * The return value will be an ERR_PTR() on error or a valid pointer to
+ * a struct regmap.
+ */
+#define regmap_init_sccb(i2c, config)					\
+	__regmap_lockdep_wrapper(__regmap_init_sccb, #config,		\
+				i2c, config)
+
+/**
  * regmap_init_slimbus() - Initialise register map
  *
  * @slimbus: Device that will be interacted with
@@ -798,6 +819,20 @@ bool regmap_ac97_default_volatile(struct device *dev, unsigned int reg);
 				i2c, config)
 
 /**
+ * devm_regmap_init_sccb() - Initialise managed register map
+ *
+ * @i2c: Device that will be interacted with
+ * @config: Configuration for register map
+ *
+ * The return value will be an ERR_PTR() on error or a valid pointer
+ * to a struct regmap.  The regmap will be automatically freed by the
+ * device management code.
+ */
+#define devm_regmap_init_sccb(i2c, config)				\
+	__regmap_lockdep_wrapper(__devm_regmap_init_sccb, #config,	\
+				i2c, config)
+
+/**
  * devm_regmap_init_spi() - Initialise register map
  *
  * @dev: Device that will be interacted with
Signature · 1 line
2.7.4
author reviewer
#9 lore raw

PATCH v4 2/3 media: ov772x: use SCCB regmap

In reply to Akinobu Mita

Convert ov772x register access to use SCCB regmap.

Cc Mark Brown <[email protected]>
Cc Peter Rosin <[email protected]>
Cc Sebastian Reichel <[email protected]>
Cc Wolfram Sang <[email protected]>
Cc Sylwester Nawrocki <[email protected]>
Cc Jacopo Mondi <[email protected]>
Cc Laurent Pinchart <[email protected]>
Cc Hans Verkuil <[email protected]>
Cc Sakari Ailus <[email protected]>
Cc Mauro Carvalho Chehab <[email protected]>
---
 drivers/media/i2c/Kconfig  |   1 +
 drivers/media/i2c/ov772x.c | 192 +++++++++++++++++++--------------------------
 2 files changed, 82 insertions(+), 111 deletions(-)
drivers/media/i2c/Kconfig +1 -0
index 341452f..b923a51 100644
@@ -715,6 +715,7 @@ config VIDEO_OV772X
 	tristate "OmniVision OV772x sensor support"
 	depends on I2C && VIDEO_V4L2
 	depends on MEDIA_CAMERA_SUPPORT
+	select REGMAP_SCCB
 	---help---
 	  This is a Video4Linux2 sensor-level driver for the OmniVision
 	  OV772x camera.
drivers/media/i2c/ov772x.c +81 -111

414 lines not on this page · raw message

Signature · 1 line
2.7.4
Acked-by on v4 2/3
#10 lore raw

Re: [PATCH -next v4 2/3] media: ov772x: use SCCB regmap

Quoted 13 lines · Akinobu Mita

Convert ov772x register access to use SCCB regmap.

Cc Mark Brown <[email protected]>
Cc Peter Rosin <[email protected]>
Cc Sebastian Reichel <[email protected]>
Cc Wolfram Sang <[email protected]>
Cc Sylwester Nawrocki <[email protected]>
Cc Jacopo Mondi <[email protected]>
Cc Laurent Pinchart <[email protected]>
Cc Hans Verkuil <[email protected]>
Cc Sakari Ailus <[email protected]>
Cc Mauro Carvalho Chehab <[email protected]>

From an I2C point of view, this makes a lot of sense:

maintainer Reviewed-by on v4 2/3
#11 lore raw

Re: [PATCH -next v4 2/3] media: ov772x: use SCCB regmap

In reply to Akinobu Mita

Hello Mita-San,
thanks for keep pushing on this SCCB issue

Only one veryt minor nit, please see below..

Quoted 78 lines · Akinobu Mita

Convert ov772x register access to use SCCB regmap.

Cc Mark Brown <[email protected]>
Cc Peter Rosin <[email protected]>
Cc Sebastian Reichel <[email protected]>
Cc Wolfram Sang <[email protected]>
Cc Sylwester Nawrocki <[email protected]>
Cc Jacopo Mondi <[email protected]>
Cc Laurent Pinchart <[email protected]>
Cc Hans Verkuil <[email protected]>
Cc Sakari Ailus <[email protected]>
Cc Mauro Carvalho Chehab <[email protected]>
---
 drivers/media/i2c/Kconfig  |   1 +
 drivers/media/i2c/ov772x.c | 192 +++++++++++++++++++--------------------------
 2 files changed, 82 insertions(+), 111 deletions(-)
drivers/media/i2c/Kconfig +1 -0
index 341452f..b923a51 100644
@@ -715,6 +715,7 @@ config VIDEO_OV772X
 	tristate "OmniVision OV772x sensor support"
 	depends on I2C && VIDEO_V4L2
 	depends on MEDIA_CAMERA_SUPPORT
+	select REGMAP_SCCB
 	---help---
 	  This is a Video4Linux2 sensor-level driver for the OmniVision
 	  OV772x camera.
drivers/media/i2c/ov772x.c +2 -24
index 7158c31..0d3ed23 100644
@@ -21,6 +21,7 @@
 #include <linux/init.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
+#include <linux/regmap.h>
 #include <linux/slab.h>
 #include <linux/v4l2-mediabus.h>
 #include <linux/videodev2.h>
@@ -414,6 +415,7 @@ struct ov772x_priv {
 	struct v4l2_subdev                subdev;
 	struct v4l2_ctrl_handler	  hdl;
 	struct clk			 *clk;
+	struct regmap			 *regmap;
 	struct ov772x_camera_info        *info;
 	struct gpio_desc		 *pwdn_gpio;
 	struct gpio_desc		 *rstb_gpio;
@@ -549,51 +551,18 @@ static struct ov772x_priv *to_ov772x(struct v4l2_subdev *sd)
 	return container_of(sd, struct ov772x_priv, subdev);
 }
 
-static int ov772x_read(struct i2c_client *client, u8 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)
-{
-	return i2c_smbus_write_byte_data(client, addr, value);
-}
-
-static int ov772x_mask_set(struct i2c_client *client, u8  command, u8  mask,
-			   u8  set)
-{
-	s32 val = ov772x_read(client, command);

drivers/media/i2c/ov772x.c static struct ov772x_priv *to_ov772x(struct v4l2_subdev *sd) · line 585

Quoted 10 lines
drivers/media/i2c/ov772x.c +0 -10
-
-	if (val < 0)
-		return val;
-
-	val &= ~mask;
-	val |= set & mask;
-
-	return ov772x_write(client, command, val);
-}
-

If I were you I would have kept these functions and wrapped the regmap operations there. This is not an issue though if you prefer it this way :)

Quoted 99 lines
drivers/media/i2c/ov772x.c +18 -19
-static int ov772x_reset(struct i2c_client *client)
+static int ov772x_reset(struct ov772x_priv *priv)
 {
 	int ret;
 
-	ret = ov772x_write(client, COM7, SCCB_RESET);
+	ret = regmap_write(priv->regmap, COM7, SCCB_RESET);
 	if (ret < 0)
 		return ret;
 
 	usleep_range(1000, 5000);
 
-	return ov772x_mask_set(client, COM2, SOFT_SLEEP_MODE, SOFT_SLEEP_MODE);
+	return regmap_update_bits(priv->regmap, COM2, SOFT_SLEEP_MODE,
+				  SOFT_SLEEP_MODE);
 }
 
 /*
@@ -611,8 +580,8 @@ static int ov772x_s_stream(struct v4l2_subdev *sd, int enable)
 	if (priv->streaming == enable)
 		goto done;
 
-	ret = ov772x_mask_set(client, COM2, SOFT_SLEEP_MODE,
-			      enable ? 0 : SOFT_SLEEP_MODE);
+	ret = regmap_update_bits(priv->regmap, COM2, SOFT_SLEEP_MODE,
+				 enable ? 0 : SOFT_SLEEP_MODE);
 	if (ret)
 		goto done;
 
@@ -657,7 +626,6 @@ static int ov772x_set_frame_rate(struct ov772x_priv *priv,
 				 const struct ov772x_color_format *cfmt,
 				 const struct ov772x_win_size *win)
 {
-	struct i2c_client *client = v4l2_get_subdevdata(&priv->subdev);
 	unsigned long fin = clk_get_rate(priv->clk);
 	unsigned int best_diff;
 	unsigned int fsize;
@@ -723,11 +691,11 @@ static int ov772x_set_frame_rate(struct ov772x_priv *priv,
 		}
 	}
 
-	ret = ov772x_write(client, COM4, com4 | COM4_RESERVED);
+	ret = regmap_write(priv->regmap, COM4, com4 | COM4_RESERVED);
 	if (ret < 0)
 		return ret;
 
-	ret = ov772x_write(client, CLKRC, clkrc | CLKRC_RESERVED);
+	ret = regmap_write(priv->regmap, CLKRC, clkrc | CLKRC_RESERVED);
 	if (ret < 0)
 		return ret;
 
@@ -788,8 +756,7 @@ static int ov772x_s_ctrl(struct v4l2_ctrl *ctrl)
 {
 	struct ov772x_priv *priv = container_of(ctrl->handler,
 						struct ov772x_priv, hdl);
-	struct v4l2_subdev *sd = &priv->subdev;
-	struct i2c_client *client = v4l2_get_subdevdata(sd);
+	struct regmap *regmap = priv->regmap;
 	int ret = 0;
 	u8 val;
 
@@ -808,27 +775,27 @@ static int ov772x_s_ctrl(struct v4l2_ctrl *ctrl)
 		val = ctrl->val ? VFLIP_IMG : 0x00;
 		if (priv->info && (priv->info->flags & OV772X_FLAG_VFLIP))
 			val ^= VFLIP_IMG;
-		return ov772x_mask_set(client, COM3, VFLIP_IMG, val);
+		return regmap_update_bits(regmap, COM3, VFLIP_IMG, val);
 	case V4L2_CID_HFLIP:
 		val = ctrl->val ? HFLIP_IMG : 0x00;
 		if (priv->info && (priv->info->flags & OV772X_FLAG_HFLIP))
 			val ^= HFLIP_IMG;
-		return ov772x_mask_set(client, COM3, HFLIP_IMG, val);
+		return regmap_update_bits(regmap, COM3, HFLIP_IMG, val);
 	case V4L2_CID_BAND_STOP_FILTER:
 		if (!ctrl->val) {
 			/* Switch the filter off, it is on now */
-			ret = ov772x_mask_set(client, BDBASE, 0xff, 0xff);
+			ret = regmap_update_bits(regmap, BDBASE, 0xff, 0xff);
 			if (!ret)
-				ret = ov772x_mask_set(client, COM8,
-						      BNDF_ON_OFF, 0);
+				ret = regmap_update_bits(regmap, COM8,
+							 BNDF_ON_OFF, 0);
 		} else {
 			/* Switch the filter on, set AEC low limit */
 			val = 256 - ctrl->val;
-			ret = ov772x_mask_set(client, COM8,
-					      BNDF_ON_OFF, BNDF_ON_OFF);
+			ret = regmap_update_bits(regmap, COM8,
+						 BNDF_ON_OFF, BNDF_ON_OFF);
 			if (!ret)
-				ret = ov772x_mask_set(client, BDBASE,
-						      0xff, val);
+				ret = regmap_update_bits(regmap, BDBASE,
+							 0xff, val);
 		}
 
 		return ret;

drivers/media/i2c/ov772x.c static int ov772x_s_ctrl(struct v4l2_ctrl *ctrl) · line 813

Quoted 7 lines
drivers/media/i2c/ov772x.c +2 -1
@@ -841,18 +808,19 @@ static int ov772x_s_ctrl(struct v4l2_ctrl *ctrl)
 static int ov772x_g_register(struct v4l2_subdev *sd,
 			     struct v4l2_dbg_register *reg)
 {
-	struct i2c_client *client = v4l2_get_subdevdata(sd);
+	struct ov772x_priv *priv = to_ov772x(sd);
 	int ret;
+	unsigned int val;

Nit: please keep variables sorted (move 'val' declaration one line up).

Apart from that, for the ov772x driver:

Thanks
j

Quoted 280 lines
drivers/media/i2c/ov772x.c +59 -58
 	reg->size = 1;
 	if (reg->reg > 0xff)
 		return -EINVAL;
 
-	ret = ov772x_read(client, reg->reg);
+	ret = regmap_read(priv->regmap, reg->reg, &val);
 	if (ret < 0)
 		return ret;
 
-	reg->val = (__u64)ret;
+	reg->val = (__u64)val;
 
 	return 0;
 }
@@ -860,13 +828,13 @@ static int ov772x_g_register(struct v4l2_subdev *sd,
 static int ov772x_s_register(struct v4l2_subdev *sd,
 			     const struct v4l2_dbg_register *reg)
 {
-	struct i2c_client *client = v4l2_get_subdevdata(sd);
+	struct ov772x_priv *priv = to_ov772x(sd);
 
 	if (reg->reg > 0xff ||
 	    reg->val > 0xff)
 		return -EINVAL;
 
-	return ov772x_write(client, reg->reg, reg->val);
+	return regmap_write(priv->regmap, reg->reg, reg->val);
 }
 #endif
 
@@ -1004,7 +972,7 @@ static void ov772x_select_params(const struct v4l2_mbus_framefmt *mf,
 
 static int ov772x_edgectrl(struct ov772x_priv *priv)
 {
-	struct i2c_client *client = v4l2_get_subdevdata(&priv->subdev);
+	struct regmap *regmap = priv->regmap;
 	int ret;
 
 	if (!priv->info)
@@ -1018,19 +986,19 @@ static int ov772x_edgectrl(struct ov772x_priv *priv)
 		 * Remove it when manual mode.
 		 */
 
-		ret = ov772x_mask_set(client, DSPAUTO, EDGE_ACTRL, 0x00);
+		ret = regmap_update_bits(regmap, DSPAUTO, EDGE_ACTRL, 0x00);
 		if (ret < 0)
 			return ret;
 
-		ret = ov772x_mask_set(client,
-				      EDGE_TRSHLD, OV772X_EDGE_THRESHOLD_MASK,
-				      priv->info->edgectrl.threshold);
+		ret = regmap_update_bits(regmap, EDGE_TRSHLD,
+					 OV772X_EDGE_THRESHOLD_MASK,
+					 priv->info->edgectrl.threshold);
 		if (ret < 0)
 			return ret;
 
-		ret = ov772x_mask_set(client,
-				      EDGE_STRNGT, OV772X_EDGE_STRENGTH_MASK,
-				      priv->info->edgectrl.strength);
+		ret = regmap_update_bits(regmap, EDGE_STRNGT,
+					 OV772X_EDGE_STRENGTH_MASK,
+					 priv->info->edgectrl.strength);
 		if (ret < 0)
 			return ret;
 
@@ -1040,15 +1008,15 @@ static int ov772x_edgectrl(struct ov772x_priv *priv)
 		 *
 		 * Set upper and lower limit.
 		 */
-		ret = ov772x_mask_set(client,
-				      EDGE_UPPER, OV772X_EDGE_UPPER_MASK,
-				      priv->info->edgectrl.upper);
+		ret = regmap_update_bits(regmap, EDGE_UPPER,
+					 OV772X_EDGE_UPPER_MASK,
+					 priv->info->edgectrl.upper);
 		if (ret < 0)
 			return ret;
 
-		ret = ov772x_mask_set(client,
-				      EDGE_LOWER, OV772X_EDGE_LOWER_MASK,
-				      priv->info->edgectrl.lower);
+		ret = regmap_update_bits(regmap, EDGE_LOWER,
+					 OV772X_EDGE_LOWER_MASK,
+					 priv->info->edgectrl.lower);
 		if (ret < 0)
 			return ret;
 	}
@@ -1060,12 +1028,11 @@ static int ov772x_set_params(struct ov772x_priv *priv,
 			     const struct ov772x_color_format *cfmt,
 			     const struct ov772x_win_size *win)
 {
-	struct i2c_client *client = v4l2_get_subdevdata(&priv->subdev);
 	int ret;
 	u8  val;
 
 	/* Reset hardware. */
-	ov772x_reset(client);
+	ov772x_reset(priv);
 
 	/* Edge Ctrl. */
 	ret = ov772x_edgectrl(priv);
@@ -1073,32 +1040,32 @@ static int ov772x_set_params(struct ov772x_priv *priv,
 		return ret;
 
 	/* Format and window size. */
-	ret = ov772x_write(client, HSTART, win->rect.left >> 2);
+	ret = regmap_write(priv->regmap, HSTART, win->rect.left >> 2);
 	if (ret < 0)
 		goto ov772x_set_fmt_error;
-	ret = ov772x_write(client, HSIZE, win->rect.width >> 2);
+	ret = regmap_write(priv->regmap, HSIZE, win->rect.width >> 2);
 	if (ret < 0)
 		goto ov772x_set_fmt_error;
-	ret = ov772x_write(client, VSTART, win->rect.top >> 1);
+	ret = regmap_write(priv->regmap, VSTART, win->rect.top >> 1);
 	if (ret < 0)
 		goto ov772x_set_fmt_error;
-	ret = ov772x_write(client, VSIZE, win->rect.height >> 1);
+	ret = regmap_write(priv->regmap, VSIZE, win->rect.height >> 1);
 	if (ret < 0)
 		goto ov772x_set_fmt_error;
-	ret = ov772x_write(client, HOUTSIZE, win->rect.width >> 2);
+	ret = regmap_write(priv->regmap, HOUTSIZE, win->rect.width >> 2);
 	if (ret < 0)
 		goto ov772x_set_fmt_error;
-	ret = ov772x_write(client, VOUTSIZE, win->rect.height >> 1);
+	ret = regmap_write(priv->regmap, VOUTSIZE, win->rect.height >> 1);
 	if (ret < 0)
 		goto ov772x_set_fmt_error;
-	ret = ov772x_write(client, HREF,
+	ret = regmap_write(priv->regmap, HREF,
 			   ((win->rect.top & 1) << HREF_VSTART_SHIFT) |
 			   ((win->rect.left & 3) << HREF_HSTART_SHIFT) |
 			   ((win->rect.height & 1) << HREF_VSIZE_SHIFT) |
 			   ((win->rect.width & 3) << HREF_HSIZE_SHIFT));
 	if (ret < 0)
 		goto ov772x_set_fmt_error;
-	ret = ov772x_write(client, EXHCH,
+	ret = regmap_write(priv->regmap, EXHCH,
 			   ((win->rect.height & 1) << EXHCH_VSIZE_SHIFT) |
 			   ((win->rect.width & 3) << EXHCH_HSIZE_SHIFT));
 	if (ret < 0)
@@ -1107,15 +1074,14 @@ static int ov772x_set_params(struct ov772x_priv *priv,
 	/* Set DSP_CTRL3. */
 	val = cfmt->dsp3;
 	if (val) {
-		ret = ov772x_mask_set(client,
-				      DSP_CTRL3, UV_MASK, val);
+		ret = regmap_update_bits(priv->regmap, DSP_CTRL3, UV_MASK, val);
 		if (ret < 0)
 			goto ov772x_set_fmt_error;
 	}
 
 	/* DSP_CTRL4: AEC reference point and DSP output format. */
 	if (cfmt->dsp4) {
-		ret = ov772x_write(client, DSP_CTRL4, cfmt->dsp4);
+		ret = regmap_write(priv->regmap, DSP_CTRL4, cfmt->dsp4);
 		if (ret < 0)
 			goto ov772x_set_fmt_error;
 	}
@@ -1131,13 +1097,12 @@ static int ov772x_set_params(struct ov772x_priv *priv,
 	if (priv->hflip_ctrl->val)
 		val ^= HFLIP_IMG;
 
-	ret = ov772x_mask_set(client,
-			      COM3, SWAP_MASK | IMG_MASK, val);
+	ret = regmap_update_bits(priv->regmap, COM3, SWAP_MASK | IMG_MASK, val);
 	if (ret < 0)
 		goto ov772x_set_fmt_error;
 
 	/* COM7: Sensor resolution and output format control. */
-	ret = ov772x_write(client, COM7, win->com7_bit | cfmt->com7);
+	ret = regmap_write(priv->regmap, COM7, win->com7_bit | cfmt->com7);
 	if (ret < 0)
 		goto ov772x_set_fmt_error;
 
@@ -1150,10 +1115,11 @@ static int ov772x_set_params(struct ov772x_priv *priv,
 	if (priv->band_filter_ctrl->val) {
 		unsigned short band_filter = priv->band_filter_ctrl->val;
 
-		ret = ov772x_mask_set(client, COM8, BNDF_ON_OFF, BNDF_ON_OFF);
+		ret = regmap_update_bits(priv->regmap, COM8,
+					 BNDF_ON_OFF, BNDF_ON_OFF);
 		if (!ret)
-			ret = ov772x_mask_set(client, BDBASE,
-					      0xff, 256 - band_filter);
+			ret = regmap_update_bits(priv->regmap, BDBASE,
+						 0xff, 256 - band_filter);
 		if (ret < 0)
 			goto ov772x_set_fmt_error;
 	}
@@ -1162,7 +1128,7 @@ static int ov772x_set_params(struct ov772x_priv *priv,
 
 ov772x_set_fmt_error:
 
-	ov772x_reset(client);
+	ov772x_reset(priv);
 
 	return ret;
 }
@@ -1276,12 +1242,12 @@ static int ov772x_video_probe(struct ov772x_priv *priv)
 		return ret;
 
 	/* Check and show product ID and manufacturer ID. */
-	pid = ov772x_read(client, PID);
-	if (pid < 0)
-		return pid;
-	ver = ov772x_read(client, VER);
-	if (ver < 0)
-		return ver;
+	ret = regmap_read(priv->regmap, PID, &pid);
+	if (ret < 0)
+		return ret;
+	ret = regmap_read(priv->regmap, VER, &ver);
+	if (ret < 0)
+		return ret;
 
 	switch (VERSION(pid, ver)) {
 	case OV7720:
@@ -1297,12 +1263,12 @@ static int ov772x_video_probe(struct ov772x_priv *priv)
 		goto done;
 	}
 
-	midh = ov772x_read(client, MIDH);
-	if (midh < 0)
-		return midh;
-	midl = ov772x_read(client, MIDL);
-	if (midl < 0)
-		return midl;
+	ret = regmap_read(priv->regmap, MIDH, &midh);
+	if (ret < 0)
+		return ret;
+	ret = regmap_read(priv->regmap, MIDL, &midl);
+	if (ret < 0)
+		return ret;
 
 	dev_info(&client->dev,
 		 "%s Product ID %0x:%0x Manufacturer ID %x:%x\n",
@@ -1386,8 +1352,12 @@ static int ov772x_probe(struct i2c_client *client,
 			const struct i2c_device_id *did)
 {
 	struct ov772x_priv	*priv;
-	struct i2c_adapter	*adapter = client->adapter;
 	int			ret;
+	static const struct regmap_config ov772x_regmap_config = {
+		.reg_bits = 8,
+		.val_bits = 8,
+		.max_register = DSPAUTO,
+	};
 
 	if (!client->dev.of_node && !client->dev.platform_data) {
 		dev_err(&client->dev,
@@ -1395,16 +1365,16 @@ static int ov772x_probe(struct i2c_client *client,
 		return -EINVAL;
 	}
 
-	if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
-		dev_err(&adapter->dev,
-			"I2C-Adapter doesn't support SMBUS_BYTE_DATA\n");
-		return -EIO;
-	}
-
 	priv = devm_kzalloc(&client->dev, sizeof(*priv), GFP_KERNEL);
 	if (!priv)
 		return -ENOMEM;
 
+	priv->regmap = devm_regmap_init_sccb(client, &ov772x_regmap_config);
+	if (IS_ERR(priv->regmap)) {
+		dev_err(&client->dev, "Failed to allocate register map\n");
+		return PTR_ERR(priv->regmap);
+	}
+
 	priv->info = client->dev.platform_data;
 	mutex_init(&priv->lock);
 
--

2.7.4

#12 lore raw

Re: [PATCH -next v4 2/3] media: ov772x: use SCCB regmap

Quoted 11 lines
Quoted 11 lines
drivers/media/i2c/ov772x.c +0 -10
-static int ov772x_mask_set(struct i2c_client *client, u8  command, u8  mask,
-			   u8  set)
-{
-	s32 val = ov772x_read(client, command);
-
-	if (val < 0)
-		return val;
-
-	val &= ~mask;
-	val |= set & mask;
Quoted 8 lines

drivers/media/i2c/ov772x.c static struct ov772x_priv *to_ov772x(struct v4l2_subdev *sd) · line 585

Quoted 4 lines
drivers/media/i2c/ov772x.c +0 -4
-
-	return ov772x_write(client, command, val);
-}
-

If I were you I would have kept these functions and wrapped the regmap operations there. This is not an issue though if you prefer it this way :)

I have suggested this way. It is not a show stopper issue, but I still like this version better.

#13 lore raw

Re: [PATCH -next v4 2/3] media: ov772x: use SCCB regmap

Quoted 20 lines · On Thursday, 19 July 2018 11:42:08 EEST Wolfram Sang wrote:
Quoted 11 lines
Quoted 11 lines

-static int ov772x_mask_set(struct i2c_client *client, u8 command, u8 mask,

drivers/media/i2c/ov772x.c +0 -9
-			   u8  set)
-{
-	s32 val = ov772x_read(client, command);
-
-	if (val < 0)
-		return val;
-
-	val &= ~mask;
-	val |= set & mask;
Quoted 8 lines

drivers/media/i2c/ov772x.c static struct ov772x_priv *to_ov772x(struct v4l2_subdev *sd) · line 585

Quoted 4 lines
drivers/media/i2c/ov772x.c +0 -4
-
-	return ov772x_write(client, command, val);
-}
-

If I were you I would have kept these functions and wrapped the regmap operations there. This is not an issue though if you prefer it this way :)

Quoted 2 lines

I have suggested this way. It is not a show stopper issue, but I still like this version better.

Wrapping the regmap functions minimizes the diff and makes it easier to backport the driver.

Signature · 3 lines
Regards,

Laurent Pinchart
#14 lore raw

Re: [PATCH -next v4 2/3] media: ov772x: use SCCB regmap

Quoted 21 lines · Laurent Pinchart
Quoted 20 lines · On Thursday, 19 July 2018 11:42:08 EEST Wolfram Sang wrote:
Quoted 19 lines
Quoted 5 lines

-static int ov772x_mask_set(struct i2c_client *client, u8 command, u8 mask,

drivers/media/i2c/ov772x.c +0 -3
-			   u8  set)
-{
-	s32 val = ov772x_read(client, command);

drivers/media/i2c/ov772x.c static struct ov772x_priv *to_ov772x(struct v4l2_subdev *sd) · line 585

Quoted 10 lines
drivers/media/i2c/ov772x.c +0 -10
-
-	if (val < 0)
-		return val;
-
-	val &= ~mask;
-	val |= set & mask;
-
-	return ov772x_write(client, command, val);
-}
-

If I were you I would have kept these functions and wrapped the regmap operations there. This is not an issue though if you prefer it this way :)

Quoted 5 lines
Quoted 2 lines

I have suggested this way. It is not a show stopper issue, but I still like this version better.

Wrapping the regmap functions minimizes the diff and makes it easier to backport the driver.

May be, but using the regmap functions directly makes the driver cleaner. Most drivers have some kind of wrappers around the I²C framework (or regmap) functions; this one is one of the few to get rid of them.

The two could be done in a separate patch, too, albeit I think the current one seems fine as such.

Signature · 2 lines
Sakari Ailus
e-mail: [email protected]
maintainer
#15 lore raw

Re: [PATCH -next v4 2/3] media: ov772x: use SCCB regmap

Hi all,

Quoted 22 lines · On Thu, Jul 19, 2018 at 04:10:20PM +0300, [email protected] wrote:
Quoted 21 lines · Laurent Pinchart
Quoted 20 lines · On Thursday, 19 July 2018 11:42:08 EEST Wolfram Sang wrote:
Quoted 19 lines
Quoted 5 lines

-static int ov772x_mask_set(struct i2c_client *client, u8 command, u8 mask,

drivers/media/i2c/ov772x.c +0 -3
-			   u8  set)
-{
-	s32 val = ov772x_read(client, command);

drivers/media/i2c/ov772x.c static struct ov772x_priv *to_ov772x(struct v4l2_subdev *sd) · line 585

Quoted 10 lines
drivers/media/i2c/ov772x.c +0 -10
-
-	if (val < 0)
-		return val;
-
-	val &= ~mask;
-	val |= set & mask;
-
-	return ov772x_write(client, command, val);
-}
-

If I were you I would have kept these functions and wrapped the regmap operations there. This is not an issue though if you prefer it this way :)

Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

I have suggested this way. It is not a show stopper issue, but I still like this version better.

Wrapping the regmap functions minimizes the diff and makes it easier to backport the driver.

This was my reasoning too, but I'm happy with the current implementation. Thanks Akinobu for handling this!

Quoted 11 lines

May be, but using the regmap functions directly makes the driver cleaner. Most drivers have some kind of wrappers around the I²C framework (or regmap) functions; this one is one of the few to get rid of them.

The two could be done in a separate patch, too, albeit I think the current one seems fine as such.

--
Sakari Ailus
e-mail: [email protected]

#16 lore raw

Re: [PATCH -next v4 2/3] media: ov772x: use SCCB regmap

In reply to Akinobu Mita

Hi Mita-san,

Quoted 13 lines · Akinobu Mita

Convert ov772x register access to use SCCB regmap.

Cc Mark Brown <[email protected]>
Cc Peter Rosin <[email protected]>
Cc Sebastian Reichel <[email protected]>
Cc Wolfram Sang <[email protected]>
Cc Sylwester Nawrocki <[email protected]>
Cc Jacopo Mondi <[email protected]>
Cc Laurent Pinchart <[email protected]>
Cc Hans Verkuil <[email protected]>
Cc Sakari Ailus <[email protected]>
Cc Mauro Carvalho Chehab <[email protected]>
Quoted 4 lines
---
 drivers/media/i2c/Kconfig  |   1 +
 drivers/media/i2c/ov772x.c | 192 +++++++++++++++++++--------------------------
 2 files changed, 82 insertions(+), 111 deletions(-)

I'll pick the two patches up when the SCCB regmap support has reached media tree master. Thanks.

Signature · 2 lines
Sakari Ailus
e-mail: [email protected]
author reviewer
#17 lore raw

PATCH v4 3/3 media: ov9650: use SCCB regmap

In reply to Akinobu Mita

Convert ov965x register access to use SCCB regmap.

Cc Mark Brown <[email protected]>
Cc Peter Rosin <[email protected]>
Cc Sebastian Reichel <[email protected]>
Cc Wolfram Sang <[email protected]>
Cc Sylwester Nawrocki <[email protected]>
Cc Jacopo Mondi <[email protected]>
Cc Laurent Pinchart <[email protected]>
Cc Hans Verkuil <[email protected]>
Cc Sakari Ailus <[email protected]>
Cc Mauro Carvalho Chehab <[email protected]>
---
 drivers/media/i2c/Kconfig  |   1 +
 drivers/media/i2c/ov9650.c | 157 ++++++++++++++++++++++-----------------------
 2 files changed, 76 insertions(+), 82 deletions(-)
drivers/media/i2c/Kconfig +1 -0
index b923a51..7028824 100644
@@ -755,6 +755,7 @@ config VIDEO_OV7740
 config VIDEO_OV9650
 	tristate "OmniVision OV9650/OV9652 sensor support"
 	depends on I2C && VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API
+	select REGMAP_SCCB
 	---help---
 	  This is a V4L2 sensor-level driver for the Omnivision
 	  OV9650 and OV9652 camera sensors.
drivers/media/i2c/ov9650.c +75 -82

473 lines not on this page · raw message

Signature · 1 line
2.7.4
Acked-by on v4 3/3
#18 lore raw

Re: [PATCH -next v4 3/3] media: ov9650: use SCCB regmap

Quoted 13 lines · Akinobu Mita

Convert ov965x register access to use SCCB regmap.

Cc Mark Brown <[email protected]>
Cc Peter Rosin <[email protected]>
Cc Sebastian Reichel <[email protected]>
Cc Wolfram Sang <[email protected]>
Cc Sylwester Nawrocki <[email protected]>
Cc Jacopo Mondi <[email protected]>
Cc Laurent Pinchart <[email protected]>
Cc Hans Verkuil <[email protected]>
Cc Sakari Ailus <[email protected]>
Cc Mauro Carvalho Chehab <[email protected]>

Again, for the I2C parts: