aboutsummaryrefslogtreecommitdiff
path: root/include/linux/cm36283.h
blob: 2872d047562434ada8e4429f1861d334a548616f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/* include/linux/cm36283.h
 *
 * Copyright (C) 2012 Capella Microsystems Inc.
 * Author: Frank Hsieh <pengyueh@gmail.com>
 *
 * This software is licensed under the terms of the GNU General Public
 * License version 2, as published by the Free Software Foundation, and
 * may be copied, distributed, and modified under those terms.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 */

#ifndef __LINUX_CM36283_H
#define __LINUX_CM36283_H

#include <linux/bitops.h>

#define CM36283_I2C_NAME "cm36283"

/* Define Slave Address*/
#define	CM36283_slave_add	0xC0>>1

#define ALS_CALIBRATED		0x6E9F
#define PS_CALIBRATED		  0x509F

/*Define Command Code*/
#define		ALS_CONF		  0x00
#define		ALS_THDH  	  0x01
#define		ALS_THDL	    0x02
#define		PS_CONF1      0x03
#define		PS_CONF3      0x04
#define		PS_CANC       0x05
#define		PS_THD        0x06
#define		RESERVED      0x07

#define		PS_DATA       0x08
#define		ALS_DATA      0x09
#define		RESERVED2     0x0A
#define		INT_FLAG      0x0B
#define		ID_REG        0x0C

/*cm36283*/
/*for ALS CONF command*/
#define CM36283_ALS_IT_80ms 	(0 << 6)
#define CM36283_ALS_IT_160ms 	(1 << 6)
#define CM36283_ALS_IT_320ms 	(2 << 6)
#define CM36283_ALS_IT_640ms 	(3 << 6)
#define CM36283_ALS_GAIN_1 		(0 << 2)
#define CM36283_ALS_GAIN_2 		(1 << 2)
#define CM36283_ALS_GAIN_4 		(2 << 2)
#define CM36283_ALS_GAIN_8 		(3 << 2)
#define CM36283_ALS_INT_EN	 	(1 << 1) /*enable/disable Interrupt*/
#define CM36283_ALS_INT_MASK	0xFFFD
#define CM36283_ALS_SD			  (1 << 0) /*enable/disable ALS func, 1:disable , 0: enable*/
#define CM36283_ALS_SD_MASK		0xFFFE

/*for PS CONF1 command*/
#define CM36283_PS_ITB_1_2	 (0 << 14)
#define CM36283_PS_ITB_1     (1 << 14)
#define CM36283_PS_ITB_2     (2 << 14)
#define CM36283_PS_ITB_4     (3 << 14)
#define CM36283_PS_INT_OFF	       (0 << 8) /*enable/disable Interrupt*/
#define CM36283_PS_INT_IN          (1 << 8)
#define CM36283_PS_INT_OUT         (2 << 8)
#define CM36283_PS_INT_IN_AND_OUT  (3 << 8)

#define CM36283_PS_INT_MASK   0xFCFF

#define CM36283_PS_DR_1_40   (0 << 6)
#define CM36283_PS_DR_1_80   (1 << 6)
#define CM36283_PS_DR_1_160  (2 << 6)
#define CM36283_PS_DR_1_320  (3 << 6)
#define CM36283_PS_IT_1T 	   (0 << 4)
#define CM36283_PS_IT_1_3T   (1 << 4)
#define CM36283_PS_IT_1_6T 	 (2 << 4)
#define CM36283_PS_IT_2T 		 (3 << 4)
#define CM36283_PS_PERS_1 	 (0 << 2)
#define CM36283_PS_PERS_2 	 (1 << 2)
#define CM36283_PS_PERS_3 	 (2 << 2)
#define CM36283_PS_PERS_4 	 (3 << 2)
#define CM36283_PS_RES_1     (1 << 1)
#define CM36283_PS_SD	       (1 << 0)/*enable/disable PS func, 1:disable , 0: enable*/
#define CM36283_PS_SD_MASK	 0xFFFE

/*for PS CONF3 command*/
#define CM36283_PS_MS_NORMAL        (0 << 14)
#define CM36283_PS_MS_LOGIC_ENABLE  (1 << 14)
#define CM36283_PS_PROL_63 	     (0 << 12)
#define CM36283_PS_PROL_127      (1 << 12)
#define CM36283_PS_PROL_191 	   (2 << 12)
#define CM36283_PS_PROL_255 		 (3 << 12)
#define CM36283_PS_SMART_PERS_ENABLE  (1 << 4)
#define CM36283_PS_ACTIVE_FORCE_MODE  (1 << 3)
#define CM36283_PS_ACTIVE_FORCE_TRIG  (1 << 2)

/*for INT FLAG*/
#define INT_FLAG_PS_SPFLAG           (1<<14)
#define INT_FLAG_ALS_IF_L            (1<<13)
#define INT_FLAG_ALS_IF_H            (1<<12)
#define INT_FLAG_PS_IF_CLOSE         (1<<9)
#define INT_FLAG_PS_IF_AWAY          (1<<8)  

#define LS_PWR_ON		BIT(0)
#define PS_PWR_ON		BIT(1)

#define CAPELLA_CM3602_IOCTL_MAGIC 'c'
#define CAPELLA_CM3602_IOCTL_GET_ENABLED \
	_IOR(CAPELLA_CM3602_IOCTL_MAGIC, 1, int *)
#define CAPELLA_CM3602_IOCTL_ENABLE \
	_IOW(CAPELLA_CM3602_IOCTL_MAGIC, 2, int *)

#define LIGHTSENSOR_IOCTL_MAGIC 'l'
#define LIGHTSENSOR_IOCTL_GET_ENABLED _IOR(LIGHTSENSOR_IOCTL_MAGIC, 1, int *)
#define LIGHTSENSOR_IOCTL_ENABLE _IOW(LIGHTSENSOR_IOCTL_MAGIC, 2, int *)

extern unsigned int ps_kparam1;
extern unsigned int ps_kparam2;

#define CM36283_LEVELS_SIZE		10

enum {
	CM36283_ALS_IT0 = 0,
	CM36283_ALS_IT1,
	CM36283_ALS_IT2,
	CM36283_ALS_IT3,
};

struct cm36283_platform_data {
	int intr;
	uint16_t levels[10];
	uint16_t golden_adc;
	int (*power)(int, uint8_t); /* power to the chip */
	uint8_t slave_addr;
	uint8_t ps_close_thd_set;
	uint8_t ps_away_thd_set;	
	uint16_t ls_cmd;
	uint16_t ps_conf1_val;
	uint16_t ps_conf3_val;	
	bool polling;
};

#endif