netup-eeprom.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  23. */
  24. #
  25. #include "cx23885.h"
  26. #include "netup-eeprom.h"
  27. #define EEPROM_I2C_ADDR 0x50
  28. int netup_eeprom_read(struct i2c_adapter *i2c_adap, u8 addr)
  29. {
  30. int ret;
  31. unsigned char buf[2];
  32. /* Read from EEPROM */
  33. struct i2c_msg msg[] = {
  34. {
  35. .addr = EEPROM_I2C_ADDR,
  36. .flags = 0,
  37. .buf = &buf[0],
  38. .len = 1
  39. }, {
  40. .addr = EEPROM_I2C_ADDR,
  41. .flags = I2C_M_RD,
  42. .buf = &buf[1],
  43. .len = 1
  44. }
  45. };
  46. buf[0] = addr;
  47. buf[1] = 0x0;
  48. ret = i2c_transfer(i2c_adap, msg, 2);
  49. if (ret != 2) {
  50. printk(KERN_ERR "eeprom i2c read error, status=%d\n", ret);
  51. return -1;
  52. }
  53. return buf[1];
  54. };
  55. int netup_eeprom_write(struct i2c_adapter *i2c_adap, u8 addr, u8 data)
  56. {
  57. int ret;
  58. unsigned char bufw[2];
  59. /* Write into EEPROM */
  60. struct i2c_msg msg[] = {
  61. {
  62. .addr = EEPROM_I2C_ADDR,
  63. .flags = 0,
  64. .buf = &bufw[0],
  65. .len = 2
  66. }
  67. };
  68. bufw[0] = addr;
  69. bufw[1] = data;
  70. ret = i2c_transfer(i2c_adap, msg, 1);
  71. if (ret != 1) {
  72. printk(KERN_ERR "eeprom i2c write error, status=%d\n", ret);
  73. return -1;
  74. }
  75. mdelay(10); /* prophylactic delay, datasheet write cycle time = 5 ms */
  76. return 0;
  77. };
  78. void netup_get_card_info(struct i2c_adapter *i2c_adap,
  79. struct netup_card_info *cinfo)
  80. {
  81. int i, j;
  82. cinfo->rev = netup_eeprom_read(i2c_adap, 63);
  83. for (i = 64, j = 0; i < 70; i++, j++)
  84. cinfo->port[0].mac[j] = netup_eeprom_read(i2c_adap, i);
  85. for (i = 70, j = 0; i < 76; i++, j++)
  86. cinfo->port[1].mac[j] = netup_eeprom_read(i2c_adap, i);
  87. };