blob: bd1869dfc8300da13932e6cf11e23f7e93a49a78 [file] [log] [blame]
Timur Tabi9d449932008-02-08 13:15:54 -06001/*
2 * Vitesse 7385 Switch Firmware Upload
3 *
4 * Author: Timur Tabi <timur@freescale.com>
5 *
6 * Copyright 2008 Freescale Semiconductor, Inc. This file is licensed
7 * under the terms of the GNU General Public License version 2. This
8 * program is licensed "as is" without any warranty of any kind, whether
9 * express or implied.
10 *
11 * This module uploads proprietary firmware for the Vitesse VSC7385 5-port
12 * switch.
13 */
14
15#include <config.h>
Simon Glassa73bda42015-11-08 23:47:45 -070016#include <console.h>
Simon Glass0f2af882020-05-10 11:40:05 -060017#include <log.h>
Timur Tabi9d449932008-02-08 13:15:54 -060018#include <asm/io.h>
Simon Glassdbd79542020-05-10 11:40:11 -060019#include <linux/delay.h>
Masahiro Yamada56a931c2016-09-21 11:28:55 +090020#include <linux/errno.h>
Kim Phillips914b0782012-10-29 13:34:34 +000021#include "vsc7385.h"
Timur Tabi9d449932008-02-08 13:15:54 -060022
23/*
24 * Upload a Vitesse VSC7385 firmware image to the hardware
25 *
26 * This function takes a pointer to a VSC7385 firmware image and a size, and
27 * uploads that firmware to the VSC7385.
28 *
29 * This firmware is typically located at a board-specific flash address,
30 * and the size is typically 8KB.
31 *
32 * The firmware is Vitesse proprietary.
33 *
34 * Further details on the register information can be obtained from Vitesse.
35 */
36int vsc7385_upload_firmware(void *firmware, unsigned int size)
37{
38 u8 *fw = firmware;
39 unsigned int i;
40
Tom Rini6a5dccc2022-11-16 13:10:41 -050041 u32 *gloreset = (u32 *) (CFG_SYS_VSC7385_BASE + 0x1c050);
42 u32 *icpu_ctrl = (u32 *) (CFG_SYS_VSC7385_BASE + 0x1c040);
43 u32 *icpu_addr = (u32 *) (CFG_SYS_VSC7385_BASE + 0x1c044);
44 u32 *icpu_data = (u32 *) (CFG_SYS_VSC7385_BASE + 0x1c048);
45 u32 *icpu_rom_map = (u32 *) (CFG_SYS_VSC7385_BASE + 0x1c070);
Timur Tabi9d449932008-02-08 13:15:54 -060046#ifdef DEBUG
Tom Rini6a5dccc2022-11-16 13:10:41 -050047 u32 *chipid = (u32 *) (CFG_SYS_VSC7385_BASE + 0x1c060);
Timur Tabi9d449932008-02-08 13:15:54 -060048#endif
49
50 out_be32(gloreset, 3);
51 udelay(200);
52
53 out_be32(icpu_ctrl, 0x8E);
54 udelay(20);
55
56 out_be32(icpu_rom_map, 1);
57 udelay(20);
58
Wolfgang Denk8f702ad2008-03-26 11:48:46 +010059 /* Write the firmware to I-RAM */
Timur Tabi9d449932008-02-08 13:15:54 -060060 out_be32(icpu_addr, 0);
61 udelay(20);
62
63 for (i = 0; i < size; i++) {
64 out_be32(icpu_data, fw[i]);
65 udelay(20);
66 if (ctrlc())
67 return -EINTR;
68 }
69
70 /* Read back and compare */
71 out_be32(icpu_addr, 0);
72 udelay(20);
73
74 for (i = 0; i < size; i++) {
75 u8 value;
76
77 value = (u8) in_be32(icpu_data);
78 udelay(20);
79 if (value != fw[i]) {
80 debug("VSC7385: Upload mismatch: address 0x%x, "
Wolfgang Denk8f702ad2008-03-26 11:48:46 +010081 "read value 0x%x, image value 0x%x\n",
82 i, value, fw[i]);
Timur Tabi9d449932008-02-08 13:15:54 -060083
84 return -EIO;
85 }
86 if (ctrlc())
87 break;
88 }
89
90 out_be32(icpu_ctrl, 0x0B);
91 udelay(20);
92
93#ifdef DEBUG
94 printf("VSC7385: Chip ID is %08x\n", in_be32(chipid));
95 udelay(20);
96#endif
97
98 return 0;
99}