11
11
#include <linux/module.h>
12
12
#include <linux/err.h>
13
13
#include <linux/spi/spi.h>
14
+ #include <linux/types.h>
14
15
#include <linux/iio/iio.h>
15
16
#include <linux/iio/sysfs.h>
16
17
#include <linux/iio/trigger.h>
@@ -121,27 +122,32 @@ struct maxim_thermocouple_data {
121
122
struct spi_device * spi ;
122
123
const struct maxim_thermocouple_chip * chip ;
123
124
char tc_type ;
124
-
125
- u8 buffer [16 ] __aligned (IIO_DMA_MINALIGN );
125
+ /* Buffer for reading up to 2 hardware channels. */
126
+ struct {
127
+ union {
128
+ __be16 raw16 ;
129
+ __be32 raw32 ;
130
+ __be16 raw [2 ];
131
+ };
132
+ aligned_s64 timestamp ;
133
+ } buffer __aligned (IIO_DMA_MINALIGN );
126
134
};
127
135
128
136
static int maxim_thermocouple_read (struct maxim_thermocouple_data * data ,
129
137
struct iio_chan_spec const * chan , int * val )
130
138
{
131
139
unsigned int storage_bytes = data -> chip -> read_size ;
132
140
unsigned int shift = chan -> scan_type .shift + (chan -> address * 8 );
133
- __be16 buf16 ;
134
- __be32 buf32 ;
135
141
int ret ;
136
142
137
143
switch (storage_bytes ) {
138
144
case 2 :
139
- ret = spi_read (data -> spi , ( void * ) & buf16 , storage_bytes );
140
- * val = be16_to_cpu (buf16 );
145
+ ret = spi_read (data -> spi , & data -> buffer . raw16 , storage_bytes );
146
+ * val = be16_to_cpu (data -> buffer . raw16 );
141
147
break ;
142
148
case 4 :
143
- ret = spi_read (data -> spi , ( void * ) & buf32 , storage_bytes );
144
- * val = be32_to_cpu (buf32 );
149
+ ret = spi_read (data -> spi , & data -> buffer . raw32 , storage_bytes );
150
+ * val = be32_to_cpu (data -> buffer . raw32 );
145
151
break ;
146
152
default :
147
153
ret = - EINVAL ;
@@ -166,9 +172,9 @@ static irqreturn_t maxim_thermocouple_trigger_handler(int irq, void *private)
166
172
struct maxim_thermocouple_data * data = iio_priv (indio_dev );
167
173
int ret ;
168
174
169
- ret = spi_read (data -> spi , data -> buffer , data -> chip -> read_size );
175
+ ret = spi_read (data -> spi , data -> buffer . raw , data -> chip -> read_size );
170
176
if (!ret ) {
171
- iio_push_to_buffers_with_ts (indio_dev , data -> buffer ,
177
+ iio_push_to_buffers_with_ts (indio_dev , & data -> buffer ,
172
178
sizeof (data -> buffer ),
173
179
iio_get_time_ns (indio_dev ));
174
180
}
0 commit comments