Chris Pascoe | fc40b26 | 2006-01-09 15:25:35 -0200 | [diff] [blame] | 1 | /* |
| 2 | |
| 3 | cx88-vp3054-i2c.c -- support for the secondary I2C bus of the |
| 4 | DNTV Live! DVB-T Pro (VP-3054), wired as: |
| 5 | GPIO[0] -> SCL, GPIO[1] -> SDA |
| 6 | |
| 7 | (c) 2005 Chris Pascoe <c.pascoe@itee.uq.edu.au> |
| 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 | GNU General Public License for more details. |
| 18 | |
| 19 | You should have received a copy of the GNU General Public License |
| 20 | along with this program; if not, write to the Free Software |
| 21 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 22 | |
| 23 | */ |
| 24 | |
| 25 | #include <linux/module.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 26 | #include <linux/slab.h> |
Chris Pascoe | fc40b26 | 2006-01-09 15:25:35 -0200 | [diff] [blame] | 27 | #include <linux/init.h> |
| 28 | |
| 29 | #include <asm/io.h> |
| 30 | |
| 31 | #include "cx88.h" |
| 32 | #include "cx88-vp3054-i2c.h" |
| 33 | |
Mauro Carvalho Chehab | 45bf2da | 2006-01-13 14:10:24 -0200 | [diff] [blame] | 34 | MODULE_DESCRIPTION("driver for cx2388x VP3054 design"); |
| 35 | MODULE_AUTHOR("Chris Pascoe <c.pascoe@itee.uq.edu.au>"); |
| 36 | MODULE_LICENSE("GPL"); |
| 37 | |
Chris Pascoe | fc40b26 | 2006-01-09 15:25:35 -0200 | [diff] [blame] | 38 | /* ----------------------------------------------------------------------- */ |
| 39 | |
| 40 | static void vp3054_bit_setscl(void *data, int state) |
| 41 | { |
| 42 | struct cx8802_dev *dev = data; |
| 43 | struct cx88_core *core = dev->core; |
Trent Piepho | f0ad909 | 2007-10-14 02:52:16 -0300 | [diff] [blame] | 44 | struct vp3054_i2c_state *vp3054_i2c = dev->vp3054; |
Chris Pascoe | fc40b26 | 2006-01-09 15:25:35 -0200 | [diff] [blame] | 45 | |
| 46 | if (state) { |
| 47 | vp3054_i2c->state |= 0x0001; /* SCL high */ |
| 48 | vp3054_i2c->state &= ~0x0100; /* external pullup */ |
| 49 | } else { |
| 50 | vp3054_i2c->state &= ~0x0001; /* SCL low */ |
| 51 | vp3054_i2c->state |= 0x0100; /* drive pin */ |
| 52 | } |
| 53 | cx_write(MO_GP0_IO, 0x010000 | vp3054_i2c->state); |
| 54 | cx_read(MO_GP0_IO); |
| 55 | } |
| 56 | |
| 57 | static void vp3054_bit_setsda(void *data, int state) |
| 58 | { |
| 59 | struct cx8802_dev *dev = data; |
| 60 | struct cx88_core *core = dev->core; |
Trent Piepho | f0ad909 | 2007-10-14 02:52:16 -0300 | [diff] [blame] | 61 | struct vp3054_i2c_state *vp3054_i2c = dev->vp3054; |
Chris Pascoe | fc40b26 | 2006-01-09 15:25:35 -0200 | [diff] [blame] | 62 | |
| 63 | if (state) { |
| 64 | vp3054_i2c->state |= 0x0002; /* SDA high */ |
| 65 | vp3054_i2c->state &= ~0x0200; /* tristate pin */ |
| 66 | } else { |
| 67 | vp3054_i2c->state &= ~0x0002; /* SDA low */ |
| 68 | vp3054_i2c->state |= 0x0200; /* drive pin */ |
| 69 | } |
| 70 | cx_write(MO_GP0_IO, 0x020000 | vp3054_i2c->state); |
| 71 | cx_read(MO_GP0_IO); |
| 72 | } |
| 73 | |
| 74 | static int vp3054_bit_getscl(void *data) |
| 75 | { |
| 76 | struct cx8802_dev *dev = data; |
| 77 | struct cx88_core *core = dev->core; |
| 78 | u32 state; |
| 79 | |
| 80 | state = cx_read(MO_GP0_IO); |
| 81 | return (state & 0x01) ? 1 : 0; |
| 82 | } |
| 83 | |
| 84 | static int vp3054_bit_getsda(void *data) |
| 85 | { |
| 86 | struct cx8802_dev *dev = data; |
| 87 | struct cx88_core *core = dev->core; |
| 88 | u32 state; |
| 89 | |
| 90 | state = cx_read(MO_GP0_IO); |
| 91 | return (state & 0x02) ? 1 : 0; |
| 92 | } |
| 93 | |
| 94 | /* ----------------------------------------------------------------------- */ |
| 95 | |
Jean Delvare | 7e520d0 | 2007-07-01 18:37:51 -0300 | [diff] [blame] | 96 | static const struct i2c_algo_bit_data vp3054_i2c_algo_template = { |
Chris Pascoe | fc40b26 | 2006-01-09 15:25:35 -0200 | [diff] [blame] | 97 | .setsda = vp3054_bit_setsda, |
| 98 | .setscl = vp3054_bit_setscl, |
| 99 | .getsda = vp3054_bit_getsda, |
| 100 | .getscl = vp3054_bit_getscl, |
| 101 | .udelay = 16, |
Chris Pascoe | fc40b26 | 2006-01-09 15:25:35 -0200 | [diff] [blame] | 102 | .timeout = 200, |
| 103 | }; |
| 104 | |
| 105 | /* ----------------------------------------------------------------------- */ |
| 106 | |
Chris Pascoe | fc40b26 | 2006-01-09 15:25:35 -0200 | [diff] [blame] | 107 | int vp3054_i2c_probe(struct cx8802_dev *dev) |
| 108 | { |
| 109 | struct cx88_core *core = dev->core; |
| 110 | struct vp3054_i2c_state *vp3054_i2c; |
| 111 | int rc; |
| 112 | |
Trent Piepho | 6a59d64 | 2007-08-15 14:41:57 -0300 | [diff] [blame] | 113 | if (core->boardnr != CX88_BOARD_DNTV_LIVE_DVB_T_PRO) |
Chris Pascoe | fc40b26 | 2006-01-09 15:25:35 -0200 | [diff] [blame] | 114 | return 0; |
| 115 | |
Trent Piepho | f0ad909 | 2007-10-14 02:52:16 -0300 | [diff] [blame] | 116 | vp3054_i2c = kzalloc(sizeof(*vp3054_i2c), GFP_KERNEL); |
| 117 | if (vp3054_i2c == NULL) |
Chris Pascoe | fc40b26 | 2006-01-09 15:25:35 -0200 | [diff] [blame] | 118 | return -ENOMEM; |
Trent Piepho | f0ad909 | 2007-10-14 02:52:16 -0300 | [diff] [blame] | 119 | dev->vp3054 = vp3054_i2c; |
Chris Pascoe | fc40b26 | 2006-01-09 15:25:35 -0200 | [diff] [blame] | 120 | |
Ezequiel Garcia | b523774 | 2012-10-23 15:57:19 -0300 | [diff] [blame] | 121 | vp3054_i2c->algo = vp3054_i2c_algo_template; |
Chris Pascoe | fc40b26 | 2006-01-09 15:25:35 -0200 | [diff] [blame] | 122 | |
Chris Pascoe | fc40b26 | 2006-01-09 15:25:35 -0200 | [diff] [blame] | 123 | vp3054_i2c->adap.dev.parent = &dev->pci->dev; |
| 124 | strlcpy(vp3054_i2c->adap.name, core->name, |
| 125 | sizeof(vp3054_i2c->adap.name)); |
Jean Delvare | 7e520d0 | 2007-07-01 18:37:51 -0300 | [diff] [blame] | 126 | vp3054_i2c->adap.owner = THIS_MODULE; |
Chris Pascoe | fc40b26 | 2006-01-09 15:25:35 -0200 | [diff] [blame] | 127 | vp3054_i2c->algo.data = dev; |
| 128 | i2c_set_adapdata(&vp3054_i2c->adap, dev); |
| 129 | vp3054_i2c->adap.algo_data = &vp3054_i2c->algo; |
Chris Pascoe | fc40b26 | 2006-01-09 15:25:35 -0200 | [diff] [blame] | 130 | |
| 131 | vp3054_bit_setscl(dev,1); |
| 132 | vp3054_bit_setsda(dev,1); |
| 133 | |
| 134 | rc = i2c_bit_add_bus(&vp3054_i2c->adap); |
| 135 | if (0 != rc) { |
| 136 | printk("%s: vp3054_i2c register FAILED\n", core->name); |
| 137 | |
Trent Piepho | f0ad909 | 2007-10-14 02:52:16 -0300 | [diff] [blame] | 138 | kfree(dev->vp3054); |
| 139 | dev->vp3054 = NULL; |
Chris Pascoe | fc40b26 | 2006-01-09 15:25:35 -0200 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | return rc; |
| 143 | } |
| 144 | |
| 145 | void vp3054_i2c_remove(struct cx8802_dev *dev) |
| 146 | { |
Trent Piepho | f0ad909 | 2007-10-14 02:52:16 -0300 | [diff] [blame] | 147 | struct vp3054_i2c_state *vp3054_i2c = dev->vp3054; |
Chris Pascoe | fc40b26 | 2006-01-09 15:25:35 -0200 | [diff] [blame] | 148 | |
| 149 | if (vp3054_i2c == NULL || |
Trent Piepho | 6a59d64 | 2007-08-15 14:41:57 -0300 | [diff] [blame] | 150 | dev->core->boardnr != CX88_BOARD_DNTV_LIVE_DVB_T_PRO) |
Chris Pascoe | fc40b26 | 2006-01-09 15:25:35 -0200 | [diff] [blame] | 151 | return; |
| 152 | |
Jean Delvare | 3269711 | 2006-12-10 21:21:33 +0100 | [diff] [blame] | 153 | i2c_del_adapter(&vp3054_i2c->adap); |
Chris Pascoe | fc40b26 | 2006-01-09 15:25:35 -0200 | [diff] [blame] | 154 | kfree(vp3054_i2c); |
| 155 | } |
| 156 | |
| 157 | EXPORT_SYMBOL(vp3054_i2c_probe); |
| 158 | EXPORT_SYMBOL(vp3054_i2c_remove); |