summaryrefslogtreecommitdiff
path: root/drivers/staging/media/atomisp/pci/atomisp_csi2.h
blob: 16ddb3ab29630e13dc064813a4d3586a935a7f6d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/* SPDX-License-Identifier: GPL-2.0 */
/*
 * Support for Medifield PNW Camera Imaging ISP subsystem.
 *
 * Copyright (c) 2010 Intel Corporation. All Rights Reserved.
 *
 * 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.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 *
 */
#ifndef __ATOMISP_CSI2_H__
#define __ATOMISP_CSI2_H__

#include <linux/gpio/consumer.h>
#include <linux/property.h>

#include <media/v4l2-subdev.h>
#include <media/v4l2-ctrls.h>

#include "../../include/linux/atomisp.h"

#define CSI2_PAD_SINK		0
#define CSI2_PAD_SOURCE		1
#define CSI2_PADS_NUM		2

#define CSI2_MAX_LANES		4
#define CSI2_MAX_LINK_FREQS	3

#define CSI2_MAX_ACPI_GPIOS	2u

struct acpi_device;
struct v4l2_device;

struct atomisp_device;
struct atomisp_sub_device;

struct atomisp_csi2_acpi_gpio_map {
	struct acpi_gpio_params params[CSI2_MAX_ACPI_GPIOS];
	struct acpi_gpio_mapping mapping[CSI2_MAX_ACPI_GPIOS + 1];
};

struct atomisp_csi2_acpi_gpio_parsing_data {
	struct acpi_device *adev;
	struct atomisp_csi2_acpi_gpio_map *map;
	u32 settings[CSI2_MAX_ACPI_GPIOS];
	unsigned int settings_count;
	unsigned int res_count;
	unsigned int map_count;
};

enum atomisp_csi2_sensor_swnodes {
	SWNODE_SENSOR,
	SWNODE_SENSOR_PORT,
	SWNODE_SENSOR_ENDPOINT,
	SWNODE_CSI2_PORT,
	SWNODE_CSI2_ENDPOINT,
	SWNODE_COUNT
};

struct atomisp_csi2_property_names {
	char clock_frequency[16];
	char rotation[9];
	char bus_type[9];
	char data_lanes[11];
	char remote_endpoint[16];
	char link_frequencies[17];
};

struct atomisp_csi2_node_names {
	char port[7];
	char endpoint[11];
	char remote_port[7];
};

struct atomisp_csi2_sensor_config {
	const char *hid;
	int lanes;
	int nr_link_freqs;
	u64 link_freqs[CSI2_MAX_LINK_FREQS];
};

struct atomisp_csi2_sensor {
	/* Append port in "-%u" format as suffix of HID */
	char name[ACPI_ID_LEN + 4];
	struct acpi_device *adev;
	int port;
	int lanes;

	/* SWNODE_COUNT + 1 for terminating NULL */
	const struct software_node *group[SWNODE_COUNT + 1];
	struct software_node swnodes[SWNODE_COUNT];
	struct atomisp_csi2_node_names node_names;
	struct atomisp_csi2_property_names prop_names;
	/* "clock-frequency", "rotation" + terminating entry */
	struct property_entry dev_properties[3];
	/* "bus-type", "data-lanes", "remote-endpoint" + "link-freq" + terminating entry */
	struct property_entry ep_properties[5];
	/* "data-lanes", "remote-endpoint" + terminating entry */
	struct property_entry csi2_properties[3];
	struct software_node_ref_args local_ref[1];
	struct software_node_ref_args remote_ref[1];
	struct software_node_ref_args vcm_ref[1];
	/* GPIO mappings storage */
	struct atomisp_csi2_acpi_gpio_map gpio_map;
};

struct atomisp_csi2_bridge {
	struct software_node csi2_node;
	char csi2_node_name[14];
	u32 data_lanes[CSI2_MAX_LANES];
	unsigned int n_sensors;
	struct atomisp_csi2_sensor sensors[ATOMISP_CAMERA_NR_PORTS];
};

struct atomisp_mipi_csi2_device {
	struct v4l2_subdev subdev;
	struct media_pad pads[CSI2_PADS_NUM];
	struct v4l2_mbus_framefmt formats[CSI2_PADS_NUM];

	struct v4l2_ctrl_handler ctrls;
	struct atomisp_device *isp;
};

int atomisp_csi2_set_ffmt(struct v4l2_subdev *sd,
			  struct v4l2_subdev_state *sd_state,
			  unsigned int which, uint16_t pad,
			  struct v4l2_mbus_framefmt *ffmt);
int atomisp_mipi_csi2_init(struct atomisp_device *isp);
void atomisp_mipi_csi2_cleanup(struct atomisp_device *isp);
void atomisp_mipi_csi2_unregister_entities(
    struct atomisp_mipi_csi2_device *csi2);
int atomisp_mipi_csi2_register_entities(struct atomisp_mipi_csi2_device *csi2,
					struct v4l2_device *vdev);
int atomisp_csi2_bridge_init(struct atomisp_device *isp);
int atomisp_csi2_bridge_parse_firmware(struct atomisp_device *isp);

void atomisp_csi2_configure(struct atomisp_sub_device *asd);

#endif /* __ATOMISP_CSI2_H__ */