blob: 6796a7c2db2521b0d4c6b79b077c39db2baa22ce [file] [log] [blame]
Thomas Gleixner7de31d02019-05-20 09:19:14 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Kristoffer Ericson9e124432009-02-18 11:47:26 +00002/*
3 *
4 * LCD driver for HP Jornada 700 series (710/720/728)
5 * Copyright (C) 2006-2009 Kristoffer Ericson <kristoffer.ericson@gmail.com>
Kristoffer Ericson9e124432009-02-18 11:47:26 +00006 */
7
8#include <linux/device.h>
9#include <linux/fb.h>
10#include <linux/kernel.h>
11#include <linux/lcd.h>
12#include <linux/module.h>
13#include <linux/platform_device.h>
14#include <linux/delay.h>
15
16#include <mach/jornada720.h>
17#include <mach/hardware.h>
18
19#include <video/s1d13xxxfb.h>
20
21#define LCD_MAX_CONTRAST 0xff
22#define LCD_DEF_CONTRAST 0x80
23
Jingoo Hanb2dcd7b2013-04-29 16:17:31 -070024static int jornada_lcd_get_power(struct lcd_device *ld)
Kristoffer Ericson9e124432009-02-18 11:47:26 +000025{
Jingoo Han3e51cd92014-08-27 10:14:43 +090026 return PPSR & PPC_LDD2 ? FB_BLANK_UNBLANK : FB_BLANK_POWERDOWN;
Kristoffer Ericson9e124432009-02-18 11:47:26 +000027}
28
Jingoo Hanb2dcd7b2013-04-29 16:17:31 -070029static int jornada_lcd_get_contrast(struct lcd_device *ld)
Kristoffer Ericson9e124432009-02-18 11:47:26 +000030{
31 int ret;
32
Jingoo Hanb2dcd7b2013-04-29 16:17:31 -070033 if (jornada_lcd_get_power(ld) != FB_BLANK_UNBLANK)
Kristoffer Ericson9e124432009-02-18 11:47:26 +000034 return 0;
35
36 jornada_ssp_start();
37
Lee Jones1e3b0972014-07-10 09:07:06 +010038 if (jornada_ssp_byte(GETCONTRAST) == TXDUMMY) {
Kristoffer Ericson9e124432009-02-18 11:47:26 +000039 ret = jornada_ssp_byte(TXDUMMY);
Lee Jones1e3b0972014-07-10 09:07:06 +010040 goto success;
Kristoffer Ericson9e124432009-02-18 11:47:26 +000041 }
Lee Jones1e3b0972014-07-10 09:07:06 +010042
43 dev_err(&ld->dev, "failed to set contrast\n");
44 ret = -ETIMEDOUT;
45
46success:
47 jornada_ssp_end();
48 return ret;
Kristoffer Ericson9e124432009-02-18 11:47:26 +000049}
50
Jingoo Hanb2dcd7b2013-04-29 16:17:31 -070051static int jornada_lcd_set_contrast(struct lcd_device *ld, int value)
Kristoffer Ericson9e124432009-02-18 11:47:26 +000052{
Lee Jones1e3b0972014-07-10 09:07:06 +010053 int ret = 0;
Kristoffer Ericson9e124432009-02-18 11:47:26 +000054
55 jornada_ssp_start();
56
57 /* start by sending our set contrast cmd to mcu */
Lee Jones1e3b0972014-07-10 09:07:06 +010058 if (jornada_ssp_byte(SETCONTRAST) == TXDUMMY) {
59 /* if successful push the new value */
60 if (jornada_ssp_byte(value) == TXDUMMY)
61 goto success;
Kristoffer Ericson9e124432009-02-18 11:47:26 +000062 }
63
Lee Jones1e3b0972014-07-10 09:07:06 +010064 dev_err(&ld->dev, "failed to set contrast\n");
65 ret = -ETIMEDOUT;
Kristoffer Ericson9e124432009-02-18 11:47:26 +000066
Lee Jones1e3b0972014-07-10 09:07:06 +010067success:
68 jornada_ssp_end();
69 return ret;
Kristoffer Ericson9e124432009-02-18 11:47:26 +000070}
71
Jingoo Hanb2dcd7b2013-04-29 16:17:31 -070072static int jornada_lcd_set_power(struct lcd_device *ld, int power)
Kristoffer Ericson9e124432009-02-18 11:47:26 +000073{
74 if (power != FB_BLANK_UNBLANK) {
75 PPSR &= ~PPC_LDD2;
76 PPDR |= PPC_LDD2;
Jingoo Hanb2dcd7b2013-04-29 16:17:31 -070077 } else {
Kristoffer Ericson9e124432009-02-18 11:47:26 +000078 PPSR |= PPC_LDD2;
Jingoo Hanb2dcd7b2013-04-29 16:17:31 -070079 }
Kristoffer Ericson9e124432009-02-18 11:47:26 +000080
81 return 0;
82}
83
84static struct lcd_ops jornada_lcd_props = {
85 .get_contrast = jornada_lcd_get_contrast,
86 .set_contrast = jornada_lcd_set_contrast,
87 .get_power = jornada_lcd_get_power,
88 .set_power = jornada_lcd_set_power,
89};
90
91static int jornada_lcd_probe(struct platform_device *pdev)
92{
93 struct lcd_device *lcd_device;
94 int ret;
95
Jingoo Han964598f2014-01-23 15:54:29 -080096 lcd_device = devm_lcd_device_register(&pdev->dev, S1D_DEVICENAME,
97 &pdev->dev, NULL, &jornada_lcd_props);
Kristoffer Ericson9e124432009-02-18 11:47:26 +000098
99 if (IS_ERR(lcd_device)) {
100 ret = PTR_ERR(lcd_device);
Jingoo Hanb2dcd7b2013-04-29 16:17:31 -0700101 dev_err(&pdev->dev, "failed to register device\n");
Kristoffer Ericson9e124432009-02-18 11:47:26 +0000102 return ret;
103 }
104
105 platform_set_drvdata(pdev, lcd_device);
106
107 /* lets set our default values */
108 jornada_lcd_set_contrast(lcd_device, LCD_DEF_CONTRAST);
109 jornada_lcd_set_power(lcd_device, FB_BLANK_UNBLANK);
110 /* give it some time to startup */
111 msleep(100);
112
113 return 0;
114}
115
Kristoffer Ericson9e124432009-02-18 11:47:26 +0000116static struct platform_driver jornada_lcd_driver = {
117 .probe = jornada_lcd_probe,
Kristoffer Ericson9e124432009-02-18 11:47:26 +0000118 .driver = {
119 .name = "jornada_lcd",
120 },
121};
122
Axel Lin81178e02012-01-10 15:09:11 -0800123module_platform_driver(jornada_lcd_driver);
Kristoffer Ericson9e124432009-02-18 11:47:26 +0000124
125MODULE_AUTHOR("Kristoffer Ericson <kristoffer.ericson@gmail.com>");
126MODULE_DESCRIPTION("HP Jornada 710/720/728 LCD driver");
127MODULE_LICENSE("GPL");