2 * Copyright (C) 2010 Bluecherry, LLC www.bluecherrydvr.com
3 * Copyright (C) 2010 Ben Collins <bcollins@bluecherry.net>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 #include <linux/kernel.h>
21 #include <linux/module.h>
22 #include <linux/pci.h>
23 #include <linux/interrupt.h>
24 #include <linux/videodev2.h>
27 #include "solo6010-tw28.h"
29 MODULE_DESCRIPTION("Softlogic 6010 MP4 Encoder/Decoder V4L2/ALSA Driver");
30 MODULE_AUTHOR("Ben Collins <bcollins@bluecherry.net>");
31 MODULE_VERSION(SOLO6010_VERSION
);
32 MODULE_LICENSE("GPL");
34 void solo6010_irq_on(struct solo6010_dev
*solo_dev
, u32 mask
)
36 solo_dev
->irq_mask
|= mask
;
37 solo_reg_write(solo_dev
, SOLO_IRQ_ENABLE
, solo_dev
->irq_mask
);
40 void solo6010_irq_off(struct solo6010_dev
*solo_dev
, u32 mask
)
42 solo_dev
->irq_mask
&= ~mask
;
43 solo_reg_write(solo_dev
, SOLO_IRQ_ENABLE
, solo_dev
->irq_mask
);
46 /* XXX We should check the return value of the sub-device ISR's */
47 static irqreturn_t
solo6010_isr(int irq
, void *data
)
49 struct solo6010_dev
*solo_dev
= data
;
53 status
= solo_reg_read(solo_dev
, SOLO_IRQ_STAT
);
57 if (status
& ~solo_dev
->irq_mask
) {
58 solo_reg_write(solo_dev
, SOLO_IRQ_STAT
,
59 status
& ~solo_dev
->irq_mask
);
60 status
&= solo_dev
->irq_mask
;
63 if (status
& SOLO_IRQ_PCI_ERR
) {
64 u32 err
= solo_reg_read(solo_dev
, SOLO_PCI_ERR
);
65 solo_p2m_error_isr(solo_dev
, err
);
66 solo_reg_write(solo_dev
, SOLO_IRQ_STAT
, SOLO_IRQ_PCI_ERR
);
69 for (i
= 0; i
< SOLO_NR_P2M
; i
++)
70 if (status
& SOLO_IRQ_P2M(i
))
71 solo_p2m_isr(solo_dev
, i
);
73 if (status
& SOLO_IRQ_IIC
)
74 solo_i2c_isr(solo_dev
);
76 if (status
& SOLO_IRQ_VIDEO_IN
)
77 solo_video_in_isr(solo_dev
);
79 /* Call this first so enc gets detected flag set */
80 if (status
& SOLO_IRQ_MOTION
)
81 solo_motion_isr(solo_dev
);
83 if (status
& SOLO_IRQ_ENCODER
)
84 solo_enc_v4l2_isr(solo_dev
);
86 if (status
& SOLO_IRQ_G723
)
87 solo_g723_isr(solo_dev
);
92 static void free_solo_dev(struct solo6010_dev
*solo_dev
)
99 pdev
= solo_dev
->pdev
;
101 /* If we never initialized the PCI device, then nothing else
102 * below here needs cleanup */
108 /* Bring down the sub-devices first */
109 solo_g723_exit(solo_dev
);
110 solo_enc_v4l2_exit(solo_dev
);
111 solo_enc_exit(solo_dev
);
112 solo_v4l2_exit(solo_dev
);
113 solo_disp_exit(solo_dev
);
114 solo_gpio_exit(solo_dev
);
115 solo_p2m_exit(solo_dev
);
116 solo_i2c_exit(solo_dev
);
118 /* Now cleanup the PCI device */
119 if (solo_dev
->reg_base
) {
120 solo6010_irq_off(solo_dev
, ~0);
121 pci_iounmap(pdev
, solo_dev
->reg_base
);
122 free_irq(pdev
->irq
, solo_dev
);
125 pci_release_regions(pdev
);
126 pci_disable_device(pdev
);
127 pci_set_drvdata(pdev
, NULL
);
132 static int __devinit
solo6010_pci_probe(struct pci_dev
*pdev
,
133 const struct pci_device_id
*id
)
135 struct solo6010_dev
*solo_dev
;
139 solo_dev
= kzalloc(sizeof(*solo_dev
), GFP_KERNEL
);
140 if (solo_dev
== NULL
)
143 solo_dev
->pdev
= pdev
;
144 spin_lock_init(&solo_dev
->reg_io_lock
);
145 pci_set_drvdata(pdev
, solo_dev
);
147 ret
= pci_enable_device(pdev
);
151 pci_set_master(pdev
);
153 ret
= pci_request_regions(pdev
, SOLO6010_NAME
);
157 solo_dev
->reg_base
= pci_ioremap_bar(pdev
, 0);
158 if (solo_dev
->reg_base
== NULL
) {
163 chip_id
= solo_reg_read(solo_dev
, SOLO_CHIP_OPTION
) &
167 solo_dev
->nr_chans
= 16;
168 solo_dev
->nr_ext
= 5;
171 solo_dev
->nr_chans
= 8;
172 solo_dev
->nr_ext
= 2;
175 dev_warn(&pdev
->dev
, "Invalid chip_id 0x%02x, "
176 "defaulting to 4 channels\n",
179 solo_dev
->nr_chans
= 4;
180 solo_dev
->nr_ext
= 1;
183 /* Disable all interrupts to start */
184 solo6010_irq_off(solo_dev
, ~0);
186 /* Initial global settings */
187 solo_reg_write(solo_dev
, SOLO_SYS_CFG
, SOLO_SYS_CFG_SDRAM64BIT
|
188 SOLO_SYS_CFG_INPUTDIV(25) |
189 SOLO_SYS_CFG_FEEDBACKDIV((SOLO_CLOCK_MHZ
* 2) - 2) |
190 SOLO_SYS_CFG_OUTDIV(3));
191 solo_reg_write(solo_dev
, SOLO_TIMER_CLOCK_NUM
, SOLO_CLOCK_MHZ
- 1);
193 /* PLL locking time of 1ms */
196 ret
= request_irq(pdev
->irq
, solo6010_isr
, IRQF_SHARED
, SOLO6010_NAME
,
201 /* Handle this from the start */
202 solo6010_irq_on(solo_dev
, SOLO_IRQ_PCI_ERR
);
204 ret
= solo_i2c_init(solo_dev
);
208 /* Setup the DMA engine */
209 sdram
= (solo_dev
->nr_chans
>= 8) ? 2 : 1;
210 solo_reg_write(solo_dev
, SOLO_DMA_CTRL
,
211 SOLO_DMA_CTRL_REFRESH_CYCLE(1) |
212 SOLO_DMA_CTRL_SDRAM_SIZE(sdram
) |
213 SOLO_DMA_CTRL_SDRAM_CLK_INVERT
|
214 SOLO_DMA_CTRL_READ_CLK_SELECT
|
215 SOLO_DMA_CTRL_LATENCY(1));
217 ret
= solo_p2m_init(solo_dev
);
221 ret
= solo_disp_init(solo_dev
);
225 ret
= solo_gpio_init(solo_dev
);
229 ret
= solo_tw28_init(solo_dev
);
233 ret
= solo_v4l2_init(solo_dev
);
237 ret
= solo_enc_init(solo_dev
);
241 ret
= solo_enc_v4l2_init(solo_dev
);
245 ret
= solo_g723_init(solo_dev
);
252 free_solo_dev(solo_dev
);
256 static void __devexit
solo6010_pci_remove(struct pci_dev
*pdev
)
258 struct solo6010_dev
*solo_dev
= pci_get_drvdata(pdev
);
260 free_solo_dev(solo_dev
);
263 static struct pci_device_id solo6010_id_table
[] = {
264 {PCI_DEVICE(PCI_VENDOR_ID_SOFTLOGIC
, PCI_DEVICE_ID_SOLO6010
)},
265 {PCI_DEVICE(PCI_VENDOR_ID_BLUECHERRY
, PCI_DEVICE_ID_NEUSOLO_4
)},
266 {PCI_DEVICE(PCI_VENDOR_ID_BLUECHERRY
, PCI_DEVICE_ID_NEUSOLO_9
)},
267 {PCI_DEVICE(PCI_VENDOR_ID_BLUECHERRY
, PCI_DEVICE_ID_NEUSOLO_16
)},
268 {PCI_DEVICE(PCI_VENDOR_ID_BLUECHERRY
, PCI_DEVICE_ID_COMMSOLO_4
)},
269 {PCI_DEVICE(PCI_VENDOR_ID_BLUECHERRY
, PCI_DEVICE_ID_COMMSOLO_9
)},
270 {PCI_DEVICE(PCI_VENDOR_ID_BLUECHERRY
, PCI_DEVICE_ID_COMMSOLO_16
)},
274 MODULE_DEVICE_TABLE(pci
, solo6010_id_table
);
276 static struct pci_driver solo6010_pci_driver
= {
277 .name
= SOLO6010_NAME
,
278 .id_table
= solo6010_id_table
,
279 .probe
= solo6010_pci_probe
,
280 .remove
= solo6010_pci_remove
,
283 static int __init
solo6010_module_init(void)
285 return pci_register_driver(&solo6010_pci_driver
);
288 static void __exit
solo6010_module_exit(void)
290 pci_unregister_driver(&solo6010_pci_driver
);
293 module_init(solo6010_module_init
);
294 module_exit(solo6010_module_exit
);