blob: 6d275b264919b91866f23965c8428e5898587632 [file] [log] [blame]
Vadim Iosevichd50ea462017-03-30 16:19:08 +03001/*
2 * Copyright (c) 2017, The Linux Foundation. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above
10 * copyright notice, this list of conditions and the following
11 * disclaimer in the documentation and/or other materials provided
12 * with the distribution.
13 * * Neither the name of The Linux Foundation nor the names of its
14 * contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30#pragma once
31#include "flashacss.h"
32
33class MarlonGateway : public flash_gateway
34{
35public:
36 MarlonGateway(const char *device_name);
37 MarlonGateway(void* flashHandle);
38 virtual ~MarlonGateway(void);
39 virtual int runCommand(UCHAR flash_cmd, FLASH_PHASE phase, bool bWrite, DWORD addr, DWORD ulSize);
40 virtual int setData(const BYTE *buffer, DWORD size);
41 virtual int getData(BYTE *buffer, DWORD size);
42 virtual int wait_done (void) const;
43 virtual int boot_done(void) const;
44 virtual bool get_lock ();
45 virtual int force_lock ();
46 virtual int release_lock();
47
48private:
49
50 int setAddr(DWORD addr);
51// void setSize(DWORD size);
52 int setCommand(UCHAR cmd, FLASH_PHASE phase, bool bWrite);
53
54 int wb(u_int32_t offset, DWORD size, const BYTE *buffer);
55 int rb(u_int32_t offset, DWORD size, const BYTE *buffer);
56 int r(u_int32_t offset, DWORD & val) const;
57 int w(u_int32_t offset, DWORD val) const;
58 int execute_cmd() const;
59
60 bool m_got_lock;
61
62 enum constants{
63 CR_USER = 0x880000,
64#ifndef MARLON_B0
65 CR_FLASH_DATA = CR_USER + 0xA8,
66 CR_FLASH_ADDR = CR_USER + 0x1B0,
67 CR_FLASH_OPCODE = CR_USER + 0x1AC,
68 CR_FLASH_STAT_CTL = CR_USER + 0x1A8,
69#else
70 CR_FLASH_DATA = CR_USER + 0x5C,
71 CR_FLASH_ADDR = CR_USER + 0x164,
72 CR_FLASH_OPCODE = CR_USER + 0x160,
73 CR_FLASH_STAT_CTL = CR_USER + 0x15C,
74#endif // MARLON_B0
75
76 // CR_FLASH_OPCODE
77 BIT_OFFSET_INST = 16,
78 BIT_SIZE_INST = 8,
79 BIT_OFFSET_ADDR_PHASE = 24,
80 BIT_OFFSET_DATA_PHASE = 25,
81 BIT_OFFSET_WRITE_OP = 31,
82
83 BIT_FLASH_STATUS_OFFSET = 0,
84 BIT_FLASH_STATUS_SIZE = 8,
85 BIT_OFFSET_BUSY = 29,
86 BIT_GO = 30,
87 BIT_LOCK = 31,
88 };
89
90};