2 * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd.
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.
9 #ifndef FIMC_MDEVICE_H_
10 #define FIMC_MDEVICE_H_
12 #include <linux/clk.h>
13 #include <linux/platform_device.h>
14 #include <linux/mutex.h>
16 #include <linux/pinctrl/consumer.h>
17 #include <media/media-device.h>
18 #include <media/media-entity.h>
19 #include <media/v4l2-device.h>
20 #include <media/v4l2-subdev.h>
21 #include <media/s5p_fimc.h>
23 #include "fimc-core.h"
24 #include "fimc-lite.h"
25 #include "mipi-csis.h"
27 #define FIMC_OF_NODE_NAME "fimc"
28 #define FIMC_LITE_OF_NODE_NAME "fimc-lite"
29 #define FIMC_IS_OF_NODE_NAME "fimc-is"
30 #define CSIS_OF_NODE_NAME "csis"
32 #define PINCTRL_STATE_IDLE "idle"
34 #define FIMC_MAX_SENSORS 8
35 #define FIMC_MAX_CAMCLKS 2
37 /* LCD/ISP Writeback clocks (PIXELASYNCMx) */
44 enum fimc_subdev_index
{
54 * This structure represents a chain of media entities, including a data
55 * source entity (e.g. an image sensor subdevice), a data capture entity
56 * - a video capture device node and any remaining entities.
58 struct fimc_pipeline
{
59 struct exynos_media_pipeline ep
;
60 struct list_head list
;
61 struct media_entity
*vdev_entity
;
62 struct v4l2_subdev
*subdevs
[IDX_MAX
];
65 #define to_fimc_pipeline(_ep) container_of(_ep, struct fimc_pipeline, ep)
67 struct fimc_csis_info
{
68 struct v4l2_subdev
*sd
;
72 struct fimc_camclk_info
{
75 unsigned long frequency
;
79 * struct fimc_sensor_info - image data source subdev information
80 * @pdata: sensor's atrributes passed as media device's platform data
81 * @subdev: image sensor v4l2 subdev
82 * @host: fimc device the sensor is currently linked to
84 * This data structure applies to image sensor and the writeback subdevs.
86 struct fimc_sensor_info
{
87 struct fimc_source_info pdata
;
88 struct v4l2_subdev
*subdev
;
89 struct fimc_dev
*host
;
93 * struct fimc_md - fimc media device information
94 * @csis: MIPI CSIS subdevs data
95 * @sensor: array of registered sensor subdevs
96 * @num_sensors: actual number of registered sensors
97 * @camclk: external sensor clock information
98 * @fimc: array of registered fimc devices
99 * @fimc_is: fimc-is data structure
100 * @use_isp: set to true when FIMC-IS subsystem is used
101 * @pmf: handle to the CAMCLK clock control FIMC helper device
102 * @media_dev: top level media device
103 * @v4l2_dev: top level v4l2_device holding up the subdevs
104 * @pdev: platform device this media device is hooked up into
105 * @pinctrl: camera port pinctrl handle
106 * @state_default: pinctrl default state handle
107 * @state_idle: pinctrl idle state handle
108 * @user_subdev_api: true if subdevs are not configured by the host driver
109 * @slock: spinlock protecting @sensor array
112 struct fimc_csis_info csis
[CSIS_MAX_ENTITIES
];
113 struct fimc_sensor_info sensor
[FIMC_MAX_SENSORS
];
115 struct fimc_camclk_info camclk
[FIMC_MAX_CAMCLKS
];
116 struct clk
*wbclk
[FIMC_MAX_WBCLKS
];
117 struct fimc_lite
*fimc_lite
[FIMC_LITE_MAX_DEVS
];
118 struct fimc_dev
*fimc
[FIMC_MAX_DEVS
];
119 struct fimc_is
*fimc_is
;
122 struct media_device media_dev
;
123 struct v4l2_device v4l2_dev
;
124 struct platform_device
*pdev
;
125 struct fimc_pinctrl
{
126 struct pinctrl
*pinctrl
;
127 struct pinctrl_state
*state_default
;
128 struct pinctrl_state
*state_idle
;
130 bool user_subdev_api
;
133 struct list_head pipelines
;
137 struct fimc_sensor_info
*source_to_sensor_info(struct fimc_source_info
*si
)
139 return container_of(si
, struct fimc_sensor_info
, pdata
);
142 static inline struct fimc_md
*entity_to_fimc_mdev(struct media_entity
*me
)
144 return me
->parent
== NULL
? NULL
:
145 container_of(me
->parent
, struct fimc_md
, media_dev
);
148 static inline void fimc_md_graph_lock(struct exynos_video_entity
*ve
)
150 mutex_lock(&ve
->vdev
.entity
.parent
->graph_mutex
);
153 static inline void fimc_md_graph_unlock(struct exynos_video_entity
*ve
)
155 mutex_unlock(&ve
->vdev
.entity
.parent
->graph_mutex
);
158 int fimc_md_set_camclk(struct v4l2_subdev
*sd
, bool on
);
161 static inline bool fimc_md_is_isp_available(struct device_node
*node
)
163 node
= of_get_child_by_name(node
, FIMC_IS_OF_NODE_NAME
);
164 return node
? of_device_is_available(node
) : false;
167 #define fimc_md_is_isp_available(node) (false)
168 #endif /* CONFIG_OF */
170 static inline struct v4l2_subdev
*__fimc_md_get_subdev(
171 struct exynos_media_pipeline
*ep
,
174 struct fimc_pipeline
*p
= to_fimc_pipeline(ep
);
176 if (!p
|| index
>= IDX_MAX
)
179 return p
->subdevs
[index
];