blob: dfa0fa0d5c782c082efcd04fe9a5f1ed964787a4 [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{
Jingoo Han3e51cd92014-08-27 10:14:43 +090030 return PPSR & PPC_LDD2 ? FB_BLANK_UNBLANK : FB_BLANK_POWERDOWN;
Kristoffer Ericson9e124432009-02-18 11:47:26 +000031}
32
Jingoo Hanb2dcd7b2013-04-29 16:17:31 -070033static int jornada_lcd_get_contrast(struct lcd_device *ld)
Kristoffer Ericson9e124432009-02-18 11:47:26 +000034{
35 int ret;
36
Jingoo Hanb2dcd7b2013-04-29 16:17:31 -070037 if (jornada_lcd_get_power(ld) != FB_BLANK_UNBLANK)
Kristoffer Ericson9e124432009-02-18 11:47:26 +000038 return 0;
39
40 jornada_ssp_start();
41
Lee Jones1e3b0972014-07-10 09:07:06 +010042 if (jornada_ssp_byte(GETCONTRAST) == TXDUMMY) {
Kristoffer Ericson9e124432009-02-18 11:47:26 +000043 ret = jornada_ssp_byte(TXDUMMY);
Lee Jones1e3b0972014-07-10 09:07:06 +010044 goto success;
Kristoffer Ericson9e124432009-02-18 11:47:26 +000045 }
Lee Jones1e3b0972014-07-10 09:07:06 +010046
47 dev_err(&ld->dev, "failed to set contrast\n");
48 ret = -ETIMEDOUT;
49
50success:
51 jornada_ssp_end();
52 return ret;
Kristoffer Ericson9e124432009-02-18 11:47:26 +000053}
54
Jingoo Hanb2dcd7b2013-04-29 16:17:31 -070055static int jornada_lcd_set_contrast(struct lcd_device *ld, int value)
Kristoffer Ericson9e124432009-02-18 11:47:26 +000056{
Lee Jones1e3b0972014-07-10 09:07:06 +010057 int ret = 0;
Kristoffer Ericson9e124432009-02-18 11:47:26 +000058
59 jornada_ssp_start();
60
61 /* start by sending our set contrast cmd to mcu */
Lee Jones1e3b0972014-07-10 09:07:06 +010062 if (jornada_ssp_byte(SETCONTRAST) == TXDUMMY) {
63 /* if successful push the new value */
64 if (jornada_ssp_byte(value) == TXDUMMY)
65 goto success;
Kristoffer Ericson9e124432009-02-18 11:47:26 +000066 }
67
Lee Jones1e3b0972014-07-10 09:07:06 +010068 dev_err(&ld->dev, "failed to set contrast\n");
69 ret = -ETIMEDOUT;
Kristoffer Ericson9e124432009-02-18 11:47:26 +000070
Lee Jones1e3b0972014-07-10 09:07:06 +010071success:
72 jornada_ssp_end();
73 return ret;
Kristoffer Ericson9e124432009-02-18 11:47:26 +000074}
75
Jingoo Hanb2dcd7b2013-04-29 16:17:31 -070076static int jornada_lcd_set_power(struct lcd_device *ld, int power)
Kristoffer Ericson9e124432009-02-18 11:47:26 +000077{
78 if (power != FB_BLANK_UNBLANK) {
79 PPSR &= ~PPC_LDD2;
80 PPDR |= PPC_LDD2;
Jingoo Hanb2dcd7b2013-04-29 16:17:31 -070081 } else {
Kristoffer Ericson9e124432009-02-18 11:47:26 +000082 PPSR |= PPC_LDD2;
Jingoo Hanb2dcd7b2013-04-29 16:17:31 -070083 }
Kristoffer Ericson9e124432009-02-18 11:47:26 +000084
85 return 0;
86}
87
88static struct lcd_ops jornada_lcd_props = {
89 .get_contrast = jornada_lcd_get_contrast,
90 .set_contrast = jornada_lcd_set_contrast,
91 .get_power = jornada_lcd_get_power,
92 .set_power = jornada_lcd_set_power,
93};
94
95static int jornada_lcd_probe(struct platform_device *pdev)
96{
97 struct lcd_device *lcd_device;
98 int ret;
99
Jingoo Han964598f2014-01-23 15:54:29 -0800100 lcd_device = devm_lcd_device_register(&pdev->dev, S1D_DEVICENAME,
101 &pdev->dev, NULL, &jornada_lcd_props);
Kristoffer Ericson9e124432009-02-18 11:47:26 +0000102
103 if (IS_ERR(lcd_device)) {
104 ret = PTR_ERR(lcd_device);
Jingoo Hanb2dcd7b2013-04-29 16:17:31 -0700105 dev_err(&pdev->dev, "failed to register device\n");
Kristoffer Ericson9e124432009-02-18 11:47:26 +0000106 return ret;
107 }
108
109 platform_set_drvdata(pdev, lcd_device);
110
111 /* lets set our default values */
112 jornada_lcd_set_contrast(lcd_device, LCD_DEF_CONTRAST);
113 jornada_lcd_set_power(lcd_device, FB_BLANK_UNBLANK);
114 /* give it some time to startup */
115 msleep(100);
116
117 return 0;
118}
119
Kristoffer Ericson9e124432009-02-18 11:47:26 +0000120static struct platform_driver jornada_lcd_driver = {
121 .probe = jornada_lcd_probe,
Kristoffer Ericson9e124432009-02-18 11:47:26 +0000122 .driver = {
123 .name = "jornada_lcd",
124 },
125};
126
Axel Lin81178e02012-01-10 15:09:11 -0800127module_platform_driver(jornada_lcd_driver);
Kristoffer Ericson9e124432009-02-18 11:47:26 +0000128
129MODULE_AUTHOR("Kristoffer Ericson <kristoffer.ericson@gmail.com>");
130MODULE_DESCRIPTION("HP Jornada 710/720/728 LCD driver");
131MODULE_LICENSE("GPL");