Commit | Line | Data |
---|---|---|
26e0ca22 LP |
1 | /* |
2 | * vsp1_lif.c -- R-Car VSP1 LCD Controller Interface | |
3 | * | |
8a1edc55 | 4 | * Copyright (C) 2013-2014 Renesas Electronics Corporation |
26e0ca22 LP |
5 | * |
6 | * Contact: Laurent Pinchart (laurent.pinchart@ideasonboard.com) | |
7 | * | |
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. | |
12 | */ | |
13 | ||
14 | #include <linux/device.h> | |
15 | #include <linux/gfp.h> | |
16 | ||
17 | #include <media/v4l2-subdev.h> | |
18 | ||
19 | #include "vsp1.h" | |
5e8dbbf3 | 20 | #include "vsp1_dl.h" |
26e0ca22 LP |
21 | #include "vsp1_lif.h" |
22 | ||
23 | #define LIF_MIN_SIZE 2U | |
0d268dcc | 24 | #define LIF_MAX_SIZE 8190U |
26e0ca22 LP |
25 | |
26 | /* ----------------------------------------------------------------------------- | |
27 | * Device Access | |
28 | */ | |
29 | ||
5e8dbbf3 LP |
30 | static inline void vsp1_lif_write(struct vsp1_lif *lif, struct vsp1_dl_list *dl, |
31 | u32 reg, u32 data) | |
26e0ca22 | 32 | { |
5e8dbbf3 | 33 | vsp1_dl_list_write(dl, reg, data); |
26e0ca22 LP |
34 | } |
35 | ||
36 | /* ----------------------------------------------------------------------------- | |
7b905f05 | 37 | * V4L2 Subdevice Operations |
26e0ca22 LP |
38 | */ |
39 | ||
40 | static int lif_enum_mbus_code(struct v4l2_subdev *subdev, | |
f7234138 | 41 | struct v4l2_subdev_pad_config *cfg, |
26e0ca22 LP |
42 | struct v4l2_subdev_mbus_code_enum *code) |
43 | { | |
44 | static const unsigned int codes[] = { | |
27ffaeb0 BB |
45 | MEDIA_BUS_FMT_ARGB8888_1X32, |
46 | MEDIA_BUS_FMT_AYUV8_1X32, | |
26e0ca22 | 47 | }; |
26e0ca22 | 48 | |
6ad9ba9c LP |
49 | return vsp1_subdev_enum_mbus_code(subdev, cfg, code, codes, |
50 | ARRAY_SIZE(codes)); | |
26e0ca22 LP |
51 | } |
52 | ||
53 | static int lif_enum_frame_size(struct v4l2_subdev *subdev, | |
f7234138 | 54 | struct v4l2_subdev_pad_config *cfg, |
26e0ca22 LP |
55 | struct v4l2_subdev_frame_size_enum *fse) |
56 | { | |
076e834f LP |
57 | return vsp1_subdev_enum_frame_size(subdev, cfg, fse, LIF_MIN_SIZE, |
58 | LIF_MIN_SIZE, LIF_MAX_SIZE, | |
59 | LIF_MAX_SIZE); | |
26e0ca22 LP |
60 | } |
61 | ||
1bd0a1bd LP |
62 | static int lif_set_format(struct v4l2_subdev *subdev, |
63 | struct v4l2_subdev_pad_config *cfg, | |
26e0ca22 LP |
64 | struct v4l2_subdev_format *fmt) |
65 | { | |
66 | struct vsp1_lif *lif = to_lif(subdev); | |
e790c3cb | 67 | struct v4l2_subdev_pad_config *config; |
26e0ca22 LP |
68 | struct v4l2_mbus_framefmt *format; |
69 | ||
e790c3cb LP |
70 | config = vsp1_entity_get_pad_config(&lif->entity, cfg, fmt->which); |
71 | if (!config) | |
72 | return -EINVAL; | |
73 | ||
26e0ca22 | 74 | /* Default to YUV if the requested format is not supported. */ |
27ffaeb0 BB |
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; | |
26e0ca22 | 78 | |
e790c3cb | 79 | format = vsp1_entity_get_pad_format(&lif->entity, config, fmt->pad); |
26e0ca22 LP |
80 | |
81 | if (fmt->pad == LIF_PAD_SOURCE) { | |
82 | /* The LIF source format is always identical to its sink | |
83 | * format. | |
84 | */ | |
85 | fmt->format = *format; | |
86 | return 0; | |
87 | } | |
88 | ||
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; | |
96 | ||
97 | fmt->format = *format; | |
98 | ||
99 | /* Propagate the format to the source pad. */ | |
e790c3cb LP |
100 | format = vsp1_entity_get_pad_format(&lif->entity, config, |
101 | LIF_PAD_SOURCE); | |
26e0ca22 LP |
102 | *format = fmt->format; |
103 | ||
104 | return 0; | |
105 | } | |
106 | ||
eb9163d3 | 107 | static const struct v4l2_subdev_pad_ops lif_pad_ops = { |
0efdf0f5 | 108 | .init_cfg = vsp1_entity_init_cfg, |
26e0ca22 LP |
109 | .enum_mbus_code = lif_enum_mbus_code, |
110 | .enum_frame_size = lif_enum_frame_size, | |
3f557220 | 111 | .get_fmt = vsp1_subdev_get_pad_format, |
26e0ca22 LP |
112 | .set_fmt = lif_set_format, |
113 | }; | |
114 | ||
eb9163d3 | 115 | static const struct v4l2_subdev_ops lif_ops = { |
26e0ca22 LP |
116 | .pad = &lif_pad_ops, |
117 | }; | |
118 | ||
7b905f05 LP |
119 | /* ----------------------------------------------------------------------------- |
120 | * VSP1 Entity Operations | |
121 | */ | |
122 | ||
83dd019d LP |
123 | static void lif_configure(struct vsp1_entity *entity, |
124 | struct vsp1_pipeline *pipe, | |
fc845e52 | 125 | struct vsp1_dl_list *dl, bool full) |
7b905f05 LP |
126 | { |
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; | |
132 | ||
fc845e52 LP |
133 | if (!full) |
134 | return; | |
135 | ||
7b905f05 LP |
136 | format = vsp1_entity_get_pad_format(&lif->entity, lif->entity.config, |
137 | LIF_PAD_SOURCE); | |
138 | ||
139 | obth = min(obth, (format->width + 1) / 2 * format->height - 4); | |
140 | ||
5e8dbbf3 | 141 | vsp1_lif_write(lif, dl, VI6_LIF_CSBTH, |
7b905f05 LP |
142 | (hbth << VI6_LIF_CSBTH_HBTH_SHIFT) | |
143 | (lbth << VI6_LIF_CSBTH_LBTH_SHIFT)); | |
144 | ||
5e8dbbf3 | 145 | vsp1_lif_write(lif, dl, VI6_LIF_CTRL, |
7b905f05 LP |
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); | |
149 | } | |
150 | ||
151 | static const struct vsp1_entity_operations lif_entity_ops = { | |
152 | .configure = lif_configure, | |
153 | }; | |
154 | ||
26e0ca22 LP |
155 | /* ----------------------------------------------------------------------------- |
156 | * Initialization and Cleanup | |
157 | */ | |
158 | ||
159 | struct vsp1_lif *vsp1_lif_create(struct vsp1_device *vsp1) | |
160 | { | |
26e0ca22 LP |
161 | struct vsp1_lif *lif; |
162 | int ret; | |
163 | ||
164 | lif = devm_kzalloc(vsp1->dev, sizeof(*lif), GFP_KERNEL); | |
165 | if (lif == NULL) | |
166 | return ERR_PTR(-ENOMEM); | |
167 | ||
7b905f05 | 168 | lif->entity.ops = &lif_entity_ops; |
26e0ca22 | 169 | lif->entity.type = VSP1_ENTITY_LIF; |
26e0ca22 | 170 | |
6a8e07b2 LP |
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. | |
174 | */ | |
175 | ret = vsp1_entity_init(vsp1, &lif->entity, "lif", 2, &lif_ops, | |
176 | MEDIA_ENT_F_PROC_VIDEO_PIXEL_FORMATTER); | |
26e0ca22 LP |
177 | if (ret < 0) |
178 | return ERR_PTR(ret); | |
179 | ||
26e0ca22 LP |
180 | return lif; |
181 | } |