RTEMS  5.1
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 
77 #define I2C_BUS_OBTAIN 0x800
78 
84 #define I2C_BUS_RELEASE 0x801
85 
91 #define I2C_BUS_GET_CONTROL 0x802
92 
98 #define I2C_BUS_SET_CLOCK 0x803
99 
105 #define I2C_BUS_CLOCK_DEFAULT 100000
106 
110 struct i2c_bus {
122  int (*transfer)(i2c_bus *bus, i2c_msg *msgs, uint32_t msg_count);
123 
133  int (*set_clock)(i2c_bus *bus, unsigned long clock);
134 
140  void (*destroy)(i2c_bus *bus);
141 
145  rtems_recursive_mutex mutex;
146 
150  uint16_t default_address;
151 
156 
160  bool use_pec;
161 
165  unsigned long retries;
166 
171 
175  unsigned long functionality;
176 };
177 
193 int i2c_bus_init(i2c_bus *bus);
194 
213 
219 void i2c_bus_destroy(i2c_bus *bus);
220 
227 
240 int i2c_bus_register(
241  i2c_bus *bus,
242  const char *bus_path
243 );
244 
250 void i2c_bus_obtain(i2c_bus *bus);
251 
257 void i2c_bus_release(i2c_bus *bus);
258 
272 int i2c_bus_transfer(i2c_bus *bus, i2c_msg *msgs, uint32_t msg_count);
273 
287 #define I2C_DEV_IO_CONTROL 0x900
288 
292 struct i2c_dev {
299  ssize_t (*read)(i2c_dev *dev, void *buf, size_t n, off_t offset);
300 
307  ssize_t (*write)(i2c_dev *dev, const void *buf, size_t n, off_t offset);
308 
315  int (*ioctl)(i2c_dev *dev, ioctl_command_t command, void *arg);
316 
320  off_t (*get_size)(i2c_dev *dev);
321 
325  blksize_t (*get_block_size)(i2c_dev *dev);
326 
330  void (*destroy)(i2c_dev *dev);
331 
336 
340  uint16_t address;
341 
348  int bus_fd;
349 };
350 
351 
369 int i2c_dev_init(i2c_dev *dev, const char *bus_path, uint16_t address);
370 
391  size_t size,
392  const char *bus_path,
393  uint16_t address
394 );
395 
401 void i2c_dev_destroy(i2c_dev *dev);
402 
409 
422 int i2c_dev_register(
423  i2c_dev *dev,
424  const char *dev_path
425 );
426  /* end of i2c device driver */
428 
431 #ifdef __cplusplus
432 }
433 #endif /* __cplusplus */
434 
435 #endif /* _DEV_I2C_I2C_H */
void i2c_bus_obtain(i2c_bus *bus)
Obtains the bus.
Definition: i2c-bus.c:34
blksize_t(* get_block_size)(i2c_dev *dev)
Gets the file block size.
Definition: i2c.h:325
int(* set_clock)(i2c_bus *bus, unsigned long clock)
Sets the bus clock.
Definition: i2c.h:133
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
ssize_t(* write)(i2c_dev *dev, const void *buf, size_t n, off_t offset)
Writes to the device.
Definition: i2c.h:307
I2C slave device control.
Definition: i2c.h:292
rtems_recursive_mutex mutex
Mutex to protect the bus access.
Definition: i2c.h:145
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
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:150
Argument type for I2C_RDWR IO control call.
Definition: i2c-dev.h:125
unsigned long functionality
Controller functionality.
Definition: i2c.h:175
void(* destroy)(i2c_bus *bus)
Destroys the bus.
Definition: i2c.h:140
I2C transfer message.
Definition: i2c.h:138
uint16_t address
The device address.
Definition: i2c.h:340
int(* transfer)(i2c_bus *bus, i2c_msg *msgs, uint32_t msg_count)
Transfers I2C messages.
Definition: i2c.h:122
void(* destroy)(i2c_dev *dev)
Destroys the device.
Definition: i2c.h:330
unsigned long retries
Transfer retry count.
Definition: i2c.h:165
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:170
I2C bus control.
Definition: i2c.h:110
void i2c_bus_release(i2c_bus *bus)
Releases the bus.
Definition: i2c-bus.c:39
RTEMS Port of Linux I2C Device API.
off_t(* get_size)(i2c_dev *dev)
Gets the file size.
Definition: i2c.h:320
int i2c_bus_init(i2c_bus *bus)
Initializes a bus control.
Definition: i2c-bus.c:300
int(* ioctl)(i2c_dev *dev, ioctl_command_t command, void *arg)
Device IO control.
Definition: i2c.h:315
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:335
bool ten_bit_address
Use 10-bit addresses.
Definition: i2c.h:155
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:348
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:160
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
ssize_t(* read)(i2c_dev *dev, void *buf, size_t n, off_t offset)
Reads from the device.
Definition: i2c.h:299
void i2c_bus_destroy(i2c_bus *bus)
Destroys a bus control.
Definition: i2c-bus.c:289