169 lines · c
1/* SPDX-License-Identifier: GPL-2.0 */2/*3 * Imagination E5010 JPEG Encoder driver.4 *5 * Copyright (C) 2023 Texas Instruments Incorporated - https://www.ti.com/6 *7 * Author: David Huang <d-huang@ti.com>8 * Author: Devarsh Thakkar <devarsht@ti.com>9 */10 11#include <media/v4l2-ctrls.h>12#include <media/v4l2-device.h>13#include <media/v4l2-fh.h>14 15#ifndef _E5010_JPEG_ENC_H16#define _E5010_JPEG_ENC_H17 18#define MAX_PLANES 219#define HEADER_SIZE 0x025D20#define MIN_DIMENSION 6421#define MAX_DIMENSION 819222#define DEFAULT_WIDTH 64023#define DEFAULT_HEIGHT 48024#define E5010_MODULE_NAME "e5010"25#define JPEG_MAX_BYTES_PER_PIXEL 226 27/* JPEG marker definitions */28#define START_OF_IMAGE 0xFFD829#define SOF_BASELINE_DCT 0xFFC030#define END_OF_IMAGE 0xFFD931#define START_OF_SCAN 0xFFDA32 33/* Definitions for the huffman table specification in the Marker segment */34#define DHT_MARKER 0xFFC435#define LH_DC 0x001F36#define LH_AC 0x00B537 38/* Definitions for the quantization table specification in the Marker segment */39#define DQT_MARKER 0xFFDB40#define ACMAX 0x03FF41#define DCMAX 0x07FF42 43/* Length and precision of the quantization table parameters */44#define LQPQ 0x0043045#define QMAX 25546 47/* Misc JPEG header definitions */48#define UC_NUM_COMP 349#define PRECISION 850#define HORZ_SAMPLING_FACTOR (2 << 4)51#define VERT_SAMPLING_FACTOR_422 152#define VERT_SAMPLING_FACTOR_420 253#define COMPONENTS_IN_SCAN 354#define PELS_IN_BLOCK 6455 56/* Used for Qp table generation */57#define LUMINOSITY 1058#define CONTRAST 159#define INCREASE 260#define QP_TABLE_SIZE (8 * 8)61#define QP_TABLE_FIELD_OFFSET 0x0462 63/*64 * vb2 queue structure65 * contains queue data information66 *67 * @fmt: format info68 * @width: frame width69 * @height: frame height70 * @bytesperline: bytes per line in memory71 * @size_image: image size in memory72 */73struct e5010_q_data {74 struct e5010_fmt *fmt;75 u32 width;76 u32 height;77 u32 width_adjusted;78 u32 height_adjusted;79 u32 sizeimage[MAX_PLANES];80 u32 bytesperline[MAX_PLANES];81 u32 sequence;82 struct v4l2_rect crop;83 bool crop_set;84};85 86/*87 * Driver device structure88 * Holds all memory handles and global parameters89 * Shared by all instances90 */91struct e5010_dev {92 struct device *dev;93 struct v4l2_device v4l2_dev;94 struct v4l2_m2m_dev *m2m_dev;95 struct video_device *vdev;96 void __iomem *core_base;97 void __iomem *mmu_base;98 struct clk *clk;99 struct e5010_context *last_context_run;100 /* Protect access to device data */101 struct mutex mutex;102 /* Protect access to hardware*/103 spinlock_t hw_lock;104};105 106/*107 * Driver context structure108 * One of these exists for every m2m context109 * Holds context specific data110 */111struct e5010_context {112 struct v4l2_fh fh;113 struct e5010_dev *e5010;114 struct e5010_q_data out_queue;115 struct e5010_q_data cap_queue;116 int quality;117 bool update_qp;118 struct v4l2_ctrl_handler ctrl_handler;119 u8 luma_qp[QP_TABLE_SIZE];120 u8 chroma_qp[QP_TABLE_SIZE];121};122 123/*124 * Buffer structure125 * Contains info for all buffers126 */127struct e5010_buffer {128 struct v4l2_m2m_buffer buffer;129};130 131enum {132 CHROMA_ORDER_CB_CR = 0, //UV ordering133 CHROMA_ORDER_CR_CB = 1, //VU ordering134};135 136enum {137 SUBSAMPLING_420 = 1,138 SUBSAMPLING_422 = 2,139};140 141/*142 * e5010 format structure143 * contains format information144 */145struct e5010_fmt {146 u32 fourcc;147 unsigned int num_planes;148 unsigned int type;149 u32 subsampling;150 u32 chroma_order;151 const struct v4l2_frmsize_stepwise frmsize;152};153 154/*155 * struct e5010_ctrl - contains info for each supported v4l2 control156 */157struct e5010_ctrl {158 unsigned int cid;159 enum v4l2_ctrl_type type;160 unsigned char name[32];161 int minimum;162 int maximum;163 int step;164 int default_value;165 unsigned char compound;166};167 168#endif169