1
2
3
4
5
6
7
8#include <linux/gpio.h>
9#include <linux/platform_device.h>
10#include <linux/slab.h>
11#include <linux/io.h>
12#include <linux/pwm_backlight.h>
13
14#include "devs.h"
15#include "gpio-cfg.h"
16
17#include "backlight-s3c64xx.h"
18
19struct samsung_bl_drvdata {
20 struct platform_pwm_backlight_data plat_data;
21 struct samsung_bl_gpio_info *gpio_info;
22};
23
24static int samsung_bl_init(struct device *dev)
25{
26 int ret = 0;
27 struct platform_pwm_backlight_data *pdata = dev->platform_data;
28 struct samsung_bl_drvdata *drvdata = container_of(pdata,
29 struct samsung_bl_drvdata, plat_data);
30 struct samsung_bl_gpio_info *bl_gpio_info = drvdata->gpio_info;
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
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_pwm_backlight_data *pdata = dev->platform_data;
47 struct samsung_bl_drvdata *drvdata = container_of(pdata,
48 struct samsung_bl_drvdata, plat_data);
49 struct samsung_bl_gpio_info *bl_gpio_info = drvdata->gpio_info;
50
51 s3c_gpio_cfgpin(bl_gpio_info->no, S3C_GPIO_OUTPUT);
52 gpio_free(bl_gpio_info->no);
53}
54
55
56
57
58
59
60
61
62
63
64static struct samsung_bl_drvdata samsung_dfl_bl_data __initdata = {
65 .plat_data = {
66 .max_brightness = 255,
67 .dft_brightness = 255,
68 .init = samsung_bl_init,
69 .exit = samsung_bl_exit,
70 },
71};
72
73static struct platform_device samsung_dfl_bl_device __initdata = {
74 .name = "pwm-backlight",
75};
76
77
78
79
80
81
82void __init samsung_bl_set(struct samsung_bl_gpio_info *gpio_info,
83 struct platform_pwm_backlight_data *bl_data)
84{
85 int ret = 0;
86 struct platform_device *samsung_bl_device;
87 struct samsung_bl_drvdata *samsung_bl_drvdata;
88 struct platform_pwm_backlight_data *samsung_bl_data;
89
90 samsung_bl_device = kmemdup(&samsung_dfl_bl_device,
91 sizeof(struct platform_device), GFP_KERNEL);
92 if (!samsung_bl_device)
93 return;
94
95 samsung_bl_drvdata = kmemdup(&samsung_dfl_bl_data,
96 sizeof(samsung_dfl_bl_data), GFP_KERNEL);
97 if (!samsung_bl_drvdata)
98 goto err_data;
99
100 samsung_bl_device->dev.platform_data = &samsung_bl_drvdata->plat_data;
101 samsung_bl_drvdata->gpio_info = gpio_info;
102 samsung_bl_data = &samsung_bl_drvdata->plat_data;
103
104
105 samsung_bl_device->dev.parent = &samsung_device_pwm.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->init)
114 samsung_bl_data->init = bl_data->init;
115 if (bl_data->notify)
116 samsung_bl_data->notify = bl_data->notify;
117 if (bl_data->notify_after)
118 samsung_bl_data->notify_after = bl_data->notify_after;
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
125 ret = platform_device_register(samsung_bl_device);
126 if (ret) {
127 printk(KERN_ERR "failed to register backlight device: %d\n", ret);
128 goto err_plat_reg2;
129 }
130
131 return;
132
133err_plat_reg2:
134 kfree(samsung_bl_data);
135err_data:
136 kfree(samsung_bl_device);
137}
138