lm7000.h 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #ifndef __LM7000_H
  2. #define __LM7000_H
  3. /* Sanyo LM7000 tuner chip control
  4. *
  5. * Copyright 2012 Ondrej Zary <linux@rainbow-software.org>
  6. * based on radio-aimslab.c by M. Kirkwood
  7. * and radio-sf16fmi.c by M. Kirkwood and Petr Vandrovec
  8. */
  9. #define LM7000_DATA (1 << 0)
  10. #define LM7000_CLK (1 << 1)
  11. #define LM7000_CE (1 << 2)
  12. #define LM7000_FM_100 (0 << 20)
  13. #define LM7000_FM_50 (1 << 20)
  14. #define LM7000_FM_25 (2 << 20)
  15. #define LM7000_BIT_FM (1 << 23)
  16. static inline void lm7000_set_freq(u32 freq, void *handle,
  17. void (*set_pins)(void *handle, u8 pins))
  18. {
  19. int i;
  20. u8 data;
  21. u32 val;
  22. freq += 171200; /* Add 10.7 MHz IF */
  23. freq /= 400; /* Convert to 25 kHz units */
  24. val = freq | LM7000_FM_25 | LM7000_BIT_FM;
  25. /* write the 24-bit register, starting with LSB */
  26. for (i = 0; i < 24; i++) {
  27. data = val & (1 << i) ? LM7000_DATA : 0;
  28. set_pins(handle, data | LM7000_CE);
  29. udelay(2);
  30. set_pins(handle, data | LM7000_CE | LM7000_CLK);
  31. udelay(2);
  32. set_pins(handle, data | LM7000_CE);
  33. udelay(2);
  34. }
  35. set_pins(handle, 0);
  36. }
  37. #endif /* __LM7000_H */