27 #include <linux/device.h>
29 #include <linux/module.h>
40 {0x01E2, 0x0F30, 0x0FEE},
41 {0x0F9B, 0x01AC, 0x0FB9},
42 {0x0FE0, 0x0EC0, 0x0260}
44 {0x0000, 0x0000, 0x0000}
58 #define FLR_CFA_GRADTHRS_HORZ 0x28
59 #define FLR_CFA_GRADTHRS_VERT 0x28
62 #define FLR_CSUP_GAIN 0x0D
63 #define FLR_CSUP_THRES 0xEB
66 #define FLR_NF_STRGTH 0x03
69 #define FLR_WBAL_DGAIN 0x100
70 #define FLR_WBAL_COEF 0x20
73 #define FLR_BLKADJ_BLUE 0x0
74 #define FLR_BLKADJ_GREEN 0x0
75 #define FLR_BLKADJ_RED 0x0
77 #define DEF_DETECT_CORRECT_VAL 0xe
110 #define PREV_MARGIN_LEFT 8
111 #define PREV_MARGIN_RIGHT 6
112 #define PREV_MARGIN_TOP 4
113 #define PREV_MARGIN_BOTTOM 4
115 #define PREV_MIN_IN_WIDTH 64
116 #define PREV_MIN_IN_HEIGHT 8
117 #define PREV_MAX_IN_HEIGHT 16384
119 #define PREV_MIN_OUT_WIDTH 0
120 #define PREV_MIN_OUT_HEIGHT 0
121 #define PREV_MAX_OUT_WIDTH_REV_1 1280
122 #define PREV_MAX_OUT_WIDTH_REV_2 3300
123 #define PREV_MAX_OUT_WIDTH_REV_15 4096
148 static u32 noise_filter_table[] = {
155 static u32 luma_enhance_table[] = {
173 isp_reg_writel(isp, yt->
table[i],
197 static void preview_enable_invalaw(
struct isp_prev_device *prev,
bool enable)
227 static void preview_enable_hmed(
struct isp_prev_device *prev,
bool enable)
250 static const unsigned int cfa_coef_order[4][4] = {
256 const unsigned int *
order = cfa_coef_order[prev->
params.cfa_order];
270 for (i = 0; i < 4; ++
i) {
299 preview_enable_chroma_suppression(
struct isp_prev_device *prev,
bool enable)
482 static void preview_enable_dcor(
struct isp_prev_device *prev,
bool enable)
498 preview_enable_drkframe_capture(
struct isp_prev_device *prev,
bool enable)
513 static void preview_enable_drkframe(
struct isp_prev_device *prev,
bool enable)
540 isp_reg_writel(isp, nf->
table[i],
660 spin_unlock_irqrestore(&prev->
params.lock, flags);
682 spin_unlock_irqrestore(&prev->
params.lock, flags);
697 | (prev->
params.params[1].update & ~active);
718 prev->
params.params[1].busy &= ~active;
725 prev->
params.params[0].busy &= ~active;
738 to_switch = (prev->
params.params[0].update & ~prev->
params.active)
739 | (prev->
params.params[1].update & prev->
params.active);
740 to_switch &= ~(prev->
params.params[0].busy |
741 prev->
params.params[1].busy);
745 prev->
params.active ^= to_switch;
750 prev->
params.params[0].update &= ~(~prev->
params.active & to_switch);
751 prev->
params.params[1].update &= ~(prev->
params.active & to_switch);
767 preview_config_luma_enhancement,
768 preview_enable_luma_enhancement,
774 preview_enable_invalaw,
788 preview_config_chroma_suppression,
789 preview_enable_chroma_suppression,
794 preview_config_whitebalance,
800 preview_config_blkadj,
806 preview_config_rgb_blending,
818 preview_config_yc_range,
834 preview_enable_drkframe_capture,
837 preview_enable_drkframe,
840 preview_enable_drkframe,
842 preview_config_noisefilter,
843 preview_enable_noisefilter,
848 preview_config_gammacorrn,
849 preview_enable_gammacorrn,
854 preview_config_contrast,
858 preview_config_brightness,
887 preview_params_lock(prev, cfg->
update,
true);
888 active = prev->
params.active;
889 spin_unlock_irqrestore(&prev->
params.lock, flags);
893 for (i = 0; i <
ARRAY_SIZE(update_attrs); i++) {
896 unsigned int bit = 1 <<
i;
901 params = &prev->
params.params[!!(active &
bit)];
903 if (cfg->
flag & bit) {
924 preview_params_unlock(prev, update,
true);
925 preview_params_switch(prev);
926 spin_unlock_irqrestore(&prev->
params.lock, flags);
949 | (prev->
params.params[1].features & ~active);
951 for (i = 0; i <
ARRAY_SIZE(update_attrs); i++) {
954 unsigned int bit = 1 <<
i;
959 params = &prev->
params.params[!(active &
bit)];
963 attr->
config(prev, params);
968 attr->
enable(prev,
false);
1028 const struct v4l2_mbus_framefmt *
format)
1033 switch (format->code) {
1035 prev->
params.cfa_order = 0;
1038 prev->
params.cfa_order = 1;
1041 prev->
params.cfa_order = 2;
1044 prev->
params.cfa_order = 3;
1060 preview_config_cfa(prev, params);
1078 unsigned int sph = prev->
crop.left;
1079 unsigned int eph = prev->
crop.left + prev->
crop.width - 1;
1080 unsigned int slv = prev->
crop.top;
1081 unsigned int elv = prev->
crop.top + prev->
crop.height - 1;
1092 | (prev->
params.params[1].features & ~active);
1151 static void preview_config_outlineoffset(
struct isp_prev_device *prev,
1178 unsigned long l3_ick = pipe->
l3_ick;
1180 unsigned int cycles_per_frame;
1181 unsigned int requests_per_frame;
1182 unsigned int cycles_per_request;
1197 cycles_per_request = div_u64((
u64)l3_ick / 2 * 256 + pipe->
max_rate - 1,
1208 requests_per_frame =
DIV_ROUND_UP(ifmt->width * 2, 256) * ifmt->height;
1209 cycles_per_frame = div_u64((
u64)l3_ick * timeperframe->
numerator,
1211 cycles_per_request = cycles_per_frame / requests_per_frame;
1213 maximum = cycles_per_request / 32;
1215 value =
max(minimum, maximum);
1217 dev_dbg(isp->
dev,
"%s: cycles per request = %u\n", __func__, value);
1245 preview_setup_hw(prev, update, prev->
params.active);
1247 prev->
params.params[0].update = 0;
1248 prev->
params.params[1].update = 0;
1254 #define PREV_PRINT_REGISTER(isp, name)\
1255 dev_dbg(isp->dev, "###PRV " #name "=0x%08x\n", \
1256 isp_reg_readl(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_##name))
1262 dev_dbg(isp->
dev,
"-------------Preview Register dump----------\n");
1301 dev_dbg(isp->
dev,
"--------------------------------------------\n");
1315 prev->
params.active = ~0;
1316 prev->
params.params[0].busy = 0;
1318 prev->
params.params[1].busy = 0;
1319 prev->
params.params[1].update = 0;
1321 params = &prev->
params.params[0];
1327 memcpy(params->
cfa.table, cfa_coef_table,
1328 sizeof(params->
cfa.table));
1333 params->
csup.hypf_en = 0;
1334 memcpy(params->
luma.table, luma_enhance_table,
1335 sizeof(params->
luma.table));
1337 memcpy(params->
nf.table, noise_filter_table,
sizeof(params->
nf.table));
1338 params->
dcor.couplet_mode_en = 1;
1352 params->
rgb2rgb = flr_rgb2rgb;
1353 params->
csc = flr_prev_csc;
1372 static unsigned int preview_max_out_width(
struct isp_prev_device *prev)
1392 struct v4l2_mbus_framefmt *
format;
1393 unsigned long flags;
1399 update = preview_params_lock(prev, 0,
false);
1400 active = prev->
params.active;
1401 spin_unlock_irqrestore(&prev->
params.lock, flags);
1406 preview_adjust_bandwidth(prev);
1408 preview_config_input_format(prev, format);
1409 preview_config_input_size(prev, active);
1412 preview_config_inlineoffset(prev, 0);
1414 preview_config_inlineoffset(prev,
1415 ALIGN(format->width, 0x20) * 2);
1417 preview_setup_hw(prev, update, active);
1437 preview_config_outlineoffset(prev,
1438 ALIGN(format->width, 0x10) * 2);
1440 preview_config_averager(prev, 0);
1441 preview_config_ycpos(prev, format->code);
1444 preview_params_unlock(prev, update,
false);
1445 spin_unlock_irqrestore(&prev->
params.lock, flags);
1478 preview_enable_oneshot(prev);
1479 isp_video_dmaqueue_flags_clr(&prev->
video_out);
1492 preview_set_inaddr(prev, buffer->
isp_addr);
1498 if (buffer !=
NULL) {
1499 preview_set_outaddr(prev, buffer->
isp_addr);
1505 switch (prev->
state) {
1507 if (isp_pipeline_ready(pipe))
1517 preview_enable_oneshot(prev);
1533 unsigned long flags;
1541 preview_params_switch(prev);
1542 update = preview_params_lock(prev, 0,
false);
1543 active = prev->
params.active;
1544 spin_unlock_irqrestore(&prev->
params.lock, flags);
1546 preview_setup_hw(prev, update, active);
1547 preview_config_input_size(prev, active);
1551 preview_isr_buffer(prev);
1553 preview_enable_oneshot(prev);
1556 preview_params_unlock(prev, update,
false);
1557 spin_unlock_irqrestore(&prev->
params.lock, flags);
1564 static int preview_video_queue(
struct isp_video *video,
1570 preview_set_inaddr(prev, buffer->
isp_addr);
1573 preview_set_outaddr(prev, buffer->
isp_addr);
1579 .queue = preview_video_queue,
1597 preview_update_brightness(prev, ctrl->
val);
1600 preview_update_contrast(prev, ctrl->
val);
1608 .s_ctrl = preview_s_ctrl,
1624 return preview_config(prev, arg);
1637 static int preview_set_stream(
struct v4l2_subdev *sd,
int enable)
1649 preview_configure(prev);
1651 preview_print_status(prev);
1661 preview_enable_oneshot(prev);
1663 isp_video_dmaqueue_flags_clr(video_out);
1672 preview_enable_oneshot(prev);
1682 isp_video_dmaqueue_flags_clr(video_out);
1690 static struct v4l2_mbus_framefmt *
1695 return v4l2_subdev_get_try_format(fh, pad);
1711 static const unsigned int preview_input_fmts[] = {
1719 static const unsigned int preview_output_fmts[] = {
1737 struct v4l2_mbus_framefmt *
fmt,
1757 preview_max_out_width(prev));
1765 for (i = 0; i <
ARRAY_SIZE(preview_input_fmts); i++) {
1766 if (fmt->code == preview_input_fmts[i])
1776 pixelcode = fmt->code;
1777 *fmt = *__preview_get_format(prev, fh,
PREV_PAD_SINK, which);
1779 switch (pixelcode) {
1782 fmt->code = pixelcode;
1795 crop = __preview_get_crop(prev, fh, which);
1796 fmt->width = crop->
width;
1797 fmt->height = crop->
height;
1819 const struct v4l2_mbus_framefmt *
sink,
1844 right - crop->
left);
1846 bottom - crop->
top);
1856 static int preview_enum_mbus_code(
struct v4l2_subdev *sd,
1858 struct v4l2_subdev_mbus_code_enum *
code)
1860 switch (code->pad) {
1862 if (code->index >=
ARRAY_SIZE(preview_input_fmts))
1865 code->code = preview_input_fmts[code->index];
1868 if (code->index >=
ARRAY_SIZE(preview_output_fmts))
1871 code->code = preview_output_fmts[code->index];
1880 static int preview_enum_frame_size(
struct v4l2_subdev *sd,
1882 struct v4l2_subdev_frame_size_enum *fse)
1885 struct v4l2_mbus_framefmt format;
1887 if (fse->index != 0)
1890 format.code = fse->code;
1894 fse->min_width = format.width;
1895 fse->min_height = format.height;
1897 if (format.code != fse->code)
1900 format.code = fse->code;
1904 fse->max_width = format.width;
1905 fse->max_height = format.height;
1920 static int preview_get_selection(
struct v4l2_subdev *sd,
1922 struct v4l2_subdev_selection *
sel)
1925 struct v4l2_mbus_framefmt *
format;
1930 switch (sel->target) {
1939 preview_try_crop(prev, format, &sel->r);
1943 sel->r = *__preview_get_crop(prev, fh, sel->which);
1963 static int preview_set_selection(
struct v4l2_subdev *sd,
1965 struct v4l2_subdev_selection *sel)
1968 struct v4l2_mbus_framefmt *
format;
1983 sel->r = *__preview_get_crop(prev, fh, sel->which);
1987 format = __preview_get_format(prev, fh,
PREV_PAD_SINK, sel->which);
1988 preview_try_crop(prev, format, &sel->r);
1989 *__preview_get_crop(prev, fh, sel->which) = sel->r;
2009 struct v4l2_mbus_framefmt *
format;
2011 format = __preview_get_format(prev, fh, fmt->
pad, fmt->
which);
2030 struct v4l2_mbus_framefmt *
format;
2033 format = __preview_get_format(prev, fh, fmt->
pad, fmt->
which);
2037 preview_try_format(prev, fh, fmt->
pad, &fmt->
format, fmt->
which);
2043 crop = __preview_get_crop(prev, fh, fmt->
which);
2049 preview_try_crop(prev, &fmt->
format, crop);
2070 static int preview_init_formats(
struct v4l2_subdev *sd,
2075 memset(&format, 0,
sizeof(format));
2079 format.format.width = 4096;
2080 format.format.height = 4096;
2081 preview_set_format(sd, fh, &format);
2088 .ioctl = preview_ioctl,
2093 .s_stream = preview_set_stream,
2098 .enum_mbus_code = preview_enum_mbus_code,
2099 .enum_frame_size = preview_enum_frame_size,
2100 .get_fmt = preview_get_format,
2101 .set_fmt = preview_set_format,
2102 .get_selection = preview_get_selection,
2103 .set_selection = preview_set_selection,
2108 .core = &preview_v4l2_core_ops,
2109 .video = &preview_v4l2_video_ops,
2110 .pad = &preview_v4l2_pad_ops,
2115 .open = preview_init_formats,
2130 static int preview_link_setup(
struct media_entity *entity,
2137 switch (local->
index | media_entity_type(remote->
entity)) {
2152 if (flags & MEDIA_LNK_FL_ENABLED) {
2169 if (flags & MEDIA_LNK_FL_ENABLED) {
2180 if (flags & MEDIA_LNK_FL_ENABLED) {
2198 .link_setup = preview_link_setup,
2199 .link_validate = v4l2_subdev_link_validate,
2256 v4l2_set_subdevdata(sd, prev);
2272 me->
ops = &preview_media_ops;
2277 preview_init_formats(sd,
NULL);
2284 prev->
video_in.ops = &preview_video_ops;
2289 prev->
video_out.ops = &preview_video_ops;
2296 goto error_video_in;
2300 goto error_video_out;
2335 preview_init_params(prev);
2337 return preview_init_entities(prev);