blob: 5a3f3e7b9bd3c15d64f8e37502d529815eacf224 [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
Kieran Bingham46ce3632018-05-18 16:42:01 -040084static void lif_configure_stream(struct vsp1_entity *entity,
85 struct vsp1_pipeline *pipe,
86 struct vsp1_dl_list *dl)
Laurent Pinchart7b905f02015-11-17 13:10:26 -020087{
88 const struct v4l2_mbus_framefmt *format;
89 struct vsp1_lif *lif = to_lif(&entity->subdev);
90 unsigned int hbth = 1300;
91 unsigned int obth = 400;
92 unsigned int lbth = 200;
93
94 format = vsp1_entity_get_pad_format(&lif->entity, lif->entity.config,
95 LIF_PAD_SOURCE);
96
97 obth = min(obth, (format->width + 1) / 2 * format->height - 4);
98
Laurent Pinchart5e8dbbf2015-11-22 20:29:25 -020099 vsp1_lif_write(lif, dl, VI6_LIF_CSBTH,
Laurent Pinchart7b905f02015-11-17 13:10:26 -0200100 (hbth << VI6_LIF_CSBTH_HBTH_SHIFT) |
101 (lbth << VI6_LIF_CSBTH_LBTH_SHIFT));
102
Laurent Pinchart5e8dbbf2015-11-22 20:29:25 -0200103 vsp1_lif_write(lif, dl, VI6_LIF_CTRL,
Laurent Pinchart7b905f02015-11-17 13:10:26 -0200104 (obth << VI6_LIF_CTRL_OBTH_SHIFT) |
105 (format->code == 0 ? VI6_LIF_CTRL_CFMT : 0) |
106 VI6_LIF_CTRL_REQSEL | VI6_LIF_CTRL_LIF_EN);
Sergei Shtylyov7f43ff92018-01-18 09:05:51 -0500107
108 /*
109 * On R-Car V3M the LIF0 buffer attribute register has to be set to a
110 * non-default value to guarantee proper operation (otherwise artifacts
111 * may appear on the output). The value required by the manual is not
112 * explained but is likely a buffer size or threshold.
113 */
114 if ((entity->vsp1->version & VI6_IP_VERSION_MASK) ==
115 (VI6_IP_VERSION_MODEL_VSPD_V3 | VI6_IP_VERSION_SOC_V3M))
116 vsp1_lif_write(lif, dl, VI6_LIF_LBA,
117 VI6_LIF_LBA_LBA0 |
118 (1536 << VI6_LIF_LBA_LBA1_SHIFT));
Laurent Pinchart7b905f02015-11-17 13:10:26 -0200119}
120
121static const struct vsp1_entity_operations lif_entity_ops = {
Kieran Bingham46ce3632018-05-18 16:42:01 -0400122 .configure_stream = lif_configure_stream,
Laurent Pinchart7b905f02015-11-17 13:10:26 -0200123};
124
125/* -----------------------------------------------------------------------------
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300126 * Initialization and Cleanup
127 */
128
Laurent Pinchart3be0bf92017-06-21 16:10:18 +0300129struct vsp1_lif *vsp1_lif_create(struct vsp1_device *vsp1, unsigned int index)
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300130{
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300131 struct vsp1_lif *lif;
132 int ret;
133
134 lif = devm_kzalloc(vsp1->dev, sizeof(*lif), GFP_KERNEL);
135 if (lif == NULL)
136 return ERR_PTR(-ENOMEM);
137
Laurent Pinchart7b905f02015-11-17 13:10:26 -0200138 lif->entity.ops = &lif_entity_ops;
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300139 lif->entity.type = VSP1_ENTITY_LIF;
Laurent Pinchart3be0bf92017-06-21 16:10:18 +0300140 lif->entity.index = index;
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300141
Laurent Pinchart9dbed952017-02-26 10:29:50 -0300142 /*
143 * The LIF is never exposed to userspace, but media entity registration
Laurent Pinchart6a8e07b2016-02-15 22:10:26 -0200144 * requires a function to be set. Use PROC_VIDEO_PIXEL_FORMATTER just to
145 * avoid triggering a WARN_ON(), the value won't be seen anywhere.
146 */
147 ret = vsp1_entity_init(vsp1, &lif->entity, "lif", 2, &lif_ops,
148 MEDIA_ENT_F_PROC_VIDEO_PIXEL_FORMATTER);
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300149 if (ret < 0)
150 return ERR_PTR(ret);
151
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300152 return lif;
153}