Commit d92e7a01 authored by Alexander Stein's avatar Alexander Stein Committed by Hans Verkuil

media: v4l2-cci: Add support for little-endian encoded registers

Some sensors, e.g. Sony IMX290, are using little-endian registers. Add
support for those by encoding the endianness into Bit 20 of the register
address.

Fixes: af73323b ("media: imx290: Convert to new CCI register access helpers")
Cc: stable@vger.kernel.org
Signed-off-by: default avatarAlexander Stein <alexander.stein@ew.tq-group.com>
Reviewed-by: default avatarHans de Goede <hdegoede@redhat.com>
Reviewed-by: default avatarLaurent Pinchart <laurent.pinchart@ideasonboard.com>
[Sakari Ailus: Fixed commit message.]
Signed-off-by: default avatarSakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: default avatarHans Verkuil <hverkuil-cisco@xs4all.nl>
parent 1545c2b9
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
int cci_read(struct regmap *map, u32 reg, u64 *val, int *err) int cci_read(struct regmap *map, u32 reg, u64 *val, int *err)
{ {
bool little_endian;
unsigned int len; unsigned int len;
u8 buf[8]; u8 buf[8];
int ret; int ret;
...@@ -25,6 +26,7 @@ int cci_read(struct regmap *map, u32 reg, u64 *val, int *err) ...@@ -25,6 +26,7 @@ int cci_read(struct regmap *map, u32 reg, u64 *val, int *err)
if (err && *err) if (err && *err)
return *err; return *err;
little_endian = reg & CCI_REG_LE;
len = CCI_REG_WIDTH_BYTES(reg); len = CCI_REG_WIDTH_BYTES(reg);
reg = CCI_REG_ADDR(reg); reg = CCI_REG_ADDR(reg);
...@@ -40,15 +42,27 @@ int cci_read(struct regmap *map, u32 reg, u64 *val, int *err) ...@@ -40,15 +42,27 @@ int cci_read(struct regmap *map, u32 reg, u64 *val, int *err)
*val = buf[0]; *val = buf[0];
break; break;
case 2: case 2:
if (little_endian)
*val = get_unaligned_le16(buf);
else
*val = get_unaligned_be16(buf); *val = get_unaligned_be16(buf);
break; break;
case 3: case 3:
if (little_endian)
*val = get_unaligned_le24(buf);
else
*val = get_unaligned_be24(buf); *val = get_unaligned_be24(buf);
break; break;
case 4: case 4:
if (little_endian)
*val = get_unaligned_le32(buf);
else
*val = get_unaligned_be32(buf); *val = get_unaligned_be32(buf);
break; break;
case 8: case 8:
if (little_endian)
*val = get_unaligned_le64(buf);
else
*val = get_unaligned_be64(buf); *val = get_unaligned_be64(buf);
break; break;
default: default:
...@@ -68,6 +82,7 @@ EXPORT_SYMBOL_GPL(cci_read); ...@@ -68,6 +82,7 @@ EXPORT_SYMBOL_GPL(cci_read);
int cci_write(struct regmap *map, u32 reg, u64 val, int *err) int cci_write(struct regmap *map, u32 reg, u64 val, int *err)
{ {
bool little_endian;
unsigned int len; unsigned int len;
u8 buf[8]; u8 buf[8];
int ret; int ret;
...@@ -75,6 +90,7 @@ int cci_write(struct regmap *map, u32 reg, u64 val, int *err) ...@@ -75,6 +90,7 @@ int cci_write(struct regmap *map, u32 reg, u64 val, int *err)
if (err && *err) if (err && *err)
return *err; return *err;
little_endian = reg & CCI_REG_LE;
len = CCI_REG_WIDTH_BYTES(reg); len = CCI_REG_WIDTH_BYTES(reg);
reg = CCI_REG_ADDR(reg); reg = CCI_REG_ADDR(reg);
...@@ -83,15 +99,27 @@ int cci_write(struct regmap *map, u32 reg, u64 val, int *err) ...@@ -83,15 +99,27 @@ int cci_write(struct regmap *map, u32 reg, u64 val, int *err)
buf[0] = val; buf[0] = val;
break; break;
case 2: case 2:
if (little_endian)
put_unaligned_le16(val, buf);
else
put_unaligned_be16(val, buf); put_unaligned_be16(val, buf);
break; break;
case 3: case 3:
if (little_endian)
put_unaligned_le24(val, buf);
else
put_unaligned_be24(val, buf); put_unaligned_be24(val, buf);
break; break;
case 4: case 4:
if (little_endian)
put_unaligned_le32(val, buf);
else
put_unaligned_be32(val, buf); put_unaligned_be32(val, buf);
break; break;
case 8: case 8:
if (little_endian)
put_unaligned_le64(val, buf);
else
put_unaligned_be64(val, buf); put_unaligned_be64(val, buf);
break; break;
default: default:
......
...@@ -43,12 +43,17 @@ struct cci_reg_sequence { ...@@ -43,12 +43,17 @@ struct cci_reg_sequence {
#define CCI_REG_WIDTH_BYTES(x) FIELD_GET(CCI_REG_WIDTH_MASK, x) #define CCI_REG_WIDTH_BYTES(x) FIELD_GET(CCI_REG_WIDTH_MASK, x)
#define CCI_REG_WIDTH(x) (CCI_REG_WIDTH_BYTES(x) << 3) #define CCI_REG_WIDTH(x) (CCI_REG_WIDTH_BYTES(x) << 3)
#define CCI_REG_ADDR(x) FIELD_GET(CCI_REG_ADDR_MASK, x) #define CCI_REG_ADDR(x) FIELD_GET(CCI_REG_ADDR_MASK, x)
#define CCI_REG_LE BIT(20)
#define CCI_REG8(x) ((1 << CCI_REG_WIDTH_SHIFT) | (x)) #define CCI_REG8(x) ((1 << CCI_REG_WIDTH_SHIFT) | (x))
#define CCI_REG16(x) ((2 << CCI_REG_WIDTH_SHIFT) | (x)) #define CCI_REG16(x) ((2 << CCI_REG_WIDTH_SHIFT) | (x))
#define CCI_REG24(x) ((3 << CCI_REG_WIDTH_SHIFT) | (x)) #define CCI_REG24(x) ((3 << CCI_REG_WIDTH_SHIFT) | (x))
#define CCI_REG32(x) ((4 << CCI_REG_WIDTH_SHIFT) | (x)) #define CCI_REG32(x) ((4 << CCI_REG_WIDTH_SHIFT) | (x))
#define CCI_REG64(x) ((8 << CCI_REG_WIDTH_SHIFT) | (x)) #define CCI_REG64(x) ((8 << CCI_REG_WIDTH_SHIFT) | (x))
#define CCI_REG16_LE(x) (CCI_REG_LE | (2U << CCI_REG_WIDTH_SHIFT) | (x))
#define CCI_REG24_LE(x) (CCI_REG_LE | (3U << CCI_REG_WIDTH_SHIFT) | (x))
#define CCI_REG32_LE(x) (CCI_REG_LE | (4U << CCI_REG_WIDTH_SHIFT) | (x))
#define CCI_REG64_LE(x) (CCI_REG_LE | (8U << CCI_REG_WIDTH_SHIFT) | (x))
/** /**
* cci_read() - Read a value from a single CCI register * cci_read() - Read a value from a single CCI register
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment