1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18#include "cthardware.h"
19#include "cthw20k1.h"
20#include "cthw20k2.h"
21#include <linux/bug.h>
22
23int create_hw_obj(struct pci_dev *pci, enum CHIPTYP chip_type,
24 enum CTCARDS model, struct hw **rhw)
25{
26 int err;
27
28 switch (chip_type) {
29 case ATC20K1:
30 err = create_20k1_hw_obj(rhw);
31 break;
32 case ATC20K2:
33 err = create_20k2_hw_obj(rhw);
34 break;
35 default:
36 err = -ENODEV;
37 break;
38 }
39 if (err)
40 return err;
41
42 (*rhw)->pci = pci;
43 (*rhw)->chip_type = chip_type;
44 (*rhw)->model = model;
45
46 return 0;
47}
48
49int destroy_hw_obj(struct hw *hw)
50{
51 int err;
52
53 switch (hw->pci->device) {
54 case 0x0005:
55 err = destroy_20k1_hw_obj(hw);
56 break;
57 case 0x000B:
58 err = destroy_20k2_hw_obj(hw);
59 break;
60 default:
61 err = -ENODEV;
62 break;
63 }
64
65 return err;
66}
67
68unsigned int get_field(unsigned int data, unsigned int field)
69{
70 int i;
71
72 if (WARN_ON(!field))
73 return 0;
74
75 for (i = 0; !(field & (1 << i)); )
76 i++;
77
78 return (data & field) >> i;
79}
80
81void set_field(unsigned int *data, unsigned int field, unsigned int value)
82{
83 int i;
84
85 if (WARN_ON(!field))
86 return;
87
88 for (i = 0; !(field & (1 << i)); )
89 i++;
90
91 *data = (*data & (~field)) | ((value << i) & field);
92}
93
94