1 /* 2 * I2C support for the X1600. 3 * 4 * Copyright (C) 2017, 2018, 2019, 2023 Paul Boddie <paul@boddie.org.uk> 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License as 8 * published by the Free Software Foundation; either version 2 of 9 * the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 * Boston, MA 02110-1301, USA 20 */ 21 22 #pragma once 23 24 #include <l4/sys/types.h> 25 #include <stdint.h> 26 27 28 29 #ifdef __cplusplus 30 31 #include <l4/devices/i2c-common.h> 32 33 // I2C channel. 34 35 class I2c_x1600_channel : public I2c_channel 36 { 37 protected: 38 bool high_speed_mode() 39 { return true; } 40 41 bool hold_enable() 42 { return false; } 43 44 bool stop_hold() 45 { return false; } 46 47 public: 48 explicit I2c_x1600_channel(l4_addr_t start, enum Clock_identifiers clock, 49 Cpm_chip *cpm, uint32_t frequency); 50 }; 51 52 // I2C device control. 53 54 class I2c_x1600_chip : public I2c_chip 55 { 56 protected: 57 unsigned int num_channels() 58 { return 2; } 59 60 I2c_channel *_get_channel(l4_addr_t addr, enum Clock_identifiers clock, 61 Cpm_chip *cpm, uint32_t frequency) 62 { return new I2c_x1600_channel(addr, clock, cpm, frequency); } 63 64 public: 65 explicit I2c_x1600_chip(l4_addr_t start, l4_addr_t end, Cpm_chip *cpm, 66 uint32_t frequency); 67 }; 68 69 #endif /* __cplusplus */ 70 71 72 73 /* C language interface. */ 74 75 EXTERN_C_BEGIN 76 77 void *x1600_i2c_init(l4_addr_t start, l4_addr_t end, void *cpm, 78 uint32_t frequency); 79 80 void *x1600_i2c_get_channel(void *i2c, uint8_t channel); 81 82 uint32_t x1600_i2c_get_frequency(void *i2c_channel); 83 84 void x1600_i2c_set_target(void *i2c_channel, uint8_t addr); 85 86 void x1600_i2c_start_read(void *i2c_channel, uint8_t buf[], unsigned int total, 87 int stop); 88 89 void x1600_i2c_read(void *i2c_channel); 90 91 void x1600_i2c_start_write(void *i2c_channel, uint8_t buf[], unsigned int total, 92 int stop); 93 94 void x1600_i2c_write(void *i2c_channel); 95 96 int x1600_i2c_read_done(void *i2c_channel); 97 98 int x1600_i2c_write_done(void *i2c_channel); 99 100 unsigned int x1600_i2c_have_read(void *i2c_channel); 101 102 unsigned int x1600_i2c_have_written(void *i2c_channel); 103 104 int x1600_i2c_failed(void *i2c_channel); 105 106 void x1600_i2c_stop(void *i2c_channel); 107 108 EXTERN_C_END