blob: a689f255270641ab21f17474e8dbfe8ced37ae19 [file] [log] [blame]
Wai Yew CHAY8cc72362009-05-14 08:05:58 +02001/**
2 * Copyright (C) 2008, Creative Technology Ltd. All Rights Reserved.
3 *
4 * This source file is released under GPL v2 license (no other versions).
5 * See the COPYING file included in the main directory of this source
6 * distribution for the license terms and conditions.
7 *
8 * @File cthardware.c
9 *
10 * @Brief
11 * This file contains the implementation of hardware access methord.
12 *
13 * @Author Liu Chun
14 * @Date Jun 26 2008
15 *
16 */
17
18#include "cthardware.h"
19#include "cthw20k1.h"
20#include "cthw20k2.h"
21#include <linux/bug.h>
22
Bill Pembertone23e7a12012-12-06 12:35:10 -050023int create_hw_obj(struct pci_dev *pci, enum CHIPTYP chip_type,
24 enum CTCARDS model, struct hw **rhw)
Wai Yew CHAY8cc72362009-05-14 08:05:58 +020025{
Takashi Iwai514eef92009-06-08 14:57:57 +020026 int err;
Wai Yew CHAY8cc72362009-05-14 08:05:58 +020027
Takashi Iwai94701952009-06-08 18:10:32 +020028 switch (chip_type) {
29 case ATC20K1:
Wai Yew CHAY8cc72362009-05-14 08:05:58 +020030 err = create_20k1_hw_obj(rhw);
31 break;
Takashi Iwai94701952009-06-08 18:10:32 +020032 case ATC20K2:
Wai Yew CHAY8cc72362009-05-14 08:05:58 +020033 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;
Takashi Iwai94701952009-06-08 18:10:32 +020043 (*rhw)->chip_type = chip_type;
44 (*rhw)->model = model;
Wai Yew CHAY8cc72362009-05-14 08:05:58 +020045
46 return 0;
47}
48
49int destroy_hw_obj(struct hw *hw)
50{
Takashi Iwai514eef92009-06-08 14:57:57 +020051 int err;
Wai Yew CHAY8cc72362009-05-14 08:05:58 +020052
53 switch (hw->pci->device) {
54 case 0x0005: /* 20k1 device */
55 err = destroy_20k1_hw_obj(hw);
56 break;
57 case 0x000B: /* 20k2 device */
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
Takashi Iwai29fa9572013-11-05 15:00:02 +010072 if (WARN_ON(!field))
73 return 0;
Wai Yew CHAY8cc72362009-05-14 08:05:58 +020074 /* @field should always be greater than 0 */
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
Takashi Iwai29fa9572013-11-05 15:00:02 +010085 if (WARN_ON(!field))
86 return;
Wai Yew CHAY8cc72362009-05-14 08:05:58 +020087 /* @field should always be greater than 0 */
88 for (i = 0; !(field & (1 << i)); )
89 i++;
90
91 *data = (*data & (~field)) | ((value << i) & field);
92}
93