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