RTEMS 6.1-rc2
Loading...
Searching...
No Matches
ti-lm25066a.h
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/*
4 * Copyright (c) 2016-2017 Chris Johns <chrisj@rtems.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 COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20 * 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/*
30 * TI LM25066A
31 * http://www.ti.com/product/LM25066A
32 */
33
34#ifndef TI_LM25066A_H
35#define TI_LM25066A_H
36
37#include <dev/i2c/i2c.h>
38
39/*
40 * PM Bus Command interface.
41 *
42 * The keys are:
43 * IO : IO direction R=read W=write
44 * SZ : Size in bytes.
45 */
46typedef enum
47{ /* IO SZ Name */
48 TI_LM25066A_OPERATION = 0, /* R 1 PMBus */
49 TI_LM25066A_CLEAR_FAULTS = 1, /* W 0 PMBus */
50 TI_LM25066A_CAPABILITY = 2, /* R 1 PMBus */
51 TI_LM25066A_VOUT_UV_WARN_LIMIT = 3, /* RW 2 PMBus */
52 TI_LM25066A_OT_FAULT_LIMIT = 4, /* RW 2 PMBus */
53 TI_LM25066A_OT_WARN_LIMIT = 5, /* RW 2 PMBus */
54 TI_LM25066A_VIN_OV_WARN_LIMIT = 6, /* RW 2 PMBus */
55 TI_LM25066A_VIN_UV_WARN_LIMIT = 7, /* RW 2 PMBus */
56 TI_LM25066A_STATUS_BYTE = 8, /* R 1 PMBus */
57 TI_LM25066A_STATUS_WORD = 9, /* R 2 PMBus */
58 TI_LM25066A_STATUS_VOUT = 10, /* R 1 PMBus */
59 TI_LM25066A_STATUS_INPUT = 11, /* R 1 PMBus */
60 TI_LM25066A_STATUS_TEMPERATURE = 12, /* R 1 PMBus */
61 TI_LM25066A_STATUS_CML = 13, /* R 1 PMBus */
62 TI_LM25066A_STATUS_MFR_SPECIFIC = 14, /* R 1 PMBus */
63 TI_LM25066A_READ_VIN = 15, /* R 2 PMBus */
64 TI_LM25066A_READ_VOUT = 16, /* R 2 PMBus */
65 TI_LM25066A_READ_TEMPERATURE_1 = 17, /* R 2 PMBus */
66 TI_LM25066A_MFR_ID = 18, /* R 3 PMBus */
67 TI_LM25066A_MFR_MODEL = 19, /* R 8 PMBus */
68 TI_LM25066A_MFR_REVISION = 20, /* R 2 PMBus */
69 TI_LM25066A_MFR_READ_VAUX = 21, /* R 2 MFR_SPECIFIC_00 */
70 TI_LM25066A_MFR_READ_IIN = 22, /* R 2 MFR_SPECIFIC_01 */
71 TI_LM25066A_MFR_READ_PIN = 23, /* R 2 MFR_SPECIFIC_02 */
72 TI_LM25066A_MFR_IIN_OC_WARN_LIMIT = 24, /* RW 2 MFR_SPECIFIC_03 */
73 TI_LM25066A_MFR_PIN_OP_WARN_LIMIT = 25, /* RW 2 MFR_SPECIFIC_04 */
74 TI_LM25066A_MFR_PIN_PEAK = 26, /* R 2 MFR_SPECIFIC_05 */
75 TI_LM25066A_MFR_CLEAR_PIN_PEAK = 27, /* W 0 MFR_SPECIFIC_06 */
76 TI_LM25066A_MFR_GATE_MASK = 28, /* RW 1 MFR_SPECIFIC_07 */
77 TI_LM25066A_MFR_ALERT_MASK = 29, /* RW 2 MFR_SPECIFIC_08 */
78 TI_LM25066A_MFR_DEVICE_SETUP = 30, /* RW 1 MFR_SPECIFIC_09 */
79 TI_LM25066A_MFR_BLOCK_READ = 31, /* R 12 MFR_SPECIFIC_10 */
80 TI_LM25066A_MFR_SAMPLES_FOR_AVG = 32, /* RW 1 MFR_SPECIFIC_11 */
81 TI_LM25066A_MFR_READ_AVG_VIN = 33, /* R 2 MFR_SPECIFIC_12 */
82 TI_LM25066A_MFR_READ_AVG_VOUT = 34, /* R 2 MFR_SPECIFIC_13 */
83 TI_LM25066A_MFR_READ_AVG_IIN = 35, /* R 2 MFR_SPECIFIC_14 */
84 TI_LM25066A_MFR_READ_AVG_PIN = 36, /* R 2 MFR_SPECIFIC_15 */
85 TI_LM25066A_MFR_BLACK_BOX_READ = 37, /* R 12 MFR_SPECIFIC_16 */
86 TI_LM25066A_MFR_DIAGNOSTIC_WORD_READ = 38, /* R 2 MFR_SPECIFIC_17 */
87 TI_LM25066A_MFR_AVG_BLOCK_READ = 39, /* R 12 MFR_SPECIFIC_18 */
88} ti_lm25066a_cmd;
89
90/*
91 * Real world converters. Page 46 of the datasheet discusses reading and
92 * writing telemtry data and obtaining the real world values. There are 8
93 * separate conversions using the same formula.
94 *
95 * The formula is:
96 *
97 * 1 -R
98 * X = - (Y x 10 - b)
99 * m
100 *
101 * X: the calculated "real world" value (volts, amps, watt, etc.)
102 * m: the slope coefficient
103 * Y: a two byte two's complement integer received from device
104 * b: the offset, a two byte two's complement integer
105 * R: the exponent, a one byte two's complement integer
106 *
107 * R in the table is inverted because we cannot store 0.01 in an int. This
108 * makes the equation:
109 *
110 * 1 Y
111 * X = - (- - b)
112 * m R
113 *
114 * The R value lets the integer result have decimal places.
115 *
116 * There are 8 conversion table entries listed in Table 41 of the
117 * data sheet. They are:
118 *
119 * 1. READ_VIN, READ_AVG_VIN, VIN_OV_WARN_LIMIT, VIN_UV_WARN_LIMIT
120 * 2. READ_VOUT, READ_AVG_VOUT, VOUT_UV_WARN_LIMIT
121 * 3. READ_VAUX
122 * 4.GND READ_IIN, READ_AVG_IIN, MFR_IIN_OC_WARN_LIMIT
123 * 4.VDD READ_IIN, READ_AVG_IIN, MFR_IIN_OC_WARN_LIMIT
124 * 5.GND READ_PIN, READ_AVG_PIN, READ_PIN_PEAK, MFR_PIN_OP_WARN_LIMIT
125 * 5.VCC READ_PIN, READ_AVG_PIN, READ_PIN_PEAK, MFR_PIN_OP_WARN_LIMIT
126 * 6. READ_TEMPERATURE_1, OT_WARN_LIMIT, OT_FAULT_LIMIT
127 *
128 * You need to provide 6 sets of conversion factors. Row 4 and 5 depend on how
129 * the device is wired. The driver will use the matching table row to convert
130 * the 2-complement 12 bit to a real world value.
131 */
132#define TI_LM25066A_CONVERSION_SIZE (6)
133typedef struct
134{
135 int m; /* The slope coefficient */
136 int b; /* The offset */
137 int R; /* The inverted power of 10 of -R */
139
140/*
141 * IO control interface.
142 */
143#define TI_LM25066A_GET (I2C_DEV_IO_CONTROL + 0)
144#define TI_LM25066A_SET (I2C_DEV_IO_CONTROL + 1)
145
146/*
147 * IO data types.
148 */
149typedef enum
150{
151 TI_LM25066A_8BIT = 0,
152 TI_LM25066A_16BIT = 1,
153 TI_LM25066A_VALUE = 2,
154 TI_LM25066A_VALUES = 3,
155 TI_LM25066A_STRING = 4,
156 TI_LM25066A_RAW = 5
157} ti_lm25066a_data;
158
159/*
160 * Struct to move data into and out of the driver.
161 */
162typedef struct
163{
164 ti_lm25066a_cmd cmd;
165 ti_lm25066a_data type;
166 union {
167 uint8_t u8;
168 uint16_t u16;
169 int value;
170 int values[6];
171 char string[9];
172 uint8_t* raw;
173 } data;
175
176/*
177 * Register the device.
178 *
179 * The conversions table has 6 columns.
180 *
181 * The values are an integer so the decimal_point value scales the value so it
182 * can fit in an integer with the required number of decimal points.
183 */
184int i2c_dev_register_ti_lm25066a(const char* bus_path,
185 const char* dev_path,
186 uint16_t address,
187 const ti_lm25066a_conversion* const conversions,
188 const int decimal_points);
189
190/*
191 * Get.
192 */
193static inline int
194ti_lm25066a_get(int fd, ti_lm25066a_io* io)
195{
196 return ioctl(fd, TI_LM25066A_GET, io);
197}
198
199/*
200 * Set.
201 */
202static inline int
203ti_lm25066a_set(int fd, ti_lm25066a_io* io)
204{
205 return ioctl(fd, TI_LM25066A_SET, io);
206}
207
208
209#endif
Inter-Integrated Circuit (I2C) Driver API.
Definition: ti-lm25066a.h:134
Definition: ti-lm25066a.h:163