Merge branch 'timers-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[deliverable/linux.git] / arch / arm / plat-samsung / dev-backlight.c
CommitLineData
f00207b2
BG
1/* 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>
3d46cceb 15#include <linux/slab.h>
f00207b2
BG
16#include <linux/io.h>
17#include <linux/pwm_backlight.h>
8088041e 18#include <linux/slab.h>
f00207b2
BG
19
20#include <plat/devs.h>
21#include <plat/gpio-cfg.h>
22#include <plat/backlight.h>
23
24static int samsung_bl_init(struct device *dev)
25{
26 int ret = 0;
27 struct platform_device *timer_dev =
28 container_of(dev->parent, struct platform_device, dev);
29 struct samsung_bl_gpio_info *bl_gpio_info =
30 timer_dev->dev.platform_data;
31
32 ret = gpio_request(bl_gpio_info->no, "Backlight");
33 if (ret) {
34 printk(KERN_ERR "failed to request GPIO for LCD Backlight\n");
35 return ret;
36 }
37
38 /* Configure GPIO pin with specific GPIO function for PWM timer */
39 s3c_gpio_cfgpin(bl_gpio_info->no, bl_gpio_info->func);
40
41 return 0;
42}
43
44static void samsung_bl_exit(struct device *dev)
45{
46 struct platform_device *timer_dev =
47 container_of(dev->parent, struct platform_device, dev);
48 struct samsung_bl_gpio_info *bl_gpio_info =
49 timer_dev->dev.platform_data;
50
51 s3c_gpio_cfgpin(bl_gpio_info->no, S3C_GPIO_OUTPUT);
52 gpio_free(bl_gpio_info->no);
53}
54
55/* Initialize few important fields of platform_pwm_backlight_data
56 * structure with default values. These fields can be overridden by
57 * board-specific values sent from machine file.
58 * For ease of operation, these fields are initialized with values
59 * used by most samsung boards.
60 * Users has the option of sending info about other parameters
61 * for their specific boards
62 */
63
64static struct platform_pwm_backlight_data samsung_dfl_bl_data __initdata = {
65 .max_brightness = 255,
66 .dft_brightness = 255,
67 .pwm_period_ns = 78770,
68 .init = samsung_bl_init,
69 .exit = samsung_bl_exit,
70};
71
72static struct platform_device samsung_dfl_bl_device __initdata = {
73 .name = "pwm-backlight",
74};
75
76/* samsung_bl_set - Set board specific data (if any) provided by user for
77 * PWM Backlight control and register specific PWM and backlight device.
78 * @gpio_info: structure containing GPIO info for PWM timer
79 * @bl_data: structure containing Backlight control data
80 */
81void samsung_bl_set(struct samsung_bl_gpio_info *gpio_info,
82 struct platform_pwm_backlight_data *bl_data)
83{
84 int ret = 0;
85 struct platform_device *samsung_bl_device;
86 struct platform_pwm_backlight_data *samsung_bl_data;
87
88 samsung_bl_device = kmemdup(&samsung_dfl_bl_device,
89 sizeof(struct platform_device), GFP_KERNEL);
90 if (!samsung_bl_device) {
91 printk(KERN_ERR "%s: no memory for platform dev\n", __func__);
92 return;
93 }
94
95 samsung_bl_data = s3c_set_platdata(&samsung_dfl_bl_data,
96 sizeof(struct platform_pwm_backlight_data), samsung_bl_device);
97 if (!samsung_bl_data) {
98 printk(KERN_ERR "%s: no memory for platform dev\n", __func__);
99 goto err_data;
100 }
101
102 /* Copy board specific data provided by user */
103 samsung_bl_data->pwm_id = bl_data->pwm_id;
104 samsung_bl_device->dev.parent =
105 &s3c_device_timer[samsung_bl_data->pwm_id].dev;
106
107 if (bl_data->max_brightness)
108 samsung_bl_data->max_brightness = bl_data->max_brightness;
109 if (bl_data->dft_brightness)
110 samsung_bl_data->dft_brightness = bl_data->dft_brightness;
111 if (bl_data->lth_brightness)
112 samsung_bl_data->lth_brightness = bl_data->lth_brightness;
113 if (bl_data->pwm_period_ns)
114 samsung_bl_data->pwm_period_ns = bl_data->pwm_period_ns;
115 if (bl_data->init)
116 samsung_bl_data->init = bl_data->init;
117 if (bl_data->notify)
118 samsung_bl_data->notify = bl_data->notify;
119 if (bl_data->exit)
120 samsung_bl_data->exit = bl_data->exit;
121 if (bl_data->check_fb)
122 samsung_bl_data->check_fb = bl_data->check_fb;
123
124 /* Keep the GPIO info for future use */
125 s3c_device_timer[samsung_bl_data->pwm_id].dev.platform_data = gpio_info;
126
127 /* Register the specific PWM timer dev for Backlight control */
128 ret = platform_device_register(
129 &s3c_device_timer[samsung_bl_data->pwm_id]);
130 if (ret) {
131 printk(KERN_ERR "failed to register pwm timer for backlight: %d\n", ret);
132 goto err_plat_reg1;
133 }
134
135 /* Register the Backlight dev */
136 ret = platform_device_register(samsung_bl_device);
137 if (ret) {
138 printk(KERN_ERR "failed to register backlight device: %d\n", ret);
139 goto err_plat_reg2;
140 }
141
142 return;
143
144err_plat_reg2:
145 platform_device_unregister(&s3c_device_timer[samsung_bl_data->pwm_id]);
146err_plat_reg1:
147 kfree(samsung_bl_data);
148err_data:
149 kfree(samsung_bl_device);
150 return;
151}
This page took 0.051102 seconds and 5 git commands to generate.