]> git.karo-electronics.de Git - mv-sheeva.git/blob - drivers/staging/crystalhd/crystalhd_lnx.c
V4L/DVB: tm6000: Add control to the power led
[mv-sheeva.git] / drivers / staging / crystalhd / crystalhd_lnx.c
1 /***************************************************************************
2   BCM70010 Linux driver
3   Copyright (c) 2005-2009, Broadcom Corporation.
4
5   This driver 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, version 2 of the License.
8
9   This driver is distributed in the hope that it will be useful,
10   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   GNU General Public License for more details.
13
14   You should have received a copy of the GNU General Public License
15   along with this driver.  If not, see <http://www.gnu.org/licenses/>.
16 ***************************************************************************/
17
18 #include <linux/smp_lock.h>
19 #include <linux/slab.h>
20
21 #include "crystalhd_lnx.h"
22
23 static struct class *crystalhd_class;
24
25 static struct crystalhd_adp *g_adp_info;
26
27 static irqreturn_t chd_dec_isr(int irq, void *arg)
28 {
29         struct crystalhd_adp *adp = (struct crystalhd_adp *) arg;
30         int rc = 0;
31         if (adp)
32                 rc = crystalhd_cmd_interrupt(&adp->cmds);
33
34         return IRQ_RETVAL(rc);
35 }
36
37 static int chd_dec_enable_int(struct crystalhd_adp *adp)
38 {
39         int rc = 0;
40
41         if (!adp || !adp->pdev) {
42                 BCMLOG_ERR("Invalid arg!!\n");
43                 return -EINVAL;
44         }
45
46         if (adp->pdev->msi_enabled)
47                 adp->msi = 1;
48         else
49                 adp->msi = pci_enable_msi(adp->pdev);
50
51         rc = request_irq(adp->pdev->irq, chd_dec_isr, IRQF_SHARED,
52                          adp->name, (void *)adp);
53         if (rc) {
54                 BCMLOG_ERR("Interrupt request failed..\n");
55                 pci_disable_msi(adp->pdev);
56         }
57
58         return rc;
59 }
60
61 static int chd_dec_disable_int(struct crystalhd_adp *adp)
62 {
63         if (!adp || !adp->pdev) {
64                 BCMLOG_ERR("Invalid arg!!\n");
65                 return -EINVAL;
66         }
67
68         free_irq(adp->pdev->irq, adp);
69
70         if (adp->msi)
71                 pci_disable_msi(adp->pdev);
72
73         return 0;
74 }
75
76 struct crystalhd_ioctl_data *chd_dec_alloc_iodata(struct crystalhd_adp *adp, bool isr)
77 {
78         unsigned long flags = 0;
79         struct crystalhd_ioctl_data *temp;
80
81         if (!adp)
82                 return NULL;
83
84         spin_lock_irqsave(&adp->lock, flags);
85
86         temp = adp->idata_free_head;
87         if (temp) {
88                 adp->idata_free_head = adp->idata_free_head->next;
89                 memset(temp, 0, sizeof(*temp));
90         }
91
92         spin_unlock_irqrestore(&adp->lock, flags);
93         return temp;
94 }
95
96 void chd_dec_free_iodata(struct crystalhd_adp *adp, struct crystalhd_ioctl_data *iodata,
97                          bool isr)
98 {
99         unsigned long flags = 0;
100
101         if (!adp || !iodata)
102                 return;
103
104         spin_lock_irqsave(&adp->lock, flags);
105         iodata->next = adp->idata_free_head;
106         adp->idata_free_head = iodata;
107         spin_unlock_irqrestore(&adp->lock, flags);
108 }
109
110 static inline int crystalhd_user_data(unsigned long ud, void *dr, int size, int set)
111 {
112         int rc;
113
114         if (!ud || !dr) {
115                 BCMLOG_ERR("Invalid arg\n");
116                 return -EINVAL;
117         }
118
119         if (set)
120                 rc = copy_to_user((void *)ud, dr, size);
121         else
122                 rc = copy_from_user(dr, (void *)ud, size);
123
124         if (rc) {
125                 BCMLOG_ERR("Invalid args for command\n");
126                 rc = -EFAULT;
127         }
128
129         return rc;
130 }
131
132 static int chd_dec_fetch_cdata(struct crystalhd_adp *adp, struct crystalhd_ioctl_data *io,
133                                uint32_t m_sz, unsigned long ua)
134 {
135         unsigned long ua_off;
136         int rc = 0;
137
138         if (!adp || !io || !ua || !m_sz) {
139                 BCMLOG_ERR("Invalid Arg!!\n");
140                 return -EINVAL;
141         }
142
143         io->add_cdata = vmalloc(m_sz);
144         if (!io->add_cdata) {
145                 BCMLOG_ERR("kalloc fail for sz:%x\n", m_sz);
146                 return -ENOMEM;
147         }
148
149         io->add_cdata_sz = m_sz;
150         ua_off = ua + sizeof(io->udata);
151         rc = crystalhd_user_data(ua_off, io->add_cdata, io->add_cdata_sz, 0);
152         if (rc) {
153                 BCMLOG_ERR("failed to pull add_cdata sz:%x ua_off:%x\n",
154                            io->add_cdata_sz, (unsigned int)ua_off);
155                 if (io->add_cdata) {
156                         kfree(io->add_cdata);
157                         io->add_cdata = NULL;
158                 }
159                 return -ENODATA;
160         }
161
162         return rc;
163 }
164
165 static int chd_dec_release_cdata(struct crystalhd_adp *adp,
166                                  struct crystalhd_ioctl_data *io, unsigned long ua)
167 {
168         unsigned long ua_off;
169         int rc;
170
171         if (!adp || !io || !ua) {
172                 BCMLOG_ERR("Invalid Arg!!\n");
173                 return -EINVAL;
174         }
175
176         if (io->cmd != BCM_IOC_FW_DOWNLOAD) {
177                 ua_off = ua + sizeof(io->udata);
178                 rc = crystalhd_user_data(ua_off, io->add_cdata,
179                                         io->add_cdata_sz, 1);
180                 if (rc) {
181                         BCMLOG_ERR("failed to push add_cdata sz:%x ua_off:%x\n",
182                                    io->add_cdata_sz, (unsigned int)ua_off);
183                         return -ENODATA;
184                 }
185         }
186
187         if (io->add_cdata) {
188                 vfree(io->add_cdata);
189                 io->add_cdata = NULL;
190         }
191
192         return 0;
193 }
194
195 static int chd_dec_proc_user_data(struct crystalhd_adp *adp,
196                                   struct crystalhd_ioctl_data *io,
197                                   unsigned long ua, int set)
198 {
199         int rc;
200         uint32_t m_sz = 0;
201
202         if (!adp || !io || !ua) {
203                 BCMLOG_ERR("Invalid Arg!!\n");
204                 return -EINVAL;
205         }
206
207         rc = crystalhd_user_data(ua, &io->udata, sizeof(io->udata), set);
208         if (rc) {
209                 BCMLOG_ERR("failed to %s iodata\n", (set ? "set" : "get"));
210                 return rc;
211         }
212
213         switch (io->cmd) {
214         case BCM_IOC_MEM_RD:
215         case BCM_IOC_MEM_WR:
216         case BCM_IOC_FW_DOWNLOAD:
217                 m_sz = io->udata.u.devMem.NumDwords * 4;
218                 if (set)
219                         rc = chd_dec_release_cdata(adp, io, ua);
220                 else
221                         rc = chd_dec_fetch_cdata(adp, io, m_sz, ua);
222                 break;
223         default:
224                 break;
225         }
226
227         return rc;
228 }
229
230 static int chd_dec_api_cmd(struct crystalhd_adp *adp, unsigned long ua,
231                            uint32_t uid, uint32_t cmd, crystalhd_cmd_proc func)
232 {
233         int rc;
234         struct crystalhd_ioctl_data *temp;
235         enum BC_STATUS sts = BC_STS_SUCCESS;
236
237         temp = chd_dec_alloc_iodata(adp, 0);
238         if (!temp) {
239                 BCMLOG_ERR("Failed to get iodata..\n");
240                 return -EINVAL;
241         }
242
243         temp->u_id = uid;
244         temp->cmd  = cmd;
245
246         rc = chd_dec_proc_user_data(adp, temp, ua, 0);
247         if (!rc) {
248                 sts = func(&adp->cmds, temp);
249                 if (sts == BC_STS_PENDING)
250                         sts = BC_STS_NOT_IMPL;
251                 temp->udata.RetSts = sts;
252                 rc = chd_dec_proc_user_data(adp, temp, ua, 1);
253         }
254
255         if (temp) {
256                 chd_dec_free_iodata(adp, temp, 0);
257                 temp = NULL;
258         }
259
260         return rc;
261 }
262
263 /* API interfaces */
264 static long chd_dec_ioctl(struct file *fd, unsigned int cmd, unsigned long ua)
265 {
266         struct crystalhd_adp *adp = chd_get_adp();
267         crystalhd_cmd_proc cproc;
268         struct crystalhd_user *uc;
269         int ret;
270
271         if (!adp || !fd) {
272                 BCMLOG_ERR("Invalid adp\n");
273                 return -EINVAL;
274         }
275
276         uc = (struct crystalhd_user *)fd->private_data;
277         if (!uc) {
278                 BCMLOG_ERR("Failed to get uc\n");
279                 return -ENODATA;
280         }
281
282         lock_kernel();
283         cproc = crystalhd_get_cmd_proc(&adp->cmds, cmd, uc);
284         if (!cproc) {
285                 BCMLOG_ERR("Unhandled command: %d\n", cmd);
286                 unlock_kernel();
287                 return -EINVAL;
288         }
289
290         ret = chd_dec_api_cmd(adp, ua, uc->uid, cmd, cproc);
291         unlock_kernel();
292         return ret;
293 }
294
295 static int chd_dec_open(struct inode *in, struct file *fd)
296 {
297         struct crystalhd_adp *adp = chd_get_adp();
298         int rc = 0;
299         enum BC_STATUS sts = BC_STS_SUCCESS;
300         struct crystalhd_user *uc = NULL;
301
302         BCMLOG_ENTER;
303         if (!adp) {
304                 BCMLOG_ERR("Invalid adp\n");
305                 return -EINVAL;
306         }
307
308         if (adp->cfg_users >= BC_LINK_MAX_OPENS) {
309                 BCMLOG(BCMLOG_INFO, "Already in use.%d\n", adp->cfg_users);
310                 return -EBUSY;
311         }
312
313         sts = crystalhd_user_open(&adp->cmds, &uc);
314         if (sts != BC_STS_SUCCESS) {
315                 BCMLOG_ERR("cmd_user_open - %d\n", sts);
316                 rc = -EBUSY;
317         }
318
319         adp->cfg_users++;
320
321         fd->private_data = uc;
322
323         return rc;
324 }
325
326 static int chd_dec_close(struct inode *in, struct file *fd)
327 {
328         struct crystalhd_adp *adp = chd_get_adp();
329         struct crystalhd_user *uc;
330
331         BCMLOG_ENTER;
332         if (!adp) {
333                 BCMLOG_ERR("Invalid adp\n");
334                 return -EINVAL;
335         }
336
337         uc = (struct crystalhd_user *)fd->private_data;
338         if (!uc) {
339                 BCMLOG_ERR("Failed to get uc\n");
340                 return -ENODATA;
341         }
342
343         crystalhd_user_close(&adp->cmds, uc);
344
345         adp->cfg_users--;
346
347         return 0;
348 }
349
350 static const struct file_operations chd_dec_fops = {
351         .owner   = THIS_MODULE,
352         .unlocked_ioctl = chd_dec_ioctl,
353         .open    = chd_dec_open,
354         .release = chd_dec_close,
355 };
356
357 static int __devinit chd_dec_init_chdev(struct crystalhd_adp *adp)
358 {
359         struct crystalhd_ioctl_data *temp;
360         struct device *dev;
361         int rc = -ENODEV, i = 0;
362
363         if (!adp)
364                 goto fail;
365
366         adp->chd_dec_major = register_chrdev(0, CRYSTALHD_API_NAME,
367                                              &chd_dec_fops);
368         if (adp->chd_dec_major < 0) {
369                 BCMLOG_ERR("Failed to create config dev\n");
370                 rc = adp->chd_dec_major;
371                 goto fail;
372         }
373
374         /* register crystalhd class */
375         crystalhd_class = class_create(THIS_MODULE, "crystalhd");
376         if (IS_ERR(crystalhd_class)) {
377                 BCMLOG_ERR("failed to create class\n");
378                 goto fail;
379         }
380
381         dev = device_create(crystalhd_class, NULL, MKDEV(adp->chd_dec_major, 0),
382                             NULL, "crystalhd");
383         if (IS_ERR(dev)) {
384                 BCMLOG_ERR("failed to create device\n");
385                 goto device_create_fail;
386         }
387
388         rc = crystalhd_create_elem_pool(adp, BC_LINK_ELEM_POOL_SZ);
389         if (rc) {
390                 BCMLOG_ERR("failed to create device\n");
391                 goto elem_pool_fail;
392         }
393
394         /* Allocate general purpose ioctl pool. */
395         for (i = 0; i < CHD_IODATA_POOL_SZ; i++) {
396                 /* FIXME: jarod: why atomic? */
397                 temp = kzalloc(sizeof(struct crystalhd_ioctl_data), GFP_ATOMIC);
398                 if (!temp) {
399                         BCMLOG_ERR("ioctl data pool kzalloc failed\n");
400                         rc = -ENOMEM;
401                         goto kzalloc_fail;
402                 }
403                 /* Add to global pool.. */
404                 chd_dec_free_iodata(adp, temp, 0);
405         }
406
407         return 0;
408
409 kzalloc_fail:
410         crystalhd_delete_elem_pool(adp);
411 elem_pool_fail:
412         device_destroy(crystalhd_class, MKDEV(adp->chd_dec_major, 0));
413 device_create_fail:
414         class_destroy(crystalhd_class);
415 fail:
416         return rc;
417 }
418
419 static void __devexit chd_dec_release_chdev(struct crystalhd_adp *adp)
420 {
421         struct crystalhd_ioctl_data *temp = NULL;
422         if (!adp)
423                 return;
424
425         if (adp->chd_dec_major > 0) {
426                 /* unregister crystalhd class */
427                 device_destroy(crystalhd_class, MKDEV(adp->chd_dec_major, 0));
428                 unregister_chrdev(adp->chd_dec_major, CRYSTALHD_API_NAME);
429                 BCMLOG(BCMLOG_INFO, "released api device - %d\n",
430                        adp->chd_dec_major);
431                 class_destroy(crystalhd_class);
432         }
433         adp->chd_dec_major = 0;
434
435         /* Clear iodata pool.. */
436         do {
437                 temp = chd_dec_alloc_iodata(adp, 0);
438                 if (temp)
439                         kfree(temp);
440         } while (temp);
441
442         crystalhd_delete_elem_pool(adp);
443 }
444
445 static int __devinit chd_pci_reserve_mem(struct crystalhd_adp *pinfo)
446 {
447         int rc;
448         unsigned long bar2 = pci_resource_start(pinfo->pdev, 2);
449         uint32_t mem_len   = pci_resource_len(pinfo->pdev, 2);
450         unsigned long bar0 = pci_resource_start(pinfo->pdev, 0);
451         uint32_t i2o_len   = pci_resource_len(pinfo->pdev, 0);
452
453         BCMLOG(BCMLOG_SSTEP, "bar2:0x%lx-0x%08x  bar0:0x%lx-0x%08x\n",
454                bar2, mem_len, bar0, i2o_len);
455
456         rc = check_mem_region(bar2, mem_len);
457         if (rc) {
458                 BCMLOG_ERR("No valid mem region...\n");
459                 return -ENOMEM;
460         }
461
462         pinfo->addr = ioremap_nocache(bar2, mem_len);
463         if (!pinfo->addr) {
464                 BCMLOG_ERR("Failed to remap mem region...\n");
465                 return -ENOMEM;
466         }
467
468         pinfo->pci_mem_start = bar2;
469         pinfo->pci_mem_len   = mem_len;
470
471         rc = check_mem_region(bar0, i2o_len);
472         if (rc) {
473                 BCMLOG_ERR("No valid mem region...\n");
474                 return -ENOMEM;
475         }
476
477         pinfo->i2o_addr = ioremap_nocache(bar0, i2o_len);
478         if (!pinfo->i2o_addr) {
479                 BCMLOG_ERR("Failed to remap mem region...\n");
480                 return -ENOMEM;
481         }
482
483         pinfo->pci_i2o_start = bar0;
484         pinfo->pci_i2o_len   = i2o_len;
485
486         rc = pci_request_regions(pinfo->pdev, pinfo->name);
487         if (rc < 0) {
488                 BCMLOG_ERR("Region request failed: %d\n", rc);
489                 return rc;
490         }
491
492         BCMLOG(BCMLOG_SSTEP, "Mapped addr:0x%08lx  i2o_addr:0x%08lx\n",
493                (unsigned long)pinfo->addr, (unsigned long)pinfo->i2o_addr);
494
495         return 0;
496 }
497
498 static void __devexit chd_pci_release_mem(struct crystalhd_adp *pinfo)
499 {
500         if (!pinfo)
501                 return;
502
503         if (pinfo->addr)
504                 iounmap(pinfo->addr);
505
506         if (pinfo->i2o_addr)
507                 iounmap(pinfo->i2o_addr);
508
509         pci_release_regions(pinfo->pdev);
510 }
511
512
513 static void __devexit chd_dec_pci_remove(struct pci_dev *pdev)
514 {
515         struct crystalhd_adp *pinfo;
516         enum BC_STATUS sts = BC_STS_SUCCESS;
517
518         BCMLOG_ENTER;
519
520         pinfo = (struct crystalhd_adp *) pci_get_drvdata(pdev);
521         if (!pinfo) {
522                 BCMLOG_ERR("could not get adp\n");
523                 return;
524         }
525
526         sts = crystalhd_delete_cmd_context(&pinfo->cmds);
527         if (sts != BC_STS_SUCCESS)
528                 BCMLOG_ERR("cmd delete :%d\n", sts);
529
530         chd_dec_release_chdev(pinfo);
531
532         chd_dec_disable_int(pinfo);
533
534         chd_pci_release_mem(pinfo);
535         pci_disable_device(pinfo->pdev);
536
537         kfree(pinfo);
538         g_adp_info = NULL;
539 }
540
541 static int __devinit chd_dec_pci_probe(struct pci_dev *pdev,
542                              const struct pci_device_id *entry)
543 {
544         struct crystalhd_adp *pinfo;
545         int rc;
546         enum BC_STATUS sts = BC_STS_SUCCESS;
547
548         BCMLOG(BCMLOG_DBG, "PCI_INFO: Vendor:0x%04x Device:0x%04x "
549                "s_vendor:0x%04x s_device: 0x%04x\n",
550                pdev->vendor, pdev->device, pdev->subsystem_vendor,
551                pdev->subsystem_device);
552
553         /* FIXME: jarod: why atomic? */
554         pinfo = kzalloc(sizeof(struct crystalhd_adp), GFP_ATOMIC);
555         if (!pinfo) {
556                 BCMLOG_ERR("Failed to allocate memory\n");
557                 return -ENOMEM;
558         }
559
560         pinfo->pdev = pdev;
561
562         rc = pci_enable_device(pdev);
563         if (rc) {
564                 BCMLOG_ERR("Failed to enable PCI device\n");
565                 return rc;
566         }
567
568         snprintf(pinfo->name, 31, "crystalhd_pci_e:%d:%d:%d",
569                  pdev->bus->number, PCI_SLOT(pdev->devfn),
570                  PCI_FUNC(pdev->devfn));
571
572         rc = chd_pci_reserve_mem(pinfo);
573         if (rc) {
574                 BCMLOG_ERR("Failed to setup memory regions.\n");
575                 return -ENOMEM;
576         }
577
578         pinfo->present  = 1;
579         pinfo->drv_data = entry->driver_data;
580
581         /* Setup adapter level lock.. */
582         spin_lock_init(&pinfo->lock);
583
584         /* setup api stuff.. */
585         chd_dec_init_chdev(pinfo);
586         rc = chd_dec_enable_int(pinfo);
587         if (rc) {
588                 BCMLOG_ERR("_enable_int err:%d\n", rc);
589                 pci_disable_device(pdev);
590                 return -ENODEV;
591         }
592
593         /* Set dma mask... */
594         if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) {
595                 pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
596                 pinfo->dmabits = 64;
597         } else if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) {
598                 pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
599                 pinfo->dmabits = 32;
600         } else {
601                 BCMLOG_ERR("Unabled to setup DMA %d\n", rc);
602                 pci_disable_device(pdev);
603                 return -ENODEV;
604         }
605
606         sts = crystalhd_setup_cmd_context(&pinfo->cmds, pinfo);
607         if (sts != BC_STS_SUCCESS) {
608                 BCMLOG_ERR("cmd setup :%d\n", sts);
609                 pci_disable_device(pdev);
610                 return -ENODEV;
611         }
612
613         pci_set_master(pdev);
614
615         pci_set_drvdata(pdev, pinfo);
616
617         g_adp_info = pinfo;
618
619         return 0;
620 }
621
622 #ifdef CONFIG_PM
623 int chd_dec_pci_suspend(struct pci_dev *pdev, pm_message_t state)
624 {
625         struct crystalhd_adp *adp;
626         struct crystalhd_ioctl_data *temp;
627         enum BC_STATUS sts = BC_STS_SUCCESS;
628
629         adp = (struct crystalhd_adp *)pci_get_drvdata(pdev);
630         if (!adp) {
631                 BCMLOG_ERR("could not get adp\n");
632                 return -ENODEV;
633         }
634
635         temp = chd_dec_alloc_iodata(adp, false);
636         if (!temp) {
637                 BCMLOG_ERR("could not get ioctl data\n");
638                 return -ENODEV;
639         }
640
641         sts = crystalhd_suspend(&adp->cmds, temp);
642         if (sts != BC_STS_SUCCESS) {
643                 BCMLOG_ERR("BCM70012 Suspend %d\n", sts);
644                 return -ENODEV;
645         }
646
647         chd_dec_free_iodata(adp, temp, false);
648         chd_dec_disable_int(adp);
649         pci_save_state(pdev);
650
651         /* Disable IO/bus master/irq router */
652         pci_disable_device(pdev);
653         pci_set_power_state(pdev, pci_choose_state(pdev, state));
654         return 0;
655 }
656
657 int chd_dec_pci_resume(struct pci_dev *pdev)
658 {
659         struct crystalhd_adp *adp;
660         enum BC_STATUS sts = BC_STS_SUCCESS;
661         int rc;
662
663         adp = (struct crystalhd_adp *)pci_get_drvdata(pdev);
664         if (!adp) {
665                 BCMLOG_ERR("could not get adp\n");
666                 return -ENODEV;
667         }
668
669         pci_set_power_state(pdev, PCI_D0);
670         pci_restore_state(pdev);
671
672         /* device's irq possibly is changed, driver should take care */
673         if (pci_enable_device(pdev)) {
674                 BCMLOG_ERR("Failed to enable PCI device\n");
675                 return 1;
676         }
677
678         pci_set_master(pdev);
679
680         rc = chd_dec_enable_int(adp);
681         if (rc) {
682                 BCMLOG_ERR("_enable_int err:%d\n", rc);
683                 pci_disable_device(pdev);
684                 return -ENODEV;
685         }
686
687         sts = crystalhd_resume(&adp->cmds);
688         if (sts != BC_STS_SUCCESS) {
689                 BCMLOG_ERR("BCM70012 Resume %d\n", sts);
690                 pci_disable_device(pdev);
691                 return -ENODEV;
692         }
693
694         return 0;
695 }
696 #endif
697
698 static DEFINE_PCI_DEVICE_TABLE(chd_dec_pci_id_table) = {
699         { PCI_VDEVICE(BROADCOM, 0x1612), 8 },
700         { 0, },
701 };
702 MODULE_DEVICE_TABLE(pci, chd_dec_pci_id_table);
703
704 static struct pci_driver bc_chd_70012_driver = {
705         .name     = "Broadcom 70012 Decoder",
706         .probe    = chd_dec_pci_probe,
707         .remove   = __devexit_p(chd_dec_pci_remove),
708         .id_table = chd_dec_pci_id_table,
709 #ifdef CONFIG_PM
710         .suspend  = chd_dec_pci_suspend,
711         .resume   = chd_dec_pci_resume
712 #endif
713 };
714
715 void chd_set_log_level(struct crystalhd_adp *adp, char *arg)
716 {
717         if ((!arg) || (strlen(arg) < 3))
718                 g_linklog_level = BCMLOG_ERROR | BCMLOG_DATA;
719         else if (!strncmp(arg, "sstep", 5))
720                 g_linklog_level = BCMLOG_INFO | BCMLOG_DATA | BCMLOG_DBG |
721                                   BCMLOG_SSTEP | BCMLOG_ERROR;
722         else if (!strncmp(arg, "info", 4))
723                 g_linklog_level = BCMLOG_ERROR | BCMLOG_DATA | BCMLOG_INFO;
724         else if (!strncmp(arg, "debug", 5))
725                 g_linklog_level = BCMLOG_ERROR | BCMLOG_DATA | BCMLOG_INFO |
726                                   BCMLOG_DBG;
727         else if (!strncmp(arg, "pball", 5))
728                 g_linklog_level = 0xFFFFFFFF & ~(BCMLOG_SPINLOCK);
729         else if (!strncmp(arg, "silent", 6))
730                 g_linklog_level = 0;
731         else
732                 g_linklog_level = 0;
733 }
734
735 struct crystalhd_adp *chd_get_adp(void)
736 {
737         return g_adp_info;
738 }
739
740 static int __init chd_dec_module_init(void)
741 {
742         int rc;
743
744         chd_set_log_level(NULL, "debug");
745         BCMLOG(BCMLOG_DATA, "Loading crystalhd %d.%d.%d\n",
746                crystalhd_kmod_major, crystalhd_kmod_minor, crystalhd_kmod_rev);
747
748         rc = pci_register_driver(&bc_chd_70012_driver);
749
750         if (rc < 0)
751                 BCMLOG_ERR("Could not find any devices. err:%d\n", rc);
752
753         return rc;
754 }
755 module_init(chd_dec_module_init);
756
757 static void __exit chd_dec_module_cleanup(void)
758 {
759         BCMLOG(BCMLOG_DATA, "unloading crystalhd %d.%d.%d\n",
760                crystalhd_kmod_major, crystalhd_kmod_minor, crystalhd_kmod_rev);
761
762         pci_unregister_driver(&bc_chd_70012_driver);
763 }
764 module_exit(chd_dec_module_cleanup);
765
766 MODULE_AUTHOR("Naren Sankar <nsankar@broadcom.com>");
767 MODULE_AUTHOR("Prasad Bolisetty <prasadb@broadcom.com>");
768 MODULE_DESCRIPTION(CRYSTAL_HD_NAME);
769 MODULE_LICENSE("GPL");
770 MODULE_ALIAS("bcm70012");