1300777Smanu/*-
2300777Smanu * Copyright (c) 2016 Emmanuel Vadot <manu@freeebsd.org>
3300777Smanu * All rights reserved.
4300777Smanu *
5300777Smanu * Redistribution and use in source and binary forms, with or without
6300777Smanu * modification, are permitted provided that the following conditions
7300777Smanu * are met:
8300777Smanu * 1. Redistributions of source code must retain the above copyright
9300777Smanu *    notice, this list of conditions and the following disclaimer.
10300777Smanu * 2. Redistributions in binary form must reproduce the above copyright
11300777Smanu *    notice, this list of conditions and the following disclaimer in the
12300777Smanu *    documentation and/or other materials provided with the distribution.
13300777Smanu *
14300777Smanu * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15300777Smanu * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16300777Smanu * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17300777Smanu * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18300777Smanu * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19300777Smanu * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20300777Smanu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21300777Smanu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22300777Smanu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23300777Smanu * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24300777Smanu *
25300777Smanu * $FreeBSD: releng/11.0/sys/arm/allwinner/axp209reg.h 300777 2016-05-26 21:09:07Z manu $
26300777Smanu */
27300777Smanu
28300777Smanu#ifndef _AXP209REG_H_
29300777Smanu#define	_AXP209REG_H_
30300777Smanu
31300777Smanu/* Power State Register */
32300777Smanu#define	AXP209_PSR		0x00
33300777Smanu#define	AXP209_PSR_ACIN		0x80
34300777Smanu#define	AXP209_PSR_ACIN_SHIFT	7
35300777Smanu#define	AXP209_PSR_VBUS		0x20
36300777Smanu#define	AXP209_PSR_VBUS_SHIFT	5
37300777Smanu
38300777Smanu/* Shutdown and battery control */
39300777Smanu#define	AXP209_SHUTBAT		0x32
40300777Smanu#define	AXP209_SHUTBAT_SHUTDOWN	0x80
41300777Smanu
42300777Smanu/* Voltage/Current Monitor */
43300777Smanu#define	AXP209_ACIN_VOLTAGE		0x56
44300777Smanu#define	AXP209_ACIN_CURRENT		0x58
45300777Smanu#define	AXP209_VBUS_VOLTAGE		0x5A
46300777Smanu#define	AXP209_VBUS_CURRENT		0x5C
47300777Smanu#define	AXP209_BAT_VOLTAGE		0x78
48300777Smanu#define	AXP209_BAT_CHARGE_CURRENT	0x7A
49300777Smanu#define	AXP209_BAT_DISCHARGE_CURRENT	0x7C
50300777Smanu
51300777Smanu#define	AXP209_VOLT_STEP	1700
52300777Smanu#define	AXP209_BATVOLT_STEP	1100
53300777Smanu#define	AXP209_ACCURRENT_STEP	625
54300777Smanu#define	AXP209_VBUSCURRENT_STEP	375
55300777Smanu#define	AXP209_BATCURRENT_STEP	500
56300777Smanu
57300777Smanu/* Temperature monitor */
58300777Smanu#define	AXP209_TEMPMON		0x5e
59300777Smanu#define	AXP209_TEMPMON_MIN	1447	/* -144.7C */
60300777Smanu
61300777Smanu/* Sensors conversion macros */
62300777Smanu#define	AXP209_SENSOR_H(a)	((a) << 4)
63300777Smanu#define	AXP209_SENSOR_L(a)	((a) & 0xf)
64300777Smanu#define	AXP209_SENSOR_BAT_H(a)	((a) << 5)
65300777Smanu#define	AXP209_SENSOR_BAT_L(a)	((a) & 0x1f)
66300777Smanu
67300777Smanu#define	AXP209_0C_TO_K		2732
68300777Smanu
69300777Smanu/* ADC Sensors */
70300777Smanu#define	AXP209_ADC_ENABLE1	0x82
71300777Smanu#define	AXP209_ADC_ENABLE2	0x83
72300777Smanu
73300777Smanu#define	AXP209_ADC1_BATVOLT	(1 << 7)
74300777Smanu#define	AXP209_ADC1_BATCURRENT	(1 << 6)
75300777Smanu#define	AXP209_ADC1_ACVOLT	(1 << 5)
76300777Smanu#define	AXP209_ADC1_ACCURRENT	(1 << 4)
77300777Smanu#define	AXP209_ADC1_VBUSVOLT	(1 << 3)
78300777Smanu#define	AXP209_ADC1_VBUSCURRENT	(1 << 2)
79300777Smanu
80300777Smanu/* Interrupt related registers */
81300777Smanu#define	AXP209_IRQ1_ENABLE	0x40
82300777Smanu#define	AXP209_IRQ1_STATUS	0x48
83300777Smanu#define	 AXP209_IRQ1_AC_OVERVOLT	(1 << 7)
84300777Smanu#define	 AXP209_IRQ1_AC_CONN		(1 << 6)
85300777Smanu#define	 AXP209_IRQ1_AC_DISCONN		(1 << 5)
86300777Smanu#define	 AXP209_IRQ1_VBUS_OVERVOLT	(1 << 4)
87300777Smanu#define	 AXP209_IRQ1_VBUS_CONN		(1 << 3)
88300777Smanu#define	 AXP209_IRQ1_VBUS_DISCONN	(1 << 2)
89300777Smanu#define	 AXP209_IRQ1_VBUS_LOW		(1 << 1)
90300777Smanu
91300777Smanu#define	AXP209_IRQ2_ENABLE	0x41
92300777Smanu#define	AXP209_IRQ2_STATUS	0x49
93300777Smanu#define	 AXP209_IRQ2_BATT_CONN			(1 << 7)
94300777Smanu#define	 AXP209_IRQ2_BATT_DISCONN		(1 << 6)
95300777Smanu#define	 AXP209_IRQ2_BATT_CHARGE_ACCT_ON	(1 << 5)
96300777Smanu#define	 AXP209_IRQ2_BATT_CHARGE_ACCT_OFF	(1 << 4)
97300777Smanu#define	 AXP209_IRQ2_BATT_CHARGING		(1 << 3)
98300777Smanu#define	 AXP209_IRQ2_BATT_CHARGED		(1 << 2)
99300777Smanu#define	 AXP209_IRQ2_BATT_TEMP_OVER		(1 << 1)
100300777Smanu#define	 AXP209_IRQ2_BATT_TEMP_LOW		(1 << 0)
101300777Smanu
102300777Smanu#define	AXP209_IRQ3_ENABLE	0x42
103300777Smanu#define	AXP209_IRQ3_STATUS	0x4A
104300777Smanu#define	 AXP209_IRQ3_TEMP_OVER		(1 << 7)
105300777Smanu#define	 AXP209_IRQ3_CHARGE_CURRENT_LOW	(1 << 6)
106300777Smanu#define	 AXP209_IRQ3_DCDC2_LOW		(1 << 4)
107300777Smanu#define	 AXP209_IRQ3_DCDC3_LOW		(1 << 3)
108300777Smanu#define	 AXP209_IRQ3_LDO3_LOW		(1 << 2)
109300777Smanu#define	 AXP209_IRQ3_PEK_SHORT		(1 << 1)
110300777Smanu#define	 AXP209_IRQ3_PEK_LONG		(1 << 0)
111300777Smanu
112300777Smanu#define	AXP209_IRQ4_ENABLE	0x43
113300777Smanu#define	AXP209_IRQ4_STATUS	0x4B
114300777Smanu#define	 AXP209_IRQ4_NOE_START		(1 << 7)
115300777Smanu#define	 AXP209_IRQ4_NOE_SHUT		(1 << 6)
116300777Smanu#define	 AXP209_IRQ4_VBUS_VALID		(1 << 5)
117300777Smanu#define	 AXP209_IRQ4_VBUS_INVALID	(1 << 4)
118300777Smanu#define	 AXP209_IRQ4_VBUS_SESSION	(1 << 3)
119300777Smanu#define	 AXP209_IRQ4_VBUS_SESSION_END	(1 << 2)
120300777Smanu#define	 AXP209_IRQ4_APS_LOW_1		(1 << 1)
121300777Smanu#define	 AXP209_IRQ4_APS_LOW_2		(1 << 0)
122300777Smanu
123300777Smanu#define	AXP209_IRQ5_ENABLE	0x44
124300777Smanu#define	AXP209_IRQ5_STATUS	0x4C
125300777Smanu#define	 AXP209_IRQ5_TIMER_EXPIRE	(1 << 7)
126300777Smanu#define	 AXP209_IRQ5_PEK_RISE_EDGE	(1 << 6)
127300777Smanu#define	 AXP209_IRQ5_PEK_FALL_EDGE	(1 << 5)
128300777Smanu#define	 AXP209_IRQ5_GPIO3	(1 << 3)
129300777Smanu#define	 AXP209_IRQ5_GPIO2	(1 << 2)
130300777Smanu#define	 AXP209_IRQ5_GPIO1	(1 << 1)
131300777Smanu#define	 AXP209_IRQ5_GPIO0	(1 << 0)
132300777Smanu
133300777Smanu#define	AXP209_IRQ_ACK		0xff
134300777Smanu
135300777Smanu/* GPIOs registers */
136300777Smanu#define	AXP209_GPIO_FUNC_MASK		0x7
137300777Smanu
138300777Smanu#define	AXP209_GPIO_FUNC_DRVLO		0x0
139300777Smanu#define	AXP209_GPIO_FUNC_DRVHI		0x1
140300777Smanu#define	AXP209_GPIO_FUNC_INPUT		0x2
141300777Smanu
142300777Smanu#define	AXP209_GPIO0_CTRL	0x90
143300777Smanu#define	AXP209_GPIO1_CTRL	0x92
144300777Smanu#define	AXP209_GPIO2_CTRL	0x93
145300777Smanu#define	AXP209_GPIO_STATUS	0x94
146300777Smanu
147300777Smanu#define	AXP209_GPIO_DATA(x)	(1 << (x + 4))
148300777Smanu
149300777Smanuenum axp209_sensor {
150300777Smanu	AXP209_TEMP,
151300777Smanu	AXP209_ACVOLT,
152300777Smanu	AXP209_ACCURRENT,
153300777Smanu	AXP209_VBUSVOLT,
154300777Smanu	AXP209_VBUSCURRENT,
155300777Smanu	AXP209_BATVOLT,
156300777Smanu	AXP209_BATCHARGECURRENT,
157300777Smanu	AXP209_BATDISCHARGECURRENT,
158300777Smanu};
159300777Smanu
160300777Smanu#endif /* _AXP209REG_H_ */
161