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