aboutsummaryrefslogtreecommitdiffstats
path: root/target/linux/ubicom32/files/arch/ubicom32/mach-ip7k/board-ip7160dpf.c
blob: 7f4e4f3e45b0fad8d72cc26fba7991390ddcc41c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
/*
 * arch/ubicom32/mach-ip7k/board-ip7160dpf.c
 *   Platform initialization for ip7160dpf board.
 *
 * (C) Copyright 2009, Ubicom, Inc.
 *
 * This file is part of the Ubicom32 Linux Kernel Port.
 *
 * The Ubicom32 Linux Kernel Port is free software: you can redistribute
 * it and/or modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation, either version 2 of the
 * License, or (at your option) any later version.
 *
 * The Ubicom32 Linux Kernel Port is distributed in the hope that it
 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
 * the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with the Ubicom32 Linux Kernel Port.  If not,
 * see <http://www.gnu.org/licenses/>.
 *
 * Ubicom32 implementation derived from (with many thanks):
 *   arch/m68knommu
 *   arch/blackfin
 *   arch/parisc
 */
#include <linux/device.h>
#include <linux/platform_device.h>
#include <linux/delay.h>
#include <linux/gpio.h>

#include <linux/i2c.h>
#include <linux/i2c-gpio.h>

#include <linux/input.h>

#include <asm/board.h>
#include <asm/machdep.h>
#include <asm/ubicom32hid.h>
#include <asm/vdc_tio.h>
#include <asm/audio.h>

/*
 * Backlight on the board PD0, hardware PWM
 */
static const struct ubicom32hid_button ip7160dpf_ubicom32hid_buttons[] = {
	{
		.type	= EV_KEY,
		.code	= KEY_UP,
		.bit	= 0,
	},
	{
		.type	= EV_KEY,
		.code	= KEY_LEFT,
		.bit	= 1,
	},
	{
		.type	= EV_KEY,
		.code	= KEY_RIGHT,
		.bit	= 2,
	},
	{
		.type	= EV_KEY,
		.code	= KEY_DOWN,
		.bit	= 3,
	},
	{
		.type	= EV_KEY,
		.code	= KEY_ENTER,
		.bit	= 4,
	},
	{
		.type	= EV_KEY,
		.code	= KEY_MENU,
		.bit	= 5,
	},
	{
		.type	= EV_KEY,
		.code	= KEY_ESC,
		.bit	= 7,
	},
};

static const struct ubicom32hid_ir ip7160dpf_ubicom32hid_ircodes[] = {
	{
		.type		= EV_KEY,
		.code		= KEY_UP,
		.ir_code	= 0xF807916E
	},
	{
		.type		= EV_KEY,
		.code		= KEY_DOWN,
		.ir_code	= 0xF20D916E
	},
	{
		.type		= EV_KEY,
		.code		= KEY_LEFT,
		.ir_code	= 0xF609916E
	},
	{
		.type		= EV_KEY,
		.code		= KEY_RIGHT,
		.ir_code	= 0xF40B916E
	},
	{
		.type		= EV_KEY,
		.code		= KEY_ENTER,
		.ir_code	= 0xF50A916E
	},
	{	/* rotate */
		.type		= EV_KEY,
		.code		= KEY_FN_F1,
		.ir_code	= 0xF906916E
	},
	{
		.type		= EV_KEY,
		.code		= KEY_MENU,
		.ir_code	= 0xF708916E
	},
	{	/* font size */
		.type		= EV_KEY,
		.code		= KEY_FN_F2,
		.ir_code	= 0xF30C916E
	},
	{
		.type		= EV_KEY,
		.code		= KEY_ESC,
		.ir_code	= 0xF10E916E
	},
	{
		.type		= EV_KEY,
		.code		= KEY_VOLUMEUP,
		.ir_code	= 0xF00F916E
	},
	{
		.type		= EV_KEY,
		.code		= KEY_VOLUMEDOWN,
		.ir_code	= 0xED12916E
	},
	{
		.type		= EV_KEY,
		.code		= KEY_MUTE,
		.ir_code	= 0xEA15916E
	},
	{
		.type		= EV_KEY,
		.code		= KEY_INFO,
		.ir_code	= 0xEF10916E
	},
	{	/* Like */
		.type		= EV_KEY,
		.code		= KEY_FN_F3,
		.ir_code	= 0xEE11916E
	},
	{	/* Dislike */
		.type		= EV_KEY,
		.code		= KEY_FN_F4,
		.ir_code	= 0xEB14916E
	},
	{
		.type		= EV_KEY,
		.code		= KEY_POWER,
		.ir_code	= 0xFD02916E
	},
};

static struct ubicom32hid_platform_data ip7160dpf_ubicom32hid_platform_data = {
	.gpio_reset		= GPIO_RI_5,
	.gpio_reset_polarity	= 0,
	.type			= UBICOM32HID_BL_TYPE_PWM,
	.invert			= 0,
	.default_intensity	= 128,
	.buttons		= ip7160dpf_ubicom32hid_buttons,
	.nbuttons		= ARRAY_SIZE(ip7160dpf_ubicom32hid_buttons),
	.ircodes		= ip7160dpf_ubicom32hid_ircodes,
	.nircodes		= ARRAY_SIZE(ip7160dpf_ubicom32hid_ircodes),
};

/*
 * Devices on the I2C bus
 *	This board has a "bus 2" which is isolated from the main bus by U47
 *	and pin RI0.  It should be safe to always enable bus 2 by setting
 *	RI0 to low, however, it should be noted that on all existing configurations
 *	of this board, U49 and U51 are not populated.
 */
static struct i2c_board_info __initdata ip7160dpf_i2c_board_info[] = {
	/*
	 * U37, CS4350 DAC, address 0x4B, bus 2
	 *	THIS ENTRY MUST BE FIRST
	 */
	{
		.type		= "cs4350",
		.addr		= 0x4B,
	}

	/*
	 * U24, ubicom32hid
	 */
	{
		.type		= "ubicom32hid",
		.addr		= 0x08,
		.platform_data	= &ip7160dpf_ubicom32hid_platform_data,
	},

	/*
	 * U49, ISL29001 Ambient Light Sensor, address 0x44, bus 2 (may not be stuffed)
	 */

	/*
	 * U51, S35390A RTC, address 0x30, bus 2 (may not be stuffed)
	 */
#ifdef CONFIG_RTC_DRV_S35390A
	{
		.type           = "s35390a",
		.addr           = 0x30,
	},
#endif
};

/*
 * I2C bus on the board, SDA PI1, SCL PI2
 */
static struct i2c_gpio_platform_data ip7160dpf_i2c_data = {
	.sda_pin		= GPIO_RI_1,
	.scl_pin		= GPIO_RI_2,
	.sda_is_open_drain	= 0,
	.scl_is_open_drain	= 0,
	.scl_is_output_only	= 1,
	.udelay			= 6,
};

static struct platform_device ip7160dpf_i2c_device = {
	.name	= "i2c-gpio",
	.id	= 0,
	.dev	= {
		.platform_data = &ip7160dpf_i2c_data,
	},
};

/*
 * List of all devices in our system
 */
static struct platform_device *ip7160dpf_devices[] __initdata = {
	&ip7160dpf_i2c_device,
};

/*
 * ip7160dpf_power_off
 *	Called to turn the power off for this board
 */
static void ip7160dpf_power_off(void)
{
	gpio_set_value(GPIO_RF_14, 0);
}

/*
 * ip7160dpf_init
 *	Called to add the devices which we have on this board
 */
static int __init ip7160dpf_init(void)
{
	int ret;
	struct platform_device *audio_dev;

	ubi_gpio_init();

	/*
	 * Hold the POWER_HOLD line
	 */
	ret = gpio_request(GPIO_RF_14, "POWER_HOLD");
	if (ret) {
		printk(KERN_ERR "%s: could not request POWER_HOLD GPIO\n", __FUNCTION__);
	}
	gpio_direction_output(GPIO_RF_14, 1);
	mach_power_off = ip7160dpf_power_off;

	/*
	 * USB SEL_HOST_USB line
	 */
	ret = gpio_request(GPIO_RI_13, "SEL_HOST_USB");
	if (ret) {
		printk(KERN_ERR "%s: could not request SEL_HOST_USB GPIO\n", __FUNCTION__);
	}
	gpio_direction_output(GPIO_RI_13, 0);

	/*
	 * USB/DAC nRESET line
	 */
	ret = gpio_request(GPIO_RI_3, "USB_DAC_nRESET");
	if (ret) {
		printk(KERN_ERR "%s: could not request USB_DAC_nRESET GPIO\n", __FUNCTION__);
	}
	gpio_direction_output(GPIO_RI_3, 0);
	udelay(1);
	gpio_direction_output(GPIO_RI_3, 1);

	/*
	 * I2C BUS2 Disable line
	 */
	ret = gpio_request(GPIO_RI_0, "DISABLE_BUS2");
	if (ret) {
		printk(KERN_ERR "%s: could not request DISABLE_BUS2 GPIO\n", __FUNCTION__);
	}
	gpio_direction_output(GPIO_RI_0, 0);

	vdc_tio_init();

	printk(KERN_INFO "%s: registering device resources\n", __FUNCTION__);
	platform_add_devices(ip7160dpf_devices, ARRAY_SIZE(ip7160dpf_devices));

	/*
	 * Allocate the audio driver if we can
	 */
	audio_dev = audio_device_alloc("snd-ubi32-cs4350", "audio-i2sout", 0);
	if (audio_dev) {
		ip7160dpf_i2c_board_info[0].platform_data = audio_dev;
	}

	printk(KERN_INFO "%s: registering i2c resources\n", __FUNCTION__);
	i2c_register_board_info(0, ip7160dpf_i2c_board_info, ARRAY_SIZE(ip7160dpf_i2c_board_info));

	return 0;
}

arch_initcall(ip7160dpf_init);