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