Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * Copyright (C) 2008, Creative Technology Ltd. All Rights Reserved.
0004  *
0005  * @File    cthardware.c
0006  *
0007  * @Brief
0008  * This file contains the implementation of hardware access methord.
0009  *
0010  * @Author  Liu Chun
0011  * @Date    Jun 26 2008
0012  */
0013 
0014 #include "cthardware.h"
0015 #include "cthw20k1.h"
0016 #include "cthw20k2.h"
0017 #include <linux/bug.h>
0018 
0019 int create_hw_obj(struct pci_dev *pci, enum CHIPTYP chip_type,
0020           enum CTCARDS model, struct hw **rhw)
0021 {
0022     int err;
0023 
0024     switch (chip_type) {
0025     case ATC20K1:
0026         err = create_20k1_hw_obj(rhw);
0027         break;
0028     case ATC20K2:
0029         err = create_20k2_hw_obj(rhw);
0030         break;
0031     default:
0032         err = -ENODEV;
0033         break;
0034     }
0035     if (err)
0036         return err;
0037 
0038     (*rhw)->pci = pci;
0039     (*rhw)->chip_type = chip_type;
0040     (*rhw)->model = model;
0041 
0042     return 0;
0043 }
0044 
0045 int destroy_hw_obj(struct hw *hw)
0046 {
0047     int err;
0048 
0049     switch (hw->pci->device) {
0050     case 0x0005:    /* 20k1 device */
0051         err = destroy_20k1_hw_obj(hw);
0052         break;
0053     case 0x000B:    /* 20k2 device */
0054         err = destroy_20k2_hw_obj(hw);
0055         break;
0056     default:
0057         err = -ENODEV;
0058         break;
0059     }
0060 
0061     return err;
0062 }
0063 
0064 unsigned int get_field(unsigned int data, unsigned int field)
0065 {
0066     int i;
0067 
0068     if (WARN_ON(!field))
0069         return 0;
0070     /* @field should always be greater than 0 */
0071     for (i = 0; !(field & (1 << i)); )
0072         i++;
0073 
0074     return (data & field) >> i;
0075 }
0076 
0077 void set_field(unsigned int *data, unsigned int field, unsigned int value)
0078 {
0079     int i;
0080 
0081     if (WARN_ON(!field))
0082         return;
0083     /* @field should always be greater than 0 */
0084     for (i = 0; !(field & (1 << i)); )
0085         i++;
0086 
0087     *data = (*data & (~field)) | ((value << i) & field);
0088 }
0089