1 /* $NetBSD: tadpmureg.h,v 1.3 2020/05/16 07:16:14 jdc Exp $ */
2 
3 /*-
4  * Copyright (c) 2018 Michael Lorenz <macallan@netbsd.org>
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 /* registers and commands for the PMU found in Tadpole SPARCle/Viper laptops */
30 
31 #ifndef TADPMUREG_H
32 #define TADPMUREG_H
33 
34 /* all values were found by looking at OF methods on the tadpmu node */
35 
36 /* these registers live in the pckbc's address space */
37 #define TADPMU_CMD  0x6
38 #define TADPMU_STATUS         0x6
39 #define TADPMU_DATA 0x2
40 
41 #define STATUS_HAVE_DATA      0x01      /* response from command */
42 #define STATUS_CMD_IN_PROGRESS          0x02
43 #define STATUS_INTR           0x04      /* interrupt happened, read data to ack */
44 #define STATUS_SEND_DATA      0x08      /* cmd waiting for data */
45 
46 #define CMD_SET_OPMODE                  0x41      /* not sure what exactly this does... */
47 #define             OPMODE_UNIX         0x75      /* other than toggling the UNIX mode  */
48 #define             OPMODE_OF 0x67      /* bit in the GENSTAT register        */
49 #define             OPMODE_DBG_ON       0x64      /* Debug ON */
50 #define             OPMODE_DBG_OFF      0x6E      /* Debug OFF */
51 #define             OPMODE_OBP          0x6F
52 #define CMD_CHRGCTL           0x42
53 #define CMD_SET_BACKLIGHT     0x43      /* apparently 0 - 1f */
54 #define CMD_SET_CPUSPEED      0x44      /* in 10MHz, so 120 == 1.2GHz */
55 #define CMD_SET_SPREADCLK     0x45
56 #define CMD_SET_FANSPEED      0x46
57 #define CMD_SET_VOLUME                  0x48      /* beeper volume */
58 #define CMD_SET_DIR_CLK                 0x80
59 #define CMD_WRITE             0xC0
60 
61 #define CMD_READ_GENSTAT      0x10
62 #define CMD_READ_BACKLIGHT    0x11
63 #define CMD_READ_SYSTEMP      0x12      /* temperature */
64 #define CMD_READ_VOLUME                 0x13
65 #define CMD_READ_VBATT                  0x14      /* Voltage * 10 (e.g. 120 = 12.0v) */
66 #define CMD_READ_VERSION      0x15
67 #define CMD_READ_CPUSPEED     0x16
68 #define CMD_READ_KEYSTAT      0x17      /* Pause-A, D, N, O, R */
69 #define CMD_READ_FAN_EN                 0x18      /* Fan(s): off=0x00, full=0x77 */
70 #define CMD_READ_GENSTAT2     0x19
71 #define READ_DIPSWITCH                  0x1A
72 
73 #define CMD_READ_FANSPEED     0x50      /* takes a parameter, returns nothing? */
74 
75 #define CMD_SHUTDOWN                    0x40
76 #define CMD_BEEP              0x47      /* Start/stop beep, param is freq */
77 #define CMD_READ_BMU                    0x70
78 #define CMD_REFLASH           0x49
79 #define CMD_READ              0x89
80 #define CMD_WRITE             0xC0
81 #define CMD_WRITE_BMU                   0xC1
82 
83 /* these are according to the ROM methods
84    #define GENSTAT_DC_PRESENT           0x01
85    #define GENSTAT_DC_ENABLE            0x02
86    #define GENSTAT_BATTERY_PRESENT      0x04
87    #define GENSTAT_BATTERY_CHARGING     0x08
88    #define GENSTAT_LID_CLOSED           0x10
89    #define GENSTAT_UNIX_MODE            0x20
90    #define GENSTAT_SPREADSPECTRUM       0x40
91 
92    Values of genstat (from observation)
93    0b = on battery
94    3b = battery charging
95    1f = battery full
96    1b = no battery
97  */
98 #define GENSTAT_UNIX_MODE               0x01
99 #define GENSTAT_BATTERY_PRESENT                   0x04      /* only valid if DC present? */
100 #define GENSTAT_BATTERY_CHARGED                   0x08
101 #define GENSTAT_DC_PRESENT              0x10
102 #define GENSTAT_BATTERY_CHARGING        0x20
103 #define GENSTAT_LID_CLOSED              0x80
104 
105 #define GENSTAT_STATE_BATTERY_FULL      0x1f
106 #define GENSTAT_STATE_BATTERY_DISCHARGE 0x0b
107 #define GENSTAT_STATE_BATTERY_CHARGE    0x3b
108 
109 #define GENSTAT2_DEBUG                  0x01                /* PMU debug enable? */
110 #define GENSTAT2_MUTE                   0x02
111 
112 /* messages from interrupts */
113 #define TADPMU_INTR_BATTERY_CHARGED     0x03
114 #define TADPMU_INTR_DCPOWER             0x04
115 #define TADPMU_INTR_LID                           0x05
116 #define TADPMU_INTR_POWERBUTTON                   0x06
117 #define TADPMU_INTR_BATTERY_VOLT        0xcd      /* Voltage change */
118 #define TADPMU_INTR_BATTERY_STATE       0xd6      /* e.g. warn -> crit */
119 /* Other observed values:
120     0xc9
121     0xcb
122     0xd2
123  */
124 
125 #endif /* TADPMUREG_H */
126