Sylver Bruneau | 530c854 | 2008-05-31 18:21:49 +0200 | [diff] [blame] | 1 | /* |
| 2 | * QNAP TS-x09 Boards common functions |
| 3 | * |
| 4 | * Maintainers: Lennert Buytenhek <buytenh@marvell.com> |
| 5 | * Byron Bradley <byron.bbradley@gmail.com> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License |
| 9 | * as published by the Free Software Foundation; either version |
| 10 | * 2 of the License, or (at your option) any later version. |
| 11 | */ |
| 12 | |
| 13 | #include <linux/kernel.h> |
| 14 | #include <linux/pci.h> |
| 15 | #include <linux/mv643xx_eth.h> |
Sylver Bruneau | a10b188 | 2008-06-25 23:41:09 +0200 | [diff] [blame] | 16 | #include <linux/timex.h> |
Sylver Bruneau | 530c854 | 2008-05-31 18:21:49 +0200 | [diff] [blame] | 17 | #include <linux/serial_reg.h> |
Arnd Bergmann | c22c2c6 | 2015-12-02 22:27:08 +0100 | [diff] [blame] | 18 | #include "orion5x.h" |
Sylver Bruneau | 530c854 | 2008-05-31 18:21:49 +0200 | [diff] [blame] | 19 | #include "tsx09-common.h" |
Lennert Buytenhek | ebe35af | 2008-08-29 05:55:51 +0200 | [diff] [blame] | 20 | #include "common.h" |
Sylver Bruneau | 530c854 | 2008-05-31 18:21:49 +0200 | [diff] [blame] | 21 | |
| 22 | /***************************************************************************** |
| 23 | * QNAP TS-x09 specific power off method via UART1-attached PIC |
| 24 | ****************************************************************************/ |
| 25 | |
| 26 | #define UART1_REG(x) (UART1_VIRT_BASE + ((UART_##x) << 2)) |
| 27 | |
| 28 | void qnap_tsx09_power_off(void) |
| 29 | { |
| 30 | /* 19200 baud divisor */ |
Lennert Buytenhek | ebe35af | 2008-08-29 05:55:51 +0200 | [diff] [blame] | 31 | const unsigned divisor = ((orion5x_tclk + (8 * 19200)) / (16 * 19200)); |
Sylver Bruneau | 530c854 | 2008-05-31 18:21:49 +0200 | [diff] [blame] | 32 | |
| 33 | pr_info("%s: triggering power-off...\n", __func__); |
| 34 | |
| 35 | /* hijack uart1 and reset into sane state (19200,8n1) */ |
| 36 | writel(0x83, UART1_REG(LCR)); |
| 37 | writel(divisor & 0xff, UART1_REG(DLL)); |
| 38 | writel((divisor >> 8) & 0xff, UART1_REG(DLM)); |
| 39 | writel(0x03, UART1_REG(LCR)); |
| 40 | writel(0x00, UART1_REG(IER)); |
| 41 | writel(0x00, UART1_REG(FCR)); |
| 42 | writel(0x00, UART1_REG(MCR)); |
| 43 | |
| 44 | /* send the power-off command 'A' to PIC */ |
| 45 | writel('A', UART1_REG(TX)); |
| 46 | } |
| 47 | |
| 48 | /***************************************************************************** |
| 49 | * Ethernet |
| 50 | ****************************************************************************/ |
| 51 | |
| 52 | struct mv643xx_eth_platform_data qnap_tsx09_eth_data = { |
Lennert Buytenhek | ac840605 | 2008-08-26 14:06:47 +0200 | [diff] [blame] | 53 | .phy_addr = MV643XX_ETH_PHY_ADDR(8), |
Sylver Bruneau | 530c854 | 2008-05-31 18:21:49 +0200 | [diff] [blame] | 54 | }; |
| 55 | |
Sylver Bruneau | 530c854 | 2008-05-31 18:21:49 +0200 | [diff] [blame] | 56 | static int __init qnap_tsx09_check_mac_addr(const char *addr_str) |
| 57 | { |
| 58 | u_int8_t addr[6]; |
Sylver Bruneau | 530c854 | 2008-05-31 18:21:49 +0200 | [diff] [blame] | 59 | |
Andy Shevchenko | 4904dbd | 2015-10-02 17:12:33 +0300 | [diff] [blame] | 60 | if (!mac_pton(addr_str, addr)) |
| 61 | return -1; |
Sylver Bruneau | 530c854 | 2008-05-31 18:21:49 +0200 | [diff] [blame] | 62 | |
Joe Perches | 7a1436d | 2015-06-14 19:01:30 -0700 | [diff] [blame] | 63 | printk(KERN_INFO "tsx09: found ethernet mac address %pM\n", addr); |
Sylver Bruneau | 530c854 | 2008-05-31 18:21:49 +0200 | [diff] [blame] | 64 | |
| 65 | memcpy(qnap_tsx09_eth_data.mac_addr, addr, 6); |
| 66 | |
| 67 | return 0; |
| 68 | } |
| 69 | |
| 70 | /* |
| 71 | * The 'NAS Config' flash partition has an ext2 filesystem which |
| 72 | * contains a file that has the ethernet MAC address in plain text |
| 73 | * (format "xx:xx:xx:xx:xx:xx\n"). |
| 74 | */ |
| 75 | void __init qnap_tsx09_find_mac_addr(u32 mem_base, u32 size) |
| 76 | { |
| 77 | unsigned long addr; |
| 78 | |
| 79 | for (addr = mem_base; addr < (mem_base + size); addr += 1024) { |
Andy Shevchenko | 4904dbd | 2015-10-02 17:12:33 +0300 | [diff] [blame] | 80 | void __iomem *nor_page; |
Sylver Bruneau | 530c854 | 2008-05-31 18:21:49 +0200 | [diff] [blame] | 81 | int ret = 0; |
| 82 | |
| 83 | nor_page = ioremap(addr, 1024); |
| 84 | if (nor_page != NULL) { |
Andy Shevchenko | 4904dbd | 2015-10-02 17:12:33 +0300 | [diff] [blame] | 85 | ret = qnap_tsx09_check_mac_addr((__force const char *)nor_page); |
Sylver Bruneau | 530c854 | 2008-05-31 18:21:49 +0200 | [diff] [blame] | 86 | iounmap(nor_page); |
| 87 | } |
| 88 | |
| 89 | if (ret == 0) |
| 90 | break; |
| 91 | } |
| 92 | } |