1 /*        $NetBSD: dbcool_var.h,v 1.17 2020/07/12 08:48:49 kim Exp $ */
2 
3 /*-
4  * Copyright (c) 2008 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Paul Goyette
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 /*
33  * A driver for dbCool(tm) family of environmental controllers
34  */
35 
36 #ifndef DBCOOLVAR_H
37 #define DBCOOLVAR_H
38 
39 #ifdef DEBUG
40 #define DBCOOL_DEBUG
41 #endif
42 
43 #include <sys/cdefs.h>
44 __KERNEL_RCSID(0, "$NetBSD: dbcool_var.h,v 1.17 2020/07/12 08:48:49 kim Exp $");
45 
46 #include <dev/i2c/i2cvar.h>
47 
48 #include <dev/sysmon/sysmonvar.h>
49 
50 #include <dev/i2c/dbcool_reg.h>
51 
52 enum dbc_pwm_params {
53           DBC_PWM_BEHAVIOR = 0,
54           DBC_PWM_MIN_DUTY,
55           DBC_PWM_MAX_DUTY,
56           DBC_PWM_CUR_DUTY,
57           DBC_PWM_LAST_PARAM
58 };
59 
60 enum dbc_sensor_type {
61           DBC_CTL = 0,
62           DBC_TEMP,
63           DBC_VOLT,
64           DBC_FAN,
65           DBC_VID,
66           DBC_EOF
67 };
68 
69 #define   DBCFLAG_TEMPOFFSET  0x0001
70 #define   DBCFLAG_HAS_MAXDUTY 0x0002
71 #define   DBCFLAG_HAS_SHDN    0x0004
72 #define   DBCFLAG_MULTI_VCC   0x0008
73 #define   DBCFLAG_4BIT_VER    0x0010
74 #define   DBCFLAG_OBSOLETE    0x0020    /* was DBCFLAG_HAS_VID */
75 #define   DBCFLAG_HAS_VID_SEL 0x0040
76 #define   DBCFLAG_HAS_PECI    0x0080
77 #define   DBCFLAG_NO_READBYTE 0x1000
78 #define   DBCFLAG_ADM1030               0x2000
79 #define   DBCFLAG_ADT7466               0x4000
80 
81 /* Maximum sensors for any dbCool device */
82 #define DBCOOL_MAXSENSORS       16
83 
84 struct reg_list {
85           uint8_t val_reg;
86           uint8_t hi_lim_reg;
87           uint8_t lo_lim_reg;
88 };
89 
90 struct dbcool_sensor {
91           enum dbc_sensor_type type;
92           struct reg_list     reg;
93           int name_index;
94           int sysctl_index;
95           int nom_volt_index;
96 };
97 
98 /*
99  * The members of dbcool_power_control need to stay in the same order
100  * as the enum dbc_pwm_params above
101  */
102 struct dbcool_power_control {
103           uint8_t   power_regs[DBC_PWM_LAST_PARAM];
104           const char *desc;
105 };
106 
107 struct chip_id;
108 
109 struct dbcool_chipset {
110           i2c_tag_t dc_tag;
111           i2c_addr_t dc_addr;
112           void (*dc_writereg)(struct dbcool_chipset *, uint8_t, uint8_t);
113           uint8_t (*dc_readreg)(struct dbcool_chipset *, uint8_t);
114           struct chip_id *dc_chip;
115 };
116 
117 struct dbcool_softc {
118           device_t sc_dev;
119           struct sysmon_envsys *sc_sme;
120           struct dbcool_chipset sc_dc;
121           envsys_data_t sc_sensor[DBCOOL_MAXSENSORS];
122           sysmon_envsys_lim_t sc_deflims[DBCOOL_MAXSENSORS];
123           uint32_t sc_defprops[DBCOOL_MAXSENSORS];
124           int sc_root_sysctl_num;
125           int sc_sysctl_num[DBCOOL_MAXSENSORS];
126           struct reg_list *sc_regs[DBCOOL_MAXSENSORS];
127           int sc_nom_volt[DBCOOL_MAXSENSORS];
128           int sc_temp_offset;
129           int64_t sc_supply_voltage;
130           bool sc_suspend;
131           struct sysctllog *sc_sysctl_log;
132           prop_dictionary_t sc_prop;
133 #ifdef DBCOOL_DEBUG
134           uint8_t sc_user_reg;
135 #endif
136 };
137 
138 struct chip_id {
139           uint8_t company;
140           uint8_t device;
141           uint8_t rev;
142           struct dbcool_sensor *table;
143           struct dbcool_power_control *power;
144           int flags;
145           int rpm_dividend;
146           const char *name;
147 };
148 
149 /*
150  * Expose some routines for the macppc's ki2c match/attach routines
151  */
152 uint8_t dbcool_readreg(struct dbcool_chipset *, uint8_t);
153 void dbcool_writereg(struct dbcool_chipset *, uint8_t, uint8_t);
154 void dbcool_setup(device_t);
155 int dbcool_chip_ident(struct dbcool_chipset *);
156 bool dbcool_pmf_suspend(device_t, const pmf_qual_t *);
157 bool dbcool_pmf_resume(device_t, const pmf_qual_t *);
158 
159 #endif    /* def DBCOOLVAR_H */
160