Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * AFE440X Heart Rate Monitors and Low-Cost Pulse Oximeters
0004  *
0005  * Copyright (C) 2015 Texas Instruments Incorporated - https://www.ti.com/
0006  *  Andrew F. Davis <afd@ti.com>
0007  */
0008 
0009 #ifndef _AFE440X_H
0010 #define _AFE440X_H
0011 
0012 /* AFE440X registers */
0013 #define AFE440X_CONTROL0        0x00
0014 #define AFE440X_LED2STC         0x01
0015 #define AFE440X_LED2ENDC        0x02
0016 #define AFE440X_LED1LEDSTC      0x03
0017 #define AFE440X_LED1LEDENDC     0x04
0018 #define AFE440X_ALED2STC        0x05
0019 #define AFE440X_ALED2ENDC       0x06
0020 #define AFE440X_LED1STC         0x07
0021 #define AFE440X_LED1ENDC        0x08
0022 #define AFE440X_LED2LEDSTC      0x09
0023 #define AFE440X_LED2LEDENDC     0x0a
0024 #define AFE440X_ALED1STC        0x0b
0025 #define AFE440X_ALED1ENDC       0x0c
0026 #define AFE440X_LED2CONVST      0x0d
0027 #define AFE440X_LED2CONVEND     0x0e
0028 #define AFE440X_ALED2CONVST     0x0f
0029 #define AFE440X_ALED2CONVEND        0x10
0030 #define AFE440X_LED1CONVST      0x11
0031 #define AFE440X_LED1CONVEND     0x12
0032 #define AFE440X_ALED1CONVST     0x13
0033 #define AFE440X_ALED1CONVEND        0x14
0034 #define AFE440X_ADCRSTSTCT0     0x15
0035 #define AFE440X_ADCRSTENDCT0        0x16
0036 #define AFE440X_ADCRSTSTCT1     0x17
0037 #define AFE440X_ADCRSTENDCT1        0x18
0038 #define AFE440X_ADCRSTSTCT2     0x19
0039 #define AFE440X_ADCRSTENDCT2        0x1a
0040 #define AFE440X_ADCRSTSTCT3     0x1b
0041 #define AFE440X_ADCRSTENDCT3        0x1c
0042 #define AFE440X_PRPCOUNT        0x1d
0043 #define AFE440X_CONTROL1        0x1e
0044 #define AFE440X_LEDCNTRL        0x22
0045 #define AFE440X_CONTROL2        0x23
0046 #define AFE440X_ALARM           0x29
0047 #define AFE440X_LED2VAL         0x2a
0048 #define AFE440X_ALED2VAL        0x2b
0049 #define AFE440X_LED1VAL         0x2c
0050 #define AFE440X_ALED1VAL        0x2d
0051 #define AFE440X_LED2_ALED2VAL       0x2e
0052 #define AFE440X_LED1_ALED1VAL       0x2f
0053 #define AFE440X_CONTROL3        0x31
0054 #define AFE440X_PDNCYCLESTC     0x32
0055 #define AFE440X_PDNCYCLEENDC        0x33
0056 
0057 /* CONTROL0 register fields */
0058 #define AFE440X_CONTROL0_REG_READ   BIT(0)
0059 #define AFE440X_CONTROL0_TM_COUNT_RST   BIT(1)
0060 #define AFE440X_CONTROL0_SW_RESET   BIT(3)
0061 
0062 /* CONTROL1 register fields */
0063 #define AFE440X_CONTROL1_TIMEREN    BIT(8)
0064 
0065 /* TIAGAIN register fields */
0066 #define AFE440X_TIAGAIN_ENSEPGAIN   BIT(15)
0067 
0068 /* CONTROL2 register fields */
0069 #define AFE440X_CONTROL2_PDN_AFE    BIT(0)
0070 #define AFE440X_CONTROL2_PDN_RX     BIT(1)
0071 #define AFE440X_CONTROL2_DYNAMIC4   BIT(3)
0072 #define AFE440X_CONTROL2_DYNAMIC3   BIT(4)
0073 #define AFE440X_CONTROL2_DYNAMIC2   BIT(14)
0074 #define AFE440X_CONTROL2_DYNAMIC1   BIT(20)
0075 
0076 /* CONTROL3 register fields */
0077 #define AFE440X_CONTROL3_CLKDIV     GENMASK(2, 0)
0078 
0079 /* CONTROL0 values */
0080 #define AFE440X_CONTROL0_WRITE      0x0
0081 #define AFE440X_CONTROL0_READ       0x1
0082 
0083 #define AFE440X_INTENSITY_CHAN(_index, _mask)           \
0084     {                           \
0085         .type = IIO_INTENSITY,              \
0086         .channel = _index,              \
0087         .address = _index,              \
0088         .scan_index = _index,               \
0089         .scan_type = {                  \
0090                 .sign = 's',            \
0091                 .realbits = 24,         \
0092                 .storagebits = 32,      \
0093                 .endianness = IIO_CPU,      \
0094         },                      \
0095         .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |  \
0096             _mask,                  \
0097         .indexed = true,                \
0098     }
0099 
0100 #define AFE440X_CURRENT_CHAN(_index)                \
0101     {                           \
0102         .type = IIO_CURRENT,                \
0103         .channel = _index,              \
0104         .address = _index,              \
0105         .scan_index = -1,               \
0106         .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |  \
0107             BIT(IIO_CHAN_INFO_SCALE),       \
0108         .indexed = true,                \
0109         .output = true,                 \
0110     }
0111 
0112 struct afe440x_val_table {
0113     int integer;
0114     int fract;
0115 };
0116 
0117 #define AFE440X_TABLE_ATTR(_name, _table)               \
0118 static ssize_t _name ## _show(struct device *dev,           \
0119                   struct device_attribute *attr, char *buf) \
0120 {                                   \
0121     ssize_t len = 0;                        \
0122     int i;                              \
0123                                     \
0124     for (i = 0; i < ARRAY_SIZE(_table); i++)            \
0125         len += scnprintf(buf + len, PAGE_SIZE - len, "%d.%06u ", \
0126                  _table[i].integer,         \
0127                  _table[i].fract);          \
0128                                     \
0129     buf[len - 1] = '\n';                        \
0130                                     \
0131     return len;                         \
0132 }                                   \
0133 static DEVICE_ATTR_RO(_name)
0134 
0135 struct afe440x_attr {
0136     struct device_attribute dev_attr;
0137     unsigned int field;
0138     const struct afe440x_val_table *val_table;
0139     unsigned int table_size;
0140 };
0141 
0142 #define to_afe440x_attr(_dev_attr)              \
0143     container_of(_dev_attr, struct afe440x_attr, dev_attr)
0144 
0145 #define AFE440X_ATTR(_name, _field, _table)         \
0146     struct afe440x_attr afe440x_attr_##_name = {        \
0147         .dev_attr = __ATTR(_name, (S_IRUGO | S_IWUSR),  \
0148                    afe440x_show_register,   \
0149                    afe440x_store_register), \
0150         .field = _field,                \
0151         .val_table = _table,                \
0152         .table_size = ARRAY_SIZE(_table),       \
0153     }
0154 
0155 #endif /* _AFE440X_H */