RTEMS: cpukit/include/dev/i2c/i2c.h Source File

| RTEMS 5.4-rc2

Loading...
Searching...
No Matches
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
37extern "C" {
38#endif /* __cplusplus */
39
40typedef struct i2c_msg i2c_msg;
41
42typedef struct i2c_bus i2c_bus;
43
44typedef struct i2c_dev i2c_dev;
45
46typedef struct i2c_rdwr_ioctl_data i2c_rdwr_ioctl_data;
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
155 bool ten_bit_address;
156
160 bool use_pec;
161
165 unsigned long retries;
166
170 rtems_interval timeout;
171
175 unsigned long functionality;
176};
177
193int i2c_bus_init(i2c_bus *bus);
194
212 i2c_bus *i2c_bus_alloc_and_init(size_t size);
213
219void i2c_bus_destroy(i2c_bus *bus);
220
226void i2c_bus_destroy_and_free(i2c_bus *bus);
227
240int i2c_bus_register(
241 i2c_bus *bus,
242 const char *bus_path
243);
244
250void i2c_bus_obtain(i2c_bus *bus);
251
257void i2c_bus_release(i2c_bus *bus);
258
272int 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
335 i2c_bus *bus;
336
340 uint16_t address;
341
348 int bus_fd;
349};
350
351
369int i2c_dev_init(i2c_dev *dev, const char *bus_path, uint16_t address);
370
390 i2c_dev *i2c_dev_alloc_and_init(
391 size_t size,
392 const char *bus_path,
393 uint16_t address
394);
395
401void i2c_dev_destroy(i2c_dev *dev);
402
408void i2c_dev_destroy_and_free(i2c_dev *dev);
409
422int 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 */
i2c.h
RTEMS Port of Linux I2C API.
rtems_interval
Watchdog_Interval rtems_interval
Used to manage and manipulate intervals specified by clock ticks.
Definition: types.h:127
i2c_bus_destroy
void i2c_bus_destroy(i2c_bus *bus)
Destroys a bus control.
Definition: i2c-bus.c:289
i2c_bus_transfer
int i2c_bus_transfer(i2c_bus *bus, i2c_msg *msgs, uint32_t msg_count)
Transfers I2C messages.
Definition: i2c-bus.c:44
i2c_bus_destroy_and_free
void i2c_bus_destroy_and_free(i2c_bus *bus)
Destroys a bus control and frees its memory.
Definition: i2c-bus.c:294
i2c_bus_obtain
void i2c_bus_obtain(i2c_bus *bus)
Obtains the bus.
Definition: i2c-bus.c:34
i2c_bus_init
int i2c_bus_init(i2c_bus *bus)
Initializes a bus control.
Definition: i2c-bus.c:300
i2c_bus_register
int i2c_bus_register(i2c_bus *bus, const char *bus_path)
Registers a bus control.
Definition: i2c-bus.c:235
i2c_bus_alloc_and_init
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
i2c_bus_release
void i2c_bus_release(i2c_bus *bus)
Releases the bus.
Definition: i2c-bus.c:39
i2c_dev_init
int i2c_dev_init(i2c_dev *dev, const char *bus_path, uint16_t address)
Initializes a device control.
Definition: i2c-dev.c:266
i2c_dev_destroy
void i2c_dev_destroy(i2c_dev *dev)
Destroys a device control.
Definition: i2c-dev.c:251
i2c_dev_alloc_and_init
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
i2c_dev_register
int i2c_dev_register(i2c_dev *dev, const char *dev_path)
Registers a device control.
Definition: i2c-dev.c:140
i2c_dev_destroy_and_free
void i2c_dev_destroy_and_free(i2c_dev *dev)
Destroys a device control and frees its memory.
Definition: i2c-dev.c:260
i2c-dev.h
RTEMS Port of Linux I2C Device API.
rtems.h
seterr.h
Data which Ease the Burden of Consistently Setting Errno.
i2c_bus
I2C bus control.
Definition: i2c.h:110
i2c_bus::functionality
unsigned long functionality
Controller functionality.
Definition: i2c.h:175
i2c_bus::retries
unsigned long retries
Transfer retry count.
Definition: i2c.h:165
i2c_bus::timeout
rtems_interval timeout
Transaction timeout in ticks.
Definition: i2c.h:170
i2c_bus::destroy
void(* destroy)(i2c_bus *bus)
Destroys the bus.
Definition: i2c.h:140
i2c_bus::default_address
uint16_t default_address
Default slave device address.
Definition: i2c.h:150
i2c_bus::use_pec
bool use_pec
Use SMBus PEC.
Definition: i2c.h:160
i2c_bus::mutex
rtems_recursive_mutex mutex
Mutex to protect the bus access.
Definition: i2c.h:145
i2c_bus::set_clock
int(* set_clock)(i2c_bus *bus, unsigned long clock)
Sets the bus clock.
Definition: i2c.h:133
i2c_bus::transfer
int(* transfer)(i2c_bus *bus, i2c_msg *msgs, uint32_t msg_count)
Transfers I2C messages.
Definition: i2c.h:122
i2c_bus::ten_bit_address
bool ten_bit_address
Use 10-bit addresses.
Definition: i2c.h:155
i2c_dev
I2C slave device control.
Definition: i2c.h:292
i2c_dev::read
ssize_t(* read)(i2c_dev *dev, void *buf, size_t n, off_t offset)
Reads from the device.
Definition: i2c.h:299
i2c_dev::get_size
off_t(* get_size)(i2c_dev *dev)
Gets the file size.
Definition: i2c.h:320
i2c_dev::ioctl
int(* ioctl)(i2c_dev *dev, ioctl_command_t command, void *arg)
Device IO control.
Definition: i2c.h:315
i2c_dev::bus
i2c_bus * bus
The bus control.
Definition: i2c.h:335
i2c_dev::get_block_size
blksize_t(* get_block_size)(i2c_dev *dev)
Gets the file block size.
Definition: i2c.h:325
i2c_dev::destroy
void(* destroy)(i2c_dev *dev)
Destroys the device.
Definition: i2c.h:330
i2c_dev::address
uint16_t address
The device address.
Definition: i2c.h:340
i2c_dev::bus_fd
int bus_fd
File descriptor of the bus.
Definition: i2c.h:348
i2c_dev::write
ssize_t(* write)(i2c_dev *dev, const void *buf, size_t n, off_t offset)
Writes to the device.
Definition: i2c.h:307
i2c_msg
I2C transfer message.
Definition: i2c.h:138
i2c_rdwr_ioctl_data
Argument type for I2C_RDWR IO control call.
Definition: i2c-dev.h:125