1 /* 2 * I2C support for the JZ4780. 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-jz4780.h> 23 24 /* 25 I2C pins: 26 27 I2C0: PD30/SMB0_SDA, PD31/SMB0_SCK 28 I2C1: PD30/SMB1_SDA, PD31/SMB1_SCK (pulled up on CI20) 29 I2C2: PF16/SMB2_SDA, PF17/SMB2_SCK 30 PWM: PD10/SMB3_SDA, PD11/SMB3_SCK 31 PWM: PE3/SMB4_SDA, PE4/SMB4_SCK 32 I2C4: PE12/SMB4_SDA, PE13/SMB4_SCK 33 HDMI: PF25/SMB4_SDA/DDCSDA, PF24/SMB4_SCK/DDCSCK 34 35 See: http://mipscreator.imgtec.com/CI20/hardware/board/ci20_jz4780_v2.0.pdf 36 */ 37 38 39 40 // Initialise a channel. 41 42 I2c_jz4780_channel::I2c_jz4780_channel(l4_addr_t start, 43 enum Clock_identifiers clock, 44 Cpm_chip *cpm, 45 uint32_t frequency) 46 : I2c_channel(start, clock, cpm, frequency) 47 { 48 } 49 50 51 52 // Initialise the I2C controller. 53 54 I2c_jz4780_chip::I2c_jz4780_chip(l4_addr_t start, l4_addr_t end, 55 Cpm_chip *cpm, 56 uint32_t frequency) 57 : I2c_chip(start, end, cpm, frequency) 58 { 59 } 60 61 62 63 // C language interface functions. 64 65 void *jz4780_i2c_init(l4_addr_t start, l4_addr_t end, void *cpm, uint32_t frequency) 66 { 67 return (void *) new I2c_jz4780_chip(start, end, static_cast<Cpm_chip *>(cpm), frequency); 68 } 69 70 void *jz4780_i2c_get_channel(void *i2c, uint8_t channel) 71 { 72 return static_cast<I2c_jz4780_chip *>(i2c)->get_channel(channel); 73 } 74 75 uint32_t jz4780_i2c_get_frequency(void *i2c_channel) 76 { 77 return static_cast<I2c_jz4780_channel *>(i2c_channel)->get_frequency(); 78 } 79 80 void jz4780_i2c_set_target(void *i2c_channel, uint8_t addr) 81 { 82 static_cast<I2c_jz4780_channel *>(i2c_channel)->set_target(addr); 83 } 84 85 void jz4780_i2c_start_read(void *i2c_channel, uint8_t buf[], unsigned int total, 86 int stop) 87 { 88 static_cast<I2c_jz4780_channel *>(i2c_channel)->start_read(buf, total, stop); 89 } 90 91 void jz4780_i2c_read(void *i2c_channel) 92 { 93 static_cast<I2c_jz4780_channel *>(i2c_channel)->read(); 94 } 95 96 void jz4780_i2c_start_write(void *i2c_channel, uint8_t buf[], unsigned int total, 97 int stop) 98 { 99 static_cast<I2c_jz4780_channel *>(i2c_channel)->start_write(buf, total, stop); 100 } 101 102 void jz4780_i2c_write(void *i2c_channel) 103 { 104 static_cast<I2c_jz4780_channel *>(i2c_channel)->write(); 105 } 106 107 int jz4780_i2c_read_done(void *i2c_channel) 108 { 109 return static_cast<I2c_jz4780_channel *>(i2c_channel)->read_done(); 110 } 111 112 int jz4780_i2c_write_done(void *i2c_channel) 113 { 114 return static_cast<I2c_jz4780_channel *>(i2c_channel)->write_done(); 115 } 116 117 unsigned int jz4780_i2c_have_read(void *i2c_channel) 118 { 119 return static_cast<I2c_jz4780_channel *>(i2c_channel)->have_read(); 120 } 121 122 unsigned int jz4780_i2c_have_written(void *i2c_channel) 123 { 124 return static_cast<I2c_jz4780_channel *>(i2c_channel)->have_written(); 125 } 126 127 int jz4780_i2c_failed(void *i2c_channel) 128 { 129 return static_cast<I2c_jz4780_channel *>(i2c_channel)->failed(); 130 } 131 132 void jz4780_i2c_stop(void *i2c_channel) 133 { 134 static_cast<I2c_jz4780_channel *>(i2c_channel)->stop(); 135 }