1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * camss.h 4 * 5 * Qualcomm MSM Camera Subsystem - Core 6 * 7 * Copyright (c) 2015, The Linux Foundation. All rights reserved. 8 * Copyright (C) 2015-2018 Linaro Ltd. 9 */ 10 #ifndef QC_MSM_CAMSS_H 11 #define QC_MSM_CAMSS_H 12 13 #include <linux/device.h> 14 #include <linux/types.h> 15 #include <media/v4l2-async.h> 16 #include <media/v4l2-device.h> 17 #include <media/v4l2-subdev.h> 18 #include <media/media-device.h> 19 #include <media/media-entity.h> 20 21 #include "camss-csid.h" 22 #include "camss-csiphy.h" 23 #include "camss-ispif.h" 24 #include "camss-vfe.h" 25 26 #define to_camss(ptr_module) \ 27 container_of(ptr_module, struct camss, ptr_module) 28 29 #define to_device(ptr_module) \ 30 (to_camss(ptr_module)->dev) 31 32 #define module_pointer(ptr_module, index) \ 33 ((const struct ptr_module##_device (*)[]) &(ptr_module[-(index)])) 34 35 #define to_camss_index(ptr_module, index) \ 36 container_of(module_pointer(ptr_module, index), \ 37 struct camss, ptr_module) 38 39 #define to_device_index(ptr_module, index) \ 40 (to_camss_index(ptr_module, index)->dev) 41 42 #define CAMSS_RES_MAX 17 43 44 struct camss_subdev_resources { 45 char *regulators[CAMSS_RES_MAX]; 46 char *clock[CAMSS_RES_MAX]; 47 char *clock_for_reset[CAMSS_RES_MAX]; 48 u32 clock_rate[CAMSS_RES_MAX][CAMSS_RES_MAX]; 49 char *reg[CAMSS_RES_MAX]; 50 char *interrupt[CAMSS_RES_MAX]; 51 char *pd_name; 52 u8 line_num; 53 bool has_pd; 54 bool is_lite; 55 const void *ops; 56 }; 57 58 struct icc_bw_tbl { 59 u32 avg; 60 u32 peak; 61 }; 62 63 struct resources_icc { 64 char *name; 65 struct icc_bw_tbl icc_bw_tbl; 66 }; 67 68 enum pm_domain { 69 PM_DOMAIN_VFE0 = 0, 70 PM_DOMAIN_VFE1 = 1, 71 PM_DOMAIN_VFELITE = 2, /* VFELITE / TOP GDSC */ 72 }; 73 74 enum camss_version { 75 CAMSS_8x16, 76 CAMSS_8x96, 77 CAMSS_660, 78 CAMSS_845, 79 CAMSS_8250, 80 CAMSS_8280XP, 81 }; 82 83 enum icc_count { 84 ICC_DEFAULT_COUNT = 0, 85 ICC_SM8250_COUNT = 4, 86 }; 87 88 struct camss_resources { 89 enum camss_version version; 90 const char *pd_name; 91 const struct camss_subdev_resources *csiphy_res; 92 const struct camss_subdev_resources *csid_res; 93 const struct camss_subdev_resources *ispif_res; 94 const struct camss_subdev_resources *vfe_res; 95 const struct resources_icc *icc_res; 96 const unsigned int icc_path_num; 97 const unsigned int csiphy_num; 98 const unsigned int csid_num; 99 const unsigned int vfe_num; 100 }; 101 102 struct camss { 103 struct v4l2_device v4l2_dev; 104 struct v4l2_async_notifier notifier; 105 struct media_device media_dev; 106 struct device *dev; 107 struct csiphy_device *csiphy; 108 struct csid_device *csid; 109 struct ispif_device *ispif; 110 struct vfe_device *vfe; 111 atomic_t ref_count; 112 int genpd_num; 113 struct device *genpd; 114 struct device_link *genpd_link; 115 struct icc_path *icc_path[ICC_SM8250_COUNT]; 116 const struct camss_resources *res; 117 }; 118 119 struct camss_camera_interface { 120 u8 csiphy_id; 121 struct csiphy_csi2_cfg csi2; 122 }; 123 124 struct camss_async_subdev { 125 struct v4l2_async_connection asd; /* must be first */ 126 struct camss_camera_interface interface; 127 }; 128 129 struct camss_clock { 130 struct clk *clk; 131 const char *name; 132 u32 *freq; 133 u32 nfreqs; 134 }; 135 136 void camss_add_clock_margin(u64 *rate); 137 int camss_enable_clocks(int nclocks, struct camss_clock *clock, 138 struct device *dev); 139 void camss_disable_clocks(int nclocks, struct camss_clock *clock); 140 struct media_entity *camss_find_sensor(struct media_entity *entity); 141 s64 camss_get_link_freq(struct media_entity *entity, unsigned int bpp, 142 unsigned int lanes); 143 int camss_get_pixel_clock(struct media_entity *entity, u64 *pixel_clock); 144 int camss_pm_domain_on(struct camss *camss, int id); 145 void camss_pm_domain_off(struct camss *camss, int id); 146 void camss_delete(struct camss *camss); 147 148 #endif /* QC_MSM_CAMSS_H */ 149