source: mainline/kernel/genarch/src/drivers/i8042/i8042.c@ 2a77841d

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 2a77841d was c2417bc, checked in by Martin Decky <martin@…>, 16 years ago

change the way how input devices are wired together according to ticket #44
(also the proposal http://lists.modry.cz/cgi-bin/private/helenos-devel/2009-March/002507.html)

  • Property mode set to 100644
File size: 3.5 KB
RevLine 
[f761f1eb]1/*
[4c7257b]2 * Copyright (c) 2009 Jakub Jermar
[f761f1eb]3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
[3c79afe]29/** @addtogroup genarch
[b45c443]30 * @{
31 */
[3c5006a0]32/**
[cc73a8a1]33 * @file
[3c79afe]34 * @brief i8042 processor driver
[3c5006a0]35 *
[411b6a6]36 * It takes care of the i8042 serial communication.
[c8bf88d]37 *
[b45c443]38 */
39
[411b6a6]40#include <genarch/drivers/i8042/i8042.h>
[91825d90]41#include <genarch/drivers/legacy/ia32/io.h>
[f761f1eb]42#include <arch/asm.h>
[607c5f9]43#include <console/chardev.h>
[411b6a6]44#include <mm/slab.h>
[84afc7b]45#include <ddi/device.h>
[6ccb238]46
[3c79afe]47#define i8042_SET_COMMAND 0x60
48#define i8042_COMMAND 0x69
[149d14e5]49#define i8042_CPU_RESET 0xfe
[3c79afe]50
51#define i8042_BUFFER_FULL_MASK 0x01
52#define i8042_WAIT_MASK 0x02
[607c5f9]53
[c9b550b]54static irq_ownership_t i8042_claim(irq_t *irq)
[41d33ac]55{
[c9b550b]56 i8042_instance_t *i8042_instance = irq->instance;
[4544884]57 i8042_t *dev = i8042_instance->i8042;
[3c79afe]58
[4544884]59 if (pio_read_8(&dev->status) & i8042_BUFFER_FULL_MASK)
60 return IRQ_ACCEPT;
61 else
62 return IRQ_DECLINE;
[cea12e9]63}
[41d33ac]64
[6cd9aa6]65static void i8042_irq_handler(irq_t *irq)
[cea12e9]66{
[4544884]67 i8042_instance_t *instance = irq->instance;
68 i8042_t *dev = instance->i8042;
69 uint8_t status;
[3c79afe]70
[4544884]71 if (((status = pio_read_8(&dev->status)) & i8042_BUFFER_FULL_MASK)) {
[3c79afe]72 uint8_t data = pio_read_8(&dev->data);
[c2417bc]73 indev_push_character(instance->kbrdin, data);
[cea12e9]74 }
75}
[6ccb238]76
[c2417bc]77/**< Clear input buffer. */
78static void i8042_clear_buffer(i8042_t *dev)
79{
80 while (pio_read_8(&dev->status) & i8042_BUFFER_FULL_MASK)
81 (void) pio_read_8(&dev->data);
82}
83
[cea12e9]84/** Initialize i8042. */
[c2417bc]85i8042_instance_t *i8042_init(i8042_t *dev, inr_t inr)
[cea12e9]86{
[3c79afe]87 i8042_instance_t *instance
88 = malloc(sizeof(i8042_instance_t), FRAME_ATOMIC);
[c2417bc]89 if (instance) {
90 instance->i8042 = dev;
91 instance->kbrdin = NULL;
92
93 irq_initialize(&instance->irq);
94 instance->irq.devno = device_assign_devno();
95 instance->irq.inr = inr;
96 instance->irq.claim = i8042_claim;
97 instance->irq.handler = i8042_irq_handler;
98 instance->irq.instance = instance;
99
100 }
[5b0ae4be]101
[c2417bc]102 return instance;
103}
104
105void i8042_wire(i8042_instance_t *instance, indev_t *kbrdin)
106{
107 ASSERT(instance);
108 ASSERT(kbrdin);
[16d71f41]109
[c2417bc]110 instance->kbrdin = kbrdin;
[5b0ae4be]111 irq_register(&instance->irq);
[c2417bc]112 i8042_clear_buffer(instance->i8042);
[30ab05f]113}
114
[149d14e5]115/* Reset CPU by pulsing pin 0 */
116void i8042_cpu_reset(i8042_t *dev)
117{
118 interrupts_disable();
119
[c2417bc]120 i8042_clear_buffer(dev);
[149d14e5]121
122 /* Reset CPU */
123 pio_write_8(&dev->status, i8042_CPU_RESET);
124}
125
[3c5006a0]126/** @}
[b45c443]127 */
Note: See TracBrowser for help on using the repository browser.