Version:  2.0.40 2.2.26 2.4.37 3.0 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 3.10 3.11 3.12 3.13 3.14 3.15 3.16

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

This page was automatically generated by LXR 0.3.1 (source).  •  Linux is a registered trademark of Linus Torvalds  •  Contact us