1 /*
2  * Copyright (C) 2009
3  * Guennadi Liakhovetski, DENX Software Engineering, <lg@denx.de>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation.
8  */
9 #include <linux/gpio.h>
10 #include <linux/input.h>
11 #include <linux/platform_device.h>
12 #include <linux/spi/spi.h>
13 
14 #include <asm/mach-types.h>
15 
16 #include "pcm037.h"
17 #include "common.h"
18 #include "devices-imx31.h"
19 #include "iomux-mx3.h"
20 
21 static unsigned int pcm037_eet_pins[] = {
22 	/* Reserve and hardwire GPIO 57 high - S6E63D6 chipselect */
23 	IOMUX_MODE(MX31_PIN_KEY_COL7, IOMUX_CONFIG_GPIO),
24 	/* GPIO keys */
25 	IOMUX_MODE(MX31_PIN_GPIO1_0,	IOMUX_CONFIG_GPIO), /* 0 */
26 	IOMUX_MODE(MX31_PIN_GPIO1_1,	IOMUX_CONFIG_GPIO), /* 1 */
27 	IOMUX_MODE(MX31_PIN_GPIO1_2,	IOMUX_CONFIG_GPIO), /* 2 */
28 	IOMUX_MODE(MX31_PIN_GPIO1_3,	IOMUX_CONFIG_GPIO), /* 3 */
29 	IOMUX_MODE(MX31_PIN_SVEN0,	IOMUX_CONFIG_GPIO), /* 32 */
30 	IOMUX_MODE(MX31_PIN_STX0,	IOMUX_CONFIG_GPIO), /* 33 */
31 	IOMUX_MODE(MX31_PIN_SRX0,	IOMUX_CONFIG_GPIO), /* 34 */
32 	IOMUX_MODE(MX31_PIN_SIMPD0,	IOMUX_CONFIG_GPIO), /* 35 */
33 	IOMUX_MODE(MX31_PIN_RTS1,	IOMUX_CONFIG_GPIO), /* 38 */
34 	IOMUX_MODE(MX31_PIN_CTS1,	IOMUX_CONFIG_GPIO), /* 39 */
35 	IOMUX_MODE(MX31_PIN_KEY_ROW4,	IOMUX_CONFIG_GPIO), /* 50 */
36 	IOMUX_MODE(MX31_PIN_KEY_ROW5,	IOMUX_CONFIG_GPIO), /* 51 */
37 	IOMUX_MODE(MX31_PIN_KEY_ROW6,	IOMUX_CONFIG_GPIO), /* 52 */
38 	IOMUX_MODE(MX31_PIN_KEY_ROW7,	IOMUX_CONFIG_GPIO), /* 53 */
39 
40 	/* LEDs */
41 	IOMUX_MODE(MX31_PIN_DTR_DTE1,	IOMUX_CONFIG_GPIO), /* 44 */
42 	IOMUX_MODE(MX31_PIN_DSR_DTE1,	IOMUX_CONFIG_GPIO), /* 45 */
43 	IOMUX_MODE(MX31_PIN_KEY_COL5,	IOMUX_CONFIG_GPIO), /* 55 */
44 	IOMUX_MODE(MX31_PIN_KEY_COL6,	IOMUX_CONFIG_GPIO), /* 56 */
45 };
46 
47 /* SPI */
48 static struct spi_board_info pcm037_spi_dev[] = {
49 	{
50 		.modalias	= "dac124s085",
51 		.max_speed_hz	= 400000,
52 		.bus_num	= 0,
53 		.chip_select	= 1,		/* Index in pcm037_spi1_cs[] */
54 		.mode		= SPI_CPHA,
55 	},
56 };
57 
58 /* Platform Data for MXC CSPI */
59 static const struct spi_imx_master pcm037_spi1_pdata __initconst = {
60 	.num_chipselect = 2,
61 };
62 
63 /* GPIO-keys input device */
64 static struct gpio_keys_button pcm037_gpio_keys[] = {
65 	{
66 		.type	= EV_KEY,
67 		.code	= KEY_L,
68 		.gpio	= 0,
69 		.desc	= "Wheel Manual",
70 		.wakeup	= 0,
71 	}, {
72 		.type	= EV_KEY,
73 		.code	= KEY_A,
74 		.gpio	= 1,
75 		.desc	= "Wheel AF",
76 		.wakeup	= 0,
77 	}, {
78 		.type	= EV_KEY,
79 		.code	= KEY_V,
80 		.gpio	= 2,
81 		.desc	= "Wheel View",
82 		.wakeup	= 0,
83 	}, {
84 		.type	= EV_KEY,
85 		.code	= KEY_M,
86 		.gpio	= 3,
87 		.desc	= "Wheel Menu",
88 		.wakeup	= 0,
89 	}, {
90 		.type	= EV_KEY,
91 		.code	= KEY_UP,
92 		.gpio	= 32,
93 		.desc	= "Nav Pad Up",
94 		.wakeup	= 0,
95 	}, {
96 		.type	= EV_KEY,
97 		.code	= KEY_RIGHT,
98 		.gpio	= 33,
99 		.desc	= "Nav Pad Right",
100 		.wakeup	= 0,
101 	}, {
102 		.type	= EV_KEY,
103 		.code	= KEY_DOWN,
104 		.gpio	= 34,
105 		.desc	= "Nav Pad Down",
106 		.wakeup	= 0,
107 	}, {
108 		.type	= EV_KEY,
109 		.code	= KEY_LEFT,
110 		.gpio	= 35,
111 		.desc	= "Nav Pad Left",
112 		.wakeup	= 0,
113 	}, {
114 		.type	= EV_KEY,
115 		.code	= KEY_ENTER,
116 		.gpio	= 38,
117 		.desc	= "Nav Pad Ok",
118 		.wakeup	= 0,
119 	}, {
120 		.type	= EV_KEY,
121 		.code	= KEY_O,
122 		.gpio	= 39,
123 		.desc	= "Wheel Off",
124 		.wakeup	= 0,
125 	}, {
126 		.type	= EV_KEY,
127 		.code	= BTN_FORWARD,
128 		.gpio	= 50,
129 		.desc	= "Focus Forward",
130 		.wakeup	= 0,
131 	}, {
132 		.type	= EV_KEY,
133 		.code	= BTN_BACK,
134 		.gpio	= 51,
135 		.desc	= "Focus Backward",
136 		.wakeup	= 0,
137 	}, {
138 		.type	= EV_KEY,
139 		.code	= BTN_MIDDLE,
140 		.gpio	= 52,
141 		.desc	= "Release Half",
142 		.wakeup	= 0,
143 	}, {
144 		.type	= EV_KEY,
145 		.code	= BTN_EXTRA,
146 		.gpio	= 53,
147 		.desc	= "Release Full",
148 		.wakeup	= 0,
149 	},
150 };
151 
152 static const struct gpio_keys_platform_data
153 		pcm037_gpio_keys_platform_data __initconst = {
154 	.buttons	= pcm037_gpio_keys,
155 	.nbuttons	= ARRAY_SIZE(pcm037_gpio_keys),
156 	.rep		= 0, /* No auto-repeat */
157 };
158 
pcm037_eet_init_devices(void)159 int __init pcm037_eet_init_devices(void)
160 {
161 	if (pcm037_variant() != PCM037_EET)
162 		return 0;
163 
164 	mxc_iomux_setup_multiple_pins(pcm037_eet_pins,
165 				ARRAY_SIZE(pcm037_eet_pins), "pcm037_eet");
166 
167 	/* SPI */
168 	spi_register_board_info(pcm037_spi_dev, ARRAY_SIZE(pcm037_spi_dev));
169 	imx31_add_spi_imx0(&pcm037_spi1_pdata);
170 
171 	imx_add_gpio_keys(&pcm037_gpio_keys_platform_data);
172 
173 	return 0;
174 }
175