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 
28b2dcd7beSJingoo Han static int jornada_lcd_get_power(struct lcd_device *ld)
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 
37b2dcd7beSJingoo Han static int jornada_lcd_get_contrast(struct lcd_device *ld)
389e124435SKristoffer Ericson {
399e124435SKristoffer Ericson 	int ret;
409e124435SKristoffer Ericson 
41b2dcd7beSJingoo Han 	if (jornada_lcd_get_power(ld) != FB_BLANK_UNBLANK)
429e124435SKristoffer Ericson 		return 0;
439e124435SKristoffer Ericson 
449e124435SKristoffer Ericson 	jornada_ssp_start();
459e124435SKristoffer Ericson 
461e3b0970SLee Jones 	if (jornada_ssp_byte(GETCONTRAST) == TXDUMMY) {
479e124435SKristoffer Ericson 		ret = jornada_ssp_byte(TXDUMMY);
481e3b0970SLee Jones 		goto success;
491e3b0970SLee Jones 	}
501e3b0970SLee Jones 
511e3b0970SLee Jones 	dev_err(&ld->dev, "failed to set contrast\n");
521e3b0970SLee Jones 	ret = -ETIMEDOUT;
531e3b0970SLee Jones 
541e3b0970SLee Jones success:
559e124435SKristoffer Ericson 	jornada_ssp_end();
569e124435SKristoffer Ericson 	return ret;
579e124435SKristoffer Ericson }
589e124435SKristoffer Ericson 
59b2dcd7beSJingoo Han static int jornada_lcd_set_contrast(struct lcd_device *ld, int value)
609e124435SKristoffer Ericson {
611e3b0970SLee Jones 	int ret = 0;
629e124435SKristoffer Ericson 
639e124435SKristoffer Ericson 	jornada_ssp_start();
649e124435SKristoffer Ericson 
659e124435SKristoffer Ericson 	/* start by sending our set contrast cmd to mcu */
661e3b0970SLee Jones 	if (jornada_ssp_byte(SETCONTRAST) == TXDUMMY) {
671e3b0970SLee Jones 		/* if successful push the new value */
681e3b0970SLee Jones 		if (jornada_ssp_byte(value) == TXDUMMY)
691e3b0970SLee Jones 			goto success;
709e124435SKristoffer Ericson 	}
719e124435SKristoffer Ericson 
721e3b0970SLee Jones 	dev_err(&ld->dev, "failed to set contrast\n");
731e3b0970SLee Jones 	ret = -ETIMEDOUT;
749e124435SKristoffer Ericson 
751e3b0970SLee Jones success:
761e3b0970SLee Jones 	jornada_ssp_end();
771e3b0970SLee Jones 	return ret;
789e124435SKristoffer Ericson }
799e124435SKristoffer Ericson 
80b2dcd7beSJingoo Han static int jornada_lcd_set_power(struct lcd_device *ld, int power)
819e124435SKristoffer Ericson {
829e124435SKristoffer Ericson 	if (power != FB_BLANK_UNBLANK) {
839e124435SKristoffer Ericson 		PPSR &= ~PPC_LDD2;
849e124435SKristoffer Ericson 		PPDR |= PPC_LDD2;
85b2dcd7beSJingoo Han 	} else {
869e124435SKristoffer Ericson 		PPSR |= PPC_LDD2;
87b2dcd7beSJingoo Han 	}
889e124435SKristoffer Ericson 
899e124435SKristoffer Ericson 	return 0;
909e124435SKristoffer Ericson }
919e124435SKristoffer Ericson 
929e124435SKristoffer Ericson static struct lcd_ops jornada_lcd_props = {
939e124435SKristoffer Ericson 	.get_contrast = jornada_lcd_get_contrast,
949e124435SKristoffer Ericson 	.set_contrast = jornada_lcd_set_contrast,
959e124435SKristoffer Ericson 	.get_power = jornada_lcd_get_power,
969e124435SKristoffer Ericson 	.set_power = jornada_lcd_set_power,
979e124435SKristoffer Ericson };
989e124435SKristoffer Ericson 
999e124435SKristoffer Ericson static int jornada_lcd_probe(struct platform_device *pdev)
1009e124435SKristoffer Ericson {
1019e124435SKristoffer Ericson 	struct lcd_device *lcd_device;
1029e124435SKristoffer Ericson 	int ret;
1039e124435SKristoffer Ericson 
104964598f2SJingoo Han 	lcd_device = devm_lcd_device_register(&pdev->dev, S1D_DEVICENAME,
105964598f2SJingoo Han 					&pdev->dev, NULL, &jornada_lcd_props);
1069e124435SKristoffer Ericson 
1079e124435SKristoffer Ericson 	if (IS_ERR(lcd_device)) {
1089e124435SKristoffer Ericson 		ret = PTR_ERR(lcd_device);
109b2dcd7beSJingoo Han 		dev_err(&pdev->dev, "failed to register device\n");
1109e124435SKristoffer Ericson 		return ret;
1119e124435SKristoffer Ericson 	}
1129e124435SKristoffer Ericson 
1139e124435SKristoffer Ericson 	platform_set_drvdata(pdev, lcd_device);
1149e124435SKristoffer Ericson 
1159e124435SKristoffer Ericson 	/* lets set our default values */
1169e124435SKristoffer Ericson 	jornada_lcd_set_contrast(lcd_device, LCD_DEF_CONTRAST);
1179e124435SKristoffer Ericson 	jornada_lcd_set_power(lcd_device, FB_BLANK_UNBLANK);
1189e124435SKristoffer Ericson 	/* give it some time to startup */
1199e124435SKristoffer Ericson 	msleep(100);
1209e124435SKristoffer Ericson 
1219e124435SKristoffer Ericson 	return 0;
1229e124435SKristoffer Ericson }
1239e124435SKristoffer Ericson 
1249e124435SKristoffer Ericson static struct platform_driver jornada_lcd_driver = {
1259e124435SKristoffer Ericson 	.probe	= jornada_lcd_probe,
1269e124435SKristoffer Ericson 	.driver	= {
1279e124435SKristoffer Ericson 		.name	= "jornada_lcd",
1289e124435SKristoffer Ericson 	},
1299e124435SKristoffer Ericson };
1309e124435SKristoffer Ericson 
13181178e02SAxel Lin module_platform_driver(jornada_lcd_driver);
1329e124435SKristoffer Ericson 
1339e124435SKristoffer Ericson MODULE_AUTHOR("Kristoffer Ericson <kristoffer.ericson@gmail.com>");
1349e124435SKristoffer Ericson MODULE_DESCRIPTION("HP Jornada 710/720/728 LCD driver");
1359e124435SKristoffer Ericson MODULE_LICENSE("GPL");
136