tuner-i2c.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. tuner-i2c.h - i2c interface for different tuners
  3. Copyright (C) 2007 Michael Krufky (mkrufky@linuxtv.org)
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. */
  16. #ifndef __TUNER_I2C_H__
  17. #define __TUNER_I2C_H__
  18. #include <linux/i2c.h>
  19. struct tuner_i2c_props {
  20. u8 addr;
  21. struct i2c_adapter *adap;
  22. };
  23. static inline int tuner_i2c_xfer_send(struct tuner_i2c_props *props, char *buf, int len)
  24. {
  25. struct i2c_msg msg = { .addr = props->addr, .flags = 0,
  26. .buf = buf, .len = len };
  27. int ret = i2c_transfer(props->adap, &msg, 1);
  28. return (ret == 1) ? len : ret;
  29. }
  30. static inline int tuner_i2c_xfer_recv(struct tuner_i2c_props *props, char *buf, int len)
  31. {
  32. struct i2c_msg msg = { .addr = props->addr, .flags = I2C_M_RD,
  33. .buf = buf, .len = len };
  34. int ret = i2c_transfer(props->adap, &msg, 1);
  35. return (ret == 1) ? len : ret;
  36. }
  37. #ifndef __TUNER_DRIVER_H__
  38. #define tuner_warn(fmt, arg...) do {\
  39. printk(KERN_WARNING PREFIX "%d-%04x: " fmt, \
  40. i2c_adapter_id(priv->i2c_props.adap), priv->i2c_props.addr , ##arg); } while (0)
  41. #define tuner_info(fmt, arg...) do {\
  42. printk(KERN_INFO PREFIX "%d-%04x: " fmt, \
  43. i2c_adapter_id(priv->i2c_props.adap), priv->i2c_props.addr , ##arg); } while (0)
  44. #define tuner_dbg(fmt, arg...) do {\
  45. if ((debug)) \
  46. printk(KERN_DEBUG PREFIX "%d-%04x: " fmt, \
  47. i2c_adapter_id(priv->i2c_props.adap), priv->i2c_props.addr , ##arg); } while (0)
  48. #endif /* __TUNER_DRIVER_H__ */
  49. #endif /* __TUNER_I2C_H__ */
  50. /*
  51. * Overrides for Emacs so that we follow Linus's tabbing style.
  52. * ---------------------------------------------------------------------------
  53. * Local variables:
  54. * c-basic-offset: 8
  55. * End:
  56. */