Chris Pascoe | fc40b26 | 2006-01-09 15:25:35 -0200 | [diff] [blame] | 1 | /* |
Mauro Carvalho Chehab | 7b61ba8 | 2016-11-16 06:59:49 -0200 | [diff] [blame] | 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 | * |
| 6 | * (c) 2005 Chris Pascoe <c.pascoe@itee.uq.edu.au> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | */ |
Chris Pascoe | fc40b26 | 2006-01-09 15:25:35 -0200 | [diff] [blame] | 18 | |
Mauro Carvalho Chehab | 65bc2fe | 2016-11-13 10:07:38 -0200 | [diff] [blame] | 19 | #include "cx88.h" |
| 20 | #include "cx88-vp3054-i2c.h" |
| 21 | |
Chris Pascoe | fc40b26 | 2006-01-09 15:25:35 -0200 | [diff] [blame] | 22 | #include <linux/module.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 23 | #include <linux/slab.h> |
Chris Pascoe | fc40b26 | 2006-01-09 15:25:35 -0200 | [diff] [blame] | 24 | #include <linux/init.h> |
Mauro Carvalho Chehab | 399426c | 2016-11-19 19:27:30 -0200 | [diff] [blame] | 25 | #include <linux/io.h> |
Chris Pascoe | fc40b26 | 2006-01-09 15:25:35 -0200 | [diff] [blame] | 26 | |
Mauro Carvalho Chehab | 45bf2da | 2006-01-13 14:10:24 -0200 | [diff] [blame] | 27 | MODULE_DESCRIPTION("driver for cx2388x VP3054 design"); |
| 28 | MODULE_AUTHOR("Chris Pascoe <c.pascoe@itee.uq.edu.au>"); |
| 29 | MODULE_LICENSE("GPL"); |
| 30 | |
Chris Pascoe | fc40b26 | 2006-01-09 15:25:35 -0200 | [diff] [blame] | 31 | /* ----------------------------------------------------------------------- */ |
| 32 | |
| 33 | static void vp3054_bit_setscl(void *data, int state) |
| 34 | { |
| 35 | struct cx8802_dev *dev = data; |
| 36 | struct cx88_core *core = dev->core; |
Trent Piepho | f0ad909 | 2007-10-14 02:52:16 -0300 | [diff] [blame] | 37 | struct vp3054_i2c_state *vp3054_i2c = dev->vp3054; |
Chris Pascoe | fc40b26 | 2006-01-09 15:25:35 -0200 | [diff] [blame] | 38 | |
| 39 | if (state) { |
| 40 | vp3054_i2c->state |= 0x0001; /* SCL high */ |
| 41 | vp3054_i2c->state &= ~0x0100; /* external pullup */ |
| 42 | } else { |
| 43 | vp3054_i2c->state &= ~0x0001; /* SCL low */ |
| 44 | vp3054_i2c->state |= 0x0100; /* drive pin */ |
| 45 | } |
| 46 | cx_write(MO_GP0_IO, 0x010000 | vp3054_i2c->state); |
| 47 | cx_read(MO_GP0_IO); |
| 48 | } |
| 49 | |
| 50 | static void vp3054_bit_setsda(void *data, int state) |
| 51 | { |
| 52 | struct cx8802_dev *dev = data; |
| 53 | struct cx88_core *core = dev->core; |
Trent Piepho | f0ad909 | 2007-10-14 02:52:16 -0300 | [diff] [blame] | 54 | struct vp3054_i2c_state *vp3054_i2c = dev->vp3054; |
Chris Pascoe | fc40b26 | 2006-01-09 15:25:35 -0200 | [diff] [blame] | 55 | |
| 56 | if (state) { |
| 57 | vp3054_i2c->state |= 0x0002; /* SDA high */ |
| 58 | vp3054_i2c->state &= ~0x0200; /* tristate pin */ |
| 59 | } else { |
| 60 | vp3054_i2c->state &= ~0x0002; /* SDA low */ |
| 61 | vp3054_i2c->state |= 0x0200; /* drive pin */ |
| 62 | } |
| 63 | cx_write(MO_GP0_IO, 0x020000 | vp3054_i2c->state); |
| 64 | cx_read(MO_GP0_IO); |
| 65 | } |
| 66 | |
| 67 | static int vp3054_bit_getscl(void *data) |
| 68 | { |
| 69 | struct cx8802_dev *dev = data; |
| 70 | struct cx88_core *core = dev->core; |
| 71 | u32 state; |
| 72 | |
| 73 | state = cx_read(MO_GP0_IO); |
| 74 | return (state & 0x01) ? 1 : 0; |
| 75 | } |
| 76 | |
| 77 | static int vp3054_bit_getsda(void *data) |
| 78 | { |
| 79 | struct cx8802_dev *dev = data; |
| 80 | struct cx88_core *core = dev->core; |
| 81 | u32 state; |
| 82 | |
| 83 | state = cx_read(MO_GP0_IO); |
| 84 | return (state & 0x02) ? 1 : 0; |
| 85 | } |
| 86 | |
| 87 | /* ----------------------------------------------------------------------- */ |
| 88 | |
Jean Delvare | 7e520d0 | 2007-07-01 18:37:51 -0300 | [diff] [blame] | 89 | static const struct i2c_algo_bit_data vp3054_i2c_algo_template = { |
Chris Pascoe | fc40b26 | 2006-01-09 15:25:35 -0200 | [diff] [blame] | 90 | .setsda = vp3054_bit_setsda, |
| 91 | .setscl = vp3054_bit_setscl, |
| 92 | .getsda = vp3054_bit_getsda, |
| 93 | .getscl = vp3054_bit_getscl, |
| 94 | .udelay = 16, |
Chris Pascoe | fc40b26 | 2006-01-09 15:25:35 -0200 | [diff] [blame] | 95 | .timeout = 200, |
| 96 | }; |
| 97 | |
| 98 | /* ----------------------------------------------------------------------- */ |
| 99 | |
Chris Pascoe | fc40b26 | 2006-01-09 15:25:35 -0200 | [diff] [blame] | 100 | int vp3054_i2c_probe(struct cx8802_dev *dev) |
| 101 | { |
| 102 | struct cx88_core *core = dev->core; |
| 103 | struct vp3054_i2c_state *vp3054_i2c; |
| 104 | int rc; |
| 105 | |
Trent Piepho | 6a59d64 | 2007-08-15 14:41:57 -0300 | [diff] [blame] | 106 | if (core->boardnr != CX88_BOARD_DNTV_LIVE_DVB_T_PRO) |
Chris Pascoe | fc40b26 | 2006-01-09 15:25:35 -0200 | [diff] [blame] | 107 | return 0; |
| 108 | |
Trent Piepho | f0ad909 | 2007-10-14 02:52:16 -0300 | [diff] [blame] | 109 | vp3054_i2c = kzalloc(sizeof(*vp3054_i2c), GFP_KERNEL); |
Mauro Carvalho Chehab | 399426c | 2016-11-19 19:27:30 -0200 | [diff] [blame] | 110 | if (!vp3054_i2c) |
Chris Pascoe | fc40b26 | 2006-01-09 15:25:35 -0200 | [diff] [blame] | 111 | return -ENOMEM; |
Trent Piepho | f0ad909 | 2007-10-14 02:52:16 -0300 | [diff] [blame] | 112 | dev->vp3054 = vp3054_i2c; |
Chris Pascoe | fc40b26 | 2006-01-09 15:25:35 -0200 | [diff] [blame] | 113 | |
Ezequiel Garcia | b523774 | 2012-10-23 15:57:19 -0300 | [diff] [blame] | 114 | vp3054_i2c->algo = vp3054_i2c_algo_template; |
Chris Pascoe | fc40b26 | 2006-01-09 15:25:35 -0200 | [diff] [blame] | 115 | |
Chris Pascoe | fc40b26 | 2006-01-09 15:25:35 -0200 | [diff] [blame] | 116 | vp3054_i2c->adap.dev.parent = &dev->pci->dev; |
| 117 | strlcpy(vp3054_i2c->adap.name, core->name, |
| 118 | sizeof(vp3054_i2c->adap.name)); |
Jean Delvare | 7e520d0 | 2007-07-01 18:37:51 -0300 | [diff] [blame] | 119 | vp3054_i2c->adap.owner = THIS_MODULE; |
Chris Pascoe | fc40b26 | 2006-01-09 15:25:35 -0200 | [diff] [blame] | 120 | vp3054_i2c->algo.data = dev; |
| 121 | i2c_set_adapdata(&vp3054_i2c->adap, dev); |
| 122 | vp3054_i2c->adap.algo_data = &vp3054_i2c->algo; |
Chris Pascoe | fc40b26 | 2006-01-09 15:25:35 -0200 | [diff] [blame] | 123 | |
Mauro Carvalho Chehab | 7b61ba8 | 2016-11-16 06:59:49 -0200 | [diff] [blame] | 124 | vp3054_bit_setscl(dev, 1); |
| 125 | vp3054_bit_setsda(dev, 1); |
Chris Pascoe | fc40b26 | 2006-01-09 15:25:35 -0200 | [diff] [blame] | 126 | |
| 127 | rc = i2c_bit_add_bus(&vp3054_i2c->adap); |
Mauro Carvalho Chehab | 7b61ba8 | 2016-11-16 06:59:49 -0200 | [diff] [blame] | 128 | if (rc != 0) { |
Mauro Carvalho Chehab | 65bc2fe | 2016-11-13 10:07:38 -0200 | [diff] [blame] | 129 | pr_err("vp3054_i2c register FAILED\n"); |
Chris Pascoe | fc40b26 | 2006-01-09 15:25:35 -0200 | [diff] [blame] | 130 | |
Trent Piepho | f0ad909 | 2007-10-14 02:52:16 -0300 | [diff] [blame] | 131 | kfree(dev->vp3054); |
| 132 | dev->vp3054 = NULL; |
Chris Pascoe | fc40b26 | 2006-01-09 15:25:35 -0200 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | return rc; |
| 136 | } |
Mauro Carvalho Chehab | 399426c | 2016-11-19 19:27:30 -0200 | [diff] [blame] | 137 | EXPORT_SYMBOL(vp3054_i2c_probe); |
Chris Pascoe | fc40b26 | 2006-01-09 15:25:35 -0200 | [diff] [blame] | 138 | |
| 139 | void vp3054_i2c_remove(struct cx8802_dev *dev) |
| 140 | { |
Trent Piepho | f0ad909 | 2007-10-14 02:52:16 -0300 | [diff] [blame] | 141 | struct vp3054_i2c_state *vp3054_i2c = dev->vp3054; |
Chris Pascoe | fc40b26 | 2006-01-09 15:25:35 -0200 | [diff] [blame] | 142 | |
Mauro Carvalho Chehab | 399426c | 2016-11-19 19:27:30 -0200 | [diff] [blame] | 143 | if (!vp3054_i2c || |
Trent Piepho | 6a59d64 | 2007-08-15 14:41:57 -0300 | [diff] [blame] | 144 | dev->core->boardnr != CX88_BOARD_DNTV_LIVE_DVB_T_PRO) |
Chris Pascoe | fc40b26 | 2006-01-09 15:25:35 -0200 | [diff] [blame] | 145 | return; |
| 146 | |
Jean Delvare | 3269711 | 2006-12-10 21:21:33 +0100 | [diff] [blame] | 147 | i2c_del_adapter(&vp3054_i2c->adap); |
Chris Pascoe | fc40b26 | 2006-01-09 15:25:35 -0200 | [diff] [blame] | 148 | kfree(vp3054_i2c); |
| 149 | } |
Chris Pascoe | fc40b26 | 2006-01-09 15:25:35 -0200 | [diff] [blame] | 150 | EXPORT_SYMBOL(vp3054_i2c_remove); |