1 // SPDX-License-Identifier: GPL-2.0-only
3 * LCD / Backlight control code for Sharp SL-6000x (tosa)
5 * Copyright (c) 2005 Dirk Opfer
6 * Copyright (c) 2007,2008 Dmitry Baryshkov
9 #include <linux/kernel.h>
10 #include <linux/module.h>
11 #include <linux/device.h>
12 #include <linux/spi/spi.h>
13 #include <linux/i2c.h>
14 #include <linux/slab.h>
15 #include <linux/gpio.h>
16 #include <linux/delay.h>
17 #include <linux/lcd.h>
20 #include <asm/mach/sharpsl_param.h>
22 #include <mach/tosa.h>
24 #define POWER_IS_ON(pwr) ((pwr) <= FB_BLANK_NORMAL)
26 #define TG_REG0_VQV 0x0001
27 #define TG_REG0_COLOR 0x0002
28 #define TG_REG0_UD 0x0004
29 #define TG_REG0_LR 0x0008
33 struct tosa_lcd_data
{
34 struct spi_device
*spi
;
35 struct lcd_device
*lcd
;
36 struct i2c_client
*i2c
;
42 static int tosa_tg_send(struct spi_device
*spi
, int adrs
, uint8_t data
)
45 struct spi_message msg
;
46 struct spi_transfer xfer
= {
52 buf
[0] = ((adrs
& 0x07) << 5) | (data
& 0x1f);
53 spi_message_init(&msg
);
54 spi_message_add_tail(&xfer
, &msg
);
56 return spi_sync(spi
, &msg
);
59 int tosa_bl_enable(struct spi_device
*spi
, int enable
)
61 /* bl_enable GP04=1 otherwise GP04=0*/
62 return tosa_tg_send(spi
, TG_GPODR2
, enable
? 0x01 : 0x00);
64 EXPORT_SYMBOL(tosa_bl_enable
);
66 static void tosa_lcd_tg_init(struct tosa_lcd_data
*data
)
69 gpio_set_value(TOSA_GPIO_TG_ON
, 0);
73 /* delayed 0clk TCTL signal for VGA */
74 tosa_tg_send(data
->spi
, TG_TPOSCTL
, 0x00);
75 /* GPOS0=powercontrol, GPOS1=GPIO, GPOS2=TCTL */
76 tosa_tg_send(data
->spi
, TG_GPOSR
, 0x02);
79 static void tosa_lcd_tg_on(struct tosa_lcd_data
*data
)
81 struct spi_device
*spi
= data
->spi
;
82 int value
= TG_REG0_COLOR
| TG_REG0_UD
| TG_REG0_LR
;
87 tosa_tg_send(spi
, TG_PNLCTL
, value
);
89 /* TG LCD pannel power up */
90 tosa_tg_send(spi
, TG_PINICTL
, 0x4);
94 tosa_tg_send(spi
, TG_PINICTL
, 0x0);
98 * after the pannel is powered up the first time,
99 * we can access the i2c bus so probe for the DAC
101 struct i2c_adapter
*adap
= i2c_get_adapter(0);
102 struct i2c_board_info info
= {
105 .platform_data
= data
->spi
,
107 data
->i2c
= i2c_new_device(adap
, &info
);
111 static void tosa_lcd_tg_off(struct tosa_lcd_data
*data
)
113 struct spi_device
*spi
= data
->spi
;
115 /* TG LCD VHSA off */
116 tosa_tg_send(spi
, TG_PINICTL
, 0x4);
119 /* TG LCD signal off */
120 tosa_tg_send(spi
, TG_PINICTL
, 0x6);
124 gpio_set_value(TOSA_GPIO_TG_ON
, 1);
128 int tosa_lcd_set_power(struct lcd_device
*lcd
, int power
)
130 struct tosa_lcd_data
*data
= lcd_get_data(lcd
);
132 if (POWER_IS_ON(power
) && !POWER_IS_ON(data
->lcd_power
))
133 tosa_lcd_tg_on(data
);
135 if (!POWER_IS_ON(power
) && POWER_IS_ON(data
->lcd_power
))
136 tosa_lcd_tg_off(data
);
138 data
->lcd_power
= power
;
142 static int tosa_lcd_get_power(struct lcd_device
*lcd
)
144 struct tosa_lcd_data
*data
= lcd_get_data(lcd
);
146 return data
->lcd_power
;
149 static int tosa_lcd_set_mode(struct lcd_device
*lcd
, struct fb_videomode
*mode
)
151 struct tosa_lcd_data
*data
= lcd_get_data(lcd
);
153 if (mode
->xres
== 320 || mode
->yres
== 320)
154 data
->is_vga
= false;
158 if (POWER_IS_ON(data
->lcd_power
))
159 tosa_lcd_tg_on(data
);
164 static struct lcd_ops tosa_lcd_ops
= {
165 .set_power
= tosa_lcd_set_power
,
166 .get_power
= tosa_lcd_get_power
,
167 .set_mode
= tosa_lcd_set_mode
,
170 static int tosa_lcd_probe(struct spi_device
*spi
)
173 struct tosa_lcd_data
*data
;
175 data
= devm_kzalloc(&spi
->dev
, sizeof(struct tosa_lcd_data
),
180 data
->is_vga
= true; /* default to VGA mode */
183 * bits_per_word cannot be configured in platform data
185 spi
->bits_per_word
= 8;
187 ret
= spi_setup(spi
);
192 spi_set_drvdata(spi
, data
);
194 ret
= devm_gpio_request_one(&spi
->dev
, TOSA_GPIO_TG_ON
,
195 GPIOF_OUT_INIT_LOW
, "tg #pwr");
201 tosa_lcd_tg_init(data
);
203 tosa_lcd_tg_on(data
);
205 data
->lcd
= devm_lcd_device_register(&spi
->dev
, "tosa-lcd", &spi
->dev
,
206 data
, &tosa_lcd_ops
);
208 if (IS_ERR(data
->lcd
)) {
209 ret
= PTR_ERR(data
->lcd
);
217 tosa_lcd_tg_off(data
);
221 static int tosa_lcd_remove(struct spi_device
*spi
)
223 struct tosa_lcd_data
*data
= spi_get_drvdata(spi
);
226 i2c_unregister_device(data
->i2c
);
228 tosa_lcd_tg_off(data
);
233 #ifdef CONFIG_PM_SLEEP
234 static int tosa_lcd_suspend(struct device
*dev
)
236 struct tosa_lcd_data
*data
= dev_get_drvdata(dev
);
238 tosa_lcd_tg_off(data
);
243 static int tosa_lcd_resume(struct device
*dev
)
245 struct tosa_lcd_data
*data
= dev_get_drvdata(dev
);
247 tosa_lcd_tg_init(data
);
248 if (POWER_IS_ON(data
->lcd_power
))
249 tosa_lcd_tg_on(data
);
251 tosa_lcd_tg_off(data
);
257 static SIMPLE_DEV_PM_OPS(tosa_lcd_pm_ops
, tosa_lcd_suspend
, tosa_lcd_resume
);
259 static struct spi_driver tosa_lcd_driver
= {
262 .pm
= &tosa_lcd_pm_ops
,
264 .probe
= tosa_lcd_probe
,
265 .remove
= tosa_lcd_remove
,
268 module_spi_driver(tosa_lcd_driver
);
270 MODULE_AUTHOR("Dmitry Baryshkov");
271 MODULE_LICENSE("GPL v2");
272 MODULE_DESCRIPTION("LCD/Backlight control for Sharp SL-6000 PDA");
273 MODULE_ALIAS("spi:tosa-lcd");