netup-eeprom.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * netup-eeprom.c
  3. *
  4. * 24LC02 EEPROM driver in conjunction with NetUP Dual DVB-S2 CI card
  5. *
  6. * Copyright (C) 2009 NetUP Inc.
  7. * Copyright (C) 2009 Abylay Ospan <aospan@netup.ru>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. *
  18. * GNU General Public License for more details.
  19. */
  20. #
  21. #include "cx23885.h"
  22. #include "netup-eeprom.h"
  23. #define EEPROM_I2C_ADDR 0x50
  24. int netup_eeprom_read(struct i2c_adapter *i2c_adap, u8 addr)
  25. {
  26. int ret;
  27. unsigned char buf[2];
  28. /* Read from EEPROM */
  29. struct i2c_msg msg[] = {
  30. {
  31. .addr = EEPROM_I2C_ADDR,
  32. .flags = 0,
  33. .buf = &buf[0],
  34. .len = 1
  35. }, {
  36. .addr = EEPROM_I2C_ADDR,
  37. .flags = I2C_M_RD,
  38. .buf = &buf[1],
  39. .len = 1
  40. }
  41. };
  42. buf[0] = addr;
  43. buf[1] = 0x0;
  44. ret = i2c_transfer(i2c_adap, msg, 2);
  45. if (ret != 2) {
  46. pr_err("eeprom i2c read error, status=%d\n", ret);
  47. return -1;
  48. }
  49. return buf[1];
  50. };
  51. int netup_eeprom_write(struct i2c_adapter *i2c_adap, u8 addr, u8 data)
  52. {
  53. int ret;
  54. unsigned char bufw[2];
  55. /* Write into EEPROM */
  56. struct i2c_msg msg[] = {
  57. {
  58. .addr = EEPROM_I2C_ADDR,
  59. .flags = 0,
  60. .buf = &bufw[0],
  61. .len = 2
  62. }
  63. };
  64. bufw[0] = addr;
  65. bufw[1] = data;
  66. ret = i2c_transfer(i2c_adap, msg, 1);
  67. if (ret != 1) {
  68. pr_err("eeprom i2c write error, status=%d\n", ret);
  69. return -1;
  70. }
  71. mdelay(10); /* prophylactic delay, datasheet write cycle time = 5 ms */
  72. return 0;
  73. };
  74. void netup_get_card_info(struct i2c_adapter *i2c_adap,
  75. struct netup_card_info *cinfo)
  76. {
  77. int i, j;
  78. cinfo->rev = netup_eeprom_read(i2c_adap, 63);
  79. for (i = 64, j = 0; i < 70; i++, j++)
  80. cinfo->port[0].mac[j] = netup_eeprom_read(i2c_adap, i);
  81. for (i = 70, j = 0; i < 76; i++, j++)
  82. cinfo->port[1].mac[j] = netup_eeprom_read(i2c_adap, i);
  83. };