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> |
| 13 | #include <linux/platform_device.h> |
| 14 | #include <linux/mutex.h> |
| 15 | #include <media/media-device.h> |
| 16 | #include <media/media-entity.h> |
| 17 | #include <media/v4l2-device.h> |
| 18 | #include <media/v4l2-subdev.h> |
| 19 | |
| 20 | #include "fimc-core.h" |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 21 | #include "fimc-lite.h" |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 22 | #include "mipi-csis.h" |
| 23 | |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 24 | /* Group IDs of sensor, MIPI-CSIS, FIMC-LITE and the writeback subdevs. */ |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 25 | #define SENSOR_GROUP_ID (1 << 8) |
| 26 | #define CSIS_GROUP_ID (1 << 9) |
| 27 | #define WRITEBACK_GROUP_ID (1 << 10) |
Sylwester Nawrocki | 693f5c4 | 2012-04-20 18:57:25 -0300 | [diff] [blame] | 28 | #define FIMC_GROUP_ID (1 << 11) |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 29 | #define FLITE_GROUP_ID (1 << 12) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 30 | |
| 31 | #define FIMC_MAX_SENSORS 8 |
| 32 | #define FIMC_MAX_CAMCLKS 2 |
| 33 | |
| 34 | struct fimc_csis_info { |
| 35 | struct v4l2_subdev *sd; |
| 36 | int id; |
| 37 | }; |
| 38 | |
| 39 | struct fimc_camclk_info { |
| 40 | struct clk *clock; |
| 41 | int use_count; |
| 42 | unsigned long frequency; |
| 43 | }; |
| 44 | |
| 45 | /** |
| 46 | * struct fimc_sensor_info - image data source subdev information |
| 47 | * @pdata: sensor's atrributes passed as media device's platform data |
| 48 | * @subdev: image sensor v4l2 subdev |
| 49 | * @host: fimc device the sensor is currently linked to |
| 50 | * @clk_on: sclk_cam clock's state associated with this subdev |
| 51 | * |
| 52 | * This data structure applies to image sensor and the writeback subdevs. |
| 53 | */ |
| 54 | struct fimc_sensor_info { |
| 55 | struct s5p_fimc_isp_info *pdata; |
| 56 | struct v4l2_subdev *subdev; |
| 57 | struct fimc_dev *host; |
| 58 | bool clk_on; |
| 59 | }; |
| 60 | |
| 61 | /** |
| 62 | * struct fimc_md - fimc media device information |
| 63 | * @csis: MIPI CSIS subdevs data |
| 64 | * @sensor: array of registered sensor subdevs |
| 65 | * @num_sensors: actual number of registered sensors |
| 66 | * @camclk: external sensor clock information |
| 67 | * @fimc: array of registered fimc devices |
| 68 | * @media_dev: top level media device |
| 69 | * @v4l2_dev: top level v4l2_device holding up the subdevs |
| 70 | * @pdev: platform device this media device is hooked up into |
| 71 | * @user_subdev_api: true if subdevs are not configured by the host driver |
| 72 | * @slock: spinlock protecting @sensor array |
| 73 | */ |
| 74 | struct fimc_md { |
| 75 | struct fimc_csis_info csis[CSIS_MAX_ENTITIES]; |
| 76 | struct fimc_sensor_info sensor[FIMC_MAX_SENSORS]; |
| 77 | int num_sensors; |
| 78 | struct fimc_camclk_info camclk[FIMC_MAX_CAMCLKS]; |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 79 | struct fimc_lite *fimc_lite[FIMC_LITE_MAX_DEVS]; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 80 | struct fimc_dev *fimc[FIMC_MAX_DEVS]; |
| 81 | struct media_device media_dev; |
| 82 | struct v4l2_device v4l2_dev; |
| 83 | struct platform_device *pdev; |
| 84 | bool user_subdev_api; |
| 85 | spinlock_t slock; |
| 86 | }; |
| 87 | |
| 88 | #define is_subdev_pad(pad) (pad == NULL || \ |
| 89 | media_entity_type(pad->entity) == MEDIA_ENT_T_V4L2_SUBDEV) |
| 90 | |
| 91 | #define me_subtype(me) \ |
| 92 | ((me->type) & (MEDIA_ENT_TYPE_MASK | MEDIA_ENT_SUBTYPE_MASK)) |
| 93 | |
| 94 | #define subdev_has_devnode(__sd) (__sd->flags & V4L2_SUBDEV_FL_HAS_DEVNODE) |
| 95 | |
| 96 | static inline struct fimc_md *entity_to_fimc_mdev(struct media_entity *me) |
| 97 | { |
| 98 | return me->parent == NULL ? NULL : |
| 99 | container_of(me->parent, struct fimc_md, media_dev); |
| 100 | } |
| 101 | |
| 102 | static inline void fimc_md_graph_lock(struct fimc_dev *fimc) |
| 103 | { |
| 104 | BUG_ON(fimc->vid_cap.vfd == NULL); |
| 105 | mutex_lock(&fimc->vid_cap.vfd->entity.parent->graph_mutex); |
| 106 | } |
| 107 | |
| 108 | static inline void fimc_md_graph_unlock(struct fimc_dev *fimc) |
| 109 | { |
| 110 | BUG_ON(fimc->vid_cap.vfd == NULL); |
| 111 | mutex_unlock(&fimc->vid_cap.vfd->entity.parent->graph_mutex); |
| 112 | } |
| 113 | |
| 114 | int fimc_md_set_camclk(struct v4l2_subdev *sd, bool on); |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 115 | void fimc_pipeline_prepare(struct fimc_pipeline *p, struct media_entity *me); |
| 116 | int fimc_pipeline_initialize(struct fimc_pipeline *p, struct media_entity *me, |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 117 | bool resume); |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 118 | int fimc_pipeline_shutdown(struct fimc_pipeline *p); |
| 119 | int fimc_pipeline_s_power(struct fimc_pipeline *p, bool state); |
| 120 | int fimc_pipeline_s_stream(struct fimc_pipeline *p, bool state); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 121 | |
| 122 | #endif |