Coding Style cleanup: remove trailing white space
[platform/kernel/u-boot.git] / board / netphone / phone_console.c
index a0485b0..d195a39 100644 (file)
@@ -2,23 +2,7 @@
  * (C) Copyright 2004 Intracom S.A.
  * Pantelis Antoniou <panto@intracom.gr>
  *
- * See file CREDITS for list of people who contributed to this
- * project.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
- * MA 02111-1307 USA
+ * SPDX-License-Identifier:    GPL-2.0+
  */
 
 /*
@@ -37,7 +21,7 @@
 
 #include <version.h>
 #include <linux/types.h>
-#include <devices.h>
+#include <stdio_dev.h>
 
 #include <sed156x.h>
 
 #define ROWS   24
 #define COLS   80
 
-#define REFRESH_HZ             (CFG_HZ/50)     /* refresh every 20ms */
-#define BLINK_HZ               (CFG_HZ/2)      /* cursor blink every 500ms */
+#define REFRESH_HZ             (CONFIG_SYS_HZ/50)      /* refresh every 20ms */
+#define BLINK_HZ               (CONFIG_SYS_HZ/2)       /* cursor blink every 500ms */
 
 /*************************************************************************************************/
 
-#define DISPLAY_BACKLIT_PORT   ((volatile immap_t *)CFG_IMMR)->im_ioport.iop_pcdat
-#define DISPLAY_BACKLIT_MASK   0x0010
+#define DISPLAY_BACKLIT_PORT   ((volatile immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pcdat
+#define DISPLAY_BACKLIT_MASK   0x0010
 
 /*************************************************************************************************/
 
-#define KP_STABLE_HZ           (CFG_HZ/100)    /* stable for 10ms */
-#define KP_REPEAT_DELAY_HZ     (CFG_HZ/4)      /* delay before repeat 250ms */
-#define KP_REPEAT_HZ           (CFG_HZ/20)     /* repeat every 50ms */
-#define KP_FORCE_DELAY_HZ      (CFG_HZ/2)      /* key was force pressed */
-#define KP_IDLE_DELAY_HZ       (CFG_HZ/2)      /* key was released and idle */
+#define KP_STABLE_HZ           (CONFIG_SYS_HZ/100)     /* stable for 10ms */
+#define KP_REPEAT_DELAY_HZ     (CONFIG_SYS_HZ/4)       /* delay before repeat 250ms */
+#define KP_REPEAT_HZ           (CONFIG_SYS_HZ/20)      /* repeat every 50ms */
+#define KP_FORCE_DELAY_HZ      (CONFIG_SYS_HZ/2)       /* key was force pressed */
+#define KP_IDLE_DELAY_HZ       (CONFIG_SYS_HZ/2)       /* key was released and idle */
 
 #if CONFIG_NETPHONE_VERSION == 1
-#define KP_SPI_RXD_PORT        (((volatile immap_t *)CFG_IMMR)->im_ioport.iop_pcdat)
-#define KP_SPI_RXD_MASK        0x0008
+#define KP_SPI_RXD_PORT (((volatile immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pcdat)
+#define KP_SPI_RXD_MASK 0x0008
 
-#define KP_SPI_TXD_PORT        (((volatile immap_t *)CFG_IMMR)->im_ioport.iop_pcdat)
-#define KP_SPI_TXD_MASK        0x0004
+#define KP_SPI_TXD_PORT (((volatile immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pcdat)
+#define KP_SPI_TXD_MASK 0x0004
 
-#define KP_SPI_CLK_PORT        (((volatile immap_t *)CFG_IMMR)->im_ioport.iop_pcdat)
-#define KP_SPI_CLK_MASK        0x0001
+#define KP_SPI_CLK_PORT (((volatile immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pcdat)
+#define KP_SPI_CLK_MASK 0x0001
 #elif CONFIG_NETPHONE_VERSION == 2
-#define KP_SPI_RXD_PORT        (((volatile immap_t *)CFG_IMMR)->im_cpm.cp_pbdat)
-#define KP_SPI_RXD_MASK        0x00000008
+#define KP_SPI_RXD_PORT (((volatile immap_t *)CONFIG_SYS_IMMR)->im_cpm.cp_pbdat)
+#define KP_SPI_RXD_MASK 0x00000008
 
-#define KP_SPI_TXD_PORT        (((volatile immap_t *)CFG_IMMR)->im_cpm.cp_pbdat)
-#define KP_SPI_TXD_MASK        0x00000004
+#define KP_SPI_TXD_PORT (((volatile immap_t *)CONFIG_SYS_IMMR)->im_cpm.cp_pbdat)
+#define KP_SPI_TXD_MASK 0x00000004
 
-#define KP_SPI_CLK_PORT        (((volatile immap_t *)CFG_IMMR)->im_cpm.cp_pbdat)
-#define KP_SPI_CLK_MASK        0x00000002
+#define KP_SPI_CLK_PORT (((volatile immap_t *)CONFIG_SYS_IMMR)->im_cpm.cp_pbdat)
+#define KP_SPI_CLK_MASK 0x00000002
 #endif
 
-#define KP_CS_PORT     (((volatile immap_t *)CFG_IMMR)->im_cpm.cp_pedat)
+#define KP_CS_PORT     (((volatile immap_t *)CONFIG_SYS_IMMR)->im_cpm.cp_pedat)
 #define KP_CS_MASK     0x00000010
 
 #define KP_SPI_RXD() (KP_SPI_RXD_PORT & KP_SPI_RXD_MASK)
                        KP_CS_PORT &= ~KP_CS_MASK; \
        } while(0)
 
-#define KP_ROWS        7
-#define KP_COLS        4
+#define KP_ROWS 7
+#define KP_COLS 4
 
 #define KP_ROWS_MASK   ((1 << KP_ROWS) - 1)
 #define KP_COLS_MASK   ((1 << KP_COLS) - 1)
 #define SCAN           0
 #define SCAN_FILTER    1
 #define SCAN_COL       2
-#define SCAN_COL_FILTER        3
+#define SCAN_COL_FILTER 3
 #define PRESSED                4
 
-#define KP_F1  0       /* leftmost dot (tab) */
-#define KP_F2  1       /* middle left dot    */
-#define KP_F3  2       /* up                 */
-#define KP_F4  3       /* middle right dot   */
-#define KP_F5  4       /* rightmost dot      */
-#define KP_F6  5       /* C                  */
-#define KP_F7  6       /* left               */
-#define KP_F8  7       /* down               */
-#define KP_F9  8       /* right              */
-#define KP_F10 9       /* enter              */
-#define KP_F11 10      /* R                  */
-#define KP_F12 11      /* save               */
-#define KP_F13 12      /* redial             */
-#define KP_F14 13      /* speaker            */
-#define KP_F15  14     /* unused             */
-#define KP_F16  15     /* unused             */
-
-#define KP_RELEASE             -1      /* key depressed                          */
-#define KP_FORCE               -2      /* key was pressed for more than force hz */
-#define KP_IDLE                        -3      /* key was released and idle              */
+#define KP_F1  0       /* leftmost dot (tab)   */
+#define KP_F2  1       /* middle left dot      */
+#define KP_F3  2       /* up                   */
+#define KP_F4  3       /* middle right dot     */
+#define KP_F5  4       /* rightmost dot        */
+#define KP_F6  5       /* C                    */
+#define KP_F7  6       /* left                 */
+#define KP_F8  7       /* down                 */
+#define KP_F9  8       /* right                */
+#define KP_F10 9       /* enter                */
+#define KP_F11 10      /* R                    */
+#define KP_F12 11      /* save                 */
+#define KP_F13 12      /* redial               */
+#define KP_F14 13      /* speaker              */
+#define KP_F15 14      /* unused               */
+#define KP_F16 15      /* unused               */
+
+#define KP_RELEASE             -1      /* key depressed                                */
+#define KP_FORCE               -2      /* key was pressed for more than force hz       */
+#define KP_IDLE                        -3      /* key was released and idle                    */
 
 #define KP_1   '1'
 #define KP_2   '2'
 #define KP_8   '8'
 #define KP_9   '9'
 #define KP_0   '0'
-#define KP_STAR        '*'
-#define KP_HASH        '#'
+#define KP_STAR '*'
+#define KP_HASH '#'
 
 /*************************************************************************************************/
 
@@ -179,7 +163,6 @@ static int last_input_mode;
 static int refresh_time;
 static int blink_time;
 static char last_fast_punct;
-static int last_tab_indicator = -1;
 
 /*************************************************************************************************/
 
@@ -199,7 +182,7 @@ static const char *whspace = " 0\n";
 /* per mode character select (for 2-9) */
 static const char *digits_sel[2][8] = {
        {       /* small */
-               "abc2",                                 /* 2 */
+               "abc2",                                 /* 2 */
                "def3",                                 /* 3 */
                "ghi4",                                 /* 4 */
                "jkl5",                                 /* 5 */
@@ -207,8 +190,8 @@ static const char *digits_sel[2][8] = {
                "pqrs7",                                /* 7 */
                "tuv8",                                 /* 8 */
                "wxyz9",                                /* 9 */
-       }, {    /* capital */
-               "ABC2",                                 /* 2 */
+       }, {    /* capital */
+               "ABC2",                                 /* 2 */
                "DEF3",                                 /* 3 */
                "GHI4",                                 /* 4 */
                "JKL5",                                 /* 5 */
@@ -239,8 +222,6 @@ static void console_init(void)
        refresh_time = REFRESH_HZ;
        blink_time = BLINK_HZ;
 
-       tab_indicator = 1;
-
        memset(vty_buf, ' ', sizeof(vty_buf));
 
        memset(last_visible_buf, ' ', sizeof(last_visible_buf));
@@ -253,6 +234,8 @@ static void console_init(void)
        sed156x_init();
        width = sed156x_text_width;
        height = sed156x_text_height - 1;
+
+       tab_indicator = 0;
 }
 
 /*****************************************************************************/
@@ -326,14 +309,7 @@ int phone_getc(void)
 
 int drv_phone_init(void)
 {
-       device_t console_dev;
-       char *penv;
-
-       /*
-        * Force console i/o to serial ?
-        */
-       if ((penv = getenv("console")) != NULL && strcmp(penv, "serial") == 0)
-               return 0;
+       struct stdio_dev console_dev;
 
        console_init();
 
@@ -348,7 +324,7 @@ int drv_phone_init(void)
        console_dev.tstc = phone_tstc;  /* 'tstc' function */
        console_dev.getc = phone_getc;  /* 'getc' function */
 
-       if (device_register(&console_dev) == 0)
+       if (stdio_register(&console_dev) == 0)
                return 1;
 
        return 0;
@@ -718,8 +694,10 @@ static void update(void)
        if (input_mode != last_input_mode)
                sed156x_output_at(sed156x_text_width - 3, sed156x_text_height - 1, input_mode_txt[input_mode], 3);
 
-       if (tab_indicator != last_tab_indicator)
+       if (tab_indicator == 0) {
                sed156x_output_at(0, sed156x_text_height - 1, "\\t", 2);
+               tab_indicator = 1;
+       }
 
        if (fast_punct != last_fast_punct)
                sed156x_output_at(4, sed156x_text_height - 1, &fast_punct, 1);
@@ -779,7 +757,6 @@ static void update(void)
 
        last_input_mode = input_mode;
        last_fast_punct = fast_punct;
-       last_tab_indicator = tab_indicator;
 }
 
 /* ensure visibility; the trick is to minimize the screen movement */
@@ -810,10 +787,10 @@ static void ensure_visible(int col, int row, int dx, int dy)
 
 
        /* move to easier to use vars */
-       x1 = disp_col;   y1 = disp_row;
+       x1 = disp_col;   y1 = disp_row;
        x2 = x1 + width; y2 = y1 + height;
-       a1 = col;        b1 = row;
-       a2 = a1 + dx;    b2 = b1 + dy;
+       a1 = col;        b1 = row;
+       a2 = a1 + dx;    b2 = b1 + dy;
 
        /* printf("(%d,%d) - (%d,%d) : (%d, %d) - (%d, %d)\n", x1, y1, x2, y2, a1, b1, a2, b2); */
 
@@ -891,7 +868,8 @@ void phone_putc(const char c)
        blink_time = BLINK_HZ;
 
        switch (c) {
-               case 13:                /* ignore */
+               case '\a':              /* ignore bell            */
+               case '\r':              /* ignore carriage return */
                        break;
 
                case '\n':              /* next line */
@@ -899,7 +877,7 @@ void phone_putc(const char c)
                        ensure_visible(curs_col, curs_row, 1, 1);
                        break;
 
-               case 9: /* tab 8 */
+               case 9: /* tab 8 */
                        /* move to tab */
                        i = curs_col;
                        i |=  0x0008;
@@ -989,7 +967,7 @@ unsigned int kp_get_col_mask(unsigned int row_mask)
 #if CONFIG_NETPHONE_VERSION == 1
        col_mask = kp_data_transfer(val) & 0x0F;
 #elif CONFIG_NETPHONE_VERSION == 2
-       col_mask = ((volatile immap_t *)CFG_IMMR)->im_cpm.cp_pedat & 0x0f;
+       col_mask = ((volatile immap_t *)CONFIG_SYS_IMMR)->im_cpm.cp_pedat & 0x0f;
        /* XXX FUCK FUCK FUCK FUCK FUCK!!!! */
        col_mask = ((col_mask & 0x08) >> 3) |   /* BKBR1 */
                   ((col_mask & 0x04) << 1) |   /* BKBR2 */
@@ -1005,13 +983,13 @@ unsigned int kp_get_col_mask(unsigned int row_mask)
 /**************************************************************************************/
 
 static const int kp_scancodes[KP_ROWS * KP_COLS] = {
-       KP_F1,   KP_F3,   KP_F4,  KP_F2,
-       KP_F6,   KP_F8,   KP_F9,  KP_F7,
-       KP_1,    KP_3,    KP_F11, KP_2,
-       KP_4,    KP_6,    KP_F12, KP_5,
-       KP_7,    KP_9,    KP_F13, KP_8,
+       KP_F1,   KP_F3,   KP_F4,  KP_F2,
+       KP_F6,   KP_F8,   KP_F9,  KP_F7,
+       KP_1,    KP_3,    KP_F11, KP_2,
+       KP_4,    KP_6,    KP_F12, KP_5,
+       KP_7,    KP_9,    KP_F13, KP_8,
        KP_STAR, KP_HASH, KP_F14, KP_0,
-       KP_F5,   KP_F15,  KP_F16, KP_F10,
+       KP_F5,   KP_F15,  KP_F16, KP_F10,
 };
 
 static const int kp_repeats[KP_ROWS * KP_COLS] = {
@@ -1141,3 +1119,10 @@ static void kp_do_poll(void)
                        break;
        }
 }
+
+/**************************************************************************************/
+
+int drv_phone_is_idle(void)
+{
+       return kp_state == SCAN;
+}