Main Page | Directories | File List | Globals

i8254.c

Go to the documentation of this file.
00001 /*
00002  * kernel_drivers/adi_chips/i8254.c
00003  *
00004  * Copyright (c) 2003-2004 Lukasz Dembinski <dembol@nasa.com.pl>
00005  * All Rights Reserved
00006  * 
00007  * Date:        2004/01
00008  * Author:      Lukasz Dembinski
00009  * Info:        i8254.c core file
00010  * Contact:     mailto: <dembol@nasa.com.pl>
00011  *
00012  */
00013 #include <agnix/agnix.h>
00014 #include <agnix/adi/adi.h>
00015 #include <agnix/spinlock.h>
00016 #include <asm/types.h>
00017 #include <agnix/ioport.h>
00018 #include <agnix/memory.h>
00019 
00020 u16 i8254_read_count(struct chip_s *chip, u8 counter)
00021 {
00022     u8 latch_word = 0;
00023     u8 lsb, msb;
00024     u16 count;
00025 
00026     CHIP_LOCK;
00027 
00028     latch_word |= (counter << 6);
00029     
00030     outb(latch_word, TCW);
00031     lsb = inb(TMRCNT + counter);
00032     msb = inb(TMRCNT + counter);
00033     count = (msb << 8) | lsb;
00034 
00035     CHIP_UNLOCK;
00036 
00037     return count;
00038 }
00039 
00040 void i8254_write_count(struct chip_s *chip, u8 counter, u16 count)
00041 {
00042     CHIP_LOCK;
00043 
00044     outb((count) & 0xFF, TMRCNT + counter);
00045     outb((count >> 8) & 0xFF, TMRCNT + counter);
00046     
00047     CHIP_UNLOCK;
00048 }
00049 
00050 void i8254_set_mode(struct chip_s *chip, u8 counter, u8 mode, u8 bcd)
00051 {
00052     u8  tcw_word = 0;
00053 
00054     CHIP_LOCK;
00055 
00056     tcw_word |= (counter << 6) | (3 << 4) | (mode << 1) | bcd;
00057     outb(tcw_word, TCW);
00058 
00059     CHIP_UNLOCK;
00060 }
00061 
00062 struct chip_pit_ops_s   i8254_pit_ops = 
00063 {
00064     i8254_set_mode,
00065     i8254_write_count,
00066     i8254_read_count    
00067 };
00068 
00069 int i8254_chip_init(struct chip_s *chip)
00070 {
00071     CHIP_LOCK;
00072 
00073     /* disable speaker, enable gate */
00074     outb((inb(0x61) & ~0x02) | 0x01, 0x61);
00075     
00076     /* counter 0, mode 2, binary */
00077     i8254_set_mode(chip, 0, 2, 0);
00078     i8254_write_count(chip, 0, i8254_RELOAD_COUNT);
00079     
00080     CHIP_UNLOCK;
00081         
00082     return 0;
00083 }
00084 
00085 int i8254_chip_release(struct chip_s *chip)
00086 {
00087     return 0;
00088 }
00089 
00090 struct chip_ops_s       i8254_chip_ops = {
00091     .init               = i8254_chip_init,
00092     .release            = i8254_chip_release
00093 };
00094 
00095 struct chip_s           i8254_chip = {
00096     .chip_name          = "i8254",
00097     .chip_class         = CHIP_CLASS_PIT,
00098     .chip_vendor        = 0x8086,
00099     .chip_priority      = 90,
00100     .chip_ops           = &i8254_chip_ops,
00101     .chip_pm_ops        = NULL,
00102     .internal_ops       = &i8254_pit_ops,
00103 };
00104 
00105 int __init i8254_init(void)
00106 {
00107     adi_register_chip(&i8254_chip);
00108 
00109     return 0;    
00110 }
Dokumentacje wygenerowano programem Doxygen 1.4.2 dla projektu Agnix