summaryrefslogtreecommitdiff
path: root/cleopatre/include/nvram.h
blob: d946ea8e6a0accb42327c90de9d04b798e7ded56 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
 * include/asm/arch/nvram.h
 *
 * Copyright (C) 2009 SPiDCOM Technologies
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 * MA 02111-1307 USA
 */

#ifndef __ASM_ARCH_NVRAM_H
#define __ASM_ARCH_NVRAM_H

#define NVRAM_MTD_NAME          "nvram"
#define SPC300_NVRAM_MAGIC      "NVRAM\0\0\0"
#define NVRAM_IS_VALID(nvram)   (!memcmp(nvram->magic, SPC300_NVRAM_MAGIC, 8))

/* GPIO common definitions */
#define MAX_INTERNAL_GPIOS 16
#define MIN_INTERNAL_GPIOS 8
#define spc300_gpio_max_nb(pkg_cfg) ((((pkg_cfg & 0x000000F0) >> 4) < 5) ? \
                                    MAX_INTERNAL_GPIOS : MIN_INTERNAL_GPIOS)
#define spc300_gpio_direction(gpio_allow_dir,num) ((gpio_allow_dir >> (num * 2)) & 0x3)

enum spc300_gpio_direction_t
{
    SPC300_GPIO_DIRECTION_NONE   = 0,
    SPC300_GPIO_DIRECTION_INPUT  = 1,
    SPC300_GPIO_DIRECTION_OUTPUT = 2,
    SPC300_GPIO_DIRECTION_BIDIR  = 3,
};

/* /!\ All values are LITTLE-ENDIAN */
typedef struct
{
    char            magic[8];               // Magic number "NVRAM\0\0\0"
    uint32_t        pkg_cfg;                // SPC300 package configuration register
    uint32_t        gpio_0_7_cfg;           // SPC300 GPIO 0 to 7 configuration register
    uint32_t        gpio_8_15_cfg;          // SPC300 GPIO 8 to 15 configuration register
    uint32_t        gpio_allow_dir;         // SPC300 GPIO allowed directions 0:none 1:in 2:out 3:bi
    union {
        struct {
            uint32_t config;                // SPC300 SDRAM configuration register
            uint32_t timing0;               // SPC300 SDRAM timing register 0
            uint32_t timing1;               // SPC300 SDRAM timing register 1
            uint32_t refresh;               // SPC300 SDRAM refresh register
        } sdram;
        struct {
            uint16_t config_offset;         // Offset of MIU config in nvram
            uint16_t config_size;           // Size of MIU config in words
            uint32_t ram_size;              // Size of MIU connected RAM in bytes
            uint32_t reserved[2];
        } miu;
    } dram;
    uint32_t        flash_org;              // Flash organization
    uint32_t        img_0_offset;           // Offset of first image address
    uint32_t        nb_images;              // Max Number of Images present in flash
    char            product_name[64];       // Product short name in string format
    char            product_partnb[64];     // Product part number in string format
    char            product_desc[128];      // Product long description in string format
    char            serial_number[64];      // Product serial number in string format
    uint32_t        eth_phy_addr;           // Address of Ethernet PHY
    unsigned char   eth_address[6];         // Ethernet MAC address
    unsigned char   eth_port_nb;            // Ethernet port number
    unsigned char   reserved1;
    unsigned char   plc_address[6];         // PowerLine MAC address
    unsigned char   reserved2[2];
    char            device_password[32];    // HomePlugAV device unique password (DPW)
    char            oem_info[64];           // Additional information for OEM
    unsigned char   tonemask[192];          // HomePlugAV tonemask
    char            manufactory_info[64];   // Name of the product manufacturer
    uint32_t        img_max_size;           // Max size of an image in
                                            // flash
    uint32_t        cpu_partnb;             // SPC3x0 partnb
    uint32_t        dynamic[256];           // Dynamic data (see miu_config)
} spc300_nvram_t; //Currently __attribute__((packed)) not needed

#ifdef __KERNEL__
extern spc300_nvram_t spc300_nvram;

static inline void spc300_nvram_copy(void* dst, void* src, unsigned int length)
{
    unsigned int burst, rest, i;
    unsigned long *src32, *dst32;
    unsigned char *src8, *dst8;

    src32 = (unsigned long*)src;
    dst32 = (unsigned long*)dst;
    burst = length / 4;
    rest = length % 4;

    for(i=0 ; i<burst ; i++)
    {
        *dst32 = *src32;
        dst32++;
        src32++;
    }
    if(rest)
    {
        src8 = (unsigned char*)src32;
        dst8 = (unsigned char*)dst32;
        for(i=0 ; i<rest ; i++)
        {
            *dst8 = *src8;
            dst8++;
            src8++;
        }
    }
}
#endif

#endif  /* __ASM_ARCH_NVRAM_H */