blob: 5f197dcaf10c017a439185f0f29860e9877a2cdd [file] [log] [blame]
Banajit Goswamif00207b2011-07-20 23:44:21 +09001/* linux/arch/arm/plat-samsung/dev-backlight.c
2 *
3 * Copyright (c) 2011 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com
5 *
6 * Common infrastructure for PWM Backlight for Samsung boards
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 */
12
13#include <linux/gpio.h>
14#include <linux/platform_device.h>
Paul Gortmaker3d46cce2011-07-31 18:16:56 -040015#include <linux/slab.h>
Banajit Goswamif00207b2011-07-20 23:44:21 +090016#include <linux/io.h>
17#include <linux/pwm_backlight.h>
Banajit Goswamif00207b2011-07-20 23:44:21 +090018
19#include <plat/devs.h>
20#include <plat/gpio-cfg.h>
21#include <plat/backlight.h>
22
23static int samsung_bl_init(struct device *dev)
24{
25 int ret = 0;
26 struct platform_device *timer_dev =
27 container_of(dev->parent, struct platform_device, dev);
28 struct samsung_bl_gpio_info *bl_gpio_info =
29 timer_dev->dev.platform_data;
30
31 ret = gpio_request(bl_gpio_info->no, "Backlight");
32 if (ret) {
33 printk(KERN_ERR "failed to request GPIO for LCD Backlight\n");
34 return ret;
35 }
36
37 /* Configure GPIO pin with specific GPIO function for PWM timer */
38 s3c_gpio_cfgpin(bl_gpio_info->no, bl_gpio_info->func);
39
40 return 0;
41}
42
43static void samsung_bl_exit(struct device *dev)
44{
45 struct platform_device *timer_dev =
46 container_of(dev->parent, struct platform_device, dev);
47 struct samsung_bl_gpio_info *bl_gpio_info =
48 timer_dev->dev.platform_data;
49
50 s3c_gpio_cfgpin(bl_gpio_info->no, S3C_GPIO_OUTPUT);
51 gpio_free(bl_gpio_info->no);
52}
53
54/* Initialize few important fields of platform_pwm_backlight_data
55 * structure with default values. These fields can be overridden by
56 * board-specific values sent from machine file.
57 * For ease of operation, these fields are initialized with values
58 * used by most samsung boards.
59 * Users has the option of sending info about other parameters
60 * for their specific boards
61 */
62
63static struct platform_pwm_backlight_data samsung_dfl_bl_data __initdata = {
64 .max_brightness = 255,
65 .dft_brightness = 255,
66 .pwm_period_ns = 78770,
67 .init = samsung_bl_init,
68 .exit = samsung_bl_exit,
69};
70
71static struct platform_device samsung_dfl_bl_device __initdata = {
72 .name = "pwm-backlight",
73};
74
75/* samsung_bl_set - Set board specific data (if any) provided by user for
76 * PWM Backlight control and register specific PWM and backlight device.
77 * @gpio_info: structure containing GPIO info for PWM timer
78 * @bl_data: structure containing Backlight control data
79 */
Tushar Behera4db17212012-03-09 08:03:13 -080080void __init samsung_bl_set(struct samsung_bl_gpio_info *gpio_info,
Banajit Goswamif00207b2011-07-20 23:44:21 +090081 struct platform_pwm_backlight_data *bl_data)
82{
83 int ret = 0;
84 struct platform_device *samsung_bl_device;
85 struct platform_pwm_backlight_data *samsung_bl_data;
86
87 samsung_bl_device = kmemdup(&samsung_dfl_bl_device,
88 sizeof(struct platform_device), GFP_KERNEL);
89 if (!samsung_bl_device) {
90 printk(KERN_ERR "%s: no memory for platform dev\n", __func__);
91 return;
92 }
93
94 samsung_bl_data = s3c_set_platdata(&samsung_dfl_bl_data,
95 sizeof(struct platform_pwm_backlight_data), samsung_bl_device);
96 if (!samsung_bl_data) {
97 printk(KERN_ERR "%s: no memory for platform dev\n", __func__);
98 goto err_data;
99 }
100
101 /* Copy board specific data provided by user */
102 samsung_bl_data->pwm_id = bl_data->pwm_id;
103 samsung_bl_device->dev.parent =
104 &s3c_device_timer[samsung_bl_data->pwm_id].dev;
105
106 if (bl_data->max_brightness)
107 samsung_bl_data->max_brightness = bl_data->max_brightness;
108 if (bl_data->dft_brightness)
109 samsung_bl_data->dft_brightness = bl_data->dft_brightness;
110 if (bl_data->lth_brightness)
111 samsung_bl_data->lth_brightness = bl_data->lth_brightness;
112 if (bl_data->pwm_period_ns)
113 samsung_bl_data->pwm_period_ns = bl_data->pwm_period_ns;
114 if (bl_data->init)
115 samsung_bl_data->init = bl_data->init;
116 if (bl_data->notify)
117 samsung_bl_data->notify = bl_data->notify;
Jingoo Han23747142011-12-26 20:29:31 +0900118 if (bl_data->notify_after)
119 samsung_bl_data->notify_after = bl_data->notify_after;
Banajit Goswamif00207b2011-07-20 23:44:21 +0900120 if (bl_data->exit)
121 samsung_bl_data->exit = bl_data->exit;
122 if (bl_data->check_fb)
123 samsung_bl_data->check_fb = bl_data->check_fb;
124
125 /* Keep the GPIO info for future use */
126 s3c_device_timer[samsung_bl_data->pwm_id].dev.platform_data = gpio_info;
127
128 /* Register the specific PWM timer dev for Backlight control */
129 ret = platform_device_register(
130 &s3c_device_timer[samsung_bl_data->pwm_id]);
131 if (ret) {
132 printk(KERN_ERR "failed to register pwm timer for backlight: %d\n", ret);
133 goto err_plat_reg1;
134 }
135
136 /* Register the Backlight dev */
137 ret = platform_device_register(samsung_bl_device);
138 if (ret) {
139 printk(KERN_ERR "failed to register backlight device: %d\n", ret);
140 goto err_plat_reg2;
141 }
142
143 return;
144
145err_plat_reg2:
146 platform_device_unregister(&s3c_device_timer[samsung_bl_data->pwm_id]);
147err_plat_reg1:
148 kfree(samsung_bl_data);
149err_data:
150 kfree(samsung_bl_device);
151 return;
152}