1 /* $Id: iop_fw_load.c,v 1.4 2005/04/07 09:27:46 larsv Exp $
3 * Firmware loader for ETRAX FS IO-Processor
5 * Copyright (C) 2004 Axis Communications AB
8 #include <linux/module.h>
9 #include <linux/kernel.h>
10 #include <linux/init.h>
11 #include <linux/device.h>
12 #include <linux/firmware.h>
14 #include <asm/arch/hwregs/reg_map.h>
15 #include <asm/arch/hwregs/iop/iop_reg_space.h>
16 #include <asm/arch/hwregs/iop/iop_mpu_macros.h>
17 #include <asm/arch/hwregs/iop/iop_mpu_defs.h>
18 #include <asm/arch/hwregs/iop/iop_spu_defs.h>
19 #include <asm/arch/hwregs/iop/iop_sw_cpu_defs.h>
21 #define IOP_TIMEOUT 100
23 static struct device iop_spu_device[2] = {
24 { .bus_id = "iop-spu0", },
25 { .bus_id = "iop-spu1", },
28 static struct device iop_mpu_device = {
32 static int wait_mpu_idle(void)
34 reg_iop_mpu_r_stat mpu_stat;
35 unsigned int timeout = IOP_TIMEOUT;
38 mpu_stat = REG_RD(iop_mpu, regi_iop_mpu, r_stat);
39 } while (mpu_stat.instr_reg_busy == regk_iop_mpu_yes && --timeout > 0);
41 printk(KERN_ERR "Timeout waiting for MPU to be idle\n");
47 int iop_fw_load_spu(const unsigned char *fw_name, unsigned int spu_inst)
49 reg_iop_sw_cpu_rw_mc_ctrl mc_ctrl = {
50 .wr_spu0_mem = regk_iop_sw_cpu_no,
51 .wr_spu1_mem = regk_iop_sw_cpu_no,
53 .cmd = regk_iop_sw_cpu_reg_copy,
54 .keep_owner = regk_iop_sw_cpu_yes
56 reg_iop_spu_rw_ctrl spu_ctrl = {
57 .en = regk_iop_spu_no,
58 .fsm = regk_iop_spu_no,
60 reg_iop_sw_cpu_r_mc_stat mc_stat;
61 const struct firmware *fw_entry;
70 retval = request_firmware(&fw_entry,
72 &iop_spu_device[spu_inst]);
76 "iop_load_spu: Failed to load firmware \"%s\"\n",
80 data = (u32 *) fw_entry->data;
82 /* acquire ownership of memory controller */
85 mc_ctrl.wr_spu0_mem = regk_iop_sw_cpu_yes;
86 REG_WR(iop_spu, regi_iop_spu0, rw_ctrl, spu_ctrl);
89 mc_ctrl.wr_spu1_mem = regk_iop_sw_cpu_yes;
90 REG_WR(iop_spu, regi_iop_spu1, rw_ctrl, spu_ctrl);
93 timeout = IOP_TIMEOUT;
95 REG_WR(iop_sw_cpu, regi_iop_sw_cpu, rw_mc_ctrl, mc_ctrl);
96 mc_stat = REG_RD(iop_sw_cpu, regi_iop_sw_cpu, r_mc_stat);
97 } while (mc_stat.owned_by_cpu == regk_iop_sw_cpu_no && --timeout > 0);
99 printk(KERN_ERR "Timeout waiting to acquire MC\n");
104 /* write to SPU memory */
105 for (i = 0; i < (fw_entry->size/4); i++) {
108 REG_WR_INT(iop_spu, regi_iop_spu0, rw_seq_pc, (i*4));
111 REG_WR_INT(iop_spu, regi_iop_spu1, rw_seq_pc, (i*4));
114 REG_WR_INT(iop_sw_cpu, regi_iop_sw_cpu, rw_mc_data, *data);
118 /* release ownership of memory controller */
119 (void) REG_RD(iop_sw_cpu, regi_iop_sw_cpu, rs_mc_data);
122 release_firmware(fw_entry);
126 int iop_fw_load_mpu(unsigned char *fw_name)
128 const unsigned int start_addr = 0;
129 reg_iop_mpu_rw_ctrl mpu_ctrl;
130 const struct firmware *fw_entry;
135 retval = request_firmware(&fw_entry, fw_name, &iop_mpu_device);
139 "iop_load_spu: Failed to load firmware \"%s\"\n",
143 data = (u32 *) fw_entry->data;
146 mpu_ctrl.en = regk_iop_mpu_no;
147 REG_WR(iop_mpu, regi_iop_mpu, rw_ctrl, mpu_ctrl);
148 /* put start address in R0 */
149 REG_WR_VECT(iop_mpu, regi_iop_mpu, rw_r, 0, start_addr);
150 /* write to memory by executing 'SWX i, 4, R0' for each word */
151 if ((retval = wait_mpu_idle()) != 0)
153 REG_WR(iop_mpu, regi_iop_mpu, rw_instr, MPU_SWX_IIR_INSTR(0, 4, 0));
154 for (i = 0; i < (fw_entry->size / 4); i++) {
155 REG_WR_INT(iop_mpu, regi_iop_mpu, rw_immediate, *data);
156 if ((retval = wait_mpu_idle()) != 0)
162 release_firmware(fw_entry);
166 int iop_start_mpu(unsigned int start_addr)
168 reg_iop_mpu_rw_ctrl mpu_ctrl = { .en = regk_iop_mpu_yes };
172 if ((retval = wait_mpu_idle()) != 0)
174 REG_WR(iop_mpu, regi_iop_mpu, rw_instr, MPU_HALT());
175 if ((retval = wait_mpu_idle()) != 0)
177 /* set PC and wait for it to bite */
178 if ((retval = wait_mpu_idle()) != 0)
180 REG_WR_INT(iop_mpu, regi_iop_mpu, rw_instr, MPU_BA_I(start_addr));
181 if ((retval = wait_mpu_idle()) != 0)
183 /* make sure the MPU starts executing with interrupts disabled */
184 REG_WR(iop_mpu, regi_iop_mpu, rw_instr, MPU_DI());
185 if ((retval = wait_mpu_idle()) != 0)
188 REG_WR(iop_mpu, regi_iop_mpu, rw_ctrl, mpu_ctrl);
193 static int __init iop_fw_load_init(void)
195 device_initialize(&iop_spu_device[0]);
196 kobject_set_name(&iop_spu_device[0].kobj, "iop-spu0");
197 kobject_add(&iop_spu_device[0].kobj);
198 device_initialize(&iop_spu_device[1]);
199 kobject_set_name(&iop_spu_device[1].kobj, "iop-spu1");
200 kobject_add(&iop_spu_device[1].kobj);
201 device_initialize(&iop_mpu_device);
202 kobject_set_name(&iop_mpu_device.kobj, "iop-mpu");
203 kobject_add(&iop_mpu_device.kobj);
207 static void __exit iop_fw_load_exit(void)
211 module_init(iop_fw_load_init);
212 module_exit(iop_fw_load_exit);
214 MODULE_DESCRIPTION("ETRAX FS IO-Processor Firmware Loader");
215 MODULE_LICENSE("GPL");
217 EXPORT_SYMBOL(iop_fw_load_spu);
218 EXPORT_SYMBOL(iop_fw_load_mpu);
219 EXPORT_SYMBOL(iop_start_mpu);