1b873663bSTodor Tomov /* SPDX-License-Identifier: GPL-2.0 */ 2ec6859b2STodor Tomov /* 3ec6859b2STodor Tomov * camss.h 4ec6859b2STodor Tomov * 5ec6859b2STodor Tomov * Qualcomm MSM Camera Subsystem - Core 6ec6859b2STodor Tomov * 7ec6859b2STodor Tomov * Copyright (c) 2015, The Linux Foundation. All rights reserved. 8ec6859b2STodor Tomov * Copyright (C) 2015-2018 Linaro Ltd. 9ec6859b2STodor Tomov */ 10ec6859b2STodor Tomov #ifndef QC_MSM_CAMSS_H 11ec6859b2STodor Tomov #define QC_MSM_CAMSS_H 12ec6859b2STodor Tomov 1302afa816STodor Tomov #include <linux/device.h> 14ec6859b2STodor Tomov #include <linux/types.h> 15ec6859b2STodor Tomov #include <media/v4l2-async.h> 16ec6859b2STodor Tomov #include <media/v4l2-device.h> 17ec6859b2STodor Tomov #include <media/v4l2-subdev.h> 18ec6859b2STodor Tomov #include <media/media-device.h> 19ec6859b2STodor Tomov #include <media/media-entity.h> 20ec6859b2STodor Tomov 21ec6859b2STodor Tomov #include "camss-csid.h" 22ec6859b2STodor Tomov #include "camss-csiphy.h" 23ec6859b2STodor Tomov #include "camss-ispif.h" 24ec6859b2STodor Tomov #include "camss-vfe.h" 25ec6859b2STodor Tomov 26ec6859b2STodor Tomov #define to_camss(ptr_module) \ 27ec6859b2STodor Tomov container_of(ptr_module, struct camss, ptr_module) 28ec6859b2STodor Tomov 29ec6859b2STodor Tomov #define to_device(ptr_module) \ 30ec6859b2STodor Tomov (to_camss(ptr_module)->dev) 31ec6859b2STodor Tomov 32ec6859b2STodor Tomov #define module_pointer(ptr_module, index) \ 33ec6859b2STodor Tomov ((const struct ptr_module##_device (*)[]) &(ptr_module[-(index)])) 34ec6859b2STodor Tomov 35ec6859b2STodor Tomov #define to_camss_index(ptr_module, index) \ 36ec6859b2STodor Tomov container_of(module_pointer(ptr_module, index), \ 37ec6859b2STodor Tomov struct camss, ptr_module) 38ec6859b2STodor Tomov 39ec6859b2STodor Tomov #define to_device_index(ptr_module, index) \ 40ec6859b2STodor Tomov (to_camss_index(ptr_module, index)->dev) 41ec6859b2STodor Tomov 429c3e59deSTodor Tomov #define CAMSS_RES_MAX 17 43ec6859b2STodor Tomov 44ec6859b2STodor Tomov struct resources { 450d814017SBryan O'Donoghue char *regulators[CAMSS_RES_MAX]; 46ec6859b2STodor Tomov char *clock[CAMSS_RES_MAX]; 47ec6859b2STodor Tomov u32 clock_rate[CAMSS_RES_MAX][CAMSS_RES_MAX]; 48ec6859b2STodor Tomov char *reg[CAMSS_RES_MAX]; 49ec6859b2STodor Tomov char *interrupt[CAMSS_RES_MAX]; 50ec6859b2STodor Tomov }; 51ec6859b2STodor Tomov 52ec6859b2STodor Tomov struct resources_ispif { 53ec6859b2STodor Tomov char *clock[CAMSS_RES_MAX]; 54ec6859b2STodor Tomov char *clock_for_reset[CAMSS_RES_MAX]; 55ec6859b2STodor Tomov char *reg[CAMSS_RES_MAX]; 56ec6859b2STodor Tomov char *interrupt; 57ec6859b2STodor Tomov }; 58ec6859b2STodor Tomov 595ba38efbSBryan O'Donoghue struct icc_bw_tbl { 605ba38efbSBryan O'Donoghue u32 avg; 615ba38efbSBryan O'Donoghue u32 peak; 625ba38efbSBryan O'Donoghue }; 635ba38efbSBryan O'Donoghue 645ba38efbSBryan O'Donoghue struct resources_icc { 655ba38efbSBryan O'Donoghue char *name; 665ba38efbSBryan O'Donoghue struct icc_bw_tbl icc_bw_tbl; 675ba38efbSBryan O'Donoghue }; 685ba38efbSBryan O'Donoghue 6902afa816STodor Tomov enum pm_domain { 702f6f8af6SRobert Foss PM_DOMAIN_VFE0 = 0, 712f6f8af6SRobert Foss PM_DOMAIN_VFE1 = 1, 7270524567SRobert Foss PM_DOMAIN_VFELITE = 2, /* VFELITE / TOP GDSC */ 7302afa816STodor Tomov }; 7402afa816STodor Tomov 759c3e59deSTodor Tomov enum camss_version { 769c3e59deSTodor Tomov CAMSS_8x16, 779c3e59deSTodor Tomov CAMSS_8x96, 789e5d1581SAngeloGioacchino Del Regno CAMSS_660, 7996387cffSRobert Foss CAMSS_845, 8053655d2aSJonathan Marek CAMSS_8250, 819c3e59deSTodor Tomov }; 829c3e59deSTodor Tomov 835ba38efbSBryan O'Donoghue enum icc_count { 845ba38efbSBryan O'Donoghue ICC_DEFAULT_COUNT = 0, 855ba38efbSBryan O'Donoghue ICC_SM8250_COUNT = 4, 865ba38efbSBryan O'Donoghue }; 875ba38efbSBryan O'Donoghue 88ec6859b2STodor Tomov struct camss { 899c3e59deSTodor Tomov enum camss_version version; 90ec6859b2STodor Tomov struct v4l2_device v4l2_dev; 91ec6859b2STodor Tomov struct v4l2_async_notifier notifier; 92ec6859b2STodor Tomov struct media_device media_dev; 93ec6859b2STodor Tomov struct device *dev; 949c3e59deSTodor Tomov int csiphy_num; 959c3e59deSTodor Tomov struct csiphy_device *csiphy; 969c3e59deSTodor Tomov int csid_num; 979c3e59deSTodor Tomov struct csid_device *csid; 989d95baf9SRobert Foss struct ispif_device *ispif; 999c3e59deSTodor Tomov int vfe_num; 100be11096dSVladimir Zapolskiy int vfe_lite_num; 1019c3e59deSTodor Tomov struct vfe_device *vfe; 102ec6859b2STodor Tomov atomic_t ref_count; 1036b1814e2SVladimir Zapolskiy int genpd_num; 1046b1814e2SVladimir Zapolskiy struct device **genpd; 1056b1814e2SVladimir Zapolskiy struct device_link **genpd_link; 1065ba38efbSBryan O'Donoghue struct icc_path *icc_path[ICC_SM8250_COUNT]; 1075ba38efbSBryan O'Donoghue struct icc_bw_tbl icc_bw_tbl[ICC_SM8250_COUNT]; 108ec6859b2STodor Tomov }; 109ec6859b2STodor Tomov 110ec6859b2STodor Tomov struct camss_camera_interface { 111ec6859b2STodor Tomov u8 csiphy_id; 112ec6859b2STodor Tomov struct csiphy_csi2_cfg csi2; 113ec6859b2STodor Tomov }; 114ec6859b2STodor Tomov 115ec6859b2STodor Tomov struct camss_async_subdev { 116*adb2dcd5SSakari Ailus struct v4l2_async_connection asd; /* must be first */ 117ec6859b2STodor Tomov struct camss_camera_interface interface; 118ec6859b2STodor Tomov }; 119ec6859b2STodor Tomov 120ec6859b2STodor Tomov struct camss_clock { 121ec6859b2STodor Tomov struct clk *clk; 122ec6859b2STodor Tomov const char *name; 123ec6859b2STodor Tomov u32 *freq; 124ec6859b2STodor Tomov u32 nfreqs; 125ec6859b2STodor Tomov }; 126ec6859b2STodor Tomov 127ec6859b2STodor Tomov void camss_add_clock_margin(u64 *rate); 128ec6859b2STodor Tomov int camss_enable_clocks(int nclocks, struct camss_clock *clock, 129ec6859b2STodor Tomov struct device *dev); 130ec6859b2STodor Tomov void camss_disable_clocks(int nclocks, struct camss_clock *clock); 13125f5c34bSTodor Tomov struct media_entity *camss_find_sensor(struct media_entity *entity); 13278c2cc28SAndrey Konovalov s64 camss_get_link_freq(struct media_entity *entity, unsigned int bpp, 13378c2cc28SAndrey Konovalov unsigned int lanes); 1342f908577SVladimir Lypak int camss_get_pixel_clock(struct media_entity *entity, u64 *pixel_clock); 13502afa816STodor Tomov int camss_pm_domain_on(struct camss *camss, int id); 13602afa816STodor Tomov void camss_pm_domain_off(struct camss *camss, int id); 137ec6859b2STodor Tomov void camss_delete(struct camss *camss); 138ec6859b2STodor Tomov 139ec6859b2STodor Tomov #endif /* QC_MSM_CAMSS_H */ 140