Commit 9e412a0a authored by Macpaul Lin's avatar Macpaul Lin Committed by Greg Kroah-Hartman

staging/gdm72xx: sdio_boot: replace firmware upgrade API

Replace firmware upgrade API in download_image().
Signed-off-by: default avatarMacpaul Lin <macpaul.from.taiwan@gmail.com>
Cc: Macpaul Lin <macpaul@gmail.com>
Cc: Paul Stewart <pstew@chromium.org>
Cc: Ben Chan <benchan@chromium.org>
Cc: Sage Ahn <syahn@gctsemi.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 2874762b
...@@ -24,15 +24,18 @@ ...@@ -24,15 +24,18 @@
#include <linux/mmc/card.h> #include <linux/mmc/card.h>
#include <linux/mmc/sdio_func.h> #include <linux/mmc/sdio_func.h>
#include <linux/firmware.h>
#include "gdm_sdio.h" #include "gdm_sdio.h"
#define TYPE_A_HEADER_SIZE 4 #define TYPE_A_HEADER_SIZE 4
#define TYPE_A_LOOKAHEAD_SIZE 16 #define TYPE_A_LOOKAHEAD_SIZE 16
#define YMEM0_SIZE 0x8000 /* 32kbytes */ #define YMEM0_SIZE 0x8000 /* 32kbytes */
#define DOWNLOAD_SIZE (YMEM0_SIZE - TYPE_A_HEADER_SIZE) #define DOWNLOAD_SIZE (YMEM0_SIZE - TYPE_A_HEADER_SIZE)
#define KRN_PATH "/lib/firmware/gdm72xx/gdmskrn.bin" #define FW_DIR "gdm72xx/"
#define RFS_PATH "/lib/firmware/gdm72xx/gdmsrfs.bin" #define FW_KRN "gdmskrn.bin"
#define FW_RFS "gdmsrfs.bin"
static u8 *tx_buf; static u8 *tx_buf;
...@@ -52,57 +55,57 @@ static int ack_ready(struct sdio_func *func) ...@@ -52,57 +55,57 @@ static int ack_ready(struct sdio_func *func)
return 0; return 0;
} }
static int download_image(struct sdio_func *func, char *img_name) static int download_image(struct sdio_func *func, const char *img_name)
{ {
int ret = 0, len, size, pno; int ret = 0, len, pno;
struct file *filp = NULL;
struct inode *inode = NULL;
u8 *buf = tx_buf; u8 *buf = tx_buf;
loff_t pos = 0; loff_t pos = 0;
int img_len;
filp = filp_open(img_name, O_RDONLY | O_LARGEFILE, 0); const struct firmware *firm;
if (IS_ERR(filp)) {
printk(KERN_ERR "Can't find %s.\n", img_name); ret = request_firmware(&firm, img_name, &func->dev);
return -ENOENT; if (ret < 0) {
printk(KERN_ERR
"requesting firmware %s failed with error %d\n",
img_name, ret);
return ret;
} }
inode = filp->f_dentry->d_inode; buf = kmalloc(DOWNLOAD_SIZE + TYPE_A_HEADER_SIZE, GFP_KERNEL);
if (!S_ISREG(inode->i_mode)) { if (buf == NULL) {
printk(KERN_ERR "Invalid file type: %s\n", img_name); printk(KERN_ERR "Error: kmalloc\n");
ret = -EINVAL; return -ENOMEM;
goto out;
} }
size = i_size_read(inode->i_mapping->host); img_len = firm->size;
if (size <= 0) {
printk(KERN_ERR "Unable to find file size: %s\n", img_name); if (img_len <= 0) {
ret = size; ret = -1;
goto out; goto out;
} }
pno = 0; pno = 0;
while ((len = filp->f_op->read(filp, buf + TYPE_A_HEADER_SIZE, while (img_len > 0) {
DOWNLOAD_SIZE, &pos))) { if (img_len > DOWNLOAD_SIZE) {
if (len < 0) { len = DOWNLOAD_SIZE;
ret = -1; buf[3] = 0;
goto out; } else {
len = img_len; /* the last packet */
buf[3] = 2;
} }
buf[0] = len & 0xff; buf[0] = len & 0xff;
buf[1] = (len >> 8) & 0xff; buf[1] = (len >> 8) & 0xff;
buf[2] = (len >> 16) & 0xff; buf[2] = (len >> 16) & 0xff;
if (pos >= size) /* The last packet */ memcpy(buf+TYPE_A_HEADER_SIZE, firm->data + pos, len);
buf[3] = 2;
else
buf[3] = 0;
ret = sdio_memcpy_toio(func, 0, buf, len + TYPE_A_HEADER_SIZE); ret = sdio_memcpy_toio(func, 0, buf, len + TYPE_A_HEADER_SIZE);
if (ret < 0) { if (ret < 0) {
printk(KERN_ERR "gdmwm: send image error: " printk(KERN_ERR "gdmwm: send image error: "
"packet number = %d ret = %d\n", pno, ret); "packet number = %d ret = %d\n", pno, ret);
goto out; goto out;
} }
if (buf[3] == 2) /* The last packet */ if (buf[3] == 2) /* The last packet */
break; break;
if (!ack_ready(func)) { if (!ack_ready(func)) {
...@@ -119,17 +122,21 @@ static int download_image(struct sdio_func *func, char *img_name) ...@@ -119,17 +122,21 @@ static int download_image(struct sdio_func *func, char *img_name)
sdio_writeb(func, 0x01, 0x13, &ret); sdio_writeb(func, 0x01, 0x13, &ret);
sdio_writeb(func, 0x00, 0x10, &ret); /* PCRRT */ sdio_writeb(func, 0x00, 0x10, &ret); /* PCRRT */
img_len -= DOWNLOAD_SIZE;
pos += DOWNLOAD_SIZE;
pno++; pno++;
} }
out: out:
filp_close(filp, NULL); kfree(buf);
return ret; return ret;
} }
int sdio_boot(struct sdio_func *func) int sdio_boot(struct sdio_func *func)
{ {
static mm_segment_t fs;
int ret; int ret;
const char *krn_name = FW_DIR FW_KRN;
const char *rfs_name = FW_DIR FW_RFS;
tx_buf = kmalloc(YMEM0_SIZE, GFP_KERNEL); tx_buf = kmalloc(YMEM0_SIZE, GFP_KERNEL);
if (tx_buf == NULL) { if (tx_buf == NULL) {
...@@ -137,21 +144,17 @@ int sdio_boot(struct sdio_func *func) ...@@ -137,21 +144,17 @@ int sdio_boot(struct sdio_func *func)
return -ENOMEM; return -ENOMEM;
} }
fs = get_fs(); ret = download_image(func, krn_name);
set_fs(get_ds());
ret = download_image(func, KRN_PATH);
if (ret) if (ret)
goto restore_fs; goto restore_fs;
printk(KERN_INFO "GCT: Kernel download success.\n"); printk(KERN_INFO "GCT: Kernel download success.\n");
ret = download_image(func, RFS_PATH); ret = download_image(func, rfs_name);
if (ret) if (ret)
goto restore_fs; goto restore_fs;
printk(KERN_INFO "GCT: Filesystem download success.\n"); printk(KERN_INFO "GCT: Filesystem download success.\n");
restore_fs: restore_fs:
set_fs(fs);
kfree(tx_buf); kfree(tx_buf);
return ret; return ret;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment