blob: fbdd5715f8290a707e791caf74f072b4621ad898 [file] [log] [blame]
Laurent Pinchart1c4b5f42018-04-22 17:33:20 -04001// SPDX-License-Identifier: GPL-2.0+
Laurent Pinchart26e0ca22013-06-04 11:22:30 -03002/*
3 * vsp1_lif.c -- R-Car VSP1 LCD Controller Interface
4 *
Laurent Pinchart8a1edc52014-02-06 14:42:31 -03005 * Copyright (C) 2013-2014 Renesas Electronics Corporation
Laurent Pinchart26e0ca22013-06-04 11:22:30 -03006 *
7 * Contact: Laurent Pinchart (laurent.pinchart@ideasonboard.com)
Laurent Pinchart26e0ca22013-06-04 11:22:30 -03008 */
9
10#include <linux/device.h>
11#include <linux/gfp.h>
12
13#include <media/v4l2-subdev.h>
14
15#include "vsp1.h"
Laurent Pinchart5e8dbbf2015-11-22 20:29:25 -020016#include "vsp1_dl.h"
Laurent Pinchart26e0ca22013-06-04 11:22:30 -030017#include "vsp1_lif.h"
18
19#define LIF_MIN_SIZE 2U
Laurent Pinchart0d268dc2016-03-25 06:51:06 -030020#define LIF_MAX_SIZE 8190U
Laurent Pinchart26e0ca22013-06-04 11:22:30 -030021
22/* -----------------------------------------------------------------------------
23 * Device Access
24 */
25
Laurent Pinchart5e8dbbf2015-11-22 20:29:25 -020026static inline void vsp1_lif_write(struct vsp1_lif *lif, struct vsp1_dl_list *dl,
27 u32 reg, u32 data)
Laurent Pinchart26e0ca22013-06-04 11:22:30 -030028{
Laurent Pinchart3be0bf92017-06-21 16:10:18 +030029 vsp1_dl_list_write(dl, reg + lif->entity.index * VI6_LIF_OFFSET, data);
Laurent Pinchart26e0ca22013-06-04 11:22:30 -030030}
31
32/* -----------------------------------------------------------------------------
Laurent Pinchart7b905f02015-11-17 13:10:26 -020033 * V4L2 Subdevice Operations
Laurent Pinchart26e0ca22013-06-04 11:22:30 -030034 */
35
Laurent Pinchartb4ccae12017-11-27 14:59:45 -050036static const unsigned int lif_codes[] = {
37 MEDIA_BUS_FMT_ARGB8888_1X32,
38 MEDIA_BUS_FMT_AYUV8_1X32,
39};
40
Laurent Pinchart26e0ca22013-06-04 11:22:30 -030041static int lif_enum_mbus_code(struct v4l2_subdev *subdev,
Hans Verkuilf7234132015-03-04 01:47:54 -080042 struct v4l2_subdev_pad_config *cfg,
Laurent Pinchart26e0ca22013-06-04 11:22:30 -030043 struct v4l2_subdev_mbus_code_enum *code)
44{
Laurent Pinchartb4ccae12017-11-27 14:59:45 -050045 return vsp1_subdev_enum_mbus_code(subdev, cfg, code, lif_codes,
46 ARRAY_SIZE(lif_codes));
Laurent Pinchart26e0ca22013-06-04 11:22:30 -030047}
48
49static int lif_enum_frame_size(struct v4l2_subdev *subdev,
Hans Verkuilf7234132015-03-04 01:47:54 -080050 struct v4l2_subdev_pad_config *cfg,
Laurent Pinchart26e0ca22013-06-04 11:22:30 -030051 struct v4l2_subdev_frame_size_enum *fse)
52{
Laurent Pinchart076e8342016-02-24 20:25:42 -030053 return vsp1_subdev_enum_frame_size(subdev, cfg, fse, LIF_MIN_SIZE,
54 LIF_MIN_SIZE, LIF_MAX_SIZE,
55 LIF_MAX_SIZE);
Laurent Pinchart26e0ca22013-06-04 11:22:30 -030056}
57
Laurent Pinchart1bd0a1b2015-11-01 15:18:32 -020058static int lif_set_format(struct v4l2_subdev *subdev,
59 struct v4l2_subdev_pad_config *cfg,
Laurent Pinchart26e0ca22013-06-04 11:22:30 -030060 struct v4l2_subdev_format *fmt)
61{
Laurent Pinchartb4ccae12017-11-27 14:59:45 -050062 return vsp1_subdev_set_pad_format(subdev, cfg, fmt, lif_codes,
63 ARRAY_SIZE(lif_codes),
64 LIF_MIN_SIZE, LIF_MIN_SIZE,
65 LIF_MAX_SIZE, LIF_MAX_SIZE);
Laurent Pinchart26e0ca22013-06-04 11:22:30 -030066}
67
Laurent Pincharteb9163d2016-06-17 21:11:26 -030068static const struct v4l2_subdev_pad_ops lif_pad_ops = {
Laurent Pinchart0efdf0f2015-11-15 20:09:08 -020069 .init_cfg = vsp1_entity_init_cfg,
Laurent Pinchart26e0ca22013-06-04 11:22:30 -030070 .enum_mbus_code = lif_enum_mbus_code,
71 .enum_frame_size = lif_enum_frame_size,
Laurent Pinchart3f557222016-02-24 21:10:13 -030072 .get_fmt = vsp1_subdev_get_pad_format,
Laurent Pinchart26e0ca22013-06-04 11:22:30 -030073 .set_fmt = lif_set_format,
74};
75
Laurent Pincharteb9163d2016-06-17 21:11:26 -030076static const struct v4l2_subdev_ops lif_ops = {
Laurent Pinchart26e0ca22013-06-04 11:22:30 -030077 .pad = &lif_pad_ops,
78};
79
80/* -----------------------------------------------------------------------------
Laurent Pinchart7b905f02015-11-17 13:10:26 -020081 * VSP1 Entity Operations
82 */
83
Laurent Pinchart83dd0192016-01-14 14:17:32 -020084static void lif_configure(struct vsp1_entity *entity,
85 struct vsp1_pipeline *pipe,
Laurent Pinchartd21fbbb2016-09-11 19:39:30 -030086 struct vsp1_dl_list *dl,
87 enum vsp1_entity_params params)
Laurent Pinchart7b905f02015-11-17 13:10:26 -020088{
89 const struct v4l2_mbus_framefmt *format;
90 struct vsp1_lif *lif = to_lif(&entity->subdev);
91 unsigned int hbth = 1300;
92 unsigned int obth = 400;
93 unsigned int lbth = 200;
94
Laurent Pinchartd21fbbb2016-09-11 19:39:30 -030095 if (params != VSP1_ENTITY_PARAMS_INIT)
Laurent Pinchartfc845e52016-06-11 04:07:56 -030096 return;
97
Laurent Pinchart7b905f02015-11-17 13:10:26 -020098 format = vsp1_entity_get_pad_format(&lif->entity, lif->entity.config,
99 LIF_PAD_SOURCE);
100
101 obth = min(obth, (format->width + 1) / 2 * format->height - 4);
102
Laurent Pinchart5e8dbbf2015-11-22 20:29:25 -0200103 vsp1_lif_write(lif, dl, VI6_LIF_CSBTH,
Laurent Pinchart7b905f02015-11-17 13:10:26 -0200104 (hbth << VI6_LIF_CSBTH_HBTH_SHIFT) |
105 (lbth << VI6_LIF_CSBTH_LBTH_SHIFT));
106
Laurent Pinchart5e8dbbf2015-11-22 20:29:25 -0200107 vsp1_lif_write(lif, dl, VI6_LIF_CTRL,
Laurent Pinchart7b905f02015-11-17 13:10:26 -0200108 (obth << VI6_LIF_CTRL_OBTH_SHIFT) |
109 (format->code == 0 ? VI6_LIF_CTRL_CFMT : 0) |
110 VI6_LIF_CTRL_REQSEL | VI6_LIF_CTRL_LIF_EN);
Sergei Shtylyov7f43ff92018-01-18 09:05:51 -0500111
112 /*
113 * On R-Car V3M the LIF0 buffer attribute register has to be set to a
114 * non-default value to guarantee proper operation (otherwise artifacts
115 * may appear on the output). The value required by the manual is not
116 * explained but is likely a buffer size or threshold.
117 */
118 if ((entity->vsp1->version & VI6_IP_VERSION_MASK) ==
119 (VI6_IP_VERSION_MODEL_VSPD_V3 | VI6_IP_VERSION_SOC_V3M))
120 vsp1_lif_write(lif, dl, VI6_LIF_LBA,
121 VI6_LIF_LBA_LBA0 |
122 (1536 << VI6_LIF_LBA_LBA1_SHIFT));
Laurent Pinchart7b905f02015-11-17 13:10:26 -0200123}
124
125static const struct vsp1_entity_operations lif_entity_ops = {
126 .configure = lif_configure,
127};
128
129/* -----------------------------------------------------------------------------
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300130 * Initialization and Cleanup
131 */
132
Laurent Pinchart3be0bf92017-06-21 16:10:18 +0300133struct vsp1_lif *vsp1_lif_create(struct vsp1_device *vsp1, unsigned int index)
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300134{
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300135 struct vsp1_lif *lif;
136 int ret;
137
138 lif = devm_kzalloc(vsp1->dev, sizeof(*lif), GFP_KERNEL);
139 if (lif == NULL)
140 return ERR_PTR(-ENOMEM);
141
Laurent Pinchart7b905f02015-11-17 13:10:26 -0200142 lif->entity.ops = &lif_entity_ops;
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300143 lif->entity.type = VSP1_ENTITY_LIF;
Laurent Pinchart3be0bf92017-06-21 16:10:18 +0300144 lif->entity.index = index;
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300145
Laurent Pinchart9dbed952017-02-26 10:29:50 -0300146 /*
147 * The LIF is never exposed to userspace, but media entity registration
Laurent Pinchart6a8e07b2016-02-15 22:10:26 -0200148 * requires a function to be set. Use PROC_VIDEO_PIXEL_FORMATTER just to
149 * avoid triggering a WARN_ON(), the value won't be seen anywhere.
150 */
151 ret = vsp1_entity_init(vsp1, &lif->entity, "lif", 2, &lif_ops,
152 MEDIA_ENT_F_PROC_VIDEO_PIXEL_FORMATTER);
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300153 if (ret < 0)
154 return ERR_PTR(ret);
155
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300156 return lif;
157}