Commit fb66852d authored by Mauro Carvalho Chehab's avatar Mauro Carvalho Chehab Committed by Mauro Carvalho Chehab

[media] tw686x: use a formula instead of two tables for div

Instead of using two tables to estimate the temporal decimation
factor, use a formula. This allows to get the closest fps, which
sounds better than the current tables.

Also, the current code doesn't store the real framerate.

This patch fixes the above issues.

[Ezequiel:
  - introduce a TW686X_MAX_FPS macro for max_fps.
  - use hweight_long instead of open coding the set bits count.]
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@osg.samsung.com>
Signed-off-by: default avatarEzequiel Garcia <ezequiel@vanguardiasur.com.ar>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@s-opensource.com>
parent f91e5c0c
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#define TW686X_INPUTS_PER_CH 4 #define TW686X_INPUTS_PER_CH 4
#define TW686X_VIDEO_WIDTH 720 #define TW686X_VIDEO_WIDTH 720
#define TW686X_VIDEO_HEIGHT(id) ((id & V4L2_STD_525_60) ? 480 : 576) #define TW686X_VIDEO_HEIGHT(id) ((id & V4L2_STD_525_60) ? 480 : 576)
#define TW686X_MAX_FPS(id) ((id & V4L2_STD_525_60) ? 30 : 25)
#define TW686X_MAX_SG_ENTRY_SIZE 4096 #define TW686X_MAX_SG_ENTRY_SIZE 4096
#define TW686X_MAX_SG_DESC_COUNT 256 /* PAL 720x576 needs 203 4-KB pages */ #define TW686X_MAX_SG_DESC_COUNT 256 /* PAL 720x576 needs 203 4-KB pages */
...@@ -340,53 +341,79 @@ static const struct tw686x_dma_ops sg_dma_ops = { ...@@ -340,53 +341,79 @@ static const struct tw686x_dma_ops sg_dma_ops = {
.field = V4L2_FIELD_SEQ_TB, .field = V4L2_FIELD_SEQ_TB,
}; };
static unsigned int tw686x_fields_map(v4l2_std_id std, unsigned int fps) static const unsigned int fps_map[15] = {
/*
* bit 31 enables selecting the field control register
* bits 0-29 are a bitmask with fields that will be output.
* For NTSC (and PAL-M, PAL-60), all 30 bits are used.
* For other PAL standards, only the first 25 bits are used.
*/
0x00000000, /* output all fields */
0x80000006, /* 2 fps (60Hz), 2 fps (50Hz) */
0x80018006, /* 4 fps (60Hz), 4 fps (50Hz) */
0x80618006, /* 6 fps (60Hz), 6 fps (50Hz) */
0x81818186, /* 8 fps (60Hz), 8 fps (50Hz) */
0x86186186, /* 10 fps (60Hz), 8 fps (50Hz) */
0x86619866, /* 12 fps (60Hz), 10 fps (50Hz) */
0x86666666, /* 14 fps (60Hz), 12 fps (50Hz) */
0x9999999e, /* 16 fps (60Hz), 14 fps (50Hz) */
0x99e6799e, /* 18 fps (60Hz), 16 fps (50Hz) */
0x9e79e79e, /* 20 fps (60Hz), 16 fps (50Hz) */
0x9e7e7e7e, /* 22 fps (60Hz), 18 fps (50Hz) */
0x9fe7f9fe, /* 24 fps (60Hz), 20 fps (50Hz) */
0x9ffe7ffe, /* 26 fps (60Hz), 22 fps (50Hz) */
0x9ffffffe, /* 28 fps (60Hz), 24 fps (50Hz) */
};
static unsigned int tw686x_real_fps(unsigned int index, unsigned int max_fps)
{ {
static const unsigned int map[15] = { unsigned long mask;
0x00000000, 0x00000001, 0x00004001, 0x00104001, 0x00404041,
0x01041041, 0x01104411, 0x01111111, 0x04444445, 0x04511445,
0x05145145, 0x05151515, 0x05515455, 0x05551555, 0x05555555
};
static const unsigned int std_625_50[26] = {
0, 1, 1, 2, 3, 3, 4, 4, 5, 5, 6, 7, 7,
8, 8, 9, 10, 10, 11, 11, 12, 13, 13, 14, 14, 0
};
static const unsigned int std_525_60[31] = {
0, 1, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7,
8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 0, 0
};
unsigned int i; if (!index || index >= ARRAY_SIZE(fps_map))
return max_fps;
if (std & V4L2_STD_525_60) { mask = GENMASK(max_fps - 1, 0);
if (fps >= ARRAY_SIZE(std_525_60)) return hweight_long(fps_map[index] & mask);
fps = 30; }
i = std_525_60[fps];
} else { static unsigned int tw686x_fps_idx(unsigned int fps, unsigned int max_fps)
if (fps >= ARRAY_SIZE(std_625_50)) {
fps = 25; unsigned int idx, real_fps;
i = std_625_50[fps]; int delta;
}
/* First guess */
idx = (12 + 15 * fps) / max_fps;
/* Minimal possible framerate is 2 frames per second */
if (!idx)
return 1;
/* Check if the difference is bigger than abs(1) and adjust */
real_fps = tw686x_real_fps(idx, max_fps);
delta = real_fps - fps;
if (delta < -1)
idx++;
else if (delta > 1)
idx--;
/* Max framerate */
if (idx >= 15)
return 0;
return map[i]; return idx;
} }
static void tw686x_set_framerate(struct tw686x_video_channel *vc, static void tw686x_set_framerate(struct tw686x_video_channel *vc,
unsigned int fps) unsigned int fps)
{ {
unsigned int map; unsigned int i;
if (vc->fps == fps) if (vc->fps == fps)
return; return;
map = tw686x_fields_map(vc->video_standard, fps) << 1; i = tw686x_fps_idx(fps, TW686X_MAX_FPS(vc->video_standard));
map |= map << 1; reg_write(vc->dev, VIDEO_FIELD_CTRL[vc->ch], fps_map[i]);
if (map > 0) vc->fps = tw686x_real_fps(i, TW686X_MAX_FPS(vc->video_standard));
map |= BIT(31);
reg_write(vc->dev, VIDEO_FIELD_CTRL[vc->ch], map);
vc->fps = fps;
} }
static const struct tw686x_format *format_by_fourcc(unsigned int fourcc) static const struct tw686x_format *format_by_fourcc(unsigned int fourcc)
......
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