summaryrefslogtreecommitdiff
path: root/firmware/target/arm/imx233/samsung-ypz5/backlight-ypz5.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/arm/imx233/samsung-ypz5/backlight-ypz5.c')
-rw-r--r--firmware/target/arm/imx233/samsung-ypz5/backlight-ypz5.c149
1 files changed, 0 insertions, 149 deletions
diff --git a/firmware/target/arm/imx233/samsung-ypz5/backlight-ypz5.c b/firmware/target/arm/imx233/samsung-ypz5/backlight-ypz5.c
deleted file mode 100644
index b02c3a1d16..0000000000
--- a/firmware/target/arm/imx233/samsung-ypz5/backlight-ypz5.c
+++ /dev/null
@@ -1,149 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * Copyright (C) 2013 by Lorenzo Miori
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
15 *
16 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
17 * KIND, either express or implied.
18 *
19 ****************************************************************************/
20
21#include "config.h"
22#include "system.h"
23#include "lcd.h"
24#include "backlight.h"
25#include "backlight-target.h"
26#include "pinctrl-imx233.h"
27
28/**
29 * AAT3151 Backlight Controller
30 */
31
32/* Timings */
33#define TIME_OFF 500
34#define TIME_LOW 50
35#define TIME_HI 50
36#define TIME_LAT 500
37
38/* Number of raising edges to select the particular register */
39#define D1_D4_CURRENT_E 17
40#define D1_D3_CURRENT_E 18
41#define D4_CURRENT_E 19
42#define MAX_CURRENT_E 20
43#define LOW_CURRENT_E 21
44
45/* The actual register address / number */
46#define D1_D4_CURRENT 1
47#define D1_D3_CURRENT 2
48#define D4_CURRENT 3
49#define MAX_CURRENT 4
50#define LOW_CURRENT 5
51
52/* Valid values for LOW_CURRENT register */
53#define MAX_CURRENT_20 1
54#define MAX_CURRENT_30 2
55#define MAX_CURRENT_15 3
56#define MAX_CURRENT_LOW_CURRENT 4
57
58static int current_level = -1;
59
60static void create_raising_edges(int num)
61{
62 while (num--)
63 {
64 /* Setting a register takes a sufficient small amount of time,
65 * in the order of 50 ns. Thus the necessary 2 delays TIME_LOW/TIME_HI
66 * are not strictly necessary */
67 imx233_pinctrl_set_gpio(3, 13, false);
68 imx233_pinctrl_set_gpio(3, 13, true);
69 }
70}
71
72static void aat3151_write(int addr, int data)
73{
74 create_raising_edges(16 + addr);
75 udelay(TIME_LAT);
76 create_raising_edges(data);
77 udelay(TIME_LAT);
78}
79
80void backlight_hw_brightness(int level)
81{
82 /* Don't try to reset backlight if not necessary
83 * Moreover this helps to avoid flickering when
84 * being in some screens like USB mode and
85 * pressing some keys / touchpad...
86 */
87 if (current_level == level) return;
88
89 /* Check for limits and adjust in case */
90 level = MIN(MAX_BRIGHTNESS_SETTING, MAX(0, level));
91
92 if (level == 0)
93 {
94 /* Set pin low for a sufficient time, puts the device into low-power consumption state
95 * In other words backlight goes off
96 */
97 imx233_pinctrl_set_gpio(3, 13, false);
98 udelay(TIME_OFF);
99 }
100 else
101 {
102 if (level > 3) {
103 /* This enables 16 levels of backlight */
104 aat3151_write(MAX_CURRENT, MAX_CURRENT_15);
105 /* Set the value according Table 1 in datasheet
106 * For MAX_CURRENT_15, the scale is from 0 mA to 15 mA in 16 steps
107 */
108 aat3151_write(D1_D3_CURRENT, 19 - level);
109 }
110 else {
111 /* This enables other 4 levels of backlight */
112 aat3151_write(MAX_CURRENT, MAX_CURRENT_LOW_CURRENT);
113 /* Set the value according Table 1 in datasheet
114 * For LOW_CURRENT, there is no "real" scale. We have scattered values.
115 * We are interested in the last 3 -> 0.5 mA; 1 mA; 2 mA
116 */
117 aat3151_write(LOW_CURRENT, 13 + level);
118 }
119 }
120 current_level = level;
121}
122
123bool backlight_hw_init(void)
124{
125 imx233_pinctrl_acquire(3, 13, "backlight");
126 imx233_pinctrl_set_function(3, 13, PINCTRL_FUNCTION_GPIO);
127 imx233_pinctrl_set_drive(3, 13, PINCTRL_DRIVE_4mA);
128 imx233_pinctrl_enable_gpio(3, 13, true);
129 imx233_pinctrl_set_gpio(3, 13, false);
130 return true;
131}
132
133void backlight_hw_on(void)
134{
135#ifdef HAVE_LCD_ENABLE
136 lcd_enable(true); /* power on lcd + visible display */
137#endif
138 /* restore the previous backlight level */
139 backlight_hw_brightness(backlight_brightness);
140}
141
142void backlight_hw_off(void)
143{
144 /* there is no real on/off but we can set to 0 brightness */
145 backlight_hw_brightness(0);
146#ifdef HAVE_LCD_ENABLE
147 lcd_enable(false); /* power off visible display */
148#endif
149}