Commit 82731a19 authored by Sakari Ailus's avatar Sakari Ailus Committed by Mauro Carvalho Chehab

media: smiapp: Use CCS register flags

Use the CCS register flags instead of the old smia flags. The
new flags include the register width information that was separate from
the register flags previously.
Signed-off-by: default avatarSakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+huawei@kernel.org>
parent 6493c4b7
...@@ -7,11 +7,11 @@ ...@@ -7,11 +7,11 @@
* Copyright (C) 2011--2012 Nokia Corporation * Copyright (C) 2011--2012 Nokia Corporation
* Contact: Sakari Ailus <sakari.ailus@iki.fi> * Contact: Sakari Ailus <sakari.ailus@iki.fi>
*/ */
#define SMIAPP_REG_MK_U8(r) ((SMIAPP_REG_8BIT << 16) | (r)) #define SMIAPP_REG_MK_U8(r) (r)
#define SMIAPP_REG_MK_U16(r) ((SMIAPP_REG_16BIT << 16) | (r)) #define SMIAPP_REG_MK_U16(r) (CCS_FL_16BIT | (r))
#define SMIAPP_REG_MK_U32(r) ((SMIAPP_REG_32BIT << 16) | (r)) #define SMIAPP_REG_MK_U32(r) (CCS_FL_32BIT | (r))
#define SMIAPP_REG_MK_F32(r) (SMIAPP_REG_FLAG_FLOAT | (SMIAPP_REG_32BIT << 16) | (r)) #define SMIAPP_REG_MK_F32(r) (CCS_FL_FLOAT_IREAL | CCS_FL_32BIT | (r))
#define SMIAPP_REG_U16_MODEL_ID SMIAPP_REG_MK_U16(0x0000) #define SMIAPP_REG_U16_MODEL_ID SMIAPP_REG_MK_U16(0x0000)
#define SMIAPP_REG_U8_REVISION_NUMBER_MAJOR SMIAPP_REG_MK_U8(0x0002) #define SMIAPP_REG_U8_REVISION_NUMBER_MAJOR SMIAPP_REG_MK_U8(0x0002)
......
...@@ -133,6 +133,16 @@ static int ____smiapp_read_8only(struct smiapp_sensor *sensor, u16 reg, ...@@ -133,6 +133,16 @@ static int ____smiapp_read_8only(struct smiapp_sensor *sensor, u16 reg,
return 0; return 0;
} }
unsigned int ccs_reg_width(u32 reg)
{
if (reg & CCS_FL_16BIT)
return sizeof(uint16_t);
if (reg & CCS_FL_32BIT)
return sizeof(uint32_t);
return sizeof(uint8_t);
}
/* /*
* Read a 8/16/32-bit i2c register. The value is returned in 'val'. * Read a 8/16/32-bit i2c register. The value is returned in 'val'.
* Returns zero if successful, or non-zero otherwise. * Returns zero if successful, or non-zero otherwise.
...@@ -141,13 +151,9 @@ static int __smiapp_read(struct smiapp_sensor *sensor, u32 reg, u32 *val, ...@@ -141,13 +151,9 @@ static int __smiapp_read(struct smiapp_sensor *sensor, u32 reg, u32 *val,
bool only8) bool only8)
{ {
struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd); struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
u8 len = SMIAPP_REG_WIDTH(reg); unsigned int len = ccs_reg_width(reg);
int rval; int rval;
if (len != SMIAPP_REG_8BIT && len != SMIAPP_REG_16BIT
&& len != SMIAPP_REG_32BIT)
return -EINVAL;
if (!only8) if (!only8)
rval = ____smiapp_read(sensor, SMIAPP_REG_ADDR(reg), len, val); rval = ____smiapp_read(sensor, SMIAPP_REG_ADDR(reg), len, val);
else else
...@@ -156,7 +162,7 @@ static int __smiapp_read(struct smiapp_sensor *sensor, u32 reg, u32 *val, ...@@ -156,7 +162,7 @@ static int __smiapp_read(struct smiapp_sensor *sensor, u32 reg, u32 *val,
if (rval < 0) if (rval < 0)
return rval; return rval;
if (reg & SMIAPP_REG_FLAG_FLOAT) if (reg & CCS_FL_FLOAT_IREAL)
*val = float_to_u32_mul_1000000(client, *val); *val = float_to_u32_mul_1000000(client, *val);
return 0; return 0;
...@@ -204,7 +210,7 @@ int smiapp_write_no_quirk(struct smiapp_sensor *sensor, u32 reg, u32 val) ...@@ -204,7 +210,7 @@ int smiapp_write_no_quirk(struct smiapp_sensor *sensor, u32 reg, u32 val)
struct i2c_msg msg; struct i2c_msg msg;
unsigned char data[6]; unsigned char data[6];
unsigned int retries; unsigned int retries;
u8 len = SMIAPP_REG_WIDTH(reg); unsigned int len = ccs_reg_width(reg);
int r; int r;
if (len > sizeof(data) - 2) if (len > sizeof(data) - 2)
......
...@@ -14,16 +14,9 @@ ...@@ -14,16 +14,9 @@
#include <linux/i2c.h> #include <linux/i2c.h>
#include <linux/types.h> #include <linux/types.h>
#define SMIAPP_REG_ADDR(reg) ((u16)reg) #include "ccs-regs.h"
#define SMIAPP_REG_WIDTH(reg) ((u8)(reg >> 16))
#define SMIAPP_REG_FLAGS(reg) ((u8)(reg >> 24))
/* Use upper 8 bits of the type field for flags */
#define SMIAPP_REG_FLAG_FLOAT (1 << 24)
#define SMIAPP_REG_8BIT 1 #define SMIAPP_REG_ADDR(reg) ((u16)reg)
#define SMIAPP_REG_16BIT 2
#define SMIAPP_REG_32BIT 4
struct smiapp_sensor; struct smiapp_sensor;
...@@ -33,4 +26,6 @@ int smiapp_read_8only(struct smiapp_sensor *sensor, u32 reg, u32 *val); ...@@ -33,4 +26,6 @@ int smiapp_read_8only(struct smiapp_sensor *sensor, u32 reg, u32 *val);
int smiapp_write_no_quirk(struct smiapp_sensor *sensor, u32 reg, u32 val); int smiapp_write_no_quirk(struct smiapp_sensor *sensor, u32 reg, u32 val);
int smiapp_write(struct smiapp_sensor *sensor, u32 reg, u32 val); int smiapp_write(struct smiapp_sensor *sensor, u32 reg, u32 val);
unsigned int ccs_reg_width(u32 reg);
#endif #endif
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