1 /* 2 * I2C support for the X1600. 3 * 4 * Copyright (C) 2017, 2018, 2021, 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 #include <l4/devices/i2c-x1600.h> 23 24 25 26 // Initialise a channel. 27 28 I2c_x1600_channel::I2c_x1600_channel(l4_addr_t start, 29 enum Clock_identifiers clock, 30 Cpm_chip *cpm, 31 uint32_t frequency) 32 : I2c_channel(start, clock, cpm, frequency) 33 { 34 } 35 36 37 38 // Initialise the I2C controller. 39 40 I2c_x1600_chip::I2c_x1600_chip(l4_addr_t start, l4_addr_t end, 41 Cpm_chip *cpm, 42 uint32_t frequency) 43 : I2c_chip(start, end, cpm, frequency) 44 { 45 } 46 47 48 49 // C language interface functions. 50 51 void *x1600_i2c_init(l4_addr_t start, l4_addr_t end, void *cpm, uint32_t frequency) 52 { 53 return (void *) new I2c_x1600_chip(start, end, static_cast<Cpm_chip *>(cpm), frequency); 54 } 55 56 void *x1600_i2c_get_channel(void *i2c, uint8_t channel) 57 { 58 return static_cast<I2c_x1600_chip *>(i2c)->get_channel(channel); 59 } 60 61 uint32_t x1600_i2c_get_frequency(void *i2c_channel) 62 { 63 return static_cast<I2c_x1600_channel *>(i2c_channel)->get_frequency(); 64 } 65 66 void x1600_i2c_set_target(void *i2c_channel, uint8_t addr) 67 { 68 static_cast<I2c_x1600_channel *>(i2c_channel)->set_target(addr); 69 } 70 71 void x1600_i2c_start_read(void *i2c_channel, uint8_t buf[], unsigned int total, 72 int stop) 73 { 74 static_cast<I2c_x1600_channel *>(i2c_channel)->start_read(buf, total, stop); 75 } 76 77 void x1600_i2c_read(void *i2c_channel) 78 { 79 static_cast<I2c_x1600_channel *>(i2c_channel)->read(); 80 } 81 82 void x1600_i2c_start_write(void *i2c_channel, uint8_t buf[], unsigned int total, 83 int stop) 84 { 85 static_cast<I2c_x1600_channel *>(i2c_channel)->start_write(buf, total, stop); 86 } 87 88 void x1600_i2c_write(void *i2c_channel) 89 { 90 static_cast<I2c_x1600_channel *>(i2c_channel)->write(); 91 } 92 93 int x1600_i2c_read_done(void *i2c_channel) 94 { 95 return static_cast<I2c_x1600_channel *>(i2c_channel)->read_done(); 96 } 97 98 int x1600_i2c_write_done(void *i2c_channel) 99 { 100 return static_cast<I2c_x1600_channel *>(i2c_channel)->write_done(); 101 } 102 103 unsigned int x1600_i2c_have_read(void *i2c_channel) 104 { 105 return static_cast<I2c_x1600_channel *>(i2c_channel)->have_read(); 106 } 107 108 unsigned int x1600_i2c_have_written(void *i2c_channel) 109 { 110 return static_cast<I2c_x1600_channel *>(i2c_channel)->have_written(); 111 } 112 113 int x1600_i2c_failed(void *i2c_channel) 114 { 115 return static_cast<I2c_x1600_channel *>(i2c_channel)->failed(); 116 } 117 118 void x1600_i2c_stop(void *i2c_channel) 119 { 120 static_cast<I2c_x1600_channel *>(i2c_channel)->stop(); 121 }