1 /* 2 * JZ4780 HDMI peripheral support. 3 * 4 * Copyright (C) 2020 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/hw_mmio_register_block.h> 32 33 // HDMI device control. 34 35 class Hdmi_jz4780_chip 36 { 37 private: 38 l4_addr_t _start, _end; 39 l4_cap_idx_t _irq; 40 Hw::Register_block<8> _regs; 41 42 // Identification. 43 44 uint16_t _version; 45 46 // Transfer properties. 47 48 bool _segment_read; 49 uint8_t _device_register; 50 51 protected: 52 void get_identification(); 53 54 void irq_init(); 55 56 void i2c_init(); 57 long i2c_wait(); 58 59 void hotplug_init(); 60 61 public: 62 Hdmi_jz4780_chip(l4_addr_t start, l4_addr_t end, l4_cap_idx_t irq); 63 64 void get_version(uint8_t *major, uint16_t *minor); 65 66 int i2c_read(uint8_t *buf, unsigned int length); 67 void i2c_set_address(uint8_t address); 68 void i2c_set_segment(uint8_t segment); 69 void i2c_set_register(uint8_t device_register); 70 71 bool connected(); 72 long wait_for_connection(); 73 }; 74 75 #endif /* __cplusplus */ 76 77 78 79 /* C language interface. */ 80 81 EXTERN_C_BEGIN 82 83 void *jz4780_hdmi_init(l4_addr_t start, l4_addr_t end, l4_cap_idx_t irq); 84 85 void jz4780_hdmi_get_version(void *hdmi, uint8_t *major, uint16_t *minor); 86 87 int jz4780_hdmi_i2c_read(void *hdmi, uint8_t *buf, unsigned int length); 88 89 void jz4780_hdmi_i2c_set_address(void *hdmi, uint8_t address); 90 91 void jz4780_hdmi_i2c_set_segment(void *hdmi, uint8_t segment); 92 93 void jz4780_hdmi_i2c_set_register(void *hdmi, uint8_t device_register); 94 95 int jz4780_hdmi_connected(void *hdmi); 96 97 long jz4780_hdmi_wait_for_connection(void *hdmi); 98 99 EXTERN_C_END