Merge branch 'staging-next' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh...
[pandora-kernel.git] / drivers / staging / iio / meter / ade7753.h
1 #ifndef _ADE7753_H
2 #define _ADE7753_H
3
4 #define ADE7753_WAVEFORM   0x01
5 #define ADE7753_AENERGY    0x02
6 #define ADE7753_RAENERGY   0x03
7 #define ADE7753_LAENERGY   0x04
8 #define ADE7753_VAENERGY   0x05
9 #define ADE7753_RVAENERGY  0x06
10 #define ADE7753_LVAENERGY  0x07
11 #define ADE7753_LVARENERGY 0x08
12 #define ADE7753_MODE       0x09
13 #define ADE7753_IRQEN      0x0A
14 #define ADE7753_STATUS     0x0B
15 #define ADE7753_RSTSTATUS  0x0C
16 #define ADE7753_CH1OS      0x0D
17 #define ADE7753_CH2OS      0x0E
18 #define ADE7753_GAIN       0x0F
19 #define ADE7753_PHCAL      0x10
20 #define ADE7753_APOS       0x11
21 #define ADE7753_WGAIN      0x12
22 #define ADE7753_WDIV       0x13
23 #define ADE7753_CFNUM      0x14
24 #define ADE7753_CFDEN      0x15
25 #define ADE7753_IRMS       0x16
26 #define ADE7753_VRMS       0x17
27 #define ADE7753_IRMSOS     0x18
28 #define ADE7753_VRMSOS     0x19
29 #define ADE7753_VAGAIN     0x1A
30 #define ADE7753_VADIV      0x1B
31 #define ADE7753_LINECYC    0x1C
32 #define ADE7753_ZXTOUT     0x1D
33 #define ADE7753_SAGCYC     0x1E
34 #define ADE7753_SAGLVL     0x1F
35 #define ADE7753_IPKLVL     0x20
36 #define ADE7753_VPKLVL     0x21
37 #define ADE7753_IPEAK      0x22
38 #define ADE7753_RSTIPEAK   0x23
39 #define ADE7753_VPEAK      0x24
40 #define ADE7753_RSTVPEAK   0x25
41 #define ADE7753_TEMP       0x26
42 #define ADE7753_PERIOD     0x27
43 #define ADE7753_TMODE      0x3D
44 #define ADE7753_CHKSUM     0x3E
45 #define ADE7753_DIEREV     0x3F
46
47 #define ADE7753_READ_REG(a)    a
48 #define ADE7753_WRITE_REG(a) ((a) | 0x80)
49
50 #define ADE7753_MAX_TX    4
51 #define ADE7753_MAX_RX    4
52 #define ADE7753_STARTUP_DELAY 1
53
54 #define ADE7753_SPI_SLOW        (u32)(300 * 1000)
55 #define ADE7753_SPI_BURST       (u32)(1000 * 1000)
56 #define ADE7753_SPI_FAST        (u32)(2000 * 1000)
57
58 #define DRIVER_NAME             "ade7753"
59
60 /**
61  * struct ade7753_state - device instance specific data
62  * @us:                 actual spi_device
63  * @work_trigger_to_ring: bh for triggered event handling
64  * @inter:              used to check if new interrupt has been triggered
65  * @last_timestamp:     passing timestamp from th to bh of interrupt handler
66  * @indio_dev:          industrial I/O device structure
67  * @trig:               data ready trigger registered with iio
68  * @tx:                 transmit buffer
69  * @rx:                 recieve buffer
70  * @buf_lock:           mutex to protect tx and rx
71  **/
72 struct ade7753_state {
73         struct spi_device               *us;
74         struct work_struct              work_trigger_to_ring;
75         s64                             last_timestamp;
76         struct iio_dev                  *indio_dev;
77         struct iio_trigger              *trig;
78         u8                              *tx;
79         u8                              *rx;
80         struct mutex                    buf_lock;
81 };
82 #if defined(CONFIG_IIO_RING_BUFFER) && defined(THIS_HAS_RING_BUFFER_SUPPORT)
83 /* At the moment triggers are only used for ring buffer
84  * filling. This may change!
85  */
86
87 enum ade7753_scan {
88         ADE7753_SCAN_ACTIVE_POWER,
89         ADE7753_SCAN_CH1,
90         ADE7753_SCAN_CH2,
91 };
92
93 void ade7753_remove_trigger(struct iio_dev *indio_dev);
94 int ade7753_probe_trigger(struct iio_dev *indio_dev);
95
96 ssize_t ade7753_read_data_from_ring(struct device *dev,
97                 struct device_attribute *attr,
98                 char *buf);
99
100
101 int ade7753_configure_ring(struct iio_dev *indio_dev);
102 void ade7753_unconfigure_ring(struct iio_dev *indio_dev);
103
104 int ade7753_initialize_ring(struct iio_ring_buffer *ring);
105 void ade7753_uninitialize_ring(struct iio_ring_buffer *ring);
106 #else /* CONFIG_IIO_RING_BUFFER */
107
108 static inline void ade7753_remove_trigger(struct iio_dev *indio_dev)
109 {
110 }
111 static inline int ade7753_probe_trigger(struct iio_dev *indio_dev)
112 {
113         return 0;
114 }
115
116 static inline ssize_t
117 ade7753_read_data_from_ring(struct device *dev,
118                 struct device_attribute *attr,
119                 char *buf)
120 {
121         return 0;
122 }
123
124 static int ade7753_configure_ring(struct iio_dev *indio_dev)
125 {
126         return 0;
127 }
128 static inline void ade7753_unconfigure_ring(struct iio_dev *indio_dev)
129 {
130 }
131 static inline int ade7753_initialize_ring(struct iio_ring_buffer *ring)
132 {
133         return 0;
134 }
135 static inline void ade7753_uninitialize_ring(struct iio_ring_buffer *ring)
136 {
137 }
138 #endif /* CONFIG_IIO_RING_BUFFER */
139
140 #endif