Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1 | /* |
Sylwester Nawrocki | 0c9204d | 2012-04-25 06:55:42 -0300 | [diff] [blame] | 2 | * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License version 2 as |
| 6 | * published by the Free Software Foundation. |
| 7 | */ |
| 8 | |
| 9 | #ifndef FIMC_MDEVICE_H_ |
| 10 | #define FIMC_MDEVICE_H_ |
| 11 | |
| 12 | #include <linux/clk.h> |
Sylwester Nawrocki | d3f5e0c | 2013-12-20 18:53:53 -0300 | [diff] [blame] | 13 | #include <linux/clk-provider.h> |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 14 | #include <linux/platform_device.h> |
| 15 | #include <linux/mutex.h> |
Sylwester Nawrocki | e781bbe3 | 2013-03-21 14:49:16 -0300 | [diff] [blame] | 16 | #include <linux/of.h> |
Sylwester Nawrocki | 4163851 | 2013-03-08 10:41:47 -0300 | [diff] [blame] | 17 | #include <linux/pinctrl/consumer.h> |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 18 | #include <media/media-device.h> |
| 19 | #include <media/media-entity.h> |
| 20 | #include <media/v4l2-device.h> |
| 21 | #include <media/v4l2-subdev.h> |
Sylwester Nawrocki | 403dfbe | 2013-05-31 11:37:22 -0300 | [diff] [blame] | 22 | #include <media/s5p_fimc.h> |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 23 | |
| 24 | #include "fimc-core.h" |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 25 | #include "fimc-lite.h" |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 26 | #include "mipi-csis.h" |
| 27 | |
Sylwester Nawrocki | e2985a2 | 2013-03-08 12:59:33 -0300 | [diff] [blame] | 28 | #define FIMC_OF_NODE_NAME "fimc" |
| 29 | #define FIMC_LITE_OF_NODE_NAME "fimc-lite" |
| 30 | #define FIMC_IS_OF_NODE_NAME "fimc-is" |
| 31 | #define CSIS_OF_NODE_NAME "csis" |
| 32 | |
Sylwester Nawrocki | 4163851 | 2013-03-08 10:41:47 -0300 | [diff] [blame] | 33 | #define PINCTRL_STATE_IDLE "idle" |
| 34 | |
Sylwester Nawrocki | fa91f10 | 2014-02-24 11:44:50 -0300 | [diff] [blame] | 35 | #define FIMC_MAX_SENSORS 4 |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 36 | #define FIMC_MAX_CAMCLKS 2 |
Sylwester Nawrocki | fa91f10 | 2014-02-24 11:44:50 -0300 | [diff] [blame] | 37 | #define DEFAULT_SENSOR_CLK_FREQ 24000000U |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 38 | |
Sylwester Nawrocki | 056f4f3 | 2013-03-21 14:43:17 -0300 | [diff] [blame] | 39 | /* LCD/ISP Writeback clocks (PIXELASYNCMx) */ |
| 40 | enum { |
| 41 | CLK_IDX_WB_A, |
| 42 | CLK_IDX_WB_B, |
| 43 | FIMC_MAX_WBCLKS |
| 44 | }; |
| 45 | |
Sylwester Nawrocki | 403dfbe | 2013-05-31 11:37:22 -0300 | [diff] [blame] | 46 | enum fimc_subdev_index { |
| 47 | IDX_SENSOR, |
| 48 | IDX_CSIS, |
| 49 | IDX_FLITE, |
| 50 | IDX_IS_ISP, |
| 51 | IDX_FIMC, |
| 52 | IDX_MAX, |
| 53 | }; |
| 54 | |
| 55 | /* |
| 56 | * This structure represents a chain of media entities, including a data |
| 57 | * source entity (e.g. an image sensor subdevice), a data capture entity |
| 58 | * - a video capture device node and any remaining entities. |
| 59 | */ |
| 60 | struct fimc_pipeline { |
| 61 | struct exynos_media_pipeline ep; |
| 62 | struct list_head list; |
| 63 | struct media_entity *vdev_entity; |
| 64 | struct v4l2_subdev *subdevs[IDX_MAX]; |
| 65 | }; |
| 66 | |
| 67 | #define to_fimc_pipeline(_ep) container_of(_ep, struct fimc_pipeline, ep) |
| 68 | |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 69 | struct fimc_csis_info { |
| 70 | struct v4l2_subdev *sd; |
| 71 | int id; |
| 72 | }; |
| 73 | |
| 74 | struct fimc_camclk_info { |
| 75 | struct clk *clock; |
| 76 | int use_count; |
| 77 | unsigned long frequency; |
| 78 | }; |
| 79 | |
| 80 | /** |
| 81 | * struct fimc_sensor_info - image data source subdev information |
| 82 | * @pdata: sensor's atrributes passed as media device's platform data |
Sylwester Nawrocki | fa91f10 | 2014-02-24 11:44:50 -0300 | [diff] [blame] | 83 | * @asd: asynchronous subdev registration data structure |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 84 | * @subdev: image sensor v4l2 subdev |
| 85 | * @host: fimc device the sensor is currently linked to |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 86 | * |
| 87 | * This data structure applies to image sensor and the writeback subdevs. |
| 88 | */ |
| 89 | struct fimc_sensor_info { |
Sylwester Nawrocki | 56bc911 | 2013-02-01 15:00:40 -0300 | [diff] [blame] | 90 | struct fimc_source_info pdata; |
Sylwester Nawrocki | fa91f10 | 2014-02-24 11:44:50 -0300 | [diff] [blame] | 91 | struct v4l2_async_subdev asd; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 92 | struct v4l2_subdev *subdev; |
| 93 | struct fimc_dev *host; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 94 | }; |
| 95 | |
Sylwester Nawrocki | d3f5e0c | 2013-12-20 18:53:53 -0300 | [diff] [blame] | 96 | struct cam_clk { |
Sylwester Nawrocki | f486e7c | 2014-04-15 14:34:29 -0300 | [diff] [blame^] | 97 | #ifdef CONFIG_COMMON_CLK |
Sylwester Nawrocki | d3f5e0c | 2013-12-20 18:53:53 -0300 | [diff] [blame] | 98 | struct clk_hw hw; |
Sylwester Nawrocki | f486e7c | 2014-04-15 14:34:29 -0300 | [diff] [blame^] | 99 | #endif |
Sylwester Nawrocki | d3f5e0c | 2013-12-20 18:53:53 -0300 | [diff] [blame] | 100 | struct fimc_md *fmd; |
| 101 | }; |
| 102 | #define to_cam_clk(_hw) container_of(_hw, struct cam_clk, hw) |
| 103 | |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 104 | /** |
| 105 | * struct fimc_md - fimc media device information |
| 106 | * @csis: MIPI CSIS subdevs data |
| 107 | * @sensor: array of registered sensor subdevs |
| 108 | * @num_sensors: actual number of registered sensors |
| 109 | * @camclk: external sensor clock information |
| 110 | * @fimc: array of registered fimc devices |
Sylwester Nawrocki | e781bbe3 | 2013-03-21 14:49:16 -0300 | [diff] [blame] | 111 | * @fimc_is: fimc-is data structure |
Sylwester Nawrocki | 056f4f3 | 2013-03-21 14:43:17 -0300 | [diff] [blame] | 112 | * @use_isp: set to true when FIMC-IS subsystem is used |
Sylwester Nawrocki | 3e20c34 | 2013-03-21 14:47:17 -0300 | [diff] [blame] | 113 | * @pmf: handle to the CAMCLK clock control FIMC helper device |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 114 | * @media_dev: top level media device |
| 115 | * @v4l2_dev: top level v4l2_device holding up the subdevs |
| 116 | * @pdev: platform device this media device is hooked up into |
Sylwester Nawrocki | 4163851 | 2013-03-08 10:41:47 -0300 | [diff] [blame] | 117 | * @pinctrl: camera port pinctrl handle |
| 118 | * @state_default: pinctrl default state handle |
| 119 | * @state_idle: pinctrl idle state handle |
Sylwester Nawrocki | d3f5e0c | 2013-12-20 18:53:53 -0300 | [diff] [blame] | 120 | * @cam_clk_provider: CAMCLK clock provider structure |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 121 | * @user_subdev_api: true if subdevs are not configured by the host driver |
| 122 | * @slock: spinlock protecting @sensor array |
| 123 | */ |
| 124 | struct fimc_md { |
| 125 | struct fimc_csis_info csis[CSIS_MAX_ENTITIES]; |
| 126 | struct fimc_sensor_info sensor[FIMC_MAX_SENSORS]; |
| 127 | int num_sensors; |
| 128 | struct fimc_camclk_info camclk[FIMC_MAX_CAMCLKS]; |
Sylwester Nawrocki | 056f4f3 | 2013-03-21 14:43:17 -0300 | [diff] [blame] | 129 | struct clk *wbclk[FIMC_MAX_WBCLKS]; |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 130 | struct fimc_lite *fimc_lite[FIMC_LITE_MAX_DEVS]; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 131 | struct fimc_dev *fimc[FIMC_MAX_DEVS]; |
Sylwester Nawrocki | e781bbe3 | 2013-03-21 14:49:16 -0300 | [diff] [blame] | 132 | struct fimc_is *fimc_is; |
Sylwester Nawrocki | 056f4f3 | 2013-03-21 14:43:17 -0300 | [diff] [blame] | 133 | bool use_isp; |
Sylwester Nawrocki | 3e20c34 | 2013-03-21 14:47:17 -0300 | [diff] [blame] | 134 | struct device *pmf; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 135 | struct media_device media_dev; |
| 136 | struct v4l2_device v4l2_dev; |
| 137 | struct platform_device *pdev; |
Sylwester Nawrocki | d3f5e0c | 2013-12-20 18:53:53 -0300 | [diff] [blame] | 138 | |
Sylwester Nawrocki | 4163851 | 2013-03-08 10:41:47 -0300 | [diff] [blame] | 139 | struct fimc_pinctrl { |
| 140 | struct pinctrl *pinctrl; |
| 141 | struct pinctrl_state *state_default; |
| 142 | struct pinctrl_state *state_idle; |
| 143 | } pinctl; |
Sylwester Nawrocki | 403dfbe | 2013-05-31 11:37:22 -0300 | [diff] [blame] | 144 | |
Sylwester Nawrocki | d3f5e0c | 2013-12-20 18:53:53 -0300 | [diff] [blame] | 145 | struct cam_clk_provider { |
| 146 | struct clk *clks[FIMC_MAX_CAMCLKS]; |
Sylwester Nawrocki | f486e7c | 2014-04-15 14:34:29 -0300 | [diff] [blame^] | 147 | #ifdef CONFIG_COMMON_CLK |
Sylwester Nawrocki | d3f5e0c | 2013-12-20 18:53:53 -0300 | [diff] [blame] | 148 | struct clk_onecell_data clk_data; |
Sylwester Nawrocki | f486e7c | 2014-04-15 14:34:29 -0300 | [diff] [blame^] | 149 | #endif |
Sylwester Nawrocki | d3f5e0c | 2013-12-20 18:53:53 -0300 | [diff] [blame] | 150 | struct device_node *of_node; |
| 151 | struct cam_clk camclk[FIMC_MAX_CAMCLKS]; |
| 152 | int num_clocks; |
| 153 | } clk_provider; |
| 154 | |
Sylwester Nawrocki | fa91f10 | 2014-02-24 11:44:50 -0300 | [diff] [blame] | 155 | struct v4l2_async_notifier subdev_notifier; |
| 156 | struct v4l2_async_subdev *async_subdevs[FIMC_MAX_SENSORS]; |
| 157 | |
Sylwester Nawrocki | d3f5e0c | 2013-12-20 18:53:53 -0300 | [diff] [blame] | 158 | bool user_subdev_api; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 159 | spinlock_t slock; |
Sylwester Nawrocki | 403dfbe | 2013-05-31 11:37:22 -0300 | [diff] [blame] | 160 | struct list_head pipelines; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 161 | }; |
| 162 | |
Sylwester Nawrocki | 4c8f062 | 2013-04-09 11:11:58 -0300 | [diff] [blame] | 163 | static inline |
| 164 | struct fimc_sensor_info *source_to_sensor_info(struct fimc_source_info *si) |
| 165 | { |
| 166 | return container_of(si, struct fimc_sensor_info, pdata); |
| 167 | } |
| 168 | |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 169 | static inline struct fimc_md *entity_to_fimc_mdev(struct media_entity *me) |
| 170 | { |
| 171 | return me->parent == NULL ? NULL : |
| 172 | container_of(me->parent, struct fimc_md, media_dev); |
| 173 | } |
| 174 | |
Sylwester Nawrocki | fa91f10 | 2014-02-24 11:44:50 -0300 | [diff] [blame] | 175 | static inline struct fimc_md *notifier_to_fimc_md(struct v4l2_async_notifier *n) |
| 176 | { |
| 177 | return container_of(n, struct fimc_md, subdev_notifier); |
| 178 | } |
| 179 | |
Sylwester Nawrocki | bc7584b | 2013-05-31 11:37:18 -0300 | [diff] [blame] | 180 | static inline void fimc_md_graph_lock(struct exynos_video_entity *ve) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 181 | { |
Sylwester Nawrocki | bc7584b | 2013-05-31 11:37:18 -0300 | [diff] [blame] | 182 | mutex_lock(&ve->vdev.entity.parent->graph_mutex); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 183 | } |
| 184 | |
Sylwester Nawrocki | bc7584b | 2013-05-31 11:37:18 -0300 | [diff] [blame] | 185 | static inline void fimc_md_graph_unlock(struct exynos_video_entity *ve) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 186 | { |
Sylwester Nawrocki | bc7584b | 2013-05-31 11:37:18 -0300 | [diff] [blame] | 187 | mutex_unlock(&ve->vdev.entity.parent->graph_mutex); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | int fimc_md_set_camclk(struct v4l2_subdev *sd, bool on); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 191 | |
Sylwester Nawrocki | e781bbe3 | 2013-03-21 14:49:16 -0300 | [diff] [blame] | 192 | #ifdef CONFIG_OF |
| 193 | static inline bool fimc_md_is_isp_available(struct device_node *node) |
| 194 | { |
| 195 | node = of_get_child_by_name(node, FIMC_IS_OF_NODE_NAME); |
| 196 | return node ? of_device_is_available(node) : false; |
| 197 | } |
| 198 | #else |
| 199 | #define fimc_md_is_isp_available(node) (false) |
| 200 | #endif /* CONFIG_OF */ |
| 201 | |
Sylwester Nawrocki | 403dfbe | 2013-05-31 11:37:22 -0300 | [diff] [blame] | 202 | static inline struct v4l2_subdev *__fimc_md_get_subdev( |
| 203 | struct exynos_media_pipeline *ep, |
| 204 | unsigned int index) |
| 205 | { |
| 206 | struct fimc_pipeline *p = to_fimc_pipeline(ep); |
| 207 | |
| 208 | if (!p || index >= IDX_MAX) |
| 209 | return NULL; |
| 210 | else |
| 211 | return p->subdevs[index]; |
| 212 | } |
| 213 | |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 214 | #endif |