Path: blob/master/arch/arm/mach-orion5x/tsx09-common.c
10817 views
/*1* QNAP TS-x09 Boards common functions2*3* Maintainers: Lennert Buytenhek <[email protected]>4* Byron Bradley <[email protected]>5*6* This program is free software; you can redistribute it and/or7* modify it under the terms of the GNU General Public License8* as published by the Free Software Foundation; either version9* 2 of the License, or (at your option) any later version.10*/1112#include <linux/kernel.h>13#include <linux/pci.h>14#include <linux/mv643xx_eth.h>15#include <linux/timex.h>16#include <linux/serial_reg.h>17#include "tsx09-common.h"18#include "common.h"1920/*****************************************************************************21* QNAP TS-x09 specific power off method via UART1-attached PIC22****************************************************************************/2324#define UART1_REG(x) (UART1_VIRT_BASE + ((UART_##x) << 2))2526void qnap_tsx09_power_off(void)27{28/* 19200 baud divisor */29const unsigned divisor = ((orion5x_tclk + (8 * 19200)) / (16 * 19200));3031pr_info("%s: triggering power-off...\n", __func__);3233/* hijack uart1 and reset into sane state (19200,8n1) */34writel(0x83, UART1_REG(LCR));35writel(divisor & 0xff, UART1_REG(DLL));36writel((divisor >> 8) & 0xff, UART1_REG(DLM));37writel(0x03, UART1_REG(LCR));38writel(0x00, UART1_REG(IER));39writel(0x00, UART1_REG(FCR));40writel(0x00, UART1_REG(MCR));4142/* send the power-off command 'A' to PIC */43writel('A', UART1_REG(TX));44}4546/*****************************************************************************47* Ethernet48****************************************************************************/4950struct mv643xx_eth_platform_data qnap_tsx09_eth_data = {51.phy_addr = MV643XX_ETH_PHY_ADDR(8),52};5354static int __init qnap_tsx09_parse_hex_nibble(char n)55{56if (n >= '0' && n <= '9')57return n - '0';5859if (n >= 'A' && n <= 'F')60return n - 'A' + 10;6162if (n >= 'a' && n <= 'f')63return n - 'a' + 10;6465return -1;66}6768static int __init qnap_tsx09_parse_hex_byte(const char *b)69{70int hi;71int lo;7273hi = qnap_tsx09_parse_hex_nibble(b[0]);74lo = qnap_tsx09_parse_hex_nibble(b[1]);7576if (hi < 0 || lo < 0)77return -1;7879return (hi << 4) | lo;80}8182static int __init qnap_tsx09_check_mac_addr(const char *addr_str)83{84u_int8_t addr[6];85int i;8687for (i = 0; i < 6; i++) {88int byte;8990/*91* Enforce "xx:xx:xx:xx:xx:xx\n" format.92*/93if (addr_str[(i * 3) + 2] != ((i < 5) ? ':' : '\n'))94return -1;9596byte = qnap_tsx09_parse_hex_byte(addr_str + (i * 3));97if (byte < 0)98return -1;99addr[i] = byte;100}101102printk(KERN_INFO "tsx09: found ethernet mac address ");103for (i = 0; i < 6; i++)104printk("%.2x%s", addr[i], (i < 5) ? ":" : ".\n");105106memcpy(qnap_tsx09_eth_data.mac_addr, addr, 6);107108return 0;109}110111/*112* The 'NAS Config' flash partition has an ext2 filesystem which113* contains a file that has the ethernet MAC address in plain text114* (format "xx:xx:xx:xx:xx:xx\n").115*/116void __init qnap_tsx09_find_mac_addr(u32 mem_base, u32 size)117{118unsigned long addr;119120for (addr = mem_base; addr < (mem_base + size); addr += 1024) {121char *nor_page;122int ret = 0;123124nor_page = ioremap(addr, 1024);125if (nor_page != NULL) {126ret = qnap_tsx09_check_mac_addr(nor_page);127iounmap(nor_page);128}129130if (ret == 0)131break;132}133}134135136