2005-11-14 00:07:56 +00:00
|
|
|
/* cx25840 firmware functions
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/i2c.h>
|
|
|
|
#include <linux/firmware.h>
|
|
|
|
#include <media/v4l2-common.h>
|
2006-03-25 13:26:09 +00:00
|
|
|
#include <media/cx25840.h>
|
2005-11-14 00:07:56 +00:00
|
|
|
|
2006-03-25 13:26:09 +00:00
|
|
|
#include "cx25840-core.h"
|
2005-11-14 00:07:56 +00:00
|
|
|
|
2006-03-25 23:43:14 +00:00
|
|
|
/*
|
|
|
|
* Mike Isely <isely@pobox.com> - The FWSEND parameter controls the
|
|
|
|
* size of the firmware chunks sent down the I2C bus to the chip.
|
|
|
|
* Previously this had been set to 1024 but unfortunately some I2C
|
|
|
|
* implementations can't transfer data in such big gulps.
|
|
|
|
* Specifically, the pvrusb2 driver has a hard limit of around 60
|
|
|
|
* bytes, due to the encapsulation there of I2C traffic into USB
|
|
|
|
* messages. So we have to significantly reduce this parameter.
|
|
|
|
*/
|
|
|
|
#define FWSEND 48
|
2005-11-14 00:07:56 +00:00
|
|
|
|
2007-02-15 06:40:34 +00:00
|
|
|
#define FWDEV(x) &((x)->dev)
|
2005-11-14 00:07:56 +00:00
|
|
|
|
2009-08-31 20:57:52 +00:00
|
|
|
static char *firmware = "";
|
2005-11-14 00:07:56 +00:00
|
|
|
|
|
|
|
module_param(firmware, charp, 0444);
|
|
|
|
|
2009-08-31 20:57:52 +00:00
|
|
|
MODULE_PARM_DESC(firmware, "Firmware image to load");
|
2005-11-14 00:07:56 +00:00
|
|
|
|
2006-01-09 17:32:41 +00:00
|
|
|
static void start_fw_load(struct i2c_client *client)
|
2005-11-14 00:07:56 +00:00
|
|
|
{
|
|
|
|
/* DL_ADDR_LB=0 DL_ADDR_HB=0 */
|
|
|
|
cx25840_write(client, 0x800, 0x00);
|
|
|
|
cx25840_write(client, 0x801, 0x00);
|
|
|
|
// DL_MAP=3 DL_AUTO_INC=0 DL_ENABLE=1
|
|
|
|
cx25840_write(client, 0x803, 0x0b);
|
|
|
|
/* AUTO_INC_DIS=1 */
|
|
|
|
cx25840_write(client, 0x000, 0x20);
|
|
|
|
}
|
|
|
|
|
2006-01-09 17:32:41 +00:00
|
|
|
static void end_fw_load(struct i2c_client *client)
|
2005-11-14 00:07:56 +00:00
|
|
|
{
|
|
|
|
/* AUTO_INC_DIS=0 */
|
|
|
|
cx25840_write(client, 0x000, 0x00);
|
|
|
|
/* DL_ENABLE=0 */
|
|
|
|
cx25840_write(client, 0x803, 0x03);
|
|
|
|
}
|
|
|
|
|
2012-07-26 15:44:19 +00:00
|
|
|
#define CX2388x_FIRMWARE "v4l-cx23885-avcore-01.fw"
|
|
|
|
#define CX231xx_FIRMWARE "v4l-cx231xx-avcore-01.fw"
|
|
|
|
#define CX25840_FIRMWARE "v4l-cx25840.fw"
|
|
|
|
|
2009-08-31 20:57:52 +00:00
|
|
|
static const char *get_fw_name(struct i2c_client *client)
|
|
|
|
{
|
|
|
|
struct cx25840_state *state = to_state(i2c_get_clientdata(client));
|
|
|
|
|
|
|
|
if (firmware[0])
|
|
|
|
return firmware;
|
2009-09-27 02:47:21 +00:00
|
|
|
if (is_cx2388x(state))
|
2012-07-26 15:44:19 +00:00
|
|
|
return CX2388x_FIRMWARE;
|
2009-09-27 02:47:21 +00:00
|
|
|
if (is_cx231xx(state))
|
2012-07-26 15:44:19 +00:00
|
|
|
return CX231xx_FIRMWARE;
|
|
|
|
return CX25840_FIRMWARE;
|
2009-08-31 20:57:52 +00:00
|
|
|
}
|
|
|
|
|
2006-01-09 17:32:41 +00:00
|
|
|
static int check_fw_load(struct i2c_client *client, int size)
|
2005-11-14 00:07:56 +00:00
|
|
|
{
|
|
|
|
/* DL_ADDR_HB DL_ADDR_LB */
|
|
|
|
int s = cx25840_read(client, 0x801) << 8;
|
|
|
|
s |= cx25840_read(client, 0x800);
|
|
|
|
|
|
|
|
if (size != s) {
|
2009-08-31 20:57:52 +00:00
|
|
|
v4l_err(client, "firmware %s load failed\n",
|
|
|
|
get_fw_name(client));
|
2005-11-14 00:07:56 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2009-08-31 20:57:52 +00:00
|
|
|
v4l_info(client, "loaded %s firmware (%d bytes)\n",
|
|
|
|
get_fw_name(client), size);
|
2005-11-14 00:07:56 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-05-23 22:58:24 +00:00
|
|
|
static int fw_write(struct i2c_client *client, const u8 *data, int size)
|
2005-11-14 00:07:56 +00:00
|
|
|
{
|
2008-04-22 17:42:14 +00:00
|
|
|
if (i2c_master_send(client, data, size) < size) {
|
2006-04-23 08:54:56 +00:00
|
|
|
v4l_err(client, "firmware load i2c failure\n");
|
|
|
|
return -ENOSYS;
|
2005-11-14 00:07:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int cx25840_loadfw(struct i2c_client *client)
|
|
|
|
{
|
2008-11-29 15:50:06 +00:00
|
|
|
struct cx25840_state *state = to_state(i2c_get_clientdata(client));
|
2005-11-14 00:07:56 +00:00
|
|
|
const struct firmware *fw = NULL;
|
2008-05-23 22:58:24 +00:00
|
|
|
u8 buffer[FWSEND];
|
|
|
|
const u8 *ptr;
|
2009-08-31 20:57:52 +00:00
|
|
|
const char *fwname = get_fw_name(client);
|
2008-04-22 17:42:14 +00:00
|
|
|
int size, retval;
|
2009-03-03 17:36:55 +00:00
|
|
|
int MAX_BUF_SIZE = FWSEND;
|
2009-07-23 15:18:54 +00:00
|
|
|
u32 gpio_oe = 0, gpio_da = 0;
|
2005-11-14 00:07:56 +00:00
|
|
|
|
2009-09-27 02:47:21 +00:00
|
|
|
if (is_cx2388x(state)) {
|
2009-07-23 15:18:54 +00:00
|
|
|
/* Preserve the GPIO OE and output bits */
|
|
|
|
gpio_oe = cx25840_read(client, 0x160);
|
|
|
|
gpio_da = cx25840_read(client, 0x164);
|
|
|
|
}
|
2009-03-03 09:07:42 +00:00
|
|
|
|
2009-09-27 02:47:21 +00:00
|
|
|
if (is_cx231xx(state) && MAX_BUF_SIZE > 16) {
|
2009-03-03 17:36:55 +00:00
|
|
|
v4l_err(client, " Firmware download size changed to 16 bytes max length\n");
|
|
|
|
MAX_BUF_SIZE = 16; /* cx231xx cannot accept more than 16 bytes at a time */
|
|
|
|
}
|
2008-01-10 04:22:39 +00:00
|
|
|
|
2009-08-31 20:57:52 +00:00
|
|
|
if (request_firmware(&fw, fwname, FWDEV(client)) != 0) {
|
|
|
|
v4l_err(client, "unable to open firmware %s\n", fwname);
|
2005-11-14 00:07:56 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
start_fw_load(client);
|
|
|
|
|
|
|
|
buffer[0] = 0x08;
|
|
|
|
buffer[1] = 0x02;
|
|
|
|
|
2008-05-23 22:58:24 +00:00
|
|
|
size = fw->size;
|
2005-11-14 00:07:56 +00:00
|
|
|
ptr = fw->data;
|
|
|
|
while (size > 0) {
|
2009-03-03 09:07:42 +00:00
|
|
|
int len = min(MAX_BUF_SIZE - 2, size);
|
2008-05-23 22:58:24 +00:00
|
|
|
|
|
|
|
memcpy(buffer + 2, ptr, len);
|
|
|
|
|
|
|
|
retval = fw_write(client, buffer, len + 2);
|
2005-11-14 00:07:56 +00:00
|
|
|
|
|
|
|
if (retval < 0) {
|
|
|
|
release_firmware(fw);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2008-05-23 22:58:24 +00:00
|
|
|
size -= len;
|
|
|
|
ptr += len;
|
2005-11-14 00:07:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
end_fw_load(client);
|
|
|
|
|
|
|
|
size = fw->size;
|
|
|
|
release_firmware(fw);
|
|
|
|
|
2009-09-27 02:47:21 +00:00
|
|
|
if (is_cx2388x(state)) {
|
2009-07-23 15:18:54 +00:00
|
|
|
/* Restore GPIO configuration after f/w load */
|
|
|
|
cx25840_write(client, 0x160, gpio_oe);
|
|
|
|
cx25840_write(client, 0x164, gpio_da);
|
|
|
|
}
|
|
|
|
|
2005-11-14 00:07:56 +00:00
|
|
|
return check_fw_load(client, size);
|
|
|
|
}
|
2012-07-26 15:44:19 +00:00
|
|
|
|
|
|
|
MODULE_FIRMWARE(CX2388x_FIRMWARE);
|
|
|
|
MODULE_FIRMWARE(CX231xx_FIRMWARE);
|
|
|
|
MODULE_FIRMWARE(CX25840_FIRMWARE);
|
|
|
|
|