1.1 --- a/pkg/devices/lib/i2c/include/i2c-jz4780.h Sat Oct 28 01:15:45 2023 +0200
1.2 +++ b/pkg/devices/lib/i2c/include/i2c-jz4780.h Sun Oct 29 16:14:38 2023 +0100
1.3 @@ -28,91 +28,28 @@
1.4
1.5 #ifdef __cplusplus
1.6
1.7 -#include <l4/devices/cpm-jz4780.h>
1.8 -#include <l4/devices/hw_mmio_register_block.h>
1.9 +#include <l4/devices/i2c-common.h>
1.10
1.11 // I2C channel.
1.12
1.13 -class I2c_jz4780_channel
1.14 +class I2c_jz4780_channel : public I2c_channel
1.15 {
1.16 -private:
1.17 - Hw::Register_block<32> _regs;
1.18 - Cpm_jz4780_chip *_cpm;
1.19 - uint32_t _frequency;
1.20 -
1.21 - // Buffer management.
1.22 -
1.23 - unsigned int _pos, _reqpos, _total;
1.24 - uint8_t *_buf;
1.25 -
1.26 - // Status conditions.
1.27 -
1.28 - int _fail;
1.29 -
1.30 public:
1.31 - I2c_jz4780_channel(l4_addr_t start, Cpm_jz4780_chip *cpm,
1.32 - uint32_t frequency);
1.33 -
1.34 - void set_target(uint8_t addr);
1.35 -
1.36 - // Reading initiation and execution.
1.37 -
1.38 - void start_read(uint8_t buf[], unsigned int total);
1.39 - void read();
1.40 -
1.41 - // Writing initiation and execution.
1.42 -
1.43 - void start_write(uint8_t buf[], unsigned int total);
1.44 - void write();
1.45 -
1.46 - // Transaction control.
1.47 -
1.48 - void stop();
1.49 - void disable();
1.50 -
1.51 - // Specific status conditions.
1.52 -
1.53 - unsigned int have_read();
1.54 - unsigned int have_written();
1.55 - int read_done();
1.56 - int write_done();
1.57 -
1.58 - int failed();
1.59 - int read_failed();
1.60 - int write_failed();
1.61 -
1.62 -private:
1.63 - void enable();
1.64 -
1.65 - int active();
1.66 - int have_input();
1.67 - int have_output();
1.68 - int can_send();
1.69 -
1.70 - void reset_flags();
1.71 - void init_parameters();
1.72 - void set_frequency();
1.73 -
1.74 - void set_read_threshold();
1.75 - void queue_reads();
1.76 - void queue_writes();
1.77 - void store_reads();
1.78 + explicit I2c_jz4780_channel(l4_addr_t start, enum Clock_identifiers clock,
1.79 + Cpm_chip *cpm, uint32_t frequency);
1.80 };
1.81
1.82 // I2C device control.
1.83
1.84 -class I2c_jz4780_chip
1.85 +class I2c_jz4780_chip : public I2c_chip
1.86 {
1.87 -private:
1.88 - l4_addr_t _start, _end;
1.89 - Cpm_jz4780_chip *_cpm;
1.90 - uint32_t _frequency;
1.91 +protected:
1.92 + unsigned int num_channels()
1.93 + { return 5; }
1.94
1.95 public:
1.96 - I2c_jz4780_chip(l4_addr_t start, l4_addr_t end, Cpm_jz4780_chip *cpm,
1.97 - uint32_t frequency);
1.98 -
1.99 - I2c_jz4780_channel *get_channel(uint8_t channel);
1.100 + explicit I2c_jz4780_chip(l4_addr_t start, l4_addr_t end, Cpm_chip *cpm,
1.101 + uint32_t frequency);
1.102 };
1.103
1.104 #endif /* __cplusplus */
1.105 @@ -126,17 +63,19 @@
1.106 void *jz4780_i2c_init(l4_addr_t start, l4_addr_t end, void *cpm,
1.107 uint32_t frequency);
1.108
1.109 -void jz4780_i2c_disable(void *i2c_channel);
1.110 +void *jz4780_i2c_get_channel(void *i2c, uint8_t channel);
1.111
1.112 -void *jz4780_i2c_get_channel(void *i2c, uint8_t channel);
1.113 +uint32_t jz4780_i2c_get_frequency(void *i2c_channel);
1.114
1.115 void jz4780_i2c_set_target(void *i2c_channel, uint8_t addr);
1.116
1.117 -void jz4780_i2c_start_read(void *i2c_channel, uint8_t buf[], unsigned int total);
1.118 +void jz4780_i2c_start_read(void *i2c_channel, uint8_t buf[], unsigned int total,
1.119 + int stop);
1.120
1.121 void jz4780_i2c_read(void *i2c_channel);
1.122
1.123 -void jz4780_i2c_start_write(void *i2c_channel, uint8_t buf[], unsigned int total);
1.124 +void jz4780_i2c_start_write(void *i2c_channel, uint8_t buf[], unsigned int total,
1.125 + int stop);
1.126
1.127 void jz4780_i2c_write(void *i2c_channel);
1.128
1.129 @@ -150,6 +89,4 @@
1.130
1.131 int jz4780_i2c_failed(void *i2c_channel);
1.132
1.133 -void jz4780_i2c_stop(void *i2c_channel);
1.134 -
1.135 EXTERN_C_END