All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] media: i2c: video-i2c: Minor corrections
@ 2022-04-19 20:20 Moses Christopher Bollavarapu
  2022-04-19 20:20 ` [PATCH 1/3] media: i2c: video-i2c: Move defines to the top of the file Moses Christopher Bollavarapu
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Moses Christopher Bollavarapu @ 2022-04-19 20:20 UTC (permalink / raw)
  To: matt.ranostay, mchehab, linux-media, linux-kernel
  Cc: Moses Christopher Bollavarapu

* Move define statements to the top of the file
* Add ram and eeprom start addr as define statements
* fix masking of bits using GENMASK macro from bits.h

Moses Christopher Bollavarapu (3):
  media: i2c: video-i2c: Move defines to the top of the file
  media: i2c: video-i2c: Replace constants with proper names
  media: i2c: video-i2c: Use GENMASK for masking bits

 drivers/media/i2c/video-i2c.c | 61 +++++++++++++++++++----------------
 1 file changed, 34 insertions(+), 27 deletions(-)

-- 
2.30.2


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/3] media: i2c: video-i2c: Move defines to the top of the file
  2022-04-19 20:20 [PATCH 0/3] media: i2c: video-i2c: Minor corrections Moses Christopher Bollavarapu
@ 2022-04-19 20:20 ` Moses Christopher Bollavarapu
  2022-04-19 20:20 ` [PATCH 2/3] media: i2c: video-i2c: Replace constants with proper names Moses Christopher Bollavarapu
  2022-04-19 20:20 ` [PATCH 3/3] media: i2c: video-i2c: Use GENMASK for masking bits Moses Christopher Bollavarapu
  2 siblings, 0 replies; 4+ messages in thread
From: Moses Christopher Bollavarapu @ 2022-04-19 20:20 UTC (permalink / raw)
  To: matt.ranostay, mchehab, linux-media, linux-kernel
  Cc: Moses Christopher Bollavarapu

Currently, the defines in this driver are after some structs and
functions, it makes more sense to move them up to the top of the file,
so that the constants can be named together with other defines.

Signed-off-by: Moses Christopher Bollavarapu <mosescb.dev@gmail.com>
---
 drivers/media/i2c/video-i2c.c | 50 +++++++++++++++++------------------
 1 file changed, 25 insertions(+), 25 deletions(-)

diff --git a/drivers/media/i2c/video-i2c.c b/drivers/media/i2c/video-i2c.c
index cb660b4bfd4b..b3fe9a507f7f 100644
--- a/drivers/media/i2c/video-i2c.c
+++ b/drivers/media/i2c/video-i2c.c
@@ -34,6 +34,31 @@
 
 #define VIDEO_I2C_DRIVER	"video-i2c"
 
+/* Power control register */
+#define AMG88XX_REG_PCTL	0x00
+#define AMG88XX_PCTL_NORMAL		0x00
+#define AMG88XX_PCTL_SLEEP		0x10
+
+/* Reset register */
+#define AMG88XX_REG_RST		0x01
+#define AMG88XX_RST_FLAG		0x30
+#define AMG88XX_RST_INIT		0x3f
+
+/* Frame rate register */
+#define AMG88XX_REG_FPSC	0x02
+#define AMG88XX_FPSC_1FPS		BIT(0)
+
+/* Thermistor register */
+#define AMG88XX_REG_TTHL	0x0e
+
+/* Temperature register */
+#define AMG88XX_REG_T01L	0x80
+
+/* Control register */
+#define MLX90640_REG_CTL1		0x800d
+#define MLX90640_REG_CTL1_MASK		0x0380
+#define MLX90640_REG_CTL1_MASK_SHIFT	7
+
 struct video_i2c_chip;
 
 struct video_i2c_buffer {
@@ -135,31 +160,6 @@ static struct nvmem_config mlx90640_nvram_config = {
 	.reg_read = mlx90640_nvram_read,
 };
 
-/* Power control register */
-#define AMG88XX_REG_PCTL	0x00
-#define AMG88XX_PCTL_NORMAL		0x00
-#define AMG88XX_PCTL_SLEEP		0x10
-
-/* Reset register */
-#define AMG88XX_REG_RST		0x01
-#define AMG88XX_RST_FLAG		0x30
-#define AMG88XX_RST_INIT		0x3f
-
-/* Frame rate register */
-#define AMG88XX_REG_FPSC	0x02
-#define AMG88XX_FPSC_1FPS		BIT(0)
-
-/* Thermistor register */
-#define AMG88XX_REG_TTHL	0x0e
-
-/* Temperature register */
-#define AMG88XX_REG_T01L	0x80
-
-/* Control register */
-#define MLX90640_REG_CTL1		0x800d
-#define MLX90640_REG_CTL1_MASK		0x0380
-#define MLX90640_REG_CTL1_MASK_SHIFT	7
-
 static int amg88xx_xfer(struct video_i2c_data *data, char *buf)
 {
 	return regmap_bulk_read(data->regmap, AMG88XX_REG_T01L, buf,
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/3] media: i2c: video-i2c: Replace constants with proper names
  2022-04-19 20:20 [PATCH 0/3] media: i2c: video-i2c: Minor corrections Moses Christopher Bollavarapu
  2022-04-19 20:20 ` [PATCH 1/3] media: i2c: video-i2c: Move defines to the top of the file Moses Christopher Bollavarapu
@ 2022-04-19 20:20 ` Moses Christopher Bollavarapu
  2022-04-19 20:20 ` [PATCH 3/3] media: i2c: video-i2c: Use GENMASK for masking bits Moses Christopher Bollavarapu
  2 siblings, 0 replies; 4+ messages in thread
From: Moses Christopher Bollavarapu @ 2022-04-19 20:20 UTC (permalink / raw)
  To: matt.ranostay, mchehab, linux-media, linux-kernel
  Cc: Moses Christopher Bollavarapu

Acc to MLX90640 datasheet:
 - 0x0400 represents the start of RAM address
 - 0x2400 represents the start of EEPROM address

Reference: https://www.melexis.com/-/media/files/documents\
           /datasheets/mlx90640-datasheet-melexis.pdf

Signed-off-by: Moses Christopher Bollavarapu <mosescb.dev@gmail.com>
---
 drivers/media/i2c/video-i2c.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/media/i2c/video-i2c.c b/drivers/media/i2c/video-i2c.c
index b3fe9a507f7f..1d5f48329cb2 100644
--- a/drivers/media/i2c/video-i2c.c
+++ b/drivers/media/i2c/video-i2c.c
@@ -54,6 +54,12 @@
 /* Temperature register */
 #define AMG88XX_REG_T01L	0x80
 
+/* RAM */
+#define MLX90640_RAM_START_ADDR		0x0400
+
+/* EEPROM */
+#define MLX90640_EEPROM_START_ADDR	0x2400
+
 /* Control register */
 #define MLX90640_REG_CTL1		0x800d
 #define MLX90640_REG_CTL1_MASK		0x0380
@@ -149,7 +155,7 @@ static int mlx90640_nvram_read(void *priv, unsigned int offset, void *val,
 {
 	struct video_i2c_data *data = priv;
 
-	return regmap_bulk_read(data->regmap, 0x2400 + offset, val, bytes);
+	return regmap_bulk_read(data->regmap, MLX90640_EEPROM_START_ADDR + offset, val, bytes);
 }
 
 static struct nvmem_config mlx90640_nvram_config = {
@@ -168,7 +174,7 @@ static int amg88xx_xfer(struct video_i2c_data *data, char *buf)
 
 static int mlx90640_xfer(struct video_i2c_data *data, char *buf)
 {
-	return regmap_bulk_read(data->regmap, 0x400, buf,
+	return regmap_bulk_read(data->regmap, MLX90640_RAM_START_ADDR, buf,
 				data->chip->buffer_size);
 }
 
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 3/3] media: i2c: video-i2c: Use GENMASK for masking bits
  2022-04-19 20:20 [PATCH 0/3] media: i2c: video-i2c: Minor corrections Moses Christopher Bollavarapu
  2022-04-19 20:20 ` [PATCH 1/3] media: i2c: video-i2c: Move defines to the top of the file Moses Christopher Bollavarapu
  2022-04-19 20:20 ` [PATCH 2/3] media: i2c: video-i2c: Replace constants with proper names Moses Christopher Bollavarapu
@ 2022-04-19 20:20 ` Moses Christopher Bollavarapu
  2 siblings, 0 replies; 4+ messages in thread
From: Moses Christopher Bollavarapu @ 2022-04-19 20:20 UTC (permalink / raw)
  To: matt.ranostay, mchehab, linux-media, linux-kernel
  Cc: Moses Christopher Bollavarapu

Replace 0x0380 with GENMASK(9, 7) to obtain 0b0000_0011_1000_0000

Signed-off-by: Moses Christopher Bollavarapu <mosescb.dev@gmail.com>
---
 drivers/media/i2c/video-i2c.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/media/i2c/video-i2c.c b/drivers/media/i2c/video-i2c.c
index 1d5f48329cb2..e08e3579c0a1 100644
--- a/drivers/media/i2c/video-i2c.c
+++ b/drivers/media/i2c/video-i2c.c
@@ -9,6 +9,7 @@
  * - Melexis MLX90640 Thermal Cameras
  */
 
+#include <linux/bits.h>
 #include <linux/delay.h>
 #include <linux/freezer.h>
 #include <linux/hwmon.h>
@@ -62,7 +63,7 @@
 
 /* Control register */
 #define MLX90640_REG_CTL1		0x800d
-#define MLX90640_REG_CTL1_MASK		0x0380
+#define MLX90640_REG_CTL1_MASK		GENMASK(9, 7)
 #define MLX90640_REG_CTL1_MASK_SHIFT	7
 
 struct video_i2c_chip;
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-04-19 20:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-19 20:20 [PATCH 0/3] media: i2c: video-i2c: Minor corrections Moses Christopher Bollavarapu
2022-04-19 20:20 ` [PATCH 1/3] media: i2c: video-i2c: Move defines to the top of the file Moses Christopher Bollavarapu
2022-04-19 20:20 ` [PATCH 2/3] media: i2c: video-i2c: Replace constants with proper names Moses Christopher Bollavarapu
2022-04-19 20:20 ` [PATCH 3/3] media: i2c: video-i2c: Use GENMASK for masking bits Moses Christopher Bollavarapu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.