cthardware.c 1.7 KB

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