Rev 4153 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4153 | Rev 4327 | ||
---|---|---|---|
Line 41... | Line 41... | ||
41 | #include <mm/slab.h> |
41 | #include <mm/slab.h> |
42 | #include <ddi/device.h> |
42 | #include <ddi/device.h> |
43 | 43 | ||
44 | #define LSR_DATA_READY 0x01 |
44 | #define LSR_DATA_READY 0x01 |
45 | 45 | ||
46 | static indev_operations_t kbrdin_ops = { |
- | |
47 | .poll = NULL |
- | |
48 | }; |
- | |
49 | - | ||
50 | static irq_ownership_t ns16550_claim(irq_t *irq) |
46 | static irq_ownership_t ns16550_claim(irq_t *irq) |
51 | { |
47 | { |
52 | ns16550_instance_t *instance = irq->instance; |
48 | ns16550_instance_t *instance = irq->instance; |
53 | ns16550_t *dev = instance->ns16550; |
49 | ns16550_t *dev = instance->ns16550; |
54 | 50 | ||
Line 62... | Line 58... | ||
62 | { |
58 | { |
63 | ns16550_instance_t *instance = irq->instance; |
59 | ns16550_instance_t *instance = irq->instance; |
64 | ns16550_t *dev = instance->ns16550; |
60 | ns16550_t *dev = instance->ns16550; |
65 | 61 | ||
66 | if (pio_read_8(&dev->lsr) & LSR_DATA_READY) { |
62 | if (pio_read_8(&dev->lsr) & LSR_DATA_READY) { |
67 | uint8_t x = pio_read_8(&dev->rbr); |
63 | uint8_t data = pio_read_8(&dev->rbr); |
68 | indev_push_character(&instance->kbrdin, x); |
64 | indev_push_character(instance->kbrdin, data); |
69 | } |
65 | } |
70 | } |
66 | } |
71 | 67 | ||
- | 68 | /**< Clear input buffer. */ |
|
- | 69 | static void ns16550_clear_buffer(ns16550_t *dev) |
|
- | 70 | { |
|
- | 71 | while ((pio_read_8(&dev->lsr) & LSR_DATA_READY)) |
|
- | 72 | (void) pio_read_8(&dev->rbr); |
|
- | 73 | } |
|
- | 74 | ||
72 | /** Initialize ns16550. |
75 | /** Initialize ns16550. |
73 | * |
76 | * |
74 | * @param dev Addrress of the beginning of the device in I/O space. |
77 | * @param dev Addrress of the beginning of the device in I/O space. |
75 | * @param devno Device number. |
78 | * @param devno Device number. |
76 | * @param inr Interrupt number. |
79 | * @param inr Interrupt number. |
77 | * @param cir Clear interrupt function. |
80 | * @param cir Clear interrupt function. |
78 | * @param cir_arg First argument to cir. |
81 | * @param cir_arg First argument to cir. |
79 | * |
82 | * |
80 | * @return Keyboard device pointer or NULL on failure. |
83 | * @return Keyboard instance or NULL on failure. |
81 | * |
84 | * |
82 | */ |
85 | */ |
83 | indev_t *ns16550_init(ns16550_t *dev, inr_t inr, cir_t cir, void *cir_arg) |
86 | ns16550_instance_t *ns16550_init(ns16550_t *dev, inr_t inr, cir_t cir, void *cir_arg) |
84 | { |
87 | { |
85 | ns16550_instance_t *instance |
88 | ns16550_instance_t *instance |
86 | = malloc(sizeof(ns16550_instance_t), FRAME_ATOMIC); |
89 | = malloc(sizeof(ns16550_instance_t), FRAME_ATOMIC); |
87 | if (!instance) |
90 | if (instance) { |
- | 91 | instance->ns16550 = dev; |
|
88 | return NULL; |
92 | instance->kbrdin = NULL; |
89 | 93 | ||
90 | indev_initialize("ns16550", &instance->kbrdin, &kbrdin_ops); |
94 | irq_initialize(&instance->irq); |
- | 95 | instance->irq.devno = device_assign_devno(); |
|
- | 96 | instance->irq.inr = inr; |
|
- | 97 | instance->irq.claim = ns16550_claim; |
|
- | 98 | instance->irq.handler = ns16550_irq_handler; |
|
- | 99 | instance->irq.instance = instance; |
|
- | 100 | instance->irq.cir = cir; |
|
- | 101 | instance->irq.cir_arg = cir_arg; |
|
- | 102 | } |
|
91 | 103 | ||
92 | instance->ns16550 = dev; |
104 | return instance; |
- | 105 | } |
|
- | 106 | ||
- | 107 | void ns16550_wire(ns16550_instance_t *instance, indev_t *kbrdin) |
|
- | 108 | { |
|
- | 109 | ASSERT(instance); |
|
- | 110 | ASSERT(kbrdin); |
|
93 | 111 | ||
94 | irq_initialize(&instance->irq); |
- | |
95 | instance->irq.devno = device_assign_devno(); |
- | |
96 | instance->irq.inr = inr; |
112 | instance->kbrdin = kbrdin; |
97 | instance->irq.claim = ns16550_claim; |
- | |
98 | instance->irq.handler = ns16550_irq_handler; |
- | |
99 | instance->irq.instance = instance; |
- | |
100 | instance->irq.cir = cir; |
- | |
101 | instance->irq.cir_arg = cir_arg; |
- | |
102 | irq_register(&instance->irq); |
113 | irq_register(&instance->irq); |
103 | 114 | ||
104 | while ((pio_read_8(&dev->lsr) & LSR_DATA_READY)) |
115 | ns16550_clear_buffer(instance->ns16550); |
105 | (void) pio_read_8(&dev->rbr); |
- | |
106 | 116 | ||
107 | /* Enable interrupts */ |
117 | /* Enable interrupts */ |
108 | pio_write_8(&dev->ier, IER_ERBFI); |
118 | pio_write_8(&instance->ns16550->ier, IER_ERBFI); |
109 | pio_write_8(&dev->mcr, MCR_OUT2); |
119 | pio_write_8(&instance->ns16550->mcr, MCR_OUT2); |
110 | - | ||
111 | return &instance->kbrdin; |
- | |
112 | } |
120 | } |
113 | 121 | ||
114 | /** @} |
122 | /** @} |
115 | */ |
123 | */ |