19e124435SKristoffer Ericson /* 29e124435SKristoffer Ericson * 39e124435SKristoffer Ericson * LCD driver for HP Jornada 700 series (710/720/728) 49e124435SKristoffer Ericson * Copyright (C) 2006-2009 Kristoffer Ericson <kristoffer.ericson@gmail.com> 59e124435SKristoffer Ericson * 69e124435SKristoffer Ericson * This program is free software; you can redistribute it and/or 79e124435SKristoffer Ericson * modify it under the terms of the GNU General Public License version 89e124435SKristoffer Ericson * 2 or any later version as published by the Free Software Foundation. 99e124435SKristoffer Ericson * 109e124435SKristoffer Ericson */ 119e124435SKristoffer Ericson 129e124435SKristoffer Ericson #include <linux/device.h> 139e124435SKristoffer Ericson #include <linux/fb.h> 149e124435SKristoffer Ericson #include <linux/kernel.h> 159e124435SKristoffer Ericson #include <linux/lcd.h> 169e124435SKristoffer Ericson #include <linux/module.h> 179e124435SKristoffer Ericson #include <linux/platform_device.h> 189e124435SKristoffer Ericson #include <linux/delay.h> 199e124435SKristoffer Ericson 209e124435SKristoffer Ericson #include <mach/jornada720.h> 219e124435SKristoffer Ericson #include <mach/hardware.h> 229e124435SKristoffer Ericson 239e124435SKristoffer Ericson #include <video/s1d13xxxfb.h> 249e124435SKristoffer Ericson 259e124435SKristoffer Ericson #define LCD_MAX_CONTRAST 0xff 269e124435SKristoffer Ericson #define LCD_DEF_CONTRAST 0x80 279e124435SKristoffer Ericson 289e124435SKristoffer Ericson static int jornada_lcd_get_power(struct lcd_device *dev) 299e124435SKristoffer Ericson { 309e124435SKristoffer Ericson /* LDD2 in PPC = LCD POWER */ 319e124435SKristoffer Ericson if (PPSR & PPC_LDD2) 329e124435SKristoffer Ericson return FB_BLANK_UNBLANK; /* PW ON */ 339e124435SKristoffer Ericson else 349e124435SKristoffer Ericson return FB_BLANK_POWERDOWN; /* PW OFF */ 359e124435SKristoffer Ericson } 369e124435SKristoffer Ericson 379e124435SKristoffer Ericson static int jornada_lcd_get_contrast(struct lcd_device *dev) 389e124435SKristoffer Ericson { 399e124435SKristoffer Ericson int ret; 409e124435SKristoffer Ericson 419e124435SKristoffer Ericson if (jornada_lcd_get_power(dev) != FB_BLANK_UNBLANK) 429e124435SKristoffer Ericson return 0; 439e124435SKristoffer Ericson 449e124435SKristoffer Ericson jornada_ssp_start(); 459e124435SKristoffer Ericson 469e124435SKristoffer Ericson if (jornada_ssp_byte(GETCONTRAST) != TXDUMMY) { 479e124435SKristoffer Ericson printk(KERN_ERR "lcd: get contrast failed\n"); 489e124435SKristoffer Ericson jornada_ssp_end(); 499e124435SKristoffer Ericson return -ETIMEDOUT; 509e124435SKristoffer Ericson } else { 519e124435SKristoffer Ericson ret = jornada_ssp_byte(TXDUMMY); 529e124435SKristoffer Ericson jornada_ssp_end(); 539e124435SKristoffer Ericson return ret; 549e124435SKristoffer Ericson } 559e124435SKristoffer Ericson } 569e124435SKristoffer Ericson 579e124435SKristoffer Ericson static int jornada_lcd_set_contrast(struct lcd_device *dev, int value) 589e124435SKristoffer Ericson { 599e124435SKristoffer Ericson int ret; 609e124435SKristoffer Ericson 619e124435SKristoffer Ericson jornada_ssp_start(); 629e124435SKristoffer Ericson 639e124435SKristoffer Ericson /* start by sending our set contrast cmd to mcu */ 649e124435SKristoffer Ericson ret = jornada_ssp_byte(SETCONTRAST); 659e124435SKristoffer Ericson 669e124435SKristoffer Ericson /* push the new value */ 679e124435SKristoffer Ericson if (jornada_ssp_byte(value) != TXDUMMY) { 689e124435SKristoffer Ericson printk(KERN_ERR "lcd : set contrast failed\n"); 699e124435SKristoffer Ericson jornada_ssp_end(); 709e124435SKristoffer Ericson return -ETIMEDOUT; 719e124435SKristoffer Ericson } 729e124435SKristoffer Ericson 739e124435SKristoffer Ericson /* if we get here we can assume everything went well */ 749e124435SKristoffer Ericson jornada_ssp_end(); 759e124435SKristoffer Ericson 769e124435SKristoffer Ericson return 0; 779e124435SKristoffer Ericson } 789e124435SKristoffer Ericson 799e124435SKristoffer Ericson static int jornada_lcd_set_power(struct lcd_device *dev, int power) 809e124435SKristoffer Ericson { 819e124435SKristoffer Ericson if (power != FB_BLANK_UNBLANK) { 829e124435SKristoffer Ericson PPSR &= ~PPC_LDD2; 839e124435SKristoffer Ericson PPDR |= PPC_LDD2; 849e124435SKristoffer Ericson } else 859e124435SKristoffer Ericson PPSR |= PPC_LDD2; 869e124435SKristoffer Ericson 879e124435SKristoffer Ericson return 0; 889e124435SKristoffer Ericson } 899e124435SKristoffer Ericson 909e124435SKristoffer Ericson static struct lcd_ops jornada_lcd_props = { 919e124435SKristoffer Ericson .get_contrast = jornada_lcd_get_contrast, 929e124435SKristoffer Ericson .set_contrast = jornada_lcd_set_contrast, 939e124435SKristoffer Ericson .get_power = jornada_lcd_get_power, 949e124435SKristoffer Ericson .set_power = jornada_lcd_set_power, 959e124435SKristoffer Ericson }; 969e124435SKristoffer Ericson 979e124435SKristoffer Ericson static int jornada_lcd_probe(struct platform_device *pdev) 989e124435SKristoffer Ericson { 999e124435SKristoffer Ericson struct lcd_device *lcd_device; 1009e124435SKristoffer Ericson int ret; 1019e124435SKristoffer Ericson 1029e124435SKristoffer Ericson lcd_device = lcd_device_register(S1D_DEVICENAME, &pdev->dev, NULL, &jornada_lcd_props); 1039e124435SKristoffer Ericson 1049e124435SKristoffer Ericson if (IS_ERR(lcd_device)) { 1059e124435SKristoffer Ericson ret = PTR_ERR(lcd_device); 1069e124435SKristoffer Ericson printk(KERN_ERR "lcd : failed to register device\n"); 1079e124435SKristoffer Ericson return ret; 1089e124435SKristoffer Ericson } 1099e124435SKristoffer Ericson 1109e124435SKristoffer Ericson platform_set_drvdata(pdev, lcd_device); 1119e124435SKristoffer Ericson 1129e124435SKristoffer Ericson /* lets set our default values */ 1139e124435SKristoffer Ericson jornada_lcd_set_contrast(lcd_device, LCD_DEF_CONTRAST); 1149e124435SKristoffer Ericson jornada_lcd_set_power(lcd_device, FB_BLANK_UNBLANK); 1159e124435SKristoffer Ericson /* give it some time to startup */ 1169e124435SKristoffer Ericson msleep(100); 1179e124435SKristoffer Ericson 1189e124435SKristoffer Ericson return 0; 1199e124435SKristoffer Ericson } 1209e124435SKristoffer Ericson 1219e124435SKristoffer Ericson static int jornada_lcd_remove(struct platform_device *pdev) 1229e124435SKristoffer Ericson { 1239e124435SKristoffer Ericson struct lcd_device *lcd_device = platform_get_drvdata(pdev); 1249e124435SKristoffer Ericson 1259e124435SKristoffer Ericson lcd_device_unregister(lcd_device); 1269e124435SKristoffer Ericson 1279e124435SKristoffer Ericson return 0; 1289e124435SKristoffer Ericson } 1299e124435SKristoffer Ericson 1309e124435SKristoffer Ericson static struct platform_driver jornada_lcd_driver = { 1319e124435SKristoffer Ericson .probe = jornada_lcd_probe, 1329e124435SKristoffer Ericson .remove = jornada_lcd_remove, 1339e124435SKristoffer Ericson .driver = { 1349e124435SKristoffer Ericson .name = "jornada_lcd", 1359e124435SKristoffer Ericson }, 1369e124435SKristoffer Ericson }; 1379e124435SKristoffer Ericson 13881178e02SAxel Lin module_platform_driver(jornada_lcd_driver); 1399e124435SKristoffer Ericson 1409e124435SKristoffer Ericson MODULE_AUTHOR("Kristoffer Ericson <kristoffer.ericson@gmail.com>"); 1419e124435SKristoffer Ericson MODULE_DESCRIPTION("HP Jornada 710/720/728 LCD driver"); 1429e124435SKristoffer Ericson MODULE_LICENSE("GPL"); 143