cx88-vp3054-i2c.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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/slab.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->vp3054;
  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->vp3054;
  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 const 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. int vp3054_i2c_probe(struct cx8802_dev *dev)
  85. {
  86. struct cx88_core *core = dev->core;
  87. struct vp3054_i2c_state *vp3054_i2c;
  88. int rc;
  89. if (core->boardnr != CX88_BOARD_DNTV_LIVE_DVB_T_PRO)
  90. return 0;
  91. vp3054_i2c = kzalloc(sizeof(*vp3054_i2c), GFP_KERNEL);
  92. if (vp3054_i2c == NULL)
  93. return -ENOMEM;
  94. dev->vp3054 = vp3054_i2c;
  95. vp3054_i2c->algo = vp3054_i2c_algo_template;
  96. vp3054_i2c->adap.dev.parent = &dev->pci->dev;
  97. strlcpy(vp3054_i2c->adap.name, core->name,
  98. sizeof(vp3054_i2c->adap.name));
  99. vp3054_i2c->adap.owner = THIS_MODULE;
  100. vp3054_i2c->algo.data = dev;
  101. i2c_set_adapdata(&vp3054_i2c->adap, dev);
  102. vp3054_i2c->adap.algo_data = &vp3054_i2c->algo;
  103. vp3054_bit_setscl(dev,1);
  104. vp3054_bit_setsda(dev,1);
  105. rc = i2c_bit_add_bus(&vp3054_i2c->adap);
  106. if (0 != rc) {
  107. printk("%s: vp3054_i2c register FAILED\n", core->name);
  108. kfree(dev->vp3054);
  109. dev->vp3054 = NULL;
  110. }
  111. return rc;
  112. }
  113. void vp3054_i2c_remove(struct cx8802_dev *dev)
  114. {
  115. struct vp3054_i2c_state *vp3054_i2c = dev->vp3054;
  116. if (vp3054_i2c == NULL ||
  117. dev->core->boardnr != CX88_BOARD_DNTV_LIVE_DVB_T_PRO)
  118. return;
  119. i2c_del_adapter(&vp3054_i2c->adap);
  120. kfree(vp3054_i2c);
  121. }
  122. EXPORT_SYMBOL(vp3054_i2c_probe);
  123. EXPORT_SYMBOL(vp3054_i2c_remove);