media-dev.h 4.0 KB
Newer Older
1
/*
2
 * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd.
3 4 5 6 7 8 9 10 11 12 13 14
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */

#ifndef FIMC_MDEVICE_H_
#define FIMC_MDEVICE_H_

#include <linux/clk.h>
#include <linux/platform_device.h>
#include <linux/mutex.h>
15
#include <linux/pinctrl/consumer.h>
16 17 18 19 20 21
#include <media/media-device.h>
#include <media/media-entity.h>
#include <media/v4l2-device.h>
#include <media/v4l2-subdev.h>

#include "fimc-core.h"
22
#include "fimc-lite.h"
23 24
#include "mipi-csis.h"

25 26 27 28 29
#define FIMC_OF_NODE_NAME	"fimc"
#define FIMC_LITE_OF_NODE_NAME	"fimc-lite"
#define FIMC_IS_OF_NODE_NAME	"fimc-is"
#define CSIS_OF_NODE_NAME	"csis"

30 31
#define PINCTRL_STATE_IDLE	"idle"

32
/* Group IDs of sensor, MIPI-CSIS, FIMC-LITE and the writeback subdevs. */
33 34 35 36 37 38 39
#define GRP_ID_SENSOR		(1 << 8)
#define GRP_ID_FIMC_IS_SENSOR	(1 << 9)
#define GRP_ID_WRITEBACK	(1 << 10)
#define GRP_ID_CSIS		(1 << 11)
#define GRP_ID_FIMC		(1 << 12)
#define GRP_ID_FLITE		(1 << 13)
#define GRP_ID_FIMC_IS		(1 << 14)
40 41 42 43

#define FIMC_MAX_SENSORS	8
#define FIMC_MAX_CAMCLKS	2

44 45 46 47 48 49 50
/* LCD/ISP Writeback clocks (PIXELASYNCMx) */
enum {
	CLK_IDX_WB_A,
	CLK_IDX_WB_B,
	FIMC_MAX_WBCLKS
};

51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
struct fimc_csis_info {
	struct v4l2_subdev *sd;
	int id;
};

struct fimc_camclk_info {
	struct clk *clock;
	int use_count;
	unsigned long frequency;
};

/**
 * struct fimc_sensor_info - image data source subdev information
 * @pdata: sensor's atrributes passed as media device's platform data
 * @subdev: image sensor v4l2 subdev
 * @host: fimc device the sensor is currently linked to
 *
 * This data structure applies to image sensor and the writeback subdevs.
 */
struct fimc_sensor_info {
71
	struct fimc_source_info pdata;
72 73 74 75 76 77 78 79 80 81 82
	struct v4l2_subdev *subdev;
	struct fimc_dev *host;
};

/**
 * struct fimc_md - fimc media device information
 * @csis: MIPI CSIS subdevs data
 * @sensor: array of registered sensor subdevs
 * @num_sensors: actual number of registered sensors
 * @camclk: external sensor clock information
 * @fimc: array of registered fimc devices
83
 * @use_isp: set to true when FIMC-IS subsystem is used
84
 * @pmf: handle to the CAMCLK clock control FIMC helper device
85 86 87
 * @media_dev: top level media device
 * @v4l2_dev: top level v4l2_device holding up the subdevs
 * @pdev: platform device this media device is hooked up into
88 89 90
 * @pinctrl: camera port pinctrl handle
 * @state_default: pinctrl default state handle
 * @state_idle: pinctrl idle state handle
91 92 93 94 95 96 97 98
 * @user_subdev_api: true if subdevs are not configured by the host driver
 * @slock: spinlock protecting @sensor array
 */
struct fimc_md {
	struct fimc_csis_info csis[CSIS_MAX_ENTITIES];
	struct fimc_sensor_info sensor[FIMC_MAX_SENSORS];
	int num_sensors;
	struct fimc_camclk_info camclk[FIMC_MAX_CAMCLKS];
99
	struct clk *wbclk[FIMC_MAX_WBCLKS];
100
	struct fimc_lite *fimc_lite[FIMC_LITE_MAX_DEVS];
101
	struct fimc_dev *fimc[FIMC_MAX_DEVS];
102
	bool use_isp;
103
	struct device *pmf;
104 105 106
	struct media_device media_dev;
	struct v4l2_device v4l2_dev;
	struct platform_device *pdev;
107 108 109 110 111
	struct fimc_pinctrl {
		struct pinctrl *pinctrl;
		struct pinctrl_state *state_default;
		struct pinctrl_state *state_idle;
	} pinctl;
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
	bool user_subdev_api;
	spinlock_t slock;
};

#define is_subdev_pad(pad) (pad == NULL || \
	media_entity_type(pad->entity) == MEDIA_ENT_T_V4L2_SUBDEV)

#define me_subtype(me) \
	((me->type) & (MEDIA_ENT_TYPE_MASK | MEDIA_ENT_SUBTYPE_MASK))

#define subdev_has_devnode(__sd) (__sd->flags & V4L2_SUBDEV_FL_HAS_DEVNODE)

static inline struct fimc_md *entity_to_fimc_mdev(struct media_entity *me)
{
	return me->parent == NULL ? NULL :
		container_of(me->parent, struct fimc_md, media_dev);
}

static inline void fimc_md_graph_lock(struct fimc_dev *fimc)
{
132
	mutex_lock(&fimc->vid_cap.vfd.entity.parent->graph_mutex);
133 134 135 136
}

static inline void fimc_md_graph_unlock(struct fimc_dev *fimc)
{
137
	mutex_unlock(&fimc->vid_cap.vfd.entity.parent->graph_mutex);
138 139 140 141 142
}

int fimc_md_set_camclk(struct v4l2_subdev *sd, bool on);

#endif