blob: e62e789f9aeeecd279c93ce6b8c7775e283074e4 [file] [log] [blame]
Kukjin Kim7f798c12015-07-30 01:48:17 +09001/*
Banajit Goswamif00207b2011-07-20 23:44:21 +09002 * Copyright (c) 2011 Samsung Electronics Co., Ltd.
3 * http://www.samsung.com
4 *
5 * Common infrastructure for PWM Backlight for Samsung boards
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#include <linux/gpio.h>
13#include <linux/platform_device.h>
Paul Gortmaker3d46cce2011-07-31 18:16:56 -040014#include <linux/slab.h>
Banajit Goswamif00207b2011-07-20 23:44:21 +090015#include <linux/io.h>
16#include <linux/pwm_backlight.h>
Banajit Goswamif00207b2011-07-20 23:44:21 +090017
18#include <plat/devs.h>
19#include <plat/gpio-cfg.h>
Kukjin Kim4a7bf562015-07-30 02:00:36 +090020
21#include "backlight.h"
Banajit Goswamif00207b2011-07-20 23:44:21 +090022
Tomasz Figad1a8d3c2013-03-09 15:27:10 +010023struct samsung_bl_drvdata {
24 struct platform_pwm_backlight_data plat_data;
25 struct samsung_bl_gpio_info *gpio_info;
26};
27
Banajit Goswamif00207b2011-07-20 23:44:21 +090028static int samsung_bl_init(struct device *dev)
29{
30 int ret = 0;
Tomasz Figad1a8d3c2013-03-09 15:27:10 +010031 struct platform_pwm_backlight_data *pdata = dev->platform_data;
32 struct samsung_bl_drvdata *drvdata = container_of(pdata,
33 struct samsung_bl_drvdata, plat_data);
34 struct samsung_bl_gpio_info *bl_gpio_info = drvdata->gpio_info;
Banajit Goswamif00207b2011-07-20 23:44:21 +090035
36 ret = gpio_request(bl_gpio_info->no, "Backlight");
37 if (ret) {
38 printk(KERN_ERR "failed to request GPIO for LCD Backlight\n");
39 return ret;
40 }
41
42 /* Configure GPIO pin with specific GPIO function for PWM timer */
43 s3c_gpio_cfgpin(bl_gpio_info->no, bl_gpio_info->func);
44
45 return 0;
46}
47
48static void samsung_bl_exit(struct device *dev)
49{
Tomasz Figad1a8d3c2013-03-09 15:27:10 +010050 struct platform_pwm_backlight_data *pdata = dev->platform_data;
51 struct samsung_bl_drvdata *drvdata = container_of(pdata,
52 struct samsung_bl_drvdata, plat_data);
53 struct samsung_bl_gpio_info *bl_gpio_info = drvdata->gpio_info;
Banajit Goswamif00207b2011-07-20 23:44:21 +090054
55 s3c_gpio_cfgpin(bl_gpio_info->no, S3C_GPIO_OUTPUT);
56 gpio_free(bl_gpio_info->no);
57}
58
59/* Initialize few important fields of platform_pwm_backlight_data
60 * structure with default values. These fields can be overridden by
61 * board-specific values sent from machine file.
62 * For ease of operation, these fields are initialized with values
63 * used by most samsung boards.
64 * Users has the option of sending info about other parameters
65 * for their specific boards
66 */
67
Tomasz Figad1a8d3c2013-03-09 15:27:10 +010068static struct samsung_bl_drvdata samsung_dfl_bl_data __initdata = {
69 .plat_data = {
70 .max_brightness = 255,
71 .dft_brightness = 255,
Thierry Redinga63652f2013-08-30 12:19:52 +020072 .enable_gpio = -1,
Tomasz Figad1a8d3c2013-03-09 15:27:10 +010073 .init = samsung_bl_init,
74 .exit = samsung_bl_exit,
75 },
Banajit Goswamif00207b2011-07-20 23:44:21 +090076};
77
78static struct platform_device samsung_dfl_bl_device __initdata = {
79 .name = "pwm-backlight",
80};
81
82/* samsung_bl_set - Set board specific data (if any) provided by user for
83 * PWM Backlight control and register specific PWM and backlight device.
84 * @gpio_info: structure containing GPIO info for PWM timer
85 * @bl_data: structure containing Backlight control data
86 */
Tushar Behera4db17212012-03-09 08:03:13 -080087void __init samsung_bl_set(struct samsung_bl_gpio_info *gpio_info,
Banajit Goswamif00207b2011-07-20 23:44:21 +090088 struct platform_pwm_backlight_data *bl_data)
89{
90 int ret = 0;
91 struct platform_device *samsung_bl_device;
Tomasz Figad1a8d3c2013-03-09 15:27:10 +010092 struct samsung_bl_drvdata *samsung_bl_drvdata;
Banajit Goswamif00207b2011-07-20 23:44:21 +090093 struct platform_pwm_backlight_data *samsung_bl_data;
94
95 samsung_bl_device = kmemdup(&samsung_dfl_bl_device,
96 sizeof(struct platform_device), GFP_KERNEL);
97 if (!samsung_bl_device) {
98 printk(KERN_ERR "%s: no memory for platform dev\n", __func__);
99 return;
100 }
101
Tomasz Figad1a8d3c2013-03-09 15:27:10 +0100102 samsung_bl_drvdata = kmemdup(&samsung_dfl_bl_data,
103 sizeof(samsung_dfl_bl_data), GFP_KERNEL);
104 if (!samsung_bl_drvdata) {
Banajit Goswamif00207b2011-07-20 23:44:21 +0900105 printk(KERN_ERR "%s: no memory for platform dev\n", __func__);
106 goto err_data;
107 }
Tomasz Figad1a8d3c2013-03-09 15:27:10 +0100108 samsung_bl_device->dev.platform_data = &samsung_bl_drvdata->plat_data;
109 samsung_bl_drvdata->gpio_info = gpio_info;
110 samsung_bl_data = &samsung_bl_drvdata->plat_data;
Banajit Goswamif00207b2011-07-20 23:44:21 +0900111
112 /* Copy board specific data provided by user */
Tomasz Figad1a8d3c2013-03-09 15:27:10 +0100113 samsung_bl_device->dev.parent = &samsung_device_pwm.dev;
Banajit Goswamif00207b2011-07-20 23:44:21 +0900114
115 if (bl_data->max_brightness)
116 samsung_bl_data->max_brightness = bl_data->max_brightness;
117 if (bl_data->dft_brightness)
118 samsung_bl_data->dft_brightness = bl_data->dft_brightness;
119 if (bl_data->lth_brightness)
120 samsung_bl_data->lth_brightness = bl_data->lth_brightness;
Thierry Redinga63652f2013-08-30 12:19:52 +0200121 if (bl_data->enable_gpio >= 0)
122 samsung_bl_data->enable_gpio = bl_data->enable_gpio;
Banajit Goswamif00207b2011-07-20 23:44:21 +0900123 if (bl_data->init)
124 samsung_bl_data->init = bl_data->init;
125 if (bl_data->notify)
126 samsung_bl_data->notify = bl_data->notify;
Jingoo Han23747142011-12-26 20:29:31 +0900127 if (bl_data->notify_after)
128 samsung_bl_data->notify_after = bl_data->notify_after;
Banajit Goswamif00207b2011-07-20 23:44:21 +0900129 if (bl_data->exit)
130 samsung_bl_data->exit = bl_data->exit;
131 if (bl_data->check_fb)
132 samsung_bl_data->check_fb = bl_data->check_fb;
133
Banajit Goswamif00207b2011-07-20 23:44:21 +0900134 /* Register the Backlight dev */
135 ret = platform_device_register(samsung_bl_device);
136 if (ret) {
137 printk(KERN_ERR "failed to register backlight device: %d\n", ret);
138 goto err_plat_reg2;
139 }
140
141 return;
142
143err_plat_reg2:
Banajit Goswamif00207b2011-07-20 23:44:21 +0900144 kfree(samsung_bl_data);
145err_data:
146 kfree(samsung_bl_device);
147 return;
148}