RTEMS 6.3
Loading...
Searching...
No Matches
i2c.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-2-Clause */
2
10
11/*
12 * Copyright (C) 2014, 2017 embedded brains GmbH & Co. KG
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
16 * are met:
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the distribution.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
34 */
35
36#ifndef _DEV_I2C_I2C_H
37#define _DEV_I2C_I2C_H
38
39#include <linux/i2c.h>
40#include <linux/i2c-dev.h>
41
42#include <rtems.h>
43#include <rtems/seterr.h>
44#include <rtems/thread.h>
45
46#include <sys/ioctl.h>
47#include <sys/stat.h>
48
49#ifdef __cplusplus
50extern "C" {
51#endif /* __cplusplus */
52
53typedef struct i2c_msg i2c_msg;
54
55typedef struct i2c_bus i2c_bus;
56
57typedef struct i2c_dev i2c_dev;
58
60
70
78
84
90#define I2C_BUS_OBTAIN 0x800
91
97#define I2C_BUS_RELEASE 0x801
98
104#define I2C_BUS_GET_CONTROL 0x802
105
111#define I2C_BUS_SET_CLOCK 0x803
112
114
118#define I2C_BUS_CLOCK_DEFAULT 100000
119
123struct i2c_bus {
135 int (*transfer)(i2c_bus *bus, i2c_msg *msgs, uint32_t msg_count);
136
146 int (*set_clock)(i2c_bus *bus, unsigned long clock);
147
153 void (*destroy)(i2c_bus *bus);
154
158 rtems_recursive_mutex mutex;
159
164
169
174
178 unsigned long retries;
179
184
188 unsigned long functionality;
189};
190
206int i2c_bus_init(i2c_bus *bus);
207
225i2c_bus *i2c_bus_alloc_and_init(size_t size);
226
232void i2c_bus_destroy(i2c_bus *bus);
233
240
254 i2c_bus *bus,
255 const char *bus_path
256);
257
267
273void i2c_bus_obtain(i2c_bus *bus);
274
280void i2c_bus_release(i2c_bus *bus);
281
296int i2c_bus_transfer(i2c_bus *bus, i2c_msg *msgs, uint32_t msg_count);
297
317 i2c_bus *bus,
318 i2c_msg *msgs,
319 uint32_t msg_count,
320 uint32_t flags
321);
322
327#define I2C_BUS_NOBLOCK (1u << 0)
328
330
338
342#define I2C_DEV_IO_CONTROL 0x900
343
347struct i2c_dev {
354 ssize_t (*read)(i2c_dev *dev, void *buf, size_t n, off_t offset);
355
362 ssize_t (*write)(i2c_dev *dev, const void *buf, size_t n, off_t offset);
363
370 int (*ioctl)(i2c_dev *dev, ioctl_command_t command, void *arg);
371
375 off_t (*get_size)(i2c_dev *dev);
376
380 blksize_t (*get_block_size)(i2c_dev *dev);
381
385 void (*destroy)(i2c_dev *dev);
386
391
395 uint16_t address;
396
404};
405
406
424int i2c_dev_init(i2c_dev *dev, const char *bus_path, uint16_t address);
425
446 size_t size,
447 const char *bus_path,
448 uint16_t address
449);
450
456void i2c_dev_destroy(i2c_dev *dev);
457
464
478 i2c_dev *dev,
479 const char *dev_path
480);
481 /* end of i2c device driver */
483
485
486#ifdef __cplusplus
487}
488#endif /* __cplusplus */
489
490#endif /* _DEV_I2C_I2C_H */
RTEMS Port of Linux I2C API.
void i2c_bus_destroy(i2c_bus *bus)
Destroys a bus control.
Definition i2c-bus.c:318
int i2c_bus_transfer(i2c_bus *bus, i2c_msg *msgs, uint32_t msg_count)
Transfers I2C messages.
Definition i2c-bus.c:83
void i2c_bus_destroy_and_free(i2c_bus *bus)
Destroys a bus control and frees its memory.
Definition i2c-bus.c:323
void i2c_bus_obtain(i2c_bus *bus)
Obtains the bus.
Definition i2c-bus.c:33
int i2c_bus_do_transfer(i2c_bus *bus, i2c_msg *msgs, uint32_t msg_count, uint32_t flags)
Transfers I2C messages with optional flags.
Definition i2c-bus.c:43
int i2c_bus_init(i2c_bus *bus)
Initializes a bus control.
Definition i2c-bus.c:329
int i2c_bus_register(i2c_bus *bus, const char *bus_path)
Registers a bus control.
Definition i2c-bus.c:264
i2c_bus * i2c_bus_alloc_and_init(size_t size)
Allocates a bus control from the heap and initializes it.
Definition i2c-bus.c:336
int i2c_bus_try_obtain(i2c_bus *bus)
Try to obtain the bus.
Definition i2c-bus.c:28
void i2c_bus_release(i2c_bus *bus)
Releases the bus.
Definition i2c-bus.c:38
int i2c_dev_init(i2c_dev *dev, const char *bus_path, uint16_t address)
Initializes a device control.
Definition i2c-dev.c:260
void i2c_dev_destroy(i2c_dev *dev)
Destroys a device control.
Definition i2c-dev.c:245
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:265
int i2c_dev_register(i2c_dev *dev, const char *dev_path)
Registers a device control.
Definition i2c-dev.c:134
void i2c_dev_destroy_and_free(i2c_dev *dev)
Destroys a device control and frees its memory.
Definition i2c-dev.c:254
Watchdog_Interval rtems_interval
This type represents clock tick intervals.
Definition types.h:114
RTEMS Port of Linux I2C Device API.
This header file defines the RTEMS Classic API.
This header file defines macros to set errno and return minus one.
I2C bus control.
Definition i2c.h:123
unsigned long functionality
Controller functionality.
Definition i2c.h:188
int(*) set_clock(i2c_bus *bus, unsigned long clock)
Sets the bus clock.
Definition i2c.h:146
unsigned long retries
Transfer retry count.
Definition i2c.h:178
rtems_interval timeout
Transaction timeout in ticks.
Definition i2c.h:183
uint16_t default_address
Default slave device address.
Definition i2c.h:163
bool use_pec
Use SMBus PEC.
Definition i2c.h:173
rtems_recursive_mutex mutex
Mutex to protect the bus access.
Definition i2c.h:158
bool ten_bit_address
Use 10-bit addresses.
Definition i2c.h:168
void(*) destroy(i2c_bus *bus)
Destroys the bus.
Definition i2c.h:153
int(*) transfer(i2c_bus *bus, i2c_msg *msgs, uint32_t msg_count)
Transfers I2C messages.
Definition i2c.h:135
I2C slave device control.
Definition i2c.h:347
int(*) ioctl(i2c_dev *dev, ioctl_command_t command, void *arg)
Device IO control.
Definition i2c.h:370
void(*) destroy(i2c_dev *dev)
Destroys the device.
Definition i2c.h:385
i2c_bus * bus
The bus control.
Definition i2c.h:390
ssize_t(*) write(i2c_dev *dev, const void *buf, size_t n, off_t offset)
Writes to the device.
Definition i2c.h:362
off_t(*) get_size(i2c_dev *dev)
Gets the file size.
Definition i2c.h:375
uint16_t address
The device address.
Definition i2c.h:395
blksize_t(*) get_block_size(i2c_dev *dev)
Gets the file block size.
Definition i2c.h:380
ssize_t(*) read(i2c_dev *dev, void *buf, size_t n, off_t offset)
Reads from the device.
Definition i2c.h:354
int bus_fd
File descriptor of the bus.
Definition i2c.h:403
I2C transfer message.
Definition i2c.h:151
Argument type for I2C_RDWR IO control call.
Definition i2c-dev.h:138
This header file provides the API of Self-Contained Objects.