Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1 | /* |
| 2 | * S5P/EXYNOS4 SoC series camera host interface media device driver |
| 3 | * |
Sylwester Nawrocki | 52917bc | 2013-05-31 11:37:24 -0300 | [diff] [blame] | 4 | * Copyright (C) 2011 - 2013 Samsung Electronics Co., Ltd. |
| 5 | * Author: Sylwester Nawrocki <s.nawrocki@samsung.com> |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published |
| 9 | * by the Free Software Foundation, either version 2 of the License, |
| 10 | * or (at your option) any later version. |
| 11 | */ |
| 12 | |
| 13 | #include <linux/bug.h> |
Sylwester Nawrocki | d3f5e0c | 2013-12-20 18:53:53 -0300 | [diff] [blame] | 14 | #include <linux/clk.h> |
| 15 | #include <linux/clk-provider.h> |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 16 | #include <linux/device.h> |
| 17 | #include <linux/errno.h> |
| 18 | #include <linux/i2c.h> |
| 19 | #include <linux/kernel.h> |
| 20 | #include <linux/list.h> |
| 21 | #include <linux/module.h> |
Sylwester Nawrocki | e2985a2 | 2013-03-08 12:59:33 -0300 | [diff] [blame] | 22 | #include <linux/of.h> |
| 23 | #include <linux/of_platform.h> |
| 24 | #include <linux/of_device.h> |
Philipp Zabel | fd9fdb7 | 2014-02-10 22:01:48 +0100 | [diff] [blame] | 25 | #include <linux/of_graph.h> |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 26 | #include <linux/platform_device.h> |
| 27 | #include <linux/pm_runtime.h> |
| 28 | #include <linux/types.h> |
| 29 | #include <linux/slab.h> |
Sylwester Nawrocki | fa91f10 | 2014-02-24 11:44:50 -0300 | [diff] [blame] | 30 | #include <media/v4l2-async.h> |
Sylwester Nawrocki | 131b6c6 | 2011-08-24 19:25:10 -0300 | [diff] [blame] | 31 | #include <media/v4l2-ctrls.h> |
Sakari Ailus | 859969b | 2016-08-26 20:17:25 -0300 | [diff] [blame] | 32 | #include <media/v4l2-fwnode.h> |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 33 | #include <media/media-device.h> |
Mauro Carvalho Chehab | d647f0b | 2015-11-13 19:40:07 -0200 | [diff] [blame] | 34 | #include <media/drv-intf/exynos-fimc.h> |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 35 | |
Sylwester Nawrocki | 56fa1a6 | 2013-03-24 16:54:25 +0100 | [diff] [blame] | 36 | #include "media-dev.h" |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 37 | #include "fimc-core.h" |
Sylwester Nawrocki | e781bbe3 | 2013-03-21 14:49:16 -0300 | [diff] [blame] | 38 | #include "fimc-is.h" |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 39 | #include "fimc-lite.h" |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 40 | #include "mipi-csis.h" |
| 41 | |
Sylwester Nawrocki | 52917bc | 2013-05-31 11:37:24 -0300 | [diff] [blame] | 42 | /* Set up image sensor subdev -> FIMC capture node notifications. */ |
| 43 | static void __setup_sensor_notification(struct fimc_md *fmd, |
| 44 | struct v4l2_subdev *sensor, |
| 45 | struct v4l2_subdev *fimc_sd) |
| 46 | { |
| 47 | struct fimc_source_info *src_inf; |
| 48 | struct fimc_sensor_info *md_si; |
| 49 | unsigned long flags; |
| 50 | |
| 51 | src_inf = v4l2_get_subdev_hostdata(sensor); |
| 52 | if (!src_inf || WARN_ON(fmd == NULL)) |
| 53 | return; |
| 54 | |
| 55 | md_si = source_to_sensor_info(src_inf); |
| 56 | spin_lock_irqsave(&fmd->slock, flags); |
| 57 | md_si->host = v4l2_get_subdevdata(fimc_sd); |
| 58 | spin_unlock_irqrestore(&fmd->slock, flags); |
| 59 | } |
| 60 | |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 61 | /** |
| 62 | * fimc_pipeline_prepare - update pipeline information with subdevice pointers |
Mauro Carvalho Chehab | 3b060ba0 | 2017-11-29 04:32:51 -0500 | [diff] [blame] | 63 | * @p: fimc pipeline |
Sylwester Nawrocki | 39bb6df6 | 2013-03-08 08:58:34 -0300 | [diff] [blame] | 64 | * @me: media entity terminating the pipeline |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 65 | * |
| 66 | * Caller holds the graph mutex. |
| 67 | */ |
Sylwester Nawrocki | b9ee31e6 | 2012-08-14 10:46:58 -0300 | [diff] [blame] | 68 | static void fimc_pipeline_prepare(struct fimc_pipeline *p, |
Sylwester Nawrocki | 403dfbe | 2013-05-31 11:37:22 -0300 | [diff] [blame] | 69 | struct media_entity *me) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 70 | { |
Sylwester Nawrocki | 52917bc | 2013-05-31 11:37:24 -0300 | [diff] [blame] | 71 | struct fimc_md *fmd = entity_to_fimc_mdev(me); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 72 | struct v4l2_subdev *sd; |
Sylwester Nawrocki | 52917bc | 2013-05-31 11:37:24 -0300 | [diff] [blame] | 73 | struct v4l2_subdev *sensor = NULL; |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 74 | int i; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 75 | |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 76 | for (i = 0; i < IDX_MAX; i++) |
| 77 | p->subdevs[i] = NULL; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 78 | |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 79 | while (1) { |
Sylwester Nawrocki | 39bb6df6 | 2013-03-08 08:58:34 -0300 | [diff] [blame] | 80 | struct media_pad *pad = NULL; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 81 | |
Sylwester Nawrocki | 39bb6df6 | 2013-03-08 08:58:34 -0300 | [diff] [blame] | 82 | /* Find remote source pad */ |
| 83 | for (i = 0; i < me->num_pads; i++) { |
| 84 | struct media_pad *spad = &me->pads[i]; |
| 85 | if (!(spad->flags & MEDIA_PAD_FL_SINK)) |
| 86 | continue; |
Andrzej Hajda | 1bddf1b | 2013-06-03 05:16:13 -0300 | [diff] [blame] | 87 | pad = media_entity_remote_pad(spad); |
Sylwester Nawrocki | 39bb6df6 | 2013-03-08 08:58:34 -0300 | [diff] [blame] | 88 | if (pad) |
| 89 | break; |
| 90 | } |
| 91 | |
Mauro Carvalho Chehab | 3efdf62 | 2015-05-07 22:12:32 -0300 | [diff] [blame] | 92 | if (!pad || !is_media_entity_v4l2_subdev(pad->entity)) |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 93 | break; |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 94 | sd = media_entity_to_v4l2_subdev(pad->entity); |
| 95 | |
| 96 | switch (sd->grp_id) { |
Sylwester Nawrocki | 588c87b | 2012-11-27 11:57:42 -0300 | [diff] [blame] | 97 | case GRP_ID_SENSOR: |
Sylwester Nawrocki | 52917bc | 2013-05-31 11:37:24 -0300 | [diff] [blame] | 98 | sensor = sd; |
| 99 | /* fall through */ |
| 100 | case GRP_ID_FIMC_IS_SENSOR: |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 101 | p->subdevs[IDX_SENSOR] = sd; |
| 102 | break; |
Sylwester Nawrocki | 588c87b | 2012-11-27 11:57:42 -0300 | [diff] [blame] | 103 | case GRP_ID_CSIS: |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 104 | p->subdevs[IDX_CSIS] = sd; |
| 105 | break; |
Sylwester Nawrocki | 588c87b | 2012-11-27 11:57:42 -0300 | [diff] [blame] | 106 | case GRP_ID_FLITE: |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 107 | p->subdevs[IDX_FLITE] = sd; |
| 108 | break; |
Sylwester Nawrocki | 588c87b | 2012-11-27 11:57:42 -0300 | [diff] [blame] | 109 | case GRP_ID_FIMC: |
Sylwester Nawrocki | 52917bc | 2013-05-31 11:37:24 -0300 | [diff] [blame] | 110 | p->subdevs[IDX_FIMC] = sd; |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 111 | break; |
Sylwester Nawrocki | e781bbe3 | 2013-03-21 14:49:16 -0300 | [diff] [blame] | 112 | case GRP_ID_FIMC_IS: |
| 113 | p->subdevs[IDX_IS_ISP] = sd; |
| 114 | break; |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 115 | default: |
Sylwester Nawrocki | e781bbe3 | 2013-03-21 14:49:16 -0300 | [diff] [blame] | 116 | break; |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 117 | } |
Sylwester Nawrocki | 39bb6df6 | 2013-03-08 08:58:34 -0300 | [diff] [blame] | 118 | me = &sd->entity; |
| 119 | if (me->num_pads == 1) |
| 120 | break; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 121 | } |
Sylwester Nawrocki | 52917bc | 2013-05-31 11:37:24 -0300 | [diff] [blame] | 122 | |
| 123 | if (sensor && p->subdevs[IDX_FIMC]) |
| 124 | __setup_sensor_notification(fmd, sensor, p->subdevs[IDX_FIMC]); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | /** |
| 128 | * __subdev_set_power - change power state of a single subdev |
| 129 | * @sd: subdevice to change power state for |
| 130 | * @on: 1 to enable power or 0 to disable |
| 131 | * |
| 132 | * Return result of s_power subdev operation or -ENXIO if sd argument |
| 133 | * is NULL. Return 0 if the subdevice does not implement s_power. |
| 134 | */ |
| 135 | static int __subdev_set_power(struct v4l2_subdev *sd, int on) |
| 136 | { |
| 137 | int *use_count; |
| 138 | int ret; |
| 139 | |
| 140 | if (sd == NULL) |
| 141 | return -ENXIO; |
| 142 | |
| 143 | use_count = &sd->entity.use_count; |
| 144 | if (on && (*use_count)++ > 0) |
| 145 | return 0; |
| 146 | else if (!on && (*use_count == 0 || --(*use_count) > 0)) |
| 147 | return 0; |
| 148 | ret = v4l2_subdev_call(sd, core, s_power, on); |
| 149 | |
| 150 | return ret != -ENOIOCTLCMD ? ret : 0; |
| 151 | } |
| 152 | |
| 153 | /** |
| 154 | * fimc_pipeline_s_power - change power state of all pipeline subdevs |
Mauro Carvalho Chehab | 3b060ba0 | 2017-11-29 04:32:51 -0500 | [diff] [blame] | 155 | * @p: fimc device terminating the pipeline |
| 156 | * @on: true to power on, false to power off |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 157 | * |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 158 | * Needs to be called with the graph mutex held. |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 159 | */ |
Sylwester Nawrocki | f8bca4f | 2012-11-20 08:54:22 -0300 | [diff] [blame] | 160 | static int fimc_pipeline_s_power(struct fimc_pipeline *p, bool on) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 161 | { |
Sylwester Nawrocki | f8bca4f | 2012-11-20 08:54:22 -0300 | [diff] [blame] | 162 | static const u8 seq[2][IDX_MAX - 1] = { |
| 163 | { IDX_IS_ISP, IDX_SENSOR, IDX_CSIS, IDX_FLITE }, |
| 164 | { IDX_CSIS, IDX_FLITE, IDX_SENSOR, IDX_IS_ISP }, |
| 165 | }; |
| 166 | int i, ret = 0; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 167 | |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 168 | if (p->subdevs[IDX_SENSOR] == NULL) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 169 | return -ENXIO; |
| 170 | |
Sylwester Nawrocki | f8bca4f | 2012-11-20 08:54:22 -0300 | [diff] [blame] | 171 | for (i = 0; i < IDX_MAX - 1; i++) { |
| 172 | unsigned int idx = seq[on][i]; |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 173 | |
Sylwester Nawrocki | f8bca4f | 2012-11-20 08:54:22 -0300 | [diff] [blame] | 174 | ret = __subdev_set_power(p->subdevs[idx], on); |
| 175 | |
| 176 | |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 177 | if (ret < 0 && ret != -ENXIO) |
Sylwester Nawrocki | f8bca4f | 2012-11-20 08:54:22 -0300 | [diff] [blame] | 178 | goto error; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 179 | } |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 180 | return 0; |
Sylwester Nawrocki | f8bca4f | 2012-11-20 08:54:22 -0300 | [diff] [blame] | 181 | error: |
| 182 | for (; i >= 0; i--) { |
| 183 | unsigned int idx = seq[on][i]; |
| 184 | __subdev_set_power(p->subdevs[idx], !on); |
| 185 | } |
| 186 | return ret; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | /** |
Jacek Anaszewski | 7677577 | 2016-01-18 14:10:26 -0200 | [diff] [blame] | 190 | * __fimc_pipeline_enable - enable power of all pipeline subdevs |
| 191 | * and the sensor clock |
| 192 | * @ep: video pipeline structure |
| 193 | * @fmd: fimc media device |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 194 | * |
Sylwester Nawrocki | 740ad92 | 2012-12-06 10:26:19 -0300 | [diff] [blame] | 195 | * Called with the graph mutex held. |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 196 | */ |
Jacek Anaszewski | 7677577 | 2016-01-18 14:10:26 -0200 | [diff] [blame] | 197 | static int __fimc_pipeline_enable(struct exynos_media_pipeline *ep, |
| 198 | struct fimc_md *fmd) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 199 | { |
Sylwester Nawrocki | 403dfbe | 2013-05-31 11:37:22 -0300 | [diff] [blame] | 200 | struct fimc_pipeline *p = to_fimc_pipeline(ep); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 201 | int ret; |
| 202 | |
Jacek Anaszewski | 7677577 | 2016-01-18 14:10:26 -0200 | [diff] [blame] | 203 | /* Enable PXLASYNC clock if this pipeline includes FIMC-IS */ |
Sylwester Nawrocki | 056f4f3 | 2013-03-21 14:43:17 -0300 | [diff] [blame] | 204 | if (!IS_ERR(fmd->wbclk[CLK_IDX_WB_B]) && p->subdevs[IDX_IS_ISP]) { |
| 205 | ret = clk_prepare_enable(fmd->wbclk[CLK_IDX_WB_B]); |
| 206 | if (ret < 0) |
| 207 | return ret; |
| 208 | } |
Sylwester Nawrocki | fa91f10 | 2014-02-24 11:44:50 -0300 | [diff] [blame] | 209 | |
Sylwester Nawrocki | 056f4f3 | 2013-03-21 14:43:17 -0300 | [diff] [blame] | 210 | ret = fimc_pipeline_s_power(p, 1); |
| 211 | if (!ret) |
| 212 | return 0; |
| 213 | |
Sylwester Nawrocki | 056f4f3 | 2013-03-21 14:43:17 -0300 | [diff] [blame] | 214 | if (!IS_ERR(fmd->wbclk[CLK_IDX_WB_B]) && p->subdevs[IDX_IS_ISP]) |
| 215 | clk_disable_unprepare(fmd->wbclk[CLK_IDX_WB_B]); |
| 216 | |
| 217 | return ret; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 218 | } |
| 219 | |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 220 | /** |
Jacek Anaszewski | 7677577 | 2016-01-18 14:10:26 -0200 | [diff] [blame] | 221 | * __fimc_pipeline_open - update the pipeline information, enable power |
| 222 | * of all pipeline subdevs and the sensor clock |
Mauro Carvalho Chehab | 3b060ba0 | 2017-11-29 04:32:51 -0500 | [diff] [blame] | 223 | * @ep: fimc device terminating the pipeline |
Jacek Anaszewski | 7677577 | 2016-01-18 14:10:26 -0200 | [diff] [blame] | 224 | * @me: media entity to start graph walk with |
| 225 | * @prepare: true to walk the current pipeline and acquire all subdevs |
| 226 | * |
| 227 | * Called with the graph mutex held. |
| 228 | */ |
| 229 | static int __fimc_pipeline_open(struct exynos_media_pipeline *ep, |
| 230 | struct media_entity *me, bool prepare) |
| 231 | { |
| 232 | struct fimc_md *fmd = entity_to_fimc_mdev(me); |
| 233 | struct fimc_pipeline *p = to_fimc_pipeline(ep); |
| 234 | struct v4l2_subdev *sd; |
| 235 | |
| 236 | if (WARN_ON(p == NULL || me == NULL)) |
| 237 | return -EINVAL; |
| 238 | |
| 239 | if (prepare) |
| 240 | fimc_pipeline_prepare(p, me); |
| 241 | |
| 242 | sd = p->subdevs[IDX_SENSOR]; |
| 243 | if (sd == NULL) { |
| 244 | pr_warn("%s(): No sensor subdev\n", __func__); |
| 245 | /* |
| 246 | * Pipeline open cannot fail so as to make it possible |
| 247 | * for the user space to configure the pipeline. |
| 248 | */ |
| 249 | return 0; |
| 250 | } |
| 251 | |
| 252 | return __fimc_pipeline_enable(ep, fmd); |
| 253 | } |
| 254 | |
| 255 | /** |
Sylwester Nawrocki | b9ee31e6 | 2012-08-14 10:46:58 -0300 | [diff] [blame] | 256 | * __fimc_pipeline_close - disable the sensor clock and pipeline power |
Mauro Carvalho Chehab | 3b060ba0 | 2017-11-29 04:32:51 -0500 | [diff] [blame] | 257 | * @ep: fimc device terminating the pipeline |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 258 | * |
Sylwester Nawrocki | 740ad92 | 2012-12-06 10:26:19 -0300 | [diff] [blame] | 259 | * Disable power of all subdevs and turn the external sensor clock off. |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 260 | */ |
Sylwester Nawrocki | 403dfbe | 2013-05-31 11:37:22 -0300 | [diff] [blame] | 261 | static int __fimc_pipeline_close(struct exynos_media_pipeline *ep) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 262 | { |
Sylwester Nawrocki | 403dfbe | 2013-05-31 11:37:22 -0300 | [diff] [blame] | 263 | struct fimc_pipeline *p = to_fimc_pipeline(ep); |
Sylwester Nawrocki | 056f4f3 | 2013-03-21 14:43:17 -0300 | [diff] [blame] | 264 | struct v4l2_subdev *sd = p ? p->subdevs[IDX_SENSOR] : NULL; |
| 265 | struct fimc_md *fmd; |
Sylwester Nawrocki | 36da6fc | 2013-05-31 11:37:23 -0300 | [diff] [blame] | 266 | int ret; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 267 | |
Sylwester Nawrocki | 36da6fc | 2013-05-31 11:37:23 -0300 | [diff] [blame] | 268 | if (sd == NULL) { |
| 269 | pr_warn("%s(): No sensor subdev\n", __func__); |
| 270 | return 0; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 271 | } |
Sylwester Nawrocki | 056f4f3 | 2013-03-21 14:43:17 -0300 | [diff] [blame] | 272 | |
Sylwester Nawrocki | 36da6fc | 2013-05-31 11:37:23 -0300 | [diff] [blame] | 273 | ret = fimc_pipeline_s_power(p, 0); |
Sylwester Nawrocki | 36da6fc | 2013-05-31 11:37:23 -0300 | [diff] [blame] | 274 | |
Sylwester Nawrocki | 056f4f3 | 2013-03-21 14:43:17 -0300 | [diff] [blame] | 275 | fmd = entity_to_fimc_mdev(&sd->entity); |
| 276 | |
| 277 | /* Disable PXLASYNC clock if this pipeline includes FIMC-IS */ |
| 278 | if (!IS_ERR(fmd->wbclk[CLK_IDX_WB_B]) && p->subdevs[IDX_IS_ISP]) |
| 279 | clk_disable_unprepare(fmd->wbclk[CLK_IDX_WB_B]); |
| 280 | |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 281 | return ret == -ENXIO ? 0 : ret; |
| 282 | } |
| 283 | |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 284 | /** |
Sylwester Nawrocki | 8d274e7 | 2012-11-13 14:35:22 -0300 | [diff] [blame] | 285 | * __fimc_pipeline_s_stream - call s_stream() on pipeline subdevs |
Mauro Carvalho Chehab | 3b060ba0 | 2017-11-29 04:32:51 -0500 | [diff] [blame] | 286 | * @ep: video pipeline structure |
Sylwester Nawrocki | 8d274e7 | 2012-11-13 14:35:22 -0300 | [diff] [blame] | 287 | * @on: passed as the s_stream() callback argument |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 288 | */ |
Sylwester Nawrocki | 403dfbe | 2013-05-31 11:37:22 -0300 | [diff] [blame] | 289 | static int __fimc_pipeline_s_stream(struct exynos_media_pipeline *ep, bool on) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 290 | { |
Sylwester Nawrocki | 8d274e7 | 2012-11-13 14:35:22 -0300 | [diff] [blame] | 291 | static const u8 seq[2][IDX_MAX] = { |
| 292 | { IDX_FIMC, IDX_SENSOR, IDX_IS_ISP, IDX_CSIS, IDX_FLITE }, |
| 293 | { IDX_CSIS, IDX_FLITE, IDX_FIMC, IDX_SENSOR, IDX_IS_ISP }, |
| 294 | }; |
Sylwester Nawrocki | 403dfbe | 2013-05-31 11:37:22 -0300 | [diff] [blame] | 295 | struct fimc_pipeline *p = to_fimc_pipeline(ep); |
Jacek Anaszewski | 7677577 | 2016-01-18 14:10:26 -0200 | [diff] [blame] | 296 | struct fimc_md *fmd = entity_to_fimc_mdev(&p->subdevs[IDX_CSIS]->entity); |
| 297 | enum fimc_subdev_index sd_id; |
Sylwester Nawrocki | 8d274e7 | 2012-11-13 14:35:22 -0300 | [diff] [blame] | 298 | int i, ret = 0; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 299 | |
Jacek Anaszewski | 7677577 | 2016-01-18 14:10:26 -0200 | [diff] [blame] | 300 | if (p->subdevs[IDX_SENSOR] == NULL) { |
| 301 | if (!fmd->user_subdev_api) { |
| 302 | /* |
| 303 | * Sensor must be already discovered if we |
| 304 | * aren't in the user_subdev_api mode |
| 305 | */ |
| 306 | return -ENODEV; |
| 307 | } |
| 308 | |
| 309 | /* Get pipeline sink entity */ |
| 310 | if (p->subdevs[IDX_FIMC]) |
| 311 | sd_id = IDX_FIMC; |
| 312 | else if (p->subdevs[IDX_IS_ISP]) |
| 313 | sd_id = IDX_IS_ISP; |
| 314 | else if (p->subdevs[IDX_FLITE]) |
| 315 | sd_id = IDX_FLITE; |
| 316 | else |
| 317 | return -ENODEV; |
| 318 | |
| 319 | /* |
| 320 | * Sensor could have been linked between open and STREAMON - |
| 321 | * check if this is the case. |
| 322 | */ |
| 323 | fimc_pipeline_prepare(p, &p->subdevs[sd_id]->entity); |
| 324 | |
| 325 | if (p->subdevs[IDX_SENSOR] == NULL) |
| 326 | return -ENODEV; |
| 327 | |
| 328 | ret = __fimc_pipeline_enable(ep, fmd); |
| 329 | if (ret < 0) |
| 330 | return ret; |
| 331 | |
| 332 | } |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 333 | |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 334 | for (i = 0; i < IDX_MAX; i++) { |
Sylwester Nawrocki | 8d274e7 | 2012-11-13 14:35:22 -0300 | [diff] [blame] | 335 | unsigned int idx = seq[on][i]; |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 336 | |
| 337 | ret = v4l2_subdev_call(p->subdevs[idx], video, s_stream, on); |
| 338 | |
| 339 | if (ret < 0 && ret != -ENOIOCTLCMD && ret != -ENODEV) |
Sylwester Nawrocki | 8d274e7 | 2012-11-13 14:35:22 -0300 | [diff] [blame] | 340 | goto error; |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 341 | } |
Jacek Anaszewski | 7677577 | 2016-01-18 14:10:26 -0200 | [diff] [blame] | 342 | |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 343 | return 0; |
Sylwester Nawrocki | 8d274e7 | 2012-11-13 14:35:22 -0300 | [diff] [blame] | 344 | error: |
Jacek Anaszewski | 7677577 | 2016-01-18 14:10:26 -0200 | [diff] [blame] | 345 | fimc_pipeline_s_power(p, !on); |
Sylwester Nawrocki | 8d274e7 | 2012-11-13 14:35:22 -0300 | [diff] [blame] | 346 | for (; i >= 0; i--) { |
| 347 | unsigned int idx = seq[on][i]; |
| 348 | v4l2_subdev_call(p->subdevs[idx], video, s_stream, !on); |
| 349 | } |
| 350 | return ret; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 351 | } |
Sylwester Nawrocki | b9ee31e6 | 2012-08-14 10:46:58 -0300 | [diff] [blame] | 352 | |
| 353 | /* Media pipeline operations for the FIMC/FIMC-LITE video device driver */ |
Sylwester Nawrocki | 403dfbe | 2013-05-31 11:37:22 -0300 | [diff] [blame] | 354 | static const struct exynos_media_pipeline_ops fimc_pipeline_ops = { |
Sylwester Nawrocki | 740ad92 | 2012-12-06 10:26:19 -0300 | [diff] [blame] | 355 | .open = __fimc_pipeline_open, |
| 356 | .close = __fimc_pipeline_close, |
| 357 | .set_stream = __fimc_pipeline_s_stream, |
Sylwester Nawrocki | b9ee31e6 | 2012-08-14 10:46:58 -0300 | [diff] [blame] | 358 | }; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 359 | |
Sylwester Nawrocki | 403dfbe | 2013-05-31 11:37:22 -0300 | [diff] [blame] | 360 | static struct exynos_media_pipeline *fimc_md_pipeline_create( |
| 361 | struct fimc_md *fmd) |
| 362 | { |
| 363 | struct fimc_pipeline *p; |
| 364 | |
| 365 | p = kzalloc(sizeof(*p), GFP_KERNEL); |
| 366 | if (!p) |
| 367 | return NULL; |
| 368 | |
| 369 | list_add_tail(&p->list, &fmd->pipelines); |
| 370 | |
| 371 | p->ep.ops = &fimc_pipeline_ops; |
| 372 | return &p->ep; |
| 373 | } |
| 374 | |
| 375 | static void fimc_md_pipelines_free(struct fimc_md *fmd) |
| 376 | { |
| 377 | while (!list_empty(&fmd->pipelines)) { |
| 378 | struct fimc_pipeline *p; |
| 379 | |
| 380 | p = list_entry(fmd->pipelines.next, typeof(*p), list); |
| 381 | list_del(&p->list); |
| 382 | kfree(p); |
| 383 | } |
| 384 | } |
| 385 | |
Sylwester Nawrocki | 2b13f7d | 2013-03-29 14:12:39 -0300 | [diff] [blame] | 386 | /* Parse port node and register as a sub-device any sensor specified there. */ |
| 387 | static int fimc_md_parse_port_node(struct fimc_md *fmd, |
| 388 | struct device_node *port, |
| 389 | unsigned int index) |
| 390 | { |
Sylwester Nawrocki | 49b2f4c5 | 2014-04-15 08:35:25 -0300 | [diff] [blame] | 391 | struct fimc_source_info *pd = &fmd->sensor[index].pdata; |
Sylwester Nawrocki | 2b13f7d | 2013-03-29 14:12:39 -0300 | [diff] [blame] | 392 | struct device_node *rem, *ep, *np; |
Sakari Ailus | 859969b | 2016-08-26 20:17:25 -0300 | [diff] [blame] | 393 | struct v4l2_fwnode_endpoint endpoint; |
Javier Martinez Canillas | 234eab8 | 2016-01-11 14:47:15 -0200 | [diff] [blame] | 394 | int ret; |
Sylwester Nawrocki | 2b13f7d | 2013-03-29 14:12:39 -0300 | [diff] [blame] | 395 | |
| 396 | /* Assume here a port node can have only one endpoint node. */ |
| 397 | ep = of_get_next_child(port, NULL); |
| 398 | if (!ep) |
| 399 | return 0; |
| 400 | |
Sakari Ailus | 859969b | 2016-08-26 20:17:25 -0300 | [diff] [blame] | 401 | ret = v4l2_fwnode_endpoint_parse(of_fwnode_handle(ep), &endpoint); |
Javier Martinez Canillas | 234eab8 | 2016-01-11 14:47:15 -0200 | [diff] [blame] | 402 | if (ret) { |
| 403 | of_node_put(ep); |
| 404 | return ret; |
| 405 | } |
| 406 | |
Christophe JAILLET | 2b2d1d4 | 2017-01-23 19:16:56 -0200 | [diff] [blame] | 407 | if (WARN_ON(endpoint.base.port == 0) || index >= FIMC_MAX_SENSORS) { |
| 408 | of_node_put(ep); |
Sylwester Nawrocki | 2b13f7d | 2013-03-29 14:12:39 -0300 | [diff] [blame] | 409 | return -EINVAL; |
Christophe JAILLET | 2b2d1d4 | 2017-01-23 19:16:56 -0200 | [diff] [blame] | 410 | } |
Sylwester Nawrocki | 2b13f7d | 2013-03-29 14:12:39 -0300 | [diff] [blame] | 411 | |
Philipp Zabel | f2a575f | 2014-02-14 11:53:56 +0100 | [diff] [blame] | 412 | pd->mux_id = (endpoint.base.port - 1) & 0x1; |
Sylwester Nawrocki | 2b13f7d | 2013-03-29 14:12:39 -0300 | [diff] [blame] | 413 | |
Philipp Zabel | fd9fdb7 | 2014-02-10 22:01:48 +0100 | [diff] [blame] | 414 | rem = of_graph_get_remote_port_parent(ep); |
Sylwester Nawrocki | 2b13f7d | 2013-03-29 14:12:39 -0300 | [diff] [blame] | 415 | of_node_put(ep); |
| 416 | if (rem == NULL) { |
Rob Herring | 68d9c47 | 2017-07-21 15:28:33 -0400 | [diff] [blame] | 417 | v4l2_info(&fmd->v4l2_dev, "Remote device at %pOF not found\n", |
| 418 | ep); |
Sylwester Nawrocki | 2b13f7d | 2013-03-29 14:12:39 -0300 | [diff] [blame] | 419 | return 0; |
| 420 | } |
Sylwester Nawrocki | 2b13f7d | 2013-03-29 14:12:39 -0300 | [diff] [blame] | 421 | |
Philipp Zabel | f2a575f | 2014-02-14 11:53:56 +0100 | [diff] [blame] | 422 | if (fimc_input_is_parallel(endpoint.base.port)) { |
Sylwester Nawrocki | 2b13f7d | 2013-03-29 14:12:39 -0300 | [diff] [blame] | 423 | if (endpoint.bus_type == V4L2_MBUS_PARALLEL) |
| 424 | pd->sensor_bus_type = FIMC_BUS_TYPE_ITU_601; |
| 425 | else |
| 426 | pd->sensor_bus_type = FIMC_BUS_TYPE_ITU_656; |
| 427 | pd->flags = endpoint.bus.parallel.flags; |
Philipp Zabel | f2a575f | 2014-02-14 11:53:56 +0100 | [diff] [blame] | 428 | } else if (fimc_input_is_mipi_csi(endpoint.base.port)) { |
Sylwester Nawrocki | 2b13f7d | 2013-03-29 14:12:39 -0300 | [diff] [blame] | 429 | /* |
| 430 | * MIPI CSI-2: only input mux selection and |
| 431 | * the sensor's clock frequency is needed. |
| 432 | */ |
| 433 | pd->sensor_bus_type = FIMC_BUS_TYPE_MIPI_CSI2; |
| 434 | } else { |
Rob Herring | 68d9c47 | 2017-07-21 15:28:33 -0400 | [diff] [blame] | 435 | v4l2_err(&fmd->v4l2_dev, "Wrong port id (%u) at node %pOF\n", |
| 436 | endpoint.base.port, rem); |
Sylwester Nawrocki | 2b13f7d | 2013-03-29 14:12:39 -0300 | [diff] [blame] | 437 | } |
| 438 | /* |
| 439 | * For FIMC-IS handled sensors, that are placed under i2c-isp device |
| 440 | * node, FIMC is connected to the FIMC-IS through its ISP Writeback |
| 441 | * input. Sensors are attached to the FIMC-LITE hostdata interface |
| 442 | * directly or through MIPI-CSIS, depending on the external media bus |
| 443 | * used. This needs to be handled in a more reliable way, not by just |
| 444 | * checking parent's node name. |
| 445 | */ |
| 446 | np = of_get_parent(rem); |
| 447 | |
| 448 | if (np && !of_node_cmp(np->name, "i2c-isp")) |
| 449 | pd->fimc_bus_type = FIMC_BUS_TYPE_ISP_WRITEBACK; |
| 450 | else |
| 451 | pd->fimc_bus_type = pd->sensor_bus_type; |
| 452 | |
Krzysztof Kozlowski | 7e8da34 | 2016-01-25 22:41:46 -0200 | [diff] [blame] | 453 | if (WARN_ON(index >= ARRAY_SIZE(fmd->sensor))) { |
| 454 | of_node_put(rem); |
Sylwester Nawrocki | fa91f10 | 2014-02-24 11:44:50 -0300 | [diff] [blame] | 455 | return -EINVAL; |
Krzysztof Kozlowski | 7e8da34 | 2016-01-25 22:41:46 -0200 | [diff] [blame] | 456 | } |
Sylwester Nawrocki | 2b13f7d | 2013-03-29 14:12:39 -0300 | [diff] [blame] | 457 | |
Sakari Ailus | 859969b | 2016-08-26 20:17:25 -0300 | [diff] [blame] | 458 | fmd->sensor[index].asd.match_type = V4L2_ASYNC_MATCH_FWNODE; |
| 459 | fmd->sensor[index].asd.match.fwnode.fwnode = of_fwnode_handle(rem); |
Sylwester Nawrocki | fa91f10 | 2014-02-24 11:44:50 -0300 | [diff] [blame] | 460 | fmd->async_subdevs[index] = &fmd->sensor[index].asd; |
| 461 | |
| 462 | fmd->num_sensors++; |
| 463 | |
| 464 | of_node_put(rem); |
| 465 | return 0; |
Sylwester Nawrocki | 2b13f7d | 2013-03-29 14:12:39 -0300 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | /* Register all SoC external sub-devices */ |
Sylwester Nawrocki | 49b2f4c5 | 2014-04-15 08:35:25 -0300 | [diff] [blame] | 469 | static int fimc_md_register_sensor_entities(struct fimc_md *fmd) |
Sylwester Nawrocki | 2b13f7d | 2013-03-29 14:12:39 -0300 | [diff] [blame] | 470 | { |
| 471 | struct device_node *parent = fmd->pdev->dev.of_node; |
| 472 | struct device_node *node, *ports; |
| 473 | int index = 0; |
| 474 | int ret; |
| 475 | |
Sylwester Nawrocki | 49b2f4c5 | 2014-04-15 08:35:25 -0300 | [diff] [blame] | 476 | /* |
| 477 | * Runtime resume one of the FIMC entities to make sure |
| 478 | * the sclk_cam clocks are not globally disabled. |
| 479 | */ |
| 480 | if (!fmd->pmf) |
| 481 | return -ENXIO; |
| 482 | |
| 483 | ret = pm_runtime_get_sync(fmd->pmf); |
| 484 | if (ret < 0) |
| 485 | return ret; |
| 486 | |
| 487 | fmd->num_sensors = 0; |
| 488 | |
Sylwester Nawrocki | 2b13f7d | 2013-03-29 14:12:39 -0300 | [diff] [blame] | 489 | /* Attach sensors linked to MIPI CSI-2 receivers */ |
| 490 | for_each_available_child_of_node(parent, node) { |
| 491 | struct device_node *port; |
| 492 | |
| 493 | if (of_node_cmp(node->name, "csis")) |
| 494 | continue; |
| 495 | /* The csis node can have only port subnode. */ |
| 496 | port = of_get_next_child(node, NULL); |
| 497 | if (!port) |
| 498 | continue; |
| 499 | |
| 500 | ret = fimc_md_parse_port_node(fmd, port, index); |
Amitoj Kaur Chawla | 458a395 | 2016-01-25 13:21:37 -0200 | [diff] [blame] | 501 | if (ret < 0) { |
| 502 | of_node_put(node); |
Sylwester Nawrocki | 49b2f4c5 | 2014-04-15 08:35:25 -0300 | [diff] [blame] | 503 | goto rpm_put; |
Amitoj Kaur Chawla | 458a395 | 2016-01-25 13:21:37 -0200 | [diff] [blame] | 504 | } |
Sylwester Nawrocki | 2b13f7d | 2013-03-29 14:12:39 -0300 | [diff] [blame] | 505 | index++; |
| 506 | } |
| 507 | |
| 508 | /* Attach sensors listed in the parallel-ports node */ |
| 509 | ports = of_get_child_by_name(parent, "parallel-ports"); |
| 510 | if (!ports) |
Sylwester Nawrocki | 49b2f4c5 | 2014-04-15 08:35:25 -0300 | [diff] [blame] | 511 | goto rpm_put; |
Sylwester Nawrocki | 2b13f7d | 2013-03-29 14:12:39 -0300 | [diff] [blame] | 512 | |
| 513 | for_each_child_of_node(ports, node) { |
| 514 | ret = fimc_md_parse_port_node(fmd, node, index); |
Amitoj Kaur Chawla | 458a395 | 2016-01-25 13:21:37 -0200 | [diff] [blame] | 515 | if (ret < 0) { |
| 516 | of_node_put(node); |
Sylwester Nawrocki | 2b13f7d | 2013-03-29 14:12:39 -0300 | [diff] [blame] | 517 | break; |
Amitoj Kaur Chawla | 458a395 | 2016-01-25 13:21:37 -0200 | [diff] [blame] | 518 | } |
Sylwester Nawrocki | 2b13f7d | 2013-03-29 14:12:39 -0300 | [diff] [blame] | 519 | index++; |
| 520 | } |
Sylwester Nawrocki | 49b2f4c5 | 2014-04-15 08:35:25 -0300 | [diff] [blame] | 521 | rpm_put: |
| 522 | pm_runtime_put(fmd->pmf); |
| 523 | return ret; |
Sylwester Nawrocki | 2b13f7d | 2013-03-29 14:12:39 -0300 | [diff] [blame] | 524 | } |
| 525 | |
Sylwester Nawrocki | e2985a2 | 2013-03-08 12:59:33 -0300 | [diff] [blame] | 526 | static int __of_get_csis_id(struct device_node *np) |
| 527 | { |
| 528 | u32 reg = 0; |
| 529 | |
| 530 | np = of_get_child_by_name(np, "port"); |
| 531 | if (!np) |
| 532 | return -EINVAL; |
| 533 | of_property_read_u32(np, "reg", ®); |
| 534 | return reg - FIMC_INPUT_MIPI_CSI2_0; |
| 535 | } |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 536 | |
| 537 | /* |
Sylwester Nawrocki | 7b43a6f | 2012-12-12 08:16:05 -0300 | [diff] [blame] | 538 | * MIPI-CSIS, FIMC and FIMC-LITE platform devices registration. |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 539 | */ |
Sylwester Nawrocki | 7b43a6f | 2012-12-12 08:16:05 -0300 | [diff] [blame] | 540 | static int register_fimc_lite_entity(struct fimc_md *fmd, |
| 541 | struct fimc_lite *fimc_lite) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 542 | { |
Sachin Kamat | 8163ec0 | 2012-10-25 10:56:00 -0300 | [diff] [blame] | 543 | struct v4l2_subdev *sd; |
Sylwester Nawrocki | 403dfbe | 2013-05-31 11:37:22 -0300 | [diff] [blame] | 544 | struct exynos_media_pipeline *ep; |
Sylwester Nawrocki | afd7348 | 2012-10-25 10:48:44 -0300 | [diff] [blame] | 545 | int ret; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 546 | |
Sylwester Nawrocki | 7b43a6f | 2012-12-12 08:16:05 -0300 | [diff] [blame] | 547 | if (WARN_ON(fimc_lite->index >= FIMC_LITE_MAX_DEVS || |
| 548 | fmd->fimc_lite[fimc_lite->index])) |
| 549 | return -EBUSY; |
| 550 | |
| 551 | sd = &fimc_lite->subdev; |
| 552 | sd->grp_id = GRP_ID_FLITE; |
Sylwester Nawrocki | 403dfbe | 2013-05-31 11:37:22 -0300 | [diff] [blame] | 553 | |
| 554 | ep = fimc_md_pipeline_create(fmd); |
| 555 | if (!ep) |
| 556 | return -ENOMEM; |
| 557 | |
| 558 | v4l2_set_subdev_hostdata(sd, ep); |
Sylwester Nawrocki | 7b43a6f | 2012-12-12 08:16:05 -0300 | [diff] [blame] | 559 | |
| 560 | ret = v4l2_device_register_subdev(&fmd->v4l2_dev, sd); |
| 561 | if (!ret) |
| 562 | fmd->fimc_lite[fimc_lite->index] = fimc_lite; |
| 563 | else |
| 564 | v4l2_err(&fmd->v4l2_dev, "Failed to register FIMC.LITE%d\n", |
| 565 | fimc_lite->index); |
| 566 | return ret; |
| 567 | } |
| 568 | |
| 569 | static int register_fimc_entity(struct fimc_md *fmd, struct fimc_dev *fimc) |
| 570 | { |
| 571 | struct v4l2_subdev *sd; |
Sylwester Nawrocki | 403dfbe | 2013-05-31 11:37:22 -0300 | [diff] [blame] | 572 | struct exynos_media_pipeline *ep; |
Sylwester Nawrocki | 7b43a6f | 2012-12-12 08:16:05 -0300 | [diff] [blame] | 573 | int ret; |
| 574 | |
| 575 | if (WARN_ON(fimc->id >= FIMC_MAX_DEVS || fmd->fimc[fimc->id])) |
| 576 | return -EBUSY; |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 577 | |
Sachin Kamat | 8163ec0 | 2012-10-25 10:56:00 -0300 | [diff] [blame] | 578 | sd = &fimc->vid_cap.subdev; |
Sylwester Nawrocki | 588c87b | 2012-11-27 11:57:42 -0300 | [diff] [blame] | 579 | sd->grp_id = GRP_ID_FIMC; |
Sylwester Nawrocki | 403dfbe | 2013-05-31 11:37:22 -0300 | [diff] [blame] | 580 | |
| 581 | ep = fimc_md_pipeline_create(fmd); |
| 582 | if (!ep) |
| 583 | return -ENOMEM; |
| 584 | |
| 585 | v4l2_set_subdev_hostdata(sd, ep); |
Sylwester Nawrocki | 693f5c4 | 2012-04-20 18:57:25 -0300 | [diff] [blame] | 586 | |
| 587 | ret = v4l2_device_register_subdev(&fmd->v4l2_dev, sd); |
Sylwester Nawrocki | 7b43a6f | 2012-12-12 08:16:05 -0300 | [diff] [blame] | 588 | if (!ret) { |
Sylwester Nawrocki | 3e20c34 | 2013-03-21 14:47:17 -0300 | [diff] [blame] | 589 | if (!fmd->pmf && fimc->pdev) |
| 590 | fmd->pmf = &fimc->pdev->dev; |
Sylwester Nawrocki | 7b43a6f | 2012-12-12 08:16:05 -0300 | [diff] [blame] | 591 | fmd->fimc[fimc->id] = fimc; |
| 592 | fimc->vid_cap.user_subdev_api = fmd->user_subdev_api; |
| 593 | } else { |
Sylwester Nawrocki | 693f5c4 | 2012-04-20 18:57:25 -0300 | [diff] [blame] | 594 | v4l2_err(&fmd->v4l2_dev, "Failed to register FIMC.%d (%d)\n", |
| 595 | fimc->id, ret); |
| 596 | } |
Sylwester Nawrocki | 7b43a6f | 2012-12-12 08:16:05 -0300 | [diff] [blame] | 597 | return ret; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 598 | } |
| 599 | |
Sylwester Nawrocki | 7b43a6f | 2012-12-12 08:16:05 -0300 | [diff] [blame] | 600 | static int register_csis_entity(struct fimc_md *fmd, |
| 601 | struct platform_device *pdev, |
| 602 | struct v4l2_subdev *sd) |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 603 | { |
Sylwester Nawrocki | 7b43a6f | 2012-12-12 08:16:05 -0300 | [diff] [blame] | 604 | struct device_node *node = pdev->dev.of_node; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 605 | int id, ret; |
| 606 | |
Sylwester Nawrocki | e2985a2 | 2013-03-08 12:59:33 -0300 | [diff] [blame] | 607 | id = node ? __of_get_csis_id(node) : max(0, pdev->id); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 608 | |
Sylwester Nawrocki | e2985a2 | 2013-03-08 12:59:33 -0300 | [diff] [blame] | 609 | if (WARN_ON(id < 0 || id >= CSIS_MAX_ENTITIES)) |
| 610 | return -ENOENT; |
| 611 | |
| 612 | if (WARN_ON(fmd->csis[id].sd)) |
Sylwester Nawrocki | 7b43a6f | 2012-12-12 08:16:05 -0300 | [diff] [blame] | 613 | return -EBUSY; |
| 614 | |
Sylwester Nawrocki | 588c87b | 2012-11-27 11:57:42 -0300 | [diff] [blame] | 615 | sd->grp_id = GRP_ID_CSIS; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 616 | ret = v4l2_device_register_subdev(&fmd->v4l2_dev, sd); |
Sylwester Nawrocki | afd7348 | 2012-10-25 10:48:44 -0300 | [diff] [blame] | 617 | if (!ret) |
| 618 | fmd->csis[id].sd = sd; |
| 619 | else |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 620 | v4l2_err(&fmd->v4l2_dev, |
Sylwester Nawrocki | 7b43a6f | 2012-12-12 08:16:05 -0300 | [diff] [blame] | 621 | "Failed to register MIPI-CSIS.%d (%d)\n", id, ret); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 622 | return ret; |
| 623 | } |
| 624 | |
Sylwester Nawrocki | e781bbe3 | 2013-03-21 14:49:16 -0300 | [diff] [blame] | 625 | static int register_fimc_is_entity(struct fimc_md *fmd, struct fimc_is *is) |
| 626 | { |
| 627 | struct v4l2_subdev *sd = &is->isp.subdev; |
Sylwester Nawrocki | 34947b8 | 2013-12-20 19:35:06 -0300 | [diff] [blame] | 628 | struct exynos_media_pipeline *ep; |
Sylwester Nawrocki | e781bbe3 | 2013-03-21 14:49:16 -0300 | [diff] [blame] | 629 | int ret; |
| 630 | |
Sylwester Nawrocki | 34947b8 | 2013-12-20 19:35:06 -0300 | [diff] [blame] | 631 | /* Allocate pipeline object for the ISP capture video node. */ |
| 632 | ep = fimc_md_pipeline_create(fmd); |
| 633 | if (!ep) |
| 634 | return -ENOMEM; |
| 635 | |
| 636 | v4l2_set_subdev_hostdata(sd, ep); |
| 637 | |
Sylwester Nawrocki | e781bbe3 | 2013-03-21 14:49:16 -0300 | [diff] [blame] | 638 | ret = v4l2_device_register_subdev(&fmd->v4l2_dev, sd); |
| 639 | if (ret) { |
| 640 | v4l2_err(&fmd->v4l2_dev, |
| 641 | "Failed to register FIMC-ISP (%d)\n", ret); |
| 642 | return ret; |
| 643 | } |
| 644 | |
| 645 | fmd->fimc_is = is; |
| 646 | return 0; |
| 647 | } |
| 648 | |
Sylwester Nawrocki | 7b43a6f | 2012-12-12 08:16:05 -0300 | [diff] [blame] | 649 | static int fimc_md_register_platform_entity(struct fimc_md *fmd, |
| 650 | struct platform_device *pdev, |
| 651 | int plat_entity) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 652 | { |
Sylwester Nawrocki | 7b43a6f | 2012-12-12 08:16:05 -0300 | [diff] [blame] | 653 | struct device *dev = &pdev->dev; |
| 654 | int ret = -EPROBE_DEFER; |
| 655 | void *drvdata; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 656 | |
Sylwester Nawrocki | 7b43a6f | 2012-12-12 08:16:05 -0300 | [diff] [blame] | 657 | /* Lock to ensure dev->driver won't change. */ |
| 658 | device_lock(dev); |
Sylwester Nawrocki | ecd9acb | 2012-03-21 09:58:09 -0300 | [diff] [blame] | 659 | |
Sylwester Nawrocki | 7b43a6f | 2012-12-12 08:16:05 -0300 | [diff] [blame] | 660 | if (!dev->driver || !try_module_get(dev->driver->owner)) |
| 661 | goto dev_unlock; |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 662 | |
Sylwester Nawrocki | 7b43a6f | 2012-12-12 08:16:05 -0300 | [diff] [blame] | 663 | drvdata = dev_get_drvdata(dev); |
Jonathan McCrohan | f58c91c | 2013-10-20 21:34:01 -0300 | [diff] [blame] | 664 | /* Some subdev didn't probe successfully id drvdata is NULL */ |
Sylwester Nawrocki | 7b43a6f | 2012-12-12 08:16:05 -0300 | [diff] [blame] | 665 | if (drvdata) { |
| 666 | switch (plat_entity) { |
| 667 | case IDX_FIMC: |
| 668 | ret = register_fimc_entity(fmd, drvdata); |
Sylwester Nawrocki | ecd9acb | 2012-03-21 09:58:09 -0300 | [diff] [blame] | 669 | break; |
Sylwester Nawrocki | 7b43a6f | 2012-12-12 08:16:05 -0300 | [diff] [blame] | 670 | case IDX_FLITE: |
| 671 | ret = register_fimc_lite_entity(fmd, drvdata); |
| 672 | break; |
| 673 | case IDX_CSIS: |
| 674 | ret = register_csis_entity(fmd, pdev, drvdata); |
| 675 | break; |
Sylwester Nawrocki | e781bbe3 | 2013-03-21 14:49:16 -0300 | [diff] [blame] | 676 | case IDX_IS_ISP: |
| 677 | ret = register_fimc_is_entity(fmd, drvdata); |
| 678 | break; |
Sylwester Nawrocki | 7b43a6f | 2012-12-12 08:16:05 -0300 | [diff] [blame] | 679 | default: |
| 680 | ret = -ENODEV; |
Sylwester Nawrocki | ecd9acb | 2012-03-21 09:58:09 -0300 | [diff] [blame] | 681 | } |
| 682 | } |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 683 | |
Sylwester Nawrocki | 7b43a6f | 2012-12-12 08:16:05 -0300 | [diff] [blame] | 684 | module_put(dev->driver->owner); |
| 685 | dev_unlock: |
| 686 | device_unlock(dev); |
| 687 | if (ret == -EPROBE_DEFER) |
| 688 | dev_info(&fmd->pdev->dev, "deferring %s device registration\n", |
| 689 | dev_name(dev)); |
| 690 | else if (ret < 0) |
| 691 | dev_err(&fmd->pdev->dev, "%s device registration failed (%d)\n", |
| 692 | dev_name(dev), ret); |
| 693 | return ret; |
| 694 | } |
| 695 | |
Sylwester Nawrocki | e2985a2 | 2013-03-08 12:59:33 -0300 | [diff] [blame] | 696 | /* Register FIMC, FIMC-LITE and CSIS media entities */ |
Sylwester Nawrocki | 49b2f4c5 | 2014-04-15 08:35:25 -0300 | [diff] [blame] | 697 | static int fimc_md_register_platform_entities(struct fimc_md *fmd, |
| 698 | struct device_node *parent) |
Sylwester Nawrocki | e2985a2 | 2013-03-08 12:59:33 -0300 | [diff] [blame] | 699 | { |
| 700 | struct device_node *node; |
| 701 | int ret = 0; |
| 702 | |
| 703 | for_each_available_child_of_node(parent, node) { |
| 704 | struct platform_device *pdev; |
| 705 | int plat_entity = -1; |
| 706 | |
| 707 | pdev = of_find_device_by_node(node); |
| 708 | if (!pdev) |
| 709 | continue; |
| 710 | |
| 711 | /* If driver of any entity isn't ready try all again later. */ |
| 712 | if (!strcmp(node->name, CSIS_OF_NODE_NAME)) |
| 713 | plat_entity = IDX_CSIS; |
Sylwester Nawrocki | e781bbe3 | 2013-03-21 14:49:16 -0300 | [diff] [blame] | 714 | else if (!strcmp(node->name, FIMC_IS_OF_NODE_NAME)) |
| 715 | plat_entity = IDX_IS_ISP; |
Sylwester Nawrocki | e2985a2 | 2013-03-08 12:59:33 -0300 | [diff] [blame] | 716 | else if (!strcmp(node->name, FIMC_LITE_OF_NODE_NAME)) |
| 717 | plat_entity = IDX_FLITE; |
| 718 | else if (!strcmp(node->name, FIMC_OF_NODE_NAME) && |
| 719 | !of_property_read_bool(node, "samsung,lcd-wb")) |
| 720 | plat_entity = IDX_FIMC; |
| 721 | |
| 722 | if (plat_entity >= 0) |
| 723 | ret = fimc_md_register_platform_entity(fmd, pdev, |
| 724 | plat_entity); |
| 725 | put_device(&pdev->dev); |
Amitoj Kaur Chawla | 458a395 | 2016-01-25 13:21:37 -0200 | [diff] [blame] | 726 | if (ret < 0) { |
| 727 | of_node_put(node); |
Sylwester Nawrocki | e2985a2 | 2013-03-08 12:59:33 -0300 | [diff] [blame] | 728 | break; |
Amitoj Kaur Chawla | 458a395 | 2016-01-25 13:21:37 -0200 | [diff] [blame] | 729 | } |
Sylwester Nawrocki | e2985a2 | 2013-03-08 12:59:33 -0300 | [diff] [blame] | 730 | } |
| 731 | |
| 732 | return ret; |
| 733 | } |
Sylwester Nawrocki | e2985a2 | 2013-03-08 12:59:33 -0300 | [diff] [blame] | 734 | |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 735 | static void fimc_md_unregister_entities(struct fimc_md *fmd) |
| 736 | { |
| 737 | int i; |
| 738 | |
| 739 | for (i = 0; i < FIMC_MAX_DEVS; i++) { |
Sylwester Nawrocki | 403dfbe | 2013-05-31 11:37:22 -0300 | [diff] [blame] | 740 | struct fimc_dev *dev = fmd->fimc[i]; |
| 741 | if (dev == NULL) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 742 | continue; |
Sylwester Nawrocki | 403dfbe | 2013-05-31 11:37:22 -0300 | [diff] [blame] | 743 | v4l2_device_unregister_subdev(&dev->vid_cap.subdev); |
| 744 | dev->vid_cap.ve.pipe = NULL; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 745 | fmd->fimc[i] = NULL; |
| 746 | } |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 747 | for (i = 0; i < FIMC_LITE_MAX_DEVS; i++) { |
Sylwester Nawrocki | 403dfbe | 2013-05-31 11:37:22 -0300 | [diff] [blame] | 748 | struct fimc_lite *dev = fmd->fimc_lite[i]; |
| 749 | if (dev == NULL) |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 750 | continue; |
Sylwester Nawrocki | 403dfbe | 2013-05-31 11:37:22 -0300 | [diff] [blame] | 751 | v4l2_device_unregister_subdev(&dev->subdev); |
| 752 | dev->ve.pipe = NULL; |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 753 | fmd->fimc_lite[i] = NULL; |
| 754 | } |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 755 | for (i = 0; i < CSIS_MAX_ENTITIES; i++) { |
| 756 | if (fmd->csis[i].sd == NULL) |
| 757 | continue; |
| 758 | v4l2_device_unregister_subdev(fmd->csis[i].sd); |
| 759 | fmd->csis[i].sd = NULL; |
| 760 | } |
Sylwester Nawrocki | e41a35c | 2013-04-18 09:05:54 -0300 | [diff] [blame] | 761 | |
| 762 | if (fmd->fimc_is) |
| 763 | v4l2_device_unregister_subdev(&fmd->fimc_is->isp.subdev); |
| 764 | |
Sylwester Nawrocki | 7b43a6f | 2012-12-12 08:16:05 -0300 | [diff] [blame] | 765 | v4l2_info(&fmd->v4l2_dev, "Unregistered all entities\n"); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 766 | } |
| 767 | |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 768 | /** |
| 769 | * __fimc_md_create_fimc_links - create links to all FIMC entities |
| 770 | * @fmd: fimc media device |
| 771 | * @source: the source entity to create links to all fimc entities from |
| 772 | * @sensor: sensor subdev linked to FIMC[fimc_id] entity, may be null |
| 773 | * @pad: the source entity pad index |
Sylwester Nawrocki | d0da3c3 | 2012-05-16 13:08:30 -0300 | [diff] [blame] | 774 | * @link_mask: bitmask of the fimc devices for which link should be enabled |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 775 | */ |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 776 | static int __fimc_md_create_fimc_sink_links(struct fimc_md *fmd, |
| 777 | struct media_entity *source, |
| 778 | struct v4l2_subdev *sensor, |
Sylwester Nawrocki | d0da3c3 | 2012-05-16 13:08:30 -0300 | [diff] [blame] | 779 | int pad, int link_mask) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 780 | { |
Sylwester Nawrocki | 4c8f062 | 2013-04-09 11:11:58 -0300 | [diff] [blame] | 781 | struct fimc_source_info *si = NULL; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 782 | struct media_entity *sink; |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 783 | unsigned int flags = 0; |
Sylwester Nawrocki | f998bb7 | 2012-11-27 13:29:48 -0300 | [diff] [blame] | 784 | int i, ret = 0; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 785 | |
Sylwester Nawrocki | f998bb7 | 2012-11-27 13:29:48 -0300 | [diff] [blame] | 786 | if (sensor) { |
| 787 | si = v4l2_get_subdev_hostdata(sensor); |
| 788 | /* Skip direct FIMC links in the logical FIMC-IS sensor path */ |
Sylwester Nawrocki | 4c8f062 | 2013-04-09 11:11:58 -0300 | [diff] [blame] | 789 | if (si && si->fimc_bus_type == FIMC_BUS_TYPE_ISP_WRITEBACK) |
Sylwester Nawrocki | f998bb7 | 2012-11-27 13:29:48 -0300 | [diff] [blame] | 790 | ret = 1; |
| 791 | } |
| 792 | |
| 793 | for (i = 0; !ret && i < FIMC_MAX_DEVS; i++) { |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 794 | if (!fmd->fimc[i]) |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 795 | continue; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 796 | /* |
| 797 | * Some FIMC variants are not fitted with camera capture |
| 798 | * interface. Skip creating a link from sensor for those. |
| 799 | */ |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 800 | if (!fmd->fimc[i]->variant->has_cam_if) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 801 | continue; |
| 802 | |
Sylwester Nawrocki | d0da3c3 | 2012-05-16 13:08:30 -0300 | [diff] [blame] | 803 | flags = ((1 << i) & link_mask) ? MEDIA_LNK_FL_ENABLED : 0; |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 804 | |
Sylwester Nawrocki | 693f5c4 | 2012-04-20 18:57:25 -0300 | [diff] [blame] | 805 | sink = &fmd->fimc[i]->vid_cap.subdev.entity; |
Mauro Carvalho Chehab | 8df00a1 | 2015-08-07 08:14:38 -0300 | [diff] [blame] | 806 | ret = media_create_pad_link(source, pad, sink, |
Sylwester Nawrocki | 88fa831 | 2013-03-20 10:44:39 -0300 | [diff] [blame] | 807 | FIMC_SD_PAD_SINK_CAM, flags); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 808 | if (ret) |
| 809 | return ret; |
| 810 | |
Sylwester Nawrocki | 237e026 | 2011-08-24 20:35:30 -0300 | [diff] [blame] | 811 | /* Notify FIMC capture subdev entity */ |
| 812 | ret = media_entity_call(sink, link_setup, &sink->pads[0], |
| 813 | &source->pads[pad], flags); |
| 814 | if (ret) |
| 815 | break; |
| 816 | |
Sylwester Nawrocki | 542fb08 | 2012-10-25 05:48:19 -0300 | [diff] [blame] | 817 | v4l2_info(&fmd->v4l2_dev, "created link [%s] %c> [%s]\n", |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 818 | source->name, flags ? '=' : '-', sink->name); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 819 | } |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 820 | |
| 821 | for (i = 0; i < FIMC_LITE_MAX_DEVS; i++) { |
| 822 | if (!fmd->fimc_lite[i]) |
| 823 | continue; |
| 824 | |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 825 | sink = &fmd->fimc_lite[i]->subdev.entity; |
Mauro Carvalho Chehab | 8df00a1 | 2015-08-07 08:14:38 -0300 | [diff] [blame] | 826 | ret = media_create_pad_link(source, pad, sink, |
Sylwester Nawrocki | f998bb7 | 2012-11-27 13:29:48 -0300 | [diff] [blame] | 827 | FLITE_SD_PAD_SINK, 0); |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 828 | if (ret) |
| 829 | return ret; |
| 830 | |
| 831 | /* Notify FIMC-LITE subdev entity */ |
| 832 | ret = media_entity_call(sink, link_setup, &sink->pads[0], |
Sylwester Nawrocki | f998bb7 | 2012-11-27 13:29:48 -0300 | [diff] [blame] | 833 | &source->pads[pad], 0); |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 834 | if (ret) |
| 835 | break; |
| 836 | |
Sylwester Nawrocki | f998bb7 | 2012-11-27 13:29:48 -0300 | [diff] [blame] | 837 | v4l2_info(&fmd->v4l2_dev, "created link [%s] -> [%s]\n", |
| 838 | source->name, sink->name); |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 839 | } |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 840 | return 0; |
| 841 | } |
| 842 | |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 843 | /* Create links from FIMC-LITE source pads to other entities */ |
| 844 | static int __fimc_md_create_flite_source_links(struct fimc_md *fmd) |
| 845 | { |
| 846 | struct media_entity *source, *sink; |
Sylwester Nawrocki | a26860b | 2012-12-05 13:43:05 -0300 | [diff] [blame] | 847 | int i, ret = 0; |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 848 | |
| 849 | for (i = 0; i < FIMC_LITE_MAX_DEVS; i++) { |
| 850 | struct fimc_lite *fimc = fmd->fimc_lite[i]; |
Sylwester Nawrocki | f998bb7 | 2012-11-27 13:29:48 -0300 | [diff] [blame] | 851 | |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 852 | if (fimc == NULL) |
| 853 | continue; |
Sylwester Nawrocki | f998bb7 | 2012-11-27 13:29:48 -0300 | [diff] [blame] | 854 | |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 855 | source = &fimc->subdev.entity; |
Sylwester Nawrocki | bc7584b | 2013-05-31 11:37:18 -0300 | [diff] [blame] | 856 | sink = &fimc->ve.vdev.entity; |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 857 | /* FIMC-LITE's subdev and video node */ |
Mauro Carvalho Chehab | 8df00a1 | 2015-08-07 08:14:38 -0300 | [diff] [blame] | 858 | ret = media_create_pad_link(source, FLITE_SD_PAD_SOURCE_DMA, |
Sylwester Nawrocki | f998bb7 | 2012-11-27 13:29:48 -0300 | [diff] [blame] | 859 | sink, 0, 0); |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 860 | if (ret) |
| 861 | break; |
Sylwester Nawrocki | f998bb7 | 2012-11-27 13:29:48 -0300 | [diff] [blame] | 862 | /* Link from FIMC-LITE to IS-ISP subdev */ |
| 863 | sink = &fmd->fimc_is->isp.subdev.entity; |
Mauro Carvalho Chehab | 8df00a1 | 2015-08-07 08:14:38 -0300 | [diff] [blame] | 864 | ret = media_create_pad_link(source, FLITE_SD_PAD_SOURCE_ISP, |
Sylwester Nawrocki | f998bb7 | 2012-11-27 13:29:48 -0300 | [diff] [blame] | 865 | sink, 0, 0); |
| 866 | if (ret) |
| 867 | break; |
| 868 | } |
| 869 | |
| 870 | return ret; |
| 871 | } |
| 872 | |
| 873 | /* Create FIMC-IS links */ |
| 874 | static int __fimc_md_create_fimc_is_links(struct fimc_md *fmd) |
| 875 | { |
Sylwester Nawrocki | 34947b8 | 2013-12-20 19:35:06 -0300 | [diff] [blame] | 876 | struct fimc_isp *isp = &fmd->fimc_is->isp; |
Sylwester Nawrocki | f998bb7 | 2012-11-27 13:29:48 -0300 | [diff] [blame] | 877 | struct media_entity *source, *sink; |
| 878 | int i, ret; |
| 879 | |
Sylwester Nawrocki | 34947b8 | 2013-12-20 19:35:06 -0300 | [diff] [blame] | 880 | source = &isp->subdev.entity; |
Sylwester Nawrocki | f998bb7 | 2012-11-27 13:29:48 -0300 | [diff] [blame] | 881 | |
| 882 | for (i = 0; i < FIMC_MAX_DEVS; i++) { |
| 883 | if (fmd->fimc[i] == NULL) |
| 884 | continue; |
| 885 | |
Sylwester Nawrocki | 34947b8 | 2013-12-20 19:35:06 -0300 | [diff] [blame] | 886 | /* Link from FIMC-IS-ISP subdev to FIMC */ |
Sylwester Nawrocki | f998bb7 | 2012-11-27 13:29:48 -0300 | [diff] [blame] | 887 | sink = &fmd->fimc[i]->vid_cap.subdev.entity; |
Mauro Carvalho Chehab | 8df00a1 | 2015-08-07 08:14:38 -0300 | [diff] [blame] | 888 | ret = media_create_pad_link(source, FIMC_ISP_SD_PAD_SRC_FIFO, |
Sylwester Nawrocki | f998bb7 | 2012-11-27 13:29:48 -0300 | [diff] [blame] | 889 | sink, FIMC_SD_PAD_SINK_FIFO, 0); |
| 890 | if (ret) |
| 891 | return ret; |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 892 | } |
| 893 | |
Sylwester Nawrocki | 34947b8 | 2013-12-20 19:35:06 -0300 | [diff] [blame] | 894 | /* Link from FIMC-IS-ISP subdev to fimc-is-isp.capture video node */ |
| 895 | sink = &isp->video_capture.ve.vdev.entity; |
| 896 | |
| 897 | /* Skip this link if the fimc-is-isp video node driver isn't built-in */ |
| 898 | if (sink->num_pads == 0) |
| 899 | return 0; |
| 900 | |
Mauro Carvalho Chehab | 8df00a1 | 2015-08-07 08:14:38 -0300 | [diff] [blame] | 901 | return media_create_pad_link(source, FIMC_ISP_SD_PAD_SRC_DMA, |
Sylwester Nawrocki | 34947b8 | 2013-12-20 19:35:06 -0300 | [diff] [blame] | 902 | sink, 0, 0); |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 903 | } |
| 904 | |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 905 | /** |
| 906 | * fimc_md_create_links - create default links between registered entities |
Mauro Carvalho Chehab | 3b060ba0 | 2017-11-29 04:32:51 -0500 | [diff] [blame] | 907 | * @fmd: fimc media device |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 908 | * |
| 909 | * Parallel interface sensor entities are connected directly to FIMC capture |
| 910 | * entities. The sensors using MIPI CSIS bus are connected through immutable |
| 911 | * link with CSI receiver entity specified by mux_id. Any registered CSIS |
| 912 | * entity has a link to each registered FIMC capture entity. Enabled links |
| 913 | * are created by default between each subsequent registered sensor and |
| 914 | * subsequent FIMC capture entity. The number of default active links is |
| 915 | * determined by the number of available sensors or FIMC entities, |
| 916 | * whichever is less. |
| 917 | */ |
| 918 | static int fimc_md_create_links(struct fimc_md *fmd) |
| 919 | { |
Sylwester Nawrocki | a8697ec | 2012-12-05 13:40:04 -0300 | [diff] [blame] | 920 | struct v4l2_subdev *csi_sensors[CSIS_MAX_ENTITIES] = { NULL }; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 921 | struct v4l2_subdev *sensor, *csis; |
Sylwester Nawrocki | 56bc911 | 2013-02-01 15:00:40 -0300 | [diff] [blame] | 922 | struct fimc_source_info *pdata; |
Sylwester Nawrocki | 237e026 | 2011-08-24 20:35:30 -0300 | [diff] [blame] | 923 | struct media_entity *source, *sink; |
Sylwester Nawrocki | d0da3c3 | 2012-05-16 13:08:30 -0300 | [diff] [blame] | 924 | int i, pad, fimc_id = 0, ret = 0; |
| 925 | u32 flags, link_mask = 0; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 926 | |
| 927 | for (i = 0; i < fmd->num_sensors; i++) { |
| 928 | if (fmd->sensor[i].subdev == NULL) |
| 929 | continue; |
| 930 | |
| 931 | sensor = fmd->sensor[i].subdev; |
Sylwester Nawrocki | 4c8f062 | 2013-04-09 11:11:58 -0300 | [diff] [blame] | 932 | pdata = v4l2_get_subdev_hostdata(sensor); |
| 933 | if (!pdata) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 934 | continue; |
| 935 | |
| 936 | source = NULL; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 937 | |
Sylwester Nawrocki | 56bc911 | 2013-02-01 15:00:40 -0300 | [diff] [blame] | 938 | switch (pdata->sensor_bus_type) { |
| 939 | case FIMC_BUS_TYPE_MIPI_CSI2: |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 940 | if (WARN(pdata->mux_id >= CSIS_MAX_ENTITIES, |
| 941 | "Wrong CSI channel id: %d\n", pdata->mux_id)) |
| 942 | return -EINVAL; |
| 943 | |
| 944 | csis = fmd->csis[pdata->mux_id].sd; |
| 945 | if (WARN(csis == NULL, |
Mauro Carvalho Chehab | 57425dc | 2016-10-18 17:44:09 -0200 | [diff] [blame] | 946 | "MIPI-CSI interface specified but s5p-csis module is not loaded!\n")) |
Sylwester Nawrocki | d12392e | 2011-10-20 05:15:59 -0300 | [diff] [blame] | 947 | return -EINVAL; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 948 | |
Andrzej Hajda | 1c9f5bd | 2012-11-22 12:13:27 -0300 | [diff] [blame] | 949 | pad = sensor->entity.num_pads - 1; |
Mauro Carvalho Chehab | 8df00a1 | 2015-08-07 08:14:38 -0300 | [diff] [blame] | 950 | ret = media_create_pad_link(&sensor->entity, pad, |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 951 | &csis->entity, CSIS_PAD_SINK, |
| 952 | MEDIA_LNK_FL_IMMUTABLE | |
| 953 | MEDIA_LNK_FL_ENABLED); |
| 954 | if (ret) |
| 955 | return ret; |
| 956 | |
Sylwester Nawrocki | 969e877 | 2012-12-07 16:40:08 -0300 | [diff] [blame] | 957 | v4l2_info(&fmd->v4l2_dev, "created link [%s] => [%s]\n", |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 958 | sensor->entity.name, csis->entity.name); |
| 959 | |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 960 | source = NULL; |
Sylwester Nawrocki | 5d33ee9 | 2012-08-16 14:06:41 -0300 | [diff] [blame] | 961 | csi_sensors[pdata->mux_id] = sensor; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 962 | break; |
| 963 | |
Sylwester Nawrocki | 56bc911 | 2013-02-01 15:00:40 -0300 | [diff] [blame] | 964 | case FIMC_BUS_TYPE_ITU_601...FIMC_BUS_TYPE_ITU_656: |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 965 | source = &sensor->entity; |
| 966 | pad = 0; |
| 967 | break; |
| 968 | |
| 969 | default: |
| 970 | v4l2_err(&fmd->v4l2_dev, "Wrong bus_type: %x\n", |
Sylwester Nawrocki | 56bc911 | 2013-02-01 15:00:40 -0300 | [diff] [blame] | 971 | pdata->sensor_bus_type); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 972 | return -EINVAL; |
| 973 | } |
| 974 | if (source == NULL) |
| 975 | continue; |
| 976 | |
Sylwester Nawrocki | d0da3c3 | 2012-05-16 13:08:30 -0300 | [diff] [blame] | 977 | link_mask = 1 << fimc_id++; |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 978 | ret = __fimc_md_create_fimc_sink_links(fmd, source, sensor, |
Sylwester Nawrocki | d0da3c3 | 2012-05-16 13:08:30 -0300 | [diff] [blame] | 979 | pad, link_mask); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 980 | } |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 981 | |
Sylwester Nawrocki | a8697ec | 2012-12-05 13:40:04 -0300 | [diff] [blame] | 982 | for (i = 0; i < CSIS_MAX_ENTITIES; i++) { |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 983 | if (fmd->csis[i].sd == NULL) |
| 984 | continue; |
Sylwester Nawrocki | f998bb7 | 2012-11-27 13:29:48 -0300 | [diff] [blame] | 985 | |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 986 | source = &fmd->csis[i].sd->entity; |
| 987 | pad = CSIS_PAD_SOURCE; |
Sylwester Nawrocki | 5d33ee9 | 2012-08-16 14:06:41 -0300 | [diff] [blame] | 988 | sensor = csi_sensors[i]; |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 989 | |
Sylwester Nawrocki | d0da3c3 | 2012-05-16 13:08:30 -0300 | [diff] [blame] | 990 | link_mask = 1 << fimc_id++; |
Sylwester Nawrocki | 5d33ee9 | 2012-08-16 14:06:41 -0300 | [diff] [blame] | 991 | ret = __fimc_md_create_fimc_sink_links(fmd, source, sensor, |
Sylwester Nawrocki | d0da3c3 | 2012-05-16 13:08:30 -0300 | [diff] [blame] | 992 | pad, link_mask); |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 993 | } |
| 994 | |
Sylwester Nawrocki | 237e026 | 2011-08-24 20:35:30 -0300 | [diff] [blame] | 995 | /* Create immutable links between each FIMC's subdev and video node */ |
| 996 | flags = MEDIA_LNK_FL_IMMUTABLE | MEDIA_LNK_FL_ENABLED; |
| 997 | for (i = 0; i < FIMC_MAX_DEVS; i++) { |
| 998 | if (!fmd->fimc[i]) |
| 999 | continue; |
Sylwester Nawrocki | f998bb7 | 2012-11-27 13:29:48 -0300 | [diff] [blame] | 1000 | |
Sylwester Nawrocki | 693f5c4 | 2012-04-20 18:57:25 -0300 | [diff] [blame] | 1001 | source = &fmd->fimc[i]->vid_cap.subdev.entity; |
Sylwester Nawrocki | bc7584b | 2013-05-31 11:37:18 -0300 | [diff] [blame] | 1002 | sink = &fmd->fimc[i]->vid_cap.ve.vdev.entity; |
Sylwester Nawrocki | f998bb7 | 2012-11-27 13:29:48 -0300 | [diff] [blame] | 1003 | |
Mauro Carvalho Chehab | 8df00a1 | 2015-08-07 08:14:38 -0300 | [diff] [blame] | 1004 | ret = media_create_pad_link(source, FIMC_SD_PAD_SOURCE, |
Sylwester Nawrocki | 237e026 | 2011-08-24 20:35:30 -0300 | [diff] [blame] | 1005 | sink, 0, flags); |
| 1006 | if (ret) |
| 1007 | break; |
| 1008 | } |
| 1009 | |
Sylwester Nawrocki | f998bb7 | 2012-11-27 13:29:48 -0300 | [diff] [blame] | 1010 | ret = __fimc_md_create_flite_source_links(fmd); |
| 1011 | if (ret < 0) |
| 1012 | return ret; |
| 1013 | |
| 1014 | if (fmd->use_isp) |
| 1015 | ret = __fimc_md_create_fimc_is_links(fmd); |
| 1016 | |
| 1017 | return ret; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1018 | } |
| 1019 | |
| 1020 | /* |
Sylwester Nawrocki | 056f4f3 | 2013-03-21 14:43:17 -0300 | [diff] [blame] | 1021 | * The peripheral sensor and CAM_BLK (PIXELASYNCMx) clocks management. |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1022 | */ |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1023 | static void fimc_md_put_clocks(struct fimc_md *fmd) |
| 1024 | { |
| 1025 | int i = FIMC_MAX_CAMCLKS; |
| 1026 | |
| 1027 | while (--i >= 0) { |
Sylwester Nawrocki | 0e23cbb | 2013-01-18 15:34:37 -0300 | [diff] [blame] | 1028 | if (IS_ERR(fmd->camclk[i].clock)) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1029 | continue; |
| 1030 | clk_put(fmd->camclk[i].clock); |
Sylwester Nawrocki | 0e23cbb | 2013-01-18 15:34:37 -0300 | [diff] [blame] | 1031 | fmd->camclk[i].clock = ERR_PTR(-EINVAL); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1032 | } |
Sylwester Nawrocki | 056f4f3 | 2013-03-21 14:43:17 -0300 | [diff] [blame] | 1033 | |
| 1034 | /* Writeback (PIXELASYNCMx) clocks */ |
| 1035 | for (i = 0; i < FIMC_MAX_WBCLKS; i++) { |
| 1036 | if (IS_ERR(fmd->wbclk[i])) |
| 1037 | continue; |
| 1038 | clk_put(fmd->wbclk[i]); |
| 1039 | fmd->wbclk[i] = ERR_PTR(-EINVAL); |
| 1040 | } |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1041 | } |
| 1042 | |
Sylwester Nawrocki | 0e23cbb | 2013-01-18 15:34:37 -0300 | [diff] [blame] | 1043 | static int fimc_md_get_clocks(struct fimc_md *fmd) |
| 1044 | { |
Sylwester Nawrocki | 49b2f4c5 | 2014-04-15 08:35:25 -0300 | [diff] [blame] | 1045 | struct device *dev = &fmd->pdev->dev; |
Sylwester Nawrocki | 0e23cbb | 2013-01-18 15:34:37 -0300 | [diff] [blame] | 1046 | char clk_name[32]; |
| 1047 | struct clk *clock; |
Sylwester Nawrocki | 044c372 | 2013-07-19 10:05:17 -0300 | [diff] [blame] | 1048 | int i, ret = 0; |
Sylwester Nawrocki | 0e23cbb | 2013-01-18 15:34:37 -0300 | [diff] [blame] | 1049 | |
| 1050 | for (i = 0; i < FIMC_MAX_CAMCLKS; i++) |
| 1051 | fmd->camclk[i].clock = ERR_PTR(-EINVAL); |
| 1052 | |
Sylwester Nawrocki | 0e23cbb | 2013-01-18 15:34:37 -0300 | [diff] [blame] | 1053 | for (i = 0; i < FIMC_MAX_CAMCLKS; i++) { |
| 1054 | snprintf(clk_name, sizeof(clk_name), "sclk_cam%u", i); |
| 1055 | clock = clk_get(dev, clk_name); |
| 1056 | |
| 1057 | if (IS_ERR(clock)) { |
Sylwester Nawrocki | 49b2f4c5 | 2014-04-15 08:35:25 -0300 | [diff] [blame] | 1058 | dev_err(dev, "Failed to get clock: %s\n", clk_name); |
Sylwester Nawrocki | 0e23cbb | 2013-01-18 15:34:37 -0300 | [diff] [blame] | 1059 | ret = PTR_ERR(clock); |
| 1060 | break; |
| 1061 | } |
Sylwester Nawrocki | 0e23cbb | 2013-01-18 15:34:37 -0300 | [diff] [blame] | 1062 | fmd->camclk[i].clock = clock; |
| 1063 | } |
| 1064 | if (ret) |
| 1065 | fimc_md_put_clocks(fmd); |
| 1066 | |
Sylwester Nawrocki | 056f4f3 | 2013-03-21 14:43:17 -0300 | [diff] [blame] | 1067 | if (!fmd->use_isp) |
| 1068 | return 0; |
| 1069 | /* |
| 1070 | * For now get only PIXELASYNCM1 clock (Writeback B/ISP), |
| 1071 | * leave PIXELASYNCM0 out for the LCD Writeback driver. |
| 1072 | */ |
| 1073 | fmd->wbclk[CLK_IDX_WB_A] = ERR_PTR(-EINVAL); |
| 1074 | |
| 1075 | for (i = CLK_IDX_WB_B; i < FIMC_MAX_WBCLKS; i++) { |
| 1076 | snprintf(clk_name, sizeof(clk_name), "pxl_async%u", i); |
| 1077 | clock = clk_get(dev, clk_name); |
| 1078 | if (IS_ERR(clock)) { |
| 1079 | v4l2_err(&fmd->v4l2_dev, "Failed to get clock: %s\n", |
| 1080 | clk_name); |
| 1081 | ret = PTR_ERR(clock); |
| 1082 | break; |
| 1083 | } |
| 1084 | fmd->wbclk[i] = clock; |
| 1085 | } |
| 1086 | if (ret) |
| 1087 | fimc_md_put_clocks(fmd); |
| 1088 | |
Sylwester Nawrocki | 0e23cbb | 2013-01-18 15:34:37 -0300 | [diff] [blame] | 1089 | return ret; |
| 1090 | } |
| 1091 | |
Sylwester Nawrocki | d3775fa | 2013-05-31 10:37:27 -0300 | [diff] [blame] | 1092 | static int __fimc_md_modify_pipeline(struct media_entity *entity, bool enable) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1093 | { |
Sylwester Nawrocki | 403dfbe | 2013-05-31 11:37:22 -0300 | [diff] [blame] | 1094 | struct exynos_video_entity *ve; |
Sylwester Nawrocki | d3775fa | 2013-05-31 10:37:27 -0300 | [diff] [blame] | 1095 | struct fimc_pipeline *p; |
Sylwester Nawrocki | 403dfbe | 2013-05-31 11:37:22 -0300 | [diff] [blame] | 1096 | struct video_device *vdev; |
Sylwester Nawrocki | d3775fa | 2013-05-31 10:37:27 -0300 | [diff] [blame] | 1097 | int ret; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1098 | |
Sylwester Nawrocki | d3775fa | 2013-05-31 10:37:27 -0300 | [diff] [blame] | 1099 | vdev = media_entity_to_video_device(entity); |
| 1100 | if (vdev->entity.use_count == 0) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1101 | return 0; |
| 1102 | |
Sylwester Nawrocki | 403dfbe | 2013-05-31 11:37:22 -0300 | [diff] [blame] | 1103 | ve = vdev_to_exynos_video_entity(vdev); |
Sylwester Nawrocki | d3775fa | 2013-05-31 10:37:27 -0300 | [diff] [blame] | 1104 | p = to_fimc_pipeline(ve->pipe); |
| 1105 | /* |
| 1106 | * Nothing to do if we are disabling the pipeline, some link |
| 1107 | * has been disconnected and p->subdevs array is cleared now. |
| 1108 | */ |
| 1109 | if (!enable && p->subdevs[IDX_SENSOR] == NULL) |
| 1110 | return 0; |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 1111 | |
Sylwester Nawrocki | d3775fa | 2013-05-31 10:37:27 -0300 | [diff] [blame] | 1112 | if (enable) |
| 1113 | ret = __fimc_pipeline_open(ve->pipe, entity, true); |
| 1114 | else |
| 1115 | ret = __fimc_pipeline_close(ve->pipe); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1116 | |
Sylwester Nawrocki | d3775fa | 2013-05-31 10:37:27 -0300 | [diff] [blame] | 1117 | if (ret == 0 && !enable) |
| 1118 | memset(p->subdevs, 0, sizeof(p->subdevs)); |
| 1119 | |
| 1120 | return ret; |
| 1121 | } |
| 1122 | |
Javier Martinez Canillas | d10c989 | 2015-08-19 12:35:21 -0300 | [diff] [blame] | 1123 | /* Locking: called with entity->graph_obj.mdev->graph_mutex mutex held. */ |
Sakari Ailus | fd7e530 | 2015-12-16 15:32:25 +0200 | [diff] [blame] | 1124 | static int __fimc_md_modify_pipelines(struct media_entity *entity, bool enable, |
Sakari Ailus | 20b8522 | 2016-11-21 14:48:30 -0200 | [diff] [blame] | 1125 | struct media_graph *graph) |
Sylwester Nawrocki | d3775fa | 2013-05-31 10:37:27 -0300 | [diff] [blame] | 1126 | { |
| 1127 | struct media_entity *entity_err = entity; |
Sylwester Nawrocki | d3775fa | 2013-05-31 10:37:27 -0300 | [diff] [blame] | 1128 | int ret; |
| 1129 | |
| 1130 | /* |
| 1131 | * Walk current graph and call the pipeline open/close routine for each |
| 1132 | * opened video node that belongs to the graph of entities connected |
| 1133 | * through active links. This is needed as we cannot power on/off the |
| 1134 | * subdevs in random order. |
| 1135 | */ |
Sakari Ailus | 20b8522 | 2016-11-21 14:48:30 -0200 | [diff] [blame] | 1136 | media_graph_walk_start(graph, entity); |
Sylwester Nawrocki | d3775fa | 2013-05-31 10:37:27 -0300 | [diff] [blame] | 1137 | |
Sakari Ailus | 20b8522 | 2016-11-21 14:48:30 -0200 | [diff] [blame] | 1138 | while ((entity = media_graph_walk_next(graph))) { |
Laurent Pinchart | 45b4687 | 2016-02-29 08:45:45 -0300 | [diff] [blame] | 1139 | if (!is_media_entity_v4l2_video_device(entity)) |
Sylwester Nawrocki | d3775fa | 2013-05-31 10:37:27 -0300 | [diff] [blame] | 1140 | continue; |
| 1141 | |
| 1142 | ret = __fimc_md_modify_pipeline(entity, enable); |
| 1143 | |
| 1144 | if (ret < 0) |
| 1145 | goto err; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1146 | } |
Sylwester Nawrocki | 740ad92 | 2012-12-06 10:26:19 -0300 | [diff] [blame] | 1147 | |
Sylwester Nawrocki | d3775fa | 2013-05-31 10:37:27 -0300 | [diff] [blame] | 1148 | return 0; |
Sylwester Nawrocki | d3775fa | 2013-05-31 10:37:27 -0300 | [diff] [blame] | 1149 | |
Sakari Ailus | fd7e530 | 2015-12-16 15:32:25 +0200 | [diff] [blame] | 1150 | err: |
Sakari Ailus | 20b8522 | 2016-11-21 14:48:30 -0200 | [diff] [blame] | 1151 | media_graph_walk_start(graph, entity_err); |
Sakari Ailus | fd7e530 | 2015-12-16 15:32:25 +0200 | [diff] [blame] | 1152 | |
Sakari Ailus | 20b8522 | 2016-11-21 14:48:30 -0200 | [diff] [blame] | 1153 | while ((entity_err = media_graph_walk_next(graph))) { |
Laurent Pinchart | 45b4687 | 2016-02-29 08:45:45 -0300 | [diff] [blame] | 1154 | if (!is_media_entity_v4l2_video_device(entity_err)) |
Sylwester Nawrocki | d3775fa | 2013-05-31 10:37:27 -0300 | [diff] [blame] | 1155 | continue; |
| 1156 | |
| 1157 | __fimc_md_modify_pipeline(entity_err, !enable); |
| 1158 | |
| 1159 | if (entity_err == entity) |
| 1160 | break; |
| 1161 | } |
| 1162 | |
| 1163 | return ret; |
| 1164 | } |
| 1165 | |
| 1166 | static int fimc_md_link_notify(struct media_link *link, unsigned int flags, |
| 1167 | unsigned int notification) |
| 1168 | { |
Sakari Ailus | 20b8522 | 2016-11-21 14:48:30 -0200 | [diff] [blame] | 1169 | struct media_graph *graph = |
Sakari Ailus | fd7e530 | 2015-12-16 15:32:25 +0200 | [diff] [blame] | 1170 | &container_of(link->graph_obj.mdev, struct fimc_md, |
| 1171 | media_dev)->link_setup_graph; |
Sylwester Nawrocki | d3775fa | 2013-05-31 10:37:27 -0300 | [diff] [blame] | 1172 | struct media_entity *sink = link->sink->entity; |
| 1173 | int ret = 0; |
| 1174 | |
| 1175 | /* Before link disconnection */ |
| 1176 | if (notification == MEDIA_DEV_NOTIFY_PRE_LINK_CH) { |
Sakari Ailus | 20b8522 | 2016-11-21 14:48:30 -0200 | [diff] [blame] | 1177 | ret = media_graph_walk_init(graph, |
Sakari Ailus | fd7e530 | 2015-12-16 15:32:25 +0200 | [diff] [blame] | 1178 | link->graph_obj.mdev); |
| 1179 | if (ret) |
| 1180 | return ret; |
Sylwester Nawrocki | d3775fa | 2013-05-31 10:37:27 -0300 | [diff] [blame] | 1181 | if (!(flags & MEDIA_LNK_FL_ENABLED)) |
Sakari Ailus | fd7e530 | 2015-12-16 15:32:25 +0200 | [diff] [blame] | 1182 | ret = __fimc_md_modify_pipelines(sink, false, graph); |
Mauro Carvalho Chehab | cdf58a6 | 2014-08-26 11:19:18 -0300 | [diff] [blame] | 1183 | #if 0 |
Sylwester Nawrocki | d3775fa | 2013-05-31 10:37:27 -0300 | [diff] [blame] | 1184 | else |
Mauro Carvalho Chehab | cdf58a6 | 2014-08-26 11:19:18 -0300 | [diff] [blame] | 1185 | /* TODO: Link state change validation */ |
| 1186 | #endif |
Sylwester Nawrocki | d3775fa | 2013-05-31 10:37:27 -0300 | [diff] [blame] | 1187 | /* After link activation */ |
Sakari Ailus | fd7e530 | 2015-12-16 15:32:25 +0200 | [diff] [blame] | 1188 | } else if (notification == MEDIA_DEV_NOTIFY_POST_LINK_CH) { |
| 1189 | if (link->flags & MEDIA_LNK_FL_ENABLED) |
| 1190 | ret = __fimc_md_modify_pipelines(sink, true, graph); |
Sakari Ailus | 20b8522 | 2016-11-21 14:48:30 -0200 | [diff] [blame] | 1191 | media_graph_walk_cleanup(graph); |
Sylwester Nawrocki | d3775fa | 2013-05-31 10:37:27 -0300 | [diff] [blame] | 1192 | } |
| 1193 | |
| 1194 | return ret ? -EPIPE : 0; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1195 | } |
| 1196 | |
Laurent Pinchart | 68429f5 | 2015-11-03 00:27:51 -0200 | [diff] [blame] | 1197 | static const struct media_device_ops fimc_md_ops = { |
| 1198 | .link_notify = fimc_md_link_notify, |
| 1199 | }; |
| 1200 | |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1201 | static ssize_t fimc_md_sysfs_show(struct device *dev, |
| 1202 | struct device_attribute *attr, char *buf) |
| 1203 | { |
| 1204 | struct platform_device *pdev = to_platform_device(dev); |
| 1205 | struct fimc_md *fmd = platform_get_drvdata(pdev); |
| 1206 | |
| 1207 | if (fmd->user_subdev_api) |
| 1208 | return strlcpy(buf, "Sub-device API (sub-dev)\n", PAGE_SIZE); |
| 1209 | |
| 1210 | return strlcpy(buf, "V4L2 video node only API (vid-dev)\n", PAGE_SIZE); |
| 1211 | } |
| 1212 | |
| 1213 | static ssize_t fimc_md_sysfs_store(struct device *dev, |
| 1214 | struct device_attribute *attr, |
| 1215 | const char *buf, size_t count) |
| 1216 | { |
| 1217 | struct platform_device *pdev = to_platform_device(dev); |
| 1218 | struct fimc_md *fmd = platform_get_drvdata(pdev); |
| 1219 | bool subdev_api; |
| 1220 | int i; |
| 1221 | |
| 1222 | if (!strcmp(buf, "vid-dev\n")) |
| 1223 | subdev_api = false; |
| 1224 | else if (!strcmp(buf, "sub-dev\n")) |
| 1225 | subdev_api = true; |
| 1226 | else |
| 1227 | return count; |
| 1228 | |
| 1229 | fmd->user_subdev_api = subdev_api; |
| 1230 | for (i = 0; i < FIMC_MAX_DEVS; i++) |
| 1231 | if (fmd->fimc[i]) |
| 1232 | fmd->fimc[i]->vid_cap.user_subdev_api = subdev_api; |
| 1233 | return count; |
| 1234 | } |
| 1235 | /* |
| 1236 | * This device attribute is to select video pipeline configuration method. |
| 1237 | * There are following valid values: |
| 1238 | * vid-dev - for V4L2 video node API only, subdevice will be configured |
| 1239 | * by the host driver. |
| 1240 | * sub-dev - for media controller API, subdevs must be configured in user |
| 1241 | * space before starting streaming. |
| 1242 | */ |
| 1243 | static DEVICE_ATTR(subdev_conf_mode, S_IWUSR | S_IRUGO, |
| 1244 | fimc_md_sysfs_show, fimc_md_sysfs_store); |
| 1245 | |
Sylwester Nawrocki | 4163851 | 2013-03-08 10:41:47 -0300 | [diff] [blame] | 1246 | static int fimc_md_get_pinctrl(struct fimc_md *fmd) |
| 1247 | { |
| 1248 | struct device *dev = &fmd->pdev->dev; |
| 1249 | struct fimc_pinctrl *pctl = &fmd->pinctl; |
| 1250 | |
| 1251 | pctl->pinctrl = devm_pinctrl_get(dev); |
| 1252 | if (IS_ERR(pctl->pinctrl)) |
| 1253 | return PTR_ERR(pctl->pinctrl); |
| 1254 | |
| 1255 | pctl->state_default = pinctrl_lookup_state(pctl->pinctrl, |
| 1256 | PINCTRL_STATE_DEFAULT); |
| 1257 | if (IS_ERR(pctl->state_default)) |
| 1258 | return PTR_ERR(pctl->state_default); |
| 1259 | |
| 1260 | pctl->state_idle = pinctrl_lookup_state(pctl->pinctrl, |
| 1261 | PINCTRL_STATE_IDLE); |
| 1262 | return 0; |
| 1263 | } |
| 1264 | |
Sylwester Nawrocki | d3f5e0c | 2013-12-20 18:53:53 -0300 | [diff] [blame] | 1265 | static int cam_clk_prepare(struct clk_hw *hw) |
| 1266 | { |
| 1267 | struct cam_clk *camclk = to_cam_clk(hw); |
| 1268 | int ret; |
| 1269 | |
| 1270 | if (camclk->fmd->pmf == NULL) |
| 1271 | return -ENODEV; |
| 1272 | |
| 1273 | ret = pm_runtime_get_sync(camclk->fmd->pmf); |
| 1274 | return ret < 0 ? ret : 0; |
| 1275 | } |
| 1276 | |
| 1277 | static void cam_clk_unprepare(struct clk_hw *hw) |
| 1278 | { |
| 1279 | struct cam_clk *camclk = to_cam_clk(hw); |
| 1280 | |
| 1281 | if (camclk->fmd->pmf == NULL) |
| 1282 | return; |
| 1283 | |
| 1284 | pm_runtime_put_sync(camclk->fmd->pmf); |
| 1285 | } |
| 1286 | |
| 1287 | static const struct clk_ops cam_clk_ops = { |
| 1288 | .prepare = cam_clk_prepare, |
| 1289 | .unprepare = cam_clk_unprepare, |
| 1290 | }; |
| 1291 | |
| 1292 | static void fimc_md_unregister_clk_provider(struct fimc_md *fmd) |
| 1293 | { |
| 1294 | struct cam_clk_provider *cp = &fmd->clk_provider; |
| 1295 | unsigned int i; |
| 1296 | |
| 1297 | if (cp->of_node) |
| 1298 | of_clk_del_provider(cp->of_node); |
| 1299 | |
| 1300 | for (i = 0; i < cp->num_clocks; i++) |
| 1301 | clk_unregister(cp->clks[i]); |
| 1302 | } |
| 1303 | |
| 1304 | static int fimc_md_register_clk_provider(struct fimc_md *fmd) |
| 1305 | { |
| 1306 | struct cam_clk_provider *cp = &fmd->clk_provider; |
| 1307 | struct device *dev = &fmd->pdev->dev; |
| 1308 | int i, ret; |
| 1309 | |
| 1310 | for (i = 0; i < FIMC_MAX_CAMCLKS; i++) { |
| 1311 | struct cam_clk *camclk = &cp->camclk[i]; |
| 1312 | struct clk_init_data init; |
| 1313 | const char *p_name; |
| 1314 | |
| 1315 | ret = of_property_read_string_index(dev->of_node, |
| 1316 | "clock-output-names", i, &init.name); |
| 1317 | if (ret < 0) |
| 1318 | break; |
| 1319 | |
| 1320 | p_name = __clk_get_name(fmd->camclk[i].clock); |
| 1321 | |
| 1322 | /* It's safe since clk_register() will duplicate the string. */ |
| 1323 | init.parent_names = &p_name; |
| 1324 | init.num_parents = 1; |
| 1325 | init.ops = &cam_clk_ops; |
| 1326 | init.flags = CLK_SET_RATE_PARENT; |
| 1327 | camclk->hw.init = &init; |
| 1328 | camclk->fmd = fmd; |
| 1329 | |
| 1330 | cp->clks[i] = clk_register(NULL, &camclk->hw); |
| 1331 | if (IS_ERR(cp->clks[i])) { |
| 1332 | dev_err(dev, "failed to register clock: %s (%ld)\n", |
| 1333 | init.name, PTR_ERR(cp->clks[i])); |
| 1334 | ret = PTR_ERR(cp->clks[i]); |
| 1335 | goto err; |
| 1336 | } |
| 1337 | cp->num_clocks++; |
| 1338 | } |
| 1339 | |
| 1340 | if (cp->num_clocks == 0) { |
| 1341 | dev_warn(dev, "clk provider not registered\n"); |
| 1342 | return 0; |
| 1343 | } |
| 1344 | |
| 1345 | cp->clk_data.clks = cp->clks; |
| 1346 | cp->clk_data.clk_num = cp->num_clocks; |
| 1347 | cp->of_node = dev->of_node; |
| 1348 | ret = of_clk_add_provider(dev->of_node, of_clk_src_onecell_get, |
| 1349 | &cp->clk_data); |
| 1350 | if (ret == 0) |
| 1351 | return 0; |
| 1352 | err: |
| 1353 | fimc_md_unregister_clk_provider(fmd); |
| 1354 | return ret; |
| 1355 | } |
Sylwester Nawrocki | d3f5e0c | 2013-12-20 18:53:53 -0300 | [diff] [blame] | 1356 | |
Sylwester Nawrocki | fa91f10 | 2014-02-24 11:44:50 -0300 | [diff] [blame] | 1357 | static int subdev_notifier_bound(struct v4l2_async_notifier *notifier, |
| 1358 | struct v4l2_subdev *subdev, |
| 1359 | struct v4l2_async_subdev *asd) |
| 1360 | { |
| 1361 | struct fimc_md *fmd = notifier_to_fimc_md(notifier); |
| 1362 | struct fimc_sensor_info *si = NULL; |
| 1363 | int i; |
| 1364 | |
| 1365 | /* Find platform data for this sensor subdev */ |
| 1366 | for (i = 0; i < ARRAY_SIZE(fmd->sensor); i++) |
Sakari Ailus | 859969b | 2016-08-26 20:17:25 -0300 | [diff] [blame] | 1367 | if (fmd->sensor[i].asd.match.fwnode.fwnode == |
| 1368 | of_fwnode_handle(subdev->dev->of_node)) |
Sylwester Nawrocki | fa91f10 | 2014-02-24 11:44:50 -0300 | [diff] [blame] | 1369 | si = &fmd->sensor[i]; |
| 1370 | |
| 1371 | if (si == NULL) |
| 1372 | return -EINVAL; |
| 1373 | |
| 1374 | v4l2_set_subdev_hostdata(subdev, &si->pdata); |
| 1375 | |
| 1376 | if (si->pdata.fimc_bus_type == FIMC_BUS_TYPE_ISP_WRITEBACK) |
| 1377 | subdev->grp_id = GRP_ID_FIMC_IS_SENSOR; |
| 1378 | else |
| 1379 | subdev->grp_id = GRP_ID_SENSOR; |
| 1380 | |
| 1381 | si->subdev = subdev; |
| 1382 | |
| 1383 | v4l2_info(&fmd->v4l2_dev, "Registered sensor subdevice: %s (%d)\n", |
| 1384 | subdev->name, fmd->num_sensors); |
| 1385 | |
| 1386 | fmd->num_sensors++; |
| 1387 | |
| 1388 | return 0; |
| 1389 | } |
| 1390 | |
| 1391 | static int subdev_notifier_complete(struct v4l2_async_notifier *notifier) |
| 1392 | { |
| 1393 | struct fimc_md *fmd = notifier_to_fimc_md(notifier); |
| 1394 | int ret; |
| 1395 | |
| 1396 | mutex_lock(&fmd->media_dev.graph_mutex); |
| 1397 | |
| 1398 | ret = fimc_md_create_links(fmd); |
| 1399 | if (ret < 0) |
| 1400 | goto unlock; |
| 1401 | |
| 1402 | ret = v4l2_device_register_subdev_nodes(&fmd->v4l2_dev); |
| 1403 | unlock: |
| 1404 | mutex_unlock(&fmd->media_dev.graph_mutex); |
Javier Martinez Canillas | 9832e15 | 2015-12-11 20:57:08 -0200 | [diff] [blame] | 1405 | if (ret < 0) |
| 1406 | return ret; |
| 1407 | |
| 1408 | return media_device_register(&fmd->media_dev); |
Sylwester Nawrocki | fa91f10 | 2014-02-24 11:44:50 -0300 | [diff] [blame] | 1409 | } |
| 1410 | |
Laurent Pinchart | b6ee3f0 | 2017-08-30 13:18:04 -0400 | [diff] [blame] | 1411 | static const struct v4l2_async_notifier_operations subdev_notifier_ops = { |
| 1412 | .bound = subdev_notifier_bound, |
| 1413 | .complete = subdev_notifier_complete, |
| 1414 | }; |
| 1415 | |
Sylwester Nawrocki | ecd9acb | 2012-03-21 09:58:09 -0300 | [diff] [blame] | 1416 | static int fimc_md_probe(struct platform_device *pdev) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1417 | { |
Sylwester Nawrocki | e2985a2 | 2013-03-08 12:59:33 -0300 | [diff] [blame] | 1418 | struct device *dev = &pdev->dev; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1419 | struct v4l2_device *v4l2_dev; |
| 1420 | struct fimc_md *fmd; |
| 1421 | int ret; |
| 1422 | |
Sylwester Nawrocki | e2985a2 | 2013-03-08 12:59:33 -0300 | [diff] [blame] | 1423 | fmd = devm_kzalloc(dev, sizeof(*fmd), GFP_KERNEL); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1424 | if (!fmd) |
| 1425 | return -ENOMEM; |
| 1426 | |
| 1427 | spin_lock_init(&fmd->slock); |
Sylwester Nawrocki | 403dfbe | 2013-05-31 11:37:22 -0300 | [diff] [blame] | 1428 | INIT_LIST_HEAD(&fmd->pipelines); |
Sylwester Nawrocki | 49b2f4c5 | 2014-04-15 08:35:25 -0300 | [diff] [blame] | 1429 | fmd->pdev = pdev; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1430 | |
| 1431 | strlcpy(fmd->media_dev.model, "SAMSUNG S5P FIMC", |
| 1432 | sizeof(fmd->media_dev.model)); |
Laurent Pinchart | 68429f5 | 2015-11-03 00:27:51 -0200 | [diff] [blame] | 1433 | fmd->media_dev.ops = &fimc_md_ops; |
Sylwester Nawrocki | e2985a2 | 2013-03-08 12:59:33 -0300 | [diff] [blame] | 1434 | fmd->media_dev.dev = dev; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1435 | |
| 1436 | v4l2_dev = &fmd->v4l2_dev; |
| 1437 | v4l2_dev->mdev = &fmd->media_dev; |
Sylwester Nawrocki | e1d72f4 | 2011-06-10 15:36:58 -0300 | [diff] [blame] | 1438 | v4l2_dev->notify = fimc_sensor_notify; |
Sylwester Nawrocki | e2985a2 | 2013-03-08 12:59:33 -0300 | [diff] [blame] | 1439 | strlcpy(v4l2_dev->name, "s5p-fimc-md", sizeof(v4l2_dev->name)); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1440 | |
Sylwester Nawrocki | e781bbe3 | 2013-03-21 14:49:16 -0300 | [diff] [blame] | 1441 | fmd->use_isp = fimc_md_is_isp_available(dev->of_node); |
Sylwester Nawrocki | 49b2f4c5 | 2014-04-15 08:35:25 -0300 | [diff] [blame] | 1442 | fmd->user_subdev_api = true; |
Sylwester Nawrocki | e781bbe3 | 2013-03-21 14:49:16 -0300 | [diff] [blame] | 1443 | |
Mauro Carvalho Chehab | 2e7508e | 2015-12-28 09:24:23 -0200 | [diff] [blame] | 1444 | media_device_init(&fmd->media_dev); |
| 1445 | |
Sylwester Nawrocki | e2985a2 | 2013-03-08 12:59:33 -0300 | [diff] [blame] | 1446 | ret = v4l2_device_register(dev, &fmd->v4l2_dev); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1447 | if (ret < 0) { |
| 1448 | v4l2_err(v4l2_dev, "Failed to register v4l2_device: %d\n", ret); |
Sylwester Nawrocki | 6d91a51 | 2012-01-30 11:37:59 -0300 | [diff] [blame] | 1449 | return ret; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1450 | } |
Sylwester Nawrocki | d3f5e0c | 2013-12-20 18:53:53 -0300 | [diff] [blame] | 1451 | |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1452 | ret = fimc_md_get_clocks(fmd); |
| 1453 | if (ret) |
Sylwester Nawrocki | fa91f10 | 2014-02-24 11:44:50 -0300 | [diff] [blame] | 1454 | goto err_md; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1455 | |
Sylwester Nawrocki | 4163851 | 2013-03-08 10:41:47 -0300 | [diff] [blame] | 1456 | ret = fimc_md_get_pinctrl(fmd); |
| 1457 | if (ret < 0) { |
| 1458 | if (ret != EPROBE_DEFER) |
| 1459 | dev_err(dev, "Failed to get pinctrl: %d\n", ret); |
Sylwester Nawrocki | fa91f10 | 2014-02-24 11:44:50 -0300 | [diff] [blame] | 1460 | goto err_clk; |
Sylwester Nawrocki | 4163851 | 2013-03-08 10:41:47 -0300 | [diff] [blame] | 1461 | } |
| 1462 | |
Sylwester Nawrocki | fa91f10 | 2014-02-24 11:44:50 -0300 | [diff] [blame] | 1463 | platform_set_drvdata(pdev, fmd); |
| 1464 | |
Sylwester Nawrocki | 49b2f4c5 | 2014-04-15 08:35:25 -0300 | [diff] [blame] | 1465 | ret = fimc_md_register_platform_entities(fmd, dev->of_node); |
Marek Szyprowski | 243d4c0 | 2016-04-28 07:25:03 -0300 | [diff] [blame] | 1466 | if (ret) |
Sylwester Nawrocki | fa91f10 | 2014-02-24 11:44:50 -0300 | [diff] [blame] | 1467 | goto err_clk; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1468 | |
Sylwester Nawrocki | 49b2f4c5 | 2014-04-15 08:35:25 -0300 | [diff] [blame] | 1469 | ret = fimc_md_register_sensor_entities(fmd); |
Marek Szyprowski | 243d4c0 | 2016-04-28 07:25:03 -0300 | [diff] [blame] | 1470 | if (ret) |
Sylwester Nawrocki | 49b2f4c5 | 2014-04-15 08:35:25 -0300 | [diff] [blame] | 1471 | goto err_m_ent; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1472 | |
| 1473 | ret = device_create_file(&pdev->dev, &dev_attr_subdev_conf_mode); |
Sylwester Nawrocki | 693f5c4 | 2012-04-20 18:57:25 -0300 | [diff] [blame] | 1474 | if (ret) |
Sylwester Nawrocki | fa91f10 | 2014-02-24 11:44:50 -0300 | [diff] [blame] | 1475 | goto err_m_ent; |
| 1476 | /* |
| 1477 | * FIMC platform devices need to be registered before the sclk_cam |
| 1478 | * clocks provider, as one of these devices needs to be activated |
| 1479 | * to enable the clock. |
| 1480 | */ |
| 1481 | ret = fimc_md_register_clk_provider(fmd); |
| 1482 | if (ret < 0) { |
| 1483 | v4l2_err(v4l2_dev, "clock provider registration failed\n"); |
| 1484 | goto err_attr; |
| 1485 | } |
Sylwester Nawrocki | 693f5c4 | 2012-04-20 18:57:25 -0300 | [diff] [blame] | 1486 | |
Sylwester Nawrocki | fa91f10 | 2014-02-24 11:44:50 -0300 | [diff] [blame] | 1487 | if (fmd->num_sensors > 0) { |
| 1488 | fmd->subdev_notifier.subdevs = fmd->async_subdevs; |
| 1489 | fmd->subdev_notifier.num_subdevs = fmd->num_sensors; |
Laurent Pinchart | b6ee3f0 | 2017-08-30 13:18:04 -0400 | [diff] [blame] | 1490 | fmd->subdev_notifier.ops = &subdev_notifier_ops; |
Sylwester Nawrocki | fa91f10 | 2014-02-24 11:44:50 -0300 | [diff] [blame] | 1491 | fmd->num_sensors = 0; |
| 1492 | |
| 1493 | ret = v4l2_async_notifier_register(&fmd->v4l2_dev, |
| 1494 | &fmd->subdev_notifier); |
| 1495 | if (ret) |
| 1496 | goto err_clk_p; |
| 1497 | } |
| 1498 | |
Sylwester Nawrocki | 693f5c4 | 2012-04-20 18:57:25 -0300 | [diff] [blame] | 1499 | return 0; |
| 1500 | |
Sylwester Nawrocki | fa91f10 | 2014-02-24 11:44:50 -0300 | [diff] [blame] | 1501 | err_clk_p: |
| 1502 | fimc_md_unregister_clk_provider(fmd); |
| 1503 | err_attr: |
| 1504 | device_remove_file(&pdev->dev, &dev_attr_subdev_conf_mode); |
Sylwester Nawrocki | 693f5c4 | 2012-04-20 18:57:25 -0300 | [diff] [blame] | 1505 | err_clk: |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1506 | fimc_md_put_clocks(fmd); |
Sylwester Nawrocki | fa91f10 | 2014-02-24 11:44:50 -0300 | [diff] [blame] | 1507 | err_m_ent: |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1508 | fimc_md_unregister_entities(fmd); |
Sylwester Nawrocki | 693f5c4 | 2012-04-20 18:57:25 -0300 | [diff] [blame] | 1509 | err_md: |
Javier Martinez Canillas | 9832e15 | 2015-12-11 20:57:08 -0200 | [diff] [blame] | 1510 | media_device_cleanup(&fmd->media_dev); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1511 | v4l2_device_unregister(&fmd->v4l2_dev); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1512 | return ret; |
| 1513 | } |
| 1514 | |
Greg Kroah-Hartman | 4c62e97 | 2012-12-21 13:17:53 -0800 | [diff] [blame] | 1515 | static int fimc_md_remove(struct platform_device *pdev) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1516 | { |
| 1517 | struct fimc_md *fmd = platform_get_drvdata(pdev); |
| 1518 | |
| 1519 | if (!fmd) |
| 1520 | return 0; |
Sylwester Nawrocki | b74bee1 | 2013-08-09 14:23:53 -0300 | [diff] [blame] | 1521 | |
Sylwester Nawrocki | d3f5e0c | 2013-12-20 18:53:53 -0300 | [diff] [blame] | 1522 | fimc_md_unregister_clk_provider(fmd); |
Sylwester Nawrocki | fa91f10 | 2014-02-24 11:44:50 -0300 | [diff] [blame] | 1523 | v4l2_async_notifier_unregister(&fmd->subdev_notifier); |
| 1524 | |
Sylwester Nawrocki | b74bee1 | 2013-08-09 14:23:53 -0300 | [diff] [blame] | 1525 | v4l2_device_unregister(&fmd->v4l2_dev); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1526 | device_remove_file(&pdev->dev, &dev_attr_subdev_conf_mode); |
| 1527 | fimc_md_unregister_entities(fmd); |
Sylwester Nawrocki | 403dfbe | 2013-05-31 11:37:22 -0300 | [diff] [blame] | 1528 | fimc_md_pipelines_free(fmd); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1529 | media_device_unregister(&fmd->media_dev); |
Javier Martinez Canillas | 9832e15 | 2015-12-11 20:57:08 -0200 | [diff] [blame] | 1530 | media_device_cleanup(&fmd->media_dev); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1531 | fimc_md_put_clocks(fmd); |
Sylwester Nawrocki | fa91f10 | 2014-02-24 11:44:50 -0300 | [diff] [blame] | 1532 | |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1533 | return 0; |
| 1534 | } |
| 1535 | |
Krzysztof Kozlowski | c42639d | 2015-05-01 12:51:01 -0300 | [diff] [blame] | 1536 | static const struct platform_device_id fimc_driver_ids[] __always_unused = { |
Sylwester Nawrocki | e2985a2 | 2013-03-08 12:59:33 -0300 | [diff] [blame] | 1537 | { .name = "s5p-fimc-md" }, |
| 1538 | { }, |
| 1539 | }; |
| 1540 | MODULE_DEVICE_TABLE(platform, fimc_driver_ids); |
| 1541 | |
| 1542 | static const struct of_device_id fimc_md_of_match[] = { |
| 1543 | { .compatible = "samsung,fimc" }, |
| 1544 | { }, |
| 1545 | }; |
| 1546 | MODULE_DEVICE_TABLE(of, fimc_md_of_match); |
| 1547 | |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1548 | static struct platform_driver fimc_md_driver = { |
| 1549 | .probe = fimc_md_probe, |
Greg Kroah-Hartman | 4c62e97 | 2012-12-21 13:17:53 -0800 | [diff] [blame] | 1550 | .remove = fimc_md_remove, |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1551 | .driver = { |
Sylwester Nawrocki | e2985a2 | 2013-03-08 12:59:33 -0300 | [diff] [blame] | 1552 | .of_match_table = of_match_ptr(fimc_md_of_match), |
| 1553 | .name = "s5p-fimc-md", |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1554 | } |
| 1555 | }; |
| 1556 | |
Sachin Kamat | 7e566be | 2012-05-26 11:11:54 -0300 | [diff] [blame] | 1557 | static int __init fimc_md_init(void) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1558 | { |
| 1559 | int ret; |
Sylwester Nawrocki | ecd9acb | 2012-03-21 09:58:09 -0300 | [diff] [blame] | 1560 | |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1561 | request_module("s5p-csis"); |
| 1562 | ret = fimc_register_driver(); |
| 1563 | if (ret) |
| 1564 | return ret; |
Sylwester Nawrocki | ecd9acb | 2012-03-21 09:58:09 -0300 | [diff] [blame] | 1565 | |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1566 | return platform_driver_register(&fimc_md_driver); |
| 1567 | } |
Sachin Kamat | 7e566be | 2012-05-26 11:11:54 -0300 | [diff] [blame] | 1568 | |
| 1569 | static void __exit fimc_md_exit(void) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1570 | { |
| 1571 | platform_driver_unregister(&fimc_md_driver); |
| 1572 | fimc_unregister_driver(); |
| 1573 | } |
| 1574 | |
| 1575 | module_init(fimc_md_init); |
| 1576 | module_exit(fimc_md_exit); |
| 1577 | |
| 1578 | MODULE_AUTHOR("Sylwester Nawrocki <s.nawrocki@samsung.com>"); |
| 1579 | MODULE_DESCRIPTION("S5P FIMC camera host interface/video postprocessor driver"); |
| 1580 | MODULE_LICENSE("GPL"); |
| 1581 | MODULE_VERSION("2.0.1"); |