18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * Driver for the LCD display on the Tensilica XTFPGA board family. 38c2ecf20Sopenharmony_ci * http://www.mytechcorp.com/cfdata/productFile/File1/MOC-16216B-B-A0A04.pdf 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * This file is subject to the terms and conditions of the GNU General Public 68c2ecf20Sopenharmony_ci * License. See the file "COPYING" in the main directory of this archive 78c2ecf20Sopenharmony_ci * for more details. 88c2ecf20Sopenharmony_ci * 98c2ecf20Sopenharmony_ci * Copyright (C) 2001, 2006 Tensilica Inc. 108c2ecf20Sopenharmony_ci * Copyright (C) 2015 Cadence Design Systems Inc. 118c2ecf20Sopenharmony_ci */ 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci#include <linux/delay.h> 148c2ecf20Sopenharmony_ci#include <linux/init.h> 158c2ecf20Sopenharmony_ci#include <linux/io.h> 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci#include <platform/hardware.h> 188c2ecf20Sopenharmony_ci#include <platform/lcd.h> 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ci/* LCD instruction and data addresses. */ 218c2ecf20Sopenharmony_ci#define LCD_INSTR_ADDR ((char *)IOADDR(CONFIG_XTFPGA_LCD_BASE_ADDR)) 228c2ecf20Sopenharmony_ci#define LCD_DATA_ADDR (LCD_INSTR_ADDR + 4) 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci#define LCD_CLEAR 0x1 258c2ecf20Sopenharmony_ci#define LCD_DISPLAY_ON 0xc 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci/* 8bit and 2 lines display */ 288c2ecf20Sopenharmony_ci#define LCD_DISPLAY_MODE8BIT 0x38 298c2ecf20Sopenharmony_ci#define LCD_DISPLAY_MODE4BIT 0x28 308c2ecf20Sopenharmony_ci#define LCD_DISPLAY_POS 0x80 318c2ecf20Sopenharmony_ci#define LCD_SHIFT_LEFT 0x18 328c2ecf20Sopenharmony_ci#define LCD_SHIFT_RIGHT 0x1c 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_cistatic void lcd_put_byte(u8 *addr, u8 data) 358c2ecf20Sopenharmony_ci{ 368c2ecf20Sopenharmony_ci#ifdef CONFIG_XTFPGA_LCD_8BIT_ACCESS 378c2ecf20Sopenharmony_ci WRITE_ONCE(*addr, data); 388c2ecf20Sopenharmony_ci#else 398c2ecf20Sopenharmony_ci WRITE_ONCE(*addr, data & 0xf0); 408c2ecf20Sopenharmony_ci WRITE_ONCE(*addr, (data << 4) & 0xf0); 418c2ecf20Sopenharmony_ci#endif 428c2ecf20Sopenharmony_ci} 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_cistatic int __init lcd_init(void) 458c2ecf20Sopenharmony_ci{ 468c2ecf20Sopenharmony_ci WRITE_ONCE(*LCD_INSTR_ADDR, LCD_DISPLAY_MODE8BIT); 478c2ecf20Sopenharmony_ci mdelay(5); 488c2ecf20Sopenharmony_ci WRITE_ONCE(*LCD_INSTR_ADDR, LCD_DISPLAY_MODE8BIT); 498c2ecf20Sopenharmony_ci udelay(200); 508c2ecf20Sopenharmony_ci WRITE_ONCE(*LCD_INSTR_ADDR, LCD_DISPLAY_MODE8BIT); 518c2ecf20Sopenharmony_ci udelay(50); 528c2ecf20Sopenharmony_ci#ifndef CONFIG_XTFPGA_LCD_8BIT_ACCESS 538c2ecf20Sopenharmony_ci WRITE_ONCE(*LCD_INSTR_ADDR, LCD_DISPLAY_MODE4BIT); 548c2ecf20Sopenharmony_ci udelay(50); 558c2ecf20Sopenharmony_ci lcd_put_byte(LCD_INSTR_ADDR, LCD_DISPLAY_MODE4BIT); 568c2ecf20Sopenharmony_ci udelay(50); 578c2ecf20Sopenharmony_ci#endif 588c2ecf20Sopenharmony_ci lcd_put_byte(LCD_INSTR_ADDR, LCD_DISPLAY_ON); 598c2ecf20Sopenharmony_ci udelay(50); 608c2ecf20Sopenharmony_ci lcd_put_byte(LCD_INSTR_ADDR, LCD_CLEAR); 618c2ecf20Sopenharmony_ci mdelay(10); 628c2ecf20Sopenharmony_ci lcd_disp_at_pos("XTENSA LINUX", 0); 638c2ecf20Sopenharmony_ci return 0; 648c2ecf20Sopenharmony_ci} 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_civoid lcd_disp_at_pos(char *str, unsigned char pos) 678c2ecf20Sopenharmony_ci{ 688c2ecf20Sopenharmony_ci lcd_put_byte(LCD_INSTR_ADDR, LCD_DISPLAY_POS | pos); 698c2ecf20Sopenharmony_ci udelay(100); 708c2ecf20Sopenharmony_ci while (*str != 0) { 718c2ecf20Sopenharmony_ci lcd_put_byte(LCD_DATA_ADDR, *str); 728c2ecf20Sopenharmony_ci udelay(200); 738c2ecf20Sopenharmony_ci str++; 748c2ecf20Sopenharmony_ci } 758c2ecf20Sopenharmony_ci} 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_civoid lcd_shiftleft(void) 788c2ecf20Sopenharmony_ci{ 798c2ecf20Sopenharmony_ci lcd_put_byte(LCD_INSTR_ADDR, LCD_SHIFT_LEFT); 808c2ecf20Sopenharmony_ci udelay(50); 818c2ecf20Sopenharmony_ci} 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_civoid lcd_shiftright(void) 848c2ecf20Sopenharmony_ci{ 858c2ecf20Sopenharmony_ci lcd_put_byte(LCD_INSTR_ADDR, LCD_SHIFT_RIGHT); 868c2ecf20Sopenharmony_ci udelay(50); 878c2ecf20Sopenharmony_ci} 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_ciarch_initcall(lcd_init); 90