Linux Audio

Check our new training course

Loading...
v5.9
 1// SPDX-License-Identifier: GPL-2.0-only
 2/*
 3 * Copyright (C) 2008, Creative Technology Ltd. All Rights Reserved.
 4 *
 
 
 
 
 5 * @File	cthardware.c
 6 *
 7 * @Brief
 8 * This file contains the implementation of hardware access methord.
 9 *
10 * @Author	Liu Chun
11 * @Date 	Jun 26 2008
 
12 */
13
14#include "cthardware.h"
15#include "cthw20k1.h"
16#include "cthw20k2.h"
17#include <linux/bug.h>
18
19int create_hw_obj(struct pci_dev *pci, enum CHIPTYP chip_type,
20		  enum CTCARDS model, struct hw **rhw)
21{
22	int err;
23
24	switch (chip_type) {
25	case ATC20K1:
26		err = create_20k1_hw_obj(rhw);
27		break;
28	case ATC20K2:
29		err = create_20k2_hw_obj(rhw);
30		break;
31	default:
32		err = -ENODEV;
33		break;
34	}
35	if (err)
36		return err;
37
38	(*rhw)->pci = pci;
39	(*rhw)->chip_type = chip_type;
40	(*rhw)->model = model;
41
42	return 0;
43}
44
45int destroy_hw_obj(struct hw *hw)
46{
47	int err;
48
49	switch (hw->pci->device) {
50	case 0x0005:	/* 20k1 device */
51		err = destroy_20k1_hw_obj(hw);
52		break;
53	case 0x000B:	/* 20k2 device */
54		err = destroy_20k2_hw_obj(hw);
55		break;
56	default:
57		err = -ENODEV;
58		break;
59	}
60
61	return err;
62}
63
64unsigned int get_field(unsigned int data, unsigned int field)
65{
66	int i;
67
68	if (WARN_ON(!field))
69		return 0;
70	/* @field should always be greater than 0 */
71	for (i = 0; !(field & (1 << i)); )
72		i++;
73
74	return (data & field) >> i;
75}
76
77void set_field(unsigned int *data, unsigned int field, unsigned int value)
78{
79	int i;
80
81	if (WARN_ON(!field))
82		return;
83	/* @field should always be greater than 0 */
84	for (i = 0; !(field & (1 << i)); )
85		i++;
86
87	*data = (*data & (~field)) | ((value << i) & field);
88}
89
v3.5.6
 1/**
 
 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
23int __devinit 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:	/* 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
72	BUG_ON(!field);
 
73	/* @field should always be greater than 0 */
74	for (i = 0; !(field & (1 << i)); )
75		i++;
76
77	return (data & field) >> i;
78}
79
80void set_field(unsigned int *data, unsigned int field, unsigned int value)
81{
82	int i;
83
84	BUG_ON(!field);
 
85	/* @field should always be greater than 0 */
86	for (i = 0; !(field & (1 << i)); )
87		i++;
88
89	*data = (*data & (~field)) | ((value << i) & field);
90}
91