1#ifndef _ADE7759_H 2#define _ADE7759_H 3 4#define ADE7759_WAVEFORM 0x01 5#define ADE7759_AENERGY 0x02 6#define ADE7759_RSTENERGY 0x03 7#define ADE7759_STATUS 0x04 8#define ADE7759_RSTSTATUS 0x05 9#define ADE7759_MODE 0x06 10#define ADE7759_CFDEN 0x07 11#define ADE7759_CH1OS 0x08 12#define ADE7759_CH2OS 0x09 13#define ADE7759_GAIN 0x0A 14#define ADE7759_APGAIN 0x0B 15#define ADE7759_PHCAL 0x0C 16#define ADE7759_APOS 0x0D 17#define ADE7759_ZXTOUT 0x0E 18#define ADE7759_SAGCYC 0x0F 19#define ADE7759_IRQEN 0x10 20#define ADE7759_SAGLVL 0x11 21#define ADE7759_TEMP 0x12 22#define ADE7759_LINECYC 0x13 23#define ADE7759_LENERGY 0x14 24#define ADE7759_CFNUM 0x15 25#define ADE7759_CHKSUM 0x1E 26#define ADE7759_DIEREV 0x1F 27 28#define ADE7759_READ_REG(a) a 29#define ADE7759_WRITE_REG(a) ((a) | 0x80) 30 31#define ADE7759_MAX_TX 6 32#define ADE7759_MAX_RX 6 33#define ADE7759_STARTUP_DELAY 1 34 35#define ADE7759_SPI_SLOW (u32)(300 * 1000) 36#define ADE7759_SPI_BURST (u32)(1000 * 1000) 37#define ADE7759_SPI_FAST (u32)(2000 * 1000) 38 39#define DRIVER_NAME "ade7759" 40 41/** 42 * struct ade7759_state - device instance specific data 43 * @us: actual spi_device 44 * @work_trigger_to_ring: bh for triggered event handling 45 * @inter: used to check if new interrupt has been triggered 46 * @last_timestamp: passing timestamp from th to bh of interrupt handler 47 * @indio_dev: industrial I/O device structure 48 * @trig: data ready trigger registered with iio 49 * @tx: transmit buffer 50 * @rx: recieve buffer 51 * @buf_lock: mutex to protect tx and rx 52 **/ 53struct ade7759_state { 54 struct spi_device *us; 55 struct work_struct work_trigger_to_ring; 56 s64 last_timestamp; 57 struct iio_dev *indio_dev; 58 struct iio_trigger *trig; 59 u8 *tx; 60 u8 *rx; 61 struct mutex buf_lock; 62}; 63#if defined(CONFIG_IIO_RING_BUFFER) && defined(THIS_HAS_RING_BUFFER_SUPPORT) 64/* At the moment triggers are only used for ring buffer 65 * filling. This may change! 66 */ 67 68enum ade7759_scan { 69 ADE7759_SCAN_ACTIVE_POWER, 70 ADE7759_SCAN_CH1_CH2, 71 ADE7759_SCAN_CH1, 72 ADE7759_SCAN_CH2, 73}; 74 75void ade7759_remove_trigger(struct iio_dev *indio_dev); 76int ade7759_probe_trigger(struct iio_dev *indio_dev); 77 78ssize_t ade7759_read_data_from_ring(struct device *dev, 79 struct device_attribute *attr, 80 char *buf); 81 82 83int ade7759_configure_ring(struct iio_dev *indio_dev); 84void ade7759_unconfigure_ring(struct iio_dev *indio_dev); 85 86int ade7759_initialize_ring(struct iio_ring_buffer *ring); 87void ade7759_uninitialize_ring(struct iio_ring_buffer *ring); 88#else /* CONFIG_IIO_RING_BUFFER */ 89 90static inline void ade7759_remove_trigger(struct iio_dev *indio_dev) 91{ 92} 93static inline int ade7759_probe_trigger(struct iio_dev *indio_dev) 94{ 95 return 0; 96} 97 98static inline ssize_t 99ade7759_read_data_from_ring(struct device *dev, 100 struct device_attribute *attr, 101 char *buf) 102{ 103 return 0; 104} 105 106static int ade7759_configure_ring(struct iio_dev *indio_dev) 107{ 108 return 0; 109} 110static inline void ade7759_unconfigure_ring(struct iio_dev *indio_dev) 111{ 112} 113static inline int ade7759_initialize_ring(struct iio_ring_buffer *ring) 114{ 115 return 0; 116} 117static inline void ade7759_uninitialize_ring(struct iio_ring_buffer *ring) 118{ 119} 120#endif /* CONFIG_IIO_RING_BUFFER */ 121 122#endif 123