lowlevel.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.  * Register get/set functions
  40.  *
  41.  */
  42. #include <linux/types.h>
  43. #include <linux/errno.h>
  44. #include <pcm1723.h>
  45. /**
  46.  *
  47.  * Get register from the PCM1723
  48.  *
  49.  * @param instance Instance of the PCM1723 to use
  50.  * @param reg Register to retrieve
  51.  *
  52.  * @return the value, or <0 on error
  53.  *
  54.  */
  55. extern int pcm1723_get_reg(pcm1723_t* instance, int reg)
  56. {
  57.   // check params
  58.   if ((reg < 0) || (reg >= PCM1723_REGISTERCOUNT)) {
  59.     
  60.     return(-EINVAL);
  61.   }
  62.   // retrieve it from the instance buffer (PCM1723 is WRITE ONLY)
  63.   return(instance->registerValues[reg] & 0x1ff);
  64. }
  65. /**
  66.  *
  67.  * Set register on the PCM1723
  68.  *
  69.  * @param instance Instance of the PCM1723 to use
  70.  * @param reg Register to retrieve
  71.  * @param val Value to set
  72.  *
  73.  * @return 0 on success, or <0 on error
  74.  *
  75.  */
  76. extern int pcm1723_set_reg(pcm1723_t* instance, int reg, int val)
  77. {
  78.   // check params
  79.   if ((reg < 0) || (reg >= PCM1723_REGISTERCOUNT)) {
  80.     
  81.     return(-EINVAL);
  82.   }
  83.   // remember the register value for later (PCM1723 is WRITE ONLY)
  84.   instance->registerValues[reg] = val & 0x1ff;
  85.   
  86.   // set it on the actual hardware
  87.   return((*instance->ops->set_reg) (instance, ((reg & 3) << 9) | (val & 0x1ff)));
  88. }
  89. /**
  90.  *
  91.  * Get specified bitmask of a register from PCM1723
  92.  *
  93.  * @param instance Instance of the PCM1723 to use
  94.  * @param reg Register to retrieve
  95.  * @param bitmask Bitmask of bits to retrive from that register
  96.  *
  97.  * @return The register bitvalues, or <0 on error
  98.  *
  99.  */
  100. extern int pcm1723_get_bits(pcm1723_t* instance, int reg, int bitmask)
  101. {
  102.   return (pcm1723_get_reg(instance, reg) & bitmask);
  103. }
  104. /**
  105.  *
  106.  * Set specified bits of a register on PCM1723
  107.  *
  108.  * @param instance Instance of the PCM1723 to use
  109.  * @param reg Register to retrieve
  110.  * @param bitmask Bitmask of bits to set from that register
  111.  * @param valuemask Values of the bits in the bitmask
  112.  *
  113.  * @return 0 on success, or <0 on error
  114.  *
  115.  */
  116. extern int pcm1723_set_bits(pcm1723_t* instance, int reg, int bitmask, int valuemask)
  117. {
  118.   int value;
  119.   // get the current register value
  120.   if ((value = pcm1723_get_reg(instance, reg)) < 0) {
  121.     
  122.     return(-EINVAL);
  123.   }
  124.   
  125.   // set it on the hardware
  126.   return(pcm1723_set_reg(instance, reg, (value & (~bitmask)) | valuemask));
  127. }