xref: /openbmc/linux/include/linux/mfd/iqs62x.h (revision 1de785a5)
1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3  * Azoteq IQS620A/621/622/624/625 Multi-Function Sensors
4  *
5  * Copyright (C) 2019 Jeff LaBundy <jeff@labundy.com>
6  */
7 
8 #ifndef __LINUX_MFD_IQS62X_H
9 #define __LINUX_MFD_IQS62X_H
10 
11 #define IQS620_PROD_NUM				0x41
12 #define IQS621_PROD_NUM				0x46
13 #define IQS622_PROD_NUM				0x42
14 #define IQS624_PROD_NUM				0x43
15 #define IQS625_PROD_NUM				0x4E
16 
17 #define IQS620_HW_NUM_V0			0x82
18 #define IQS620_HW_NUM_V1			IQS620_HW_NUM_V0
19 #define IQS620_HW_NUM_V2			IQS620_HW_NUM_V0
20 #define IQS620_HW_NUM_V3			0x92
21 
22 #define IQS621_ALS_FLAGS			0x16
23 #define IQS622_ALS_FLAGS			0x14
24 
25 #define IQS624_HALL_UI				0x70
26 #define IQS624_HALL_UI_WHL_EVENT		BIT(4)
27 #define IQS624_HALL_UI_INT_EVENT		BIT(3)
28 #define IQS624_HALL_UI_AUTO_CAL			BIT(2)
29 
30 #define IQS624_INTERVAL_DIV			0x7D
31 
32 #define IQS620_GLBL_EVENT_MASK			0xD7
33 #define IQS620_GLBL_EVENT_MASK_PMU		BIT(6)
34 
35 #define IQS62X_NUM_KEYS				16
36 #define IQS62X_NUM_EVENTS			(IQS62X_NUM_KEYS + 6)
37 
38 #define IQS62X_EVENT_SIZE			10
39 
40 enum iqs62x_ui_sel {
41 	IQS62X_UI_PROX,
42 	IQS62X_UI_SAR1,
43 };
44 
45 enum iqs62x_event_reg {
46 	IQS62X_EVENT_NONE,
47 	IQS62X_EVENT_SYS,
48 	IQS62X_EVENT_PROX,
49 	IQS62X_EVENT_HYST,
50 	IQS62X_EVENT_HALL,
51 	IQS62X_EVENT_ALS,
52 	IQS62X_EVENT_IR,
53 	IQS62X_EVENT_WHEEL,
54 	IQS62X_EVENT_INTER,
55 	IQS62X_EVENT_UI_LO,
56 	IQS62X_EVENT_UI_HI,
57 };
58 
59 enum iqs62x_event_flag {
60 	/* keys */
61 	IQS62X_EVENT_PROX_CH0_T,
62 	IQS62X_EVENT_PROX_CH0_P,
63 	IQS62X_EVENT_PROX_CH1_T,
64 	IQS62X_EVENT_PROX_CH1_P,
65 	IQS62X_EVENT_PROX_CH2_T,
66 	IQS62X_EVENT_PROX_CH2_P,
67 	IQS62X_EVENT_HYST_POS_T,
68 	IQS62X_EVENT_HYST_POS_P,
69 	IQS62X_EVENT_HYST_NEG_T,
70 	IQS62X_EVENT_HYST_NEG_P,
71 	IQS62X_EVENT_SAR1_ACT,
72 	IQS62X_EVENT_SAR1_QRD,
73 	IQS62X_EVENT_SAR1_MOVE,
74 	IQS62X_EVENT_SAR1_HALT,
75 	IQS62X_EVENT_WHEEL_UP,
76 	IQS62X_EVENT_WHEEL_DN,
77 
78 	/* switches */
79 	IQS62X_EVENT_HALL_N_T,
80 	IQS62X_EVENT_HALL_N_P,
81 	IQS62X_EVENT_HALL_S_T,
82 	IQS62X_EVENT_HALL_S_P,
83 
84 	/* everything else */
85 	IQS62X_EVENT_SYS_RESET,
86 	IQS62X_EVENT_SYS_ATI,
87 };
88 
89 struct iqs62x_event_data {
90 	u16 ui_data;
91 	u8 als_flags;
92 	u8 ir_flags;
93 	u8 interval;
94 };
95 
96 struct iqs62x_event_desc {
97 	enum iqs62x_event_reg reg;
98 	u8 mask;
99 	u8 val;
100 };
101 
102 struct iqs62x_dev_desc {
103 	const char *dev_name;
104 	const struct mfd_cell *sub_devs;
105 	int num_sub_devs;
106 	u8 prod_num;
107 	u8 sw_num;
108 	const u8 *cal_regs;
109 	int num_cal_regs;
110 	u8 prox_mask;
111 	u8 sar_mask;
112 	u8 hall_mask;
113 	u8 hyst_mask;
114 	u8 temp_mask;
115 	u8 als_mask;
116 	u8 ir_mask;
117 	u8 prox_settings;
118 	u8 als_flags;
119 	u8 hall_flags;
120 	u8 hyst_shift;
121 	u8 interval;
122 	u8 interval_div;
123 	const char *fw_name;
124 	const enum iqs62x_event_reg (*event_regs)[IQS62X_EVENT_SIZE];
125 };
126 
127 struct iqs62x_core {
128 	const struct iqs62x_dev_desc *dev_desc;
129 	struct i2c_client *client;
130 	struct regmap *regmap;
131 	struct blocking_notifier_head nh;
132 	struct list_head fw_blk_head;
133 	struct completion ati_done;
134 	struct completion fw_done;
135 	enum iqs62x_ui_sel ui_sel;
136 	unsigned long event_cache;
137 	u8 sw_num;
138 	u8 hw_num;
139 };
140 
141 extern const struct iqs62x_event_desc iqs62x_events[IQS62X_NUM_EVENTS];
142 
143 #endif /* __LINUX_MFD_IQS62X_H */
144