~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/arm/mach-orion5x/tsx09-common.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0-or-later
  2 /*
  3  * QNAP TS-x09 Boards common functions
  4  *
  5  * Maintainers: Lennert Buytenhek <buytenh@marvell.com>
  6  *              Byron Bradley <byron.bbradley@gmail.com>
  7  */
  8 
  9 #include <linux/kernel.h>
 10 #include <linux/pci.h>
 11 #include <linux/mv643xx_eth.h>
 12 #include <linux/timex.h>
 13 #include <linux/serial_reg.h>
 14 #include "orion5x.h"
 15 #include "tsx09-common.h"
 16 #include "common.h"
 17 
 18 /*****************************************************************************
 19  * QNAP TS-x09 specific power off method via UART1-attached PIC
 20  ****************************************************************************/
 21 
 22 #define UART1_REG(x)    (UART1_VIRT_BASE + ((UART_##x) << 2))
 23 
 24 void qnap_tsx09_power_off(void)
 25 {
 26         /* 19200 baud divisor */
 27         const unsigned divisor = ((orion5x_tclk + (8 * 19200)) / (16 * 19200));
 28 
 29         pr_info("%s: triggering power-off...\n", __func__);
 30 
 31         /* hijack uart1 and reset into sane state (19200,8n1) */
 32         writel(0x83, UART1_REG(LCR));
 33         writel(divisor & 0xff, UART1_REG(DLL));
 34         writel((divisor >> 8) & 0xff, UART1_REG(DLM));
 35         writel(0x03, UART1_REG(LCR));
 36         writel(0x00, UART1_REG(IER));
 37         writel(0x00, UART1_REG(FCR));
 38         writel(0x00, UART1_REG(MCR));
 39 
 40         /* send the power-off command 'A' to PIC */
 41         writel('A', UART1_REG(TX));
 42 }
 43 
 44 /*****************************************************************************
 45  * Ethernet
 46  ****************************************************************************/
 47 
 48 struct mv643xx_eth_platform_data qnap_tsx09_eth_data = {
 49         .phy_addr       = MV643XX_ETH_PHY_ADDR(8),
 50 };
 51 
 52 static int __init qnap_tsx09_parse_hex_nibble(char n)
 53 {
 54         if (n >= '' && n <= '9')
 55                 return n - '';
 56 
 57         if (n >= 'A' && n <= 'F')
 58                 return n - 'A' + 10;
 59 
 60         if (n >= 'a' && n <= 'f')
 61                 return n - 'a' + 10;
 62 
 63         return -1;
 64 }
 65 
 66 static int __init qnap_tsx09_parse_hex_byte(const char *b)
 67 {
 68         int hi;
 69         int lo;
 70 
 71         hi = qnap_tsx09_parse_hex_nibble(b[0]);
 72         lo = qnap_tsx09_parse_hex_nibble(b[1]);
 73 
 74         if (hi < 0 || lo < 0)
 75                 return -1;
 76 
 77         return (hi << 4) | lo;
 78 }
 79 
 80 static int __init qnap_tsx09_check_mac_addr(const char *addr_str)
 81 {
 82         u_int8_t addr[6];
 83         int i;
 84 
 85         for (i = 0; i < 6; i++) {
 86                 int byte;
 87 
 88                 /*
 89                  * Enforce "xx:xx:xx:xx:xx:xx\n" format.
 90                  */
 91                 if (addr_str[(i * 3) + 2] != ((i < 5) ? ':' : '\n'))
 92                         return -1;
 93 
 94                 byte = qnap_tsx09_parse_hex_byte(addr_str + (i * 3));
 95                 if (byte < 0)
 96                         return -1;
 97                 addr[i] = byte;
 98         }
 99 
100         printk(KERN_INFO "tsx09: found ethernet mac address %pM\n", addr);
101 
102         memcpy(qnap_tsx09_eth_data.mac_addr, addr, 6);
103 
104         return 0;
105 }
106 
107 /*
108  * The 'NAS Config' flash partition has an ext2 filesystem which
109  * contains a file that has the ethernet MAC address in plain text
110  * (format "xx:xx:xx:xx:xx:xx\n").
111  */
112 void __init qnap_tsx09_find_mac_addr(u32 mem_base, u32 size)
113 {
114         unsigned long addr;
115 
116         for (addr = mem_base; addr < (mem_base + size); addr += 1024) {
117                 char *nor_page;
118                 int ret = 0;
119 
120                 nor_page = ioremap(addr, 1024);
121                 if (nor_page != NULL) {
122                         ret = qnap_tsx09_check_mac_addr(nor_page);
123                         iounmap(nor_page);
124                 }
125 
126                 if (ret == 0)
127                         break;
128         }
129 }
130 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php