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