mirror of
git://nv-tegra.nvidia.com/linux-nv-oot.git
synced 2025-12-22 17:25:35 +03:00
media: i2c: enable IMX390 WDR mode
Enable WDR(wide dynamic range) mode for IMX390. The following modification and addition are done: 1 Add WDR mode table 2 Restructure IMX390 driver for WDR gain and framerate 3 Use common driver to configure serializer(max9295) and deserializer(max9296) Bug 4505240 Change-Id: I52fc3f03a66fe4e2446d7b41f409ed4154c42f02 Signed-off-by: Ankur Pawar <ankurp@nvidia.com> Reviewed-on: https://git-master.nvidia.com/r/c/linux-nv-oot/+/3105249 Reviewed-by: Narendra Kondapalli <nkondapalli@nvidia.com> Reviewed-by: Shubham Chandra <shubhamc@nvidia.com> GVS: buildbot_gerritrpt <buildbot_gerritrpt@nvidia.com> Reviewed-by: Praveen AC <pac@nvidia.com>
This commit is contained in:
committed by
mobile promotions
parent
517660e465
commit
adc35280cb
@@ -20,6 +20,7 @@ obj-m += nv_imx477.o
|
|||||||
obj-m += nv_ov5693.o
|
obj-m += nv_ov5693.o
|
||||||
obj-m += nv_ar0234.o
|
obj-m += nv_ar0234.o
|
||||||
obj-m += nv_hawk_owl.o
|
obj-m += nv_hawk_owl.o
|
||||||
|
obj-m += max929x.o
|
||||||
endif
|
endif
|
||||||
|
|
||||||
obj-m += pca9570.o
|
obj-m += pca9570.o
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
182
drivers/media/i2c/max929x.c
Normal file
182
drivers/media/i2c/max929x.c
Normal file
@@ -0,0 +1,182 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-2.0-only
|
||||||
|
// SPDX-FileCopyrightText: Copyright (c) 2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||||
|
/*
|
||||||
|
* max929x.c - max929x IO Expander driver
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <linux/seq_file.h>
|
||||||
|
#include <linux/debugfs.h>
|
||||||
|
#include <media/camera_common.h>
|
||||||
|
#include <linux/module.h>
|
||||||
|
#include <linux/gpio/consumer.h>
|
||||||
|
#include <linux/gpio.h>
|
||||||
|
#include <linux/module.h>
|
||||||
|
#include <linux/seq_file.h>
|
||||||
|
#include <linux/of.h>
|
||||||
|
#include <linux/of_device.h>
|
||||||
|
#include <linux/of_gpio.h>
|
||||||
|
|
||||||
|
#include "max929x.h"
|
||||||
|
|
||||||
|
struct max929x {
|
||||||
|
struct i2c_client *i2c_client;
|
||||||
|
struct regmap *regmap;
|
||||||
|
unsigned int pwdn_gpio;
|
||||||
|
unsigned short ser_addr;
|
||||||
|
};
|
||||||
|
struct max929x *priv;
|
||||||
|
|
||||||
|
static int max929x_write_reg(u8 slave_addr, u16 reg, u8 val)
|
||||||
|
{
|
||||||
|
struct i2c_client *i2c_client = priv->i2c_client;
|
||||||
|
int err;
|
||||||
|
|
||||||
|
i2c_client->addr = slave_addr;
|
||||||
|
err = regmap_write(priv->regmap, reg, val);
|
||||||
|
if (err)
|
||||||
|
dev_err(&i2c_client->dev, "%s:i2c write failed, slave_addr 0x%x, 0x%x = 0x%x\n",
|
||||||
|
__func__, slave_addr, reg, val);
|
||||||
|
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int max929x_write_reg_list(struct max929x_reg *table, int size)
|
||||||
|
{
|
||||||
|
struct device dev = priv->i2c_client->dev;
|
||||||
|
int err = 0;
|
||||||
|
int i;
|
||||||
|
u8 slave_addr;
|
||||||
|
u16 reg;
|
||||||
|
u8 val;
|
||||||
|
|
||||||
|
for (i = 0; i < size; i++) {
|
||||||
|
if (table[i].slave_addr == SER_SLAVE2)
|
||||||
|
slave_addr = priv->ser_addr;
|
||||||
|
else
|
||||||
|
slave_addr = table[i].slave_addr;
|
||||||
|
|
||||||
|
reg = table[i].reg;
|
||||||
|
val = table[i].val;
|
||||||
|
|
||||||
|
if (slave_addr == 0xf1) {
|
||||||
|
msleep(val);
|
||||||
|
msleep(2000);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
dev_dbg(&dev, "%s: size %d, slave_addr 0x%x, reg 0x%x, val 0x%x\n",
|
||||||
|
__func__, size, slave_addr, reg, val);
|
||||||
|
|
||||||
|
err = max929x_write_reg(slave_addr, reg, val);
|
||||||
|
if (err != 0)
|
||||||
|
break;
|
||||||
|
mdelay(5);
|
||||||
|
}
|
||||||
|
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct regmap_config max929x_regmap_config = {
|
||||||
|
.reg_bits = 16,
|
||||||
|
.val_bits = 8,
|
||||||
|
.cache_type = REGCACHE_RBTREE,
|
||||||
|
};
|
||||||
|
|
||||||
|
static int max929x_probe(struct i2c_client *client,
|
||||||
|
const struct i2c_device_id *id)
|
||||||
|
{
|
||||||
|
struct device dev = client->dev;
|
||||||
|
struct device_node *np = (&dev)->of_node;
|
||||||
|
unsigned short ser_addr = SER_SLAVE2;
|
||||||
|
int err;
|
||||||
|
|
||||||
|
dev_dbg(&dev, "%s: enter\n", __func__);
|
||||||
|
|
||||||
|
priv = devm_kzalloc(&client->dev, sizeof(*priv), GFP_KERNEL);
|
||||||
|
priv->i2c_client = client;
|
||||||
|
priv->regmap = devm_regmap_init_i2c(priv->i2c_client, &max929x_regmap_config);
|
||||||
|
if (IS_ERR(priv->regmap)) {
|
||||||
|
dev_err(&client->dev,
|
||||||
|
"regmap init failed: %ld\n", PTR_ERR(priv->regmap));
|
||||||
|
return -ENODEV;
|
||||||
|
}
|
||||||
|
|
||||||
|
priv->pwdn_gpio = of_get_named_gpio(np, "pwdn-gpios", 0);
|
||||||
|
if (priv->pwdn_gpio < 0) {
|
||||||
|
dev_err(&dev, "pwdn-gpios not found\n");
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (priv->pwdn_gpio) {
|
||||||
|
gpio_direction_output(priv->pwdn_gpio, 1);
|
||||||
|
gpio_set_value(priv->pwdn_gpio, 1);
|
||||||
|
msleep(100);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Try to find the I2C address of serializer by writting to register
|
||||||
|
* 0x00 at i2c slave address 0x62 and 0x40. When write is successful
|
||||||
|
* the slave address is saved and used when configuring serializer.
|
||||||
|
*/
|
||||||
|
if (max929x_write_reg(SER_SLAVE2, MAX9295_DEV_ADDR, SER_SLAVE2 << 1)) {
|
||||||
|
if (max929x_write_reg(SER_SLAVE1, MAX9295_DEV_ADDR, SER_SLAVE1 << 1)) {
|
||||||
|
dev_err(&dev, "%s: failed to find serializer at 0x%x or 0x%x\n",
|
||||||
|
__func__, SER_SLAVE2, SER_SLAVE1);
|
||||||
|
return -ENODEV;
|
||||||
|
}
|
||||||
|
ser_addr = SER_SLAVE1;
|
||||||
|
}
|
||||||
|
|
||||||
|
msleep(100);
|
||||||
|
priv->ser_addr = ser_addr;
|
||||||
|
|
||||||
|
err = max929x_write_reg_list(max929x_Double_Dser_Ser_init,
|
||||||
|
sizeof(max929x_Double_Dser_Ser_init)/sizeof(struct max929x_reg));
|
||||||
|
if (err == 0)
|
||||||
|
dev_dbg(&dev, "%s: success\n", __func__);
|
||||||
|
else
|
||||||
|
dev_err(&dev, "%s: fail\n", __func__);
|
||||||
|
|
||||||
|
dev_set_drvdata(&client->dev, priv);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int max929x_remove(struct i2c_client *client)
|
||||||
|
{
|
||||||
|
struct device dev = client->dev;
|
||||||
|
|
||||||
|
gpio_set_value(priv->pwdn_gpio, 0);
|
||||||
|
dev_dbg(&dev, "%s: \n", __func__);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const struct i2c_device_id max929x_id[] = {
|
||||||
|
{ "max929x", 0 },
|
||||||
|
{ },
|
||||||
|
};
|
||||||
|
MODULE_DEVICE_TABLE(i2c, max929x_id);
|
||||||
|
|
||||||
|
const struct of_device_id max929x_of_match[] = {
|
||||||
|
{ .compatible = "Maxim,max929x", },
|
||||||
|
{ },
|
||||||
|
};
|
||||||
|
MODULE_DEVICE_TABLE(of, max929x_of_match);
|
||||||
|
|
||||||
|
static struct i2c_driver max929x_i2c_driver = {
|
||||||
|
.driver = {
|
||||||
|
.owner = THIS_MODULE,
|
||||||
|
.name = "max929x",
|
||||||
|
.of_match_table = of_match_ptr(max929x_of_match),
|
||||||
|
},
|
||||||
|
.probe = max929x_probe,
|
||||||
|
.remove = max929x_remove,
|
||||||
|
.id_table = max929x_id,
|
||||||
|
};
|
||||||
|
|
||||||
|
module_i2c_driver(max929x_i2c_driver);
|
||||||
|
|
||||||
|
MODULE_DESCRIPTION("IO Expander driver max929x");
|
||||||
|
MODULE_AUTHOR("NVIDIA Corporation");
|
||||||
|
MODULE_LICENSE("GPL v2");
|
||||||
152
drivers/media/i2c/max929x.h
Normal file
152
drivers/media/i2c/max929x.h
Normal file
@@ -0,0 +1,152 @@
|
|||||||
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||||
|
/* SPDX-FileCopyrightText: Copyright (c) 2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. */
|
||||||
|
|
||||||
|
#ifndef __MAX929X_H__
|
||||||
|
#define __MAX929X_H__
|
||||||
|
|
||||||
|
/* TI FPD Link III 954 deser I2C address */
|
||||||
|
#define TI954_ADDR (0x30)
|
||||||
|
/* TI FPD Link III 953 ser I2C address */
|
||||||
|
#define TI953_ADDR (0x18)
|
||||||
|
/* TI 953 alias address */
|
||||||
|
#define TI953_CAM1_ADDR (0x29)
|
||||||
|
#define TI953_CAM2_ADDR (0X2A)
|
||||||
|
|
||||||
|
#define MAX9295_DEV_ADDR 0x00
|
||||||
|
|
||||||
|
#define SENSOR_ADDR (0x1a)
|
||||||
|
/* CAM alias address */
|
||||||
|
#define CAM1_SENSOR_ADDR (0x1b)
|
||||||
|
#define CAM2_SENSOR_ADDR (0x1c)
|
||||||
|
|
||||||
|
#define TI954_RESET_ADDR (0x01)
|
||||||
|
#define TI954_RESET_VAL (0x02)
|
||||||
|
|
||||||
|
#define AFDRV_I2C_ADDR (0x3E)
|
||||||
|
/*AF ctrl*/
|
||||||
|
#define AFDRV1_I2C_ADDR (0x21)
|
||||||
|
#define AFDRV2_I2C_ADDR (0x20)
|
||||||
|
|
||||||
|
#define EEPROM_I2C_ADDR (0x50)
|
||||||
|
/*eeprom ctrl*/
|
||||||
|
#define EEPROM1_I2C_ADDR (0x51)
|
||||||
|
#define EEPROM2_I2C_ADDR (0x52)
|
||||||
|
|
||||||
|
struct max929x_reg {
|
||||||
|
u8 slave_addr;
|
||||||
|
u16 reg;
|
||||||
|
u8 val;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Serializer slave addresses */
|
||||||
|
#define SER_SLAVE1 0x40
|
||||||
|
#define SER_SLAVE2 0x62
|
||||||
|
|
||||||
|
/* Deserializer slave addresses */
|
||||||
|
#define DESER_SLAVE 0x48
|
||||||
|
|
||||||
|
/*
|
||||||
|
* MAX9296 i2c addr 0x90(8bits) 0x48(7bits)
|
||||||
|
* (MAX9296 link A) MAX9295 i2c addr 0xc4(8bits) 0x62(7bits)
|
||||||
|
*/
|
||||||
|
static struct max929x_reg max929x_Double_Dser_Ser_init[] = {
|
||||||
|
/* set MFP0 low to reset sensor */
|
||||||
|
{0x62, 0x02be, 0x80},
|
||||||
|
/* Set SER to 1x4 mode (phy_config = 0) */
|
||||||
|
{0x62, 0x0330, 0x00},
|
||||||
|
{0x62, 0x0332, 0xe4},
|
||||||
|
/* Additional lane map */
|
||||||
|
{0x62, 0x0333, 0xe4},
|
||||||
|
/* Set 4 lanes for serializer (ctrl1_num_lanes = 3) */
|
||||||
|
{0x62, 0x0331, 0x31},
|
||||||
|
/* Start video from both port A and port B. */
|
||||||
|
{0x62, 0x0311, 0x20},
|
||||||
|
/*
|
||||||
|
* Enable info lines. Additional start bits for Port A and B.
|
||||||
|
* Use data from port B for all pipelines
|
||||||
|
*/
|
||||||
|
{0x62, 0x0308, 0x62},
|
||||||
|
/* Route 16bit DCG (DT = 0x30) to VIDEO_X (Bit 6 enable) */
|
||||||
|
{0x62, 0x0314, 0x22},
|
||||||
|
/* Route 12bit RAW (DT = 0x2C) to VIDEO_Y (Bit 6 enable) */
|
||||||
|
{0x62, 0x0316, 0x6c},
|
||||||
|
/* Route EMBEDDED8 to VIDEO_Z (Bit 6 enable) */
|
||||||
|
{0x62, 0x0318, 0x22},
|
||||||
|
/* Unused VIDEO_U */
|
||||||
|
{0x62, 0x031A, 0x22},
|
||||||
|
/*
|
||||||
|
* Make sure all pipelines start transmission
|
||||||
|
* (VID_TX_EN_X/Y/Z/U = 1)
|
||||||
|
*/
|
||||||
|
{0x62, 0x0002, 0x22},
|
||||||
|
/* Set MIPI Phy Mode: 2x(1x4) mode */
|
||||||
|
{0x48, 0x0330, 0x04},
|
||||||
|
/* lane maps - all 4 ports mapped straight */
|
||||||
|
{0x48, 0x0333, 0x4E},
|
||||||
|
/* Additional lane map */
|
||||||
|
{0x48, 0x0334, 0xE4},
|
||||||
|
/*
|
||||||
|
* lane count - 0 lanes striping on controller 0
|
||||||
|
* (Port A slave in 2x1x4 mode).
|
||||||
|
*/
|
||||||
|
{0x48, 0x040A, 0x00},
|
||||||
|
/*
|
||||||
|
* lane count - 4 lanes striping on controller 1
|
||||||
|
* (Port A master in 2x1x4 mode).
|
||||||
|
*/
|
||||||
|
{0x48, 0x044A, 0xd0},
|
||||||
|
/*
|
||||||
|
* lane count - 4 lanes striping on controller 2
|
||||||
|
* (Port B master in 2x1x4 mode).
|
||||||
|
*/
|
||||||
|
{0x48, 0x048A, 0xd0},
|
||||||
|
/*
|
||||||
|
* lane count - 0 lanes striping on controller 3
|
||||||
|
* (Port B slave in 2x1x4 mode).
|
||||||
|
*/
|
||||||
|
{0x48, 0x04CA, 0x00},
|
||||||
|
/*
|
||||||
|
* MIPI clock rate - 1.5Gbps from controller 0 clock
|
||||||
|
* (Port A slave in 2x1x4 mode).
|
||||||
|
*/
|
||||||
|
{0x48, 0x031D, 0x2f},
|
||||||
|
/*
|
||||||
|
* MIPI clock rate - 1.5Gbps from controller 1 clock
|
||||||
|
* (Port A master in 2x1x4 mode).
|
||||||
|
*/
|
||||||
|
{0x48, 0x0320, 0x2f},
|
||||||
|
/*
|
||||||
|
* MIPI clock rate - 1.5Gbps from controller 2 clock
|
||||||
|
* (Port B master in 2x1x4 mode).
|
||||||
|
*/
|
||||||
|
{0x48, 0x0323, 0x2f},
|
||||||
|
/*
|
||||||
|
* MIPI clock rate - 1.5Gbps from controller 2 clock
|
||||||
|
* (Port B slave in 2x1x4 mode).
|
||||||
|
*/
|
||||||
|
{0x48, 0x0326, 0x2f},
|
||||||
|
/* Route data from stream 0 to pipe X */
|
||||||
|
{0x48, 0x0050, 0x00},
|
||||||
|
/* Route data from stream 0 to pipe Y */
|
||||||
|
{0x48, 0x0051, 0x01},
|
||||||
|
/* Route data from stream 0 to pipe Z */
|
||||||
|
{0x48, 0x0052, 0x02},
|
||||||
|
/* Route data from stream 0 to pipe U */
|
||||||
|
{0x48, 0x0053, 0x03},
|
||||||
|
/* Enable all PHYS. */
|
||||||
|
{0x48, 0x0332, 0xF0},
|
||||||
|
/* Enable sensor power down pin. Put imager in,Active mode */
|
||||||
|
{0x62, 0x02be, 0x90},
|
||||||
|
/* Output RCLK to sensor. */
|
||||||
|
{0x62, 0x03F1, 0x89},
|
||||||
|
/* MFP8 for FSIN */
|
||||||
|
{0x62, 0x02D8, 0x10},
|
||||||
|
{0x62, 0x02D6, 0x04},
|
||||||
|
/* need disable pixel clk out inb order to use MFP1 */
|
||||||
|
{0x48, 0x0005, 0x00},
|
||||||
|
/* GPIO TX compensation */
|
||||||
|
{0x48, 0x02B3, 0x83},
|
||||||
|
{0x48, 0x02B4, 0x10},
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
File diff suppressed because it is too large
Load Diff
911
drivers/media/i2c/nv_imx390_archived.c
Normal file
911
drivers/media/i2c/nv_imx390_archived.c
Normal file
@@ -0,0 +1,911 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-2.0-only
|
||||||
|
// SPDX-FileCopyrightText: Copyright (c) 2018-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||||
|
|
||||||
|
#include <nvidia/conftest.h>
|
||||||
|
|
||||||
|
#include <linux/slab.h>
|
||||||
|
#include <linux/uaccess.h>
|
||||||
|
#include <linux/gpio.h>
|
||||||
|
#include <linux/module.h>
|
||||||
|
|
||||||
|
#include <linux/seq_file.h>
|
||||||
|
#include <linux/of.h>
|
||||||
|
#include <linux/of_device.h>
|
||||||
|
#include <linux/of_gpio.h>
|
||||||
|
|
||||||
|
#include <media/max9295.h>
|
||||||
|
#include <media/max9296.h>
|
||||||
|
|
||||||
|
#include <media/tegracam_core.h>
|
||||||
|
#include "imx390_mode_tbls.h"
|
||||||
|
|
||||||
|
#define IMX390_MIN_GAIN (0)
|
||||||
|
#define IMX390_MAX_GAIN (30)
|
||||||
|
#define IMX390_MAX_GAIN_REG ((IMX390_MAX_GAIN - IMX390_MIN_GAIN) * 10 / 3)
|
||||||
|
#define IMX390_DEFAULT_FRAME_LENGTH (1125)
|
||||||
|
#define IMX390_FRAME_LENGTH_ADDR_MSB 0x200A
|
||||||
|
#define IMX390_FRAME_LENGTH_ADDR_MID 0x2009
|
||||||
|
#define IMX390_FRAME_LENGTH_ADDR_LSB 0x2008
|
||||||
|
#define IMX390_COARSE_TIME_SHS1_ADDR_MSB 0x000E
|
||||||
|
#define IMX390_COARSE_TIME_SHS1_ADDR_MID 0x000D
|
||||||
|
#define IMX390_COARSE_TIME_SHS1_ADDR_LSB 0x000C
|
||||||
|
#define IMX390_COARSE_TIME_SHS2_ADDR_MSB 0x0012
|
||||||
|
#define IMX390_COARSE_TIME_SHS2_ADDR_MID 0x0011
|
||||||
|
#define IMX390_COARSE_TIME_SHS2_ADDR_LSB 0x0010
|
||||||
|
#define IMX390_GROUP_HOLD_ADDR 0x0008
|
||||||
|
#define IMX390_ANALOG_GAIN_SP1H_ADDR 0x0018
|
||||||
|
#define IMX390_ANALOG_GAIN_SP1L_ADDR 0x001A
|
||||||
|
|
||||||
|
static const struct of_device_id imx390_of_match[] = {
|
||||||
|
{ .compatible = "sony,imx390",},
|
||||||
|
{ },
|
||||||
|
};
|
||||||
|
MODULE_DEVICE_TABLE(of, imx390_of_match);
|
||||||
|
|
||||||
|
static const u32 ctrl_cid_list[] = {
|
||||||
|
TEGRA_CAMERA_CID_GAIN,
|
||||||
|
TEGRA_CAMERA_CID_EXPOSURE,
|
||||||
|
TEGRA_CAMERA_CID_EXPOSURE_SHORT,
|
||||||
|
TEGRA_CAMERA_CID_FRAME_RATE,
|
||||||
|
TEGRA_CAMERA_CID_HDR_EN,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct imx390 {
|
||||||
|
struct i2c_client *i2c_client;
|
||||||
|
const struct i2c_device_id *id;
|
||||||
|
struct v4l2_subdev *subdev;
|
||||||
|
struct device *ser_dev;
|
||||||
|
struct device *dser_dev;
|
||||||
|
struct gmsl_link_ctx g_ctx;
|
||||||
|
u32 frame_length;
|
||||||
|
struct camera_common_data *s_data;
|
||||||
|
struct tegracam_device *tc_dev;
|
||||||
|
};
|
||||||
|
|
||||||
|
static const struct regmap_config sensor_regmap_config = {
|
||||||
|
.reg_bits = 16,
|
||||||
|
.val_bits = 8,
|
||||||
|
.cache_type = REGCACHE_RBTREE,
|
||||||
|
};
|
||||||
|
|
||||||
|
static inline void imx390_get_frame_length_regs(imx390_reg *regs,
|
||||||
|
u32 frame_length)
|
||||||
|
{
|
||||||
|
regs->addr = IMX390_FRAME_LENGTH_ADDR_MSB;
|
||||||
|
regs->val = (frame_length >> 16) & 0x01;
|
||||||
|
|
||||||
|
(regs + 1)->addr = IMX390_FRAME_LENGTH_ADDR_MID;
|
||||||
|
(regs + 1)->val = (frame_length >> 8) & 0xff;
|
||||||
|
|
||||||
|
(regs + 2)->addr = IMX390_FRAME_LENGTH_ADDR_LSB;
|
||||||
|
(regs + 2)->val = (frame_length) & 0xff;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void imx390_get_coarse_time_regs_shs1(imx390_reg *regs,
|
||||||
|
u32 coarse_time)
|
||||||
|
{
|
||||||
|
regs->addr = IMX390_COARSE_TIME_SHS1_ADDR_MSB;
|
||||||
|
regs->val = (coarse_time >> 16) & 0x0f;
|
||||||
|
|
||||||
|
(regs + 1)->addr = IMX390_COARSE_TIME_SHS1_ADDR_MID;
|
||||||
|
(regs + 1)->val = (coarse_time >> 8) & 0xff;
|
||||||
|
|
||||||
|
(regs + 2)->addr = IMX390_COARSE_TIME_SHS1_ADDR_LSB;
|
||||||
|
(regs + 2)->val = (coarse_time) & 0xff;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void imx390_get_coarse_time_regs_shs2(imx390_reg *regs,
|
||||||
|
u32 coarse_time)
|
||||||
|
{
|
||||||
|
regs->addr = IMX390_COARSE_TIME_SHS2_ADDR_MSB;
|
||||||
|
regs->val = (coarse_time >> 16) & 0x0f;
|
||||||
|
|
||||||
|
(regs + 1)->addr = IMX390_COARSE_TIME_SHS2_ADDR_MID;
|
||||||
|
(regs + 1)->val = (coarse_time >> 8) & 0xff;
|
||||||
|
|
||||||
|
(regs + 2)->addr = IMX390_COARSE_TIME_SHS2_ADDR_LSB;
|
||||||
|
(regs + 2)->val = (coarse_time) & 0xff;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void imx390_get_gain_reg(imx390_reg *regs,
|
||||||
|
u16 gain)
|
||||||
|
{
|
||||||
|
regs->addr = IMX390_ANALOG_GAIN_SP1H_ADDR;
|
||||||
|
regs->val = (gain) & 0xff;
|
||||||
|
|
||||||
|
(regs + 1)->addr = IMX390_ANALOG_GAIN_SP1H_ADDR + 1;
|
||||||
|
(regs + 1)->val = (gain >> 8) & 0xff;
|
||||||
|
|
||||||
|
(regs + 2)->addr = IMX390_ANALOG_GAIN_SP1L_ADDR;
|
||||||
|
(regs + 2)->val = (gain) & 0xff;
|
||||||
|
|
||||||
|
(regs + 3)->addr = IMX390_ANALOG_GAIN_SP1L_ADDR + 1;
|
||||||
|
(regs + 3)->val = (gain >> 8) & 0xff;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int test_mode;
|
||||||
|
module_param(test_mode, int, 0644);
|
||||||
|
|
||||||
|
static inline int imx390_read_reg(struct camera_common_data *s_data,
|
||||||
|
u16 addr, u8 *val)
|
||||||
|
{
|
||||||
|
int err = 0;
|
||||||
|
u32 reg_val = 0;
|
||||||
|
|
||||||
|
err = regmap_read(s_data->regmap, addr, ®_val);
|
||||||
|
*val = reg_val & 0xFF;
|
||||||
|
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int imx390_write_reg(struct camera_common_data *s_data,
|
||||||
|
u16 addr, u8 val)
|
||||||
|
{
|
||||||
|
int err;
|
||||||
|
struct device *dev = s_data->dev;
|
||||||
|
|
||||||
|
err = regmap_write(s_data->regmap, addr, val);
|
||||||
|
if (err)
|
||||||
|
dev_err(dev, "%s:i2c write failed, 0x%x = %x\n",
|
||||||
|
__func__, addr, val);
|
||||||
|
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int imx390_write_table(struct imx390 *priv,
|
||||||
|
const imx390_reg table[])
|
||||||
|
{
|
||||||
|
struct camera_common_data *s_data = priv->s_data;
|
||||||
|
|
||||||
|
return regmap_util_write_table_8(s_data->regmap,
|
||||||
|
table,
|
||||||
|
NULL, 0,
|
||||||
|
IMX390_TABLE_WAIT_MS,
|
||||||
|
IMX390_TABLE_END);
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct mutex serdes_lock__;
|
||||||
|
|
||||||
|
static int imx390_gmsl_serdes_setup(struct imx390 *priv)
|
||||||
|
{
|
||||||
|
int err = 0;
|
||||||
|
int des_err = 0;
|
||||||
|
struct device *dev;
|
||||||
|
|
||||||
|
if (!priv || !priv->ser_dev || !priv->dser_dev || !priv->i2c_client)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
|
dev = &priv->i2c_client->dev;
|
||||||
|
|
||||||
|
mutex_lock(&serdes_lock__);
|
||||||
|
|
||||||
|
/* For now no separate power on required for serializer device */
|
||||||
|
max9296_power_on(priv->dser_dev);
|
||||||
|
|
||||||
|
/* setup serdes addressing and control pipeline */
|
||||||
|
err = max9296_setup_link(priv->dser_dev, &priv->i2c_client->dev);
|
||||||
|
if (err) {
|
||||||
|
dev_err(dev, "gmsl deserializer link config failed\n");
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
err = max9295_setup_control(priv->ser_dev);
|
||||||
|
|
||||||
|
/* proceed even if ser setup failed, to setup deser correctly */
|
||||||
|
if (err)
|
||||||
|
dev_err(dev, "gmsl serializer setup failed\n");
|
||||||
|
|
||||||
|
des_err = max9296_setup_control(priv->dser_dev, &priv->i2c_client->dev);
|
||||||
|
if (des_err) {
|
||||||
|
dev_err(dev, "gmsl deserializer setup failed\n");
|
||||||
|
/* overwrite err only if deser setup also failed */
|
||||||
|
err = des_err;
|
||||||
|
}
|
||||||
|
|
||||||
|
error:
|
||||||
|
mutex_unlock(&serdes_lock__);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void imx390_gmsl_serdes_reset(struct imx390 *priv)
|
||||||
|
{
|
||||||
|
mutex_lock(&serdes_lock__);
|
||||||
|
|
||||||
|
/* reset serdes addressing and control pipeline */
|
||||||
|
max9295_reset_control(priv->ser_dev);
|
||||||
|
max9296_reset_control(priv->dser_dev, &priv->i2c_client->dev);
|
||||||
|
|
||||||
|
max9296_power_off(priv->dser_dev);
|
||||||
|
|
||||||
|
mutex_unlock(&serdes_lock__);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int imx390_power_on(struct camera_common_data *s_data)
|
||||||
|
{
|
||||||
|
int err = 0;
|
||||||
|
struct camera_common_power_rail *pw = s_data->power;
|
||||||
|
struct camera_common_pdata *pdata = s_data->pdata;
|
||||||
|
struct device *dev = s_data->dev;
|
||||||
|
|
||||||
|
dev_dbg(dev, "%s: power on\n", __func__);
|
||||||
|
if (pdata && pdata->power_on) {
|
||||||
|
err = pdata->power_on(pw);
|
||||||
|
if (err)
|
||||||
|
dev_err(dev, "%s failed.\n", __func__);
|
||||||
|
else
|
||||||
|
pw->state = SWITCH_ON;
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
pw->state = SWITCH_ON;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int imx390_power_off(struct camera_common_data *s_data)
|
||||||
|
{
|
||||||
|
int err = 0;
|
||||||
|
struct camera_common_power_rail *pw = s_data->power;
|
||||||
|
struct camera_common_pdata *pdata = s_data->pdata;
|
||||||
|
struct device *dev = s_data->dev;
|
||||||
|
|
||||||
|
dev_dbg(dev, "%s:\n", __func__);
|
||||||
|
|
||||||
|
if (pdata && pdata->power_off) {
|
||||||
|
err = pdata->power_off(pw);
|
||||||
|
if (!err)
|
||||||
|
goto power_off_done;
|
||||||
|
else
|
||||||
|
dev_err(dev, "%s failed.\n", __func__);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
power_off_done:
|
||||||
|
pw->state = SWITCH_OFF;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int imx390_power_get(struct tegracam_device *tc_dev)
|
||||||
|
{
|
||||||
|
struct device *dev = tc_dev->dev;
|
||||||
|
struct camera_common_data *s_data = tc_dev->s_data;
|
||||||
|
struct camera_common_power_rail *pw = s_data->power;
|
||||||
|
struct camera_common_pdata *pdata = s_data->pdata;
|
||||||
|
const char *mclk_name;
|
||||||
|
const char *parentclk_name;
|
||||||
|
struct clk *parent;
|
||||||
|
int err = 0;
|
||||||
|
|
||||||
|
mclk_name = pdata->mclk_name ?
|
||||||
|
pdata->mclk_name : "cam_mclk1";
|
||||||
|
pw->mclk = devm_clk_get(dev, mclk_name);
|
||||||
|
if (IS_ERR(pw->mclk)) {
|
||||||
|
dev_err(dev, "unable to get clock %s\n", mclk_name);
|
||||||
|
return PTR_ERR(pw->mclk);
|
||||||
|
}
|
||||||
|
|
||||||
|
parentclk_name = pdata->parentclk_name;
|
||||||
|
if (parentclk_name) {
|
||||||
|
parent = devm_clk_get(dev, parentclk_name);
|
||||||
|
if (IS_ERR(parent)) {
|
||||||
|
dev_err(dev, "unable to get parent clcok %s",
|
||||||
|
parentclk_name);
|
||||||
|
} else {
|
||||||
|
err = clk_set_parent(pw->mclk, parent);
|
||||||
|
if (err < 0)
|
||||||
|
dev_dbg(dev,
|
||||||
|
"%s failed to set parent clock %d\n",
|
||||||
|
__func__, err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pw->state = SWITCH_OFF;
|
||||||
|
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int imx390_power_put(struct tegracam_device *tc_dev)
|
||||||
|
{
|
||||||
|
struct camera_common_data *s_data = tc_dev->s_data;
|
||||||
|
struct camera_common_power_rail *pw = s_data->power;
|
||||||
|
|
||||||
|
if (unlikely(!pw))
|
||||||
|
return -EFAULT;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int imx390_set_group_hold(struct tegracam_device *tc_dev, bool val)
|
||||||
|
{
|
||||||
|
struct camera_common_data *s_data = tc_dev->s_data;
|
||||||
|
struct device *dev = tc_dev->dev;
|
||||||
|
int err;
|
||||||
|
|
||||||
|
err = imx390_write_reg(s_data,
|
||||||
|
IMX390_GROUP_HOLD_ADDR, val);
|
||||||
|
if (err) {
|
||||||
|
dev_dbg(dev,
|
||||||
|
"%s: Group hold control error\n", __func__);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int imx390_set_gain(struct tegracam_device *tc_dev, s64 val)
|
||||||
|
{
|
||||||
|
struct camera_common_data *s_data = tc_dev->s_data;
|
||||||
|
struct device *dev = tc_dev->dev;
|
||||||
|
const struct sensor_mode_properties *mode =
|
||||||
|
&s_data->sensor_props.sensor_modes[s_data->mode_prop_idx];
|
||||||
|
imx390_reg reg_list[4];
|
||||||
|
int err, i;
|
||||||
|
u16 gain;
|
||||||
|
|
||||||
|
gain = (u16)(val / mode->control_properties.step_gain_val);
|
||||||
|
|
||||||
|
dev_dbg(dev, "%s: db: %d\n", __func__, gain);
|
||||||
|
|
||||||
|
if (gain > IMX390_MAX_GAIN_REG)
|
||||||
|
gain = IMX390_MAX_GAIN_REG;
|
||||||
|
|
||||||
|
imx390_get_gain_reg(reg_list, gain);
|
||||||
|
for (i = 0; i < 4; i++) {
|
||||||
|
err = imx390_write_reg(s_data, reg_list[i].addr,
|
||||||
|
reg_list[i].val);
|
||||||
|
if (err)
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
fail:
|
||||||
|
dev_info(dev, "%s: GAIN control error\n", __func__);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int imx390_set_frame_rate(struct tegracam_device *tc_dev, s64 val)
|
||||||
|
{
|
||||||
|
struct imx390 *priv = (struct imx390 *)tegracam_get_privdata(tc_dev);
|
||||||
|
|
||||||
|
/* fixed 30fps */
|
||||||
|
priv->frame_length = IMX390_DEFAULT_FRAME_LENGTH;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int imx390_set_exposure(struct tegracam_device *tc_dev, s64 val)
|
||||||
|
{
|
||||||
|
struct imx390 *priv = (struct imx390 *)tegracam_get_privdata(tc_dev);
|
||||||
|
struct camera_common_data *s_data = tc_dev->s_data;
|
||||||
|
const struct sensor_mode_properties *mode =
|
||||||
|
&s_data->sensor_props.sensor_modes[s_data->mode];
|
||||||
|
imx390_reg reg_list[3];
|
||||||
|
int err;
|
||||||
|
u32 coarse_time;
|
||||||
|
u32 shs1;
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
if (priv->frame_length == 0)
|
||||||
|
priv->frame_length = IMX390_DEFAULT_FRAME_LENGTH;
|
||||||
|
|
||||||
|
/* coarse time in lines */
|
||||||
|
coarse_time = (u32) (val * s_data->frmfmt[s_data->mode].framerates[0] *
|
||||||
|
priv->frame_length / mode->control_properties.exposure_factor);
|
||||||
|
|
||||||
|
shs1 = priv->frame_length - coarse_time;
|
||||||
|
/* 0 and 1 are prohibited */
|
||||||
|
if (shs1 < 2)
|
||||||
|
shs1 = 2;
|
||||||
|
|
||||||
|
imx390_get_coarse_time_regs_shs1(reg_list, shs1);
|
||||||
|
for (i = 0; i < 3; i++) {
|
||||||
|
err = imx390_write_reg(priv->s_data, reg_list[i].addr,
|
||||||
|
reg_list[i].val);
|
||||||
|
if (err)
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
imx390_get_coarse_time_regs_shs2(reg_list, shs1);
|
||||||
|
for (i = 0; i < 3; i++) {
|
||||||
|
err = imx390_write_reg(priv->s_data, reg_list[i].addr,
|
||||||
|
reg_list[i].val);
|
||||||
|
if (err)
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
fail:
|
||||||
|
dev_dbg(&priv->i2c_client->dev,
|
||||||
|
"%s: set coarse time error\n", __func__);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct tegracam_ctrl_ops imx390_ctrl_ops = {
|
||||||
|
.numctrls = ARRAY_SIZE(ctrl_cid_list),
|
||||||
|
.ctrl_cid_list = ctrl_cid_list,
|
||||||
|
.set_gain = imx390_set_gain,
|
||||||
|
.set_exposure = imx390_set_exposure,
|
||||||
|
.set_exposure_short = imx390_set_exposure,
|
||||||
|
.set_frame_rate = imx390_set_frame_rate,
|
||||||
|
.set_group_hold = imx390_set_group_hold,
|
||||||
|
};
|
||||||
|
|
||||||
|
static struct camera_common_pdata
|
||||||
|
*imx390_parse_dt(struct tegracam_device *tc_dev)
|
||||||
|
{
|
||||||
|
struct device *dev = tc_dev->dev;
|
||||||
|
struct device_node *node = dev->of_node;
|
||||||
|
struct camera_common_pdata *board_priv_pdata;
|
||||||
|
const struct of_device_id *match;
|
||||||
|
int err;
|
||||||
|
|
||||||
|
if (!node)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
match = of_match_device(imx390_of_match, dev);
|
||||||
|
if (!match) {
|
||||||
|
dev_err(dev, "Failed to find matching dt id\n");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
board_priv_pdata = devm_kzalloc(dev,
|
||||||
|
sizeof(*board_priv_pdata), GFP_KERNEL);
|
||||||
|
|
||||||
|
err = of_property_read_string(node, "mclk",
|
||||||
|
&board_priv_pdata->mclk_name);
|
||||||
|
if (err)
|
||||||
|
dev_err(dev, "mclk not in DT\n");
|
||||||
|
|
||||||
|
return board_priv_pdata;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int imx390_set_mode(struct tegracam_device *tc_dev)
|
||||||
|
{
|
||||||
|
struct imx390 *priv = (struct imx390 *)tegracam_get_privdata(tc_dev);
|
||||||
|
struct camera_common_data *s_data = tc_dev->s_data;
|
||||||
|
struct device *dev = tc_dev->dev;
|
||||||
|
const struct of_device_id *match;
|
||||||
|
|
||||||
|
match = of_match_device(imx390_of_match, dev);
|
||||||
|
if (!match) {
|
||||||
|
dev_err(dev, "Failed to find matching dt id\n");
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (s_data->mode_prop_idx < 0)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
|
return imx390_write_table(priv, mode_table[s_data->mode_prop_idx]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int imx390_start_streaming(struct tegracam_device *tc_dev)
|
||||||
|
{
|
||||||
|
struct imx390 *priv = (struct imx390 *)tegracam_get_privdata(tc_dev);
|
||||||
|
struct device *dev = tc_dev->dev;
|
||||||
|
int err;
|
||||||
|
|
||||||
|
/* enable serdes streaming */
|
||||||
|
err = max9295_setup_streaming(priv->ser_dev);
|
||||||
|
if (err)
|
||||||
|
goto exit;
|
||||||
|
err = max9296_setup_streaming(priv->dser_dev, dev);
|
||||||
|
if (err)
|
||||||
|
goto exit;
|
||||||
|
err = max9296_start_streaming(priv->dser_dev, dev);
|
||||||
|
if (err)
|
||||||
|
goto exit;
|
||||||
|
|
||||||
|
err = imx390_write_table(priv,
|
||||||
|
mode_table[IMX390_MODE_START_STREAM]);
|
||||||
|
if (err)
|
||||||
|
return err;
|
||||||
|
|
||||||
|
msleep(20);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
exit:
|
||||||
|
dev_err(dev, "%s: error setting stream\n", __func__);
|
||||||
|
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int imx390_stop_streaming(struct tegracam_device *tc_dev)
|
||||||
|
{
|
||||||
|
struct device *dev = tc_dev->dev;
|
||||||
|
struct imx390 *priv = (struct imx390 *)tegracam_get_privdata(tc_dev);
|
||||||
|
|
||||||
|
/* disable serdes streaming */
|
||||||
|
max9296_stop_streaming(priv->dser_dev, dev);
|
||||||
|
|
||||||
|
return imx390_write_table(priv, mode_table[IMX390_MODE_STOP_STREAM]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct camera_common_sensor_ops imx390_common_ops = {
|
||||||
|
.numfrmfmts = ARRAY_SIZE(imx390_frmfmt),
|
||||||
|
.frmfmt_table = imx390_frmfmt,
|
||||||
|
.power_on = imx390_power_on,
|
||||||
|
.power_off = imx390_power_off,
|
||||||
|
.write_reg = imx390_write_reg,
|
||||||
|
.read_reg = imx390_read_reg,
|
||||||
|
.parse_dt = imx390_parse_dt,
|
||||||
|
.power_get = imx390_power_get,
|
||||||
|
.power_put = imx390_power_put,
|
||||||
|
.set_mode = imx390_set_mode,
|
||||||
|
.start_streaming = imx390_start_streaming,
|
||||||
|
.stop_streaming = imx390_stop_streaming,
|
||||||
|
};
|
||||||
|
|
||||||
|
static int imx390_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
|
||||||
|
{
|
||||||
|
struct i2c_client *client = v4l2_get_subdevdata(sd);
|
||||||
|
|
||||||
|
dev_dbg(&client->dev, "%s:\n", __func__);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const struct v4l2_subdev_internal_ops imx390_subdev_internal_ops = {
|
||||||
|
.open = imx390_open,
|
||||||
|
};
|
||||||
|
|
||||||
|
static int imx390_board_setup(struct imx390 *priv)
|
||||||
|
{
|
||||||
|
struct tegracam_device *tc_dev = priv->tc_dev;
|
||||||
|
struct device *dev = tc_dev->dev;
|
||||||
|
struct device_node *node = dev->of_node;
|
||||||
|
struct device_node *ser_node;
|
||||||
|
struct i2c_client *ser_i2c = NULL;
|
||||||
|
struct device_node *dser_node;
|
||||||
|
struct i2c_client *dser_i2c = NULL;
|
||||||
|
struct device_node *gmsl;
|
||||||
|
int value = 0xFFFF;
|
||||||
|
const char *str_value;
|
||||||
|
const char *str_value1[2];
|
||||||
|
int i;
|
||||||
|
int err;
|
||||||
|
|
||||||
|
err = of_property_read_u32(node, "reg", &priv->g_ctx.sdev_reg);
|
||||||
|
if (err < 0) {
|
||||||
|
dev_err(dev, "reg not found\n");
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
err = of_property_read_u32(node, "def-addr",
|
||||||
|
&priv->g_ctx.sdev_def);
|
||||||
|
if (err < 0) {
|
||||||
|
dev_err(dev, "def-addr not found\n");
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
ser_node = of_parse_phandle(node, "nvidia,gmsl-ser-device", 0);
|
||||||
|
if (ser_node == NULL) {
|
||||||
|
dev_err(dev,
|
||||||
|
"missing %s handle\n",
|
||||||
|
"nvidia,gmsl-ser-device");
|
||||||
|
err = -EINVAL;
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
err = of_property_read_u32(ser_node, "reg", &priv->g_ctx.ser_reg);
|
||||||
|
if (err < 0) {
|
||||||
|
dev_err(dev, "serializer reg not found\n");
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
ser_i2c = of_find_i2c_device_by_node(ser_node);
|
||||||
|
of_node_put(ser_node);
|
||||||
|
|
||||||
|
if (ser_i2c == NULL) {
|
||||||
|
err = -EPROBE_DEFER;
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
if (ser_i2c->dev.driver == NULL) {
|
||||||
|
dev_err(dev, "missing serializer driver\n");
|
||||||
|
err = -EINVAL;
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
priv->ser_dev = &ser_i2c->dev;
|
||||||
|
|
||||||
|
dser_node = of_parse_phandle(node, "nvidia,gmsl-dser-device", 0);
|
||||||
|
if (dser_node == NULL) {
|
||||||
|
dev_err(dev,
|
||||||
|
"missing %s handle\n",
|
||||||
|
"nvidia,gmsl-dser-device");
|
||||||
|
err = -EINVAL;
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
dser_i2c = of_find_i2c_device_by_node(dser_node);
|
||||||
|
of_node_put(dser_node);
|
||||||
|
|
||||||
|
if (dser_i2c == NULL) {
|
||||||
|
err = -EPROBE_DEFER;
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
if (dser_i2c->dev.driver == NULL) {
|
||||||
|
dev_err(dev, "missing deserializer driver\n");
|
||||||
|
err = -EINVAL;
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
priv->dser_dev = &dser_i2c->dev;
|
||||||
|
|
||||||
|
/* populate g_ctx from DT */
|
||||||
|
gmsl = of_get_child_by_name(node, "gmsl-link");
|
||||||
|
if (gmsl == NULL) {
|
||||||
|
dev_err(dev, "missing gmsl-link device node\n");
|
||||||
|
err = -EINVAL;
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
err = of_property_read_string(gmsl, "dst-csi-port", &str_value);
|
||||||
|
if (err < 0) {
|
||||||
|
dev_err(dev, "No dst-csi-port found\n");
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
priv->g_ctx.dst_csi_port =
|
||||||
|
(!strcmp(str_value, "a")) ? GMSL_CSI_PORT_A : GMSL_CSI_PORT_B;
|
||||||
|
|
||||||
|
err = of_property_read_string(gmsl, "src-csi-port", &str_value);
|
||||||
|
if (err < 0) {
|
||||||
|
dev_err(dev, "No src-csi-port found\n");
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
priv->g_ctx.src_csi_port =
|
||||||
|
(!strcmp(str_value, "a")) ? GMSL_CSI_PORT_A : GMSL_CSI_PORT_B;
|
||||||
|
|
||||||
|
err = of_property_read_string(gmsl, "csi-mode", &str_value);
|
||||||
|
if (err < 0) {
|
||||||
|
dev_err(dev, "No csi-mode found\n");
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!strcmp(str_value, "1x4")) {
|
||||||
|
priv->g_ctx.csi_mode = GMSL_CSI_1X4_MODE;
|
||||||
|
} else if (!strcmp(str_value, "2x4")) {
|
||||||
|
priv->g_ctx.csi_mode = GMSL_CSI_2X4_MODE;
|
||||||
|
} else if (!strcmp(str_value, "4x2")) {
|
||||||
|
priv->g_ctx.csi_mode = GMSL_CSI_4X2_MODE;
|
||||||
|
} else if (!strcmp(str_value, "2x2")) {
|
||||||
|
priv->g_ctx.csi_mode = GMSL_CSI_2X2_MODE;
|
||||||
|
} else {
|
||||||
|
dev_err(dev, "invalid csi mode\n");
|
||||||
|
err = -EINVAL;
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
err = of_property_read_string(gmsl, "serdes-csi-link", &str_value);
|
||||||
|
if (err < 0) {
|
||||||
|
dev_err(dev, "No serdes-csi-link found\n");
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
priv->g_ctx.serdes_csi_link =
|
||||||
|
(!strcmp(str_value, "a")) ?
|
||||||
|
GMSL_SERDES_CSI_LINK_A : GMSL_SERDES_CSI_LINK_B;
|
||||||
|
|
||||||
|
err = of_property_read_u32(gmsl, "st-vc", &value);
|
||||||
|
if (err < 0) {
|
||||||
|
dev_err(dev, "No st-vc info\n");
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
priv->g_ctx.st_vc = value;
|
||||||
|
|
||||||
|
err = of_property_read_u32(gmsl, "vc-id", &value);
|
||||||
|
if (err < 0) {
|
||||||
|
dev_err(dev, "No vc-id info\n");
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
priv->g_ctx.dst_vc = value;
|
||||||
|
|
||||||
|
err = of_property_read_u32(gmsl, "num-lanes", &value);
|
||||||
|
if (err < 0) {
|
||||||
|
dev_err(dev, "No num-lanes info\n");
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
priv->g_ctx.num_csi_lanes = value;
|
||||||
|
|
||||||
|
priv->g_ctx.num_streams =
|
||||||
|
of_property_count_strings(gmsl, "streams");
|
||||||
|
if (priv->g_ctx.num_streams <= 0) {
|
||||||
|
dev_err(dev, "No streams found\n");
|
||||||
|
err = -EINVAL;
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < priv->g_ctx.num_streams; i++) {
|
||||||
|
err = of_property_read_string_index(gmsl, "streams", i,
|
||||||
|
&str_value1[i]);
|
||||||
|
if (err < 0) {
|
||||||
|
dev_err(dev, "Failed to get streams index\n");
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!str_value1[i]) {
|
||||||
|
dev_err(dev, "invalid stream info\n");
|
||||||
|
err = -EINVAL;
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
if (!strcmp(str_value1[i], "raw12")) {
|
||||||
|
priv->g_ctx.streams[i].st_data_type =
|
||||||
|
GMSL_CSI_DT_RAW_12;
|
||||||
|
} else if (!strcmp(str_value1[i], "embed")) {
|
||||||
|
priv->g_ctx.streams[i].st_data_type =
|
||||||
|
GMSL_CSI_DT_EMBED;
|
||||||
|
} else if (!strcmp(str_value1[i], "ued-u1")) {
|
||||||
|
priv->g_ctx.streams[i].st_data_type =
|
||||||
|
GMSL_CSI_DT_UED_U1;
|
||||||
|
} else {
|
||||||
|
dev_err(dev, "invalid stream data type\n");
|
||||||
|
err = -EINVAL;
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
priv->g_ctx.s_dev = dev;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
error:
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined(NV_I2C_DRIVER_STRUCT_PROBE_WITHOUT_I2C_DEVICE_ID_ARG) /* Linux 6.3 */
|
||||||
|
static int imx390_probe(struct i2c_client *client)
|
||||||
|
#else
|
||||||
|
static int imx390_probe(struct i2c_client *client,
|
||||||
|
const struct i2c_device_id *id)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
struct device *dev = &client->dev;
|
||||||
|
struct device_node *node = dev->of_node;
|
||||||
|
struct tegracam_device *tc_dev;
|
||||||
|
struct imx390 *priv;
|
||||||
|
int err;
|
||||||
|
|
||||||
|
dev_info(dev, "probing v4l2 sensor.\n");
|
||||||
|
|
||||||
|
if (!IS_ENABLED(CONFIG_OF) || !node)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
|
priv = devm_kzalloc(dev, sizeof(struct imx390), GFP_KERNEL);
|
||||||
|
if (!priv)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
|
tc_dev = devm_kzalloc(dev,
|
||||||
|
sizeof(struct tegracam_device), GFP_KERNEL);
|
||||||
|
if (!tc_dev)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
|
priv->i2c_client = tc_dev->client = client;
|
||||||
|
tc_dev->dev = dev;
|
||||||
|
strscpy(tc_dev->name, "imx390", sizeof(tc_dev->name));
|
||||||
|
tc_dev->dev_regmap_config = &sensor_regmap_config;
|
||||||
|
tc_dev->sensor_ops = &imx390_common_ops;
|
||||||
|
tc_dev->v4l2sd_internal_ops = &imx390_subdev_internal_ops;
|
||||||
|
tc_dev->tcctrl_ops = &imx390_ctrl_ops;
|
||||||
|
|
||||||
|
err = tegracam_device_register(tc_dev);
|
||||||
|
if (err) {
|
||||||
|
dev_err(dev, "tegra camera driver registration failed\n");
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
priv->tc_dev = tc_dev;
|
||||||
|
priv->s_data = tc_dev->s_data;
|
||||||
|
priv->subdev = &tc_dev->s_data->subdev;
|
||||||
|
|
||||||
|
tegracam_set_privdata(tc_dev, (void *)priv);
|
||||||
|
|
||||||
|
err = imx390_board_setup(priv);
|
||||||
|
if (err) {
|
||||||
|
tegracam_device_unregister(tc_dev);
|
||||||
|
dev_err(dev, "board setup failed\n");
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
mutex_init(&serdes_lock__);
|
||||||
|
|
||||||
|
/* Pair sensor to serializer dev */
|
||||||
|
err = max9295_sdev_pair(priv->ser_dev, &priv->g_ctx);
|
||||||
|
if (err) {
|
||||||
|
dev_err(&client->dev, "gmsl ser pairing failed\n");
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Register sensor to deserializer dev */
|
||||||
|
err = max9296_sdev_register(priv->dser_dev, &priv->g_ctx);
|
||||||
|
if (err) {
|
||||||
|
dev_err(&client->dev, "gmsl deserializer register failed\n");
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* gmsl serdes setup
|
||||||
|
*
|
||||||
|
* Sensor power on/off should be the right place for serdes
|
||||||
|
* setup/reset. But the problem is, the total required delay
|
||||||
|
* in serdes setup/reset exceeds the frame wait timeout, looks to
|
||||||
|
* be related to multiple channel open and close sequence
|
||||||
|
* issue (#BUG 200477330).
|
||||||
|
* Once this bug is fixed, these may be moved to power on/off.
|
||||||
|
* The delays in serdes is as per guidelines and can't be reduced,
|
||||||
|
* so it is placed in probe/remove, though for that, deserializer
|
||||||
|
* would be powered on always post boot, until 1.2v is supplied
|
||||||
|
* to deserializer from CVB.
|
||||||
|
*/
|
||||||
|
err = imx390_gmsl_serdes_setup(priv);
|
||||||
|
if (err) {
|
||||||
|
dev_err(&client->dev,
|
||||||
|
"%s gmsl serdes setup failed\n", __func__);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
err = tegracam_v4l2subdev_register(tc_dev, true);
|
||||||
|
if (err) {
|
||||||
|
dev_err(dev, "tegra camera subdev registration failed\n");
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
dev_info(&client->dev, "Detected IMX390 sensor\n");
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined(NV_I2C_DRIVER_STRUCT_REMOVE_RETURN_TYPE_INT) /* Linux 6.1 */
|
||||||
|
static int imx390_remove(struct i2c_client *client)
|
||||||
|
#else
|
||||||
|
static void imx390_remove(struct i2c_client *client)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
struct camera_common_data *s_data = to_camera_common_data(&client->dev);
|
||||||
|
struct imx390 *priv;
|
||||||
|
|
||||||
|
if (!s_data)
|
||||||
|
#if defined(NV_I2C_DRIVER_STRUCT_REMOVE_RETURN_TYPE_INT) /* Linux 6.1 */
|
||||||
|
return -EINVAL;
|
||||||
|
#else
|
||||||
|
return;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
priv = (struct imx390 *)s_data->priv;
|
||||||
|
|
||||||
|
imx390_gmsl_serdes_reset(priv);
|
||||||
|
|
||||||
|
mutex_destroy(&serdes_lock__);
|
||||||
|
tegracam_v4l2subdev_unregister(priv->tc_dev);
|
||||||
|
tegracam_device_unregister(priv->tc_dev);
|
||||||
|
|
||||||
|
#if defined(NV_I2C_DRIVER_STRUCT_REMOVE_RETURN_TYPE_INT) /* Linux 6.1 */
|
||||||
|
return 0;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
static const struct i2c_device_id imx390_id[] = {
|
||||||
|
{ "imx390", 0 },
|
||||||
|
{ }
|
||||||
|
};
|
||||||
|
|
||||||
|
MODULE_DEVICE_TABLE(i2c, imx390_id);
|
||||||
|
|
||||||
|
static struct i2c_driver imx390_i2c_driver = {
|
||||||
|
.driver = {
|
||||||
|
.name = "imx390",
|
||||||
|
.owner = THIS_MODULE,
|
||||||
|
.of_match_table = of_match_ptr(imx390_of_match),
|
||||||
|
},
|
||||||
|
.probe = imx390_probe,
|
||||||
|
.remove = imx390_remove,
|
||||||
|
.id_table = imx390_id,
|
||||||
|
};
|
||||||
|
|
||||||
|
module_i2c_driver(imx390_i2c_driver);
|
||||||
|
|
||||||
|
MODULE_DESCRIPTION("Media Controller driver for Sony IMX390");
|
||||||
|
MODULE_AUTHOR("NVIDIA Corporation");
|
||||||
|
MODULE_AUTHOR("Sudhir Vyas <svyas@nvidia.com");
|
||||||
|
MODULE_LICENSE("GPL v2");
|
||||||
Reference in New Issue
Block a user