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