]> www.infradead.org Git - users/rw/ppcboot.git/commitdiff
Add LCD driver for R360MPI board.
authorwdenk <wdenk>
Fri, 26 Jul 2002 11:33:15 +0000 (11:33 +0000)
committerwdenk <wdenk>
Fri, 26 Jul 2002 11:33:15 +0000 (11:33 +0000)
Support LCD display that don't use 8 bpp
(like the monochrome on the R360MPI).

board/r360mpi/flash.c
board/r360mpi/r360mpi.c
cpu/mpc8xx/lcd.c
include/configs/R360MPI.h

index 84276f9cef5dd0fbca4c37a1d79b7c4afc69a28b..35c3c1a8660a65226b3b79de3adfe02b35c0cfb5 100644 (file)
@@ -310,9 +310,9 @@ int flash_erase (flash_info_t *info, int s_first, int s_last)
                        }
 
                        *addr = (FPW)0x00FF00FF;        /* reset to read mode */
-                       printf (" done\n");
                }
        }
+       printf (" done\n");
        return rcode;
 }
 
@@ -328,7 +328,11 @@ int write_buff (flash_info_t *info, uchar *src, ulong addr, ulong cnt)
 {
        ulong cp, wp;
        FPW data;
+#if 0
        int count, i, l, rc, port_width;
+#else
+       int i, l, rc, port_width;
+#endif
 
        if (info->flash_id == FLASH_UNKNOWN) {
                return 4;
@@ -386,7 +390,9 @@ int write_buff (flash_info_t *info, uchar *src, ulong addr, ulong cnt)
        /*
         * handle word aligned part
         */
+#if 0
        count = 0;
+#endif
        while (cnt >= port_width) {
                data = 0;
                for (i=0; i<port_width; ++i) {
@@ -397,11 +403,13 @@ int write_buff (flash_info_t *info, uchar *src, ulong addr, ulong cnt)
                }
                wp  += port_width;
                cnt -= port_width;
-               if (count++ > 0x800)
+#if 0
+               if (count++ > 0x20000)
                {
                        putc('.');
                        count = 0;
                }
+#endif
        }
 
        if (cnt == 0) {
index 75f92c18f1e498363ee3b865321841c8a4ac4b85..6562ee80ff788604ecd4c493caa0d45ef648f0a9 100644 (file)
@@ -24,6 +24,7 @@
 #include <ppcboot.h>
 #include <config.h>
 #include <mpc8xx.h>
+#include <i2c.h>
 
 /*
  *  Memory Controller Using
@@ -240,3 +241,12 @@ static long int dram_size (long int mamr_value, long int *base, long int maxsize
     }
     return (maxsize);
 }
+
+/* ------------------------------------------------------------------------- */
+
+void  r360_pwm_write (uchar reg, uchar val) {
+    if (i2c_write(CFG_I2C_PWM_ADDR, reg, 1, &val, 1)) {
+       printf("Can't write PWM register 0x%02X.\n", reg);
+    }
+}
+
index 4ffa90cb06a94c6301446e7271973c834ddf73d6..6fd30be9855af0621d952544e00fe80dfdf8bdcd 100644 (file)
 /************************************************************************/
 /* ** CONFIG STUFF -- should be moved to board config file             */
 /************************************************************************/
+#ifndef CONFIG_EDT32F10
 #define CONFIG_LCD_LOGO
 #define LCD_INFO               /* Display Logo, (C) and system info    */
+#endif
 /* #define LCD_TEST_PATTERN */ /* color backgnd for frame/color adjust */
 /* #define CFG_INVERT_COLORS */        /* Not needed - adjust vl_dp instead    */
 /************************************************************************/
 /* ** CONSOLE CONSTANTS                                                        */
 /************************************************************************/
 
+#if LCD_BPP == LCD_MONOCHROME
+
+/*
+ * Simple color definitions
+ */
+#define CONSOLE_COLOR_BLACK     0
+#define CONSOLE_COLOR_WHITE     1      /* Must remain last / highest */
+
+#else
+
 /*
  * Simple color definitions
  */
 #define CONSOLE_COLOR_GREY     14
 #define CONSOLE_COLOR_WHITE    15      /* Must remain last / highest */
 
+#endif
+
 #if defined(CONFIG_LCD_LOGO) && (CONSOLE_COLOR_WHITE >= BMP_LOGO_OFFSET)
 #error Default Color Map overlaps with Logo Color Map
 #endif
@@ -114,6 +128,7 @@ static void lcd_enable (void);
 static void    *lcd_logo (bd_t *bd);
 static void    lcd_setcolreg (ushort regno,
                                ushort red, ushort green, ushort blue);
+static void    lcd_initcolregs (void);
 static int     lcd_getbgcolor (void);
 static void    lcd_setfgcolor (int color);
 static void    lcd_setbgcolor (int color);
@@ -166,6 +181,11 @@ typedef struct vidinfo {
     u_char     vl_wbf;         /* Wait between frames */
 } vidinfo_t;
 
+#define LCD_MONOCHROME 0
+#define LCD_COLOR2     1
+#define LCD_COLOR4     2
+#define LCD_COLOR8     3
+
 /*----------------------------------------------------------------------*/
 #ifdef CONFIG_NEC_NL6648AC33
 /*
@@ -270,8 +290,29 @@ static vidinfo_t panel_info = {
     OPTREX_BPP, 0, 0, 0, 0, 0, 0, 0, 0, 4
 };
 #endif /* CONFIG_OPTREX_BW */
+
+/*-----------------------------------------------------------------*/
+#ifdef CONFIG_EDT32F10
+/*
+ * Emerging Display Technologies 320x240. Passive, monochrome, single scan.
+ */
+#define LCD_BPP                LCD_MONOCHROME
+#define LCD_DF         20
+
+static vidinfo_t panel_info = {
+    320, 240, 0, 0, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_HIGH, CFG_LOW,
+    LCD_BPP,  0, 0, 0, 0, 0, 15, 0, 0
+};
+#endif
 /*----------------------------------------------------------------------*/
 
+#ifndef LCD_BPP
+#define LCD_BPP                        LCD_COLOR8
+#endif
+#ifndef LCD_DF
+#define LCD_DF                 1
+#endif
+
 #define NBITS(bit_code)                (1 << (bit_code))
 #define NCOLORS(bit_code)      (1 << NBITS(bit_code))
 
@@ -309,6 +350,15 @@ static void *lcd_console_address;  /* Start of console buffer      */
 #define CONSOLE_SIZE           (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
 #define CONSOLE_SCROLL_SIZE    (CONSOLE_SIZE - CONSOLE_ROW_SIZE)
 
+#if  LCD_BPP == LCD_MONOCHROME
+#define COLOR_MASK(c)          ((c)      | (c) << 1 | (c) << 2 | (c) << 3 | \
+                                (c) << 4 | (c) << 5 | (c) << 6 | (c) << 7)
+#elif LCD_BPP == LCD_COLOR8
+#define COLOR_MASK(c)          (c)
+#else
+#error Unsupported LCD BPP.
+#endif
+
 static short console_col;
 static short console_row;
 
@@ -321,10 +371,7 @@ static void console_scrollup (void)
        memcpy (CONSOLE_ROW_FIRST, CONSOLE_ROW_SECOND, CONSOLE_SCROLL_SIZE);
 
        /* Clear the last one */
-       /*
-        * WARNING: the following code assumes 8 Bits per pixel
-        */
-       memset (CONSOLE_ROW_LAST, lcd_color_bg, CONSOLE_ROW_SIZE);
+       memset (CONSOLE_ROW_LAST, COLOR_MASK(lcd_color_bg), CONSOLE_ROW_SIZE);
 #else
        /*
         * Poor attempt to optimize speed by moving "long"s.
@@ -438,30 +485,44 @@ void lcd_puts (const char *s)
 static void lcd_drawchars (ushort x, ushort y, uchar *str, int count)
 {
        uchar *dest;
-       ushort row;
+       ushort off, row;
 
-       dest = (uchar *)(lcd_base + y * lcd_line_length + x);
+       dest = (uchar *)(lcd_base + y * lcd_line_length + x * (1 << LCD_BPP) / 8);
+       off  = x * (1 << LCD_BPP) % 8;
 
-       /*
-        * WARNING: the following code assumes 8 Bits per pixel
-        */
        for (row=0;  row < VIDEO_FONT_HEIGHT;  ++row, dest += lcd_line_length)  {
                uchar *s = str;
                uchar *d = dest;
                int i;
 
+#if LCD_BPP == LCD_MONOCHROME
+               uchar rest = *d & -(1 << (8-off));
+               uchar sym;
+#endif
                for (i=0; i<count; ++i) {
                        uchar c, bits;
 
                        c = *s++;
                        bits = video_fontdata[c * VIDEO_FONT_HEIGHT + row];
 
+#if LCD_BPP == LCD_MONOCHROME
+                       sym  = (COLOR_MASK(lcd_color_fg) & bits) |
+                              (COLOR_MASK(lcd_color_bg) & ~bits);
+
+                       *d++ = rest | (sym >> off);
+                       rest = sym << (8-off);
+#elif LCD_BPP == LCD_COLOR8
                        for (c=0; c<8; ++c) {
                                *d++ = (bits & 0x80) ?
                                                lcd_color_fg : lcd_color_bg;
                                bits <<= 1;
                        }
+#endif
                }
+
+#if LCD_BPP == LCD_MONOCHROME
+               *d  = rest | (*d & ((1 << (8-off)) - 1));
+#endif
        }
 }
 
@@ -563,6 +624,11 @@ static int lcd_init (bd_t *bd, void *lcdbase)
 
        lcd_ctrl_init (lcdbase);
 
+#if LCD_BPP == LCD_MONOCHROME
+       /* Setting the palette */
+       lcd_initcolregs();
+
+#elif LCD_BPP == LCD_COLOR8
        /* Setting the palette */
        lcd_setcolreg  (CONSOLE_COLOR_BLACK,       0,    0,    0);
        lcd_setcolreg  (CONSOLE_COLOR_RED,      0xFF,    0,    0);
@@ -573,6 +639,7 @@ static int lcd_init (bd_t *bd, void *lcdbase)
        lcd_setcolreg  (CONSOLE_COLOR_CYAN,        0, 0xFF, 0xFF);
        lcd_setcolreg  (CONSOLE_COLOR_GREY,     0xAA, 0xAA, 0xAA);
        lcd_setcolreg  (CONSOLE_COLOR_WHITE,    0xFF, 0xFF, 0xFF);
+#endif
 
 #ifndef CFG_WHITE_ON_BLACK
        lcd_setfgcolor (CONSOLE_COLOR_BLACK);
@@ -586,11 +653,8 @@ static int lcd_init (bd_t *bd, void *lcdbase)
        test_pattern();
 #else
        /* set framebuffer to background color */
-       /*
-        * WARNING: the following code assumes 8 Bits per pixel
-        */
        memset ((char *)lcd_base,
-               lcd_getbgcolor(),
+               COLOR_MASK(lcd_getbgcolor()),
                lcd_line_length*panel_info.vl_row);
 #endif
 
@@ -659,7 +723,7 @@ static void lcd_ctrl_init (void *lcdbase)
         */
 
        lccrtmp  = LCDBIT (LCCR_BNUM_BIT,
-                          (((panel_info.vl_row * panel_info.vl_col) * 8) / 128));
+                  (((panel_info.vl_row * panel_info.vl_col) * (1 << LCD_BPP)) / 128));
 
        lccrtmp |= LCDBIT (LCCR_CLKP_BIT, panel_info.vl_clkp)   |
                   LCDBIT (LCCR_OEP_BIT,  panel_info.vl_oep)    |
@@ -693,8 +757,9 @@ static void lcd_ctrl_init (void *lcdbase)
         * 64 MHz would be bad).
         */
        immr->im_clkrst.car_sccr &= ~0x1F;
-       immr->im_clkrst.car_sccr |= 1;  /* was 8 */
+       immr->im_clkrst.car_sccr |= LCD_DF;     /* was 8 */
 
+#ifndef CONFIG_EDT32F10
        /* Enable LCD on port D.
         */
        immr->im_ioport.iop_pdpar |= 0x1FFF;
@@ -704,6 +769,14 @@ static void lcd_ctrl_init (void *lcdbase)
         */
        immr->im_cpm.cp_pbpar |= 0x00005001;
        immr->im_cpm.cp_pbdir |= 0x00005001;
+#else
+       /* Enable LCD on port D.
+        */
+       immr->im_ioport.iop_pdpar |= 0x1DFF;
+       immr->im_ioport.iop_pdpar &= ~0x0200;
+       immr->im_ioport.iop_pddir |= 0x1FFF;
+       immr->im_ioport.iop_pddat |= 0x0200;
+#endif
 
        /* Load the physical address of the linear frame buffer
         * into the LCD controller.
@@ -716,10 +789,18 @@ static void lcd_ctrl_init (void *lcdbase)
        /* MORE HACKS...This must be updated according to 823 manual
         * for different panels.
         */
+#ifndef CONFIG_EDT32F10
        lcdp->lcd_lchcr = LCHCR_BO |
                          LCDBIT (LCHCR_AT_BIT, 4) |
                          LCDBIT (LCHCR_HPC_BIT, panel_info.vl_col) |
                          panel_info.vl_wbl;
+#else
+       lcdp->lcd_lchcr = LCHCR_BO |
+                         LCDBIT (LCHCR_AT_BIT, 4) |
+                         LCDBIT (LCHCR_HPC_BIT, panel_info.vl_col/4) |
+                         panel_info.vl_wbl;
+#endif
+
        lcdp->lcd_lcvcr = LCDBIT (LCVCR_VPW_BIT, panel_info.vl_vpw) |
                          LCDBIT (LCVCR_LCD_AC_BIT, panel_info.vl_lcdac) |
                          LCDBIT (LCVCR_VPC_BIT, panel_info.vl_row) |
@@ -777,6 +858,21 @@ lcd_setcolreg (ushort regno, ushort red, ushort green, ushort blue)
 
 /*----------------------------------------------------------------------*/
 
+static
+void lcd_initcolregs (void)
+{
+       volatile immap_t *immr = (immap_t *) CFG_IMMR;
+       volatile cpm8xx_t *cp = &(immr->im_cpm);
+       ushort regno;
+
+       for (regno = 0; regno < 16; regno++) {
+               cp->lcd_cmap[regno * 2] = 0;
+               cp->lcd_cmap[(regno * 2) + 1] = regno & 0x0f;
+       }
+}
+
+/*----------------------------------------------------------------------*/
+
 static void lcd_setfgcolor (int color)
 {
        lcd_color_fg = color & 0x0F;
@@ -815,11 +911,19 @@ static void lcd_enable (void)
        /* Enable the LCD panel */
        immr->im_siu_conf.sc_sdcr |= (1 << (31 - 25));          /* LAM = 1 */
        lcdp->lcd_lccr |= LCCR_PON;
-#ifdef CONFIG_LWMON
+#if defined(CONFIG_LWMON)
     {  uchar c = pic_read (0x60);
        c |= 0x07;      /* Power on CCFL, Enable CCFL, Chip Enable LCD */
        pic_write (0x60, c);
     }
+#elif defined(CONFIG_R360MPI)
+    {
+       extern void r360_pwm_write (uchar reg, uchar val);
+
+       r360_pwm_write(8, 1);
+       r360_pwm_write(0, 4);
+       r360_pwm_write(1, 6);
+    }
 #endif /* CONFIG_LWMON */
 }
 
@@ -831,11 +935,18 @@ static void lcd_disable (void)
        volatile immap_t *immr = (immap_t *) CFG_IMMR;
        volatile lcd823_t *lcdp = &immr->im_lcd;
 
-#ifdef CONFIG_LWMON
+#if defined(CONFIG_LWMON)
     {  uchar c = pic_read (0x60);
        c &= ~0x07;     /* Power off CCFL, Disable CCFL, Chip Disable LCD */
        pic_write (0x60, c);
     }
+#elif defined(CONFIG_R360MPI)
+    {
+       extern void r360_pwm_write (uchar reg, uchar val);
+
+       r360_pwm_write(0, 0);
+       r360_pwm_write(1, 0);
+    }
 #endif /* CONFIG_LWMON */
        /* Disable the LCD panel */
        lcdp->lcd_lccr &= ~LCCR_PON;
index 1f2afc42f3ca16b0fc35d9b999797c14cee6783f..f6d95f01536c1f3ab19a1249b7a47b26b8b88dba 100644 (file)
@@ -36,9 +36,8 @@
 #define CONFIG_MPC823          1       /* This is a MPC823 CPU         */
 #define CONFIG_R360MPI         1
 
-#ifdef CONFIG_LCD                      /* with LCD controller ?        */
-/* #define CONFIG_NEC_NL6648BC20 1 / * use NEC NL6648BC20 display      */
-#endif
+#define CONFIG_LCD
+#define CONFIG_EDT32F10
 
 #define MPC8XX_FACT             1              /* Multiply by 1        */
 #define MPC8XX_XIN              50000000       /* 50 MHz in            */
 
 #define        CONFIG_RTC_MPC8xx               /* use internal RTC of MPC8xx   */
 
+#define CONFIG_SOFT_I2C                1       /* To I2C with hardware support */
+#define CFG_I2C_SPEED          500000  /* I2C speed and slave address */
+#define CFG_I2C_SLAVE          0x7F
+
+/*
+ * Software (bit-bang) I2C driver configuration
+ */
+#define PB_SCL                 0x00000020      /* PB 26 */
+#define PB_SDA                 0x00000010      /* PB 27 */
+
+#define I2C_INIT               (immr->im_cpm.cp_pbdir |=  PB_SCL)
+#define I2C_ACTIVE             (immr->im_cpm.cp_pbdir |=  PB_SDA)
+#define I2C_TRISTATE           (immr->im_cpm.cp_pbdir &= ~PB_SDA)
+#define I2C_READ               ((immr->im_cpm.cp_pbdat & PB_SDA) != 0)
+#define I2C_SDA(bit)           if(bit) immr->im_cpm.cp_pbdat |=  PB_SDA; \
+                               else    immr->im_cpm.cp_pbdat &= ~PB_SDA
+#define I2C_SCL(bit)           if(bit) immr->im_cpm.cp_pbdat |=  PB_SCL; \
+                               else    immr->im_cpm.cp_pbdat &= ~PB_SCL
+#define I2C_DELAY              udelay(50)
+
+#define CFG_I2C_PWM_ADDR       0x58    /* Power management coprocessor */
+#define CFG_I2C_KBD_ADDR       0x50    /* Keyboard coprocessor */
+#define CFG_I2C_TERM_ADDR      0x49    /* Temperature Sensors */
+
 #define CONFIG_COMMANDS              ( CONFIG_CMD_DFL  | \
                                CFG_CMD_DHCP    | \
-                               CFG_CMD_DATE    )
+                               CFG_CMD_DATE    | \
+                               CFG_CMD_I2C     )
 
 /* this must be included AFTER the definition of CONFIG_COMMANDS (if any) */
 #include <cmd_confdefs.h>