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