From 86f4fd9830600c2ffe9fbdb169a356a5a623fb0c Mon Sep 17 00:00:00 2001
From: Vladimir Barinov <vladimir.barinov@cogentembedded.com>
Date: Thu, 25 Apr 2019 22:33:55 +0300
Subject: [PATCH 110/122] lvds: AR0233: add module trigger parameter

This add trigger as module parameter or dts since this is hardware
dependent

Signed-off-by: Vladimir Barinov <vladimir.barinov@cogentembedded.com>
---
 drivers/media/i2c/soc_camera/ar0233.c      | 20 ++++++++++++++++++--
 drivers/media/i2c/soc_camera/ar0233_rev1.h |  8 --------
 drivers/media/i2c/soc_camera/ar0233_rev2.h |  9 ---------
 3 files changed, 18 insertions(+), 19 deletions(-)

diff --git a/drivers/media/i2c/soc_camera/ar0233.c b/drivers/media/i2c/soc_camera/ar0233.c
index e18fa55..8257cf1 100644
--- a/drivers/media/i2c/soc_camera/ar0233.c
+++ b/drivers/media/i2c/soc_camera/ar0233.c
@@ -41,10 +41,13 @@ struct ar0233_priv {
 	int				ti9x4_addr;
 	int				ti9x3_addr;
 	int				port;
-	int				gpio_resetb;
-	int				gpio_fsin;
+	int				trigger;
 };
 
+static int trigger = 0;
+module_param(trigger, int, 0644);
+MODULE_PARM_DESC(trigger, " Trigger gpio number (default: 0 - GPIO0) ");
+
 static inline struct ar0233_priv *to_ar0233(const struct i2c_client *client)
 {
 	return container_of(i2c_get_clientdata(client), struct ar0233_priv, sd);
@@ -421,8 +424,15 @@ static int ar0233_initialize(struct i2c_client *client)
 		dev_err(&client->dev, "Unsupported chip revision\n");
 	}
 
+	/* Enable trigger*/
+	reg16_write16(client, 0x340A, (~(BIT(priv->trigger) << 4)) & 0xf0);	/* GPIO_CONTROL1: GPIOn input enable */
+	reg16_write16(client, 0x340C, (0x2 << 2*priv->trigger));		/* GPIO_CONTROL2: GPIOn is trigger */
+	reg16_write16(client, 0x30CE, 0x0120);					/* TRIGGER_MODE */
+	//reg16_write16(client, 0x30DC, 0x0120);				/* TRIGGER_DELAY */
+
 	/* Enable stream */
 	reg16_read16(client, 0x301a, &val);	// read inital reset_register value
+	val |= (1 << 8);			/* GPI pins enable */
 	val |= (1 << 2);			// Set streamOn bit
 	reg16_write16(client, 0x301a, val);	// Start Streaming
 
@@ -444,6 +454,8 @@ static int ar0233_parse_dt(struct device_node *np, struct ar0233_priv *priv)
 		if (!endpoint)
 			break;
 
+		of_property_read_u32(endpoint, "trigger", &priv->trigger);
+
 		rendpoint = of_parse_phandle(endpoint, "remote-endpoint", 0);
 		if (!rendpoint)
 			continue;
@@ -473,6 +485,10 @@ static int ar0233_parse_dt(struct device_node *np, struct ar0233_priv *priv)
 	}
 	client->addr = tmp_addr;
 
+	/* module params override dts */
+	if (trigger)
+		priv->trigger = trigger;
+
 	return 0;
 }
 
diff --git a/drivers/media/i2c/soc_camera/ar0233_rev1.h b/drivers/media/i2c/soc_camera/ar0233_rev1.h
index c29ac6a..288b465 100644
--- a/drivers/media/i2c/soc_camera/ar0233_rev1.h
+++ b/drivers/media/i2c/soc_camera/ar0233_rev1.h
@@ -1247,12 +1247,4 @@ static const struct ar0233_reg ar0233_regs_wizard_rev1[] = {
 {0x3D14, 0x001E},
 {0x3D16, 0x045E},
 #endif /* MEC DLO default */
-
-#if 1 /* Enable_trigger_input */
-{0x340A, 0x0070}, // GPIO_CONTROL1: GPIO1 is trigger
-{0x340C, 0x0080}, // GPIO_CONTROL2: GPIO1 is trigger
-{0x30CE, 0x0120}, // TRIGGER_MODE
-//{0x30DC, 0x0120}, // TRIGGER_DELAY
-{0x301A, 0x0118}, // GPI pins enable
-#endif /* Enable_trigger_input */
 };
diff --git a/drivers/media/i2c/soc_camera/ar0233_rev2.h b/drivers/media/i2c/soc_camera/ar0233_rev2.h
index f4b75a2..0dea2dd 100644
--- a/drivers/media/i2c/soc_camera/ar0233_rev2.h
+++ b/drivers/media/i2c/soc_camera/ar0233_rev2.h
@@ -28,7 +28,6 @@
 #define MIPI_DT_bit12
 #define LUT_24_to_12
 #define HDR_ratio_gain_default
-#define Enable_trigger_input
 
 /* 3Exp HDR 1280P Mipi_12bit_4lane_30fps, XCLK=27MHz */
 static const struct ar0233_reg ar0233_regs_wizard_rev2[] = {
@@ -1249,12 +1248,4 @@ static const struct ar0233_reg ar0233_regs_wizard_rev2[] = {
 {0x300A, AR0233_SENSOR_HEIGHT + 100}, // Frame_length_Lines
 {0x300C, AR0233_SENSOR_WIDTH + 400}, // Line_length_pck
 {0x3012, 0x144}, //Integration_time
-
-#ifdef Enable_trigger_input
-{0x340A, 0x0070}, // GPIO_CONTROL1: GPIO1 is trigger
-{0x340C, 0x0080}, // GPIO_CONTROL2: GPIO1 is trigger
-{0x30CE, 0x0120}, // TRIGGER_MODE
-//{0x30DC, 0x0120}, // TRIGGER_DELAY
-{0x301A, 0x0118}, // GPI pins enable
-#endif /* Enable_trigger_input */
 };
-- 
2.7.4

