Mercurial > pt1
annotate driver/pt1_pci.c @ 138:45b4afa656d2
adapted to kernel 3.8.0
author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
---|---|
date | Thu, 25 Apr 2013 15:08:34 +0900 |
parents | 2dc994610477 |
children | 1e7718cc2556 |
rev | line source |
---|---|
108
bc173c443e4d
make sure that wait after set_sleepmode()
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
102
diff
changeset
|
1 /* -*- tab-width: 4; indent-tabs-mode: t -*- */ |
0 | 2 /* pt1-pci.c: A PT1 on PCI bus driver for Linux. */ |
3 #define DRV_NAME "pt1-pci" | |
90
c6311b6efd9c
- version string should be generated upon revision on mercurial repository
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
86
diff
changeset
|
4 #include "version.h" |
0 | 5 |
6 #include <linux/module.h> | |
7 #include <linux/kernel.h> | |
8 #include <linux/errno.h> | |
9 #include <linux/pci.h> | |
10 #include <linux/init.h> | |
11 #include <linux/interrupt.h> | |
131
2dc994610477
kernel 3.4.x no longer has asm/system.h
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
124
diff
changeset
|
12 #include <linux/version.h> |
2dc994610477
kernel 3.4.x no longer has asm/system.h
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
124
diff
changeset
|
13 #include <linux/mutex.h> |
0 | 14 |
131
2dc994610477
kernel 3.4.x no longer has asm/system.h
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
124
diff
changeset
|
15 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0) |
0 | 16 #include <asm/system.h> |
131
2dc994610477
kernel 3.4.x no longer has asm/system.h
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
124
diff
changeset
|
17 #endif |
0 | 18 #include <asm/io.h> |
19 #include <asm/irq.h> | |
20 #include <asm/uaccess.h> | |
131
2dc994610477
kernel 3.4.x no longer has asm/system.h
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
124
diff
changeset
|
21 |
36 | 22 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23) |
0 | 23 #include <linux/freezer.h> |
24 #else | |
25 #define set_freezable() | |
36 | 26 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,11) |
0 | 27 typedef struct pm_message { |
28 int event; | |
29 } pm_message_t; | |
30 #endif | |
31 #endif | |
32 #include <linux/kthread.h> | |
33 #include <linux/dma-mapping.h> | |
34 | |
35 #include <linux/fs.h> | |
36 #include <linux/cdev.h> | |
37 | |
38 #include <linux/ioctl.h> | |
39 | |
40 #include "pt1_com.h" | |
41 #include "pt1_pci.h" | |
42 #include "pt1_tuner.h" | |
43 #include "pt1_i2c.h" | |
44 #include "pt1_tuner_data.h" | |
45 #include "pt1_ioctl.h" | |
46 | |
138
45b4afa656d2
adapted to kernel 3.8.0
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
131
diff
changeset
|
47 #if LINUX_VERSION_CODE > KERNEL_VERSION(3,8,0) |
45b4afa656d2
adapted to kernel 3.8.0
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
131
diff
changeset
|
48 #define __devinit |
45b4afa656d2
adapted to kernel 3.8.0
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
131
diff
changeset
|
49 #define __devinitdata |
45b4afa656d2
adapted to kernel 3.8.0
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
131
diff
changeset
|
50 #define __devexit |
45b4afa656d2
adapted to kernel 3.8.0
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
131
diff
changeset
|
51 #define __devexit_p |
45b4afa656d2
adapted to kernel 3.8.0
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
131
diff
changeset
|
52 #endif |
45b4afa656d2
adapted to kernel 3.8.0
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
131
diff
changeset
|
53 |
0 | 54 /* These identify the driver base version and may not be removed. */ |
55 static char version[] __devinitdata = | |
93 | 56 DRV_NAME ".c: " DRV_VERSION " " DRV_RELDATE " \n"; |
0 | 57 |
90
c6311b6efd9c
- version string should be generated upon revision on mercurial repository
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
86
diff
changeset
|
58 MODULE_AUTHOR("Tomoaki Ishikawa tomy@users.sourceforge.jp and Yoshiki Yazawa yaz@honeyplanet.jp"); |
c6311b6efd9c
- version string should be generated upon revision on mercurial repository
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
86
diff
changeset
|
59 #define DRIVER_DESC "PCI earthsoft PT1/2 driver" |
0 | 60 MODULE_DESCRIPTION(DRIVER_DESC); |
61 MODULE_LICENSE("GPL"); | |
62 | |
51
c915076353ae
backout 23b6f99f65b2 for now. it may cause scheduling while atomic operation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
50
diff
changeset
|
63 static int debug = 7; /* 1 normal messages, 0 quiet .. 7 verbose. */ |
c915076353ae
backout 23b6f99f65b2 for now. it may cause scheduling while atomic operation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
50
diff
changeset
|
64 static int lnb = 0; /* LNB OFF:0 +11V:1 +15V:2 */ |
0 | 65 |
66 module_param(debug, int, 0); | |
67 module_param(lnb, int, 0); | |
68 MODULE_PARM_DESC(debug, "debug level (1-2)"); | |
69 MODULE_PARM_DESC(debug, "LNB level (0:OFF 1:+11V 2:+15V)"); | |
70 | |
64
98a92ce5382e
added fake support code for PT2. the PT2 part is not expected to work. be careful!
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
51
diff
changeset
|
71 #define VENDOR_EARTHSOFT 0x10ee |
98a92ce5382e
added fake support code for PT2. the PT2 part is not expected to work. be careful!
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
51
diff
changeset
|
72 #define PCI_PT1_ID 0x211a |
98a92ce5382e
added fake support code for PT2. the PT2 part is not expected to work. be careful!
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
51
diff
changeset
|
73 #define PCI_PT2_ID 0x222a |
98a92ce5382e
added fake support code for PT2. the PT2 part is not expected to work. be careful!
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
51
diff
changeset
|
74 |
0 | 75 static struct pci_device_id pt1_pci_tbl[] = { |
64
98a92ce5382e
added fake support code for PT2. the PT2 part is not expected to work. be careful!
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
51
diff
changeset
|
76 { VENDOR_EARTHSOFT, PCI_PT1_ID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, |
98a92ce5382e
added fake support code for PT2. the PT2 part is not expected to work. be careful!
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
51
diff
changeset
|
77 { VENDOR_EARTHSOFT, PCI_PT2_ID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, |
0 | 78 { 0, } |
79 }; | |
80 MODULE_DEVICE_TABLE(pci, pt1_pci_tbl); | |
81 #define DEV_NAME "pt1video" | |
82 | |
37
c359e7adf700
propagate upstream change:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
36
diff
changeset
|
83 #define PACKET_SIZE 188 // 1パケット長 |
0 | 84 #define MAX_READ_BLOCK 4 // 1度に読み出す最大DMAバッファ数 |
9
07b2fc07ff48
updated to current driver to support signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
85 #define MAX_PCI_DEVICE 128 // 最大64枚 |
0 | 86 #define DMA_SIZE 4096 // DMAバッファサイズ |
124 | 87 #define DMA_RING_SIZE 128 // number of DMA RINGS |
88 #define DMA_RING_MAX 511 // number of DMA entries in a RING(1023はNGで511まで) | |
89 #define CHANNEL_DMA_SIZE (2*1024*1024) // 地デジ用(16Mbps) | |
90 #define BS_CHANNEL_DMA_SIZE (4*1024*1024) // BS用(32Mbps) | |
120
3914cc1b2375
- adapted to 3.x kernels
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
119
diff
changeset
|
91 #define READ_SIZE (16*DMA_SIZE) |
0 | 92 |
93 typedef struct _DMA_CONTROL{ | |
94 dma_addr_t ring_dma[DMA_RING_MAX] ; // DMA情報 | |
95 __u32 *data[DMA_RING_MAX]; | |
96 }DMA_CONTROL; | |
97 | |
98 typedef struct _PT1_CHANNEL PT1_CHANNEL; | |
99 | |
100 typedef struct _pt1_device{ | |
101 unsigned long mmio_start ; | |
102 __u32 mmio_len ; | |
103 void __iomem *regs; | |
104 struct mutex lock ; | |
105 dma_addr_t ring_dma[DMA_RING_SIZE] ; // DMA情報 | |
106 void *dmaptr[DMA_RING_SIZE] ; | |
107 struct task_struct *kthread; | |
108 dev_t dev ; | |
31
289794dc265f
adapted to use of multiple number of pt1:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
30
diff
changeset
|
109 int card_number; |
0 | 110 __u32 base_minor ; |
111 struct cdev cdev[MAX_CHANNEL]; | |
112 wait_queue_head_t dma_wait_q ;// for poll on reading | |
40
8f30a05cded2
imported patch dmactlalloc
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
37
diff
changeset
|
113 DMA_CONTROL *dmactl[DMA_RING_SIZE]; |
0 | 114 PT1_CHANNEL *channel[MAX_CHANNEL]; |
64
98a92ce5382e
added fake support code for PT2. the PT2 part is not expected to work. be careful!
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
51
diff
changeset
|
115 int cardtype; |
98a92ce5382e
added fake support code for PT2. the PT2 part is not expected to work. be careful!
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
51
diff
changeset
|
116 } PT1_DEVICE; |
0 | 117 |
118 typedef struct _MICRO_PACKET{ | |
119 char data[3]; | |
120 char head ; | |
121 }MICRO_PACKET; | |
122 | |
123 struct _PT1_CHANNEL{ | |
124 __u32 valid ; // 使用中フラグ | |
125 __u32 address ; // I2Cアドレス | |
126 __u32 channel ; // チャネル番号 | |
37
c359e7adf700
propagate upstream change:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
36
diff
changeset
|
127 int type ; // チャネルタイプ |
c359e7adf700
propagate upstream change:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
36
diff
changeset
|
128 __u32 packet_size ; // パケットサイズ |
0 | 129 __u32 drop ; // パケットドロップ数 |
130 struct mutex lock ; // CH別mutex_lock用 | |
131 __u32 size ; // DMAされたサイズ | |
132 __u32 maxsize ; // DMA用バッファサイズ | |
133 __u32 bufsize ; // チャネルに割り振られたサイズ | |
134 __u32 overflow ; // オーバーフローエラー発生 | |
135 __u32 counetererr ; // 転送カウンタ1エラー | |
136 __u32 transerr ; // 転送エラー | |
137 __u32 minor ; // マイナー番号 | |
138 __u8 *buf; // CH別受信メモリ | |
41
51a006a8d843
imported patch ringbuf-vmalloc
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
40
diff
changeset
|
139 __u32 pointer; |
0 | 140 __u8 req_dma ; // 溢れたチャネル |
37
c359e7adf700
propagate upstream change:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
36
diff
changeset
|
141 __u8 packet_buf[PACKET_SIZE] ; // 溢れたチャネル |
0 | 142 PT1_DEVICE *ptr ; // カード別情報 |
143 wait_queue_head_t wait_q ; // for poll on reading | |
144 }; | |
145 | |
146 // I2Cアドレス(video0, 1 = ISDB-S) (video2, 3 = ISDB-T) | |
147 int i2c_address[MAX_CHANNEL] = {T0_ISDB_S, T1_ISDB_S, T0_ISDB_T, T1_ISDB_T}; | |
86 | 148 int real_channel[MAX_CHANNEL] = {0, 2, 1, 3}; |
0 | 149 int channeltype[MAX_CHANNEL] = {CHANNEL_TYPE_ISDB_S, CHANNEL_TYPE_ISDB_S, |
150 CHANNEL_TYPE_ISDB_T, CHANNEL_TYPE_ISDB_T}; | |
151 | |
152 static PT1_DEVICE *device[MAX_PCI_DEVICE]; | |
9
07b2fc07ff48
updated to current driver to support signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
153 static struct class *pt1video_class; |
0 | 154 |
155 #define PT1MAJOR 251 | |
156 #define DRIVERNAME "pt1video" | |
157 | |
158 static void reset_dma(PT1_DEVICE *dev_conf) | |
159 { | |
160 | |
161 int lp ; | |
162 __u32 addr ; | |
163 int ring_pos = 0; | |
164 int data_pos = 0 ; | |
165 __u32 *dataptr ; | |
166 | |
167 // データ初期化 | |
168 for(ring_pos = 0 ; ring_pos < DMA_RING_SIZE ; ring_pos++){ | |
169 for(data_pos = 0 ; data_pos < DMA_RING_MAX ; data_pos++){ | |
40
8f30a05cded2
imported patch dmactlalloc
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
37
diff
changeset
|
170 dataptr = (dev_conf->dmactl[ring_pos])->data[data_pos]; |
9
07b2fc07ff48
updated to current driver to support signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
171 dataptr[(DMA_SIZE / sizeof(__u32)) - 2] = 0; |
0 | 172 } |
173 } | |
174 // 転送カウンタをリセット | |
175 writel(0x00000010, dev_conf->regs); | |
176 // 転送カウンタをインクリメント | |
177 for(lp = 0 ; lp < DMA_RING_SIZE ; lp++){ | |
178 writel(0x00000020, dev_conf->regs); | |
179 } | |
180 | |
181 addr = (int)dev_conf->ring_dma[0] ; | |
182 addr >>= 12 ; | |
183 // DMAバッファ設定 | |
184 writel(addr, dev_conf->regs + DMA_ADDR); | |
185 // DMA開始 | |
186 writel(0x0c000040, dev_conf->regs); | |
187 | |
188 } | |
189 static int pt1_thread(void *data) | |
190 { | |
191 PT1_DEVICE *dev_conf = data ; | |
192 PT1_CHANNEL *channel ; | |
193 int ring_pos = 0; | |
194 int data_pos = 0 ; | |
195 int lp ; | |
196 int chno ; | |
37
c359e7adf700
propagate upstream change:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
36
diff
changeset
|
197 int dma_channel ; |
c359e7adf700
propagate upstream change:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
36
diff
changeset
|
198 int packet_pos ; |
0 | 199 __u32 *dataptr ; |
200 __u32 *curdataptr ; | |
201 __u32 val ; | |
202 union mpacket{ | |
203 __u32 val ; | |
204 MICRO_PACKET packet ; | |
205 }micro; | |
206 | |
207 set_freezable(); | |
208 reset_dma(dev_conf); | |
209 printk(KERN_INFO "pt1_thread run\n"); | |
210 | |
211 for(;;){ | |
212 if(kthread_should_stop()){ | |
213 break ; | |
214 } | |
215 | |
216 for(;;){ | |
40
8f30a05cded2
imported patch dmactlalloc
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
37
diff
changeset
|
217 dataptr = (dev_conf->dmactl[ring_pos])->data[data_pos]; |
0 | 218 // データあり? |
219 if(dataptr[(DMA_SIZE / sizeof(__u32)) - 2] == 0){ | |
220 break ; | |
221 } | |
222 micro.val = *dataptr ; | |
223 curdataptr = dataptr ; | |
224 data_pos += 1 ; | |
225 for(lp = 0 ; lp < (DMA_SIZE / sizeof(__u32)) ; lp++, dataptr++){ | |
226 micro.val = *dataptr ; | |
37
c359e7adf700
propagate upstream change:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
36
diff
changeset
|
227 dma_channel = ((micro.packet.head >> 5) & 0x07); |
c359e7adf700
propagate upstream change:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
36
diff
changeset
|
228 //チャネル情報不正 |
c359e7adf700
propagate upstream change:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
36
diff
changeset
|
229 if(dma_channel > MAX_CHANNEL){ |
c359e7adf700
propagate upstream change:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
36
diff
changeset
|
230 printk(KERN_ERR "DMA Channel Number Error(%d)\n", dma_channel); |
c359e7adf700
propagate upstream change:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
36
diff
changeset
|
231 continue ; |
c359e7adf700
propagate upstream change:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
36
diff
changeset
|
232 } |
86 | 233 chno = real_channel[(((micro.packet.head >> 5) & 0x07) - 1)]; |
37
c359e7adf700
propagate upstream change:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
36
diff
changeset
|
234 packet_pos = ((micro.packet.head >> 2) & 0x07); |
0 | 235 channel = dev_conf->channel[chno] ; |
236 // エラーチェック | |
237 if((micro.packet.head & MICROPACKET_ERROR)){ | |
238 val = readl(dev_conf->regs); | |
239 if((val & BIT_RAM_OVERFLOW)){ | |
240 channel->overflow += 1 ; | |
241 } | |
242 if((val & BIT_INITIATOR_ERROR)){ | |
243 channel->counetererr += 1 ; | |
244 } | |
245 if((val & BIT_INITIATOR_WARNING)){ | |
246 channel->transerr += 1 ; | |
247 } | |
248 // 初期化して先頭から | |
249 reset_dma(dev_conf); | |
250 ring_pos = data_pos = 0 ; | |
251 break ; | |
252 } | |
253 // 未使用チャネルは捨てる | |
254 if(channel->valid == FALSE){ | |
255 continue ; | |
256 } | |
257 mutex_lock(&channel->lock); | |
258 // あふれたら読み出すまで待つ | |
259 while(1){ | |
41
51a006a8d843
imported patch ringbuf-vmalloc
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
40
diff
changeset
|
260 if(channel->size >= (channel->maxsize - PACKET_SIZE - 4)){ |
0 | 261 // 該当チャンネルのDMA読みだし待ちにする |
262 wake_up(&channel->wait_q); | |
263 channel->req_dma = TRUE ; | |
264 mutex_unlock(&channel->lock); | |
265 // タスクに時間を渡す為中断 | |
266 wait_event_timeout(dev_conf->dma_wait_q, (channel->req_dma == FALSE), | |
267 msecs_to_jiffies(500)); | |
268 mutex_lock(&channel->lock); | |
269 channel->drop += 1 ; | |
270 }else{ | |
271 break ; | |
272 } | |
273 } | |
37
c359e7adf700
propagate upstream change:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
36
diff
changeset
|
274 // 先頭で、一時バッファに残っている場合 |
c359e7adf700
propagate upstream change:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
36
diff
changeset
|
275 if((micro.packet.head & 0x02) && (channel->packet_size != 0)){ |
c359e7adf700
propagate upstream change:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
36
diff
changeset
|
276 channel->packet_size = 0 ; |
c359e7adf700
propagate upstream change:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
36
diff
changeset
|
277 } |
0 | 278 // データコピー |
124 | 279 channel->packet_buf[channel->packet_size] = micro.packet.data[2]; |
280 channel->packet_buf[channel->packet_size+1] = micro.packet.data[1]; | |
281 channel->packet_buf[channel->packet_size+2] = micro.packet.data[0]; | |
282 channel->packet_size += 3; | |
37
c359e7adf700
propagate upstream change:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
36
diff
changeset
|
283 |
c359e7adf700
propagate upstream change:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
36
diff
changeset
|
284 // パケットが出来たらコピーする |
c359e7adf700
propagate upstream change:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
36
diff
changeset
|
285 if(channel->packet_size >= PACKET_SIZE){ |
41
51a006a8d843
imported patch ringbuf-vmalloc
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
40
diff
changeset
|
286 if (channel->pointer + channel->size >= channel->maxsize) { |
51a006a8d843
imported patch ringbuf-vmalloc
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
40
diff
changeset
|
287 // リングバッファの境界を越えていてリングバッファの先頭に戻っている場合 |
51a006a8d843
imported patch ringbuf-vmalloc
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
40
diff
changeset
|
288 // channel->pointer + channel->size - channel->maxsize でリングバッファ先頭からのアドレスになる |
51a006a8d843
imported patch ringbuf-vmalloc
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
40
diff
changeset
|
289 memcpy(&channel->buf[channel->pointer + channel->size - channel->maxsize], channel->packet_buf, PACKET_SIZE); |
51a006a8d843
imported patch ringbuf-vmalloc
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
40
diff
changeset
|
290 } else if (channel->pointer + channel->size + PACKET_SIZE > channel->maxsize) { |
51a006a8d843
imported patch ringbuf-vmalloc
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
40
diff
changeset
|
291 // リングバッファの境界をまたぐように書き込まれる場合 |
51a006a8d843
imported patch ringbuf-vmalloc
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
40
diff
changeset
|
292 // リングバッファの境界まで書き込み |
51a006a8d843
imported patch ringbuf-vmalloc
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
40
diff
changeset
|
293 __u32 tmp_size = channel->maxsize - (channel->pointer + channel->size); |
51a006a8d843
imported patch ringbuf-vmalloc
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
40
diff
changeset
|
294 memcpy(&channel->buf[channel->pointer + channel->size], channel->packet_buf, tmp_size); |
51a006a8d843
imported patch ringbuf-vmalloc
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
40
diff
changeset
|
295 // 先頭に戻って書き込み |
51a006a8d843
imported patch ringbuf-vmalloc
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
40
diff
changeset
|
296 memcpy(channel->buf, &channel->packet_buf[tmp_size], PACKET_SIZE - tmp_size); |
51a006a8d843
imported patch ringbuf-vmalloc
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
40
diff
changeset
|
297 } else { |
51a006a8d843
imported patch ringbuf-vmalloc
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
40
diff
changeset
|
298 // リングバッファ内で収まる場合 |
51a006a8d843
imported patch ringbuf-vmalloc
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
40
diff
changeset
|
299 // 通常の書き込み |
51a006a8d843
imported patch ringbuf-vmalloc
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
40
diff
changeset
|
300 memcpy(&channel->buf[channel->pointer + channel->size], channel->packet_buf, PACKET_SIZE); |
51a006a8d843
imported patch ringbuf-vmalloc
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
40
diff
changeset
|
301 } |
37
c359e7adf700
propagate upstream change:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
36
diff
changeset
|
302 channel->size += PACKET_SIZE ; |
c359e7adf700
propagate upstream change:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
36
diff
changeset
|
303 channel->packet_size = 0 ; |
0 | 304 } |
305 mutex_unlock(&channel->lock); | |
306 } | |
307 curdataptr[(DMA_SIZE / sizeof(__u32)) - 2] = 0; | |
308 | |
309 if(data_pos >= DMA_RING_MAX){ | |
310 data_pos = 0; | |
311 ring_pos += 1 ; | |
312 // DMAリングが変わった場合はインクリメント | |
313 writel(0x00000020, dev_conf->regs); | |
314 if(ring_pos >= DMA_RING_SIZE){ | |
315 ring_pos = 0 ; | |
316 } | |
317 } | |
318 | |
120
3914cc1b2375
- adapted to 3.x kernels
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
119
diff
changeset
|
319 // 頻度を落す(wait until READ_SIZE) |
0 | 320 for(lp = 0 ; lp < MAX_CHANNEL ; lp++){ |
86 | 321 channel = dev_conf->channel[real_channel[lp]] ; |
120
3914cc1b2375
- adapted to 3.x kernels
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
119
diff
changeset
|
322 if((channel->size >= READ_SIZE) && (channel->valid == TRUE)){ |
0 | 323 wake_up(&channel->wait_q); |
324 } | |
325 } | |
326 } | |
124 | 327 schedule_timeout_interruptible(msecs_to_jiffies(100)); |
0 | 328 } |
329 return 0 ; | |
330 } | |
331 static int pt1_open(struct inode *inode, struct file *file) | |
332 { | |
31
289794dc265f
adapted to use of multiple number of pt1:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
30
diff
changeset
|
333 int major = imajor(inode); |
0 | 334 int minor = iminor(inode); |
335 int lp ; | |
336 int lp2 ; | |
337 PT1_CHANNEL *channel ; | |
338 | |
339 for(lp = 0 ; lp < MAX_PCI_DEVICE ; lp++){ | |
340 if(device[lp] == NULL){ | |
341 return -EIO ; | |
342 } | |
31
289794dc265f
adapted to use of multiple number of pt1:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
30
diff
changeset
|
343 |
289794dc265f
adapted to use of multiple number of pt1:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
30
diff
changeset
|
344 if(MAJOR(device[lp]->dev) == major && |
289794dc265f
adapted to use of multiple number of pt1:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
30
diff
changeset
|
345 device[lp]->base_minor <= minor && |
289794dc265f
adapted to use of multiple number of pt1:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
30
diff
changeset
|
346 device[lp]->base_minor + MAX_CHANNEL > minor) { |
289794dc265f
adapted to use of multiple number of pt1:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
30
diff
changeset
|
347 |
0 | 348 mutex_lock(&device[lp]->lock); |
349 for(lp2 = 0 ; lp2 < MAX_CHANNEL ; lp2++){ | |
350 channel = device[lp]->channel[lp2] ; | |
351 if(channel->minor == minor){ | |
352 if(channel->valid == TRUE){ | |
353 mutex_unlock(&device[lp]->lock); | |
354 return -EIO ; | |
355 } | |
111
c8cfd684fee8
re-enable set_sleepmode. backing out r109.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
109
diff
changeset
|
356 |
102
6e661e828b43
send tuners to sleep mode when they are inactive
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
95
diff
changeset
|
357 /* wake tuner up */ |
6e661e828b43
send tuners to sleep mode when they are inactive
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
95
diff
changeset
|
358 set_sleepmode(channel->ptr->regs, &channel->lock, |
6e661e828b43
send tuners to sleep mode when they are inactive
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
95
diff
changeset
|
359 channel->address, channel->type, |
6e661e828b43
send tuners to sleep mode when they are inactive
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
95
diff
changeset
|
360 TYPE_WAKEUP); |
124 | 361 schedule_timeout_interruptible(msecs_to_jiffies(100)); |
111
c8cfd684fee8
re-enable set_sleepmode. backing out r109.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
109
diff
changeset
|
362 |
0 | 363 channel->drop = 0 ; |
364 channel->valid = TRUE ; | |
365 channel->overflow = 0 ; | |
366 channel->counetererr = 0 ; | |
367 channel->transerr = 0 ; | |
37
c359e7adf700
propagate upstream change:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
36
diff
changeset
|
368 channel->packet_size = 0 ; |
0 | 369 file->private_data = channel; |
370 mutex_lock(&channel->lock); | |
371 // データ初期化 | |
372 channel->size = 0 ; | |
373 mutex_unlock(&channel->lock); | |
374 mutex_unlock(&device[lp]->lock); | |
375 return 0 ; | |
376 } | |
377 } | |
378 } | |
379 } | |
380 return -EIO; | |
381 } | |
382 static int pt1_release(struct inode *inode, struct file *file) | |
383 { | |
384 PT1_CHANNEL *channel = file->private_data; | |
385 | |
386 mutex_lock(&channel->ptr->lock); | |
387 SetStream(channel->ptr->regs, channel->channel, FALSE); | |
388 channel->valid = FALSE ; | |
31
289794dc265f
adapted to use of multiple number of pt1:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
30
diff
changeset
|
389 printk(KERN_INFO "(%d:%d)Drop=%08d:%08d:%08d:%08d\n", imajor(inode), iminor(inode), channel->drop, |
0 | 390 channel->overflow, channel->counetererr, channel->transerr); |
391 channel->overflow = 0 ; | |
392 channel->counetererr = 0 ; | |
393 channel->transerr = 0 ; | |
394 channel->drop = 0 ; | |
395 // 停止している場合は起こす | |
396 if(channel->req_dma == TRUE){ | |
397 channel->req_dma = FALSE ; | |
398 wake_up(&channel->ptr->dma_wait_q); | |
399 } | |
400 mutex_unlock(&channel->ptr->lock); | |
102
6e661e828b43
send tuners to sleep mode when they are inactive
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
95
diff
changeset
|
401 |
6e661e828b43
send tuners to sleep mode when they are inactive
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
95
diff
changeset
|
402 /* send tuner to sleep */ |
6e661e828b43
send tuners to sleep mode when they are inactive
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
95
diff
changeset
|
403 set_sleepmode(channel->ptr->regs, &channel->lock, |
6e661e828b43
send tuners to sleep mode when they are inactive
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
95
diff
changeset
|
404 channel->address, channel->type, TYPE_SLEEP); |
124 | 405 schedule_timeout_interruptible(msecs_to_jiffies(100)); |
102
6e661e828b43
send tuners to sleep mode when they are inactive
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
95
diff
changeset
|
406 |
0 | 407 return 0; |
408 } | |
409 | |
410 static ssize_t pt1_read(struct file *file, char __user *buf, size_t cnt, loff_t * ppos) | |
411 { | |
412 PT1_CHANNEL *channel = file->private_data; | |
413 __u32 size ; | |
36 | 414 unsigned long dummy; |
0 | 415 |
120
3914cc1b2375
- adapted to 3.x kernels
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
119
diff
changeset
|
416 // READ_SIZE単位で起こされるのを待つ(CPU負荷対策) |
3914cc1b2375
- adapted to 3.x kernels
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
119
diff
changeset
|
417 if(channel->size < READ_SIZE){ |
3914cc1b2375
- adapted to 3.x kernels
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
119
diff
changeset
|
418 wait_event_timeout(channel->wait_q, (channel->size >= READ_SIZE), |
0 | 419 msecs_to_jiffies(500)); |
420 } | |
421 mutex_lock(&channel->lock); | |
422 if(!channel->size){ | |
423 size = 0 ; | |
424 }else{ | |
41
51a006a8d843
imported patch ringbuf-vmalloc
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
40
diff
changeset
|
425 __u32 tmp_size = 0; |
51a006a8d843
imported patch ringbuf-vmalloc
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
40
diff
changeset
|
426 if (cnt < channel->size) { |
51a006a8d843
imported patch ringbuf-vmalloc
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
40
diff
changeset
|
427 // バッファにあるデータより小さい読み込みの場合 |
51a006a8d843
imported patch ringbuf-vmalloc
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
40
diff
changeset
|
428 size = cnt; |
51a006a8d843
imported patch ringbuf-vmalloc
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
40
diff
changeset
|
429 } else { |
51a006a8d843
imported patch ringbuf-vmalloc
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
40
diff
changeset
|
430 // バッファにあるデータ以上の読み込みの場合 |
51a006a8d843
imported patch ringbuf-vmalloc
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
40
diff
changeset
|
431 size = channel->size; |
0 | 432 } |
41
51a006a8d843
imported patch ringbuf-vmalloc
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
40
diff
changeset
|
433 if (channel->maxsize <= size + channel->pointer) { |
51a006a8d843
imported patch ringbuf-vmalloc
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
40
diff
changeset
|
434 // リングバッファの境界を越える場合 |
51a006a8d843
imported patch ringbuf-vmalloc
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
40
diff
changeset
|
435 tmp_size = channel->maxsize - channel->pointer; |
51a006a8d843
imported patch ringbuf-vmalloc
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
40
diff
changeset
|
436 // 境界までコピー |
44 | 437 dummy = copy_to_user(buf, &channel->buf[channel->pointer], tmp_size); |
41
51a006a8d843
imported patch ringbuf-vmalloc
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
40
diff
changeset
|
438 // 残りをコピー |
44 | 439 dummy = copy_to_user(&buf[tmp_size], channel->buf, size - tmp_size); |
41
51a006a8d843
imported patch ringbuf-vmalloc
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
40
diff
changeset
|
440 channel->pointer = size - tmp_size; |
51a006a8d843
imported patch ringbuf-vmalloc
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
40
diff
changeset
|
441 } else { |
51a006a8d843
imported patch ringbuf-vmalloc
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
40
diff
changeset
|
442 // 普通にコピー |
44 | 443 dummy = copy_to_user(buf, &channel->buf[channel->pointer], size); |
41
51a006a8d843
imported patch ringbuf-vmalloc
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
40
diff
changeset
|
444 channel->pointer += size; |
51a006a8d843
imported patch ringbuf-vmalloc
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
40
diff
changeset
|
445 } |
51a006a8d843
imported patch ringbuf-vmalloc
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
40
diff
changeset
|
446 channel->size -= size; |
0 | 447 } |
448 // 読み終わったかつ使用しているのがが4K以下 | |
9
07b2fc07ff48
updated to current driver to support signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
449 if(channel->req_dma == TRUE){ |
0 | 450 channel->req_dma = FALSE ; |
451 wake_up(&channel->ptr->dma_wait_q); | |
452 } | |
453 mutex_unlock(&channel->lock); | |
454 return size ; | |
455 } | |
456 static int SetFreq(PT1_CHANNEL *channel, FREQUENCY *freq) | |
457 { | |
458 | |
459 switch(channel->type){ | |
460 case CHANNEL_TYPE_ISDB_S: | |
461 { | |
462 ISDB_S_TMCC tmcc ; | |
463 if(bs_tune(channel->ptr->regs, | |
464 &channel->ptr->lock, | |
465 channel->address, | |
466 freq->frequencyno, | |
467 &tmcc) < 0){ | |
468 return -EIO ; | |
469 } | |
470 | |
471 #if 0 | |
472 printk(KERN_INFO "clockmargin = (%x)\n", (tmcc.clockmargin & 0xFF)); | |
473 printk(KERN_INFO "carriermargin = (%x)\n", (tmcc.carriermargin & 0xFF)); | |
102
6e661e828b43
send tuners to sleep mode when they are inactive
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
95
diff
changeset
|
474 { |
6e661e828b43
send tuners to sleep mode when they are inactive
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
95
diff
changeset
|
475 int lp; |
6e661e828b43
send tuners to sleep mode when they are inactive
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
95
diff
changeset
|
476 for(lp = 0 ; lp < MAX_BS_TS_ID ; lp++){ |
6e661e828b43
send tuners to sleep mode when they are inactive
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
95
diff
changeset
|
477 if(tmcc.ts_id[lp].ts_id == 0xFFFF){ |
6e661e828b43
send tuners to sleep mode when they are inactive
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
95
diff
changeset
|
478 continue ; |
6e661e828b43
send tuners to sleep mode when they are inactive
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
95
diff
changeset
|
479 } |
6e661e828b43
send tuners to sleep mode when they are inactive
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
95
diff
changeset
|
480 printk(KERN_INFO "Slot(%d:%x)\n", lp, tmcc.ts_id[lp].ts_id); |
6e661e828b43
send tuners to sleep mode when they are inactive
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
95
diff
changeset
|
481 printk(KERN_INFO "mode (low/high) = (%x:%x)\n", |
6e661e828b43
send tuners to sleep mode when they are inactive
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
95
diff
changeset
|
482 tmcc.ts_id[lp].low_mode, tmcc.ts_id[lp].high_mode); |
6e661e828b43
send tuners to sleep mode when they are inactive
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
95
diff
changeset
|
483 printk(KERN_INFO "slot (low/high) = (%x:%x)\n", |
6e661e828b43
send tuners to sleep mode when they are inactive
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
95
diff
changeset
|
484 tmcc.ts_id[lp].low_slot, |
6e661e828b43
send tuners to sleep mode when they are inactive
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
95
diff
changeset
|
485 tmcc.ts_id[lp].high_slot); |
0 | 486 } |
487 } | |
488 #endif | |
489 ts_lock(channel->ptr->regs, | |
490 &channel->ptr->lock, | |
491 channel->address, | |
492 tmcc.ts_id[freq->slot].ts_id); | |
493 } | |
494 break ; | |
495 case CHANNEL_TYPE_ISDB_T: | |
496 { | |
497 if(isdb_t_frequency(channel->ptr->regs, | |
498 &channel->ptr->lock, | |
499 channel->address, | |
500 freq->frequencyno, freq->slot) < 0){ | |
501 return -EINVAL ; | |
502 } | |
503 } | |
504 } | |
505 return 0 ; | |
506 } | |
95
a201531113ca
implement decent LNB management
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
93
diff
changeset
|
507 |
a201531113ca
implement decent LNB management
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
93
diff
changeset
|
508 static int count_used_bs_tuners(PT1_DEVICE *device) |
a201531113ca
implement decent LNB management
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
93
diff
changeset
|
509 { |
a201531113ca
implement decent LNB management
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
93
diff
changeset
|
510 int count = 0; |
a201531113ca
implement decent LNB management
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
93
diff
changeset
|
511 int i; |
a201531113ca
implement decent LNB management
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
93
diff
changeset
|
512 |
a201531113ca
implement decent LNB management
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
93
diff
changeset
|
513 for(i=0; i<MAX_CHANNEL; i++) { |
a201531113ca
implement decent LNB management
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
93
diff
changeset
|
514 if(device && device->channel[i] && |
a201531113ca
implement decent LNB management
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
93
diff
changeset
|
515 device->channel[i]->type == CHANNEL_TYPE_ISDB_S && |
a201531113ca
implement decent LNB management
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
93
diff
changeset
|
516 device->channel[i]->valid) |
a201531113ca
implement decent LNB management
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
93
diff
changeset
|
517 count++; |
a201531113ca
implement decent LNB management
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
93
diff
changeset
|
518 } |
a201531113ca
implement decent LNB management
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
93
diff
changeset
|
519 |
a201531113ca
implement decent LNB management
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
93
diff
changeset
|
520 printk(KERN_INFO "used bs tuners on %p = %d\n", device, count); |
a201531113ca
implement decent LNB management
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
93
diff
changeset
|
521 return count; |
a201531113ca
implement decent LNB management
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
93
diff
changeset
|
522 } |
a201531113ca
implement decent LNB management
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
93
diff
changeset
|
523 |
119
7662d0ecd74b
revised new ioctl functions
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
118
diff
changeset
|
524 static long pt1_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg0) |
0 | 525 { |
526 PT1_CHANNEL *channel = file->private_data; | |
95
a201531113ca
implement decent LNB management
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
93
diff
changeset
|
527 int signal; |
36 | 528 unsigned long dummy; |
529 void *arg = (void *)arg0; | |
80
f336fd2dcf28
make LNB voltage can be specified from user application
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
79
diff
changeset
|
530 int lnb_eff, lnb_usr; |
f336fd2dcf28
make LNB voltage can be specified from user application
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
79
diff
changeset
|
531 char *voltage[] = {"0V", "11V", "15V"}; |
95
a201531113ca
implement decent LNB management
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
93
diff
changeset
|
532 int count; |
0 | 533 |
534 switch(cmd){ | |
535 case SET_CHANNEL: | |
536 { | |
537 FREQUENCY freq ; | |
36 | 538 dummy = copy_from_user(&freq, arg, sizeof(FREQUENCY)); |
0 | 539 return SetFreq(channel, &freq); |
540 } | |
541 case START_REC: | |
542 SetStream(channel->ptr->regs, channel->channel, TRUE); | |
543 return 0 ; | |
544 case STOP_REC: | |
545 SetStream(channel->ptr->regs, channel->channel, FALSE); | |
120
3914cc1b2375
- adapted to 3.x kernels
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
119
diff
changeset
|
546 schedule_timeout_interruptible(msecs_to_jiffies(100)); |
0 | 547 return 0 ; |
9
07b2fc07ff48
updated to current driver to support signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
548 case GET_SIGNAL_STRENGTH: |
07b2fc07ff48
updated to current driver to support signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
549 switch(channel->type){ |
07b2fc07ff48
updated to current driver to support signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
550 case CHANNEL_TYPE_ISDB_S: |
86 | 551 signal = isdb_s_read_signal_strength(channel->ptr->regs, |
552 &channel->ptr->lock, | |
553 channel->address); | |
9
07b2fc07ff48
updated to current driver to support signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
554 break ; |
07b2fc07ff48
updated to current driver to support signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
555 case CHANNEL_TYPE_ISDB_T: |
36 | 556 signal = isdb_t_read_signal_strength(channel->ptr->regs, |
9
07b2fc07ff48
updated to current driver to support signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
557 &channel->ptr->lock, channel->address); |
07b2fc07ff48
updated to current driver to support signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
558 break ; |
07b2fc07ff48
updated to current driver to support signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
559 } |
36 | 560 dummy = copy_to_user(arg, &signal, sizeof(int)); |
9
07b2fc07ff48
updated to current driver to support signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
561 return 0 ; |
07b2fc07ff48
updated to current driver to support signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
562 case LNB_ENABLE: |
95
a201531113ca
implement decent LNB management
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
93
diff
changeset
|
563 count = count_used_bs_tuners(channel->ptr); |
a201531113ca
implement decent LNB management
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
93
diff
changeset
|
564 if(count <= 1) { |
a201531113ca
implement decent LNB management
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
93
diff
changeset
|
565 lnb_usr = (int)arg0; |
a201531113ca
implement decent LNB management
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
93
diff
changeset
|
566 lnb_eff = lnb_usr ? lnb_usr : lnb; |
a201531113ca
implement decent LNB management
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
93
diff
changeset
|
567 settuner_reset(channel->ptr->regs, channel->ptr->cardtype, lnb_eff, TUNER_POWER_ON_RESET_DISABLE); |
a201531113ca
implement decent LNB management
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
93
diff
changeset
|
568 printk(KERN_INFO "PT1:LNB on %s\n", voltage[lnb_eff]); |
a201531113ca
implement decent LNB management
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
93
diff
changeset
|
569 } |
9
07b2fc07ff48
updated to current driver to support signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
570 return 0 ; |
07b2fc07ff48
updated to current driver to support signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
571 case LNB_DISABLE: |
95
a201531113ca
implement decent LNB management
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
93
diff
changeset
|
572 count = count_used_bs_tuners(channel->ptr); |
a201531113ca
implement decent LNB management
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
93
diff
changeset
|
573 if(count <= 1) { |
82
cfb2da5ee428
added LNB reference count to maintain power state during recording.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
80
diff
changeset
|
574 settuner_reset(channel->ptr->regs, channel->ptr->cardtype, LNB_OFF, TUNER_POWER_ON_RESET_DISABLE); |
95
a201531113ca
implement decent LNB management
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
93
diff
changeset
|
575 printk(KERN_INFO "PT1:LNB off\n"); |
a201531113ca
implement decent LNB management
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
93
diff
changeset
|
576 } |
9
07b2fc07ff48
updated to current driver to support signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
577 return 0 ; |
0 | 578 } |
579 return -EINVAL; | |
580 } | |
581 | |
119
7662d0ecd74b
revised new ioctl functions
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
118
diff
changeset
|
582 static long pt1_unlocked_ioctl(struct file *file, unsigned int cmd, unsigned long arg0) |
7662d0ecd74b
revised new ioctl functions
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
118
diff
changeset
|
583 { |
120
3914cc1b2375
- adapted to 3.x kernels
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
119
diff
changeset
|
584 PT1_CHANNEL *channel = file->private_data; |
119
7662d0ecd74b
revised new ioctl functions
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
118
diff
changeset
|
585 long ret; |
7662d0ecd74b
revised new ioctl functions
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
118
diff
changeset
|
586 |
120
3914cc1b2375
- adapted to 3.x kernels
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
119
diff
changeset
|
587 mutex_lock(&channel->lock); |
119
7662d0ecd74b
revised new ioctl functions
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
118
diff
changeset
|
588 ret = pt1_do_ioctl(file, cmd, arg0); |
120
3914cc1b2375
- adapted to 3.x kernels
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
119
diff
changeset
|
589 mutex_unlock(&channel->lock); |
119
7662d0ecd74b
revised new ioctl functions
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
118
diff
changeset
|
590 |
7662d0ecd74b
revised new ioctl functions
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
118
diff
changeset
|
591 return ret; |
7662d0ecd74b
revised new ioctl functions
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
118
diff
changeset
|
592 } |
7662d0ecd74b
revised new ioctl functions
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
118
diff
changeset
|
593 |
7662d0ecd74b
revised new ioctl functions
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
118
diff
changeset
|
594 static long pt1_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg0) |
7662d0ecd74b
revised new ioctl functions
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
118
diff
changeset
|
595 { |
7662d0ecd74b
revised new ioctl functions
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
118
diff
changeset
|
596 long ret; |
7662d0ecd74b
revised new ioctl functions
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
118
diff
changeset
|
597 /* should do 32bit <-> 64bit conversion here? --yaz */ |
7662d0ecd74b
revised new ioctl functions
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
118
diff
changeset
|
598 ret = pt1_unlocked_ioctl(file, cmd, arg0); |
7662d0ecd74b
revised new ioctl functions
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
118
diff
changeset
|
599 |
7662d0ecd74b
revised new ioctl functions
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
118
diff
changeset
|
600 return ret; |
7662d0ecd74b
revised new ioctl functions
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
118
diff
changeset
|
601 } |
7662d0ecd74b
revised new ioctl functions
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
118
diff
changeset
|
602 |
7662d0ecd74b
revised new ioctl functions
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
118
diff
changeset
|
603 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,36) |
7662d0ecd74b
revised new ioctl functions
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
118
diff
changeset
|
604 static int pt1_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg0) |
7662d0ecd74b
revised new ioctl functions
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
118
diff
changeset
|
605 { |
7662d0ecd74b
revised new ioctl functions
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
118
diff
changeset
|
606 int ret; |
7662d0ecd74b
revised new ioctl functions
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
118
diff
changeset
|
607 ret = (int)pt1_do_ioctl(file, cmd, arg0); |
7662d0ecd74b
revised new ioctl functions
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
118
diff
changeset
|
608 return ret; |
7662d0ecd74b
revised new ioctl functions
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
118
diff
changeset
|
609 } |
7662d0ecd74b
revised new ioctl functions
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
118
diff
changeset
|
610 #endif |
7662d0ecd74b
revised new ioctl functions
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
118
diff
changeset
|
611 |
0 | 612 /* |
613 */ | |
614 static const struct file_operations pt1_fops = { | |
615 .owner = THIS_MODULE, | |
616 .open = pt1_open, | |
617 .release = pt1_release, | |
618 .read = pt1_read, | |
119
7662d0ecd74b
revised new ioctl functions
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
118
diff
changeset
|
619 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,36) |
0 | 620 .ioctl = pt1_ioctl, |
120
3914cc1b2375
- adapted to 3.x kernels
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
119
diff
changeset
|
621 #else |
119
7662d0ecd74b
revised new ioctl functions
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
118
diff
changeset
|
622 .unlocked_ioctl = pt1_unlocked_ioctl, |
7662d0ecd74b
revised new ioctl functions
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
118
diff
changeset
|
623 .compat_ioctl = pt1_compat_ioctl, |
120
3914cc1b2375
- adapted to 3.x kernels
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
119
diff
changeset
|
624 #endif |
0 | 625 .llseek = no_llseek, |
626 }; | |
627 | |
628 int pt1_makering(struct pci_dev *pdev, PT1_DEVICE *dev_conf) | |
629 { | |
630 int lp ; | |
631 int lp2 ; | |
632 DMA_CONTROL *dmactl; | |
633 __u32 *dmaptr ; | |
634 __u32 addr ; | |
635 __u32 *ptr ; | |
636 | |
637 //DMAリング作成 | |
638 for(lp = 0 ; lp < DMA_RING_SIZE ; lp++){ | |
639 ptr = dev_conf->dmaptr[lp]; | |
640 if(lp == (DMA_RING_SIZE - 1)){ | |
641 addr = (__u32)dev_conf->ring_dma[0]; | |
642 }else{ | |
643 addr = (__u32)dev_conf->ring_dma[(lp + 1)]; | |
644 } | |
645 addr >>= 12 ; | |
646 memcpy(ptr, &addr, sizeof(__u32)); | |
647 ptr += 1 ; | |
648 | |
40
8f30a05cded2
imported patch dmactlalloc
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
37
diff
changeset
|
649 dmactl = dev_conf->dmactl[lp]; |
0 | 650 for(lp2 = 0 ; lp2 < DMA_RING_MAX ; lp2++){ |
651 dmaptr = pci_alloc_consistent(pdev, DMA_SIZE, &dmactl->ring_dma[lp2]); | |
652 if(dmaptr == NULL){ | |
653 printk(KERN_INFO "PT1:DMA ALLOC ERROR\n"); | |
654 return -1 ; | |
655 } | |
656 dmactl->data[lp2] = dmaptr ; | |
657 // DMAデータエリア初期化 | |
658 dmaptr[(DMA_SIZE / sizeof(__u32)) - 2] = 0 ; | |
659 addr = (__u32)dmactl->ring_dma[lp2]; | |
660 addr >>= 12 ; | |
661 memcpy(ptr, &addr, sizeof(__u32)); | |
662 ptr += 1 ; | |
663 } | |
664 } | |
665 return 0 ; | |
666 } | |
667 int pt1_dma_init(struct pci_dev *pdev, PT1_DEVICE *dev_conf) | |
668 { | |
669 int lp ; | |
670 void *ptr ; | |
671 | |
672 for(lp = 0 ; lp < DMA_RING_SIZE ; lp++){ | |
673 ptr = pci_alloc_consistent(pdev, DMA_SIZE, &dev_conf->ring_dma[lp]); | |
674 if(ptr == NULL){ | |
675 printk(KERN_INFO "PT1:DMA ALLOC ERROR\n"); | |
676 return -1 ; | |
677 } | |
678 dev_conf->dmaptr[lp] = ptr ; | |
679 } | |
680 | |
681 return pt1_makering(pdev, dev_conf); | |
682 } | |
683 int pt1_dma_free(struct pci_dev *pdev, PT1_DEVICE *dev_conf) | |
684 { | |
685 | |
686 int lp ; | |
687 int lp2 ; | |
688 | |
689 for(lp = 0 ; lp < DMA_RING_SIZE ; lp++){ | |
690 if(dev_conf->dmaptr[lp] != NULL){ | |
691 pci_free_consistent(pdev, DMA_SIZE, | |
692 dev_conf->dmaptr[lp], dev_conf->ring_dma[lp]); | |
693 for(lp2 = 0 ; lp2 < DMA_RING_MAX ; lp2++){ | |
40
8f30a05cded2
imported patch dmactlalloc
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
37
diff
changeset
|
694 if((dev_conf->dmactl[lp])->data[lp2] != NULL){ |
0 | 695 pci_free_consistent(pdev, DMA_SIZE, |
40
8f30a05cded2
imported patch dmactlalloc
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
37
diff
changeset
|
696 (dev_conf->dmactl[lp])->data[lp2], |
8f30a05cded2
imported patch dmactlalloc
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
37
diff
changeset
|
697 (dev_conf->dmactl[lp])->ring_dma[lp2]); |
0 | 698 } |
699 } | |
700 } | |
701 } | |
702 return 0 ; | |
703 } | |
704 static int __devinit pt1_pci_init_one (struct pci_dev *pdev, | |
705 const struct pci_device_id *ent) | |
706 { | |
707 int rc ; | |
708 int lp ; | |
709 int minor ; | |
710 u16 cmd ; | |
711 PT1_DEVICE *dev_conf ; | |
712 PT1_CHANNEL *channel ; | |
40
8f30a05cded2
imported patch dmactlalloc
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
37
diff
changeset
|
713 int i; |
36 | 714 struct resource *dummy; |
0 | 715 |
716 rc = pci_enable_device(pdev); | |
717 if (rc) | |
718 return rc; | |
64
98a92ce5382e
added fake support code for PT2. the PT2 part is not expected to work. be careful!
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
51
diff
changeset
|
719 rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
0 | 720 if (rc) { |
721 printk(KERN_ERR "PT1:DMA MASK ERROR"); | |
722 return rc; | |
723 } | |
724 | |
725 pci_read_config_word(pdev, PCI_COMMAND, &cmd); | |
726 if (!(cmd & PCI_COMMAND_MASTER)) { | |
727 printk(KERN_INFO "Attempting to enable Bus Mastering\n"); | |
728 pci_set_master(pdev); | |
729 pci_read_config_word(pdev, PCI_COMMAND, &cmd); | |
730 if (!(cmd & PCI_COMMAND_MASTER)) { | |
731 printk(KERN_ERR "Bus Mastering is not enabled\n"); | |
732 return -EIO; | |
733 } | |
734 } | |
735 printk(KERN_INFO "Bus Mastering Enabled.\n"); | |
736 | |
737 dev_conf = kzalloc(sizeof(PT1_DEVICE), GFP_KERNEL); | |
738 if(!dev_conf){ | |
739 printk(KERN_ERR "PT1:out of memory !"); | |
740 return -ENOMEM ; | |
741 } | |
40
8f30a05cded2
imported patch dmactlalloc
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
37
diff
changeset
|
742 for (i = 0; i < DMA_RING_SIZE; i++) { |
8f30a05cded2
imported patch dmactlalloc
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
37
diff
changeset
|
743 dev_conf->dmactl[i] = kzalloc(sizeof(DMA_CONTROL), GFP_KERNEL); |
8f30a05cded2
imported patch dmactlalloc
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
37
diff
changeset
|
744 if(!dev_conf->dmactl[i]){ |
8f30a05cded2
imported patch dmactlalloc
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
37
diff
changeset
|
745 int j; |
8f30a05cded2
imported patch dmactlalloc
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
37
diff
changeset
|
746 for (j = 0; j < i; j++) { |
8f30a05cded2
imported patch dmactlalloc
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
37
diff
changeset
|
747 kfree(dev_conf->dmactl[j]); |
8f30a05cded2
imported patch dmactlalloc
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
37
diff
changeset
|
748 } |
8f30a05cded2
imported patch dmactlalloc
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
37
diff
changeset
|
749 kfree(dev_conf); |
8f30a05cded2
imported patch dmactlalloc
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
37
diff
changeset
|
750 printk(KERN_ERR "PT1:out of memory !"); |
8f30a05cded2
imported patch dmactlalloc
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
37
diff
changeset
|
751 return -ENOMEM ; |
8f30a05cded2
imported patch dmactlalloc
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
37
diff
changeset
|
752 } |
8f30a05cded2
imported patch dmactlalloc
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
37
diff
changeset
|
753 } |
64
98a92ce5382e
added fake support code for PT2. the PT2 part is not expected to work. be careful!
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
51
diff
changeset
|
754 |
98a92ce5382e
added fake support code for PT2. the PT2 part is not expected to work. be careful!
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
51
diff
changeset
|
755 switch(ent->device) { |
98a92ce5382e
added fake support code for PT2. the PT2 part is not expected to work. be careful!
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
51
diff
changeset
|
756 case PCI_PT1_ID: |
98a92ce5382e
added fake support code for PT2. the PT2 part is not expected to work. be careful!
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
51
diff
changeset
|
757 dev_conf->cardtype = PT1; |
98a92ce5382e
added fake support code for PT2. the PT2 part is not expected to work. be careful!
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
51
diff
changeset
|
758 break; |
98a92ce5382e
added fake support code for PT2. the PT2 part is not expected to work. be careful!
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
51
diff
changeset
|
759 case PCI_PT2_ID: |
98a92ce5382e
added fake support code for PT2. the PT2 part is not expected to work. be careful!
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
51
diff
changeset
|
760 dev_conf->cardtype = PT2; |
98a92ce5382e
added fake support code for PT2. the PT2 part is not expected to work. be careful!
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
51
diff
changeset
|
761 break; |
98a92ce5382e
added fake support code for PT2. the PT2 part is not expected to work. be careful!
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
51
diff
changeset
|
762 default: |
98a92ce5382e
added fake support code for PT2. the PT2 part is not expected to work. be careful!
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
51
diff
changeset
|
763 break; |
98a92ce5382e
added fake support code for PT2. the PT2 part is not expected to work. be careful!
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
51
diff
changeset
|
764 } |
98a92ce5382e
added fake support code for PT2. the PT2 part is not expected to work. be careful!
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
51
diff
changeset
|
765 |
0 | 766 // PCIアドレスをマップする |
767 dev_conf->mmio_start = pci_resource_start(pdev, 0); | |
768 dev_conf->mmio_len = pci_resource_len(pdev, 0); | |
36 | 769 dummy = request_mem_region(dev_conf->mmio_start, dev_conf->mmio_len, DEV_NAME); |
770 if (!dummy) { | |
79 | 771 printk(KERN_ERR "PT1:cannot request iomem (0x%llx).\n", (unsigned long long) dev_conf->mmio_start); |
0 | 772 goto out_err_regbase; |
773 } | |
774 | |
775 dev_conf->regs = ioremap(dev_conf->mmio_start, dev_conf->mmio_len); | |
776 if (!dev_conf->regs){ | |
79 | 777 printk(KERN_ERR "pt1:Can't remap register area.\n"); |
0 | 778 goto out_err_regbase; |
779 } | |
780 // 初期化処理 | |
79 | 781 if(xc3s_init(dev_conf->regs, dev_conf->cardtype)){ |
0 | 782 printk(KERN_ERR "Error xc3s_init\n"); |
783 goto out_err_fpga; | |
784 } | |
785 // チューナリセット | |
64
98a92ce5382e
added fake support code for PT2. the PT2 part is not expected to work. be careful!
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
51
diff
changeset
|
786 settuner_reset(dev_conf->regs, dev_conf->cardtype, LNB_OFF, TUNER_POWER_ON_RESET_ENABLE); |
124 | 787 schedule_timeout_interruptible(msecs_to_jiffies(100)); |
0 | 788 |
64
98a92ce5382e
added fake support code for PT2. the PT2 part is not expected to work. be careful!
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
51
diff
changeset
|
789 settuner_reset(dev_conf->regs, dev_conf->cardtype, LNB_OFF, TUNER_POWER_ON_RESET_DISABLE); |
124 | 790 schedule_timeout_interruptible(msecs_to_jiffies(100)); |
0 | 791 mutex_init(&dev_conf->lock); |
792 | |
793 // Tuner 初期化処理 | |
794 for(lp = 0 ; lp < MAX_TUNER ; lp++){ | |
69
272a8fba970b
added very rough support for PT2.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
64
diff
changeset
|
795 rc = tuner_init(dev_conf->regs, dev_conf->cardtype, &dev_conf->lock, lp); |
0 | 796 if(rc < 0){ |
797 printk(KERN_ERR "Error tuner_init\n"); | |
798 goto out_err_fpga; | |
799 } | |
800 } | |
801 // 初期化完了 | |
802 for(lp = 0 ; lp < MAX_CHANNEL ; lp++){ | |
36 | 803 set_sleepmode(dev_conf->regs, &dev_conf->lock, |
111
c8cfd684fee8
re-enable set_sleepmode. backing out r109.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
109
diff
changeset
|
804 i2c_address[lp], channeltype[lp], TYPE_SLEEP); |
36 | 805 |
124 | 806 schedule_timeout_interruptible(msecs_to_jiffies(100)); |
0 | 807 } |
808 rc = alloc_chrdev_region(&dev_conf->dev, 0, MAX_CHANNEL, DEV_NAME); | |
809 if(rc < 0){ | |
810 goto out_err_fpga; | |
811 } | |
812 | |
813 // 初期化 | |
814 init_waitqueue_head(&dev_conf->dma_wait_q); | |
815 | |
816 minor = MINOR(dev_conf->dev) ; | |
817 dev_conf->base_minor = minor ; | |
818 for(lp = 0 ; lp < MAX_PCI_DEVICE ; lp++){ | |
79 | 819 printk(KERN_INFO "PT1:device[%d]=%p\n", lp, device[lp]); |
0 | 820 if(device[lp] == NULL){ |
821 device[lp] = dev_conf ; | |
31
289794dc265f
adapted to use of multiple number of pt1:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
30
diff
changeset
|
822 dev_conf->card_number = lp; |
0 | 823 break ; |
824 } | |
825 } | |
826 for(lp = 0 ; lp < MAX_CHANNEL ; lp++){ | |
827 cdev_init(&dev_conf->cdev[lp], &pt1_fops); | |
30
eb694d8e4c7e
setup owner in initialization
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
828 dev_conf->cdev[lp].owner = THIS_MODULE; |
31
289794dc265f
adapted to use of multiple number of pt1:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
30
diff
changeset
|
829 cdev_add(&dev_conf->cdev[lp], |
289794dc265f
adapted to use of multiple number of pt1:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
30
diff
changeset
|
830 MKDEV(MAJOR(dev_conf->dev), (MINOR(dev_conf->dev) + lp)), 1); |
0 | 831 channel = kzalloc(sizeof(PT1_CHANNEL), GFP_KERNEL); |
832 if(!channel){ | |
833 printk(KERN_ERR "PT1:out of memory !"); | |
834 return -ENOMEM ; | |
835 } | |
836 | |
837 // 共通情報 | |
838 mutex_init(&channel->lock); | |
839 // 待ち状態を解除 | |
840 channel->req_dma = FALSE ; | |
841 // マイナー番号設定 | |
842 channel->minor = MINOR(dev_conf->dev) + lp ; | |
843 // 対象のI2Cデバイス | |
844 channel->address = i2c_address[lp] ; | |
845 channel->type = channeltype[lp] ; | |
846 // 実際のチューナ番号 | |
86 | 847 channel->channel = real_channel[lp] ; |
0 | 848 channel->ptr = dev_conf ; |
849 channel->size = 0 ; | |
850 dev_conf->channel[lp] = channel ; | |
851 | |
852 init_waitqueue_head(&channel->wait_q); | |
853 | |
854 switch(channel->type){ | |
855 case CHANNEL_TYPE_ISDB_T: | |
124 | 856 channel->maxsize = CHANNEL_DMA_SIZE ; |
857 channel->buf = vmalloc(CHANNEL_DMA_SIZE); | |
41
51a006a8d843
imported patch ringbuf-vmalloc
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
40
diff
changeset
|
858 channel->pointer = 0; |
0 | 859 break ; |
860 case CHANNEL_TYPE_ISDB_S: | |
124 | 861 channel->maxsize = BS_CHANNEL_DMA_SIZE ; |
862 channel->buf = vmalloc(BS_CHANNEL_DMA_SIZE); | |
41
51a006a8d843
imported patch ringbuf-vmalloc
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
40
diff
changeset
|
863 channel->pointer = 0; |
0 | 864 break ; |
865 } | |
866 if(channel->buf == NULL){ | |
867 goto out_err_v4l; | |
868 } | |
9
07b2fc07ff48
updated to current driver to support signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
869 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27) |
79 | 870 printk(KERN_INFO "PT1:card_number = %d\n", |
31
289794dc265f
adapted to use of multiple number of pt1:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
30
diff
changeset
|
871 dev_conf->card_number); |
289794dc265f
adapted to use of multiple number of pt1:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
30
diff
changeset
|
872 device_create(pt1video_class, |
289794dc265f
adapted to use of multiple number of pt1:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
30
diff
changeset
|
873 NULL, |
289794dc265f
adapted to use of multiple number of pt1:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
30
diff
changeset
|
874 MKDEV(MAJOR(dev_conf->dev), |
289794dc265f
adapted to use of multiple number of pt1:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
30
diff
changeset
|
875 (MINOR(dev_conf->dev) + lp)), |
289794dc265f
adapted to use of multiple number of pt1:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
30
diff
changeset
|
876 NULL, |
289794dc265f
adapted to use of multiple number of pt1:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
30
diff
changeset
|
877 "pt1video%u", |
289794dc265f
adapted to use of multiple number of pt1:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
30
diff
changeset
|
878 MINOR(dev_conf->dev) + lp + |
289794dc265f
adapted to use of multiple number of pt1:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
30
diff
changeset
|
879 dev_conf->card_number * MAX_CHANNEL); |
9
07b2fc07ff48
updated to current driver to support signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
880 #else |
31
289794dc265f
adapted to use of multiple number of pt1:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
30
diff
changeset
|
881 device_create(pt1video_class, |
289794dc265f
adapted to use of multiple number of pt1:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
30
diff
changeset
|
882 NULL, |
289794dc265f
adapted to use of multiple number of pt1:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
30
diff
changeset
|
883 MKDEV(MAJOR(dev_conf->dev), |
289794dc265f
adapted to use of multiple number of pt1:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
30
diff
changeset
|
884 (MINOR(dev_conf->dev) + lp)), |
289794dc265f
adapted to use of multiple number of pt1:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
30
diff
changeset
|
885 "pt1video%u", |
289794dc265f
adapted to use of multiple number of pt1:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
30
diff
changeset
|
886 MINOR(dev_conf->dev) + lp + |
289794dc265f
adapted to use of multiple number of pt1:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
30
diff
changeset
|
887 dev_conf->card_number * MAX_CHANNEL); |
9
07b2fc07ff48
updated to current driver to support signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
888 #endif |
07b2fc07ff48
updated to current driver to support signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
889 |
0 | 890 #if 0 |
891 dev_conf->vdev[lp] = video_device_alloc(); | |
892 memcpy(dev_conf->vdev[lp], &pt1_template, sizeof(pt1_template)); | |
893 video_set_drvdata(dev_conf->vdev[lp], channel); | |
894 video_register_device(dev_conf->vdev[lp], VFL_TYPE_GRABBER, -1); | |
895 #endif | |
896 } | |
31
289794dc265f
adapted to use of multiple number of pt1:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
30
diff
changeset
|
897 |
0 | 898 if(pt1_dma_init(pdev, dev_conf) < 0){ |
899 goto out_err_dma; | |
900 } | |
901 dev_conf->kthread = kthread_run(pt1_thread, dev_conf, "pt1"); | |
902 pci_set_drvdata(pdev, dev_conf); | |
903 return 0; | |
904 | |
905 out_err_dma: | |
906 pt1_dma_free(pdev, dev_conf); | |
907 out_err_v4l: | |
908 for(lp = 0 ; lp < MAX_CHANNEL ; lp++){ | |
909 if(dev_conf->channel[lp] != NULL){ | |
910 if(dev_conf->channel[lp]->buf != NULL){ | |
41
51a006a8d843
imported patch ringbuf-vmalloc
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
40
diff
changeset
|
911 vfree(dev_conf->channel[lp]->buf); |
0 | 912 } |
913 kfree(dev_conf->channel[lp]); | |
914 } | |
915 } | |
916 out_err_fpga: | |
917 writel(0xb0b0000, dev_conf->regs); | |
64
98a92ce5382e
added fake support code for PT2. the PT2 part is not expected to work. be careful!
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
51
diff
changeset
|
918 writel(0, dev_conf->regs + CFG_REGS_ADDR); |
0 | 919 iounmap(dev_conf->regs); |
920 release_mem_region(dev_conf->mmio_start, dev_conf->mmio_len); | |
40
8f30a05cded2
imported patch dmactlalloc
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
37
diff
changeset
|
921 for (i = 0; i < DMA_RING_SIZE; i++) { |
8f30a05cded2
imported patch dmactlalloc
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
37
diff
changeset
|
922 kfree(dev_conf->dmactl[i]); |
8f30a05cded2
imported patch dmactlalloc
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
37
diff
changeset
|
923 } |
0 | 924 kfree(dev_conf); |
925 out_err_regbase: | |
926 return -EIO; | |
927 | |
928 } | |
929 | |
930 static void __devexit pt1_pci_remove_one(struct pci_dev *pdev) | |
931 { | |
932 | |
933 int lp ; | |
934 __u32 val ; | |
935 PT1_DEVICE *dev_conf = (PT1_DEVICE *)pci_get_drvdata(pdev); | |
40
8f30a05cded2
imported patch dmactlalloc
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
37
diff
changeset
|
936 int i; |
0 | 937 |
938 if(dev_conf){ | |
939 if(dev_conf->kthread) { | |
940 kthread_stop(dev_conf->kthread); | |
941 dev_conf->kthread = NULL; | |
942 } | |
943 | |
944 // DMA終了 | |
945 writel(0x08080000, dev_conf->regs); | |
946 for(lp = 0 ; lp < 10 ; lp++){ | |
947 val = readl(dev_conf->regs); | |
948 if(!(val & (1 << 6))){ | |
949 break ; | |
950 } | |
124 | 951 schedule_timeout_interruptible(msecs_to_jiffies(100)); |
0 | 952 } |
953 pt1_dma_free(pdev, dev_conf); | |
954 for(lp = 0 ; lp < MAX_CHANNEL ; lp++){ | |
955 if(dev_conf->channel[lp] != NULL){ | |
956 cdev_del(&dev_conf->cdev[lp]); | |
41
51a006a8d843
imported patch ringbuf-vmalloc
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
40
diff
changeset
|
957 vfree(dev_conf->channel[lp]->buf); |
0 | 958 kfree(dev_conf->channel[lp]); |
959 } | |
31
289794dc265f
adapted to use of multiple number of pt1:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
30
diff
changeset
|
960 device_destroy(pt1video_class, |
289794dc265f
adapted to use of multiple number of pt1:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
30
diff
changeset
|
961 MKDEV(MAJOR(dev_conf->dev), |
289794dc265f
adapted to use of multiple number of pt1:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
30
diff
changeset
|
962 (MINOR(dev_conf->dev) + lp))); |
0 | 963 } |
31
289794dc265f
adapted to use of multiple number of pt1:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
30
diff
changeset
|
964 |
0 | 965 unregister_chrdev_region(dev_conf->dev, MAX_CHANNEL); |
966 writel(0xb0b0000, dev_conf->regs); | |
64
98a92ce5382e
added fake support code for PT2. the PT2 part is not expected to work. be careful!
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
51
diff
changeset
|
967 writel(0, dev_conf->regs + CFG_REGS_ADDR); |
98a92ce5382e
added fake support code for PT2. the PT2 part is not expected to work. be careful!
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
51
diff
changeset
|
968 settuner_reset(dev_conf->regs, dev_conf->cardtype, LNB_OFF, TUNER_POWER_OFF); |
0 | 969 release_mem_region(dev_conf->mmio_start, dev_conf->mmio_len); |
970 iounmap(dev_conf->regs); | |
40
8f30a05cded2
imported patch dmactlalloc
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
37
diff
changeset
|
971 for (i = 0; i < DMA_RING_SIZE; i++) { |
8f30a05cded2
imported patch dmactlalloc
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
37
diff
changeset
|
972 kfree(dev_conf->dmactl[i]); |
8f30a05cded2
imported patch dmactlalloc
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
37
diff
changeset
|
973 } |
31
289794dc265f
adapted to use of multiple number of pt1:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
30
diff
changeset
|
974 device[dev_conf->card_number] = NULL; |
0 | 975 kfree(dev_conf); |
976 } | |
977 pci_set_drvdata(pdev, NULL); | |
978 } | |
979 #ifdef CONFIG_PM | |
980 | |
981 static int pt1_pci_suspend (struct pci_dev *pdev, pm_message_t state) | |
982 { | |
983 return 0; | |
984 } | |
985 | |
986 static int pt1_pci_resume (struct pci_dev *pdev) | |
987 { | |
988 return 0; | |
989 } | |
990 | |
991 #endif /* CONFIG_PM */ | |
992 | |
993 | |
994 static struct pci_driver pt1_driver = { | |
995 .name = DRV_NAME, | |
996 .probe = pt1_pci_init_one, | |
997 .remove = __devexit_p(pt1_pci_remove_one), | |
998 .id_table = pt1_pci_tbl, | |
999 #ifdef CONFIG_PM | |
1000 .suspend = pt1_pci_suspend, | |
1001 .resume = pt1_pci_resume, | |
1002 #endif /* CONFIG_PM */ | |
1003 | |
1004 }; | |
1005 | |
1006 | |
1007 static int __init pt1_pci_init(void) | |
1008 { | |
93 | 1009 printk(KERN_INFO "%s", version); |
9
07b2fc07ff48
updated to current driver to support signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
1010 pt1video_class = class_create(THIS_MODULE, DRIVERNAME); |
07b2fc07ff48
updated to current driver to support signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
1011 if (IS_ERR(pt1video_class)) |
07b2fc07ff48
updated to current driver to support signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
1012 return PTR_ERR(pt1video_class); |
0 | 1013 return pci_register_driver(&pt1_driver); |
1014 } | |
1015 | |
1016 | |
1017 static void __exit pt1_pci_cleanup(void) | |
1018 { | |
120
3914cc1b2375
- adapted to 3.x kernels
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
119
diff
changeset
|
1019 pci_unregister_driver(&pt1_driver); |
9
07b2fc07ff48
updated to current driver to support signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
1020 class_destroy(pt1video_class); |
0 | 1021 } |
1022 | |
1023 module_init(pt1_pci_init); | |
1024 module_exit(pt1_pci_cleanup); |