ARM: tegra: fix regulator_get() return value check
[linux-3.10.git] / arch / arm / mach-tegra / panel-s-edp-uhdtv-15-6.c
1 /*
2  * arch/arm/mach-tegra/panel-s-uhdtv-15-6.c
3  *
4  * Copyright (c) 2012-2013, NVIDIA CORPORATION. All rights reserved.
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms and conditions of the GNU General Public License,
8  * version 2, as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18
19 #include <mach/dc.h>
20 #include <linux/delay.h>
21 #include <linux/gpio.h>
22 #include <linux/tegra_pwm_bl.h>
23 #include <linux/regulator/consumer.h>
24 #include <linux/pwm_backlight.h>
25 #include <linux/leds.h>
26 #include <linux/ioport.h>
27 #include "board.h"
28 #include "board-panel.h"
29 #include "devices.h"
30 #include "gpio-names.h"
31 #include "tegra12_host1x_devices.h"
32
33 #define DC_CTRL_MODE    TEGRA_DC_OUT_CONTINUOUS_MODE
34
35 #define EDP_PANEL_BL_PWM        TEGRA_GPIO_PH1
36
37 static bool reg_requested;
38 static struct platform_device *disp_device;
39
40 static struct regulator *vdd_lcd_bl_en; /* VDD_LCD_BL_EN */
41
42 static struct regulator *vdd_ds_1v8; /* VDD_1V8_AON */
43 static struct regulator *avdd_3v3_dp; /* EDP_3V3_IN: LCD_RST_GPIO */
44 static struct regulator *avdd_lcd; /* VDD_LCD_HV */
45
46 static int shield_edp_regulator_get(struct device *dev)
47 {
48         int err = 0;
49
50         if (reg_requested)
51                 return 0;
52
53         vdd_ds_1v8 = regulator_get(dev, "vdd_ds_1v8");
54         if (IS_ERR(vdd_ds_1v8)) {
55                 pr_err("vdd_ds_1v8 regulator get failed\n");
56                 err = PTR_ERR(vdd_ds_1v8);
57                 vdd_ds_1v8 = NULL;
58                 goto fail;
59         }
60
61         /* backlight */
62         vdd_lcd_bl_en = regulator_get(dev, "vdd_lcd_bl_en");
63         if (IS_ERR(vdd_lcd_bl_en)) {
64                 pr_err("vdd_lcd_bl_en regulator get failed\n");
65                 err = PTR_ERR(vdd_lcd_bl_en);
66                 vdd_lcd_bl_en = NULL;
67                 goto fail;
68         }
69
70         /* lcd */
71         avdd_lcd = regulator_get(dev, "avdd_lcd");
72         if (IS_ERR(avdd_lcd)) {
73                 pr_err("avdd_lcd regulator get failed\n");
74                 err = PTR_ERR(avdd_lcd);
75                 avdd_lcd = NULL;
76                 goto fail;
77         }
78
79         /* LCD_RST */
80         avdd_3v3_dp = regulator_get(dev, "avdd_3v3_dp");
81         if (IS_ERR(avdd_3v3_dp)) {
82                 pr_err("avdd_3v3_dp regulator get failed\n");
83                 err = PTR_ERR(avdd_3v3_dp);
84                 avdd_3v3_dp = NULL;
85                 goto fail;
86         }
87
88         reg_requested = true;
89         return 0;
90 fail:
91         return err;
92 }
93
94 static int edp_s_uhdtv_15_6_enable(struct device *dev)
95 {
96         int err = 0;
97
98         err = shield_edp_regulator_get(dev);
99         if (err < 0) {
100                 pr_err("edp regulator get failed\n");
101                 goto fail;
102         }
103
104         if (vdd_ds_1v8) {
105                 err = regulator_enable(vdd_ds_1v8);
106                 if (err < 0) {
107                         pr_err("vdd_ds_1v8 regulator enable failed\n");
108                         goto fail;
109                 }
110         }
111
112         if (avdd_lcd) {
113                 err = regulator_enable(avdd_lcd);
114                 if (err < 0) {
115                         pr_err("avdd_lcd regulator enable failed\n");
116                         goto fail;
117                 }
118         }
119
120         /* LCD_RST */
121         if (avdd_3v3_dp) {
122                 err = regulator_enable(avdd_3v3_dp);
123                 if (err < 0) {
124                         pr_err("avdd_3v3_dp regulator enable failed\n");
125                         goto fail;
126                 }
127         }
128
129         msleep(110);
130
131         if (vdd_lcd_bl_en) {
132                 err = regulator_enable(vdd_lcd_bl_en);
133                 if (err < 0) {
134                         pr_err("vdd_lcd_bl_en regulator enable failed\n");
135                         goto fail;
136                 }
137         }
138         msleep(180);
139
140         return 0;
141 fail:
142         return err;
143 }
144
145 static int edp_s_uhdtv_15_6_disable(void)
146 {
147         if (vdd_lcd_bl_en)
148                 regulator_disable(vdd_lcd_bl_en);
149
150         if (avdd_3v3_dp)
151                 regulator_disable(avdd_3v3_dp);
152
153         if (avdd_lcd)
154                 regulator_disable(avdd_lcd);
155
156         if (vdd_ds_1v8)
157                 regulator_disable(vdd_ds_1v8);
158
159         msleep(500);
160
161         return 0;
162 }
163
164 static int edp_s_uhdtv_15_6_postsuspend(void)
165 {
166         return 0;
167 }
168
169 static struct tegra_dc_out_pin edp_out_pins[] = {
170         {
171                 .name   = TEGRA_DC_OUT_PIN_H_SYNC,
172                 .pol    = TEGRA_DC_OUT_PIN_POL_LOW,
173         },
174         {
175                 .name   = TEGRA_DC_OUT_PIN_V_SYNC,
176                 .pol    = TEGRA_DC_OUT_PIN_POL_LOW,
177         },
178         {
179                 .name   = TEGRA_DC_OUT_PIN_PIXEL_CLOCK,
180                 .pol    = TEGRA_DC_OUT_PIN_POL_LOW,
181         },
182         {
183                 .name   = TEGRA_DC_OUT_PIN_DATA_ENABLE,
184                 .pol    = TEGRA_DC_OUT_PIN_POL_HIGH,
185         },
186 };
187
188 static struct tegra_dc_mode edp_s_uhdtv_15_6_modes[] = {
189         {
190                 .pclk = 522090000,
191                 .h_ref_to_sync = 1,
192                 .v_ref_to_sync = 1,
193                 .h_sync_width = 32,
194                 .v_sync_width = 5,
195                 .h_back_porch = 80,
196                 .v_back_porch = 54,
197                 .h_active = 3840,
198                 .v_active = 2160,
199                 .h_front_porch = 48,
200                 .v_front_porch = 3,
201         },
202 };
203
204 static int edp_s_uhdtv_15_6_bl_notify(struct device *unused, int brightness)
205 {
206         int cur_sd_brightness = atomic_read(&sd_brightness);
207
208         /* SD brightness is a percentage */
209         brightness = (brightness * cur_sd_brightness) / 255;
210
211         /* Apply any backlight response curve */
212         if (brightness > 255)
213                 pr_info("Error: Brightness > 255!\n");
214
215         return brightness;
216 }
217
218 static int edp_s_uhdtv_15_6_check_fb(struct device *dev, struct fb_info *info)
219 {
220         return info->device == &disp_device->dev;
221 }
222
223 static struct platform_pwm_backlight_data edp_s_uhdtv_15_6_bl_data = {
224         .pwm_id         = 1,
225         .max_brightness = 255,
226         .dft_brightness = 224,
227         .pwm_period_ns  = 5000000,
228         .pwm_gpio       = EDP_PANEL_BL_PWM,
229         .notify         = edp_s_uhdtv_15_6_bl_notify,
230         /* Only toggle backlight on fb blank notifications for disp1 */
231         .check_fb       = edp_s_uhdtv_15_6_check_fb,
232 };
233
234 static struct platform_device __maybe_unused
235                 edp_s_uhdtv_15_6_bl_device = {
236         .name   = "pwm-backlight",
237         .id     = -1,
238         .dev    = {
239                 .platform_data = &edp_s_uhdtv_15_6_bl_data,
240         },
241 };
242
243 static struct platform_device __maybe_unused
244                         *edp_s_uhdtv_15_6_bl_devices[] __initdata = {
245         &tegra_pwfm_device,
246         &edp_s_uhdtv_15_6_bl_device,
247 };
248
249 static int  __init edp_s_uhdtv_15_6_register_bl_dev(void)
250 {
251         int err = 0;
252         err = platform_add_devices(edp_s_uhdtv_15_6_bl_devices,
253                                 ARRAY_SIZE(edp_s_uhdtv_15_6_bl_devices));
254         if (err) {
255                 pr_err("disp1 bl device registration failed");
256                 return err;
257         }
258         return err;
259 }
260
261 static void edp_s_uhdtv_15_6_set_disp_device(
262         struct platform_device *shield_display_device)
263 {
264         disp_device = shield_display_device;
265 }
266
267 static void edp_s_uhdtv_15_6_dc_out_init(struct tegra_dc_out *out)
268 {
269         out->align = TEGRA_DC_ALIGN_MSB;
270         out->order = TEGRA_DC_ORDER_RED_BLUE;
271         out->flags = DC_CTRL_MODE;
272         out->modes = edp_s_uhdtv_15_6_modes;
273         out->n_modes = ARRAY_SIZE(edp_s_uhdtv_15_6_modes);
274         out->out_pins = edp_out_pins;
275         out->n_out_pins = ARRAY_SIZE(edp_out_pins);
276         out->depth = 16;
277         out->parent_clk = "pll_d_out0";
278         out->enable = edp_s_uhdtv_15_6_enable;
279         out->disable = edp_s_uhdtv_15_6_disable;
280         out->postsuspend = edp_s_uhdtv_15_6_postsuspend;
281         out->width = 346;
282         out->height = 194;
283         out->hotplug_gpio = TEGRA_GPIO_PFF0;
284 }
285
286 static void edp_s_uhdtv_15_6_fb_data_init(struct tegra_fb_data *fb)
287 {
288         fb->xres = edp_s_uhdtv_15_6_modes[0].h_active;
289         fb->yres = edp_s_uhdtv_15_6_modes[0].v_active;
290 }
291
292 static void
293 edp_s_uhdtv_15_6_sd_settings_init(struct tegra_dc_sd_settings *settings)
294 {
295         settings->bl_device_name = "pwm-backlight";
296 }
297
298 struct tegra_panel __initdata edp_s_uhdtv_15_6 = {
299         .init_sd_settings = edp_s_uhdtv_15_6_sd_settings_init,
300         .init_dc_out = edp_s_uhdtv_15_6_dc_out_init,
301         .init_fb_data = edp_s_uhdtv_15_6_fb_data_init,
302         .register_bl_dev = edp_s_uhdtv_15_6_register_bl_dev,
303         .set_disp_device = edp_s_uhdtv_15_6_set_disp_device,
304 };
305 EXPORT_SYMBOL(edp_s_uhdtv_15_6);