blob: b061413f1a65c8968ef47542623c6d7f3a6028af [file] [log] [blame]
Kristoffer Ericson9e124432009-02-18 11:47:26 +00001/*
2 *
3 * LCD driver for HP Jornada 700 series (710/720/728)
4 * Copyright (C) 2006-2009 Kristoffer Ericson <kristoffer.ericson@gmail.com>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License version
8 * 2 or any later version as published by the Free Software Foundation.
9 *
10 */
11
12#include <linux/device.h>
13#include <linux/fb.h>
14#include <linux/kernel.h>
15#include <linux/lcd.h>
16#include <linux/module.h>
17#include <linux/platform_device.h>
18#include <linux/delay.h>
19
20#include <mach/jornada720.h>
21#include <mach/hardware.h>
22
23#include <video/s1d13xxxfb.h>
24
25#define LCD_MAX_CONTRAST 0xff
26#define LCD_DEF_CONTRAST 0x80
27
Jingoo Hanb2dcd7b2013-04-29 16:17:31 -070028static int jornada_lcd_get_power(struct lcd_device *ld)
Kristoffer Ericson9e124432009-02-18 11:47:26 +000029{
30 /* LDD2 in PPC = LCD POWER */
31 if (PPSR & PPC_LDD2)
32 return FB_BLANK_UNBLANK; /* PW ON */
33 else
34 return FB_BLANK_POWERDOWN; /* PW OFF */
35}
36
Jingoo Hanb2dcd7b2013-04-29 16:17:31 -070037static int jornada_lcd_get_contrast(struct lcd_device *ld)
Kristoffer Ericson9e124432009-02-18 11:47:26 +000038{
39 int ret;
40
Jingoo Hanb2dcd7b2013-04-29 16:17:31 -070041 if (jornada_lcd_get_power(ld) != FB_BLANK_UNBLANK)
Kristoffer Ericson9e124432009-02-18 11:47:26 +000042 return 0;
43
44 jornada_ssp_start();
45
46 if (jornada_ssp_byte(GETCONTRAST) != TXDUMMY) {
Jingoo Hanb2dcd7b2013-04-29 16:17:31 -070047 dev_err(&ld->dev, "get contrast failed\n");
Kristoffer Ericson9e124432009-02-18 11:47:26 +000048 jornada_ssp_end();
49 return -ETIMEDOUT;
50 } else {
51 ret = jornada_ssp_byte(TXDUMMY);
52 jornada_ssp_end();
53 return ret;
54 }
55}
56
Jingoo Hanb2dcd7b2013-04-29 16:17:31 -070057static int jornada_lcd_set_contrast(struct lcd_device *ld, int value)
Kristoffer Ericson9e124432009-02-18 11:47:26 +000058{
59 int ret;
60
61 jornada_ssp_start();
62
63 /* start by sending our set contrast cmd to mcu */
64 ret = jornada_ssp_byte(SETCONTRAST);
65
66 /* push the new value */
67 if (jornada_ssp_byte(value) != TXDUMMY) {
Jingoo Hanb2dcd7b2013-04-29 16:17:31 -070068 dev_err(&ld->dev, "set contrast failed\n");
Kristoffer Ericson9e124432009-02-18 11:47:26 +000069 jornada_ssp_end();
70 return -ETIMEDOUT;
71 }
72
73 /* if we get here we can assume everything went well */
74 jornada_ssp_end();
75
76 return 0;
77}
78
Jingoo Hanb2dcd7b2013-04-29 16:17:31 -070079static int jornada_lcd_set_power(struct lcd_device *ld, int power)
Kristoffer Ericson9e124432009-02-18 11:47:26 +000080{
81 if (power != FB_BLANK_UNBLANK) {
82 PPSR &= ~PPC_LDD2;
83 PPDR |= PPC_LDD2;
Jingoo Hanb2dcd7b2013-04-29 16:17:31 -070084 } else {
Kristoffer Ericson9e124432009-02-18 11:47:26 +000085 PPSR |= PPC_LDD2;
Jingoo Hanb2dcd7b2013-04-29 16:17:31 -070086 }
Kristoffer Ericson9e124432009-02-18 11:47:26 +000087
88 return 0;
89}
90
91static struct lcd_ops jornada_lcd_props = {
92 .get_contrast = jornada_lcd_get_contrast,
93 .set_contrast = jornada_lcd_set_contrast,
94 .get_power = jornada_lcd_get_power,
95 .set_power = jornada_lcd_set_power,
96};
97
98static int jornada_lcd_probe(struct platform_device *pdev)
99{
100 struct lcd_device *lcd_device;
101 int ret;
102
103 lcd_device = lcd_device_register(S1D_DEVICENAME, &pdev->dev, NULL, &jornada_lcd_props);
104
105 if (IS_ERR(lcd_device)) {
106 ret = PTR_ERR(lcd_device);
Jingoo Hanb2dcd7b2013-04-29 16:17:31 -0700107 dev_err(&pdev->dev, "failed to register device\n");
Kristoffer Ericson9e124432009-02-18 11:47:26 +0000108 return ret;
109 }
110
111 platform_set_drvdata(pdev, lcd_device);
112
113 /* lets set our default values */
114 jornada_lcd_set_contrast(lcd_device, LCD_DEF_CONTRAST);
115 jornada_lcd_set_power(lcd_device, FB_BLANK_UNBLANK);
116 /* give it some time to startup */
117 msleep(100);
118
119 return 0;
120}
121
122static int jornada_lcd_remove(struct platform_device *pdev)
123{
124 struct lcd_device *lcd_device = platform_get_drvdata(pdev);
125
126 lcd_device_unregister(lcd_device);
127
128 return 0;
129}
130
131static struct platform_driver jornada_lcd_driver = {
132 .probe = jornada_lcd_probe,
133 .remove = jornada_lcd_remove,
134 .driver = {
135 .name = "jornada_lcd",
136 },
137};
138
Axel Lin81178e02012-01-10 15:09:11 -0800139module_platform_driver(jornada_lcd_driver);
Kristoffer Ericson9e124432009-02-18 11:47:26 +0000140
141MODULE_AUTHOR("Kristoffer Ericson <kristoffer.ericson@gmail.com>");
142MODULE_DESCRIPTION("HP Jornada 710/720/728 LCD driver");
143MODULE_LICENSE("GPL");