Skip to content

Commit 94bcda1

Browse files
author
philippe baetens
committed
media/i2c: changes to Mira220 driver:
Small fixes, mostly cosmetic. Removed unneeded code. Differentiate between physical array and active array. Signed-off-by: philippe baetens <[email protected]>
1 parent 88be0ee commit 94bcda1

File tree

1 file changed

+35
-53
lines changed

1 file changed

+35
-53
lines changed

drivers/media/i2c/mira220.c

Lines changed: 35 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -22,85 +22,92 @@
2222
#include <media/v4l2-cci.h>
2323
#include <linux/unaligned.h>
2424

25-
#include <linux/v4l2-controls.h>
26-
27-
#define MIRA220_NATIVE_WIDTH 1600U
28-
#define MIRA220_NATIVE_HEIGHT 1400U
29-
30-
#define MIRA220_PIXEL_ARRAY_LEFT 0U
31-
#define MIRA220_PIXEL_ARRAY_TOP 0U
25+
/* Active pixel array is 1600 (H) x 1400 (V) pixels.
26+
* Physical resolution including buffer pixels: 1642 (H) x 1464 (V) pixels.
27+
*/
28+
#define MIRA220_NATIVE_WIDTH 1642U
29+
#define MIRA220_NATIVE_HEIGHT 1464U
30+
#define MIRA220_PIXEL_ARRAY_LEFT 21U
31+
#define MIRA220_PIXEL_ARRAY_TOP 32U
3232
#define MIRA220_PIXEL_ARRAY_WIDTH 1600U
3333
#define MIRA220_PIXEL_ARRAY_HEIGHT 1400U
3434

35-
/* mira220 does not support analog gain. */
35+
/* Mira220 does not support analog gain. */
3636
#define MIRA220_ANALOG_GAIN_MIN 1
3737
#define MIRA220_ANALOG_GAIN_MAX 1
3838
#define MIRA220_ANALOG_GAIN_STEP 1
3939
#define MIRA220_ANALOG_GAIN_DEFAULT MIRA220_ANALOG_GAIN_MIN
4040

41+
/* Bit depth */
4142
#define MIRA220_BIT_DEPTH_REG CCI_REG8(0x209E)
4243
#define MIRA220_BIT_DEPTH_12_BIT 0x02
4344
#define MIRA220_BIT_DEPTH_10_BIT 0x04
4445
#define MIRA220_BIT_DEPTH_8_BIT 0x06
45-
4646
#define MIRA220_CSI_DATA_TYPE_REG CCI_REG8(0x208D)
4747
#define MIRA220_CSI_DATA_TYPE_12_BIT 0x04
4848
#define MIRA220_CSI_DATA_TYPE_10_BIT 0x02
4949
#define MIRA220_CSI_DATA_TYPE_8_BIT 0x01
5050

51+
/* Imager state master/slave registers */
5152
#define MIRA220_IMAGER_STATE_REG CCI_REG8(0x1003)
5253
#define MIRA220_IMAGER_STATE_STOP_AT_ROW 0x02
5354
#define MIRA220_IMAGER_STATE_STOP_AT_FRAME 0x04
5455
#define MIRA220_IMAGER_STATE_MASTER_CONTROL 0x10
56+
#define MIRA220_IMAGER_STATE_SLAVE_CONTROL 0x08
5557

58+
/* Start image acquisition */
5659
#define MIRA220_IMAGER_RUN_REG CCI_REG8(0x10F0)
5760
#define MIRA220_IMAGER_RUN_START 0x01
5861
#define MIRA220_IMAGER_RUN_STOP 0x00
5962

63+
/* Continuous running, not limited to nr of frames. */
6064
#define MIRA220_IMAGER_RUN_CONT_REG CCI_REG8(0x1002)
6165
#define MIRA220_IMAGER_RUN_CONT_ENABLE 0x04
6266
#define MIRA220_IMAGER_RUN_CONT_DISABLE 0x00
6367

64-
// Exposure time is indicated in number of rows
68+
/* Exposure time is indicated in number of rows */
6569
#define MIRA220_EXP_TIME_REG CCI_REG16_LE(0x100C)
66-
// VBLANK is indicated in number of rows
70+
71+
/* Vertical Blank */
6772
#define MIRA220_VBLANK_REG CCI_REG16_LE(0x1012)
6873

74+
/* Horizontal flip */
6975
#define MIRA220_HFLIP_REG CCI_REG8(0x209C)
7076
#define MIRA220_HFLIP_ENABLE_MIRROR 1
7177
#define MIRA220_HFLIP_DISABLE_MIRROR 0
7278

79+
/* Vertical flip */
7380
#define MIRA220_VFLIP_REG CCI_REG8(0x1095)
7481
#define MIRA220_VFLIP_ENABLE_FLIP 1
7582
#define MIRA220_VFLIP_DISABLE_FLIP 0
7683

84+
/* OTP control */
7785
#define MIRA220_OTP_CMD_REG CCI_REG8(0x0080)
7886
#define MIRA220_OTP_CMD_UP 0x4
7987
#define MIRA220_OTP_CMD_DOWN 0x8
8088

89+
/* Global sampling time */
8190
#define MIRA220_GLOB_NUM_CLK_CYCLES 1928
91+
92+
/* External clock frequency is 38.4 M */
8293
#define MIRA220_SUPPORTED_XCLK_FREQ 38400000
94+
8395
// Default exposure is adjusted to mode with smallest height
8496
#define MIRA220_DEFAULT_EXPOSURE 1000
8597
#define MIRA220_EXPOSURE_MIN 1
8698
// Power on function timing
8799
#define MIRA220_XCLR_MIN_DELAY_US 100000
88100
#define MIRA220_XCLR_DELAY_RANGE_US 30
89101

102+
/* Pixel rate is an artificial value
103+
* This value is used for timing calculations
104+
* in combination with vblank/hblank
105+
*/
90106
#define MIRA220_PIXEL_RATE 384000000 //384M (x10)
91107

92-
/* Should match device tree link freq */
93-
#define MIRA220_DEFAULT_LINK_FREQ 750000000
94-
95-
96-
#define MIRA220_HBLANK_640x480_120FPS 3860
97-
#define MIRA220_HBLANK_1600x1400_30FPS 2900
98-
#define MIRA220_HBLANK_1600x1400_1500 1400
99-
100-
#define MIRA220_HBLANK_400x400_304 2640
101-
#define MIRA220_HBLANK_640x480_304 2400
102108
#define MIRA220_HBLANK_1600x1400_304 1440
103109

110+
/* Test Pattern */
104111
#define MIRA220_REG_TEST_PATTERN CCI_REG8(0x2091)
105112
#define MIRA220_TEST_PATTERN_DISABLE 0x00
106113
#define MIRA220_TEST_PATTERN_VERTICAL_GRADIENT 0x01
@@ -1153,20 +1160,10 @@ static int mira220_write_stop_streaming_regs(struct mira220 *mira220)
11531160
{
11541161
struct i2c_client *const client = v4l2_get_subdevdata(&mira220->sd);
11551162
int ret = 0;
1156-
int try_cnt;
1157-
1158-
for (try_cnt = 0; try_cnt < 5; try_cnt++) {
1159-
ret = cci_write(mira220->regmap, MIRA220_IMAGER_STATE_REG,
1160-
MIRA220_IMAGER_STATE_STOP_AT_ROW, NULL);
1161-
if (ret) {
1162-
dev_err(&client->dev,
1163-
"Error setting stop-at-row imager state at try %d",
1164-
try_cnt);
1165-
usleep_range(1000, 1100);
1166-
} else {
1167-
break;
1168-
}
1169-
}
1163+
1164+
ret = cci_write(mira220->regmap, MIRA220_IMAGER_STATE_REG,
1165+
MIRA220_IMAGER_STATE_STOP_AT_ROW, NULL);
1166+
11701167
if (ret) {
11711168
dev_err(&client->dev,
11721169
"Error setting stop-at-row imager state after multiple attempts. Exiting.");
@@ -1187,10 +1184,10 @@ static int mira220_write_stop_streaming_regs(struct mira220 *mira220)
11871184

11881185
// Returns the maximum exposure time in row_length (reg value).
11891186
// Calculation is baded on Mira220 datasheet Section 9.2.
1190-
static u32 mira220_calculate_max_exposure_time(u32 vsize, u32 vblank,
1187+
static u32 mira220_calculate_max_exposure_time(u32 height, u32 vblank,
11911188
u32 row_length)
11921189
{
1193-
return (vsize + vblank) -
1190+
return (height + vblank) -
11941191
(int)(MIRA220_GLOB_NUM_CLK_CYCLES / row_length);
11951192
}
11961193

@@ -1225,9 +1222,7 @@ static int mira220_write_exposure_reg(struct mira220 *mira220, u32 exposure)
12251222
// Gets the format code if supported. Otherwise returns the default format code `codes[0]`
12261223
static u32 mira220_validate_format_code_or_default(struct mira220 *mira220,
12271224
u32 code)
1228-
{
1229-
struct i2c_client *client = v4l2_get_subdevdata(&mira220->sd);
1230-
unsigned int i;
1225+
{ unsigned int i;
12311226

12321227
lockdep_assert_held(&mira220->mutex);
12331228

@@ -1236,11 +1231,6 @@ static u32 mira220_validate_format_code_or_default(struct mira220 *mira220,
12361231
break;
12371232

12381233
if (i >= ARRAY_SIZE(codes)) {
1239-
dev_err_ratelimited(&client->dev,
1240-
"Could not set requested format code %u",
1241-
code);
1242-
dev_err_ratelimited(&client->dev, "Using default format %u",
1243-
codes[0]);
12441234
i = 0;
12451235
}
12461236

@@ -1961,7 +1951,6 @@ static int mira220_probe(struct i2c_client *client)
19611951
struct mira220 *mira220;
19621952
int ret;
19631953

1964-
dev_err(dev, "[MIRA220] name: %s.\n", client->name);
19651954

19661955
mira220 = devm_kzalloc(&client->dev, sizeof(*mira220), GFP_KERNEL);
19671956
if (!mira220)
@@ -1970,9 +1959,6 @@ static int mira220_probe(struct i2c_client *client)
19701959
v4l2_i2c_subdev_init(&mira220->sd, client, &mira220_subdev_ops);
19711960
mira220->regmap = devm_cci_regmap_init_i2c(client, 16);
19721961

1973-
/* Parse device tree to check if dtoverlay has param skip-reg-upload=1 */
1974-
/* Set default TBD I2C device address to LED I2C Address*/
1975-
19761962
/* Get system clock (xclk) */
19771963
mira220->xclk = devm_clk_get(dev, NULL);
19781964
if (IS_ERR(mira220->xclk)) {
@@ -2084,9 +2070,6 @@ static const struct of_device_id mira220_dt_ids[] = {
20842070
{ /* sentinel */ } };
20852071
MODULE_DEVICE_TABLE(of, mira220_dt_ids);
20862072

2087-
static const struct i2c_device_id mira220_ids[] = { { "mira220", 0 }, {} };
2088-
MODULE_DEVICE_TABLE(i2c, mira220_ids);
2089-
20902073
static struct i2c_driver mira220_i2c_driver = {
20912074
.driver = {
20922075
.name = "mira220",
@@ -2095,7 +2078,6 @@ static struct i2c_driver mira220_i2c_driver = {
20952078
},
20962079
.probe = mira220_probe,
20972080
.remove = mira220_remove,
2098-
.id_table = mira220_ids,
20992081
};
21002082

21012083
module_i2c_driver(mira220_i2c_driver);

0 commit comments

Comments
 (0)