RTEMS  5.0.0
i2c.h
Go to the documentation of this file.
1 
9 /*
10  * Copyright (c) 2014, 2017 embedded brains GmbH. All rights reserved.
11  *
12  * embedded brains GmbH
13  * Dornierstr. 4
14  * 82178 Puchheim
15  * Germany
16  * <rtems@embedded-brains.de>
17  *
18  * The license and distribution terms for this file may be
19  * found in the file LICENSE in this distribution or at
20  * http://www.rtems.org/license/LICENSE.
21  */
22 
23 #ifndef _DEV_I2C_I2C_H
24 #define _DEV_I2C_I2C_H
25 
26 #include <linux/i2c.h>
27 #include <linux/i2c-dev.h>
28 
29 #include <rtems.h>
30 #include <rtems/seterr.h>
31 #include <rtems/thread.h>
32 
33 #include <sys/ioctl.h>
34 #include <sys/stat.h>
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif /* __cplusplus */
39 
40 typedef struct i2c_msg i2c_msg;
41 
42 typedef struct i2c_bus i2c_bus;
43 
44 typedef struct i2c_dev i2c_dev;
45 
47 
75 #define I2C_BUS_OBTAIN 0x800
76 
82 #define I2C_BUS_RELEASE 0x801
83 
89 #define I2C_BUS_GET_CONTROL 0x802
90 
96 #define I2C_BUS_SET_CLOCK 0x803
97 
103 #define I2C_BUS_CLOCK_DEFAULT 100000
104 
108 struct i2c_bus {
120  int (*transfer)(i2c_bus *bus, i2c_msg *msgs, uint32_t msg_count);
121 
131  int (*set_clock)(i2c_bus *bus, unsigned long clock);
132 
138  void (*destroy)(i2c_bus *bus);
139 
143  rtems_recursive_mutex mutex;
144 
148  uint16_t default_address;
149 
154 
158  bool use_pec;
159 
163  unsigned long retries;
164 
169 
173  unsigned long functionality;
174 };
175 
191 int i2c_bus_init(i2c_bus *bus);
192 
211 
217 void i2c_bus_destroy(i2c_bus *bus);
218 
225 
238 int i2c_bus_register(
239  i2c_bus *bus,
240  const char *bus_path
241 );
242 
248 void i2c_bus_obtain(i2c_bus *bus);
249 
255 void i2c_bus_release(i2c_bus *bus);
256 
270 int i2c_bus_transfer(i2c_bus *bus, i2c_msg *msgs, uint32_t msg_count);
271 
285 #define I2C_DEV_IO_CONTROL 0x900
286 
290 struct i2c_dev {
297  ssize_t (*read)(i2c_dev *dev, void *buf, size_t n, off_t offset);
298 
305  ssize_t (*write)(i2c_dev *dev, const void *buf, size_t n, off_t offset);
306 
313  int (*ioctl)(i2c_dev *dev, ioctl_command_t command, void *arg);
314 
318  off_t (*get_size)(i2c_dev *dev);
319 
323  blksize_t (*get_block_size)(i2c_dev *dev);
324 
328  void (*destroy)(i2c_dev *dev);
329 
334 
338  uint16_t address;
339 
346  int bus_fd;
347 };
348 
349 
367 int i2c_dev_init(i2c_dev *dev, const char *bus_path, uint16_t address);
368 
389  size_t size,
390  const char *bus_path,
391  uint16_t address
392 );
393 
399 void i2c_dev_destroy(i2c_dev *dev);
400 
407 
420 int i2c_dev_register(
421  i2c_dev *dev,
422  const char *dev_path
423 );
424  /* end of i2c device driver */
426 
429 #ifdef __cplusplus
430 }
431 #endif /* __cplusplus */
432 
433 #endif /* _DEV_I2C_I2C_H */
void i2c_bus_obtain(i2c_bus *bus)
Obtains the bus.
Definition: i2c-bus.c:34
ssize_t read(int fd, void *buffer, size_t count)
Definition: read.c:27
int(* set_clock)(i2c_bus *bus, unsigned long clock)
Sets the bus clock.
Definition: i2c.h:131
Data which Ease the Burden of Consistently Setting Errno.
void i2c_bus_destroy_and_free(i2c_bus *bus)
Destroys a bus control and frees its memory.
Definition: i2c-bus.c:294
Watchdog_Interval rtems_interval
Used to manage and manipulate intervals specified by clock ticks.
Definition: types.h:127
I2C slave device control.
Definition: i2c.h:290
rtems_recursive_mutex mutex
Mutex to protect the bus access.
Definition: i2c.h:143
i2c_dev * i2c_dev_alloc_and_init(size_t size, const char *bus_path, uint16_t address)
Allocates a device control from the heap and initializes it.
Definition: i2c-dev.c:271
ssize_t write(int fd, const void *buffer, size_t count)
Definition: write.c:30
int i2c_dev_init(i2c_dev *dev, const char *bus_path, uint16_t address)
Initializes a device control.
Definition: i2c-dev.c:266
uint16_t default_address
Default slave device address.
Definition: i2c.h:148
Argument type for I2C_RDWR IO control call.
Definition: i2c-dev.h:125
unsigned long functionality
Controller functionality.
Definition: i2c.h:173
void(* destroy)(i2c_bus *bus)
Destroys the bus.
Definition: i2c.h:138
I2C transfer message.
Definition: i2c.h:138
uint16_t address
The device address.
Definition: i2c.h:338
int(* transfer)(i2c_bus *bus, i2c_msg *msgs, uint32_t msg_count)
Transfers I2C messages.
Definition: i2c.h:120
unsigned long retries
Transfer retry count.
Definition: i2c.h:163
int i2c_bus_register(i2c_bus *bus, const char *bus_path)
Registers a bus control.
Definition: i2c-bus.c:235
rtems_interval timeout
Transaction timeout in ticks.
Definition: i2c.h:168
I2C bus control.
Definition: i2c.h:108
void i2c_bus_release(i2c_bus *bus)
Releases the bus.
Definition: i2c-bus.c:39
RTEMS Port of Linux I2C Device API.
int i2c_bus_init(i2c_bus *bus)
Initializes a bus control.
Definition: i2c-bus.c:300
void i2c_dev_destroy(i2c_dev *dev)
Destroys a device control.
Definition: i2c-dev.c:251
i2c_bus * bus
The bus control.
Definition: i2c.h:333
bool ten_bit_address
Use 10-bit addresses.
Definition: i2c.h:153
int i2c_dev_register(i2c_dev *dev, const char *dev_path)
Registers a device control.
Definition: i2c-dev.c:140
RTEMS Port of Linux I2C API.
int bus_fd
File descriptor of the bus.
Definition: i2c.h:346
int i2c_bus_transfer(i2c_bus *bus, i2c_msg *msgs, uint32_t msg_count)
Transfers I2C messages.
Definition: i2c-bus.c:44
unsigned size
Definition: tte.h:74
bool use_pec
Use SMBus PEC.
Definition: i2c.h:158
i2c_bus * i2c_bus_alloc_and_init(size_t size)
Allocates a bus control from the heap and initializes it.
Definition: i2c-bus.c:307
void i2c_dev_destroy_and_free(i2c_dev *dev)
Destroys a device control and frees its memory.
Definition: i2c-dev.c:260
void i2c_bus_destroy(i2c_bus *bus)
Destroys a bus control.
Definition: i2c-bus.c:289