netup-init.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * netup-init.c
  3. *
  4. * NetUP Dual DVB-S2 CI driver
  5. *
  6. * Copyright (C) 2009 NetUP Inc.
  7. * Copyright (C) 2009 Igor M. Liplianin <liplianin@netup.ru>
  8. * Copyright (C) 2009 Abylay Ospan <aospan@netup.ru>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. *
  19. * GNU General Public License for more details.
  20. */
  21. #include "cx23885.h"
  22. #include "netup-init.h"
  23. static void i2c_av_write(struct i2c_adapter *i2c, u16 reg, u8 val)
  24. {
  25. int ret;
  26. u8 buf[3];
  27. struct i2c_msg msg = {
  28. .addr = 0x88 >> 1,
  29. .flags = 0,
  30. .buf = buf,
  31. .len = 3
  32. };
  33. buf[0] = reg >> 8;
  34. buf[1] = reg & 0xff;
  35. buf[2] = val;
  36. ret = i2c_transfer(i2c, &msg, 1);
  37. if (ret != 1)
  38. printk(KERN_ERR "%s: i2c write error!\n", __func__);
  39. }
  40. static void i2c_av_write4(struct i2c_adapter *i2c, u16 reg, u32 val)
  41. {
  42. int ret;
  43. u8 buf[6];
  44. struct i2c_msg msg = {
  45. .addr = 0x88 >> 1,
  46. .flags = 0,
  47. .buf = buf,
  48. .len = 6
  49. };
  50. buf[0] = reg >> 8;
  51. buf[1] = reg & 0xff;
  52. buf[2] = val & 0xff;
  53. buf[3] = (val >> 8) & 0xff;
  54. buf[4] = (val >> 16) & 0xff;
  55. buf[5] = val >> 24;
  56. ret = i2c_transfer(i2c, &msg, 1);
  57. if (ret != 1)
  58. printk(KERN_ERR "%s: i2c write error!\n", __func__);
  59. }
  60. static u8 i2c_av_read(struct i2c_adapter *i2c, u16 reg)
  61. {
  62. int ret;
  63. u8 buf[2];
  64. struct i2c_msg msg = {
  65. .addr = 0x88 >> 1,
  66. .flags = 0,
  67. .buf = buf,
  68. .len = 2
  69. };
  70. buf[0] = reg >> 8;
  71. buf[1] = reg & 0xff;
  72. ret = i2c_transfer(i2c, &msg, 1);
  73. if (ret != 1)
  74. printk(KERN_ERR "%s: i2c write error!\n", __func__);
  75. msg.flags = I2C_M_RD;
  76. msg.len = 1;
  77. ret = i2c_transfer(i2c, &msg, 1);
  78. if (ret != 1)
  79. printk(KERN_ERR "%s: i2c read error!\n", __func__);
  80. return buf[0];
  81. }
  82. static void i2c_av_and_or(struct i2c_adapter *i2c, u16 reg, unsigned and_mask,
  83. u8 or_value)
  84. {
  85. i2c_av_write(i2c, reg, (i2c_av_read(i2c, reg) & and_mask) | or_value);
  86. }
  87. /* set 27MHz on AUX_CLK */
  88. void netup_initialize(struct cx23885_dev *dev)
  89. {
  90. struct cx23885_i2c *i2c_bus = &dev->i2c_bus[2];
  91. struct i2c_adapter *i2c = &i2c_bus->i2c_adap;
  92. /* Stop microcontroller */
  93. i2c_av_and_or(i2c, 0x803, ~0x10, 0x00);
  94. /* Aux PLL frac for 27 MHz */
  95. i2c_av_write4(i2c, 0x114, 0xea0eb3);
  96. /* Aux PLL int for 27 MHz */
  97. i2c_av_write4(i2c, 0x110, 0x090319);
  98. /* start microcontroller */
  99. i2c_av_and_or(i2c, 0x803, ~0x10, 0x10);
  100. }