162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * drivers/media/i2c/ccs/ccs-quirk.h
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * Generic driver for MIPI CCS/SMIA/SMIA++ compliant camera sensors
662306a36Sopenharmony_ci *
762306a36Sopenharmony_ci * Copyright (C) 2020 Intel Corporation
862306a36Sopenharmony_ci * Copyright (C) 2011--2012 Nokia Corporation
962306a36Sopenharmony_ci * Contact: Sakari Ailus <sakari.ailus@linux.intel.com>
1062306a36Sopenharmony_ci */
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_ci#ifndef __CCS_QUIRK__
1362306a36Sopenharmony_ci#define __CCS_QUIRK__
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_cistruct ccs_sensor;
1662306a36Sopenharmony_ci
1762306a36Sopenharmony_ci/**
1862306a36Sopenharmony_ci * struct ccs_quirk - quirks for sensors that deviate from SMIA++ standard
1962306a36Sopenharmony_ci *
2062306a36Sopenharmony_ci * @limits: Replace sensor->limits with values which can't be read from
2162306a36Sopenharmony_ci *	    sensor registers. Called the first time the sensor is powered up.
2262306a36Sopenharmony_ci * @post_poweron: Called always after the sensor has been fully powered on.
2362306a36Sopenharmony_ci * @pre_streamon: Called just before streaming is enabled.
2462306a36Sopenharmony_ci * @post_streamoff: Called right after stopping streaming.
2562306a36Sopenharmony_ci * @pll_flags: Return flags for the PLL calculator.
2662306a36Sopenharmony_ci * @init: Quirk initialisation, called the last in probe(). This is
2762306a36Sopenharmony_ci *	  also appropriate for adding sensor specific controls, for instance.
2862306a36Sopenharmony_ci * @reg_access: Register access quirk. The quirk may divert the access
2962306a36Sopenharmony_ci *		to another register, or no register at all.
3062306a36Sopenharmony_ci *
3162306a36Sopenharmony_ci *		@write: Is this read (false) or write (true) access?
3262306a36Sopenharmony_ci *		@reg: Pointer to the register to access
3362306a36Sopenharmony_ci *		@value: Register value, set by the caller on write, or
3462306a36Sopenharmony_ci *			by the quirk on read
3562306a36Sopenharmony_ci *		@return: 0 on success, -ENOIOCTLCMD if no register
3662306a36Sopenharmony_ci *			 access may be done by the caller (default read
3762306a36Sopenharmony_ci *			 value is zero), else negative error code on error
3862306a36Sopenharmony_ci * @flags: Quirk flags
3962306a36Sopenharmony_ci */
4062306a36Sopenharmony_cistruct ccs_quirk {
4162306a36Sopenharmony_ci	int (*limits)(struct ccs_sensor *sensor);
4262306a36Sopenharmony_ci	int (*post_poweron)(struct ccs_sensor *sensor);
4362306a36Sopenharmony_ci	int (*pre_streamon)(struct ccs_sensor *sensor);
4462306a36Sopenharmony_ci	int (*post_streamoff)(struct ccs_sensor *sensor);
4562306a36Sopenharmony_ci	unsigned long (*pll_flags)(struct ccs_sensor *sensor);
4662306a36Sopenharmony_ci	int (*init)(struct ccs_sensor *sensor);
4762306a36Sopenharmony_ci	int (*reg_access)(struct ccs_sensor *sensor, bool write, u32 *reg,
4862306a36Sopenharmony_ci			  u32 *val);
4962306a36Sopenharmony_ci	unsigned long flags;
5062306a36Sopenharmony_ci};
5162306a36Sopenharmony_ci
5262306a36Sopenharmony_ci#define CCS_QUIRK_FLAG_8BIT_READ_ONLY			(1 << 0)
5362306a36Sopenharmony_ci
5462306a36Sopenharmony_cistruct ccs_reg_8 {
5562306a36Sopenharmony_ci	u16 reg;
5662306a36Sopenharmony_ci	u8 val;
5762306a36Sopenharmony_ci};
5862306a36Sopenharmony_ci
5962306a36Sopenharmony_ci#define CCS_MK_QUIRK_REG_8(_reg, _val) \
6062306a36Sopenharmony_ci	{				\
6162306a36Sopenharmony_ci		.reg = (u16)_reg,	\
6262306a36Sopenharmony_ci		.val = _val,		\
6362306a36Sopenharmony_ci	}
6462306a36Sopenharmony_ci
6562306a36Sopenharmony_ci#define ccs_call_quirk(sensor, _quirk, ...)				\
6662306a36Sopenharmony_ci	((sensor)->minfo.quirk &&					\
6762306a36Sopenharmony_ci	 (sensor)->minfo.quirk->_quirk ?				\
6862306a36Sopenharmony_ci	 (sensor)->minfo.quirk->_quirk(sensor, ##__VA_ARGS__) : 0)
6962306a36Sopenharmony_ci
7062306a36Sopenharmony_ci#define ccs_needs_quirk(sensor, _quirk)		\
7162306a36Sopenharmony_ci	((sensor)->minfo.quirk ?			\
7262306a36Sopenharmony_ci	 (sensor)->minfo.quirk->flags & _quirk : 0)
7362306a36Sopenharmony_ci
7462306a36Sopenharmony_ciextern const struct ccs_quirk smiapp_jt8ev1_quirk;
7562306a36Sopenharmony_ciextern const struct ccs_quirk smiapp_imx125es_quirk;
7662306a36Sopenharmony_ciextern const struct ccs_quirk smiapp_jt8ew9_quirk;
7762306a36Sopenharmony_ciextern const struct ccs_quirk smiapp_tcm8500md_quirk;
7862306a36Sopenharmony_ci
7962306a36Sopenharmony_ci#endif /* __CCS_QUIRK__ */
80