netup-init.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  24. */
  25. #include "cx23885.h"
  26. #include "netup-init.h"
  27. static void i2c_av_write(struct i2c_adapter *i2c, u16 reg, u8 val)
  28. {
  29. int ret;
  30. u8 buf[3];
  31. struct i2c_msg msg = {
  32. .addr = 0x88 >> 1,
  33. .flags = 0,
  34. .buf = buf,
  35. .len = 3
  36. };
  37. buf[0] = reg >> 8;
  38. buf[1] = reg & 0xff;
  39. buf[2] = val;
  40. ret = i2c_transfer(i2c, &msg, 1);
  41. if (ret != 1)
  42. printk(KERN_ERR "%s: i2c write error!\n", __func__);
  43. }
  44. static void i2c_av_write4(struct i2c_adapter *i2c, u16 reg, u32 val)
  45. {
  46. int ret;
  47. u8 buf[6];
  48. struct i2c_msg msg = {
  49. .addr = 0x88 >> 1,
  50. .flags = 0,
  51. .buf = buf,
  52. .len = 6
  53. };
  54. buf[0] = reg >> 8;
  55. buf[1] = reg & 0xff;
  56. buf[2] = val & 0xff;
  57. buf[3] = (val >> 8) & 0xff;
  58. buf[4] = (val >> 16) & 0xff;
  59. buf[5] = val >> 24;
  60. ret = i2c_transfer(i2c, &msg, 1);
  61. if (ret != 1)
  62. printk(KERN_ERR "%s: i2c write error!\n", __func__);
  63. }
  64. static u8 i2c_av_read(struct i2c_adapter *i2c, u16 reg)
  65. {
  66. int ret;
  67. u8 buf[2];
  68. struct i2c_msg msg = {
  69. .addr = 0x88 >> 1,
  70. .flags = 0,
  71. .buf = buf,
  72. .len = 2
  73. };
  74. buf[0] = reg >> 8;
  75. buf[1] = reg & 0xff;
  76. ret = i2c_transfer(i2c, &msg, 1);
  77. if (ret != 1)
  78. printk(KERN_ERR "%s: i2c write error!\n", __func__);
  79. msg.flags = I2C_M_RD;
  80. msg.len = 1;
  81. ret = i2c_transfer(i2c, &msg, 1);
  82. if (ret != 1)
  83. printk(KERN_ERR "%s: i2c read error!\n", __func__);
  84. return buf[0];
  85. }
  86. static void i2c_av_and_or(struct i2c_adapter *i2c, u16 reg, unsigned and_mask,
  87. u8 or_value)
  88. {
  89. i2c_av_write(i2c, reg, (i2c_av_read(i2c, reg) & and_mask) | or_value);
  90. }
  91. /* set 27MHz on AUX_CLK */
  92. void netup_initialize(struct cx23885_dev *dev)
  93. {
  94. struct cx23885_i2c *i2c_bus = &dev->i2c_bus[2];
  95. struct i2c_adapter *i2c = &i2c_bus->i2c_adap;
  96. /* Stop microcontroller */
  97. i2c_av_and_or(i2c, 0x803, ~0x10, 0x00);
  98. /* Aux PLL frac for 27 MHz */
  99. i2c_av_write4(i2c, 0x114, 0xea0eb3);
  100. /* Aux PLL int for 27 MHz */
  101. i2c_av_write4(i2c, 0x110, 0x090319);
  102. /* start microcontroller */
  103. i2c_av_and_or(i2c, 0x803, ~0x10, 0x10);
  104. }