blob: 8b0a26335d70a287d6a31fb262d45c45e9ad8bc8 [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
Kieran Bingham12832dd2018-05-18 16:42:02 -040026static inline void vsp1_lif_write(struct vsp1_lif *lif,
27 struct vsp1_dl_body *dlb, u32 reg, u32 data)
Laurent Pinchart26e0ca22013-06-04 11:22:30 -030028{
Kieran Bingham12832dd2018-05-18 16:42:02 -040029 vsp1_dl_body_write(dlb, reg + lif->entity.index * VI6_LIF_OFFSET,
30 data);
Laurent Pinchart26e0ca22013-06-04 11:22:30 -030031}
32
33/* -----------------------------------------------------------------------------
Laurent Pinchart7b905f02015-11-17 13:10:26 -020034 * V4L2 Subdevice Operations
Laurent Pinchart26e0ca22013-06-04 11:22:30 -030035 */
36
Laurent Pinchartb4ccae12017-11-27 14:59:45 -050037static const unsigned int lif_codes[] = {
38 MEDIA_BUS_FMT_ARGB8888_1X32,
39 MEDIA_BUS_FMT_AYUV8_1X32,
40};
41
Laurent Pinchart26e0ca22013-06-04 11:22:30 -030042static int lif_enum_mbus_code(struct v4l2_subdev *subdev,
Hans Verkuilf7234132015-03-04 01:47:54 -080043 struct v4l2_subdev_pad_config *cfg,
Laurent Pinchart26e0ca22013-06-04 11:22:30 -030044 struct v4l2_subdev_mbus_code_enum *code)
45{
Laurent Pinchartb4ccae12017-11-27 14:59:45 -050046 return vsp1_subdev_enum_mbus_code(subdev, cfg, code, lif_codes,
47 ARRAY_SIZE(lif_codes));
Laurent Pinchart26e0ca22013-06-04 11:22:30 -030048}
49
50static int lif_enum_frame_size(struct v4l2_subdev *subdev,
Hans Verkuilf7234132015-03-04 01:47:54 -080051 struct v4l2_subdev_pad_config *cfg,
Laurent Pinchart26e0ca22013-06-04 11:22:30 -030052 struct v4l2_subdev_frame_size_enum *fse)
53{
Laurent Pinchart076e8342016-02-24 20:25:42 -030054 return vsp1_subdev_enum_frame_size(subdev, cfg, fse, LIF_MIN_SIZE,
55 LIF_MIN_SIZE, LIF_MAX_SIZE,
56 LIF_MAX_SIZE);
Laurent Pinchart26e0ca22013-06-04 11:22:30 -030057}
58
Laurent Pinchart1bd0a1b2015-11-01 15:18:32 -020059static int lif_set_format(struct v4l2_subdev *subdev,
60 struct v4l2_subdev_pad_config *cfg,
Laurent Pinchart26e0ca22013-06-04 11:22:30 -030061 struct v4l2_subdev_format *fmt)
62{
Laurent Pinchartb4ccae12017-11-27 14:59:45 -050063 return vsp1_subdev_set_pad_format(subdev, cfg, fmt, lif_codes,
64 ARRAY_SIZE(lif_codes),
65 LIF_MIN_SIZE, LIF_MIN_SIZE,
66 LIF_MAX_SIZE, LIF_MAX_SIZE);
Laurent Pinchart26e0ca22013-06-04 11:22:30 -030067}
68
Laurent Pincharteb9163d2016-06-17 21:11:26 -030069static const struct v4l2_subdev_pad_ops lif_pad_ops = {
Laurent Pinchart0efdf0f2015-11-15 20:09:08 -020070 .init_cfg = vsp1_entity_init_cfg,
Laurent Pinchart26e0ca22013-06-04 11:22:30 -030071 .enum_mbus_code = lif_enum_mbus_code,
72 .enum_frame_size = lif_enum_frame_size,
Laurent Pinchart3f557222016-02-24 21:10:13 -030073 .get_fmt = vsp1_subdev_get_pad_format,
Laurent Pinchart26e0ca22013-06-04 11:22:30 -030074 .set_fmt = lif_set_format,
75};
76
Laurent Pincharteb9163d2016-06-17 21:11:26 -030077static const struct v4l2_subdev_ops lif_ops = {
Laurent Pinchart26e0ca22013-06-04 11:22:30 -030078 .pad = &lif_pad_ops,
79};
80
81/* -----------------------------------------------------------------------------
Laurent Pinchart7b905f02015-11-17 13:10:26 -020082 * VSP1 Entity Operations
83 */
84
Kieran Bingham46ce3632018-05-18 16:42:01 -040085static void lif_configure_stream(struct vsp1_entity *entity,
86 struct vsp1_pipeline *pipe,
Kieran Bingham12832dd2018-05-18 16:42:02 -040087 struct vsp1_dl_body *dlb)
Laurent Pinchart7b905f02015-11-17 13:10:26 -020088{
89 const struct v4l2_mbus_framefmt *format;
90 struct vsp1_lif *lif = to_lif(&entity->subdev);
Laurent Pinchartde2bc452017-10-26 02:27:51 -040091 unsigned int hbth;
92 unsigned int obth;
93 unsigned int lbth;
Laurent Pinchart7b905f02015-11-17 13:10:26 -020094
95 format = vsp1_entity_get_pad_format(&lif->entity, lif->entity.config,
96 LIF_PAD_SOURCE);
97
Laurent Pinchart230bce52018-11-21 22:38:07 -050098 switch (entity->vsp1->version & VI6_IP_VERSION_MODEL_MASK) {
Laurent Pinchartde2bc452017-10-26 02:27:51 -040099 case VI6_IP_VERSION_MODEL_VSPD_GEN2:
100 case VI6_IP_VERSION_MODEL_VSPD_V2H:
101 hbth = 1536;
102 obth = min(128U, (format->width + 1) / 2 * format->height - 4);
103 lbth = 1520;
104 break;
105
106 case VI6_IP_VERSION_MODEL_VSPDL_GEN3:
107 case VI6_IP_VERSION_MODEL_VSPD_V3:
108 hbth = 0;
109 obth = 1500;
110 lbth = 0;
111 break;
112
113 case VI6_IP_VERSION_MODEL_VSPD_GEN3:
114 default:
115 hbth = 0;
116 obth = 3000;
117 lbth = 0;
118 break;
119 }
Laurent Pinchart7b905f02015-11-17 13:10:26 -0200120
Kieran Bingham12832dd2018-05-18 16:42:02 -0400121 vsp1_lif_write(lif, dlb, VI6_LIF_CSBTH,
Laurent Pinchart7b905f02015-11-17 13:10:26 -0200122 (hbth << VI6_LIF_CSBTH_HBTH_SHIFT) |
123 (lbth << VI6_LIF_CSBTH_LBTH_SHIFT));
124
Kieran Bingham12832dd2018-05-18 16:42:02 -0400125 vsp1_lif_write(lif, dlb, VI6_LIF_CTRL,
Laurent Pinchart7b905f02015-11-17 13:10:26 -0200126 (obth << VI6_LIF_CTRL_OBTH_SHIFT) |
127 (format->code == 0 ? VI6_LIF_CTRL_CFMT : 0) |
128 VI6_LIF_CTRL_REQSEL | VI6_LIF_CTRL_LIF_EN);
Sergei Shtylyov7f43ff92018-01-18 09:05:51 -0500129
130 /*
131 * On R-Car V3M the LIF0 buffer attribute register has to be set to a
132 * non-default value to guarantee proper operation (otherwise artifacts
133 * may appear on the output). The value required by the manual is not
134 * explained but is likely a buffer size or threshold.
135 */
136 if ((entity->vsp1->version & VI6_IP_VERSION_MASK) ==
137 (VI6_IP_VERSION_MODEL_VSPD_V3 | VI6_IP_VERSION_SOC_V3M))
Kieran Bingham12832dd2018-05-18 16:42:02 -0400138 vsp1_lif_write(lif, dlb, VI6_LIF_LBA,
Sergei Shtylyov7f43ff92018-01-18 09:05:51 -0500139 VI6_LIF_LBA_LBA0 |
140 (1536 << VI6_LIF_LBA_LBA1_SHIFT));
Laurent Pinchart7b905f02015-11-17 13:10:26 -0200141}
142
143static const struct vsp1_entity_operations lif_entity_ops = {
Kieran Bingham46ce3632018-05-18 16:42:01 -0400144 .configure_stream = lif_configure_stream,
Laurent Pinchart7b905f02015-11-17 13:10:26 -0200145};
146
147/* -----------------------------------------------------------------------------
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300148 * Initialization and Cleanup
149 */
150
Laurent Pinchart3be0bf92017-06-21 16:10:18 +0300151struct vsp1_lif *vsp1_lif_create(struct vsp1_device *vsp1, unsigned int index)
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300152{
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300153 struct vsp1_lif *lif;
154 int ret;
155
156 lif = devm_kzalloc(vsp1->dev, sizeof(*lif), GFP_KERNEL);
157 if (lif == NULL)
158 return ERR_PTR(-ENOMEM);
159
Laurent Pinchart7b905f02015-11-17 13:10:26 -0200160 lif->entity.ops = &lif_entity_ops;
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300161 lif->entity.type = VSP1_ENTITY_LIF;
Laurent Pinchart3be0bf92017-06-21 16:10:18 +0300162 lif->entity.index = index;
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300163
Laurent Pinchart9dbed952017-02-26 10:29:50 -0300164 /*
165 * The LIF is never exposed to userspace, but media entity registration
Laurent Pinchart6a8e07b2016-02-15 22:10:26 -0200166 * requires a function to be set. Use PROC_VIDEO_PIXEL_FORMATTER just to
167 * avoid triggering a WARN_ON(), the value won't be seen anywhere.
168 */
169 ret = vsp1_entity_init(vsp1, &lif->entity, "lif", 2, &lif_ops,
170 MEDIA_ENT_F_PROC_VIDEO_PIXEL_FORMATTER);
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300171 if (ret < 0)
172 return ERR_PTR(ret);
173
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300174 return lif;
175}