tuner-i2c.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. static inline int tuner_i2c_xfer_send_recv(struct tuner_i2c_props *props,
  38. char *obuf, int olen,
  39. char *ibuf, int ilen)
  40. {
  41. struct i2c_msg msg[2] = { { .addr = props->addr, .flags = 0,
  42. .buf = obuf, .len = olen },
  43. { .addr = props->addr, .flags = I2C_M_RD,
  44. .buf = ibuf, .len = ilen } };
  45. int ret = i2c_transfer(props->adap, msg, 2);
  46. return (ret == 2) ? ilen : ret;
  47. }
  48. #define tuner_warn(fmt, arg...) do { \
  49. printk(KERN_WARNING "%s %d-%04x: " fmt, PREFIX, \
  50. i2c_adapter_id(priv->i2c_props.adap), \
  51. priv->i2c_props.addr, ##arg); \
  52. } while (0)
  53. #define tuner_info(fmt, arg...) do { \
  54. printk(KERN_INFO "%s %d-%04x: " fmt, PREFIX, \
  55. i2c_adapter_id(priv->i2c_props.adap), \
  56. priv->i2c_props.addr , ##arg); \
  57. } while (0)
  58. #define tuner_err(fmt, arg...) do { \
  59. printk(KERN_ERR "%s %d-%04x: " fmt, PREFIX, \
  60. i2c_adapter_id(priv->i2c_props.adap), \
  61. priv->i2c_props.addr , ##arg); \
  62. } while (0)
  63. #define tuner_dbg(fmt, arg...) do { \
  64. if ((debug)) \
  65. printk(KERN_DEBUG "%s %d-%04x: " fmt, PREFIX, \
  66. i2c_adapter_id(priv->i2c_props.adap), \
  67. priv->i2c_props.addr , ##arg); \
  68. } while (0)
  69. #endif /* __TUNER_I2C_H__ */