Manu Abraham | 41e840b | 2009-12-02 21:57:10 -0300 | [diff] [blame] | 1 | /* |
| 2 | Mantis PCI bridge driver |
| 3 | |
Manu Abraham | 8825a09 | 2009-12-15 09:13:49 -0300 | [diff] [blame] | 4 | Copyright (C) Manu Abraham (abraham.manu@gmail.com) |
Manu Abraham | 41e840b | 2009-12-02 21:57:10 -0300 | [diff] [blame] | 5 | |
| 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 | |
| 11 | This program is distributed in the hope that it will be useful, |
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | GNU General Public License for more details. |
| 15 | |
| 16 | You should have received a copy of the GNU General Public License |
| 17 | along with this program; if not, write to the Free Software |
| 18 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 19 | */ |
| 20 | |
| 21 | #include "mantis_common.h" |
| 22 | #include "mantis_core.h" |
Manu Abraham | df0cca1 | 2009-12-02 22:07:24 -0300 | [diff] [blame] | 23 | #include "mantis_vp1033.h" |
| 24 | #include "mantis_vp1034.h" |
Manu Abraham | 873c8c2 | 2009-12-04 04:43:04 -0300 | [diff] [blame] | 25 | #include "mantis_vp1041.h" |
Manu Abraham | df0cca1 | 2009-12-02 22:07:24 -0300 | [diff] [blame] | 26 | #include "mantis_vp2033.h" |
Manu Abraham | b2eb131 | 2009-12-04 04:42:22 -0300 | [diff] [blame] | 27 | #include "mantis_vp2040.h" |
Manu Abraham | df0cca1 | 2009-12-02 22:07:24 -0300 | [diff] [blame] | 28 | #include "mantis_vp3030.h" |
Manu Abraham | 41e840b | 2009-12-02 21:57:10 -0300 | [diff] [blame] | 29 | |
| 30 | static int read_eeprom_byte(struct mantis_pci *mantis, u8 *data, u8 length) |
| 31 | { |
| 32 | int err; |
| 33 | struct i2c_msg msg[] = { |
| 34 | { |
| 35 | .addr = 0x50, |
| 36 | .flags = 0, |
| 37 | .buf = data, |
| 38 | .len = 1 |
Manu Abraham | f5ae4f6 | 2009-12-15 08:47:21 -0300 | [diff] [blame] | 39 | }, { |
Manu Abraham | 41e840b | 2009-12-02 21:57:10 -0300 | [diff] [blame] | 40 | .addr = 0x50, |
| 41 | .flags = I2C_M_RD, |
| 42 | .buf = data, |
| 43 | .len = length |
| 44 | }, |
| 45 | }; |
Manu Abraham | f5ae4f6 | 2009-12-15 08:47:21 -0300 | [diff] [blame] | 46 | |
| 47 | err = i2c_transfer(&mantis->adapter, msg, 2); |
| 48 | if (err < 0) { |
Manu Abraham | 41e840b | 2009-12-02 21:57:10 -0300 | [diff] [blame] | 49 | dprintk(verbose, MANTIS_ERROR, 1, |
| 50 | "ERROR: i2c read: < err=%i d0=0x%02x d1=0x%02x >", |
| 51 | err, data[0], data[1]); |
| 52 | |
| 53 | return err; |
| 54 | } |
Manu Abraham | 41e840b | 2009-12-02 21:57:10 -0300 | [diff] [blame] | 55 | |
| 56 | return 0; |
| 57 | } |
| 58 | |
Manu Abraham | 41e840b | 2009-12-02 21:57:10 -0300 | [diff] [blame] | 59 | static int get_mac_address(struct mantis_pci *mantis) |
| 60 | { |
| 61 | int err; |
| 62 | |
| 63 | mantis->mac_address[0] = 0x08; |
Manu Abraham | f5ae4f6 | 2009-12-15 08:47:21 -0300 | [diff] [blame] | 64 | err = read_eeprom_byte(mantis, &mantis->mac_address[0], 6); |
| 65 | if (err < 0) { |
Manu Abraham | 41e840b | 2009-12-02 21:57:10 -0300 | [diff] [blame] | 66 | dprintk(verbose, MANTIS_ERROR, 1, "Mantis EEPROM read error"); |
| 67 | |
| 68 | return err; |
| 69 | } |
Manu Abraham | df0cca1 | 2009-12-02 22:07:24 -0300 | [diff] [blame] | 70 | dprintk(verbose, MANTIS_ERROR, 0, |
Andy Shevchenko | 0e44dec | 2010-09-11 14:33:27 -0300 | [diff] [blame] | 71 | " MAC Address=[%pM]\n", mantis->mac_address); |
Manu Abraham | 41e840b | 2009-12-02 21:57:10 -0300 | [diff] [blame] | 72 | |
| 73 | return 0; |
| 74 | } |
| 75 | |
Manu Abraham | df0cca1 | 2009-12-02 22:07:24 -0300 | [diff] [blame] | 76 | #define MANTIS_MODEL_UNKNOWN "UNKNOWN" |
| 77 | #define MANTIS_DEV_UNKNOWN "UNKNOWN" |
| 78 | |
| 79 | struct mantis_hwconfig unknown_device = { |
| 80 | .model_name = MANTIS_MODEL_UNKNOWN, |
| 81 | .dev_type = MANTIS_DEV_UNKNOWN, |
| 82 | }; |
| 83 | |
| 84 | static void mantis_load_config(struct mantis_pci *mantis) |
| 85 | { |
| 86 | switch (mantis->subsystem_device) { |
Manu Abraham | f5ae4f6 | 2009-12-15 08:47:21 -0300 | [diff] [blame] | 87 | case MANTIS_VP_1033_DVB_S: /* VP-1033 */ |
Manu Abraham | df0cca1 | 2009-12-02 22:07:24 -0300 | [diff] [blame] | 88 | mantis->hwconfig = &vp1033_mantis_config; |
| 89 | break; |
Manu Abraham | f5ae4f6 | 2009-12-15 08:47:21 -0300 | [diff] [blame] | 90 | case MANTIS_VP_1034_DVB_S: /* VP-1034 */ |
Manu Abraham | df0cca1 | 2009-12-02 22:07:24 -0300 | [diff] [blame] | 91 | mantis->hwconfig = &vp1034_mantis_config; |
| 92 | break; |
Manu Abraham | f5ae4f6 | 2009-12-15 08:47:21 -0300 | [diff] [blame] | 93 | case MANTIS_VP_1041_DVB_S2: /* VP-1041 */ |
Manu Abraham | 35afca9 | 2009-12-04 04:47:30 -0300 | [diff] [blame] | 94 | case TECHNISAT_SKYSTAR_HD2: |
Manu Abraham | 873c8c2 | 2009-12-04 04:43:04 -0300 | [diff] [blame] | 95 | mantis->hwconfig = &vp1041_mantis_config; |
| 96 | break; |
Manu Abraham | f5ae4f6 | 2009-12-15 08:47:21 -0300 | [diff] [blame] | 97 | case MANTIS_VP_2033_DVB_C: /* VP-2033 */ |
Manu Abraham | df0cca1 | 2009-12-02 22:07:24 -0300 | [diff] [blame] | 98 | mantis->hwconfig = &vp2033_mantis_config; |
| 99 | break; |
Manu Abraham | f5ae4f6 | 2009-12-15 08:47:21 -0300 | [diff] [blame] | 100 | case MANTIS_VP_2040_DVB_C: /* VP-2040 */ |
Igor M. Liplianin | 9fa4d6a | 2012-05-09 07:23:14 -0300 | [diff] [blame] | 101 | case CINERGY_C: /* VP-2040 clone */ |
Marko Viitamaki | f5701b6 | 2009-12-04 05:32:30 -0300 | [diff] [blame] | 102 | case TECHNISAT_CABLESTAR_HD2: |
Manu Abraham | b2eb131 | 2009-12-04 04:42:22 -0300 | [diff] [blame] | 103 | mantis->hwconfig = &vp2040_mantis_config; |
| 104 | break; |
Manu Abraham | f5ae4f6 | 2009-12-15 08:47:21 -0300 | [diff] [blame] | 105 | case MANTIS_VP_3030_DVB_T: /* VP-3030 */ |
Manu Abraham | df0cca1 | 2009-12-02 22:07:24 -0300 | [diff] [blame] | 106 | mantis->hwconfig = &vp3030_mantis_config; |
| 107 | break; |
| 108 | default: |
| 109 | mantis->hwconfig = &unknown_device; |
| 110 | break; |
| 111 | } |
| 112 | } |
Manu Abraham | 41e840b | 2009-12-02 21:57:10 -0300 | [diff] [blame] | 113 | |
| 114 | int mantis_core_init(struct mantis_pci *mantis) |
| 115 | { |
| 116 | int err = 0; |
| 117 | |
Manu Abraham | df0cca1 | 2009-12-02 22:07:24 -0300 | [diff] [blame] | 118 | mantis_load_config(mantis); |
| 119 | dprintk(verbose, MANTIS_ERROR, 0, "found a %s PCI %s device on (%02x:%02x.%x),\n", |
| 120 | mantis->hwconfig->model_name, mantis->hwconfig->dev_type, |
| 121 | mantis->pdev->bus->number, PCI_SLOT(mantis->pdev->devfn), PCI_FUNC(mantis->pdev->devfn)); |
| 122 | dprintk(verbose, MANTIS_ERROR, 0, " Mantis Rev %d [%04x:%04x], ", |
| 123 | mantis->revision, |
| 124 | mantis->subsystem_vendor, mantis->subsystem_device); |
| 125 | dprintk(verbose, MANTIS_ERROR, 0, |
| 126 | "irq: %d, latency: %d\n memory: 0x%lx, mmio: 0x%p\n", |
| 127 | mantis->pdev->irq, mantis->latency, |
| 128 | mantis->mantis_addr, mantis->mantis_mmio); |
| 129 | |
Manu Abraham | f5ae4f6 | 2009-12-15 08:47:21 -0300 | [diff] [blame] | 130 | err = mantis_i2c_init(mantis); |
| 131 | if (err < 0) { |
Manu Abraham | 41e840b | 2009-12-02 21:57:10 -0300 | [diff] [blame] | 132 | dprintk(verbose, MANTIS_ERROR, 1, "Mantis I2C init failed"); |
| 133 | return err; |
| 134 | } |
Manu Abraham | f5ae4f6 | 2009-12-15 08:47:21 -0300 | [diff] [blame] | 135 | err = get_mac_address(mantis); |
| 136 | if (err < 0) { |
Manu Abraham | 41e840b | 2009-12-02 21:57:10 -0300 | [diff] [blame] | 137 | dprintk(verbose, MANTIS_ERROR, 1, "get MAC address failed"); |
| 138 | return err; |
| 139 | } |
Manu Abraham | f5ae4f6 | 2009-12-15 08:47:21 -0300 | [diff] [blame] | 140 | err = mantis_dma_init(mantis); |
| 141 | if (err < 0) { |
Manu Abraham | 41e840b | 2009-12-02 21:57:10 -0300 | [diff] [blame] | 142 | dprintk(verbose, MANTIS_ERROR, 1, "Mantis DMA init failed"); |
| 143 | return err; |
| 144 | } |
Manu Abraham | f5ae4f6 | 2009-12-15 08:47:21 -0300 | [diff] [blame] | 145 | err = mantis_dvb_init(mantis); |
| 146 | if (err < 0) { |
Manu Abraham | 41e840b | 2009-12-02 21:57:10 -0300 | [diff] [blame] | 147 | dprintk(verbose, MANTIS_DEBUG, 1, "Mantis DVB init failed"); |
| 148 | return err; |
| 149 | } |
Manu Abraham | f5ae4f6 | 2009-12-15 08:47:21 -0300 | [diff] [blame] | 150 | err = mantis_uart_init(mantis); |
| 151 | if (err < 0) { |
Manu Abraham | add2063 | 2009-12-04 05:39:57 -0300 | [diff] [blame] | 152 | dprintk(verbose, MANTIS_DEBUG, 1, "Mantis UART init failed"); |
| 153 | return err; |
| 154 | } |
Manu Abraham | 41e840b | 2009-12-02 21:57:10 -0300 | [diff] [blame] | 155 | |
| 156 | return 0; |
| 157 | } |
| 158 | |
| 159 | int mantis_core_exit(struct mantis_pci *mantis) |
| 160 | { |
Manu Abraham | 41e840b | 2009-12-02 21:57:10 -0300 | [diff] [blame] | 161 | mantis_dma_stop(mantis); |
| 162 | dprintk(verbose, MANTIS_ERROR, 1, "DMA engine stopping"); |
Manu Abraham | add2063 | 2009-12-04 05:39:57 -0300 | [diff] [blame] | 163 | |
| 164 | mantis_uart_exit(mantis); |
| 165 | dprintk(verbose, MANTIS_ERROR, 1, "UART exit failed"); |
| 166 | |
Manu Abraham | 41e840b | 2009-12-02 21:57:10 -0300 | [diff] [blame] | 167 | if (mantis_dma_exit(mantis) < 0) |
| 168 | dprintk(verbose, MANTIS_ERROR, 1, "DMA exit failed"); |
| 169 | if (mantis_dvb_exit(mantis) < 0) |
| 170 | dprintk(verbose, MANTIS_ERROR, 1, "DVB exit failed"); |
| 171 | if (mantis_i2c_exit(mantis) < 0) |
| 172 | dprintk(verbose, MANTIS_ERROR, 1, "I2C adapter delete.. failed"); |
| 173 | |
| 174 | return 0; |
| 175 | } |
| 176 | |
Manu Abraham | f5ae4f6 | 2009-12-15 08:47:21 -0300 | [diff] [blame] | 177 | /* Turn the given bit on or off. */ |
Manu Abraham | 41e840b | 2009-12-02 21:57:10 -0300 | [diff] [blame] | 178 | void gpio_set_bits(struct mantis_pci *mantis, u32 bitpos, u8 value) |
| 179 | { |
Manu Abraham | 4d5a28e | 2009-12-04 05:15:38 -0300 | [diff] [blame] | 180 | u32 cur; |
Marko Ristola | f8e26cd | 2009-12-04 04:35:35 -0300 | [diff] [blame] | 181 | |
Manu Abraham | 4d5a28e | 2009-12-04 05:15:38 -0300 | [diff] [blame] | 182 | cur = mmread(MANTIS_GPIF_ADDR); |
Manu Abraham | 41e840b | 2009-12-02 21:57:10 -0300 | [diff] [blame] | 183 | if (value) |
Manu Abraham | 4d5a28e | 2009-12-04 05:15:38 -0300 | [diff] [blame] | 184 | mantis->gpio_status = cur | (1 << bitpos); |
Manu Abraham | 41e840b | 2009-12-02 21:57:10 -0300 | [diff] [blame] | 185 | else |
Manu Abraham | 4d5a28e | 2009-12-04 05:15:38 -0300 | [diff] [blame] | 186 | mantis->gpio_status = cur & (~(1 << bitpos)); |
Manu Abraham | 41e840b | 2009-12-02 21:57:10 -0300 | [diff] [blame] | 187 | |
Manu Abraham | 4d5a28e | 2009-12-04 05:15:38 -0300 | [diff] [blame] | 188 | mmwrite(mantis->gpio_status, MANTIS_GPIF_ADDR); |
Manu Abraham | 41e840b | 2009-12-02 21:57:10 -0300 | [diff] [blame] | 189 | mmwrite(0x00, MANTIS_GPIF_DOUT); |
| 190 | udelay(100); |
Manu Abraham | 41e840b | 2009-12-02 21:57:10 -0300 | [diff] [blame] | 191 | } |
| 192 | |
Manu Abraham | f5ae4f6 | 2009-12-15 08:47:21 -0300 | [diff] [blame] | 193 | /* direction = 0 , no CI passthrough ; 1 , CI passthrough */ |
Manu Abraham | 41e840b | 2009-12-02 21:57:10 -0300 | [diff] [blame] | 194 | void mantis_set_direction(struct mantis_pci *mantis, int direction) |
| 195 | { |
| 196 | u32 reg; |
| 197 | |
| 198 | reg = mmread(0x28); |
| 199 | dprintk(verbose, MANTIS_DEBUG, 1, "TS direction setup"); |
Manu Abraham | f5ae4f6 | 2009-12-15 08:47:21 -0300 | [diff] [blame] | 200 | if (direction == 0x01) { |
| 201 | /* to CI */ |
Manu Abraham | 41e840b | 2009-12-02 21:57:10 -0300 | [diff] [blame] | 202 | reg |= 0x04; |
| 203 | mmwrite(reg, 0x28); |
| 204 | reg &= 0xff - 0x04; |
| 205 | mmwrite(reg, 0x28); |
| 206 | } else { |
| 207 | reg &= 0xff - 0x04; |
| 208 | mmwrite(reg, 0x28); |
| 209 | reg |= 0x04; |
| 210 | mmwrite(reg, 0x28); |
| 211 | } |
| 212 | } |