Main Page | Directories | File List | Globals

floppy.c File Reference

#include <agnix/agnix.h>
#include <agnix/irq.h>
#include <agnix/adi/adi.h>
#include <agnix/memory.h>
#include <agnix/ioport.h>
#include <agnix/list.h>
#include <agnix/spinlock.h>
#include <agnix/console.h>

Include dependency graph for floppy.c:

Go to the source code of this file.

Defines

#define MOD_NAME   "FLOPPY: "

Functions

int floppy_reset (void)
int floppy_set_defaults (void)
int floppy_request_command (u8 command)
int floppy_result_command (u8 *result_buf, int max_len)
int floppy_interrupt_check (void)
void floppy_interrupt (u32 irq)
void floppy_motor_on (void)
void floppy_motor_off (void)
int floppy_setup_DMA (struct adi_blkreq_s *blkreq)
int floppy_request_read (struct adi_blkreq_s *blkreq)
int floppy_request_set_data (struct adi_blkreq_s *blkreq)
int floppy_request (struct adi_blkreq_s *blkreq)
int floppy_get_version (void)
int floppy_set_irq (void)
int floppy_set_dma (void)
int floppy_free_irq (void)
int floppy_free_dma (void)
int floppy_init (void)
int adi_blkdrv_floppy_init (void)

Variables

u8 floppy_DOR = DOR_DMA_GATE_NEG | DOR_RESET_NEG
int floppy_was_request = 0
chip_s dma_chip
irq_routine_s floppy_irq
adi_blkdev_ops_s floppy_ops
adi_blkdev_s floppy_dev


Define Documentation

#define MOD_NAME   "FLOPPY: "
 

Definition at line 23 of file floppy.c.


Function Documentation

int adi_blkdrv_floppy_init void   ) 
 

Definition at line 289 of file floppy.c.

References floppy_init().

Referenced by adi_blkdrv_init().

00290 {
00291     return floppy_init();
00292 }

Here is the call graph for this function:

int floppy_free_dma void   ) 
 

Definition at line 249 of file floppy.c.

References dma_chip, dma_put_channel(), MOD_NAME, and printk().

00250 {
00251     if (dma_ops(&dma_chip)->dma_put_channel(&dma_chip, FLOPPY_DMA) < 0) {
00252         printk(MOD_NAME "can not free dma %d channel\n", FLOPPY_DMA);
00253         return -1;
00254     }
00255 
00256     return 0;
00257 }

Here is the call graph for this function:

int floppy_free_irq void   ) 
 

Definition at line 244 of file floppy.c.

References floppy_irq, and free_irq().

Referenced by floppy_init().

00245 {
00246     return free_irq(FLOPPY_IRQ, &floppy_irq);
00247 }

Here is the call graph for this function:

int floppy_get_version void   ) 
 

Definition at line 165 of file floppy.c.

References floppy_request_command(), floppy_result_command(), MOD_NAME, and printk().

Referenced by floppy_init().

00166 {
00167     int result_len;
00168     u8 result_buf[16];
00169 
00170     floppy_request_command(FLOPPY_CMD_DUMPREGS);
00171     if ((result_len = floppy_result_command(result_buf, 16)) <= 0) {
00172         printk(MOD_NAME "bad FDC version\n");
00173         return -1;
00174     }
00175     
00176     if (result_len == 1 && result_buf[0] == 0x80) {
00177         printk(MOD_NAME "FDC 8272A detected\n");
00178         return FLOPPY_VER_8272A;
00179     }
00180     else
00181         printk(MOD_NAME "FDC version = %02x\n", result_buf[0]);
00182     
00183     floppy_request_command(FLOPPY_CMD_PARTID);
00184     if ((result_len = floppy_result_command(result_buf, 16)) != 1) {
00185         printk(MOD_NAME "PARTID cmd error\n");
00186         return FLOPPY_VER_UNKNOWN;
00187     }
00188     
00189     switch(result_buf[0]) {
00190         case 0x00:
00191             printk(MOD_NAME "FDC 82078 detected\n");
00192             return FLOPPY_VER_82078;
00193         
00194         case 0x20:
00195             printk(MOD_NAME "FDC 44-pin 82078 detected\n");
00196             return FLOPPY_VER_82078;
00197 
00198         case 0x40:
00199             printk(MOD_NAME "FDC 44-pin S82078B detected\n");
00200             return FLOPPY_VER_S82078B;
00201 
00202         case 0x60:
00203             printk(MOD_NAME "FDC National Semiconductor PC87306 detected\n");
00204             return FLOPPY_VER_87306;
00205             
00206         case 0x80:
00207             printk(MOD_NAME "FDC 82077 detected\n");
00208             return FLOPPY_VER_82077;
00209         
00210         default:
00211             printk(MOD_NAME "FDC with unknown PARTID detected\n");
00212             return FLOPPY_VER_UNKNOWN;
00213     }
00214     
00215     return -1;
00216 }

Here is the call graph for this function:

int floppy_init void   ) 
 

Definition at line 270 of file floppy.c.

References adi_register_blkdev(), floppy_dev, floppy_free_irq(), floppy_get_version(), floppy_set_defaults(), floppy_set_dma(), and floppy_set_irq().

Referenced by adi_blkdrv_floppy_init().

00271 {
00272     
00273     if (floppy_set_irq() < 0)
00274         return -1; 
00275 
00276     if (floppy_set_dma() < 0) {
00277         floppy_free_irq();
00278         return -1; 
00279     }
00280 
00281     adi_register_blkdev(&floppy_dev);
00282         
00283     floppy_set_defaults();
00284     floppy_get_version();
00285 
00286     return 0;
00287 }

Here is the call graph for this function:

void floppy_interrupt u32  irq  ) 
 

Definition at line 92 of file floppy.c.

References printk().

00093 {
00094     printk("floppy irq\n");    
00095 }

Here is the call graph for this function:

int floppy_interrupt_check void   ) 
 

Definition at line 87 of file floppy.c.

References floppy_was_request.

00088 {
00089     return floppy_was_request;
00090 }

void floppy_motor_off void   ) 
 

Definition at line 104 of file floppy.c.

References floppy_DOR.

Referenced by floppy_request_read().

00105 {
00106     floppy_DOR &= ~DOR_MOT_EN0;
00107     outb(floppy_DOR, FLOPPY_DOR);
00108 }

void floppy_motor_on void   ) 
 

Definition at line 98 of file floppy.c.

References floppy_DOR.

Referenced by floppy_request_read().

00099 {
00100     floppy_DOR |= DOR_MOT_EN0;
00101     outb(floppy_DOR, FLOPPY_DOR);
00102 }

int floppy_request struct adi_blkreq_s *  blkreq  ) 
 

Definition at line 154 of file floppy.c.

References floppy_request_read(), and floppy_request_set_data().

00155 {
00156     /* TODO */
00157 
00158     blkreq->req_len_bytes = 10;
00159     floppy_request_set_data(blkreq);
00160     floppy_request_read(blkreq);    
00161 
00162     return 0;
00163 }

Here is the call graph for this function:

int floppy_request_command u8  command  ) 
 

Definition at line 42 of file floppy.c.

References floppy_was_request, and printk().

Referenced by floppy_get_version().

00043 {
00044     int i;
00045     u8 msr;
00046 
00047     for (i = 0; i < FLOPPY_MAX_POLL_REQ_REPLIES; i++) {
00048         msr = inb(FLOPPY_MSR);
00049         if ((msr & MSR_RQM) && (!(msr & MSR_DIO))) {
00050             printk("send command ok\n");
00051             outb(command, FLOPPY_FIFO);
00052             return 0;
00053         }
00054     }
00055     
00056     floppy_was_request = 1;
00057     
00058     return -1;
00059 }

Here is the call graph for this function:

int floppy_request_read struct adi_blkreq_s *  blkreq  ) 
 

Definition at line 124 of file floppy.c.

References floppy_motor_off(), floppy_motor_on(), and floppy_setup_DMA().

Referenced by floppy_request().

00125 {
00126     floppy_setup_DMA(blkreq);
00127 
00128     int i, k;
00129     for (k = 0; k < 4; k++) {
00130     floppy_motor_on();
00131     for (i = 0; i < 200000; i++);    
00132     floppy_motor_off();
00133     for (i = 0; i < 200000; i++);    
00134     }
00135     
00136     return 0;
00137 }

Here is the call graph for this function:

int floppy_request_set_data struct adi_blkreq_s *  blkreq  ) 
 

Definition at line 139 of file floppy.c.

References get_free_dma_pages().

Referenced by floppy_request().

00140 {
00141     u32 req_pages  = 1;
00142     u8  page_order = 0;
00143     
00144     while((req_pages << PAGE_SHIFT) < blkreq->req_len_bytes) {
00145         req_pages <<= 1;
00146         page_order++;
00147     }
00148 
00149     blkreq->req_buf = (u8 *)get_free_dma_pages(page_order);
00150     
00151     return 0;
00152 }

Here is the call graph for this function:

int floppy_reset void   ) 
 

Definition at line 30 of file floppy.c.

00031 {
00032     return 0;
00033 }

int floppy_result_command u8 *  result_buf,
int  max_len
 

Definition at line 61 of file floppy.c.

References floppy_was_request, MOD_NAME, and printk().

Referenced by floppy_get_version().

00062 {
00063     int i;
00064     int k = 0;
00065     u8 msr;
00066 
00067     for (k = 0; k < max_len; k++) {
00068         for (i = 0; i < FLOPPY_MAX_POLL_RES_REPLIES; i++) {
00069             msr = inb(FLOPPY_MSR);
00070             if ((msr & (MSR_RQM | MSR_DIO | MSR_CMD_BUSY)) == (MSR_RQM | MSR_DIO | MSR_CMD_BUSY)) {
00071                 result_buf[k] = inb(FLOPPY_FIFO);
00072                 break;
00073             }
00074         }
00075         
00076         if (i == FLOPPY_MAX_POLL_RES_REPLIES) {
00077             printk(MOD_NAME "%d %x\n", k, msr);
00078             break;
00079         }
00080     }
00081     
00082     floppy_was_request = 0;
00083     
00084     return k;    
00085 }

Here is the call graph for this function:

int floppy_set_defaults void   ) 
 

Definition at line 35 of file floppy.c.

References floppy_DOR.

Referenced by floppy_init().

00036 {
00037     outb(floppy_DOR, FLOPPY_DOR);
00038 
00039     return 0;
00040 }

int floppy_set_dma void   ) 
 

Definition at line 234 of file floppy.c.

References dma_chip, dma_request_channel(), MOD_NAME, and printk().

Referenced by floppy_init().

00235 {
00236     if (dma_ops(&dma_chip)->dma_request_channel(&dma_chip, FLOPPY_DMA) < 0) {
00237         printk(MOD_NAME "can not request dma %d channel\n", FLOPPY_DMA);
00238         return -1;
00239     }
00240 
00241     return 0;
00242 }

Here is the call graph for this function:

int floppy_set_irq void   ) 
 

Definition at line 224 of file floppy.c.

References floppy_irq, install_irq(), MOD_NAME, and printk().

Referenced by floppy_init().

00225 {
00226     if (install_irq(FLOPPY_IRQ, &floppy_irq) < 0) {     
00227         printk(MOD_NAME "can not install irq %d routine\n", FLOPPY_IRQ);
00228         return -1;
00229     }
00230     
00231     return 0;
00232 }

Here is the call graph for this function:

int floppy_setup_DMA struct adi_blkreq_s *  blkreq  ) 
 

Definition at line 110 of file floppy.c.

References dma_chip.

Referenced by floppy_request_read().

00111 {
00112     dma_ops(&dma_chip)->dma_lock     (&dma_chip);
00113     dma_ops(&dma_chip)->dma_disable  (&dma_chip, FLOPPY_DMA);
00114     dma_ops(&dma_chip)->dma_clear_ff (&dma_chip, FLOPPY_DMA);
00115     dma_ops(&dma_chip)->dma_set_mode (&dma_chip, FLOPPY_DMA, DMA_MODE_READ);    
00116     dma_ops(&dma_chip)->dma_set_addr (&dma_chip, FLOPPY_DMA, (u32)virt_to_phys(blkreq->req_buf));    
00117     dma_ops(&dma_chip)->dma_set_count(&dma_chip, FLOPPY_DMA, (u16)blkreq->req_len_bytes);    
00118     dma_ops(&dma_chip)->dma_enable   (&dma_chip, FLOPPY_DMA);
00119     dma_ops(&dma_chip)->dma_unlock   (&dma_chip);
00120 
00121     return 0;
00122 }


Variable Documentation

struct chip_s dma_chip
 

Definition at line 230 of file dma.c.

Referenced by dma_init(), floppy_free_dma(), floppy_set_dma(), and floppy_setup_DMA().

struct adi_blkdev_s floppy_dev
 

Initial value:

 {
    .dev_name           = "floppy",
    .dev_nr             = BLKDEV_FLOPPY_NR,
    .dev_flags          = BLKDEV_FLAG_DMA_REQ,
    .dev_ops            = &floppy_ops
}

Definition at line 263 of file floppy.c.

Referenced by floppy_init().

u8 floppy_DOR = DOR_DMA_GATE_NEG | DOR_RESET_NEG
 

Definition at line 25 of file floppy.c.

Referenced by floppy_motor_off(), floppy_motor_on(), and floppy_set_defaults().

struct irq_routine_s floppy_irq
 

Initial value:

 {
    .proc       = floppy_interrupt,
    .check      = floppy_interrupt_check,
    .flags      = IRQ_FLAG_RANDOM
}

Definition at line 218 of file floppy.c.

Referenced by floppy_free_irq(), and floppy_set_irq().

struct adi_blkdev_ops_s floppy_ops
 

Initial value:

 {
    .block_req          = floppy_request
}

Definition at line 259 of file floppy.c.

int floppy_was_request = 0
 

Definition at line 26 of file floppy.c.

Referenced by floppy_interrupt_check(), floppy_request_command(), and floppy_result_command().

Dokumentacje wygenerowano programem Doxygen 1.4.2 dla projektu Agnix