i2c-direct.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /****************************************************************************
  2. * Driver for Solarflare Solarstorm network controllers and boards
  3. * Copyright 2005 Fen Systems Ltd.
  4. * Copyright 2006 Solarflare Communications Inc.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License version 2 as published
  8. * by the Free Software Foundation, incorporated herein by reference.
  9. */
  10. #ifndef EFX_I2C_DIRECT_H
  11. #define EFX_I2C_DIRECT_H
  12. #include "net_driver.h"
  13. /*
  14. * Direct control of an I2C bus
  15. */
  16. struct efx_i2c_interface;
  17. /**
  18. * struct efx_i2c_bit_operations - I2C bus direct control methods
  19. *
  20. * I2C bus direct control methods.
  21. *
  22. * @setsda: Set state of SDA line
  23. * @setscl: Set state of SCL line
  24. * @getsda: Get state of SDA line
  25. * @getscl: Get state of SCL line
  26. * @udelay: Delay between each bit operation
  27. * @mdelay: Delay between each byte write
  28. */
  29. struct efx_i2c_bit_operations {
  30. void (*setsda) (struct efx_i2c_interface *i2c);
  31. void (*setscl) (struct efx_i2c_interface *i2c);
  32. int (*getsda) (struct efx_i2c_interface *i2c);
  33. int (*getscl) (struct efx_i2c_interface *i2c);
  34. unsigned int udelay;
  35. unsigned int mdelay;
  36. };
  37. /**
  38. * struct efx_i2c_interface - an I2C interface
  39. *
  40. * An I2C interface.
  41. *
  42. * @efx: Attached Efx NIC
  43. * @op: I2C bus control methods
  44. * @sda: Current output state of SDA line
  45. * @scl: Current output state of SCL line
  46. */
  47. struct efx_i2c_interface {
  48. struct efx_nic *efx;
  49. struct efx_i2c_bit_operations *op;
  50. unsigned int sda:1;
  51. unsigned int scl:1;
  52. };
  53. extern int efx_i2c_check_presence(struct efx_i2c_interface *i2c, u8 device_id);
  54. extern int efx_i2c_fast_read(struct efx_i2c_interface *i2c,
  55. u8 device_id, u8 offset,
  56. u8 *data, unsigned int len);
  57. extern int efx_i2c_fast_write(struct efx_i2c_interface *i2c,
  58. u8 device_id, u8 offset,
  59. const u8 *data, unsigned int len);
  60. extern int efx_i2c_read(struct efx_i2c_interface *i2c,
  61. u8 device_id, u8 offset, u8 *data, unsigned int len);
  62. extern int efx_i2c_write(struct efx_i2c_interface *i2c,
  63. u8 device_id, u8 offset,
  64. const u8 *data, unsigned int len);
  65. extern int efx_i2c_send_bytes(struct efx_i2c_interface *i2c, u8 device_id,
  66. const u8 *bytes, unsigned int len);
  67. extern int efx_i2c_recv_bytes(struct efx_i2c_interface *i2c, u8 device_id,
  68. u8 *bytes, unsigned int len);
  69. /* Versions of the API that retry on failure. */
  70. extern int efx_i2c_check_presence_retry(struct efx_i2c_interface *i2c,
  71. u8 device_id);
  72. extern int efx_i2c_read_retry(struct efx_i2c_interface *i2c,
  73. u8 device_id, u8 offset, u8 *data, unsigned int len);
  74. extern int efx_i2c_write_retry(struct efx_i2c_interface *i2c,
  75. u8 device_id, u8 offset,
  76. const u8 *data, unsigned int len);
  77. #endif /* EFX_I2C_DIRECT_H */