1 /*
2  * Copyright (c) 2013 Google Inc.
3  *
4  * Use of this source code is governed by a MIT-style
5  * license that can be found in the LICENSE file or at
6  * https://opensource.org/licenses/MIT
7  */
8 #pragma once
9 
10 #include <stdint.h>
11 #include <dev/i2c.h>
12 
13 typedef struct gpio_i2c_info {
14     const int sda;
15     const int scl;
16     uint32_t  hcd;  /* 1/2 I2C clock delay in cpu cycles */
17     uint32_t  qcd;  /* 1/4 I2C clock delay in cpu cycles */
18 } gpio_i2c_info_t;
19 
20 #define DEFINE_GPIO_I2C(_name,                 \
21                         _sda_gpio_id,          \
22                         _scl_gpio_id,          \
23                         _clk_ticks)            \
24 static const gpio_i2c_info_t _name = {         \
25     .sda            = _sda_gpio_id,            \
26     .scl            = _scl_gpio_id,            \
27     .hcd            = ((_clk_ticks + 1) >> 1), \
28     .qcd            = ((_clk_ticks + 3) >> 2), \
29 }
30 
31 void gpio_i2c_add_bus(uint32_t bus_id, const gpio_i2c_info_t *info);
32 
33 void gpio_i2c_init_early(void);
34 void gpio_i2c_init(void);
35 status_t gpio_i2c_transmit(int, uint8_t, const void *, size_t);
36 status_t gpio_i2c_receive(int, uint8_t, void *, size_t);
37 status_t gpio_i2c_write_reg_bytes(int, uint8_t, uint8_t, const uint8_t *, size_t);
38 status_t gpio_i2c_read_reg_bytes(int, uint8_t, uint8_t, uint8_t *, size_t);
39 
40