RTEMS: cpukit/include/dev/i2c/ti-lm25066a.h Source File

| RTEMS 5.4-rc2

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