Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -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 | b3b9614 | 2009-12-04 05:41:11 -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 <linux/kernel.h> |
| 22 | #include <linux/i2c.h> |
| 23 | |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 24 | #include <linux/signal.h> |
| 25 | #include <linux/sched.h> |
| 26 | #include <linux/interrupt.h> |
| 27 | |
| 28 | #include "dmxdev.h" |
| 29 | #include "dvbdev.h" |
| 30 | #include "dvb_demux.h" |
| 31 | #include "dvb_frontend.h" |
| 32 | #include "dvb_net.h" |
| 33 | |
| 34 | #include "mantis_common.h" |
| 35 | #include "mantis_reg.h" |
| 36 | #include "mantis_ioc.h" |
| 37 | |
Manu Abraham | 3e978a8 | 2009-12-04 05:56:35 -0300 | [diff] [blame] | 38 | static int read_eeprom_bytes(struct mantis_pci *mantis, u8 reg, u8 *data, u8 length) |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 39 | { |
| 40 | struct i2c_adapter *adapter = &mantis->adapter; |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 41 | int err; |
Manu Abraham | 3e978a8 | 2009-12-04 05:56:35 -0300 | [diff] [blame] | 42 | u8 buf = reg; |
| 43 | |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 44 | struct i2c_msg msg[] = { |
Manu Abraham | 3e978a8 | 2009-12-04 05:56:35 -0300 | [diff] [blame] | 45 | { .addr = 0x50, .flags = 0, .buf = &buf, .len = 1 }, |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 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 | } |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 59 | int mantis_get_mac(struct mantis_pci *mantis) |
| 60 | { |
| 61 | int err; |
Manu Abraham | 3e978a8 | 2009-12-04 05:56:35 -0300 | [diff] [blame] | 62 | u8 mac_addr[6] = {0}; |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 63 | |
Manu Abraham | 3e978a8 | 2009-12-04 05:56:35 -0300 | [diff] [blame] | 64 | err = read_eeprom_bytes(mantis, 0x08, mac_addr, 6); |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 65 | if (err < 0) { |
| 66 | dprintk(MANTIS_ERROR, 1, "ERROR: Mantis EEPROM read error <%d>", err); |
| 67 | |
| 68 | return err; |
| 69 | } |
| 70 | |
Andy Shevchenko | 0e44dec | 2010-09-11 14:33:27 -0300 | [diff] [blame] | 71 | dprintk(MANTIS_ERROR, 0, " MAC Address=[%pM]\n", mac_addr); |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 72 | |
| 73 | return 0; |
| 74 | } |
| 75 | EXPORT_SYMBOL_GPL(mantis_get_mac); |
| 76 | |
| 77 | /* Turn the given bit on or off. */ |
Ben Hutchings | 3037fd1 | 2010-11-14 14:56:00 -0300 | [diff] [blame^] | 78 | void mantis_gpio_set_bits(struct mantis_pci *mantis, u32 bitpos, u8 value) |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 79 | { |
| 80 | u32 cur; |
| 81 | |
Manu Abraham | 3e978a8 | 2009-12-04 05:56:35 -0300 | [diff] [blame] | 82 | dprintk(MANTIS_DEBUG, 1, "Set Bit <%d> to <%d>", bitpos, value); |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 83 | cur = mmread(MANTIS_GPIF_ADDR); |
| 84 | if (value) |
| 85 | mantis->gpio_status = cur | (1 << bitpos); |
| 86 | else |
| 87 | mantis->gpio_status = cur & (~(1 << bitpos)); |
| 88 | |
Manu Abraham | 3e978a8 | 2009-12-04 05:56:35 -0300 | [diff] [blame] | 89 | dprintk(MANTIS_DEBUG, 1, "GPIO Value <%02x>", mantis->gpio_status); |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 90 | mmwrite(mantis->gpio_status, MANTIS_GPIF_ADDR); |
| 91 | mmwrite(0x00, MANTIS_GPIF_DOUT); |
| 92 | } |
Ben Hutchings | 3037fd1 | 2010-11-14 14:56:00 -0300 | [diff] [blame^] | 93 | EXPORT_SYMBOL_GPL(mantis_gpio_set_bits); |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 94 | |
| 95 | int mantis_stream_control(struct mantis_pci *mantis, enum mantis_stream_control stream_ctl) |
| 96 | { |
| 97 | u32 reg; |
| 98 | |
| 99 | reg = mmread(MANTIS_CONTROL); |
| 100 | switch (stream_ctl) { |
| 101 | case STREAM_TO_HIF: |
| 102 | dprintk(MANTIS_DEBUG, 1, "Set stream to HIF"); |
| 103 | reg &= 0xff - MANTIS_BYPASS; |
| 104 | mmwrite(reg, MANTIS_CONTROL); |
| 105 | reg |= MANTIS_BYPASS; |
| 106 | mmwrite(reg, MANTIS_CONTROL); |
| 107 | break; |
| 108 | |
| 109 | case STREAM_TO_CAM: |
| 110 | dprintk(MANTIS_DEBUG, 1, "Set stream to CAM"); |
| 111 | reg |= MANTIS_BYPASS; |
| 112 | mmwrite(reg, MANTIS_CONTROL); |
| 113 | reg &= 0xff - MANTIS_BYPASS; |
| 114 | mmwrite(reg, MANTIS_CONTROL); |
| 115 | break; |
| 116 | default: |
| 117 | dprintk(MANTIS_ERROR, 1, "Unknown MODE <%02x>", stream_ctl); |
| 118 | return -1; |
| 119 | } |
| 120 | |
| 121 | return 0; |
| 122 | } |
| 123 | EXPORT_SYMBOL_GPL(mantis_stream_control); |