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

TOMOYO Linux Cross Reference
Linux/arch/powerpc/platforms/embedded6xx/ls_uart.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 /*
  2  * AVR power-management chip interface for the Buffalo Linkstation /
  3  * Kurobox Platform.
  4  *
  5  * Author: 2006 (c) G. Liakhovetski
  6  *       g.liakhovetski@gmx.de
  7  *
  8  * This file is licensed under the terms of the GNU General Public License
  9  * version 2.  This program is licensed "as is" without any warranty of
 10  * any kind, whether express or implied.
 11  */
 12 #include <linux/workqueue.h>
 13 #include <linux/string.h>
 14 #include <linux/delay.h>
 15 #include <linux/serial_reg.h>
 16 #include <linux/serial_8250.h>
 17 #include <linux/of.h>
 18 #include <linux/of_address.h>
 19 #include <asm/io.h>
 20 #include <asm/termbits.h>
 21 
 22 #include "mpc10x.h"
 23 
 24 static void __iomem *avr_addr;
 25 static unsigned long avr_clock;
 26 
 27 static struct work_struct wd_work;
 28 
 29 static void wd_stop(struct work_struct *unused)
 30 {
 31         const char string[] = "AAAAFFFFJJJJ>>>>VVVV>>>>ZZZZVVVVKKKK";
 32         int i = 0, rescue = 8;
 33         int len = strlen(string);
 34 
 35         while (rescue--) {
 36                 int j;
 37                 char lsr = in_8(avr_addr + UART_LSR);
 38 
 39                 if (lsr & (UART_LSR_THRE | UART_LSR_TEMT)) {
 40                         for (j = 0; j < 16 && i < len; j++, i++)
 41                                 out_8(avr_addr + UART_TX, string[i]);
 42                         if (i == len) {
 43                                 /* Read "OK" back: 4ms for the last "KKKK"
 44                                    plus a couple bytes back */
 45                                 msleep(7);
 46                                 printk("linkstation: disarming the AVR watchdog: ");
 47                                 while (in_8(avr_addr + UART_LSR) & UART_LSR_DR)
 48                                         printk("%c", in_8(avr_addr + UART_RX));
 49                                 break;
 50                         }
 51                 }
 52                 msleep(17);
 53         }
 54         printk("\n");
 55 }
 56 
 57 #define AVR_QUOT(clock) ((clock) + 8 * 9600) / (16 * 9600)
 58 
 59 void avr_uart_configure(void)
 60 {
 61         unsigned char cval = UART_LCR_WLEN8;
 62         unsigned int quot = AVR_QUOT(avr_clock);
 63 
 64         if (!avr_addr || !avr_clock)
 65                 return;
 66 
 67         out_8(avr_addr + UART_LCR, cval);                       /* initialise UART */
 68         out_8(avr_addr + UART_MCR, 0);
 69         out_8(avr_addr + UART_IER, 0);
 70 
 71         cval |= UART_LCR_STOP | UART_LCR_PARITY | UART_LCR_EPAR;
 72 
 73         out_8(avr_addr + UART_LCR, cval);                       /* Set character format */
 74 
 75         out_8(avr_addr + UART_LCR, cval | UART_LCR_DLAB);       /* set DLAB */
 76         out_8(avr_addr + UART_DLL, quot & 0xff);                /* LS of divisor */
 77         out_8(avr_addr + UART_DLM, quot >> 8);                  /* MS of divisor */
 78         out_8(avr_addr + UART_LCR, cval);                       /* reset DLAB */
 79         out_8(avr_addr + UART_FCR, UART_FCR_ENABLE_FIFO);       /* enable FIFO */
 80 }
 81 
 82 void avr_uart_send(const char c)
 83 {
 84         if (!avr_addr || !avr_clock)
 85                 return;
 86 
 87         out_8(avr_addr + UART_TX, c);
 88         out_8(avr_addr + UART_TX, c);
 89         out_8(avr_addr + UART_TX, c);
 90         out_8(avr_addr + UART_TX, c);
 91 }
 92 
 93 static void __init ls_uart_init(void)
 94 {
 95         local_irq_disable();
 96 
 97 #ifndef CONFIG_SERIAL_8250
 98         out_8(avr_addr + UART_FCR, UART_FCR_ENABLE_FIFO);       /* enable FIFO */
 99         out_8(avr_addr + UART_FCR, UART_FCR_ENABLE_FIFO |
100               UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT);       /* clear FIFOs */
101         out_8(avr_addr + UART_FCR, 0);
102         out_8(avr_addr + UART_IER, 0);
103 
104         /* Clear up interrupts */
105         (void) in_8(avr_addr + UART_LSR);
106         (void) in_8(avr_addr + UART_RX);
107         (void) in_8(avr_addr + UART_IIR);
108         (void) in_8(avr_addr + UART_MSR);
109 #endif
110         avr_uart_configure();
111 
112         local_irq_enable();
113 }
114 
115 static int __init ls_uarts_init(void)
116 {
117         struct device_node *avr;
118         struct resource res;
119         int len, ret;
120 
121         avr = of_find_node_by_path("/soc10x/serial@80004500");
122         if (!avr)
123                 return -EINVAL;
124 
125         avr_clock = *(u32*)of_get_property(avr, "clock-frequency", &len);
126         if (!avr_clock)
127                 return -EINVAL;
128 
129         ret = of_address_to_resource(avr, 0, &res);
130         if (ret)
131                 return ret;
132 
133         of_node_put(avr);
134 
135         avr_addr = ioremap(res.start, 32);
136         if (!avr_addr)
137                 return -EFAULT;
138 
139         ls_uart_init();
140 
141         INIT_WORK(&wd_work, wd_stop);
142         schedule_work(&wd_work);
143 
144         return 0;
145 }
146 
147 machine_late_initcall(linkstation, ls_uarts_init);
148 

~ [ 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