1 /* 2 * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. 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> 13 #include <linux/platform_device.h> 14 #include <linux/mutex.h> 15 #include <linux/of.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 22 #include "fimc-core.h" 23 #include "fimc-lite.h" 24 #include "mipi-csis.h" 25 26 #define FIMC_OF_NODE_NAME "fimc" 27 #define FIMC_LITE_OF_NODE_NAME "fimc-lite" 28 #define FIMC_IS_OF_NODE_NAME "fimc-is" 29 #define CSIS_OF_NODE_NAME "csis" 30 31 #define PINCTRL_STATE_IDLE "idle" 32 33 #define FIMC_MAX_SENSORS 8 34 #define FIMC_MAX_CAMCLKS 2 35 36 /* LCD/ISP Writeback clocks (PIXELASYNCMx) */ 37 enum { 38 CLK_IDX_WB_A, 39 CLK_IDX_WB_B, 40 FIMC_MAX_WBCLKS 41 }; 42 43 struct fimc_csis_info { 44 struct v4l2_subdev *sd; 45 int id; 46 }; 47 48 struct fimc_camclk_info { 49 struct clk *clock; 50 int use_count; 51 unsigned long frequency; 52 }; 53 54 /** 55 * struct fimc_sensor_info - image data source subdev information 56 * @pdata: sensor's atrributes passed as media device's platform data 57 * @subdev: image sensor v4l2 subdev 58 * @host: fimc device the sensor is currently linked to 59 * 60 * This data structure applies to image sensor and the writeback subdevs. 61 */ 62 struct fimc_sensor_info { 63 struct fimc_source_info pdata; 64 struct v4l2_subdev *subdev; 65 struct fimc_dev *host; 66 }; 67 68 /** 69 * struct fimc_md - fimc media device information 70 * @csis: MIPI CSIS subdevs data 71 * @sensor: array of registered sensor subdevs 72 * @num_sensors: actual number of registered sensors 73 * @camclk: external sensor clock information 74 * @fimc: array of registered fimc devices 75 * @fimc_is: fimc-is data structure 76 * @use_isp: set to true when FIMC-IS subsystem is used 77 * @pmf: handle to the CAMCLK clock control FIMC helper device 78 * @media_dev: top level media device 79 * @v4l2_dev: top level v4l2_device holding up the subdevs 80 * @pdev: platform device this media device is hooked up into 81 * @pinctrl: camera port pinctrl handle 82 * @state_default: pinctrl default state handle 83 * @state_idle: pinctrl idle state handle 84 * @user_subdev_api: true if subdevs are not configured by the host driver 85 * @slock: spinlock protecting @sensor array 86 */ 87 struct fimc_md { 88 struct fimc_csis_info csis[CSIS_MAX_ENTITIES]; 89 struct fimc_sensor_info sensor[FIMC_MAX_SENSORS]; 90 int num_sensors; 91 struct fimc_camclk_info camclk[FIMC_MAX_CAMCLKS]; 92 struct clk *wbclk[FIMC_MAX_WBCLKS]; 93 struct fimc_lite *fimc_lite[FIMC_LITE_MAX_DEVS]; 94 struct fimc_dev *fimc[FIMC_MAX_DEVS]; 95 struct fimc_is *fimc_is; 96 bool use_isp; 97 struct device *pmf; 98 struct media_device media_dev; 99 struct v4l2_device v4l2_dev; 100 struct platform_device *pdev; 101 struct fimc_pinctrl { 102 struct pinctrl *pinctrl; 103 struct pinctrl_state *state_default; 104 struct pinctrl_state *state_idle; 105 } pinctl; 106 bool user_subdev_api; 107 spinlock_t slock; 108 }; 109 110 #define is_subdev_pad(pad) (pad == NULL || \ 111 media_entity_type(pad->entity) == MEDIA_ENT_T_V4L2_SUBDEV) 112 113 #define me_subtype(me) \ 114 ((me->type) & (MEDIA_ENT_TYPE_MASK | MEDIA_ENT_SUBTYPE_MASK)) 115 116 #define subdev_has_devnode(__sd) (__sd->flags & V4L2_SUBDEV_FL_HAS_DEVNODE) 117 118 static inline source_to_sensor_info(struct fimc_source_info * si)119struct fimc_sensor_info *source_to_sensor_info(struct fimc_source_info *si) 120 { 121 return container_of(si, struct fimc_sensor_info, pdata); 122 } 123 entity_to_fimc_mdev(struct media_entity * me)124static inline struct fimc_md *entity_to_fimc_mdev(struct media_entity *me) 125 { 126 return me->parent == NULL ? NULL : 127 container_of(me->parent, struct fimc_md, media_dev); 128 } 129 fimc_md_graph_lock(struct fimc_dev * fimc)130static inline void fimc_md_graph_lock(struct fimc_dev *fimc) 131 { 132 mutex_lock(&fimc->vid_cap.vfd.entity.parent->graph_mutex); 133 } 134 fimc_md_graph_unlock(struct fimc_dev * fimc)135static inline void fimc_md_graph_unlock(struct fimc_dev *fimc) 136 { 137 mutex_unlock(&fimc->vid_cap.vfd.entity.parent->graph_mutex); 138 } 139 140 int fimc_md_set_camclk(struct v4l2_subdev *sd, bool on); 141 142 #ifdef CONFIG_OF fimc_md_is_isp_available(struct device_node * node)143static inline bool fimc_md_is_isp_available(struct device_node *node) 144 { 145 node = of_get_child_by_name(node, FIMC_IS_OF_NODE_NAME); 146 return node ? of_device_is_available(node) : false; 147 } 148 #else 149 #define fimc_md_is_isp_available(node) (false) 150 #endif /* CONFIG_OF */ 151 152 #endif 153