Laurent Pinchart | 1c4b5f4 | 2018-04-22 17:33:20 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 2 | /* |
| 3 | * vsp1_lif.c -- R-Car VSP1 LCD Controller Interface |
| 4 | * |
Laurent Pinchart | 8a1edc5 | 2014-02-06 14:42:31 -0300 | [diff] [blame] | 5 | * Copyright (C) 2013-2014 Renesas Electronics Corporation |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 6 | * |
| 7 | * Contact: Laurent Pinchart (laurent.pinchart@ideasonboard.com) |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <linux/device.h> |
| 11 | #include <linux/gfp.h> |
| 12 | |
| 13 | #include <media/v4l2-subdev.h> |
| 14 | |
| 15 | #include "vsp1.h" |
Laurent Pinchart | 5e8dbbf | 2015-11-22 20:29:25 -0200 | [diff] [blame] | 16 | #include "vsp1_dl.h" |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 17 | #include "vsp1_lif.h" |
| 18 | |
| 19 | #define LIF_MIN_SIZE 2U |
Laurent Pinchart | 0d268dc | 2016-03-25 06:51:06 -0300 | [diff] [blame] | 20 | #define LIF_MAX_SIZE 8190U |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 21 | |
| 22 | /* ----------------------------------------------------------------------------- |
| 23 | * Device Access |
| 24 | */ |
| 25 | |
Laurent Pinchart | 5e8dbbf | 2015-11-22 20:29:25 -0200 | [diff] [blame] | 26 | static inline void vsp1_lif_write(struct vsp1_lif *lif, struct vsp1_dl_list *dl, |
| 27 | u32 reg, u32 data) |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 28 | { |
Laurent Pinchart | 3be0bf9 | 2017-06-21 16:10:18 +0300 | [diff] [blame] | 29 | vsp1_dl_list_write(dl, reg + lif->entity.index * VI6_LIF_OFFSET, data); |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | /* ----------------------------------------------------------------------------- |
Laurent Pinchart | 7b905f0 | 2015-11-17 13:10:26 -0200 | [diff] [blame] | 33 | * V4L2 Subdevice Operations |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 34 | */ |
| 35 | |
Laurent Pinchart | b4ccae1 | 2017-11-27 14:59:45 -0500 | [diff] [blame] | 36 | static const unsigned int lif_codes[] = { |
| 37 | MEDIA_BUS_FMT_ARGB8888_1X32, |
| 38 | MEDIA_BUS_FMT_AYUV8_1X32, |
| 39 | }; |
| 40 | |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 41 | static int lif_enum_mbus_code(struct v4l2_subdev *subdev, |
Hans Verkuil | f723413 | 2015-03-04 01:47:54 -0800 | [diff] [blame] | 42 | struct v4l2_subdev_pad_config *cfg, |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 43 | struct v4l2_subdev_mbus_code_enum *code) |
| 44 | { |
Laurent Pinchart | b4ccae1 | 2017-11-27 14:59:45 -0500 | [diff] [blame] | 45 | return vsp1_subdev_enum_mbus_code(subdev, cfg, code, lif_codes, |
| 46 | ARRAY_SIZE(lif_codes)); |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | static int lif_enum_frame_size(struct v4l2_subdev *subdev, |
Hans Verkuil | f723413 | 2015-03-04 01:47:54 -0800 | [diff] [blame] | 50 | struct v4l2_subdev_pad_config *cfg, |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 51 | struct v4l2_subdev_frame_size_enum *fse) |
| 52 | { |
Laurent Pinchart | 076e834 | 2016-02-24 20:25:42 -0300 | [diff] [blame] | 53 | return vsp1_subdev_enum_frame_size(subdev, cfg, fse, LIF_MIN_SIZE, |
| 54 | LIF_MIN_SIZE, LIF_MAX_SIZE, |
| 55 | LIF_MAX_SIZE); |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 56 | } |
| 57 | |
Laurent Pinchart | 1bd0a1b | 2015-11-01 15:18:32 -0200 | [diff] [blame] | 58 | static int lif_set_format(struct v4l2_subdev *subdev, |
| 59 | struct v4l2_subdev_pad_config *cfg, |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 60 | struct v4l2_subdev_format *fmt) |
| 61 | { |
Laurent Pinchart | b4ccae1 | 2017-11-27 14:59:45 -0500 | [diff] [blame] | 62 | 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 Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 66 | } |
| 67 | |
Laurent Pinchart | eb9163d | 2016-06-17 21:11:26 -0300 | [diff] [blame] | 68 | static const struct v4l2_subdev_pad_ops lif_pad_ops = { |
Laurent Pinchart | 0efdf0f | 2015-11-15 20:09:08 -0200 | [diff] [blame] | 69 | .init_cfg = vsp1_entity_init_cfg, |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 70 | .enum_mbus_code = lif_enum_mbus_code, |
| 71 | .enum_frame_size = lif_enum_frame_size, |
Laurent Pinchart | 3f55722 | 2016-02-24 21:10:13 -0300 | [diff] [blame] | 72 | .get_fmt = vsp1_subdev_get_pad_format, |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 73 | .set_fmt = lif_set_format, |
| 74 | }; |
| 75 | |
Laurent Pinchart | eb9163d | 2016-06-17 21:11:26 -0300 | [diff] [blame] | 76 | static const struct v4l2_subdev_ops lif_ops = { |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 77 | .pad = &lif_pad_ops, |
| 78 | }; |
| 79 | |
| 80 | /* ----------------------------------------------------------------------------- |
Laurent Pinchart | 7b905f0 | 2015-11-17 13:10:26 -0200 | [diff] [blame] | 81 | * VSP1 Entity Operations |
| 82 | */ |
| 83 | |
Kieran Bingham | 46ce363 | 2018-05-18 16:42:01 -0400 | [diff] [blame^] | 84 | static void lif_configure_stream(struct vsp1_entity *entity, |
| 85 | struct vsp1_pipeline *pipe, |
| 86 | struct vsp1_dl_list *dl) |
Laurent Pinchart | 7b905f0 | 2015-11-17 13:10:26 -0200 | [diff] [blame] | 87 | { |
| 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 Pinchart | 5e8dbbf | 2015-11-22 20:29:25 -0200 | [diff] [blame] | 99 | vsp1_lif_write(lif, dl, VI6_LIF_CSBTH, |
Laurent Pinchart | 7b905f0 | 2015-11-17 13:10:26 -0200 | [diff] [blame] | 100 | (hbth << VI6_LIF_CSBTH_HBTH_SHIFT) | |
| 101 | (lbth << VI6_LIF_CSBTH_LBTH_SHIFT)); |
| 102 | |
Laurent Pinchart | 5e8dbbf | 2015-11-22 20:29:25 -0200 | [diff] [blame] | 103 | vsp1_lif_write(lif, dl, VI6_LIF_CTRL, |
Laurent Pinchart | 7b905f0 | 2015-11-17 13:10:26 -0200 | [diff] [blame] | 104 | (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 Shtylyov | 7f43ff9 | 2018-01-18 09:05:51 -0500 | [diff] [blame] | 107 | |
| 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 Pinchart | 7b905f0 | 2015-11-17 13:10:26 -0200 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | static const struct vsp1_entity_operations lif_entity_ops = { |
Kieran Bingham | 46ce363 | 2018-05-18 16:42:01 -0400 | [diff] [blame^] | 122 | .configure_stream = lif_configure_stream, |
Laurent Pinchart | 7b905f0 | 2015-11-17 13:10:26 -0200 | [diff] [blame] | 123 | }; |
| 124 | |
| 125 | /* ----------------------------------------------------------------------------- |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 126 | * Initialization and Cleanup |
| 127 | */ |
| 128 | |
Laurent Pinchart | 3be0bf9 | 2017-06-21 16:10:18 +0300 | [diff] [blame] | 129 | struct vsp1_lif *vsp1_lif_create(struct vsp1_device *vsp1, unsigned int index) |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 130 | { |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 131 | 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 Pinchart | 7b905f0 | 2015-11-17 13:10:26 -0200 | [diff] [blame] | 138 | lif->entity.ops = &lif_entity_ops; |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 139 | lif->entity.type = VSP1_ENTITY_LIF; |
Laurent Pinchart | 3be0bf9 | 2017-06-21 16:10:18 +0300 | [diff] [blame] | 140 | lif->entity.index = index; |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 141 | |
Laurent Pinchart | 9dbed95 | 2017-02-26 10:29:50 -0300 | [diff] [blame] | 142 | /* |
| 143 | * The LIF is never exposed to userspace, but media entity registration |
Laurent Pinchart | 6a8e07b | 2016-02-15 22:10:26 -0200 | [diff] [blame] | 144 | * 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 Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 149 | if (ret < 0) |
| 150 | return ERR_PTR(ret); |
| 151 | |
Laurent Pinchart | 26e0ca2 | 2013-06-04 11:22:30 -0300 | [diff] [blame] | 152 | return lif; |
| 153 | } |