diff options
Diffstat (limited to 'drivers/media/dvb/mantis/mantis_ioc.c')
| -rw-r--r-- | drivers/media/dvb/mantis/mantis_ioc.c | 124 |
1 files changed, 124 insertions, 0 deletions
diff --git a/drivers/media/dvb/mantis/mantis_ioc.c b/drivers/media/dvb/mantis/mantis_ioc.c new file mode 100644 index 00000000000..24fcdc63d6d --- /dev/null +++ b/drivers/media/dvb/mantis/mantis_ioc.c | |||
| @@ -0,0 +1,124 @@ | |||
| 1 | /* | ||
| 2 | Mantis PCI bridge driver | ||
| 3 | |||
| 4 | Copyright (C) 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 <linux/signal.h> | ||
| 25 | #include <linux/sched.h> | ||
| 26 | #include <linux/interrupt.h> | ||
| 27 | #include <asm/io.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_bytes(struct mantis_pci *mantis, u8 reg, u8 *data, u8 length) | ||
| 40 | { | ||
| 41 | struct i2c_adapter *adapter = &mantis->adapter; | ||
| 42 | int err; | ||
| 43 | u8 buf = reg; | ||
| 44 | |||
| 45 | struct i2c_msg msg[] = { | ||
| 46 | { .addr = 0x50, .flags = 0, .buf = &buf, .len = 1 }, | ||
| 47 | { .addr = 0x50, .flags = I2C_M_RD, .buf = data, .len = length }, | ||
| 48 | }; | ||
| 49 | |||
| 50 | err = i2c_transfer(adapter, msg, 2); | ||
| 51 | if (err < 0) { | ||
| 52 | dprintk(MANTIS_ERROR, 1, "ERROR: i2c read: < err=%i d0=0x%02x d1=0x%02x >", | ||
| 53 | err, data[0], data[1]); | ||
| 54 | |||
| 55 | return err; | ||
| 56 | } | ||
| 57 | |||
| 58 | return 0; | ||
| 59 | } | ||
| 60 | int mantis_get_mac(struct mantis_pci *mantis) | ||
| 61 | { | ||
| 62 | int err; | ||
| 63 | u8 mac_addr[6] = {0}; | ||
| 64 | |||
| 65 | err = read_eeprom_bytes(mantis, 0x08, mac_addr, 6); | ||
| 66 | if (err < 0) { | ||
| 67 | dprintk(MANTIS_ERROR, 1, "ERROR: Mantis EEPROM read error <%d>", err); | ||
| 68 | |||
| 69 | return err; | ||
| 70 | } | ||
| 71 | |||
| 72 | dprintk(MANTIS_ERROR, 0, " MAC Address=[%pM]\n", mac_addr); | ||
| 73 | |||
| 74 | return 0; | ||
| 75 | } | ||
| 76 | EXPORT_SYMBOL_GPL(mantis_get_mac); | ||
| 77 | |||
| 78 | /* Turn the given bit on or off. */ | ||
| 79 | void mantis_gpio_set_bits(struct mantis_pci *mantis, u32 bitpos, u8 value) | ||
| 80 | { | ||
| 81 | u32 cur; | ||
| 82 | |||
| 83 | dprintk(MANTIS_DEBUG, 1, "Set Bit <%d> to <%d>", bitpos, value); | ||
| 84 | cur = mmread(MANTIS_GPIF_ADDR); | ||
| 85 | if (value) | ||
| 86 | mantis->gpio_status = cur | (1 << bitpos); | ||
| 87 | else | ||
| 88 | mantis->gpio_status = cur & (~(1 << bitpos)); | ||
| 89 | |||
| 90 | dprintk(MANTIS_DEBUG, 1, "GPIO Value <%02x>", mantis->gpio_status); | ||
| 91 | mmwrite(mantis->gpio_status, MANTIS_GPIF_ADDR); | ||
| 92 | mmwrite(0x00, MANTIS_GPIF_DOUT); | ||
| 93 | } | ||
| 94 | EXPORT_SYMBOL_GPL(mantis_gpio_set_bits); | ||
| 95 | |||
| 96 | int mantis_stream_control(struct mantis_pci *mantis, enum mantis_stream_control stream_ctl) | ||
| 97 | { | ||
| 98 | u32 reg; | ||
| 99 | |||
| 100 | reg = mmread(MANTIS_CONTROL); | ||
| 101 | switch (stream_ctl) { | ||
| 102 | case STREAM_TO_HIF: | ||
| 103 | dprintk(MANTIS_DEBUG, 1, "Set stream to HIF"); | ||
| 104 | reg &= 0xff - MANTIS_BYPASS; | ||
| 105 | mmwrite(reg, MANTIS_CONTROL); | ||
| 106 | reg |= MANTIS_BYPASS; | ||
| 107 | mmwrite(reg, MANTIS_CONTROL); | ||
| 108 | break; | ||
| 109 | |||
| 110 | case STREAM_TO_CAM: | ||
| 111 | dprintk(MANTIS_DEBUG, 1, "Set stream to CAM"); | ||
| 112 | reg |= MANTIS_BYPASS; | ||
| 113 | mmwrite(reg, MANTIS_CONTROL); | ||
| 114 | reg &= 0xff - MANTIS_BYPASS; | ||
| 115 | mmwrite(reg, MANTIS_CONTROL); | ||
| 116 | break; | ||
| 117 | default: | ||
| 118 | dprintk(MANTIS_ERROR, 1, "Unknown MODE <%02x>", stream_ctl); | ||
| 119 | return -1; | ||
| 120 | } | ||
| 121 | |||
| 122 | return 0; | ||
| 123 | } | ||
| 124 | EXPORT_SYMBOL_GPL(mantis_stream_control); | ||
