summaryrefslogtreecommitdiff
path: root/drivers/staging/media/allegro-dvt/allegro-core.c
diff options
context:
space:
mode:
authorMichael Tretter <m.tretter@pengutronix.de>2020-03-16 16:26:26 +0100
committerMauro Carvalho Chehab <mchehab+huawei@kernel.org>2020-03-20 09:12:37 +0100
commitc32c815503fa3bfae575cf92648685c30796f448 (patch)
tree77138d1ba83fffbeb0dc8f931800c9ef7bb7a732 /drivers/staging/media/allegro-dvt/allegro-core.c
parent2fc29ef598b98915ddc698c998cc33c4530b84c8 (diff)
media: allegro: fix calculation of CPB size
The cpb_size is given in kilobytes, but the bitrate is given in bits per second. Therefore, the calculation of the initial removal delay and the cpb size for the firmware were wrong. Convert the bitrate to kilobytes before calculating the cpb size in 90 kHz units for sending it to the firmware. Also reuse the result for the initial removal delay, to make it obvious that we are setting the initial removal delay to the maximum value. Signed-off-by: Michael Tretter <m.tretter@pengutronix.de> Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Diffstat (limited to 'drivers/staging/media/allegro-dvt/allegro-core.c')
-rw-r--r--drivers/staging/media/allegro-dvt/allegro-core.c25
1 files changed, 20 insertions, 5 deletions
diff --git a/drivers/staging/media/allegro-dvt/allegro-core.c b/drivers/staging/media/allegro-dvt/allegro-core.c
index 3b2e970c13ac..ab17e850bd1f 100644
--- a/drivers/staging/media/allegro-dvt/allegro-core.c
+++ b/drivers/staging/media/allegro-dvt/allegro-core.c
@@ -5,6 +5,7 @@
* Allegro DVT video encoder driver
*/
+#include <linux/bits.h>
#include <linux/firmware.h>
#include <linux/interrupt.h>
#include <linux/io.h>
@@ -1053,6 +1054,22 @@ v4l2_bitrate_mode_to_mcu_mode(enum v4l2_mpeg_video_bitrate_mode mode)
}
}
+static u32 v4l2_cpb_size_to_mcu(unsigned int cpb_size, unsigned int bitrate)
+{
+ unsigned int cpb_size_kbit;
+ unsigned int bitrate_kbps;
+
+ /*
+ * The mcu expects the CPB size in units of a 90 kHz clock, but the
+ * channel follows the V4L2_CID_MPEG_VIDEO_H264_CPB_SIZE and stores
+ * the CPB size in kilobytes.
+ */
+ cpb_size_kbit = cpb_size * BITS_PER_BYTE;
+ bitrate_kbps = bitrate / 1000;
+
+ return (cpb_size_kbit * 90000) / bitrate_kbps;
+}
+
static int allegro_mcu_send_create_channel(struct allegro_dev *dev,
struct allegro_channel *channel)
{
@@ -1094,12 +1111,10 @@ static int allegro_mcu_send_create_channel(struct allegro_dev *dev,
msg.rate_control_mode =
v4l2_bitrate_mode_to_mcu_mode(channel->bitrate_mode);
+ msg.cpb_size = v4l2_cpb_size_to_mcu(channel->cpb_size,
+ channel->bitrate_peak);
/* Shall be ]0;cpb_size in 90 kHz units]. Use maximum value. */
- msg.initial_rem_delay =
- ((channel->cpb_size * 1000) / channel->bitrate_peak) * 90000;
- /* Encoder expects cpb_size in units of a 90 kHz clock. */
- msg.cpb_size =
- ((channel->cpb_size * 1000) / channel->bitrate_peak) * 90000;
+ msg.initial_rem_delay = msg.cpb_size;
msg.framerate = 25;
msg.clk_ratio = 1000;
msg.target_bitrate = channel->bitrate;