blob: 957787a2f48002379639ee362e0ba59935ab7062 [file] [log] [blame]
Sylwester Nawrockid3953222011-09-01 06:01:08 -03001/*
Sylwester Nawrocki0c9204d2012-04-25 06:55:42 -03002 * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd.
Sylwester Nawrockid3953222011-09-01 06:01:08 -03003 *
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 Nawrockid3f5e0c2013-12-20 18:53:53 -030013#include <linux/clk-provider.h>
Sylwester Nawrockid3953222011-09-01 06:01:08 -030014#include <linux/platform_device.h>
15#include <linux/mutex.h>
Sylwester Nawrockie781bbe32013-03-21 14:49:16 -030016#include <linux/of.h>
Sylwester Nawrocki41638512013-03-08 10:41:47 -030017#include <linux/pinctrl/consumer.h>
Sylwester Nawrockid3953222011-09-01 06:01:08 -030018#include <media/media-device.h>
19#include <media/media-entity.h>
20#include <media/v4l2-device.h>
21#include <media/v4l2-subdev.h>
Mauro Carvalho Chehabd647f0b2015-11-13 19:40:07 -020022#include <media/drv-intf/exynos-fimc.h>
Sylwester Nawrockid3953222011-09-01 06:01:08 -030023
24#include "fimc-core.h"
Sylwester Nawrocki4af81312012-04-27 05:29:05 -030025#include "fimc-lite.h"
Sylwester Nawrockid3953222011-09-01 06:01:08 -030026#include "mipi-csis.h"
27
Sylwester Nawrockie2985a22013-03-08 12:59:33 -030028#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 Nawrocki41638512013-03-08 10:41:47 -030033#define PINCTRL_STATE_IDLE "idle"
34
Sylwester Nawrockifa91f102014-02-24 11:44:50 -030035#define FIMC_MAX_SENSORS 4
Sylwester Nawrockid3953222011-09-01 06:01:08 -030036#define FIMC_MAX_CAMCLKS 2
Sylwester Nawrockifa91f102014-02-24 11:44:50 -030037#define DEFAULT_SENSOR_CLK_FREQ 24000000U
Sylwester Nawrockid3953222011-09-01 06:01:08 -030038
Sylwester Nawrocki056f4f32013-03-21 14:43:17 -030039/* LCD/ISP Writeback clocks (PIXELASYNCMx) */
40enum {
41 CLK_IDX_WB_A,
42 CLK_IDX_WB_B,
43 FIMC_MAX_WBCLKS
44};
45
Sylwester Nawrocki403dfbe2013-05-31 11:37:22 -030046enum 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 */
60struct 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 Nawrockid3953222011-09-01 06:01:08 -030069struct fimc_csis_info {
70 struct v4l2_subdev *sd;
71 int id;
72};
73
74struct 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 Nawrockifa91f102014-02-24 11:44:50 -030083 * @asd: asynchronous subdev registration data structure
Sylwester Nawrockid3953222011-09-01 06:01:08 -030084 * @subdev: image sensor v4l2 subdev
85 * @host: fimc device the sensor is currently linked to
Sylwester Nawrockid3953222011-09-01 06:01:08 -030086 *
87 * This data structure applies to image sensor and the writeback subdevs.
88 */
89struct fimc_sensor_info {
Sylwester Nawrocki56bc9112013-02-01 15:00:40 -030090 struct fimc_source_info pdata;
Sylwester Nawrockifa91f102014-02-24 11:44:50 -030091 struct v4l2_async_subdev asd;
Sylwester Nawrockid3953222011-09-01 06:01:08 -030092 struct v4l2_subdev *subdev;
93 struct fimc_dev *host;
Sylwester Nawrockid3953222011-09-01 06:01:08 -030094};
95
Sylwester Nawrockid3f5e0c2013-12-20 18:53:53 -030096struct cam_clk {
97 struct clk_hw hw;
98 struct fimc_md *fmd;
99};
100#define to_cam_clk(_hw) container_of(_hw, struct cam_clk, hw)
101
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300102/**
103 * struct fimc_md - fimc media device information
104 * @csis: MIPI CSIS subdevs data
105 * @sensor: array of registered sensor subdevs
106 * @num_sensors: actual number of registered sensors
107 * @camclk: external sensor clock information
108 * @fimc: array of registered fimc devices
Sylwester Nawrockie781bbe32013-03-21 14:49:16 -0300109 * @fimc_is: fimc-is data structure
Sylwester Nawrocki056f4f32013-03-21 14:43:17 -0300110 * @use_isp: set to true when FIMC-IS subsystem is used
Sylwester Nawrocki3e20c342013-03-21 14:47:17 -0300111 * @pmf: handle to the CAMCLK clock control FIMC helper device
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300112 * @media_dev: top level media device
113 * @v4l2_dev: top level v4l2_device holding up the subdevs
114 * @pdev: platform device this media device is hooked up into
Sylwester Nawrocki41638512013-03-08 10:41:47 -0300115 * @pinctrl: camera port pinctrl handle
116 * @state_default: pinctrl default state handle
117 * @state_idle: pinctrl idle state handle
Sylwester Nawrockid3f5e0c2013-12-20 18:53:53 -0300118 * @cam_clk_provider: CAMCLK clock provider structure
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300119 * @user_subdev_api: true if subdevs are not configured by the host driver
120 * @slock: spinlock protecting @sensor array
121 */
122struct fimc_md {
123 struct fimc_csis_info csis[CSIS_MAX_ENTITIES];
124 struct fimc_sensor_info sensor[FIMC_MAX_SENSORS];
125 int num_sensors;
126 struct fimc_camclk_info camclk[FIMC_MAX_CAMCLKS];
Sylwester Nawrocki056f4f32013-03-21 14:43:17 -0300127 struct clk *wbclk[FIMC_MAX_WBCLKS];
Sylwester Nawrocki4af81312012-04-27 05:29:05 -0300128 struct fimc_lite *fimc_lite[FIMC_LITE_MAX_DEVS];
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300129 struct fimc_dev *fimc[FIMC_MAX_DEVS];
Sylwester Nawrockie781bbe32013-03-21 14:49:16 -0300130 struct fimc_is *fimc_is;
Sylwester Nawrocki056f4f32013-03-21 14:43:17 -0300131 bool use_isp;
Sylwester Nawrocki3e20c342013-03-21 14:47:17 -0300132 struct device *pmf;
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300133 struct media_device media_dev;
134 struct v4l2_device v4l2_dev;
135 struct platform_device *pdev;
Sylwester Nawrockid3f5e0c2013-12-20 18:53:53 -0300136
Sylwester Nawrocki41638512013-03-08 10:41:47 -0300137 struct fimc_pinctrl {
138 struct pinctrl *pinctrl;
139 struct pinctrl_state *state_default;
140 struct pinctrl_state *state_idle;
141 } pinctl;
Sylwester Nawrocki403dfbe2013-05-31 11:37:22 -0300142
Sylwester Nawrockid3f5e0c2013-12-20 18:53:53 -0300143 struct cam_clk_provider {
144 struct clk *clks[FIMC_MAX_CAMCLKS];
145 struct clk_onecell_data clk_data;
146 struct device_node *of_node;
147 struct cam_clk camclk[FIMC_MAX_CAMCLKS];
148 int num_clocks;
149 } clk_provider;
150
Sylwester Nawrockifa91f102014-02-24 11:44:50 -0300151 struct v4l2_async_notifier subdev_notifier;
152 struct v4l2_async_subdev *async_subdevs[FIMC_MAX_SENSORS];
153
Sylwester Nawrockid3f5e0c2013-12-20 18:53:53 -0300154 bool user_subdev_api;
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300155 spinlock_t slock;
Sylwester Nawrocki403dfbe2013-05-31 11:37:22 -0300156 struct list_head pipelines;
Sakari Ailus20b85222016-11-21 14:48:30 -0200157 struct media_graph link_setup_graph;
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300158};
159
Sylwester Nawrocki4c8f0622013-04-09 11:11:58 -0300160static inline
161struct fimc_sensor_info *source_to_sensor_info(struct fimc_source_info *si)
162{
163 return container_of(si, struct fimc_sensor_info, pdata);
164}
165
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300166static inline struct fimc_md *entity_to_fimc_mdev(struct media_entity *me)
167{
Javier Martinez Canillasd10c9892015-08-19 12:35:21 -0300168 return me->graph_obj.mdev == NULL ? NULL :
169 container_of(me->graph_obj.mdev, struct fimc_md, media_dev);
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300170}
171
Sylwester Nawrockifa91f102014-02-24 11:44:50 -0300172static inline struct fimc_md *notifier_to_fimc_md(struct v4l2_async_notifier *n)
173{
174 return container_of(n, struct fimc_md, subdev_notifier);
175}
176
Sylwester Nawrockibc7584b2013-05-31 11:37:18 -0300177static inline void fimc_md_graph_lock(struct exynos_video_entity *ve)
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300178{
Javier Martinez Canillasd10c9892015-08-19 12:35:21 -0300179 mutex_lock(&ve->vdev.entity.graph_obj.mdev->graph_mutex);
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300180}
181
Sylwester Nawrockibc7584b2013-05-31 11:37:18 -0300182static inline void fimc_md_graph_unlock(struct exynos_video_entity *ve)
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300183{
Javier Martinez Canillasd10c9892015-08-19 12:35:21 -0300184 mutex_unlock(&ve->vdev.entity.graph_obj.mdev->graph_mutex);
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300185}
186
187int fimc_md_set_camclk(struct v4l2_subdev *sd, bool on);
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300188
Sylwester Nawrockie781bbe32013-03-21 14:49:16 -0300189#ifdef CONFIG_OF
190static inline bool fimc_md_is_isp_available(struct device_node *node)
191{
192 node = of_get_child_by_name(node, FIMC_IS_OF_NODE_NAME);
193 return node ? of_device_is_available(node) : false;
194}
195#else
196#define fimc_md_is_isp_available(node) (false)
197#endif /* CONFIG_OF */
198
Sylwester Nawrocki403dfbe2013-05-31 11:37:22 -0300199static inline struct v4l2_subdev *__fimc_md_get_subdev(
200 struct exynos_media_pipeline *ep,
201 unsigned int index)
202{
203 struct fimc_pipeline *p = to_fimc_pipeline(ep);
204
205 if (!p || index >= IDX_MAX)
206 return NULL;
207 else
208 return p->subdevs[index];
209}
210
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300211#endif