1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Support for Compaq iPAQ H3600 handheld computer
4  *
5  * Copyright (c) 2000,1 Compaq Computer Corporation. (Author: Jamey Hicks)
6  * Copyright (c) 2009 Dmitry Artamonow <mad_soft@inbox.ru>
7  */
8 
9 #include <linux/init.h>
10 #include <linux/kernel.h>
11 #include <linux/gpio.h>
12 
13 #include <video/sa1100fb.h>
14 
15 #include <asm/mach-types.h>
16 #include <asm/mach/arch.h>
17 #include <linux/platform_data/irda-sa11x0.h>
18 
19 #include <mach/h3xxx.h>
20 #include <mach/irqs.h>
21 
22 #include "generic.h"
23 
24 /*
25  * helper for sa1100fb
26  */
27 static struct gpio h3600_lcd_gpio[] = {
28 	{ H3XXX_EGPIO_LCD_ON,	GPIOF_OUT_INIT_LOW,	"LCD power" },
29 	{ H3600_EGPIO_LCD_PCI,	GPIOF_OUT_INIT_LOW,	"LCD control" },
30 	{ H3600_EGPIO_LCD_5V_ON, GPIOF_OUT_INIT_LOW,	"LCD 5v" },
31 	{ H3600_EGPIO_LVDD_ON,	GPIOF_OUT_INIT_LOW,	"LCD 9v/-6.5v" },
32 };
33 
h3600_lcd_request(void)34 static bool h3600_lcd_request(void)
35 {
36 	static bool h3600_lcd_ok;
37 	int rc;
38 
39 	if (h3600_lcd_ok)
40 		return true;
41 
42 	rc = gpio_request_array(h3600_lcd_gpio, ARRAY_SIZE(h3600_lcd_gpio));
43 	if (rc)
44 		pr_err("%s: can't request GPIOs\n", __func__);
45 	else
46 		h3600_lcd_ok = true;
47 
48 	return h3600_lcd_ok;
49 }
50 
h3600_lcd_power(int enable)51 static void h3600_lcd_power(int enable)
52 {
53 	if (!h3600_lcd_request())
54 		return;
55 
56 	gpio_direction_output(H3XXX_EGPIO_LCD_ON, enable);
57 	gpio_direction_output(H3600_EGPIO_LCD_PCI, enable);
58 	gpio_direction_output(H3600_EGPIO_LCD_5V_ON, enable);
59 	gpio_direction_output(H3600_EGPIO_LVDD_ON, enable);
60 }
61 
62 static const struct sa1100fb_rgb h3600_rgb_16 = {
63 	.red	= { .offset = 12, .length = 4, },
64 	.green	= { .offset = 7,  .length = 4, },
65 	.blue	= { .offset = 1,  .length = 4, },
66 	.transp	= { .offset = 0,  .length = 0, },
67 };
68 
69 static struct sa1100fb_mach_info h3600_lcd_info = {
70 	.pixclock	= 174757, 	.bpp		= 16,
71 	.xres		= 320,		.yres		= 240,
72 
73 	.hsync_len	= 3,		.vsync_len	= 3,
74 	.left_margin	= 12,		.upper_margin	= 10,
75 	.right_margin	= 17,		.lower_margin	= 1,
76 
77 	.cmap_static	= 1,
78 
79 	.lccr0		= LCCR0_Color | LCCR0_Sngl | LCCR0_Act,
80 	.lccr3		= LCCR3_OutEnH | LCCR3_PixRsEdg | LCCR3_ACBsDiv(2),
81 
82 	.rgb[RGB_16] = &h3600_rgb_16,
83 
84 	.lcd_power = h3600_lcd_power,
85 };
86 
87 
h3600_map_io(void)88 static void __init h3600_map_io(void)
89 {
90 	h3xxx_map_io();
91 }
92 
93 /*
94  * This turns the IRDA power on or off on the Compaq H3600
95  */
96 static struct gpio h3600_irda_gpio[] = {
97 	{ H3600_EGPIO_IR_ON,	GPIOF_OUT_INIT_LOW, "IrDA power" },
98 	{ H3600_EGPIO_IR_FSEL,	GPIOF_OUT_INIT_LOW, "IrDA fsel" },
99 };
100 
h3600_irda_set_power(struct device * dev,unsigned int state)101 static int h3600_irda_set_power(struct device *dev, unsigned int state)
102 {
103 	gpio_set_value(H3600_EGPIO_IR_ON, state);
104 	return 0;
105 }
106 
h3600_irda_set_speed(struct device * dev,unsigned int speed)107 static void h3600_irda_set_speed(struct device *dev, unsigned int speed)
108 {
109 	gpio_set_value(H3600_EGPIO_IR_FSEL, !(speed < 4000000));
110 }
111 
h3600_irda_startup(struct device * dev)112 static int h3600_irda_startup(struct device *dev)
113 {
114 	return gpio_request_array(h3600_irda_gpio, sizeof(h3600_irda_gpio));
115 }
116 
h3600_irda_shutdown(struct device * dev)117 static void h3600_irda_shutdown(struct device *dev)
118 {
119 	return gpio_free_array(h3600_irda_gpio, sizeof(h3600_irda_gpio));
120 }
121 
122 static struct irda_platform_data h3600_irda_data = {
123 	.set_power	= h3600_irda_set_power,
124 	.set_speed	= h3600_irda_set_speed,
125 	.startup	= h3600_irda_startup,
126 	.shutdown	= h3600_irda_shutdown,
127 };
128 
h3600_mach_init(void)129 static void __init h3600_mach_init(void)
130 {
131 	h3xxx_mach_init();
132 
133 	sa11x0_register_lcd(&h3600_lcd_info);
134 	sa11x0_register_irda(&h3600_irda_data);
135 }
136 
137 MACHINE_START(H3600, "Compaq iPAQ H3600")
138 	.atag_offset	= 0x100,
139 	.map_io		= h3600_map_io,
140 	.nr_irqs	= SA1100_NR_IRQS,
141 	.init_irq	= sa1100_init_irq,
142 	.init_time	= sa1100_timer_init,
143 	.init_machine	= h3600_mach_init,
144 	.init_late	= sa11x0_init_late,
145 	.restart	= sa11x0_restart,
146 MACHINE_END
147 
148