media: ti-vpe: cal: Turn reg_(read|write)_field() into inline functions
Turn the reg_(read|write)_field() macros into inline functions for additional type safety. Use the FIELD_GET() and FIELD_PREP() macros internally instead of reinventing the wheel. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Tomi Valkeinen <tomi.valkeinen@ti.com> Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
This commit is contained in:
parent
d2b084eb1e
commit
50797fb30b
@ -6,6 +6,7 @@
|
|||||||
* Benoit Parrot, <bparrot@ti.com>
|
* Benoit Parrot, <bparrot@ti.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <linux/bitfield.h>
|
||||||
#include <linux/clk.h>
|
#include <linux/clk.h>
|
||||||
#include <linux/delay.h>
|
#include <linux/delay.h>
|
||||||
#include <linux/interrupt.h>
|
#include <linux/interrupt.h>
|
||||||
@ -76,13 +77,6 @@ static const struct v4l2_fract
|
|||||||
#define reg_read(dev, offset) ioread32(dev->base + offset)
|
#define reg_read(dev, offset) ioread32(dev->base + offset)
|
||||||
#define reg_write(dev, offset, val) iowrite32(val, dev->base + offset)
|
#define reg_write(dev, offset, val) iowrite32(val, dev->base + offset)
|
||||||
|
|
||||||
#define reg_read_field(dev, offset, mask) get_field(reg_read(dev, offset), \
|
|
||||||
mask)
|
|
||||||
#define reg_write_field(dev, offset, field, mask) { \
|
|
||||||
u32 val = reg_read(dev, offset); \
|
|
||||||
set_field(&val, field, mask); \
|
|
||||||
reg_write(dev, offset, val); }
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------------
|
/* ------------------------------------------------------------------
|
||||||
* Basic structures
|
* Basic structures
|
||||||
* ------------------------------------------------------------------
|
* ------------------------------------------------------------------
|
||||||
@ -418,6 +412,21 @@ struct cal_ctx {
|
|||||||
bool dma_act;
|
bool dma_act;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static inline u32 reg_read_field(struct cal_dev *dev, u32 offset, u32 mask)
|
||||||
|
{
|
||||||
|
return FIELD_GET(mask, reg_read(dev, offset));
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void reg_write_field(struct cal_dev *dev, u32 offset, u32 value,
|
||||||
|
u32 mask)
|
||||||
|
{
|
||||||
|
u32 val = reg_read(dev, offset);
|
||||||
|
|
||||||
|
val &= ~mask;
|
||||||
|
val |= FIELD_PREP(mask, value);
|
||||||
|
reg_write(dev, offset, val);
|
||||||
|
}
|
||||||
|
|
||||||
static const struct cal_fmt *find_format_by_pix(struct cal_ctx *ctx,
|
static const struct cal_fmt *find_format_by_pix(struct cal_ctx *ctx,
|
||||||
u32 pixelformat)
|
u32 pixelformat)
|
||||||
{
|
{
|
||||||
@ -453,11 +462,6 @@ static inline struct cal_ctx *notifier_to_ctx(struct v4l2_async_notifier *n)
|
|||||||
return container_of(n, struct cal_ctx, notifier);
|
return container_of(n, struct cal_ctx, notifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int get_field(u32 value, u32 mask)
|
|
||||||
{
|
|
||||||
return (value & mask) >> __ffs(mask);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void set_field(u32 *valp, u32 field, u32 mask)
|
static inline void set_field(u32 *valp, u32 field, u32 mask)
|
||||||
{
|
{
|
||||||
u32 val = *valp;
|
u32 val = *valp;
|
||||||
|
Loading…
Reference in New Issue
Block a user