437 #endif
438 db->mii.dev = dev;
439 db->mii.mdio_read = mdio_read;
440 db->mii.mdio_write = mdio_write;
441 db->mii.phy_id = 1;
442 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20)
443 db->mii.phy_id_mask = 0x1F;
444 db->mii.reg_num_mask = 0x1F;
445 #endif
446 //db->msg_enable =(debug == 0 ? DMFE_DEF_MSG_ENABLE : ((1 << debug) - 1));
447
448 /* Read SROM content */
449 for (i=0; i<64; i++)
450 ((u16 *)db->srom)[i] = read_srom_word(db, i);
451
452 /* Get the PID and VID from EEPROM to check */
453 id_val = (((u16 *)db->srom)[4])|(((u16 *)db->srom)[5]<<16);
454 printk('id_val=%xn', id_val);
455 if (id_val == DM9KS_ID || id_val == DM9010_ID)
456 HasEEPROM =1;
457
458 /* Set Node Address */
459 for (i=0; i<6; i++)
460 {
461 if (HasEEPROM) /* use EEPROM */
462 dev->dev_addr[i] = db->srom[i];
463 else /* No EEPROM */
464 dev->dev_addr[i] = MAC_addr[i];
465 }
466 }//end of if()
467 iobase += 0x10;
468 }while(!dm9000_found && iobase <= DM9KS_MAX_IO);
469
470 return dm9000_found ? 0:-ENODEV;
471 }
472
473
474 /*
475 Open the interface.
476 The interface is opened whenever 'ifconfig' actives it.
477 */
478 static int dmfe_open(struct net_device *dev)
479 {
480 board_info_t *db = (board_info_t *)dev->priv;
481 u8 reg_nsr;
482 int i;
483 DMFE_DBUG(0, 'dmfe_open', 0);
484 //对于2440来说,可以设置它为上升沿触发
485 if (request_irq(dev->irq,&dmfe_interrupt,IRQF_TRIGGER_RISING,dev->name,dev)) //申请注册中断
486 return -EAGAIN;
487
488 /* Initilize DM910X board */
489 dmfe_init_dm9000(dev);
490 #ifdef DM8606
491 // control DM8606
492 printk('[8606]reg0=0x%04xn',dm8606_read(db,0));
493 printk('[8606]reg1=0x%04xn',dm8606_read(db,0x1));
494 #endif
495 /* Init driver variable */
496 db->reset_counter = 0;
497 db->reset_tx_timeout = 0;
498 db->cont_rx_pkt_cnt = 0;
499
500 /* check link state and media speed */
501 db->Speed =10;
502 i=0;
503 do {
504 reg_nsr = ior(db,DM9KS_NSR);
505 if(reg_nsr & 0x40) /* link OK!! */
506 {
507 /* wait for detected Speed */
508 mdelay(200);
509 reg_nsr = ior(db,DM9KS_NSR);
510 if(reg_nsr & 0x80)
511 db->Speed =10;
512 else
513 db->Speed =100;
514 break;
515 }
516 i++;
517 mdelay(1);
518 }while(i<3000); /* wait 3 second */
519 //printk('i=%d Speed=%dn',i,db->Speed);
520 /* set and active a timer process */
521 init_timer(&db->timer);
522 db->timer.expires = DMFE_TIMER_WUT;
523 db->timer.data = (unsigned long)dev;
524 db->timer.function = &dmfe_timer;
525 add_timer(&db->timer); //Move to DM9000 initiallization was finished.
526
527 netif_start_queue(dev);
528
529 return 0;
530 }
531
532 /* Set PHY operationg mode
533 */
534 static void set_PHY_mode(board_info_t *db)
535 {
536 #ifndef DM8606
537 u16 phy_reg0 = 0x1000;/* Auto-negotiation*/
538 u16 phy_reg4 = 0x01e1;
539
540 if ( !(db->op_mode & DM9KS_AUTO) ) // op_mode didn't auto sense */
541 {
542 switch(db->op_mode) {
543 case DM9KS_10MHD: phy_reg4 = 0x21;
544 phy_reg0 = 0x1000;
545 break;
546 case DM9KS_10MFD: phy_reg4 = 0x41;
547 phy_reg0 = 0x1100;
548 break;
549 case DM9KS_100MHD: phy_reg4 = 0x81;
550 phy_reg0 = 0x3000;
551 break;
552 case DM9KS_100MFD: phy_reg4 = 0x101;
553 phy_reg0 = 0x3100;
554 break;
555 default:
556 break;
557 } // end of switch
558 } // end of if
559 #ifdef FLOW_CONTROL
560 phy_write(db, 4, phy_reg4|(1<<10));
561 #else
562 phy_write(db, 4, phy_reg4);
563 #endif //end of FLOW_CONTROL
564 phy_write(db, 0, phy_reg0|0x200);
565 #else
566 /* Fiber mode */
567 phy_write(db, 16, 0x4014);
568 phy_write(db, 0, 0x2100);
569 #endif //end of DM8606
570
571 if (db->chip_revision == 0x1A)
572 {
573 //set 10M TX idle =65mA (TX 100% utility is 160mA)
574 phy_write(db,20, phy_read(db,20)|(1<<11)|(1<<10));
575
576 //:fix harmonic
577 //For short code:
578 //PHY_REG 27 (1Bh) <- 0000h
579 phy_write(db, 27, 0x0000);
580 //PHY_REG 27 (1Bh) <- AA00h
581 phy_write(db, 27, 0xaa00);
582
583 //PHY_REG 27 (1Bh) <- 0017h
584 phy_write(db, 27, 0x0017);
585 //PHY_REG 27 (1Bh) <- AA17h
586 phy_write(db, 27, 0xaa17);
587
588 //PHY_REG 27 (1Bh) <- 002Fh
589 phy_write(db, 27, 0x002f);
590 //PHY_REG 27 (1Bh) <- AA2Fh
591 phy_write(db, 27, 0xaa2f);
上一篇:s3c2440的USB热插拔驱动问题
下一篇:S3C实现DMA驱动程序编写
推荐阅读最新更新时间:2024-11-13 19:29
设计资源 培训 开发板 精华推荐
- IP5328
- 基于TMS320F2812的图像识别智能跟踪小车源码
- LT3091MPR 简单电缆压降补偿的典型应用
- LT3973HMS 5V 降压转换器的典型应用
- L7806A 分体式电源稳压器的典型应用 (± 15 V - 1 A)
- 借助这款用于 LTC3440 的高效单电感器同步降压-升压稳压器,可以更轻松地将锂离子电池电压转换为 3.3V
- 具有短路保护功能的 NCV78M09BDTRKG 9V 电流提升的典型应用
- LTC1479CG 1A 双路镍氢电池电源管理系统的典型应用电路
- EVAL-AD7686CB,用于评估 AD7686CRM 16 位、500 K 高分辨率 ADC 的评估板
- EVAL-ADM1070MEB,ADM1070 热插拔控制器评估套件