cthardware.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. #include "cthardware.h"
  14. #include "cthw20k1.h"
  15. #include "cthw20k2.h"
  16. #include <linux/bug.h>
  17. int create_hw_obj(struct pci_dev *pci, enum CHIPTYP chip_type,
  18. enum CTCARDS model, struct hw **rhw)
  19. {
  20. int err;
  21. switch (chip_type) {
  22. case ATC20K1:
  23. err = create_20k1_hw_obj(rhw);
  24. break;
  25. case ATC20K2:
  26. err = create_20k2_hw_obj(rhw);
  27. break;
  28. default:
  29. err = -ENODEV;
  30. break;
  31. }
  32. if (err)
  33. return err;
  34. (*rhw)->pci = pci;
  35. (*rhw)->chip_type = chip_type;
  36. (*rhw)->model = model;
  37. return 0;
  38. }
  39. int destroy_hw_obj(struct hw *hw)
  40. {
  41. int err;
  42. switch (hw->pci->device) {
  43. case 0x0005: /* 20k1 device */
  44. err = destroy_20k1_hw_obj(hw);
  45. break;
  46. case 0x000B: /* 20k2 device */
  47. err = destroy_20k2_hw_obj(hw);
  48. break;
  49. default:
  50. err = -ENODEV;
  51. break;
  52. }
  53. return err;
  54. }
  55. unsigned int get_field(unsigned int data, unsigned int field)
  56. {
  57. int i;
  58. if (WARN_ON(!field))
  59. return 0;
  60. /* @field should always be greater than 0 */
  61. for (i = 0; !(field & (1 << i)); )
  62. i++;
  63. return (data & field) >> i;
  64. }
  65. void set_field(unsigned int *data, unsigned int field, unsigned int value)
  66. {
  67. int i;
  68. if (WARN_ON(!field))
  69. return;
  70. /* @field should always be greater than 0 */
  71. for (i = 0; !(field & (1 << i)); )
  72. i++;
  73. *data = (*data & (~field)) | ((value << i) & field);
  74. }