Mercurial > pt1
comparison driver/pt1_pci.c @ 95:a201531113ca
implement decent LNB management
author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
---|---|
date | Tue, 09 Feb 2010 06:27:01 +0900 |
parents | ee357d8f987f |
children | 6e661e828b43 |
comparison
equal
deleted
inserted
replaced
94:c940283dd890 | 95:a201531113ca |
---|---|
49 MODULE_DESCRIPTION(DRIVER_DESC); | 49 MODULE_DESCRIPTION(DRIVER_DESC); |
50 MODULE_LICENSE("GPL"); | 50 MODULE_LICENSE("GPL"); |
51 | 51 |
52 static int debug = 7; /* 1 normal messages, 0 quiet .. 7 verbose. */ | 52 static int debug = 7; /* 1 normal messages, 0 quiet .. 7 verbose. */ |
53 static int lnb = 0; /* LNB OFF:0 +11V:1 +15V:2 */ | 53 static int lnb = 0; /* LNB OFF:0 +11V:1 +15V:2 */ |
54 static int lnb_ref_count = 0; | |
55 struct mutex lnb_mutex; | |
56 | 54 |
57 module_param(debug, int, 0); | 55 module_param(debug, int, 0); |
58 module_param(lnb, int, 0); | 56 module_param(lnb, int, 0); |
59 MODULE_PARM_DESC(debug, "debug level (1-2)"); | 57 MODULE_PARM_DESC(debug, "debug level (1-2)"); |
60 MODULE_PARM_DESC(debug, "LNB level (0:OFF 1:+11V 2:+15V)"); | 58 MODULE_PARM_DESC(debug, "LNB level (0:OFF 1:+11V 2:+15V)"); |
478 } | 476 } |
479 } | 477 } |
480 } | 478 } |
481 return 0 ; | 479 return 0 ; |
482 } | 480 } |
481 | |
482 static int count_used_bs_tuners(PT1_DEVICE *device) | |
483 { | |
484 int count = 0; | |
485 int i; | |
486 | |
487 for(i=0; i<MAX_CHANNEL; i++) { | |
488 if(device && device->channel[i] && | |
489 device->channel[i]->type == CHANNEL_TYPE_ISDB_S && | |
490 device->channel[i]->valid) | |
491 count++; | |
492 } | |
493 | |
494 printk(KERN_INFO "used bs tuners on %p = %d\n", device, count); | |
495 return count; | |
496 } | |
497 | |
483 static int pt1_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg0) | 498 static int pt1_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg0) |
484 { | 499 { |
485 PT1_CHANNEL *channel = file->private_data; | 500 PT1_CHANNEL *channel = file->private_data; |
486 int signal ; | 501 int signal; |
487 unsigned long dummy; | 502 unsigned long dummy; |
488 void *arg = (void *)arg0; | 503 void *arg = (void *)arg0; |
489 int lnb_eff, lnb_usr; | 504 int lnb_eff, lnb_usr; |
490 char *voltage[] = {"0V", "11V", "15V"}; | 505 char *voltage[] = {"0V", "11V", "15V"}; |
506 int count; | |
491 | 507 |
492 switch(cmd){ | 508 switch(cmd){ |
493 case SET_CHANNEL: | 509 case SET_CHANNEL: |
494 { | 510 { |
495 FREQUENCY freq ; | 511 FREQUENCY freq ; |
515 break ; | 531 break ; |
516 } | 532 } |
517 dummy = copy_to_user(arg, &signal, sizeof(int)); | 533 dummy = copy_to_user(arg, &signal, sizeof(int)); |
518 return 0 ; | 534 return 0 ; |
519 case LNB_ENABLE: | 535 case LNB_ENABLE: |
520 lnb_usr = (int)arg0; | 536 count = count_used_bs_tuners(channel->ptr); |
521 lnb_eff = lnb_usr ? lnb_usr : lnb; | 537 if(count <= 1) { |
522 mutex_lock(&lnb_mutex); | 538 lnb_usr = (int)arg0; |
523 lnb_ref_count += 1; | 539 lnb_eff = lnb_usr ? lnb_usr : lnb; |
524 settuner_reset(channel->ptr->regs, channel->ptr->cardtype, lnb_eff, TUNER_POWER_ON_RESET_DISABLE); | 540 settuner_reset(channel->ptr->regs, channel->ptr->cardtype, lnb_eff, TUNER_POWER_ON_RESET_DISABLE); |
525 mutex_unlock(&lnb_mutex); | 541 printk(KERN_INFO "PT1:LNB on %s\n", voltage[lnb_eff]); |
526 printk(KERN_INFO "PT1:LNB = %s\n", voltage[lnb_eff]); | 542 } |
527 printk(KERN_INFO "PT1:LNB ref_count = %d\n", lnb_ref_count); | |
528 return 0 ; | 543 return 0 ; |
529 case LNB_DISABLE: | 544 case LNB_DISABLE: |
530 mutex_lock(&lnb_mutex); | 545 count = count_used_bs_tuners(channel->ptr); |
531 lnb_ref_count -= 1; | 546 if(count <= 1) { |
532 if(!lnb_ref_count) | |
533 settuner_reset(channel->ptr->regs, channel->ptr->cardtype, LNB_OFF, TUNER_POWER_ON_RESET_DISABLE); | 547 settuner_reset(channel->ptr->regs, channel->ptr->cardtype, LNB_OFF, TUNER_POWER_ON_RESET_DISABLE); |
534 mutex_unlock(&lnb_mutex); | 548 printk(KERN_INFO "PT1:LNB off\n"); |
535 printk(KERN_INFO "PT1:LNB ref_count = %d\n", lnb_ref_count); | 549 } |
536 return 0 ; | 550 return 0 ; |
537 } | 551 } |
538 return -EINVAL; | 552 return -EINVAL; |
539 } | 553 } |
540 | 554 |
711 schedule_timeout_interruptible(msecs_to_jiffies(50)); | 725 schedule_timeout_interruptible(msecs_to_jiffies(50)); |
712 | 726 |
713 settuner_reset(dev_conf->regs, dev_conf->cardtype, LNB_OFF, TUNER_POWER_ON_RESET_DISABLE); | 727 settuner_reset(dev_conf->regs, dev_conf->cardtype, LNB_OFF, TUNER_POWER_ON_RESET_DISABLE); |
714 schedule_timeout_interruptible(msecs_to_jiffies(10)); | 728 schedule_timeout_interruptible(msecs_to_jiffies(10)); |
715 mutex_init(&dev_conf->lock); | 729 mutex_init(&dev_conf->lock); |
716 mutex_init(&lnb_mutex); | |
717 | 730 |
718 // Tuner 初期化処理 | 731 // Tuner 初期化処理 |
719 for(lp = 0 ; lp < MAX_TUNER ; lp++){ | 732 for(lp = 0 ; lp < MAX_TUNER ; lp++){ |
720 rc = tuner_init(dev_conf->regs, dev_conf->cardtype, &dev_conf->lock, lp); | 733 rc = tuner_init(dev_conf->regs, dev_conf->cardtype, &dev_conf->lock, lp); |
721 if(rc < 0){ | 734 if(rc < 0){ |