blob: 2872d047562434ada8e4429f1861d334a548616f [file] [log] [blame]
Joseph Hsiao091151d2013-06-17 11:37:05 +08001/* include/linux/cm36283.h
2 *
3 * Copyright (C) 2012 Capella Microsystems Inc.
4 * Author: Frank Hsieh <pengyueh@gmail.com>
5 *
6 * This software is licensed under the terms of the GNU General Public
7 * License version 2, as published by the Free Software Foundation, and
8 * may be copied, distributed, and modified under those terms.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 */
16
17#ifndef __LINUX_CM36283_H
18#define __LINUX_CM36283_H
19
Oliver Wangd13d1922013-08-22 17:37:21 +080020#include <linux/bitops.h>
21
Joseph Hsiao091151d2013-06-17 11:37:05 +080022#define CM36283_I2C_NAME "cm36283"
23
24/* Define Slave Address*/
25#define CM36283_slave_add 0xC0>>1
26
27#define ALS_CALIBRATED 0x6E9F
28#define PS_CALIBRATED 0x509F
29
30/*Define Command Code*/
31#define ALS_CONF 0x00
32#define ALS_THDH 0x01
33#define ALS_THDL 0x02
34#define PS_CONF1 0x03
35#define PS_CONF3 0x04
36#define PS_CANC 0x05
37#define PS_THD 0x06
38#define RESERVED 0x07
39
40#define PS_DATA 0x08
41#define ALS_DATA 0x09
42#define RESERVED2 0x0A
43#define INT_FLAG 0x0B
44#define ID_REG 0x0C
45
46/*cm36283*/
47/*for ALS CONF command*/
48#define CM36283_ALS_IT_80ms (0 << 6)
49#define CM36283_ALS_IT_160ms (1 << 6)
50#define CM36283_ALS_IT_320ms (2 << 6)
51#define CM36283_ALS_IT_640ms (3 << 6)
52#define CM36283_ALS_GAIN_1 (0 << 2)
53#define CM36283_ALS_GAIN_2 (1 << 2)
54#define CM36283_ALS_GAIN_4 (2 << 2)
55#define CM36283_ALS_GAIN_8 (3 << 2)
56#define CM36283_ALS_INT_EN (1 << 1) /*enable/disable Interrupt*/
57#define CM36283_ALS_INT_MASK 0xFFFD
58#define CM36283_ALS_SD (1 << 0) /*enable/disable ALS func, 1:disable , 0: enable*/
59#define CM36283_ALS_SD_MASK 0xFFFE
60
61/*for PS CONF1 command*/
62#define CM36283_PS_ITB_1_2 (0 << 14)
63#define CM36283_PS_ITB_1 (1 << 14)
64#define CM36283_PS_ITB_2 (2 << 14)
65#define CM36283_PS_ITB_4 (3 << 14)
66#define CM36283_PS_INT_OFF (0 << 8) /*enable/disable Interrupt*/
67#define CM36283_PS_INT_IN (1 << 8)
68#define CM36283_PS_INT_OUT (2 << 8)
69#define CM36283_PS_INT_IN_AND_OUT (3 << 8)
70
71#define CM36283_PS_INT_MASK 0xFCFF
72
73#define CM36283_PS_DR_1_40 (0 << 6)
74#define CM36283_PS_DR_1_80 (1 << 6)
75#define CM36283_PS_DR_1_160 (2 << 6)
76#define CM36283_PS_DR_1_320 (3 << 6)
77#define CM36283_PS_IT_1T (0 << 4)
78#define CM36283_PS_IT_1_3T (1 << 4)
79#define CM36283_PS_IT_1_6T (2 << 4)
80#define CM36283_PS_IT_2T (3 << 4)
81#define CM36283_PS_PERS_1 (0 << 2)
82#define CM36283_PS_PERS_2 (1 << 2)
83#define CM36283_PS_PERS_3 (2 << 2)
84#define CM36283_PS_PERS_4 (3 << 2)
85#define CM36283_PS_RES_1 (1 << 1)
86#define CM36283_PS_SD (1 << 0)/*enable/disable PS func, 1:disable , 0: enable*/
87#define CM36283_PS_SD_MASK 0xFFFE
88
89/*for PS CONF3 command*/
90#define CM36283_PS_MS_NORMAL (0 << 14)
91#define CM36283_PS_MS_LOGIC_ENABLE (1 << 14)
92#define CM36283_PS_PROL_63 (0 << 12)
93#define CM36283_PS_PROL_127 (1 << 12)
94#define CM36283_PS_PROL_191 (2 << 12)
95#define CM36283_PS_PROL_255 (3 << 12)
96#define CM36283_PS_SMART_PERS_ENABLE (1 << 4)
97#define CM36283_PS_ACTIVE_FORCE_MODE (1 << 3)
98#define CM36283_PS_ACTIVE_FORCE_TRIG (1 << 2)
99
100/*for INT FLAG*/
101#define INT_FLAG_PS_SPFLAG (1<<14)
102#define INT_FLAG_ALS_IF_L (1<<13)
103#define INT_FLAG_ALS_IF_H (1<<12)
104#define INT_FLAG_PS_IF_CLOSE (1<<9)
105#define INT_FLAG_PS_IF_AWAY (1<<8)
106
Oliver Wangd13d1922013-08-22 17:37:21 +0800107#define LS_PWR_ON BIT(0)
108#define PS_PWR_ON BIT(1)
109
110#define CAPELLA_CM3602_IOCTL_MAGIC 'c'
111#define CAPELLA_CM3602_IOCTL_GET_ENABLED \
112 _IOR(CAPELLA_CM3602_IOCTL_MAGIC, 1, int *)
113#define CAPELLA_CM3602_IOCTL_ENABLE \
114 _IOW(CAPELLA_CM3602_IOCTL_MAGIC, 2, int *)
115
116#define LIGHTSENSOR_IOCTL_MAGIC 'l'
117#define LIGHTSENSOR_IOCTL_GET_ENABLED _IOR(LIGHTSENSOR_IOCTL_MAGIC, 1, int *)
118#define LIGHTSENSOR_IOCTL_ENABLE _IOW(LIGHTSENSOR_IOCTL_MAGIC, 2, int *)
119
Joseph Hsiao091151d2013-06-17 11:37:05 +0800120extern unsigned int ps_kparam1;
121extern unsigned int ps_kparam2;
122
Oliver Wang8a1b8be2013-08-23 13:42:10 +0800123#define CM36283_LEVELS_SIZE 10
124
Oliver Wanged314dd2013-08-23 16:34:37 +0800125enum {
126 CM36283_ALS_IT0 = 0,
127 CM36283_ALS_IT1,
128 CM36283_ALS_IT2,
129 CM36283_ALS_IT3,
130};
131
Joseph Hsiao091151d2013-06-17 11:37:05 +0800132struct cm36283_platform_data {
133 int intr;
134 uint16_t levels[10];
135 uint16_t golden_adc;
136 int (*power)(int, uint8_t); /* power to the chip */
137 uint8_t slave_addr;
138 uint8_t ps_close_thd_set;
139 uint8_t ps_away_thd_set;
140 uint16_t ls_cmd;
141 uint16_t ps_conf1_val;
142 uint16_t ps_conf3_val;
Oliver Wang8a1b8be2013-08-23 13:42:10 +0800143 bool polling;
Joseph Hsiao091151d2013-06-17 11:37:05 +0800144};
145
146#endif