Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 //
0003 // Copyright (c) 2011 Samsung Electronics Co., Ltd.
0004 //              http://www.samsung.com
0005 //
0006 // Common infrastructure for PWM Backlight for Samsung boards
0007 
0008 #include <linux/gpio.h>
0009 #include <linux/platform_device.h>
0010 #include <linux/slab.h>
0011 #include <linux/io.h>
0012 #include <linux/pwm_backlight.h>
0013 
0014 #include "devs.h"
0015 #include "gpio-cfg.h"
0016 
0017 #include "backlight-s3c64xx.h"
0018 
0019 struct samsung_bl_drvdata {
0020     struct platform_pwm_backlight_data plat_data;
0021     struct samsung_bl_gpio_info *gpio_info;
0022 };
0023 
0024 static int samsung_bl_init(struct device *dev)
0025 {
0026     int ret = 0;
0027     struct platform_pwm_backlight_data *pdata = dev->platform_data;
0028     struct samsung_bl_drvdata *drvdata = container_of(pdata,
0029                     struct samsung_bl_drvdata, plat_data);
0030     struct samsung_bl_gpio_info *bl_gpio_info = drvdata->gpio_info;
0031 
0032     ret = gpio_request(bl_gpio_info->no, "Backlight");
0033     if (ret) {
0034         printk(KERN_ERR "failed to request GPIO for LCD Backlight\n");
0035         return ret;
0036     }
0037 
0038     /* Configure GPIO pin with specific GPIO function for PWM timer */
0039     s3c_gpio_cfgpin(bl_gpio_info->no, bl_gpio_info->func);
0040 
0041     return 0;
0042 }
0043 
0044 static void samsung_bl_exit(struct device *dev)
0045 {
0046     struct platform_pwm_backlight_data *pdata = dev->platform_data;
0047     struct samsung_bl_drvdata *drvdata = container_of(pdata,
0048                     struct samsung_bl_drvdata, plat_data);
0049     struct samsung_bl_gpio_info *bl_gpio_info = drvdata->gpio_info;
0050 
0051     s3c_gpio_cfgpin(bl_gpio_info->no, S3C_GPIO_OUTPUT);
0052     gpio_free(bl_gpio_info->no);
0053 }
0054 
0055 /* Initialize few important fields of platform_pwm_backlight_data
0056  * structure with default values. These fields can be overridden by
0057  * board-specific values sent from machine file.
0058  * For ease of operation, these fields are initialized with values
0059  * used by most samsung boards.
0060  * Users has the option of sending info about other parameters
0061  * for their specific boards
0062  */
0063 
0064 static struct samsung_bl_drvdata samsung_dfl_bl_data __initdata = {
0065     .plat_data = {
0066         .max_brightness = 255,
0067         .dft_brightness = 255,
0068         .init           = samsung_bl_init,
0069         .exit           = samsung_bl_exit,
0070     },
0071 };
0072 
0073 static struct platform_device samsung_dfl_bl_device __initdata = {
0074     .name       = "pwm-backlight",
0075 };
0076 
0077 /* samsung_bl_set - Set board specific data (if any) provided by user for
0078  * PWM Backlight control and register specific PWM and backlight device.
0079  * @gpio_info:  structure containing GPIO info for PWM timer
0080  * @bl_data:    structure containing Backlight control data
0081  */
0082 void __init samsung_bl_set(struct samsung_bl_gpio_info *gpio_info,
0083     struct platform_pwm_backlight_data *bl_data)
0084 {
0085     int ret = 0;
0086     struct platform_device *samsung_bl_device;
0087     struct samsung_bl_drvdata *samsung_bl_drvdata;
0088     struct platform_pwm_backlight_data *samsung_bl_data;
0089 
0090     samsung_bl_device = kmemdup(&samsung_dfl_bl_device,
0091             sizeof(struct platform_device), GFP_KERNEL);
0092     if (!samsung_bl_device)
0093         return;
0094 
0095     samsung_bl_drvdata = kmemdup(&samsung_dfl_bl_data,
0096                 sizeof(samsung_dfl_bl_data), GFP_KERNEL);
0097     if (!samsung_bl_drvdata)
0098         goto err_data;
0099 
0100     samsung_bl_device->dev.platform_data = &samsung_bl_drvdata->plat_data;
0101     samsung_bl_drvdata->gpio_info = gpio_info;
0102     samsung_bl_data = &samsung_bl_drvdata->plat_data;
0103 
0104     /* Copy board specific data provided by user */
0105     samsung_bl_device->dev.parent = &samsung_device_pwm.dev;
0106 
0107     if (bl_data->max_brightness)
0108         samsung_bl_data->max_brightness = bl_data->max_brightness;
0109     if (bl_data->dft_brightness)
0110         samsung_bl_data->dft_brightness = bl_data->dft_brightness;
0111     if (bl_data->lth_brightness)
0112         samsung_bl_data->lth_brightness = bl_data->lth_brightness;
0113     if (bl_data->init)
0114         samsung_bl_data->init = bl_data->init;
0115     if (bl_data->notify)
0116         samsung_bl_data->notify = bl_data->notify;
0117     if (bl_data->notify_after)
0118         samsung_bl_data->notify_after = bl_data->notify_after;
0119     if (bl_data->exit)
0120         samsung_bl_data->exit = bl_data->exit;
0121     if (bl_data->check_fb)
0122         samsung_bl_data->check_fb = bl_data->check_fb;
0123 
0124     /* Register the Backlight dev */
0125     ret = platform_device_register(samsung_bl_device);
0126     if (ret) {
0127         printk(KERN_ERR "failed to register backlight device: %d\n", ret);
0128         goto err_plat_reg2;
0129     }
0130 
0131     return;
0132 
0133 err_plat_reg2:
0134     kfree(samsung_bl_data);
0135 err_data:
0136     kfree(samsung_bl_device);
0137 }