
Hi,
I am taking a look at serial ports in U-Boot and it seems that the various functions in 'struct serial_device' do not include a pointer to the device they are talking about. Therefore for devices with multiple ports there is no way for these functions to know what to do.
The workaround in drivers/serial/serial.c (at least for NS16550) seems to be to declare stub functions which have the port number built in:
/* Multi serial device functions */ #define DECLARE_ESERIAL_FUNCTIONS(port) \ int eserial##port##_init (void) {\ int clock_divisor; \ clock_divisor = calc_divisor(serial_ports[port-1]); \ NS16550_init(serial_ports[port-1], clock_divisor); \ return(0);}\ void eserial##port##_setbrg (void) {\ serial_setbrg_dev(port);}\ int eserial##port##_getc (void) {\ return serial_getc_dev(port);}\ int eserial##port##_tstc (void) {\ return serial_tstc_dev(port);}\ void eserial##port##_putc (const char c) {\ serial_putc_dev(port, c);}\ void eserial##port##_puts (const char *s) {\ serial_puts_dev(port, s);}
... DECLARE_ESERIAL_FUNCTIONS(1); struct serial_device eserial1_device = INIT_ESERIAL_STRUCTURE(1,"eserial0","EUART1"); DECLARE_ESERIAL_FUNCTIONS(2); struct serial_device eserial2_device = INIT_ESERIAL_STRUCTURE(2,"eserial1","EUART2");
Would it not be better to pass the port number (or better the serial_device *) to each of the functions putc(), puts(), etc? What am I missing here?
Regards, Simon