2017-12-25 22:54:33 +03:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
//
|
|
|
|
// Copyright (c) 2011 Samsung Electronics Co., Ltd.
|
|
|
|
// http://www.samsung.com
|
|
|
|
//
|
|
|
|
// Common infrastructure for PWM Backlight for Samsung boards
|
2011-07-20 18:44:21 +04:00
|
|
|
|
|
|
|
#include <linux/gpio.h>
|
|
|
|
#include <linux/platform_device.h>
|
2011-08-01 02:16:56 +04:00
|
|
|
#include <linux/slab.h>
|
2011-07-20 18:44:21 +04:00
|
|
|
#include <linux/io.h>
|
|
|
|
#include <linux/pwm_backlight.h>
|
|
|
|
|
|
|
|
#include <plat/devs.h>
|
|
|
|
#include <plat/gpio-cfg.h>
|
2015-07-29 20:00:36 +03:00
|
|
|
|
|
|
|
#include "backlight.h"
|
2011-07-20 18:44:21 +04:00
|
|
|
|
2013-03-09 18:27:10 +04:00
|
|
|
struct samsung_bl_drvdata {
|
|
|
|
struct platform_pwm_backlight_data plat_data;
|
|
|
|
struct samsung_bl_gpio_info *gpio_info;
|
|
|
|
};
|
|
|
|
|
2011-07-20 18:44:21 +04:00
|
|
|
static int samsung_bl_init(struct device *dev)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
2013-03-09 18:27:10 +04:00
|
|
|
struct platform_pwm_backlight_data *pdata = dev->platform_data;
|
|
|
|
struct samsung_bl_drvdata *drvdata = container_of(pdata,
|
|
|
|
struct samsung_bl_drvdata, plat_data);
|
|
|
|
struct samsung_bl_gpio_info *bl_gpio_info = drvdata->gpio_info;
|
2011-07-20 18:44:21 +04:00
|
|
|
|
|
|
|
ret = gpio_request(bl_gpio_info->no, "Backlight");
|
|
|
|
if (ret) {
|
|
|
|
printk(KERN_ERR "failed to request GPIO for LCD Backlight\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Configure GPIO pin with specific GPIO function for PWM timer */
|
|
|
|
s3c_gpio_cfgpin(bl_gpio_info->no, bl_gpio_info->func);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void samsung_bl_exit(struct device *dev)
|
|
|
|
{
|
2013-03-09 18:27:10 +04:00
|
|
|
struct platform_pwm_backlight_data *pdata = dev->platform_data;
|
|
|
|
struct samsung_bl_drvdata *drvdata = container_of(pdata,
|
|
|
|
struct samsung_bl_drvdata, plat_data);
|
|
|
|
struct samsung_bl_gpio_info *bl_gpio_info = drvdata->gpio_info;
|
2011-07-20 18:44:21 +04:00
|
|
|
|
|
|
|
s3c_gpio_cfgpin(bl_gpio_info->no, S3C_GPIO_OUTPUT);
|
|
|
|
gpio_free(bl_gpio_info->no);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize few important fields of platform_pwm_backlight_data
|
|
|
|
* structure with default values. These fields can be overridden by
|
|
|
|
* board-specific values sent from machine file.
|
|
|
|
* For ease of operation, these fields are initialized with values
|
|
|
|
* used by most samsung boards.
|
|
|
|
* Users has the option of sending info about other parameters
|
|
|
|
* for their specific boards
|
|
|
|
*/
|
|
|
|
|
2013-03-09 18:27:10 +04:00
|
|
|
static struct samsung_bl_drvdata samsung_dfl_bl_data __initdata = {
|
|
|
|
.plat_data = {
|
|
|
|
.max_brightness = 255,
|
|
|
|
.dft_brightness = 255,
|
|
|
|
.init = samsung_bl_init,
|
|
|
|
.exit = samsung_bl_exit,
|
|
|
|
},
|
2011-07-20 18:44:21 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct platform_device samsung_dfl_bl_device __initdata = {
|
|
|
|
.name = "pwm-backlight",
|
|
|
|
};
|
|
|
|
|
|
|
|
/* samsung_bl_set - Set board specific data (if any) provided by user for
|
|
|
|
* PWM Backlight control and register specific PWM and backlight device.
|
|
|
|
* @gpio_info: structure containing GPIO info for PWM timer
|
|
|
|
* @bl_data: structure containing Backlight control data
|
|
|
|
*/
|
2012-03-09 20:03:13 +04:00
|
|
|
void __init samsung_bl_set(struct samsung_bl_gpio_info *gpio_info,
|
2011-07-20 18:44:21 +04:00
|
|
|
struct platform_pwm_backlight_data *bl_data)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
struct platform_device *samsung_bl_device;
|
2013-03-09 18:27:10 +04:00
|
|
|
struct samsung_bl_drvdata *samsung_bl_drvdata;
|
2011-07-20 18:44:21 +04:00
|
|
|
struct platform_pwm_backlight_data *samsung_bl_data;
|
|
|
|
|
|
|
|
samsung_bl_device = kmemdup(&samsung_dfl_bl_device,
|
|
|
|
sizeof(struct platform_device), GFP_KERNEL);
|
2017-10-02 23:20:39 +03:00
|
|
|
if (!samsung_bl_device)
|
2011-07-20 18:44:21 +04:00
|
|
|
return;
|
|
|
|
|
2013-03-09 18:27:10 +04:00
|
|
|
samsung_bl_drvdata = kmemdup(&samsung_dfl_bl_data,
|
|
|
|
sizeof(samsung_dfl_bl_data), GFP_KERNEL);
|
2017-10-02 23:20:39 +03:00
|
|
|
if (!samsung_bl_drvdata)
|
2011-07-20 18:44:21 +04:00
|
|
|
goto err_data;
|
2017-10-02 23:20:39 +03:00
|
|
|
|
2013-03-09 18:27:10 +04:00
|
|
|
samsung_bl_device->dev.platform_data = &samsung_bl_drvdata->plat_data;
|
|
|
|
samsung_bl_drvdata->gpio_info = gpio_info;
|
|
|
|
samsung_bl_data = &samsung_bl_drvdata->plat_data;
|
2011-07-20 18:44:21 +04:00
|
|
|
|
|
|
|
/* Copy board specific data provided by user */
|
2013-03-09 18:27:10 +04:00
|
|
|
samsung_bl_device->dev.parent = &samsung_device_pwm.dev;
|
2011-07-20 18:44:21 +04:00
|
|
|
|
|
|
|
if (bl_data->max_brightness)
|
|
|
|
samsung_bl_data->max_brightness = bl_data->max_brightness;
|
|
|
|
if (bl_data->dft_brightness)
|
|
|
|
samsung_bl_data->dft_brightness = bl_data->dft_brightness;
|
|
|
|
if (bl_data->lth_brightness)
|
|
|
|
samsung_bl_data->lth_brightness = bl_data->lth_brightness;
|
|
|
|
if (bl_data->init)
|
|
|
|
samsung_bl_data->init = bl_data->init;
|
|
|
|
if (bl_data->notify)
|
|
|
|
samsung_bl_data->notify = bl_data->notify;
|
2011-12-26 15:29:31 +04:00
|
|
|
if (bl_data->notify_after)
|
|
|
|
samsung_bl_data->notify_after = bl_data->notify_after;
|
2011-07-20 18:44:21 +04:00
|
|
|
if (bl_data->exit)
|
|
|
|
samsung_bl_data->exit = bl_data->exit;
|
|
|
|
if (bl_data->check_fb)
|
|
|
|
samsung_bl_data->check_fb = bl_data->check_fb;
|
|
|
|
|
|
|
|
/* Register the Backlight dev */
|
|
|
|
ret = platform_device_register(samsung_bl_device);
|
|
|
|
if (ret) {
|
|
|
|
printk(KERN_ERR "failed to register backlight device: %d\n", ret);
|
|
|
|
goto err_plat_reg2;
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
err_plat_reg2:
|
|
|
|
kfree(samsung_bl_data);
|
|
|
|
err_data:
|
|
|
|
kfree(samsung_bl_device);
|
|
|
|
}
|