media: atomisp: csi2-bridge: Add support for setting "clock-" and "link-frequencies...
[platform/kernel/linux-starfive.git] / drivers / staging / media / atomisp / pci / atomisp_csi2.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Support for Medifield PNW Camera Imaging ISP subsystem.
4  *
5  * Copyright (c) 2010 Intel Corporation. All Rights Reserved.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License version
9  * 2 as published by the Free Software Foundation.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  *
17  */
18 #ifndef __ATOMISP_CSI2_H__
19 #define __ATOMISP_CSI2_H__
20
21 #include <linux/gpio/consumer.h>
22 #include <linux/property.h>
23
24 #include <media/v4l2-subdev.h>
25 #include <media/v4l2-ctrls.h>
26
27 #include "../../include/linux/atomisp.h"
28
29 #define CSI2_PAD_SINK           0
30 #define CSI2_PAD_SOURCE         1
31 #define CSI2_PADS_NUM           2
32
33 #define CSI2_MAX_LANES          4
34 #define CSI2_MAX_LINK_FREQS     3
35
36 #define CSI2_MAX_ACPI_GPIOS     2u
37
38 struct acpi_device;
39 struct v4l2_device;
40
41 struct atomisp_device;
42 struct atomisp_sub_device;
43
44 struct atomisp_csi2_acpi_gpio_map {
45         struct acpi_gpio_params params[CSI2_MAX_ACPI_GPIOS];
46         struct acpi_gpio_mapping mapping[CSI2_MAX_ACPI_GPIOS + 1];
47 };
48
49 struct atomisp_csi2_acpi_gpio_parsing_data {
50         struct acpi_device *adev;
51         struct atomisp_csi2_acpi_gpio_map *map;
52         u32 settings[CSI2_MAX_ACPI_GPIOS];
53         unsigned int settings_count;
54         unsigned int res_count;
55         unsigned int map_count;
56 };
57
58 enum atomisp_csi2_sensor_swnodes {
59         SWNODE_SENSOR,
60         SWNODE_SENSOR_PORT,
61         SWNODE_SENSOR_ENDPOINT,
62         SWNODE_CSI2_PORT,
63         SWNODE_CSI2_ENDPOINT,
64         SWNODE_COUNT
65 };
66
67 struct atomisp_csi2_property_names {
68         char clock_frequency[16];
69         char rotation[9];
70         char bus_type[9];
71         char data_lanes[11];
72         char remote_endpoint[16];
73         char link_frequencies[17];
74 };
75
76 struct atomisp_csi2_node_names {
77         char port[7];
78         char endpoint[11];
79         char remote_port[7];
80 };
81
82 struct atomisp_csi2_sensor_config {
83         const char *hid;
84         int lanes;
85         int nr_link_freqs;
86         u64 link_freqs[CSI2_MAX_LINK_FREQS];
87 };
88
89 struct atomisp_csi2_sensor {
90         /* Append port in "-%u" format as suffix of HID */
91         char name[ACPI_ID_LEN + 4];
92         struct acpi_device *adev;
93         int port;
94         int lanes;
95
96         /* SWNODE_COUNT + 1 for terminating NULL */
97         const struct software_node *group[SWNODE_COUNT + 1];
98         struct software_node swnodes[SWNODE_COUNT];
99         struct atomisp_csi2_node_names node_names;
100         struct atomisp_csi2_property_names prop_names;
101         /* "clock-frequency", "rotation" + terminating entry */
102         struct property_entry dev_properties[3];
103         /* "bus-type", "data-lanes", "remote-endpoint" + "link-freq" + terminating entry */
104         struct property_entry ep_properties[5];
105         /* "data-lanes", "remote-endpoint" + terminating entry */
106         struct property_entry csi2_properties[3];
107         struct software_node_ref_args local_ref[1];
108         struct software_node_ref_args remote_ref[1];
109         struct software_node_ref_args vcm_ref[1];
110         /* GPIO mappings storage */
111         struct atomisp_csi2_acpi_gpio_map gpio_map;
112 };
113
114 struct atomisp_csi2_bridge {
115         struct software_node csi2_node;
116         char csi2_node_name[14];
117         u32 data_lanes[CSI2_MAX_LANES];
118         unsigned int n_sensors;
119         struct atomisp_csi2_sensor sensors[ATOMISP_CAMERA_NR_PORTS];
120 };
121
122 struct atomisp_mipi_csi2_device {
123         struct v4l2_subdev subdev;
124         struct media_pad pads[CSI2_PADS_NUM];
125         struct v4l2_mbus_framefmt formats[CSI2_PADS_NUM];
126
127         struct v4l2_ctrl_handler ctrls;
128         struct atomisp_device *isp;
129 };
130
131 int atomisp_csi2_set_ffmt(struct v4l2_subdev *sd,
132                           struct v4l2_subdev_state *sd_state,
133                           unsigned int which, uint16_t pad,
134                           struct v4l2_mbus_framefmt *ffmt);
135 int atomisp_mipi_csi2_init(struct atomisp_device *isp);
136 void atomisp_mipi_csi2_cleanup(struct atomisp_device *isp);
137 void atomisp_mipi_csi2_unregister_entities(
138     struct atomisp_mipi_csi2_device *csi2);
139 int atomisp_mipi_csi2_register_entities(struct atomisp_mipi_csi2_device *csi2,
140                                         struct v4l2_device *vdev);
141 int atomisp_csi2_bridge_init(struct atomisp_device *isp);
142 int atomisp_csi2_bridge_parse_firmware(struct atomisp_device *isp);
143
144 void atomisp_csi2_configure(struct atomisp_sub_device *asd);
145
146 #endif /* __ATOMISP_CSI2_H__ */