1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * linux/arch/arm/mach-omap1/board-palmte.c
4 *
5 * Modified from board-generic.c
6 *
7 * Support for the Palm Tungsten E PDA.
8 *
9 * Original version : Laurent Gonzalez
10 *
11 * Maintainers : http://palmtelinux.sf.net
12 *                palmtelinux-developpers@lists.sf.net
13 *
14 * Copyright (c) 2006 Andrzej Zaborowski  <balrog@zabor.org>
15 */
16#include <linux/gpio/machine.h>
17#include <linux/gpio/consumer.h>
18#include <linux/kernel.h>
19#include <linux/init.h>
20#include <linux/input.h>
21#include <linux/platform_device.h>
22#include <linux/mtd/mtd.h>
23#include <linux/mtd/partitions.h>
24#include <linux/mtd/physmap.h>
25#include <linux/spi/spi.h>
26#include <linux/interrupt.h>
27#include <linux/apm-emulation.h>
28#include <linux/omapfb.h>
29#include <linux/omap-dma.h>
30#include <linux/platform_data/keypad-omap.h>
31#include <linux/platform_data/omap1_bl.h>
32
33#include <asm/mach-types.h>
34#include <asm/mach/arch.h>
35#include <asm/mach/map.h>
36
37#include "tc.h"
38#include "flash.h"
39#include "mux.h"
40#include "hardware.h"
41#include "usb.h"
42#include "mmc.h"
43#include "common.h"
44
45#define PALMTE_USBDETECT_GPIO	0
46#define PALMTE_USB_OR_DC_GPIO	1
47#define PALMTE_TSC_GPIO		4
48#define PALMTE_PINTDAV_GPIO	6
49#define PALMTE_MMC_WP_GPIO	8
50#define PALMTE_MMC_POWER_GPIO	9
51#define PALMTE_HDQ_GPIO		11
52#define PALMTE_HEADPHONES_GPIO	14
53#define PALMTE_SPEAKER_GPIO	15
54#define PALMTE_DC_GPIO		OMAP_MPUIO(2)
55#define PALMTE_MMC_SWITCH_GPIO	OMAP_MPUIO(4)
56#define PALMTE_MMC1_GPIO	OMAP_MPUIO(6)
57#define PALMTE_MMC2_GPIO	OMAP_MPUIO(7)
58#define PALMTE_MMC3_GPIO	OMAP_MPUIO(11)
59
60static const unsigned int palmte_keymap[] = {
61	KEY(0, 0, KEY_F1),		/* Calendar */
62	KEY(1, 0, KEY_F2),		/* Contacts */
63	KEY(2, 0, KEY_F3),		/* Tasks List */
64	KEY(3, 0, KEY_F4),		/* Note Pad */
65	KEY(4, 0, KEY_POWER),
66	KEY(0, 1, KEY_LEFT),
67	KEY(1, 1, KEY_DOWN),
68	KEY(2, 1, KEY_UP),
69	KEY(3, 1, KEY_RIGHT),
70	KEY(4, 1, KEY_ENTER),
71};
72
73static const struct matrix_keymap_data palmte_keymap_data = {
74	.keymap		= palmte_keymap,
75	.keymap_size	= ARRAY_SIZE(palmte_keymap),
76};
77
78static struct omap_kp_platform_data palmte_kp_data = {
79	.rows	= 8,
80	.cols	= 8,
81	.keymap_data = &palmte_keymap_data,
82	.rep	= true,
83	.delay	= 12,
84};
85
86static struct resource palmte_kp_resources[] = {
87	[0]	= {
88		.start	= INT_KEYBOARD,
89		.end	= INT_KEYBOARD,
90		.flags	= IORESOURCE_IRQ,
91	},
92};
93
94static struct platform_device palmte_kp_device = {
95	.name		= "omap-keypad",
96	.id		= -1,
97	.dev		= {
98		.platform_data	= &palmte_kp_data,
99	},
100	.num_resources	= ARRAY_SIZE(palmte_kp_resources),
101	.resource	= palmte_kp_resources,
102};
103
104static struct mtd_partition palmte_rom_partitions[] = {
105	/* PalmOS "Small ROM", contains the bootloader and the debugger */
106	{
107		.name		= "smallrom",
108		.offset		= 0,
109		.size		= 0xa000,
110		.mask_flags	= MTD_WRITEABLE,
111	},
112	/* PalmOS "Big ROM", a filesystem with all the OS code and data */
113	{
114		.name		= "bigrom",
115		.offset		= SZ_128K,
116		/*
117		 * 0x5f0000 bytes big in the multi-language ("EFIGS") version,
118		 * 0x7b0000 bytes in the English-only ("enUS") version.
119		 */
120		.size		= 0x7b0000,
121		.mask_flags	= MTD_WRITEABLE,
122	},
123};
124
125static struct physmap_flash_data palmte_rom_data = {
126	.width		= 2,
127	.set_vpp	= omap1_set_vpp,
128	.parts		= palmte_rom_partitions,
129	.nr_parts	= ARRAY_SIZE(palmte_rom_partitions),
130};
131
132static struct resource palmte_rom_resource = {
133	.start		= OMAP_CS0_PHYS,
134	.end		= OMAP_CS0_PHYS + SZ_8M - 1,
135	.flags		= IORESOURCE_MEM,
136};
137
138static struct platform_device palmte_rom_device = {
139	.name		= "physmap-flash",
140	.id		= -1,
141	.dev		= {
142		.platform_data	= &palmte_rom_data,
143	},
144	.num_resources	= 1,
145	.resource	= &palmte_rom_resource,
146};
147
148static struct platform_device palmte_lcd_device = {
149	.name		= "lcd_palmte",
150	.id		= -1,
151};
152
153static struct omap_backlight_config palmte_backlight_config = {
154	.default_intensity	= 0xa0,
155};
156
157static struct platform_device palmte_backlight_device = {
158	.name		= "omap-bl",
159	.id		= -1,
160	.dev		= {
161		.platform_data	= &palmte_backlight_config,
162	},
163};
164
165static struct platform_device *palmte_devices[] __initdata = {
166	&palmte_rom_device,
167	&palmte_kp_device,
168	&palmte_lcd_device,
169	&palmte_backlight_device,
170};
171
172static struct omap_usb_config palmte_usb_config __initdata = {
173	.register_dev	= 1,	/* Mini-B only receptacle */
174	.hmc_mode	= 0,
175	.pins[0]	= 2,
176};
177
178static const struct omap_lcd_config palmte_lcd_config __initconst = {
179	.ctrl_name	= "internal",
180};
181
182static struct spi_board_info palmte_spi_info[] __initdata = {
183	{
184		.modalias	= "tsc2102",
185		.bus_num	= 2,	/* uWire (officially) */
186		.chip_select	= 0,	/* As opposed to 3 */
187		.max_speed_hz	= 8000000,
188	},
189};
190
191#if IS_ENABLED(CONFIG_MMC_OMAP)
192
193static struct omap_mmc_platform_data _palmte_mmc_config = {
194	.nr_slots			= 1,
195	.slots[0]			= {
196		.ocr_mask		= MMC_VDD_32_33|MMC_VDD_33_34,
197		.name			= "mmcblk",
198	},
199};
200
201static struct omap_mmc_platform_data *palmte_mmc_config[OMAP15XX_NR_MMC] = {
202	[0] = &_palmte_mmc_config,
203};
204
205static void palmte_mmc_init(void)
206{
207	omap1_init_mmc(palmte_mmc_config, OMAP15XX_NR_MMC);
208}
209
210#else /* CONFIG_MMC_OMAP */
211
212static void palmte_mmc_init(void)
213{
214}
215
216#endif /* CONFIG_MMC_OMAP */
217
218static struct gpiod_lookup_table palmte_irq_gpio_table = {
219	.dev_id = NULL,
220	.table = {
221		/* GPIO used for TSC2102 PINTDAV IRQ */
222		GPIO_LOOKUP("gpio-0-15", PALMTE_PINTDAV_GPIO, "tsc2102_irq",
223			    GPIO_ACTIVE_HIGH),
224		/* GPIO used for USB or DC input detection */
225		GPIO_LOOKUP("gpio-0-15", PALMTE_USB_OR_DC_GPIO, "usb_dc_irq",
226			    GPIO_ACTIVE_HIGH),
227		{ }
228	},
229};
230
231static void __init omap_palmte_init(void)
232{
233	struct gpio_desc *d;
234
235	/* mux pins for uarts */
236	omap_cfg_reg(UART1_TX);
237	omap_cfg_reg(UART1_RTS);
238	omap_cfg_reg(UART2_TX);
239	omap_cfg_reg(UART2_RTS);
240	omap_cfg_reg(UART3_TX);
241	omap_cfg_reg(UART3_RX);
242
243	platform_add_devices(palmte_devices, ARRAY_SIZE(palmte_devices));
244
245	gpiod_add_lookup_table(&palmte_irq_gpio_table);
246	d = gpiod_get(NULL, "tsc2102_irq", GPIOD_IN);
247	if (IS_ERR(d))
248		pr_err("Unable to get TSC2102 IRQ GPIO descriptor\n");
249	else
250		palmte_spi_info[0].irq = gpiod_to_irq(d);
251	spi_register_board_info(palmte_spi_info, ARRAY_SIZE(palmte_spi_info));
252
253	/* We are getting this just to set it up as input */
254	d = gpiod_get(NULL, "usb_dc_irq", GPIOD_IN);
255	if (IS_ERR(d))
256		pr_err("Unable to get USB/DC IRQ GPIO descriptor\n");
257	else
258		gpiod_put(d);
259
260	omap_serial_init();
261	omap1_usb_init(&palmte_usb_config);
262	omap_register_i2c_bus(1, 100, NULL, 0);
263
264	omapfb_set_lcd_config(&palmte_lcd_config);
265	palmte_mmc_init();
266}
267
268MACHINE_START(OMAP_PALMTE, "OMAP310 based Palm Tungsten E")
269	.atag_offset	= 0x100,
270	.map_io		= omap1_map_io,
271	.init_early     = omap1_init_early,
272	.init_irq	= omap1_init_irq,
273	.init_machine	= omap_palmte_init,
274	.init_late	= omap1_init_late,
275	.init_time	= omap1_timer_init,
276	.restart	= omap1_restart,
277MACHINE_END
278