17de31d0dSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
29e124435SKristoffer Ericson /*
39e124435SKristoffer Ericson  *
49e124435SKristoffer Ericson  * LCD driver for HP Jornada 700 series (710/720/728)
59e124435SKristoffer Ericson  * Copyright (C) 2006-2009 Kristoffer Ericson <kristoffer.ericson@gmail.com>
69e124435SKristoffer Ericson  */
79e124435SKristoffer Ericson 
89e124435SKristoffer Ericson #include <linux/device.h>
99e124435SKristoffer Ericson #include <linux/fb.h>
109e124435SKristoffer Ericson #include <linux/kernel.h>
119e124435SKristoffer Ericson #include <linux/lcd.h>
129e124435SKristoffer Ericson #include <linux/module.h>
139e124435SKristoffer Ericson #include <linux/platform_device.h>
149e124435SKristoffer Ericson #include <linux/delay.h>
159e124435SKristoffer Ericson 
169e124435SKristoffer Ericson #include <mach/jornada720.h>
179e124435SKristoffer Ericson #include <mach/hardware.h>
189e124435SKristoffer Ericson 
199e124435SKristoffer Ericson #include <video/s1d13xxxfb.h>
209e124435SKristoffer Ericson 
219e124435SKristoffer Ericson #define LCD_MAX_CONTRAST	0xff
229e124435SKristoffer Ericson #define LCD_DEF_CONTRAST	0x80
239e124435SKristoffer Ericson 
jornada_lcd_get_power(struct lcd_device * ld)24b2dcd7beSJingoo Han static int jornada_lcd_get_power(struct lcd_device *ld)
259e124435SKristoffer Ericson {
263e51cd93SJingoo Han 	return PPSR & PPC_LDD2 ? FB_BLANK_UNBLANK : FB_BLANK_POWERDOWN;
279e124435SKristoffer Ericson }
289e124435SKristoffer Ericson 
jornada_lcd_get_contrast(struct lcd_device * ld)29b2dcd7beSJingoo Han static int jornada_lcd_get_contrast(struct lcd_device *ld)
309e124435SKristoffer Ericson {
319e124435SKristoffer Ericson 	int ret;
329e124435SKristoffer Ericson 
33b2dcd7beSJingoo Han 	if (jornada_lcd_get_power(ld) != FB_BLANK_UNBLANK)
349e124435SKristoffer Ericson 		return 0;
359e124435SKristoffer Ericson 
369e124435SKristoffer Ericson 	jornada_ssp_start();
379e124435SKristoffer Ericson 
381e3b0970SLee Jones 	if (jornada_ssp_byte(GETCONTRAST) == TXDUMMY) {
399e124435SKristoffer Ericson 		ret = jornada_ssp_byte(TXDUMMY);
401e3b0970SLee Jones 		goto success;
411e3b0970SLee Jones 	}
421e3b0970SLee Jones 
431e3b0970SLee Jones 	dev_err(&ld->dev, "failed to set contrast\n");
441e3b0970SLee Jones 	ret = -ETIMEDOUT;
451e3b0970SLee Jones 
461e3b0970SLee Jones success:
479e124435SKristoffer Ericson 	jornada_ssp_end();
489e124435SKristoffer Ericson 	return ret;
499e124435SKristoffer Ericson }
509e124435SKristoffer Ericson 
jornada_lcd_set_contrast(struct lcd_device * ld,int value)51b2dcd7beSJingoo Han static int jornada_lcd_set_contrast(struct lcd_device *ld, int value)
529e124435SKristoffer Ericson {
531e3b0970SLee Jones 	int ret = 0;
549e124435SKristoffer Ericson 
559e124435SKristoffer Ericson 	jornada_ssp_start();
569e124435SKristoffer Ericson 
579e124435SKristoffer Ericson 	/* start by sending our set contrast cmd to mcu */
581e3b0970SLee Jones 	if (jornada_ssp_byte(SETCONTRAST) == TXDUMMY) {
591e3b0970SLee Jones 		/* if successful push the new value */
601e3b0970SLee Jones 		if (jornada_ssp_byte(value) == TXDUMMY)
611e3b0970SLee Jones 			goto success;
629e124435SKristoffer Ericson 	}
639e124435SKristoffer Ericson 
641e3b0970SLee Jones 	dev_err(&ld->dev, "failed to set contrast\n");
651e3b0970SLee Jones 	ret = -ETIMEDOUT;
669e124435SKristoffer Ericson 
671e3b0970SLee Jones success:
681e3b0970SLee Jones 	jornada_ssp_end();
691e3b0970SLee Jones 	return ret;
709e124435SKristoffer Ericson }
719e124435SKristoffer Ericson 
jornada_lcd_set_power(struct lcd_device * ld,int power)72b2dcd7beSJingoo Han static int jornada_lcd_set_power(struct lcd_device *ld, int power)
739e124435SKristoffer Ericson {
749e124435SKristoffer Ericson 	if (power != FB_BLANK_UNBLANK) {
759e124435SKristoffer Ericson 		PPSR &= ~PPC_LDD2;
769e124435SKristoffer Ericson 		PPDR |= PPC_LDD2;
77b2dcd7beSJingoo Han 	} else {
789e124435SKristoffer Ericson 		PPSR |= PPC_LDD2;
79b2dcd7beSJingoo Han 	}
809e124435SKristoffer Ericson 
819e124435SKristoffer Ericson 	return 0;
829e124435SKristoffer Ericson }
839e124435SKristoffer Ericson 
849e124435SKristoffer Ericson static struct lcd_ops jornada_lcd_props = {
859e124435SKristoffer Ericson 	.get_contrast = jornada_lcd_get_contrast,
869e124435SKristoffer Ericson 	.set_contrast = jornada_lcd_set_contrast,
879e124435SKristoffer Ericson 	.get_power = jornada_lcd_get_power,
889e124435SKristoffer Ericson 	.set_power = jornada_lcd_set_power,
899e124435SKristoffer Ericson };
909e124435SKristoffer Ericson 
jornada_lcd_probe(struct platform_device * pdev)919e124435SKristoffer Ericson static int jornada_lcd_probe(struct platform_device *pdev)
929e124435SKristoffer Ericson {
939e124435SKristoffer Ericson 	struct lcd_device *lcd_device;
949e124435SKristoffer Ericson 	int ret;
959e124435SKristoffer Ericson 
96964598f2SJingoo Han 	lcd_device = devm_lcd_device_register(&pdev->dev, S1D_DEVICENAME,
97964598f2SJingoo Han 					&pdev->dev, NULL, &jornada_lcd_props);
989e124435SKristoffer Ericson 
999e124435SKristoffer Ericson 	if (IS_ERR(lcd_device)) {
1009e124435SKristoffer Ericson 		ret = PTR_ERR(lcd_device);
101b2dcd7beSJingoo Han 		dev_err(&pdev->dev, "failed to register device\n");
1029e124435SKristoffer Ericson 		return ret;
1039e124435SKristoffer Ericson 	}
1049e124435SKristoffer Ericson 
1059e124435SKristoffer Ericson 	platform_set_drvdata(pdev, lcd_device);
1069e124435SKristoffer Ericson 
1079e124435SKristoffer Ericson 	/* lets set our default values */
1089e124435SKristoffer Ericson 	jornada_lcd_set_contrast(lcd_device, LCD_DEF_CONTRAST);
1099e124435SKristoffer Ericson 	jornada_lcd_set_power(lcd_device, FB_BLANK_UNBLANK);
1109e124435SKristoffer Ericson 	/* give it some time to startup */
1119e124435SKristoffer Ericson 	msleep(100);
1129e124435SKristoffer Ericson 
1139e124435SKristoffer Ericson 	return 0;
1149e124435SKristoffer Ericson }
1159e124435SKristoffer Ericson 
1169e124435SKristoffer Ericson static struct platform_driver jornada_lcd_driver = {
1179e124435SKristoffer Ericson 	.probe	= jornada_lcd_probe,
1189e124435SKristoffer Ericson 	.driver	= {
1199e124435SKristoffer Ericson 		.name	= "jornada_lcd",
1209e124435SKristoffer Ericson 	},
1219e124435SKristoffer Ericson };
1229e124435SKristoffer Ericson 
12381178e02SAxel Lin module_platform_driver(jornada_lcd_driver);
1249e124435SKristoffer Ericson 
1259e124435SKristoffer Ericson MODULE_AUTHOR("Kristoffer Ericson <kristoffer.ericson@gmail.com>");
1269e124435SKristoffer Ericson MODULE_DESCRIPTION("HP Jornada 710/720/728 LCD driver");
1279e124435SKristoffer Ericson MODULE_LICENSE("GPL");
128