Mercurial > pt1.oyama
comparison driver/pt1_pci.c @ 36:65c8ac567074
cleaning up:
- eliminate warnings
- remove dangling white spaces
- changed new line code in Makefile from CR+LF to LF
author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
---|---|
date | Fri, 13 Mar 2009 14:32:44 +0900 |
parents | 289794dc265f |
children | c359e7adf700 |
comparison
equal
deleted
inserted
replaced
35:b17f95181af4 | 36:65c8ac567074 |
---|---|
15 #include <asm/io.h> | 15 #include <asm/io.h> |
16 #include <asm/irq.h> | 16 #include <asm/irq.h> |
17 #include <asm/uaccess.h> | 17 #include <asm/uaccess.h> |
18 #include <linux/version.h> | 18 #include <linux/version.h> |
19 #include <linux/mutex.h> | 19 #include <linux/mutex.h> |
20 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23) | 20 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23) |
21 #include <linux/freezer.h> | 21 #include <linux/freezer.h> |
22 #else | 22 #else |
23 #define set_freezable() | 23 #define set_freezable() |
24 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,11) | 24 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,11) |
25 typedef struct pm_message { | 25 typedef struct pm_message { |
26 int event; | 26 int event; |
27 } pm_message_t; | 27 } pm_message_t; |
28 #endif | 28 #endif |
29 #endif | 29 #endif |
67 #define DEV_NAME "pt1video" | 67 #define DEV_NAME "pt1video" |
68 | 68 |
69 #define MAX_READ_BLOCK 4 // 1度に読み出す最大DMAバッファ数 | 69 #define MAX_READ_BLOCK 4 // 1度に読み出す最大DMAバッファ数 |
70 #define MAX_PCI_DEVICE 128 // 最大64枚 | 70 #define MAX_PCI_DEVICE 128 // 最大64枚 |
71 #define DMA_SIZE 4096 // DMAバッファサイズ | 71 #define DMA_SIZE 4096 // DMAバッファサイズ |
72 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22) | 72 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22) |
73 #define DMA_RING_SIZE 128 // RINGサイズ | 73 #define DMA_RING_SIZE 128 // RINGサイズ |
74 #define DMA_RING_MAX 511 // 1RINGにいくつ詰めるか(1023はNGで511まで) | 74 #define DMA_RING_MAX 511 // 1RINGにいくつ詰めるか(1023はNGで511まで) |
75 #define CHANEL_DMA_SIZE (2*1024*1024) // 地デジ用(16Mbps) | 75 #define CHANEL_DMA_SIZE (2*1024*1024) // 地デジ用(16Mbps) |
76 #define BS_CHANEL_DMA_SIZE (4*1024*1024) // BS用(32Mbps) | 76 #define BS_CHANEL_DMA_SIZE (4*1024*1024) // BS用(32Mbps) |
77 #else | 77 #else |
180 int ring_pos = 0; | 180 int ring_pos = 0; |
181 int data_pos = 0 ; | 181 int data_pos = 0 ; |
182 int lp ; | 182 int lp ; |
183 int chno ; | 183 int chno ; |
184 int lp2 ; | 184 int lp2 ; |
185 __u32 addr ; | |
186 __u32 *dataptr ; | 185 __u32 *dataptr ; |
187 __u32 *curdataptr ; | 186 __u32 *curdataptr ; |
188 __u32 val ; | 187 __u32 val ; |
189 union mpacket{ | 188 union mpacket{ |
190 __u32 val ; | 189 __u32 val ; |
326 } | 325 } |
327 return -EIO; | 326 return -EIO; |
328 } | 327 } |
329 static int pt1_release(struct inode *inode, struct file *file) | 328 static int pt1_release(struct inode *inode, struct file *file) |
330 { | 329 { |
331 int minor = iminor(inode); | |
332 PT1_CHANNEL *channel = file->private_data; | 330 PT1_CHANNEL *channel = file->private_data; |
333 | 331 |
334 mutex_lock(&channel->ptr->lock); | 332 mutex_lock(&channel->ptr->lock); |
335 SetStream(channel->ptr->regs, channel->channel, FALSE); | 333 SetStream(channel->ptr->regs, channel->channel, FALSE); |
336 channel->valid = FALSE ; | 334 channel->valid = FALSE ; |
351 | 349 |
352 static ssize_t pt1_read(struct file *file, char __user *buf, size_t cnt, loff_t * ppos) | 350 static ssize_t pt1_read(struct file *file, char __user *buf, size_t cnt, loff_t * ppos) |
353 { | 351 { |
354 PT1_CHANNEL *channel = file->private_data; | 352 PT1_CHANNEL *channel = file->private_data; |
355 __u32 size ; | 353 __u32 size ; |
356 | 354 unsigned long dummy; |
357 | 355 |
358 // 4K単位で起こされるのを待つ(CPU負荷対策) | 356 // 4K単位で起こされるのを待つ(CPU負荷対策) |
359 if(channel->size < DMA_SIZE){ | 357 if(channel->size < DMA_SIZE){ |
360 wait_event_timeout(channel->wait_q, (channel->size >= DMA_SIZE), | 358 wait_event_timeout(channel->wait_q, (channel->size >= DMA_SIZE), |
361 msecs_to_jiffies(500)); | 359 msecs_to_jiffies(500)); |
365 size = 0 ; | 363 size = 0 ; |
366 }else{ | 364 }else{ |
367 if(cnt < channel->size){ | 365 if(cnt < channel->size){ |
368 // バッファが足りない場合は残りを移動する | 366 // バッファが足りない場合は残りを移動する |
369 size = cnt ; | 367 size = cnt ; |
370 copy_to_user(buf, channel->buf, cnt); | 368 dummy = copy_to_user(buf, channel->buf, cnt); |
371 memmove(channel->buf, &channel->buf[cnt], (channel->size - cnt)); | 369 memmove(channel->buf, &channel->buf[cnt], (channel->size - cnt)); |
372 channel->size -= cnt ; | 370 channel->size -= cnt ; |
373 }else{ | 371 }else{ |
374 size = channel->size ; | 372 size = channel->size ; |
375 copy_to_user(buf, channel->buf, size); | 373 dummy = copy_to_user(buf, channel->buf, size); |
376 channel->size = 0 ; | 374 channel->size = 0 ; |
377 } | 375 } |
378 } | 376 } |
379 // 読み終わったかつ使用しているのがが4K以下 | 377 // 読み終わったかつ使用しているのがが4K以下 |
380 if(channel->req_dma == TRUE){ | 378 if(channel->req_dma == TRUE){ |
431 } | 429 } |
432 } | 430 } |
433 } | 431 } |
434 return 0 ; | 432 return 0 ; |
435 } | 433 } |
436 static int pt1_ioctl(struct inode *inode, struct file *file, unsigned int cmd, void *arg) | 434 static int pt1_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg0) |
437 { | 435 { |
438 PT1_CHANNEL *channel = file->private_data; | 436 PT1_CHANNEL *channel = file->private_data; |
439 int signal ; | 437 int signal ; |
438 unsigned long dummy; | |
439 void *arg = (void *)arg0; | |
440 | 440 |
441 switch(cmd){ | 441 switch(cmd){ |
442 case SET_CHANNEL: | 442 case SET_CHANNEL: |
443 { | 443 { |
444 FREQUENCY freq ; | 444 FREQUENCY freq ; |
445 copy_from_user(&freq, arg, sizeof(FREQUENCY)); | 445 dummy = copy_from_user(&freq, arg, sizeof(FREQUENCY)); |
446 return SetFreq(channel, &freq); | 446 return SetFreq(channel, &freq); |
447 } | 447 } |
448 case START_REC: | 448 case START_REC: |
449 SetStream(channel->ptr->regs, channel->channel, TRUE); | 449 SetStream(channel->ptr->regs, channel->channel, TRUE); |
450 return 0 ; | 450 return 0 ; |
460 channel->address); | 460 channel->address); |
461 } | 461 } |
462 break ; | 462 break ; |
463 case CHANNEL_TYPE_ISDB_T: | 463 case CHANNEL_TYPE_ISDB_T: |
464 // calc C/N | 464 // calc C/N |
465 signal = isdb_t_read_signal_strength(channel->ptr->regs, | 465 signal = isdb_t_read_signal_strength(channel->ptr->regs, |
466 &channel->ptr->lock, channel->address); | 466 &channel->ptr->lock, channel->address); |
467 break ; | 467 break ; |
468 } | 468 } |
469 copy_to_user(arg, &signal, sizeof(int)); | 469 dummy = copy_to_user(arg, &signal, sizeof(int)); |
470 return 0 ; | 470 return 0 ; |
471 case LNB_ENABLE: | 471 case LNB_ENABLE: |
472 if(lnb){ | 472 if(lnb){ |
473 settuner_reset(channel->ptr->regs, lnb, TUNER_POWER_ON_RESET_DISABLE); | 473 settuner_reset(channel->ptr->regs, lnb, TUNER_POWER_ON_RESET_DISABLE); |
474 } | 474 } |
576 int lp ; | 576 int lp ; |
577 int minor ; | 577 int minor ; |
578 u16 cmd ; | 578 u16 cmd ; |
579 PT1_DEVICE *dev_conf ; | 579 PT1_DEVICE *dev_conf ; |
580 PT1_CHANNEL *channel ; | 580 PT1_CHANNEL *channel ; |
581 struct resource *dummy; | |
581 | 582 |
582 rc = pci_enable_device(pdev); | 583 rc = pci_enable_device(pdev); |
583 if (rc) | 584 if (rc) |
584 return rc; | 585 return rc; |
585 rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK); | 586 rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK); |
606 return -ENOMEM ; | 607 return -ENOMEM ; |
607 } | 608 } |
608 // PCIアドレスをマップする | 609 // PCIアドレスをマップする |
609 dev_conf->mmio_start = pci_resource_start(pdev, 0); | 610 dev_conf->mmio_start = pci_resource_start(pdev, 0); |
610 dev_conf->mmio_len = pci_resource_len(pdev, 0); | 611 dev_conf->mmio_len = pci_resource_len(pdev, 0); |
611 rc = request_mem_region(dev_conf->mmio_start, dev_conf->mmio_len, DEV_NAME); | 612 dummy = request_mem_region(dev_conf->mmio_start, dev_conf->mmio_len, DEV_NAME); |
612 if (!rc) { | 613 if (!dummy) { |
613 printk(KERN_ERR "PT1: cannot request iomem (0x%llx).\n", (unsigned long long) dev_conf->mmio_start); | 614 printk(KERN_ERR "PT1: cannot request iomem (0x%llx).\n", (unsigned long long) dev_conf->mmio_start); |
614 goto out_err_regbase; | 615 goto out_err_regbase; |
615 } | 616 } |
616 | 617 |
617 dev_conf->regs = ioremap(dev_conf->mmio_start, dev_conf->mmio_len); | 618 dev_conf->regs = ioremap(dev_conf->mmio_start, dev_conf->mmio_len); |
640 goto out_err_fpga; | 641 goto out_err_fpga; |
641 } | 642 } |
642 } | 643 } |
643 // 初期化完了 | 644 // 初期化完了 |
644 for(lp = 0 ; lp < MAX_CHANNEL ; lp++){ | 645 for(lp = 0 ; lp < MAX_CHANNEL ; lp++){ |
645 set_sleepmode(dev_conf->regs, &dev_conf->lock, | 646 set_sleepmode(dev_conf->regs, &dev_conf->lock, |
646 i2c_address[lp], channeltype[lp], TYPE_SLEEP); | 647 i2c_address[lp], channeltype[lp], TYPE_SLEEP); |
647 | 648 |
648 schedule_timeout_interruptible(msecs_to_jiffies(50)); | 649 schedule_timeout_interruptible(msecs_to_jiffies(50)); |
649 } | 650 } |
650 rc = alloc_chrdev_region(&dev_conf->dev, 0, MAX_CHANNEL, DEV_NAME); | 651 rc = alloc_chrdev_region(&dev_conf->dev, 0, MAX_CHANNEL, DEV_NAME); |
651 if(rc < 0){ | 652 if(rc < 0){ |
652 goto out_err_fpga; | 653 goto out_err_fpga; |
837 }; | 838 }; |
838 | 839 |
839 | 840 |
840 static int __init pt1_pci_init(void) | 841 static int __init pt1_pci_init(void) |
841 { | 842 { |
843 printk(version); | |
842 pt1video_class = class_create(THIS_MODULE, DRIVERNAME); | 844 pt1video_class = class_create(THIS_MODULE, DRIVERNAME); |
843 if (IS_ERR(pt1video_class)) | 845 if (IS_ERR(pt1video_class)) |
844 return PTR_ERR(pt1video_class); | 846 return PTR_ERR(pt1video_class); |
845 return pci_register_driver(&pt1_driver); | 847 return pci_register_driver(&pt1_driver); |
846 } | 848 } |