Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame^] | 1 | /* |
| 2 | Mantis PCI bridge driver |
| 3 | |
| 4 | Copyright (C) 2005, 2006 Manu Abraham (abraham.manu@gmail.com) |
| 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 <linux/kernel.h> |
| 22 | #include <linux/i2c.h> |
| 23 | |
| 24 | #include <asm/irq.h> |
| 25 | #include <linux/signal.h> |
| 26 | #include <linux/sched.h> |
| 27 | #include <linux/interrupt.h> |
| 28 | |
| 29 | #include "dmxdev.h" |
| 30 | #include "dvbdev.h" |
| 31 | #include "dvb_demux.h" |
| 32 | #include "dvb_frontend.h" |
| 33 | #include "dvb_net.h" |
| 34 | |
| 35 | #include "mantis_common.h" |
| 36 | #include "mantis_reg.h" |
| 37 | #include "mantis_ioc.h" |
| 38 | |
| 39 | static int read_eeprom_byte(struct mantis_pci *mantis, u8 *data, u8 length) |
| 40 | { |
| 41 | struct i2c_adapter *adapter = &mantis->adapter; |
| 42 | |
| 43 | int err; |
| 44 | struct i2c_msg msg[] = { |
| 45 | { .addr = 0x50, .flags = 0, .buf = data, .len = 1 }, |
| 46 | { .addr = 0x50, .flags = I2C_M_RD, .buf = data, .len = length }, |
| 47 | }; |
| 48 | |
| 49 | err = i2c_transfer(adapter, msg, 2); |
| 50 | if (err < 0) { |
| 51 | dprintk(MANTIS_ERROR, 1, "ERROR: i2c read: < err=%i d0=0x%02x d1=0x%02x >", |
| 52 | err, data[0], data[1]); |
| 53 | |
| 54 | return err; |
| 55 | } |
| 56 | |
| 57 | return 0; |
| 58 | } |
| 59 | |
| 60 | static int write_eeprom_byte(struct mantis_pci *mantis, u8 *data, u8 length) |
| 61 | { |
| 62 | struct i2c_adapter *adapter = &mantis->adapter; |
| 63 | int err; |
| 64 | |
| 65 | struct i2c_msg msg = { .addr = 0x50, .flags = 0, .buf = data, .len = length }; |
| 66 | |
| 67 | err = i2c_transfer(adapter, &msg, 1); |
| 68 | if (err < 0) { |
| 69 | dprintk(MANTIS_ERROR, 1, "ERROR: i2c write: < err=%i length=0x%02x d0=0x%02x, d1=0x%02x >", |
| 70 | err, length, data[0], data[1]); |
| 71 | |
| 72 | return err; |
| 73 | } |
| 74 | |
| 75 | return 0; |
| 76 | } |
| 77 | |
| 78 | int mantis_get_mac(struct mantis_pci *mantis) |
| 79 | { |
| 80 | int err; |
| 81 | |
| 82 | mantis->mac_address[0] = 0x08; |
| 83 | |
| 84 | err = read_eeprom_byte(mantis, &mantis->mac_address[0], 6); |
| 85 | if (err < 0) { |
| 86 | dprintk(MANTIS_ERROR, 1, "ERROR: Mantis EEPROM read error <%d>", err); |
| 87 | |
| 88 | return err; |
| 89 | } |
| 90 | |
| 91 | dprintk(MANTIS_ERROR, 0, |
| 92 | " MAC Address=[%02x:%02x:%02x:%02x:%02x:%02x]\n", |
| 93 | mantis->mac_address[0], mantis->mac_address[1], |
| 94 | mantis->mac_address[2], mantis->mac_address[3], |
| 95 | mantis->mac_address[4], mantis->mac_address[5]); |
| 96 | |
| 97 | return 0; |
| 98 | } |
| 99 | EXPORT_SYMBOL_GPL(mantis_get_mac); |
| 100 | |
| 101 | /* Turn the given bit on or off. */ |
| 102 | void gpio_set_bits(struct mantis_pci *mantis, u32 bitpos, u8 value) |
| 103 | { |
| 104 | u32 cur; |
| 105 | |
| 106 | cur = mmread(MANTIS_GPIF_ADDR); |
| 107 | if (value) |
| 108 | mantis->gpio_status = cur | (1 << bitpos); |
| 109 | else |
| 110 | mantis->gpio_status = cur & (~(1 << bitpos)); |
| 111 | |
| 112 | mmwrite(mantis->gpio_status, MANTIS_GPIF_ADDR); |
| 113 | mmwrite(0x00, MANTIS_GPIF_DOUT); |
| 114 | } |
| 115 | EXPORT_SYMBOL_GPL(gpio_set_bits); |
| 116 | |
| 117 | int mantis_stream_control(struct mantis_pci *mantis, enum mantis_stream_control stream_ctl) |
| 118 | { |
| 119 | u32 reg; |
| 120 | |
| 121 | reg = mmread(MANTIS_CONTROL); |
| 122 | switch (stream_ctl) { |
| 123 | case STREAM_TO_HIF: |
| 124 | dprintk(MANTIS_DEBUG, 1, "Set stream to HIF"); |
| 125 | reg &= 0xff - MANTIS_BYPASS; |
| 126 | mmwrite(reg, MANTIS_CONTROL); |
| 127 | reg |= MANTIS_BYPASS; |
| 128 | mmwrite(reg, MANTIS_CONTROL); |
| 129 | break; |
| 130 | |
| 131 | case STREAM_TO_CAM: |
| 132 | dprintk(MANTIS_DEBUG, 1, "Set stream to CAM"); |
| 133 | reg |= MANTIS_BYPASS; |
| 134 | mmwrite(reg, MANTIS_CONTROL); |
| 135 | reg &= 0xff - MANTIS_BYPASS; |
| 136 | mmwrite(reg, MANTIS_CONTROL); |
| 137 | break; |
| 138 | default: |
| 139 | dprintk(MANTIS_ERROR, 1, "Unknown MODE <%02x>", stream_ctl); |
| 140 | return -1; |
| 141 | } |
| 142 | |
| 143 | return 0; |
| 144 | } |
| 145 | EXPORT_SYMBOL_GPL(mantis_stream_control); |