2 * Copyright (c) 2012 GCT Semiconductor, Inc. All rights reserved.
4 * This software is licensed under the terms of the GNU General Public
5 * License version 2, as published by the Free Software Foundation, and
6 * may be copied, distributed, and modified under those terms.
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.
14 #include <linux/module.h>
15 #include <linux/kernel.h>
17 #include <linux/uaccess.h>
19 #include <linux/sched.h>
20 #include <linux/slab.h>
22 #include <linux/mmc/core.h>
23 #include <linux/mmc/card.h>
24 #include <linux/mmc/sdio_func.h>
26 #include <linux/firmware.h>
29 #include "sdio_boot.h"
31 #define TYPE_A_HEADER_SIZE 4
32 #define TYPE_A_LOOKAHEAD_SIZE 16
33 #define YMEM0_SIZE 0x8000 /* 32kbytes */
34 #define DOWNLOAD_SIZE (YMEM0_SIZE - TYPE_A_HEADER_SIZE)
36 #define FW_DIR "gdm72xx/"
37 #define FW_KRN "gdmskrn.bin"
38 #define FW_RFS "gdmsrfs.bin"
42 static int ack_ready(struct sdio_func
*func
)
44 unsigned long wait
= jiffies
+ HZ
;
48 while (time_before(jiffies
, wait
)) {
49 val
= sdio_readb(func
, 0x13, &ret
);
58 static int download_image(struct sdio_func
*func
, const char *img_name
)
60 int ret
= 0, len
, pno
;
64 const struct firmware
*firm
;
66 ret
= request_firmware(&firm
, img_name
, &func
->dev
);
69 "requesting firmware %s failed with error %d\n",
74 buf
= kmalloc(DOWNLOAD_SIZE
+ TYPE_A_HEADER_SIZE
, GFP_KERNEL
);
87 if (img_len
> DOWNLOAD_SIZE
) {
91 len
= img_len
; /* the last packet */
96 buf
[1] = (len
>> 8) & 0xff;
97 buf
[2] = (len
>> 16) & 0xff;
99 memcpy(buf
+TYPE_A_HEADER_SIZE
, firm
->data
+ pos
, len
);
100 ret
= sdio_memcpy_toio(func
, 0, buf
, len
+ TYPE_A_HEADER_SIZE
);
103 "send image error: packet number = %d ret = %d\n",
108 if (buf
[3] == 2) /* The last packet */
110 if (!ack_ready(func
)) {
112 dev_err(&func
->dev
, "Ack is not ready.\n");
115 ret
= sdio_memcpy_fromio(func
, buf
, 0, TYPE_A_LOOKAHEAD_SIZE
);
118 "receive ack error: packet number = %d ret = %d\n",
122 sdio_writeb(func
, 0x01, 0x13, &ret
);
123 sdio_writeb(func
, 0x00, 0x10, &ret
); /* PCRRT */
125 img_len
-= DOWNLOAD_SIZE
;
126 pos
+= DOWNLOAD_SIZE
;
135 int sdio_boot(struct sdio_func
*func
)
138 const char *krn_name
= FW_DIR FW_KRN
;
139 const char *rfs_name
= FW_DIR FW_RFS
;
141 tx_buf
= kmalloc(YMEM0_SIZE
, GFP_KERNEL
);
145 ret
= download_image(func
, krn_name
);
148 dev_info(&func
->dev
, "GCT: Kernel download success.\n");
150 ret
= download_image(func
, rfs_name
);
153 dev_info(&func
->dev
, "GCT: Filesystem download success.\n");
This page took 0.05385 seconds and 5 git commands to generate.