cthardware.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 __devinit 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. BUG_ON(!field);
  63. /* @field should always be greater than 0 */
  64. for (i = 0; !(field & (1 << i)); )
  65. i++;
  66. return (data & field) >> i;
  67. }
  68. void set_field(unsigned int *data, unsigned int field, unsigned int value)
  69. {
  70. int i;
  71. BUG_ON(!field);
  72. /* @field should always be greater than 0 */
  73. for (i = 0; !(field & (1 << i)); )
  74. i++;
  75. *data = (*data & (~field)) | ((value << i) & field);
  76. }