summaryrefslogtreecommitdiffstats
path: root/u-boot/board/goldelico/gta04/backlight.c
blob: 76b6e435c70283a7d1ae53b28b87950687283240 (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
/* u-boot driver for the GTA04 backlight
 *
 * Copyright (C) 2010 by Golden Delicious Computers GmbH&Co. KG
 * Author: H. Nikolaus Schaller <hns@goldelico.com>
 * All rights reserved.
 *
 * This program 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.
 *
 * This program 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 this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 * MA 02111-1307 USA
 *
 */

#include <common.h>
#include <asm/errno.h>
#include <asm/io.h>
#include <asm/arch/mux.h>
#include <asm/arch/sys_proto.h>
#include <asm/arch/gpio.h>
#include <asm/mach-types.h>
#include "backlight.h"

#if defined(CONFIG_OMAP3_GTA04)

#define GPIO_BACKLIGHT		57	/* = GPT11_PWM */
#define GPT_BACKLIGHT		OMAP34XX_GPT11

#elif defined(CONFIG_OMAP3_BEAGLE_HYBRID)

#define GPIO_BACKLIGHT		145	/* = GPT10_PWM */
#define GPT_BACKLIGHT		OMAP34XX_GPT10

#elif defined(CONFIG_OMAP3_BEAGLE_EXPANDER)

#define GPIO_BACKLIGHT		146	/* = GPT11_PWM (instead of UART2-TX) */
#define GPT_BACKLIGHT		OMAP34XX_GPT11

#else

#error undefined CONFIG

#endif

#define USE_PWM	0

void backlight_set_level(int level)	// 0..255
{
#if USE_PWM
	struct gptimer *gpt_base = (struct gptimer *)GPT_BACKLIGHT;
	// 	writel(value, &gpt_base->registername);
#else
	omap_set_gpio_dataout(GPIO_BACKLIGHT, level >= 128);	// for simplicity we just have on/off
	level=(level >= 128)?255:0;
#endif
	printf("lcm backlight level set to %d (0..255)\n", level);
}

int backlight_init(void)
{
#if USE_PWM
	struct gptimer *gpt_base = (struct gptimer *)GPT_BACKLIGHT;
#if defined(CONFIG_OMAP3_GTA04)
	MUX_VAL(CP(GPMC_NCS6),		(IEN | PTD | DIS | M3)) /* GPT_11 - Backlight enable*/\
#elif defined(CONFIG_OMAP3_BEAGLE_HYBRID)
	MUX_VAL(CP(UART2_RTS),		(IEN  | PTD | DIS | M2)) /* switch to GPT10 */
#elif defined(CONFIG_OMAP3_BEAGLE_EXPANDER)
	MUX_VAL(CP(UART2_TX),		(IEN  | PTD | DIS | M2)) /* switch to GPT11 */
#else	
#error undefined CONFIG
#endif
	// 	writel(value, &gpt_base->registername);
	// program registers for generating a 100-1000 Hz PWM signal
	// or PWM synchronized to VSYNC (to avoid flicker)
	printf("did backlight_init() on PWM\n");

#error todo
	
#else
#if defined(CONFIG_OMAP3_GTA04)
	MUX_VAL(CP(GPMC_NCS6),		(IEN | PTD | DIS | M4)) /*GPIO_57 - Backlight enable*/
#elif defined(CONFIG_OMAP3_BEAGLE_HYBRID)
	MUX_VAL(CP(UART2_RTS),		(IEN  | PTD | DIS | M4)) /*GPIO_145*/
#elif defined(CONFIG_OMAP3_BEAGLE_EXPANDER)
	MUX_VAL(CP(UART2_TX),		(IEN  | PTD | DIS | M4)) /*GPIO_146*/
#else	
#error undefined CONFIG
#endif
	if(omap_request_gpio(GPIO_BACKLIGHT) == 0)	// 0 == ok
		{
		omap_set_gpio_direction(GPIO_BACKLIGHT, 0);		// output
		printf("did backlight_init() on GPIO_%d\n", GPIO_BACKLIGHT);		
		}
	else
		{
		printf("backlight_init() on GPIO_%d failed\n", GPIO_BACKLIGHT);		
		}

#endif

	return 0;
}