From fa541006e93ceccfbee6a8b89026c3aa96036c16 Mon Sep 17 00:00:00 2001 From: Vladimir Barinov Date: Sat, 16 Mar 2019 10:28:42 +0300 Subject: [PATCH 106/122] AR0143: add choose of imager setup in command line: ar0143.setup=0 - choose custom setup ar0143.setup=1 - choose ONSEMI rev1 setup (default) Signed-off-by: Vladimir Barinov --- drivers/media/i2c/soc_camera/ar0143.c | 41 ++++++++++++++++++++++++++--------- drivers/media/i2c/soc_camera/ar0143.h | 2 +- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/drivers/media/i2c/soc_camera/ar0143.c b/drivers/media/i2c/soc_camera/ar0143.c index 65dc4fb..b0ed9ff 100644 --- a/drivers/media/i2c/soc_camera/ar0143.c +++ b/drivers/media/i2c/soc_camera/ar0143.c @@ -25,6 +25,7 @@ #define AR0143_I2C_ADDR 0x10 #define AR0143_PID 0x3000 +#define AR0143_REV 0x300E #define AR0143_VERSION_REG 0x0D54 #define AR0143_MEDIA_BUS_FMT MEDIA_BUS_FMT_SGRBG12_1X12 @@ -36,6 +37,7 @@ struct ar0143_priv { struct v4l2_rect rect; int init_complete; u8 id[6]; + int setup; /* serializers */ int max9286_addr; int max9271_addr; @@ -49,6 +51,10 @@ struct ar0143_priv { int frame_preamble; }; +static int setup = 1; +module_param(setup, int, 0644); +MODULE_PARM_DESC(setup, " Forse setup (default: 1 - rev1)"); + static inline struct ar0143_priv *to_ar0143(const struct i2c_client *client) { return container_of(i2c_get_clientdata(client), struct ar0143_priv, sd); @@ -432,7 +438,7 @@ static int ar0143_initialize(struct i2c_client *client) { struct ar0143_priv *priv = to_ar0143(client); u16 val = 0; - u16 pid = 0; + u16 pid = 0, rev = 0; int ret = 0; int tmp_addr; @@ -447,8 +453,19 @@ static int ar0143_initialize(struct i2c_client *client) goto err; } + /* check revision */ + reg16_read16(client, AR0143_REV, &rev); + /* Read OTP IDs */ + ar0143_otp_id_read(client); /* Program wizard registers */ - ar0143_set_regs(client, ar0143_regs_wizard_rev1, ARRAY_SIZE(ar0143_regs_wizard_rev1)); + switch (priv->setup) { + case 0: + ar0143_set_regs(client, ar0143_regs_wizard_custom, ARRAY_SIZE(ar0143_regs_wizard_custom)); + break; + case 1: + default: + ar0143_set_regs(client, ar0143_regs_wizard_rev1, ARRAY_SIZE(ar0143_regs_wizard_rev1)); + } tmp_addr = client->addr; if (priv->max9271_addr) { @@ -467,15 +484,12 @@ static int ar0143_initialize(struct i2c_client *client) client->addr = tmp_addr; /* Enable stream */ - reg16_read16(client, 0x301a, &val); // read inital reset_register value - val |= (1 << 2); // Set streamOn bit - reg16_write16(client, 0x301a, val); // Start Streaming + reg16_read16(client, 0x301a, &val); + val |= (1 << 2); + reg16_write16(client, 0x301a, val); - /* Read OTP IDs */ - ar0143_otp_id_read(client); - - dev_info(&client->dev, "ar0143 PID %x, res %dx%d, OTP_ID %02x:%02x:%02x:%02x:%02x:%02x\n", - pid, AR0143_MAX_WIDTH, AR0143_MAX_HEIGHT, priv->id[0], priv->id[1], priv->id[2], priv->id[3], priv->id[4], priv->id[5]); + dev_info(&client->dev, "ar0143 PID %x (rev %x), res %dx%d, OTP_ID %02x:%02x:%02x:%02x:%02x:%02x\n", + pid, rev, AR0143_MAX_WIDTH, AR0143_MAX_HEIGHT, priv->id[0], priv->id[1], priv->id[2], priv->id[3], priv->id[4], priv->id[5]); err: ar0143_s_port(client, 0); @@ -489,6 +503,9 @@ static int ar0143_parse_dt(struct device_node *np, struct ar0143_priv *priv) struct device_node *endpoint = NULL, *rendpoint = NULL; int tmp_addr = 0; + if (of_property_read_u32(np, "onnn,setup", &priv->setup)) + priv->setup = 1; + for (i = 0; ; i++) { endpoint = of_graph_get_next_endpoint(np, endpoint); if (!endpoint) @@ -542,6 +559,10 @@ static int ar0143_parse_dt(struct device_node *np, struct ar0143_priv *priv) mdelay(10); + /* module params override dts */ + if (setup != 1) + priv->setup = setup; + return 0; } diff --git a/drivers/media/i2c/soc_camera/ar0143.h b/drivers/media/i2c/soc_camera/ar0143.h index 042dd50..14d8175 100644 --- a/drivers/media/i2c/soc_camera/ar0143.h +++ b/drivers/media/i2c/soc_camera/ar0143.h @@ -32,5 +32,5 @@ struct ar0143_reg { u16 val; }; -//#include "ar0143_custom.h" +#include "ar0143_custom.h" #include "ar0143_rev1.h" -- 2.7.4