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