1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief I2C Driver for SEMTECH SC620 Octal LED Driver |
---|
5 | */ |
---|
6 | |
---|
7 | /* |
---|
8 | * Copyright (c) 2013 embedded brains GmbH. All rights reserved. |
---|
9 | * |
---|
10 | * embedded brains GmbH |
---|
11 | * Obere Lagerstr. 30 |
---|
12 | * 82178 Puchheim |
---|
13 | * Germany |
---|
14 | * <rtems@embedded-brains.de> |
---|
15 | * |
---|
16 | * The license and distribution terms for this file may be |
---|
17 | * found in the file LICENSE in this distribution or at |
---|
18 | * http://www.rtems.org/license/LICENSE. |
---|
19 | */ |
---|
20 | |
---|
21 | #ifdef HAVE_CONFIG_H |
---|
22 | #include "config.h" |
---|
23 | #endif |
---|
24 | |
---|
25 | #include <libchip/i2c-sc620.h> |
---|
26 | |
---|
27 | #include <rtems/libio.h> |
---|
28 | |
---|
29 | #define SC620_REG_COUNT 10 |
---|
30 | |
---|
31 | static rtems_status_code i2c_sc620_write( |
---|
32 | rtems_device_major_number major, |
---|
33 | rtems_device_minor_number minor, |
---|
34 | void *arg |
---|
35 | ) |
---|
36 | { |
---|
37 | rtems_status_code sc = RTEMS_IO_ERROR; |
---|
38 | rtems_libio_rw_args_t *rw = arg; |
---|
39 | unsigned char *buf = (unsigned char *) &rw->buffer[0]; |
---|
40 | |
---|
41 | if (rw->count == 2 && buf[0] < SC620_REG_COUNT) { |
---|
42 | int rv; |
---|
43 | |
---|
44 | rv = rtems_libi2c_start_write_bytes( |
---|
45 | minor, buf, 2 |
---|
46 | ); |
---|
47 | if (rv == 2) { |
---|
48 | sc = rtems_libi2c_send_stop(minor); |
---|
49 | } |
---|
50 | } |
---|
51 | |
---|
52 | rw->bytes_moved = sc == RTEMS_SUCCESSFUL ? 2 : 0; |
---|
53 | |
---|
54 | return sc; |
---|
55 | } |
---|
56 | |
---|
57 | static rtems_status_code i2c_sc620_read( |
---|
58 | rtems_device_major_number major, |
---|
59 | rtems_device_minor_number minor, |
---|
60 | void *arg |
---|
61 | ) |
---|
62 | { |
---|
63 | rtems_status_code sc = RTEMS_IO_ERROR; |
---|
64 | rtems_libio_rw_args_t *rw = arg; |
---|
65 | unsigned char *buf = (unsigned char *) &rw->buffer[0]; |
---|
66 | |
---|
67 | if (rw->count == 1 && buf[0] < SC620_REG_COUNT) { |
---|
68 | int rv; |
---|
69 | |
---|
70 | rv = rtems_libi2c_start_write_bytes(minor, buf, 1); |
---|
71 | if (rv == 1) { |
---|
72 | sc = rtems_libi2c_send_addr(minor, 0); |
---|
73 | if (sc == RTEMS_SUCCESSFUL) { |
---|
74 | rv = rtems_libi2c_read_bytes(minor, buf, 1); |
---|
75 | if (rv == 1) { |
---|
76 | sc = rtems_libi2c_send_stop(minor); |
---|
77 | } |
---|
78 | } |
---|
79 | } |
---|
80 | } |
---|
81 | |
---|
82 | rw->bytes_moved = sc == RTEMS_SUCCESSFUL ? 1 : 0; |
---|
83 | |
---|
84 | return sc; |
---|
85 | } |
---|
86 | |
---|
87 | static rtems_driver_address_table i2c_sc620_ops = { |
---|
88 | .read_entry = i2c_sc620_read, |
---|
89 | .write_entry = i2c_sc620_write |
---|
90 | }; |
---|
91 | |
---|
92 | rtems_libi2c_drv_t i2c_sc620_driver = { |
---|
93 | .ops = &i2c_sc620_ops, |
---|
94 | .size = sizeof(i2c_sc620_driver) |
---|
95 | }; |
---|