Merge branch 'jeffm-discard-4.3' into for-linus-4.3
[linux-2.6-block.git] / drivers / media / i2c / smiapp / smiapp-quirk.h
CommitLineData
ccfc97bd 1/*
cb7a01ac 2 * drivers/media/i2c/smiapp/smiapp-quirk.h
ccfc97bd
SA
3 *
4 * Generic driver for SMIA/SMIA++ compliant camera modules
5 *
6 * Copyright (C) 2011--2012 Nokia Corporation
8c5dff90 7 * Contact: Sakari Ailus <sakari.ailus@iki.fi>
ccfc97bd
SA
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * version 2 as published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
ccfc97bd
SA
17 */
18
19#ifndef __SMIAPP_QUIRK__
20#define __SMIAPP_QUIRK__
21
22struct smiapp_sensor;
23
24/**
25 * struct smiapp_quirk - quirks for sensors that deviate from SMIA++ standard
26 *
27 * @limits: Replace sensor->limits with values which can't be read from
28 * sensor registers. Called the first time the sensor is powered up.
29 * @post_poweron: Called always after the sensor has been fully powered on.
30 * @pre_streamon: Called just before streaming is enabled.
31 * @post_streamon: Called right after stopping streaming.
0d825a12
SA
32 * @pll_flags: Return flags for the PLL calculator.
33 * @init: Quirk initialisation, called the last in probe(). This is
34 * also appropriate for adding sensor specific controls, for instance.
6f7481b6
SA
35 * @reg_access: Register access quirk. The quirk may divert the access
36 * to another register, or no register at all.
37 *
38 * @write: Is this read (false) or write (true) access?
39 * @reg: Pointer to the register to access
40 * @value: Register value, set by the caller on write, or
41 * by the quirk on read
42 *
43 * @return: 0 on success, -ENOIOCTLCMD if no register
44 * access may be done by the caller (default read
45 * value is zero), else negative error code on error
ccfc97bd
SA
46 */
47struct smiapp_quirk {
48 int (*limits)(struct smiapp_sensor *sensor);
49 int (*post_poweron)(struct smiapp_sensor *sensor);
50 int (*pre_streamon)(struct smiapp_sensor *sensor);
51 int (*post_streamoff)(struct smiapp_sensor *sensor);
03efb2a0 52 unsigned long (*pll_flags)(struct smiapp_sensor *sensor);
0d825a12 53 int (*init)(struct smiapp_sensor *sensor);
6f7481b6
SA
54 int (*reg_access)(struct smiapp_sensor *sensor, bool write, u32 *reg,
55 u32 *val);
ccfc97bd
SA
56 unsigned long flags;
57};
58
caf447bf 59#define SMIAPP_QUIRK_FLAG_8BIT_READ_ONLY (1 << 0)
ccfc97bd
SA
60
61struct smiapp_reg_8 {
62 u16 reg;
63 u8 val;
64};
65
66void smiapp_replace_limit(struct smiapp_sensor *sensor,
67 u32 limit, u32 val);
68
125a1c06
SA
69#define SMIAPP_MK_QUIRK_REG_8(_reg, _val) \
70 { \
71 .reg = (u16)_reg, \
72 .val = _val, \
73 }
74
3b1635e0
SA
75#define smiapp_call_quirk(sensor, _quirk, ...) \
76 ((sensor)->minfo.quirk && \
77 (sensor)->minfo.quirk->_quirk ? \
78 (sensor)->minfo.quirk->_quirk(sensor, ##__VA_ARGS__) : 0)
ccfc97bd 79
3b1635e0
SA
80#define smiapp_needs_quirk(sensor, _quirk) \
81 ((sensor)->minfo.quirk ? \
82 (sensor)->minfo.quirk->flags & _quirk : 0)
ccfc97bd
SA
83
84extern const struct smiapp_quirk smiapp_jt8ev1_quirk;
85extern const struct smiapp_quirk smiapp_imx125es_quirk;
86extern const struct smiapp_quirk smiapp_jt8ew9_quirk;
87extern const struct smiapp_quirk smiapp_tcm8500md_quirk;
88
89#endif /* __SMIAPP_QUIRK__ */