diff options
| author | Devin Heitmueller <dheitmueller@kernellabs.com> | 2010-03-13 15:10:24 -0500 |
|---|---|---|
| committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2010-05-19 11:59:07 -0400 |
| commit | cb1c0f8e7099ef5ba20c046df3a3790b5683c573 (patch) | |
| tree | 7760ce95dd9d38069e53d8281ca6fac2d581641e | |
| parent | 0abf26291d95b09eda44453a0c0655a54b8d90f7 (diff) | |
V4L/DVB: ngene: split out i2c code into a separate file
Split out the i2c related code from the ngene-core.c into a new file called
ngene-i2c.c. This is part of a larger refactoring of the driver in preparation
for adding analog support.
Note that this patch makes *no* functional change - all I did was cut/paste the
code and add the function prototypes to ngene.h as needed.
Signed-off-by: Devin Heitmueller <dheitmueller@kernellabs.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
| -rw-r--r-- | drivers/media/dvb/ngene/Makefile | 2 | ||||
| -rw-r--r-- | drivers/media/dvb/ngene/ngene-core.c | 137 | ||||
| -rw-r--r-- | drivers/media/dvb/ngene/ngene-i2c.c | 179 | ||||
| -rw-r--r-- | drivers/media/dvb/ngene/ngene.h | 7 |
4 files changed, 190 insertions, 135 deletions
diff --git a/drivers/media/dvb/ngene/Makefile b/drivers/media/dvb/ngene/Makefile index df2c593c9951..5e7d310c6edb 100644 --- a/drivers/media/dvb/ngene/Makefile +++ b/drivers/media/dvb/ngene/Makefile | |||
| @@ -2,7 +2,7 @@ | |||
| 2 | # Makefile for the nGene device driver | 2 | # Makefile for the nGene device driver |
| 3 | # | 3 | # |
| 4 | 4 | ||
| 5 | ngene-objs := ngene-core.o | 5 | ngene-objs := ngene-core.o ngene-i2c.o |
| 6 | 6 | ||
| 7 | obj-$(CONFIG_DVB_NGENE) += ngene.o | 7 | obj-$(CONFIG_DVB_NGENE) += ngene.o |
| 8 | 8 | ||
diff --git a/drivers/media/dvb/ngene/ngene-core.c b/drivers/media/dvb/ngene/ngene-core.c index ae1f6127f142..fedd341eb015 100644 --- a/drivers/media/dvb/ngene/ngene-core.c +++ b/drivers/media/dvb/ngene/ngene-core.c | |||
| @@ -353,7 +353,7 @@ static int ngene_command_mutex(struct ngene *dev, struct ngene_command *com) | |||
| 353 | return 0; | 353 | return 0; |
| 354 | } | 354 | } |
| 355 | 355 | ||
| 356 | static int ngene_command(struct ngene *dev, struct ngene_command *com) | 356 | int ngene_command(struct ngene *dev, struct ngene_command *com) |
| 357 | { | 357 | { |
| 358 | int result; | 358 | int result; |
| 359 | 359 | ||
| @@ -364,55 +364,6 @@ static int ngene_command(struct ngene *dev, struct ngene_command *com) | |||
| 364 | } | 364 | } |
| 365 | 365 | ||
| 366 | 366 | ||
| 367 | static int ngene_command_i2c_read(struct ngene *dev, u8 adr, | ||
| 368 | u8 *out, u8 outlen, u8 *in, u8 inlen, int flag) | ||
| 369 | { | ||
| 370 | struct ngene_command com; | ||
| 371 | |||
| 372 | com.cmd.hdr.Opcode = CMD_I2C_READ; | ||
| 373 | com.cmd.hdr.Length = outlen + 3; | ||
| 374 | com.cmd.I2CRead.Device = adr << 1; | ||
| 375 | memcpy(com.cmd.I2CRead.Data, out, outlen); | ||
| 376 | com.cmd.I2CRead.Data[outlen] = inlen; | ||
| 377 | com.cmd.I2CRead.Data[outlen + 1] = 0; | ||
| 378 | com.in_len = outlen + 3; | ||
| 379 | com.out_len = inlen + 1; | ||
| 380 | |||
| 381 | if (ngene_command(dev, &com) < 0) | ||
| 382 | return -EIO; | ||
| 383 | |||
| 384 | if ((com.cmd.raw8[0] >> 1) != adr) | ||
| 385 | return -EIO; | ||
| 386 | |||
| 387 | if (flag) | ||
| 388 | memcpy(in, com.cmd.raw8, inlen + 1); | ||
| 389 | else | ||
| 390 | memcpy(in, com.cmd.raw8 + 1, inlen); | ||
| 391 | return 0; | ||
| 392 | } | ||
| 393 | |||
| 394 | static int ngene_command_i2c_write(struct ngene *dev, u8 adr, | ||
| 395 | u8 *out, u8 outlen) | ||
| 396 | { | ||
| 397 | struct ngene_command com; | ||
| 398 | |||
| 399 | |||
| 400 | com.cmd.hdr.Opcode = CMD_I2C_WRITE; | ||
| 401 | com.cmd.hdr.Length = outlen + 1; | ||
| 402 | com.cmd.I2CRead.Device = adr << 1; | ||
| 403 | memcpy(com.cmd.I2CRead.Data, out, outlen); | ||
| 404 | com.in_len = outlen + 1; | ||
| 405 | com.out_len = 1; | ||
| 406 | |||
| 407 | if (ngene_command(dev, &com) < 0) | ||
| 408 | return -EIO; | ||
| 409 | |||
| 410 | if (com.cmd.raw8[0] == 1) | ||
| 411 | return -EIO; | ||
| 412 | |||
| 413 | return 0; | ||
| 414 | } | ||
| 415 | |||
| 416 | static int ngene_command_load_firmware(struct ngene *dev, | 367 | static int ngene_command_load_firmware(struct ngene *dev, |
| 417 | u8 *ngene_fw, u32 size) | 368 | u8 *ngene_fw, u32 size) |
| 418 | { | 369 | { |
| @@ -478,7 +429,7 @@ static int ngene_command_config_free_buf(struct ngene *dev, u8 *config) | |||
| 478 | return 0; | 429 | return 0; |
| 479 | } | 430 | } |
| 480 | 431 | ||
| 481 | static int ngene_command_gpio_set(struct ngene *dev, u8 select, u8 level) | 432 | int ngene_command_gpio_set(struct ngene *dev, u8 select, u8 level) |
| 482 | { | 433 | { |
| 483 | struct ngene_command com; | 434 | struct ngene_command com; |
| 484 | 435 | ||
| @@ -776,91 +727,9 @@ static int ngene_command_stream_control(struct ngene *dev, u8 stream, | |||
| 776 | 727 | ||
| 777 | 728 | ||
| 778 | /****************************************************************************/ | 729 | /****************************************************************************/ |
| 779 | /* I2C **********************************************************************/ | 730 | /* EEPROM TAGS **************************************************************/ |
| 780 | /****************************************************************************/ | 731 | /****************************************************************************/ |
| 781 | 732 | ||
| 782 | static void ngene_i2c_set_bus(struct ngene *dev, int bus) | ||
| 783 | { | ||
| 784 | if (!(dev->card_info->i2c_access & 2)) | ||
| 785 | return; | ||
| 786 | if (dev->i2c_current_bus == bus) | ||
| 787 | return; | ||
| 788 | |||
| 789 | switch (bus) { | ||
| 790 | case 0: | ||
| 791 | ngene_command_gpio_set(dev, 3, 0); | ||
| 792 | ngene_command_gpio_set(dev, 2, 1); | ||
| 793 | break; | ||
| 794 | |||
| 795 | case 1: | ||
| 796 | ngene_command_gpio_set(dev, 2, 0); | ||
| 797 | ngene_command_gpio_set(dev, 3, 1); | ||
| 798 | break; | ||
| 799 | } | ||
| 800 | dev->i2c_current_bus = bus; | ||
| 801 | } | ||
| 802 | |||
| 803 | static int ngene_i2c_master_xfer(struct i2c_adapter *adapter, | ||
| 804 | struct i2c_msg msg[], int num) | ||
| 805 | { | ||
| 806 | struct ngene_channel *chan = | ||
| 807 | (struct ngene_channel *)i2c_get_adapdata(adapter); | ||
| 808 | struct ngene *dev = chan->dev; | ||
| 809 | |||
| 810 | down(&dev->i2c_switch_mutex); | ||
| 811 | ngene_i2c_set_bus(dev, chan->number); | ||
| 812 | |||
| 813 | if (num == 2 && msg[1].flags & I2C_M_RD && !(msg[0].flags & I2C_M_RD)) | ||
| 814 | if (!ngene_command_i2c_read(dev, msg[0].addr, | ||
| 815 | msg[0].buf, msg[0].len, | ||
| 816 | msg[1].buf, msg[1].len, 0)) | ||
| 817 | goto done; | ||
| 818 | |||
| 819 | if (num == 1 && !(msg[0].flags & I2C_M_RD)) | ||
| 820 | if (!ngene_command_i2c_write(dev, msg[0].addr, | ||
| 821 | msg[0].buf, msg[0].len)) | ||
| 822 | goto done; | ||
| 823 | if (num == 1 && (msg[0].flags & I2C_M_RD)) | ||
| 824 | if (!ngene_command_i2c_read(dev, msg[0].addr, NULL, 0, | ||
| 825 | msg[0].buf, msg[0].len, 0)) | ||
| 826 | goto done; | ||
| 827 | |||
| 828 | up(&dev->i2c_switch_mutex); | ||
| 829 | return -EIO; | ||
| 830 | |||
| 831 | done: | ||
| 832 | up(&dev->i2c_switch_mutex); | ||
| 833 | return num; | ||
| 834 | } | ||
| 835 | |||
| 836 | |||
| 837 | static u32 ngene_i2c_functionality(struct i2c_adapter *adap) | ||
| 838 | { | ||
| 839 | return I2C_FUNC_SMBUS_EMUL; | ||
| 840 | } | ||
| 841 | |||
| 842 | static struct i2c_algorithm ngene_i2c_algo = { | ||
| 843 | .master_xfer = ngene_i2c_master_xfer, | ||
| 844 | .functionality = ngene_i2c_functionality, | ||
| 845 | }; | ||
| 846 | |||
| 847 | static int ngene_i2c_init(struct ngene *dev, int dev_nr) | ||
| 848 | { | ||
| 849 | struct i2c_adapter *adap = &(dev->channel[dev_nr].i2c_adapter); | ||
| 850 | |||
| 851 | i2c_set_adapdata(adap, &(dev->channel[dev_nr])); | ||
| 852 | adap->class = I2C_CLASS_TV_DIGITAL | I2C_CLASS_TV_ANALOG; | ||
| 853 | |||
| 854 | strcpy(adap->name, "nGene"); | ||
| 855 | |||
| 856 | adap->algo = &ngene_i2c_algo; | ||
| 857 | adap->algo_data = (void *)&(dev->channel[dev_nr]); | ||
| 858 | adap->dev.parent = &dev->pci_dev->dev; | ||
| 859 | |||
| 860 | return i2c_add_adapter(adap); | ||
| 861 | } | ||
| 862 | |||
| 863 | |||
| 864 | /****************************************************************************/ | 733 | /****************************************************************************/ |
| 865 | /* DVB functions and API interface ******************************************/ | 734 | /* DVB functions and API interface ******************************************/ |
| 866 | /****************************************************************************/ | 735 | /****************************************************************************/ |
diff --git a/drivers/media/dvb/ngene/ngene-i2c.c b/drivers/media/dvb/ngene/ngene-i2c.c new file mode 100644 index 000000000000..2ef54ca6badd --- /dev/null +++ b/drivers/media/dvb/ngene/ngene-i2c.c | |||
| @@ -0,0 +1,179 @@ | |||
| 1 | /* | ||
| 2 | * ngene-i2c.c: nGene PCIe bridge driver i2c functions | ||
| 3 | * | ||
| 4 | * Copyright (C) 2005-2007 Micronas | ||
| 5 | * | ||
| 6 | * Copyright (C) 2008-2009 Ralph Metzler <rjkm@metzlerbros.de> | ||
| 7 | * Modifications for new nGene firmware, | ||
| 8 | * support for EEPROM-copying, | ||
| 9 | * support for new dual DVB-S2 card prototype | ||
| 10 | * | ||
| 11 | * | ||
| 12 | * This program is free software; you can redistribute it and/or | ||
| 13 | * modify it under the terms of the GNU General Public License | ||
| 14 | * version 2 only, as published by the Free Software Foundation. | ||
| 15 | * | ||
| 16 | * | ||
| 17 | * This program is distributed in the hope that it will be useful, | ||
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 20 | * GNU General Public License for more details. | ||
| 21 | * | ||
| 22 | * | ||
| 23 | * You should have received a copy of the GNU General Public License | ||
| 24 | * along with this program; if not, write to the Free Software | ||
| 25 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
| 26 | * 02110-1301, USA | ||
| 27 | * Or, point your browser to http://www.gnu.org/copyleft/gpl.html | ||
| 28 | */ | ||
| 29 | |||
| 30 | /* FIXME - some of these can probably be removed */ | ||
| 31 | #include <linux/module.h> | ||
| 32 | #include <linux/init.h> | ||
| 33 | #include <linux/delay.h> | ||
| 34 | #include <linux/slab.h> | ||
| 35 | #include <linux/poll.h> | ||
| 36 | #include <linux/io.h> | ||
| 37 | #include <asm/div64.h> | ||
| 38 | #include <linux/pci.h> | ||
| 39 | #include <linux/pci_ids.h> | ||
| 40 | #include <linux/smp_lock.h> | ||
| 41 | #include <linux/timer.h> | ||
| 42 | #include <linux/version.h> | ||
| 43 | #include <linux/byteorder/generic.h> | ||
| 44 | #include <linux/firmware.h> | ||
| 45 | #include <linux/vmalloc.h> | ||
| 46 | |||
| 47 | #include "ngene.h" | ||
| 48 | |||
| 49 | /* Firmware command for i2c operations */ | ||
| 50 | static int ngene_command_i2c_read(struct ngene *dev, u8 adr, | ||
| 51 | u8 *out, u8 outlen, u8 *in, u8 inlen, int flag) | ||
| 52 | { | ||
| 53 | struct ngene_command com; | ||
| 54 | |||
| 55 | com.cmd.hdr.Opcode = CMD_I2C_READ; | ||
| 56 | com.cmd.hdr.Length = outlen + 3; | ||
| 57 | com.cmd.I2CRead.Device = adr << 1; | ||
| 58 | memcpy(com.cmd.I2CRead.Data, out, outlen); | ||
| 59 | com.cmd.I2CRead.Data[outlen] = inlen; | ||
| 60 | com.cmd.I2CRead.Data[outlen + 1] = 0; | ||
| 61 | com.in_len = outlen + 3; | ||
| 62 | com.out_len = inlen + 1; | ||
| 63 | |||
| 64 | if (ngene_command(dev, &com) < 0) | ||
| 65 | return -EIO; | ||
| 66 | |||
| 67 | if ((com.cmd.raw8[0] >> 1) != adr) | ||
| 68 | return -EIO; | ||
| 69 | |||
| 70 | if (flag) | ||
| 71 | memcpy(in, com.cmd.raw8, inlen + 1); | ||
| 72 | else | ||
| 73 | memcpy(in, com.cmd.raw8 + 1, inlen); | ||
| 74 | return 0; | ||
| 75 | } | ||
| 76 | |||
| 77 | static int ngene_command_i2c_write(struct ngene *dev, u8 adr, | ||
| 78 | u8 *out, u8 outlen) | ||
| 79 | { | ||
| 80 | struct ngene_command com; | ||
| 81 | |||
| 82 | |||
| 83 | com.cmd.hdr.Opcode = CMD_I2C_WRITE; | ||
| 84 | com.cmd.hdr.Length = outlen + 1; | ||
| 85 | com.cmd.I2CRead.Device = adr << 1; | ||
| 86 | memcpy(com.cmd.I2CRead.Data, out, outlen); | ||
| 87 | com.in_len = outlen + 1; | ||
| 88 | com.out_len = 1; | ||
| 89 | |||
| 90 | if (ngene_command(dev, &com) < 0) | ||
| 91 | return -EIO; | ||
| 92 | |||
| 93 | if (com.cmd.raw8[0] == 1) | ||
| 94 | return -EIO; | ||
| 95 | |||
| 96 | return 0; | ||
| 97 | } | ||
| 98 | |||
| 99 | static void ngene_i2c_set_bus(struct ngene *dev, int bus) | ||
| 100 | { | ||
| 101 | if (!(dev->card_info->i2c_access & 2)) | ||
| 102 | return; | ||
| 103 | if (dev->i2c_current_bus == bus) | ||
| 104 | return; | ||
| 105 | |||
| 106 | switch (bus) { | ||
| 107 | case 0: | ||
| 108 | ngene_command_gpio_set(dev, 3, 0); | ||
| 109 | ngene_command_gpio_set(dev, 2, 1); | ||
| 110 | break; | ||
| 111 | |||
| 112 | case 1: | ||
| 113 | ngene_command_gpio_set(dev, 2, 0); | ||
| 114 | ngene_command_gpio_set(dev, 3, 1); | ||
| 115 | break; | ||
| 116 | } | ||
| 117 | dev->i2c_current_bus = bus; | ||
| 118 | } | ||
| 119 | |||
| 120 | static int ngene_i2c_master_xfer(struct i2c_adapter *adapter, | ||
| 121 | struct i2c_msg msg[], int num) | ||
| 122 | { | ||
| 123 | struct ngene_channel *chan = | ||
| 124 | (struct ngene_channel *)i2c_get_adapdata(adapter); | ||
| 125 | struct ngene *dev = chan->dev; | ||
| 126 | |||
| 127 | down(&dev->i2c_switch_mutex); | ||
| 128 | ngene_i2c_set_bus(dev, chan->number); | ||
| 129 | |||
| 130 | if (num == 2 && msg[1].flags & I2C_M_RD && !(msg[0].flags & I2C_M_RD)) | ||
| 131 | if (!ngene_command_i2c_read(dev, msg[0].addr, | ||
| 132 | msg[0].buf, msg[0].len, | ||
| 133 | msg[1].buf, msg[1].len, 0)) | ||
| 134 | goto done; | ||
| 135 | |||
| 136 | if (num == 1 && !(msg[0].flags & I2C_M_RD)) | ||
| 137 | if (!ngene_command_i2c_write(dev, msg[0].addr, | ||
| 138 | msg[0].buf, msg[0].len)) | ||
| 139 | goto done; | ||
| 140 | if (num == 1 && (msg[0].flags & I2C_M_RD)) | ||
| 141 | if (!ngene_command_i2c_read(dev, msg[0].addr, NULL, 0, | ||
| 142 | msg[0].buf, msg[0].len, 0)) | ||
| 143 | goto done; | ||
| 144 | |||
| 145 | up(&dev->i2c_switch_mutex); | ||
| 146 | return -EIO; | ||
| 147 | |||
| 148 | done: | ||
| 149 | up(&dev->i2c_switch_mutex); | ||
| 150 | return num; | ||
| 151 | } | ||
| 152 | |||
| 153 | |||
| 154 | static u32 ngene_i2c_functionality(struct i2c_adapter *adap) | ||
| 155 | { | ||
| 156 | return I2C_FUNC_SMBUS_EMUL; | ||
| 157 | } | ||
| 158 | |||
| 159 | static struct i2c_algorithm ngene_i2c_algo = { | ||
| 160 | .master_xfer = ngene_i2c_master_xfer, | ||
| 161 | .functionality = ngene_i2c_functionality, | ||
| 162 | }; | ||
| 163 | |||
| 164 | int ngene_i2c_init(struct ngene *dev, int dev_nr) | ||
| 165 | { | ||
| 166 | struct i2c_adapter *adap = &(dev->channel[dev_nr].i2c_adapter); | ||
| 167 | |||
| 168 | i2c_set_adapdata(adap, &(dev->channel[dev_nr])); | ||
| 169 | adap->class = I2C_CLASS_TV_DIGITAL | I2C_CLASS_TV_ANALOG; | ||
| 170 | |||
| 171 | strcpy(adap->name, "nGene"); | ||
| 172 | |||
| 173 | adap->algo = &ngene_i2c_algo; | ||
| 174 | adap->algo_data = (void *)&(dev->channel[dev_nr]); | ||
| 175 | adap->dev.parent = &dev->pci_dev->dev; | ||
| 176 | |||
| 177 | return i2c_add_adapter(adap); | ||
| 178 | } | ||
| 179 | |||
diff --git a/drivers/media/dvb/ngene/ngene.h b/drivers/media/dvb/ngene/ngene.h index ca3af5c6238f..0c2d5a7d183a 100644 --- a/drivers/media/dvb/ngene/ngene.h +++ b/drivers/media/dvb/ngene/ngene.h | |||
| @@ -854,6 +854,13 @@ struct ngene_buffer { | |||
| 854 | #endif | 854 | #endif |
| 855 | 855 | ||
| 856 | 856 | ||
| 857 | /* Provided by ngene-core.c */ | ||
| 858 | int ngene_command(struct ngene *dev, struct ngene_command *com); | ||
| 859 | int ngene_command_gpio_set(struct ngene *dev, u8 select, u8 level); | ||
| 860 | |||
| 861 | /* Provided by ngene-i2c.c */ | ||
| 862 | int ngene_i2c_init(struct ngene *dev, int dev_nr); | ||
| 863 | |||
| 857 | #endif | 864 | #endif |
| 858 | 865 | ||
| 859 | /* LocalWords: Endif | 866 | /* LocalWords: Endif |
