2 * vsp1_lif.c -- R-Car VSP1 LCD Controller Interface
4 * Copyright (C) 2013-2014 Renesas Electronics Corporation
6 * Contact: Laurent Pinchart (laurent.pinchart@ideasonboard.com)
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
14 #include <linux/device.h>
15 #include <linux/gfp.h>
17 #include <media/v4l2-subdev.h>
23 #define LIF_MIN_SIZE 2U
24 #define LIF_MAX_SIZE 8190U
26 /* -----------------------------------------------------------------------------
30 static inline void vsp1_lif_write(struct vsp1_lif
*lif
, struct vsp1_dl_list
*dl
,
33 vsp1_dl_list_write(dl
, reg
, data
);
36 /* -----------------------------------------------------------------------------
37 * V4L2 Subdevice Operations
40 static int lif_enum_mbus_code(struct v4l2_subdev
*subdev
,
41 struct v4l2_subdev_pad_config
*cfg
,
42 struct v4l2_subdev_mbus_code_enum
*code
)
44 static const unsigned int codes
[] = {
45 MEDIA_BUS_FMT_ARGB8888_1X32
,
46 MEDIA_BUS_FMT_AYUV8_1X32
,
49 return vsp1_subdev_enum_mbus_code(subdev
, cfg
, code
, codes
,
53 static int lif_enum_frame_size(struct v4l2_subdev
*subdev
,
54 struct v4l2_subdev_pad_config
*cfg
,
55 struct v4l2_subdev_frame_size_enum
*fse
)
57 return vsp1_subdev_enum_frame_size(subdev
, cfg
, fse
, LIF_MIN_SIZE
,
58 LIF_MIN_SIZE
, LIF_MAX_SIZE
,
62 static int lif_set_format(struct v4l2_subdev
*subdev
,
63 struct v4l2_subdev_pad_config
*cfg
,
64 struct v4l2_subdev_format
*fmt
)
66 struct vsp1_lif
*lif
= to_lif(subdev
);
67 struct v4l2_subdev_pad_config
*config
;
68 struct v4l2_mbus_framefmt
*format
;
70 config
= vsp1_entity_get_pad_config(&lif
->entity
, cfg
, fmt
->which
);
74 /* Default to YUV if the requested format is not supported. */
75 if (fmt
->format
.code
!= MEDIA_BUS_FMT_ARGB8888_1X32
&&
76 fmt
->format
.code
!= MEDIA_BUS_FMT_AYUV8_1X32
)
77 fmt
->format
.code
= MEDIA_BUS_FMT_AYUV8_1X32
;
79 format
= vsp1_entity_get_pad_format(&lif
->entity
, config
, fmt
->pad
);
81 if (fmt
->pad
== LIF_PAD_SOURCE
) {
82 /* The LIF source format is always identical to its sink
85 fmt
->format
= *format
;
89 format
->code
= fmt
->format
.code
;
90 format
->width
= clamp_t(unsigned int, fmt
->format
.width
,
91 LIF_MIN_SIZE
, LIF_MAX_SIZE
);
92 format
->height
= clamp_t(unsigned int, fmt
->format
.height
,
93 LIF_MIN_SIZE
, LIF_MAX_SIZE
);
94 format
->field
= V4L2_FIELD_NONE
;
95 format
->colorspace
= V4L2_COLORSPACE_SRGB
;
97 fmt
->format
= *format
;
99 /* Propagate the format to the source pad. */
100 format
= vsp1_entity_get_pad_format(&lif
->entity
, config
,
102 *format
= fmt
->format
;
107 static const struct v4l2_subdev_pad_ops lif_pad_ops
= {
108 .init_cfg
= vsp1_entity_init_cfg
,
109 .enum_mbus_code
= lif_enum_mbus_code
,
110 .enum_frame_size
= lif_enum_frame_size
,
111 .get_fmt
= vsp1_subdev_get_pad_format
,
112 .set_fmt
= lif_set_format
,
115 static const struct v4l2_subdev_ops lif_ops
= {
119 /* -----------------------------------------------------------------------------
120 * VSP1 Entity Operations
123 static void lif_configure(struct vsp1_entity
*entity
,
124 struct vsp1_pipeline
*pipe
,
125 struct vsp1_dl_list
*dl
, bool full
)
127 const struct v4l2_mbus_framefmt
*format
;
128 struct vsp1_lif
*lif
= to_lif(&entity
->subdev
);
129 unsigned int hbth
= 1300;
130 unsigned int obth
= 400;
131 unsigned int lbth
= 200;
136 format
= vsp1_entity_get_pad_format(&lif
->entity
, lif
->entity
.config
,
139 obth
= min(obth
, (format
->width
+ 1) / 2 * format
->height
- 4);
141 vsp1_lif_write(lif
, dl
, VI6_LIF_CSBTH
,
142 (hbth
<< VI6_LIF_CSBTH_HBTH_SHIFT
) |
143 (lbth
<< VI6_LIF_CSBTH_LBTH_SHIFT
));
145 vsp1_lif_write(lif
, dl
, VI6_LIF_CTRL
,
146 (obth
<< VI6_LIF_CTRL_OBTH_SHIFT
) |
147 (format
->code
== 0 ? VI6_LIF_CTRL_CFMT
: 0) |
148 VI6_LIF_CTRL_REQSEL
| VI6_LIF_CTRL_LIF_EN
);
151 static const struct vsp1_entity_operations lif_entity_ops
= {
152 .configure
= lif_configure
,
155 /* -----------------------------------------------------------------------------
156 * Initialization and Cleanup
159 struct vsp1_lif
*vsp1_lif_create(struct vsp1_device
*vsp1
)
161 struct vsp1_lif
*lif
;
164 lif
= devm_kzalloc(vsp1
->dev
, sizeof(*lif
), GFP_KERNEL
);
166 return ERR_PTR(-ENOMEM
);
168 lif
->entity
.ops
= &lif_entity_ops
;
169 lif
->entity
.type
= VSP1_ENTITY_LIF
;
171 /* The LIF is never exposed to userspace, but media entity registration
172 * requires a function to be set. Use PROC_VIDEO_PIXEL_FORMATTER just to
173 * avoid triggering a WARN_ON(), the value won't be seen anywhere.
175 ret
= vsp1_entity_init(vsp1
, &lif
->entity
, "lif", 2, &lif_ops
,
176 MEDIA_ENT_F_PROC_VIDEO_PIXEL_FORMATTER
);