cx88-vp3054-i2c.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /*
  2. cx88-vp3054-i2c.c -- support for the secondary I2C bus of the
  3. DNTV Live! DVB-T Pro (VP-3054), wired as:
  4. GPIO[0] -> SCL, GPIO[1] -> SDA
  5. (c) 2005 Chris Pascoe <c.pascoe@itee.uq.edu.au>
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18. #include <linux/module.h>
  19. #include <linux/moduleparam.h>
  20. #include <linux/init.h>
  21. #include <asm/io.h>
  22. #include "cx88.h"
  23. #include "cx88-vp3054-i2c.h"
  24. MODULE_DESCRIPTION("driver for cx2388x VP3054 design");
  25. MODULE_AUTHOR("Chris Pascoe <c.pascoe@itee.uq.edu.au>");
  26. MODULE_LICENSE("GPL");
  27. /* ----------------------------------------------------------------------- */
  28. static void vp3054_bit_setscl(void *data, int state)
  29. {
  30. struct cx8802_dev *dev = data;
  31. struct cx88_core *core = dev->core;
  32. struct vp3054_i2c_state *vp3054_i2c = dev->card_priv;
  33. if (state) {
  34. vp3054_i2c->state |= 0x0001; /* SCL high */
  35. vp3054_i2c->state &= ~0x0100; /* external pullup */
  36. } else {
  37. vp3054_i2c->state &= ~0x0001; /* SCL low */
  38. vp3054_i2c->state |= 0x0100; /* drive pin */
  39. }
  40. cx_write(MO_GP0_IO, 0x010000 | vp3054_i2c->state);
  41. cx_read(MO_GP0_IO);
  42. }
  43. static void vp3054_bit_setsda(void *data, int state)
  44. {
  45. struct cx8802_dev *dev = data;
  46. struct cx88_core *core = dev->core;
  47. struct vp3054_i2c_state *vp3054_i2c = dev->card_priv;
  48. if (state) {
  49. vp3054_i2c->state |= 0x0002; /* SDA high */
  50. vp3054_i2c->state &= ~0x0200; /* tristate pin */
  51. } else {
  52. vp3054_i2c->state &= ~0x0002; /* SDA low */
  53. vp3054_i2c->state |= 0x0200; /* drive pin */
  54. }
  55. cx_write(MO_GP0_IO, 0x020000 | vp3054_i2c->state);
  56. cx_read(MO_GP0_IO);
  57. }
  58. static int vp3054_bit_getscl(void *data)
  59. {
  60. struct cx8802_dev *dev = data;
  61. struct cx88_core *core = dev->core;
  62. u32 state;
  63. state = cx_read(MO_GP0_IO);
  64. return (state & 0x01) ? 1 : 0;
  65. }
  66. static int vp3054_bit_getsda(void *data)
  67. {
  68. struct cx8802_dev *dev = data;
  69. struct cx88_core *core = dev->core;
  70. u32 state;
  71. state = cx_read(MO_GP0_IO);
  72. return (state & 0x02) ? 1 : 0;
  73. }
  74. /* ----------------------------------------------------------------------- */
  75. static struct i2c_algo_bit_data vp3054_i2c_algo_template = {
  76. .setsda = vp3054_bit_setsda,
  77. .setscl = vp3054_bit_setscl,
  78. .getsda = vp3054_bit_getsda,
  79. .getscl = vp3054_bit_getscl,
  80. .udelay = 16,
  81. .timeout = 200,
  82. };
  83. /* ----------------------------------------------------------------------- */
  84. static struct i2c_adapter vp3054_i2c_adap_template = {
  85. .name = "cx2388x",
  86. .owner = THIS_MODULE,
  87. .id = I2C_HW_B_CX2388x,
  88. };
  89. static struct i2c_client vp3054_i2c_client_template = {
  90. .name = "VP-3054",
  91. };
  92. int vp3054_i2c_probe(struct cx8802_dev *dev)
  93. {
  94. struct cx88_core *core = dev->core;
  95. struct vp3054_i2c_state *vp3054_i2c;
  96. int rc;
  97. if (core->board != CX88_BOARD_DNTV_LIVE_DVB_T_PRO)
  98. return 0;
  99. dev->card_priv = kzalloc(sizeof(*vp3054_i2c), GFP_KERNEL);
  100. if (dev->card_priv == NULL)
  101. return -ENOMEM;
  102. vp3054_i2c = dev->card_priv;
  103. memcpy(&vp3054_i2c->adap, &vp3054_i2c_adap_template,
  104. sizeof(vp3054_i2c->adap));
  105. memcpy(&vp3054_i2c->algo, &vp3054_i2c_algo_template,
  106. sizeof(vp3054_i2c->algo));
  107. memcpy(&vp3054_i2c->client, &vp3054_i2c_client_template,
  108. sizeof(vp3054_i2c->client));
  109. vp3054_i2c->adap.class |= I2C_CLASS_TV_DIGITAL;
  110. vp3054_i2c->adap.dev.parent = &dev->pci->dev;
  111. strlcpy(vp3054_i2c->adap.name, core->name,
  112. sizeof(vp3054_i2c->adap.name));
  113. vp3054_i2c->algo.data = dev;
  114. i2c_set_adapdata(&vp3054_i2c->adap, dev);
  115. vp3054_i2c->adap.algo_data = &vp3054_i2c->algo;
  116. vp3054_i2c->client.adapter = &vp3054_i2c->adap;
  117. vp3054_bit_setscl(dev,1);
  118. vp3054_bit_setsda(dev,1);
  119. rc = i2c_bit_add_bus(&vp3054_i2c->adap);
  120. if (0 != rc) {
  121. printk("%s: vp3054_i2c register FAILED\n", core->name);
  122. kfree(dev->card_priv);
  123. dev->card_priv = NULL;
  124. }
  125. return rc;
  126. }
  127. void vp3054_i2c_remove(struct cx8802_dev *dev)
  128. {
  129. struct vp3054_i2c_state *vp3054_i2c = dev->card_priv;
  130. if (vp3054_i2c == NULL ||
  131. dev->core->board != CX88_BOARD_DNTV_LIVE_DVB_T_PRO)
  132. return;
  133. i2c_del_adapter(&vp3054_i2c->adap);
  134. kfree(vp3054_i2c);
  135. }
  136. EXPORT_SYMBOL(vp3054_i2c_probe);
  137. EXPORT_SYMBOL(vp3054_i2c_remove);