module.c
上传用户:aoeyumen
上传日期:2007-01-06
资源大小:3329k
文件大小:4k
源码类别:

DVD

开发平台:

Unix_Linux

  1. /*
  2.   **********************************************************************
  3.   *
  4.   *     Copyright 1999, 2000 Creative Labs, Inc.
  5.   *
  6.   **********************************************************************
  7.   *
  8.   *     Date                 Author               Summary of changes
  9.   *     ----                 ------               ------------------
  10.   *     October 20, 1999     Andrew de Quincey    Rewrote and extended
  11.   *                          Lucien Murray-Pitts  original incomplete 
  12.   *                                               driver.
  13.   *
  14.   *     April 18, 1999       Andrew Veliath       Original Driver
  15.   *                                               implementation
  16.   *
  17.   **********************************************************************
  18.   *
  19.   *     This program is free software; you can redistribute it and/or
  20.   *     modify it under the terms of the GNU General Public License as
  21.   *     published by the Free Software Foundation; either version 2 of
  22.   *     the License, or (at your option) any later version.
  23.   *
  24.   *     This program is distributed in the hope that it will be useful,
  25.   *     but WITHOUT ANY WARRANTY; without even the implied warranty of
  26.   *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  27.   *     GNU General Public License for more details.
  28.   *
  29.   *     You should have received a copy of the GNU General Public
  30.   *     License along with this program; if not, write to the Free
  31.   *     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
  32.   *     USA.
  33.   *
  34.   **********************************************************************
  35.   */
  36. /**
  37.  *
  38.  * Driver for the Burr-Brown PCM1723 DAC
  39.  * Driver maintenance functions
  40.  *
  41.  */
  42. #define EXPORT_SYMTAB
  43. #include <linux/config.h>
  44. #undef MODVERSION
  45. #undef CONFIG_MODVERSIONS
  46. #include <linux/version.h>
  47. #include <linux/module.h>
  48. #include <linux/kernel.h>
  49. #include <linux/sched.h>
  50. #include <linux/string.h>
  51. #include <linux/ptrace.h>
  52. #include <linux/errno.h>
  53. #include <linux/ioport.h>
  54. #include <linux/malloc.h>
  55. #include <linux/interrupt.h>
  56. #include <linux/pci.h>
  57. #include <linux/delay.h>
  58. #include <linux/init.h>
  59. #include <linux/pci.h>
  60. #include <linux/cdrom.h>
  61. #include <linux/videodev.h>
  62. #include <asm/byteorder.h>
  63. #include <asm/bitops.h>
  64. #include <asm/io.h>
  65. #include <asm/irq.h>
  66. #include <asm/uaccess.h>
  67. #include <asm/spinlock.h>
  68. #include <pcm1723.h>
  69. /**
  70.  *
  71.  * Create new pcm1723 driver instance
  72.  *
  73.  * @param ops Lowlevel operations to talk to chip
  74.  * @param data Any extra data for said functions
  75.  *
  76.  * @return new instance (or NULL on error)
  77.  *
  78.  */
  79. extern pcm1723_t* pcm1723_new (pcm1723_ops_t* ops, void* data)
  80. {
  81.   pcm1723_t* instance;
  82.   int val;
  83.   int i;
  84.   
  85.   // validate supplied ops
  86.   if (ops == NULL)
  87.     return NULL;
  88.   
  89.   // allocate
  90.   instance = (pcm1723_t*) vmalloc (sizeof (pcm1723_t));
  91.   if (!instance)
  92.     return NULL;
  93.   
  94.   // setup
  95.   instance->ops = ops;
  96.   instance->data = data;
  97.   // zero the registerValues
  98.   for(i=0; i < PCM1723_REGISTERCOUNT; i++) {
  99.     instance->registerValues[i] = 0;
  100.   }
  101.   
  102.   // initialise the device
  103.   if (pcm1723_init(instance) < 0) {
  104.     
  105.     printk (KERN_INFO PCM1723_LOGNAME ": [%s] Cannot initialise pcm1723.n",
  106.     instance->ops->name);
  107.     vfree(instance);
  108.     return(NULL);
  109.   }
  110.   
  111.   // ok, module has one more usage
  112.   MOD_INC_USE_COUNT;
  113.   // log creation
  114.   printk (KERN_INFO PCM1723_LOGNAME "(%s): instance created.n", 
  115.   instance->ops->name);
  116.   
  117.   // return it!
  118.   return(instance);
  119. }
  120. /**
  121.  *
  122.  * Destroy a Pcm1723 driver instance
  123.  *
  124.  * @param instance The instance to destroy
  125.  *
  126.  */
  127. extern void pcm1723_free (pcm1723_t* instance)
  128. {
  129.   char* tmpName = instance->ops->name;
  130.   // free instance
  131.   vfree (instance);
  132.   // one less usage of module
  133.   MOD_DEC_USE_COUNT;
  134.   // log destruction
  135.   printk (KERN_INFO PCM1723_LOGNAME ": [%s] instance destroyed.n", 
  136.   tmpName);
  137. }
  138. #ifdef MODULE
  139. int init_module(void)
  140. {
  141.   return(0);
  142. }
  143. void cleanup_module(void)
  144. {
  145. }
  146. #endif
  147. EXPORT_SYMBOL(pcm1723_new);
  148. EXPORT_SYMBOL(pcm1723_free);
  149. EXPORT_SYMBOL(pcm1723_init);
  150. EXPORT_SYMBOL(pcm1723_set_sample_frequency);
  151. EXPORT_SYMBOL(pcm1723_set_input_width);
  152. EXPORT_SYMBOL(pcm1723_set_mute_mode);
  153. EXPORT_SYMBOL(pcm1723_set_stereo_mode);
  154. EXPORT_SYMBOL(pcm1723_set_clock_frequency);
  155. EXPORT_SYMBOL(pcm1723_get_reg);
  156. EXPORT_SYMBOL(pcm1723_set_reg);
  157. EXPORT_SYMBOL(pcm1723_get_bits);
  158. EXPORT_SYMBOL(pcm1723_set_bits);