Linux kernel & device driver programming

Cross-Referenced Linux and Device Driver Code

[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ]
Version: [ 2.6.11.8 ] [ 2.6.25 ] [ 2.6.25.8 ] [ 2.6.31.13 ] Architecture: [ i386 ]
  1 /* cx25840 firmware functions
  2  *
  3  * This program is free software; you can redistribute it and/or
  4  * modify it under the terms of the GNU General Public License
  5  * as published by the Free Software Foundation; either version 2
  6  * of the License, or (at your option) any later version.
  7  *
  8  * This program is distributed in the hope that it will be useful,
  9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 11  * GNU General Public License for more details.
 12  *
 13  * You should have received a copy of the GNU General Public License
 14  * along with this program; if not, write to the Free Software
 15  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 16  */
 17 
 18 #include <linux/module.h>
 19 #include <linux/i2c.h>
 20 #include <linux/firmware.h>
 21 #include <media/v4l2-common.h>
 22 #include <media/cx25840.h>
 23 
 24 #include "cx25840-core.h"
 25 
 26 #define FWFILE "v4l-cx25840.fw"
 27 #define FWFILE_CX23885 "v4l-cx23885-avcore-01.fw"
 28 
 29 /*
 30  * Mike Isely <isely@pobox.com> - The FWSEND parameter controls the
 31  * size of the firmware chunks sent down the I2C bus to the chip.
 32  * Previously this had been set to 1024 but unfortunately some I2C
 33  * implementations can't transfer data in such big gulps.
 34  * Specifically, the pvrusb2 driver has a hard limit of around 60
 35  * bytes, due to the encapsulation there of I2C traffic into USB
 36  * messages.  So we have to significantly reduce this parameter.
 37  */
 38 #define FWSEND 48
 39 
 40 #define FWDEV(x) &((x)->dev)
 41 
 42 static char *firmware = FWFILE;
 43 
 44 module_param(firmware, charp, 0444);
 45 
 46 MODULE_PARM_DESC(firmware, "Firmware image [default: " FWFILE "]");
 47 
 48 static void start_fw_load(struct i2c_client *client)
 49 {
 50         /* DL_ADDR_LB=0 DL_ADDR_HB=0 */
 51         cx25840_write(client, 0x800, 0x00);
 52         cx25840_write(client, 0x801, 0x00);
 53         // DL_MAP=3 DL_AUTO_INC=0 DL_ENABLE=1
 54         cx25840_write(client, 0x803, 0x0b);
 55         /* AUTO_INC_DIS=1 */
 56         cx25840_write(client, 0x000, 0x20);
 57 }
 58 
 59 static void end_fw_load(struct i2c_client *client)
 60 {
 61         /* AUTO_INC_DIS=0 */
 62         cx25840_write(client, 0x000, 0x00);
 63         /* DL_ENABLE=0 */
 64         cx25840_write(client, 0x803, 0x03);
 65 }
 66 
 67 static int check_fw_load(struct i2c_client *client, int size)
 68 {
 69         /* DL_ADDR_HB DL_ADDR_LB */
 70         int s = cx25840_read(client, 0x801) << 8;
 71         s |= cx25840_read(client, 0x800);
 72 
 73         if (size != s) {
 74                 v4l_err(client, "firmware %s load failed\n", firmware);
 75                 return -EINVAL;
 76         }
 77 
 78         v4l_info(client, "loaded %s firmware (%d bytes)\n", firmware, size);
 79         return 0;
 80 }
 81 
 82 static int fw_write(struct i2c_client *client, u8 * data, int size)
 83 {
 84         int sent;
 85 
 86         if ((sent = i2c_master_send(client, data, size)) < size) {
 87                 v4l_err(client, "firmware load i2c failure\n");
 88                 return -ENOSYS;
 89         }
 90 
 91         return 0;
 92 }
 93 
 94 int cx25840_loadfw(struct i2c_client *client)
 95 {
 96         struct cx25840_state *state = i2c_get_clientdata(client);
 97         const struct firmware *fw = NULL;
 98         u8 buffer[4], *ptr;
 99         int size, send, retval;
100 
101         if (state->is_cx23885)
102                 firmware = FWFILE_CX23885;
103 
104         if (request_firmware(&fw, firmware, FWDEV(client)) != 0) {
105                 v4l_err(client, "unable to open firmware %s\n", firmware);
106                 return -EINVAL;
107         }
108 
109         start_fw_load(client);
110 
111         buffer[0] = 0x08;
112         buffer[1] = 0x02;
113         buffer[2] = fw->data[0];
114         buffer[3] = fw->data[1];
115         retval = fw_write(client, buffer, 4);
116 
117         if (retval < 0) {
118                 release_firmware(fw);
119                 return retval;
120         }
121 
122         size = fw->size - 2;
123         ptr = fw->data;
124         while (size > 0) {
125                 ptr[0] = 0x08;
126                 ptr[1] = 0x02;
127                 send = size > (FWSEND - 2) ? FWSEND : size + 2;
128                 retval = fw_write(client, ptr, send);
129 
130                 if (retval < 0) {
131                         release_firmware(fw);
132                         return retval;
133                 }
134 
135                 size -= FWSEND - 2;
136                 ptr += FWSEND - 2;
137         }
138 
139         end_fw_load(client);
140 
141         size = fw->size;
142         release_firmware(fw);
143 
144         return check_fw_load(client, size);
145 }
146 
  This page was automatically generated by the LXR engine.