162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * CCS static data in-memory data structure definitions 462306a36Sopenharmony_ci * 562306a36Sopenharmony_ci * Copyright 2019--2020 Intel Corporation 662306a36Sopenharmony_ci */ 762306a36Sopenharmony_ci 862306a36Sopenharmony_ci#ifndef __CCS_DATA_H__ 962306a36Sopenharmony_ci#define __CCS_DATA_H__ 1062306a36Sopenharmony_ci 1162306a36Sopenharmony_ci#include <linux/types.h> 1262306a36Sopenharmony_ci 1362306a36Sopenharmony_cistruct device; 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_ci/** 1662306a36Sopenharmony_ci * struct ccs_data_block_version - CCS static data version 1762306a36Sopenharmony_ci * @version_major: Major version number 1862306a36Sopenharmony_ci * @version_minor: Minor version number 1962306a36Sopenharmony_ci * @date_year: Year 2062306a36Sopenharmony_ci * @date_month: Month 2162306a36Sopenharmony_ci * @date_day: Day 2262306a36Sopenharmony_ci */ 2362306a36Sopenharmony_cistruct ccs_data_block_version { 2462306a36Sopenharmony_ci u16 version_major; 2562306a36Sopenharmony_ci u16 version_minor; 2662306a36Sopenharmony_ci u16 date_year; 2762306a36Sopenharmony_ci u8 date_month; 2862306a36Sopenharmony_ci u8 date_day; 2962306a36Sopenharmony_ci}; 3062306a36Sopenharmony_ci 3162306a36Sopenharmony_ci/** 3262306a36Sopenharmony_ci * struct ccs_reg - CCS register value 3362306a36Sopenharmony_ci * @addr: The 16-bit address of the register 3462306a36Sopenharmony_ci * @len: Length of the data 3562306a36Sopenharmony_ci * @value: Data 3662306a36Sopenharmony_ci */ 3762306a36Sopenharmony_cistruct ccs_reg { 3862306a36Sopenharmony_ci u16 addr; 3962306a36Sopenharmony_ci u16 len; 4062306a36Sopenharmony_ci u8 *value; 4162306a36Sopenharmony_ci}; 4262306a36Sopenharmony_ci 4362306a36Sopenharmony_ci/** 4462306a36Sopenharmony_ci * struct ccs_if_rule - CCS static data if rule 4562306a36Sopenharmony_ci * @addr: Register address 4662306a36Sopenharmony_ci * @value: Register value 4762306a36Sopenharmony_ci * @mask: Value applied to both actual register value and @value 4862306a36Sopenharmony_ci */ 4962306a36Sopenharmony_cistruct ccs_if_rule { 5062306a36Sopenharmony_ci u16 addr; 5162306a36Sopenharmony_ci u8 value; 5262306a36Sopenharmony_ci u8 mask; 5362306a36Sopenharmony_ci}; 5462306a36Sopenharmony_ci 5562306a36Sopenharmony_ci/** 5662306a36Sopenharmony_ci * struct ccs_frame_format_desc - CCS frame format descriptor 5762306a36Sopenharmony_ci * @pixelcode: The pixelcode; CCS_DATA_BLOCK_FFD_PIXELCODE_* 5862306a36Sopenharmony_ci * @value: Value related to the pixelcode 5962306a36Sopenharmony_ci */ 6062306a36Sopenharmony_cistruct ccs_frame_format_desc { 6162306a36Sopenharmony_ci u8 pixelcode; 6262306a36Sopenharmony_ci u16 value; 6362306a36Sopenharmony_ci}; 6462306a36Sopenharmony_ci 6562306a36Sopenharmony_ci/** 6662306a36Sopenharmony_ci * struct ccs_frame_format_descs - A series of CCS frame format descriptors 6762306a36Sopenharmony_ci * @num_column_descs: Number of column descriptors 6862306a36Sopenharmony_ci * @num_row_descs: Number of row descriptors 6962306a36Sopenharmony_ci * @column_descs: Column descriptors 7062306a36Sopenharmony_ci * @row_descs: Row descriptors 7162306a36Sopenharmony_ci */ 7262306a36Sopenharmony_cistruct ccs_frame_format_descs { 7362306a36Sopenharmony_ci u8 num_column_descs; 7462306a36Sopenharmony_ci u8 num_row_descs; 7562306a36Sopenharmony_ci struct ccs_frame_format_desc *column_descs; 7662306a36Sopenharmony_ci struct ccs_frame_format_desc *row_descs; 7762306a36Sopenharmony_ci}; 7862306a36Sopenharmony_ci 7962306a36Sopenharmony_ci/** 8062306a36Sopenharmony_ci * struct ccs_pdaf_readout - CCS PDAF data readout descriptor 8162306a36Sopenharmony_ci * @pdaf_readout_info_order: PDAF readout order 8262306a36Sopenharmony_ci * @ffd: Frame format of PDAF data 8362306a36Sopenharmony_ci */ 8462306a36Sopenharmony_cistruct ccs_pdaf_readout { 8562306a36Sopenharmony_ci u8 pdaf_readout_info_order; 8662306a36Sopenharmony_ci struct ccs_frame_format_descs *ffd; 8762306a36Sopenharmony_ci}; 8862306a36Sopenharmony_ci 8962306a36Sopenharmony_ci/** 9062306a36Sopenharmony_ci * struct ccs_rule - A CCS static data rule 9162306a36Sopenharmony_ci * @num_if_rules: Number of if rules 9262306a36Sopenharmony_ci * @if_rules: If rules 9362306a36Sopenharmony_ci * @num_read_only_regs: Number of read-only registers 9462306a36Sopenharmony_ci * @read_only_regs: Read-only registers 9562306a36Sopenharmony_ci * @num_manufacturer_regs: Number of manufacturer-specific registers 9662306a36Sopenharmony_ci * @manufacturer_regs: Manufacturer-specific registers 9762306a36Sopenharmony_ci * @frame_format: Frame format 9862306a36Sopenharmony_ci * @pdaf_readout: PDAF readout 9962306a36Sopenharmony_ci */ 10062306a36Sopenharmony_cistruct ccs_rule { 10162306a36Sopenharmony_ci size_t num_if_rules; 10262306a36Sopenharmony_ci struct ccs_if_rule *if_rules; 10362306a36Sopenharmony_ci size_t num_read_only_regs; 10462306a36Sopenharmony_ci struct ccs_reg *read_only_regs; 10562306a36Sopenharmony_ci size_t num_manufacturer_regs; 10662306a36Sopenharmony_ci struct ccs_reg *manufacturer_regs; 10762306a36Sopenharmony_ci struct ccs_frame_format_descs *frame_format; 10862306a36Sopenharmony_ci struct ccs_pdaf_readout *pdaf_readout; 10962306a36Sopenharmony_ci}; 11062306a36Sopenharmony_ci 11162306a36Sopenharmony_ci/** 11262306a36Sopenharmony_ci * struct ccs_pdaf_pix_loc_block_desc - PDAF pixel location block descriptor 11362306a36Sopenharmony_ci * @block_type_id: Block type identifier, from 0 to n 11462306a36Sopenharmony_ci * @repeat_x: Number of times this block is repeated to right 11562306a36Sopenharmony_ci */ 11662306a36Sopenharmony_cistruct ccs_pdaf_pix_loc_block_desc { 11762306a36Sopenharmony_ci u8 block_type_id; 11862306a36Sopenharmony_ci u16 repeat_x; 11962306a36Sopenharmony_ci}; 12062306a36Sopenharmony_ci 12162306a36Sopenharmony_ci/** 12262306a36Sopenharmony_ci * struct ccs_pdaf_pix_loc_block_desc_group - PDAF pixel location block 12362306a36Sopenharmony_ci * descriptor group 12462306a36Sopenharmony_ci * @repeat_y: Number of times the group is repeated down 12562306a36Sopenharmony_ci * @num_block_descs: Number of block descriptors in @block_descs 12662306a36Sopenharmony_ci * @block_descs: Block descriptors 12762306a36Sopenharmony_ci */ 12862306a36Sopenharmony_cistruct ccs_pdaf_pix_loc_block_desc_group { 12962306a36Sopenharmony_ci u8 repeat_y; 13062306a36Sopenharmony_ci u16 num_block_descs; 13162306a36Sopenharmony_ci struct ccs_pdaf_pix_loc_block_desc *block_descs; 13262306a36Sopenharmony_ci}; 13362306a36Sopenharmony_ci 13462306a36Sopenharmony_ci/** 13562306a36Sopenharmony_ci * struct ccs_pdaf_pix_loc_pixel_desc - PDAF pixel location block descriptor 13662306a36Sopenharmony_ci * @pixel_type: Type of the pixel; CCS_DATA_PDAF_PIXEL_TYPE_* 13762306a36Sopenharmony_ci * @small_offset_x: offset X coordinate 13862306a36Sopenharmony_ci * @small_offset_y: offset Y coordinate 13962306a36Sopenharmony_ci */ 14062306a36Sopenharmony_cistruct ccs_pdaf_pix_loc_pixel_desc { 14162306a36Sopenharmony_ci u8 pixel_type; 14262306a36Sopenharmony_ci u8 small_offset_x; 14362306a36Sopenharmony_ci u8 small_offset_y; 14462306a36Sopenharmony_ci}; 14562306a36Sopenharmony_ci 14662306a36Sopenharmony_ci/** 14762306a36Sopenharmony_ci * struct ccs_pdaf_pix_loc_pixel_desc_group - PDAF pixel location pixel 14862306a36Sopenharmony_ci * descriptor group 14962306a36Sopenharmony_ci * @num_descs: Number of descriptors in @descs 15062306a36Sopenharmony_ci * @descs: PDAF pixel location pixel descriptors 15162306a36Sopenharmony_ci */ 15262306a36Sopenharmony_cistruct ccs_pdaf_pix_loc_pixel_desc_group { 15362306a36Sopenharmony_ci u8 num_descs; 15462306a36Sopenharmony_ci struct ccs_pdaf_pix_loc_pixel_desc *descs; 15562306a36Sopenharmony_ci}; 15662306a36Sopenharmony_ci 15762306a36Sopenharmony_ci/** 15862306a36Sopenharmony_ci * struct ccs_pdaf_pix_loc - PDAF pixel locations 15962306a36Sopenharmony_ci * @main_offset_x: Start X coordinate of PDAF pixel blocks 16062306a36Sopenharmony_ci * @main_offset_y: Start Y coordinate of PDAF pixel blocks 16162306a36Sopenharmony_ci * @global_pdaf_type: PDAF pattern type 16262306a36Sopenharmony_ci * @block_width: Width of a block in pixels 16362306a36Sopenharmony_ci * @block_height: Heigth of a block in pixels 16462306a36Sopenharmony_ci * @num_block_desc_groups: Number of block descriptor groups 16562306a36Sopenharmony_ci * @block_desc_groups: Block descriptor groups 16662306a36Sopenharmony_ci * @num_pixel_desc_grups: Number of pixel descriptor groups 16762306a36Sopenharmony_ci * @pixel_desc_groups: Pixel descriptor groups 16862306a36Sopenharmony_ci */ 16962306a36Sopenharmony_cistruct ccs_pdaf_pix_loc { 17062306a36Sopenharmony_ci u16 main_offset_x; 17162306a36Sopenharmony_ci u16 main_offset_y; 17262306a36Sopenharmony_ci u8 global_pdaf_type; 17362306a36Sopenharmony_ci u8 block_width; 17462306a36Sopenharmony_ci u8 block_height; 17562306a36Sopenharmony_ci u16 num_block_desc_groups; 17662306a36Sopenharmony_ci struct ccs_pdaf_pix_loc_block_desc_group *block_desc_groups; 17762306a36Sopenharmony_ci u8 num_pixel_desc_grups; 17862306a36Sopenharmony_ci struct ccs_pdaf_pix_loc_pixel_desc_group *pixel_desc_groups; 17962306a36Sopenharmony_ci}; 18062306a36Sopenharmony_ci 18162306a36Sopenharmony_ci/** 18262306a36Sopenharmony_ci * struct ccs_data_container - In-memory CCS static data 18362306a36Sopenharmony_ci * @version: CCS static data version 18462306a36Sopenharmony_ci * @num_sensor_read_only_regs: Number of the read-only registers for the sensor 18562306a36Sopenharmony_ci * @sensor_read_only_regs: Read-only registers for the sensor 18662306a36Sopenharmony_ci * @num_sensor_manufacturer_regs: Number of the manufacturer-specific registers 18762306a36Sopenharmony_ci * for the sensor 18862306a36Sopenharmony_ci * @sensor_manufacturer_regs: Manufacturer-specific registers for the sensor 18962306a36Sopenharmony_ci * @num_sensor_rules: Number of rules for the sensor 19062306a36Sopenharmony_ci * @sensor_rules: Rules for the sensor 19162306a36Sopenharmony_ci * @num_module_read_only_regs: Number of the read-only registers for the module 19262306a36Sopenharmony_ci * @module_read_only_regs: Read-only registers for the module 19362306a36Sopenharmony_ci * @num_module_manufacturer_regs: Number of the manufacturer-specific registers 19462306a36Sopenharmony_ci * for the module 19562306a36Sopenharmony_ci * @module_manufacturer_regs: Manufacturer-specific registers for the module 19662306a36Sopenharmony_ci * @num_module_rules: Number of rules for the module 19762306a36Sopenharmony_ci * @module_rules: Rules for the module 19862306a36Sopenharmony_ci * @sensor_pdaf: PDAF data for the sensor 19962306a36Sopenharmony_ci * @module_pdaf: PDAF data for the module 20062306a36Sopenharmony_ci * @license_length: Lenght of the license data 20162306a36Sopenharmony_ci * @license: License data 20262306a36Sopenharmony_ci * @end: Whether or not there's an end block 20362306a36Sopenharmony_ci * @backing: Raw data, pointed to from elsewhere so keep it around 20462306a36Sopenharmony_ci */ 20562306a36Sopenharmony_cistruct ccs_data_container { 20662306a36Sopenharmony_ci struct ccs_data_block_version *version; 20762306a36Sopenharmony_ci size_t num_sensor_read_only_regs; 20862306a36Sopenharmony_ci struct ccs_reg *sensor_read_only_regs; 20962306a36Sopenharmony_ci size_t num_sensor_manufacturer_regs; 21062306a36Sopenharmony_ci struct ccs_reg *sensor_manufacturer_regs; 21162306a36Sopenharmony_ci size_t num_sensor_rules; 21262306a36Sopenharmony_ci struct ccs_rule *sensor_rules; 21362306a36Sopenharmony_ci size_t num_module_read_only_regs; 21462306a36Sopenharmony_ci struct ccs_reg *module_read_only_regs; 21562306a36Sopenharmony_ci size_t num_module_manufacturer_regs; 21662306a36Sopenharmony_ci struct ccs_reg *module_manufacturer_regs; 21762306a36Sopenharmony_ci size_t num_module_rules; 21862306a36Sopenharmony_ci struct ccs_rule *module_rules; 21962306a36Sopenharmony_ci struct ccs_pdaf_pix_loc *sensor_pdaf; 22062306a36Sopenharmony_ci struct ccs_pdaf_pix_loc *module_pdaf; 22162306a36Sopenharmony_ci size_t license_length; 22262306a36Sopenharmony_ci char *license; 22362306a36Sopenharmony_ci bool end; 22462306a36Sopenharmony_ci void *backing; 22562306a36Sopenharmony_ci}; 22662306a36Sopenharmony_ci 22762306a36Sopenharmony_ciint ccs_data_parse(struct ccs_data_container *ccsdata, const void *data, 22862306a36Sopenharmony_ci size_t len, struct device *dev, bool verbose); 22962306a36Sopenharmony_ci 23062306a36Sopenharmony_ci#endif /* __CCS_DATA_H__ */ 231