kexts: serialcon: implement writing to serial ports via tty interface
This commit is contained in:
@@ -162,6 +162,16 @@ void serialcon_init(int baud)
|
||||
console_register(&serialcon);
|
||||
}
|
||||
|
||||
static void serialcon_putc(struct device *dev, int c, int xpos, int ypos, tty_attrib_t attrib)
|
||||
{
|
||||
unsigned int port = (uintptr_t)dev->dev_priv;
|
||||
serial_putchar(port, c);
|
||||
}
|
||||
|
||||
static struct tty_driver_ops serialcon_ops = {
|
||||
.tty_putc = serialcon_putc,
|
||||
};
|
||||
|
||||
static kern_status_t online(struct kext *self)
|
||||
{
|
||||
serialcon_driver = tty_driver_create(self, "ttyS");
|
||||
@@ -169,6 +179,8 @@ static kern_status_t online(struct kext *self)
|
||||
return KERN_NO_MEMORY;
|
||||
}
|
||||
|
||||
serialcon_driver->tty_ops = &serialcon_ops;
|
||||
|
||||
tty_driver_register(serialcon_driver);
|
||||
|
||||
struct device *ttyS0 = tty_device_create();
|
||||
@@ -176,11 +188,21 @@ static kern_status_t online(struct kext *self)
|
||||
struct device *ttyS2 = tty_device_create();
|
||||
struct device *ttyS3 = tty_device_create();
|
||||
|
||||
ttyS0->dev_priv = (void *)COM1;
|
||||
ttyS1->dev_priv = (void *)COM2;
|
||||
ttyS2->dev_priv = (void *)COM3;
|
||||
ttyS3->dev_priv = (void *)COM4;
|
||||
|
||||
snprintf(ttyS0->dev_name, sizeof ttyS0->dev_name, "ttyS0");
|
||||
snprintf(ttyS1->dev_name, sizeof ttyS1->dev_name, "ttyS1");
|
||||
snprintf(ttyS2->dev_name, sizeof ttyS2->dev_name, "ttyS2");
|
||||
snprintf(ttyS3->dev_name, sizeof ttyS3->dev_name, "ttyS3");
|
||||
|
||||
init_serial_port(COM1, 115200);
|
||||
init_serial_port(COM2, 115200);
|
||||
init_serial_port(COM3, 115200);
|
||||
init_serial_port(COM4, 115200);
|
||||
|
||||
tty_device_register(ttyS0, serialcon_driver, misc_device());
|
||||
tty_device_register(ttyS1, serialcon_driver, misc_device());
|
||||
tty_device_register(ttyS2, serialcon_driver, misc_device());
|
||||
|
||||
Reference in New Issue
Block a user