Linux kernel & device driver programming

Cross-Referenced Linux and Device Driver Code

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