Banajit Goswami | f00207b | 2011-07-20 23:44:21 +0900 | [diff] [blame] | 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> |
Paul Gortmaker | 3d46cce | 2011-07-31 18:16:56 -0400 | [diff] [blame] | 15 | #include <linux/slab.h> |
Banajit Goswami | f00207b | 2011-07-20 23:44:21 +0900 | [diff] [blame] | 16 | #include <linux/io.h> |
| 17 | #include <linux/pwm_backlight.h> |
Banajit Goswami | f00207b | 2011-07-20 23:44:21 +0900 | [diff] [blame] | 18 | |
| 19 | #include <plat/devs.h> |
| 20 | #include <plat/gpio-cfg.h> |
| 21 | #include <plat/backlight.h> |
| 22 | |
Tomasz Figa | d1a8d3c | 2013-03-09 15:27:10 +0100 | [diff] [blame] | 23 | struct samsung_bl_drvdata { |
| 24 | struct platform_pwm_backlight_data plat_data; |
| 25 | struct samsung_bl_gpio_info *gpio_info; |
| 26 | }; |
| 27 | |
Banajit Goswami | f00207b | 2011-07-20 23:44:21 +0900 | [diff] [blame] | 28 | static int samsung_bl_init(struct device *dev) |
| 29 | { |
| 30 | int ret = 0; |
Tomasz Figa | d1a8d3c | 2013-03-09 15:27:10 +0100 | [diff] [blame] | 31 | 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 Goswami | f00207b | 2011-07-20 23:44:21 +0900 | [diff] [blame] | 35 | |
| 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 | |
| 48 | static void samsung_bl_exit(struct device *dev) |
| 49 | { |
Tomasz Figa | d1a8d3c | 2013-03-09 15:27:10 +0100 | [diff] [blame] | 50 | 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 Goswami | f00207b | 2011-07-20 23:44:21 +0900 | [diff] [blame] | 54 | |
| 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 Figa | d1a8d3c | 2013-03-09 15:27:10 +0100 | [diff] [blame] | 68 | static struct samsung_bl_drvdata samsung_dfl_bl_data __initdata = { |
| 69 | .plat_data = { |
| 70 | .max_brightness = 255, |
| 71 | .dft_brightness = 255, |
| 72 | .pwm_period_ns = 78770, |
Thierry Reding | a63652f | 2013-08-30 12:19:52 +0200 | [diff] [blame] | 73 | .enable_gpio = -1, |
Tomasz Figa | d1a8d3c | 2013-03-09 15:27:10 +0100 | [diff] [blame] | 74 | .init = samsung_bl_init, |
| 75 | .exit = samsung_bl_exit, |
| 76 | }, |
Banajit Goswami | f00207b | 2011-07-20 23:44:21 +0900 | [diff] [blame] | 77 | }; |
| 78 | |
| 79 | static struct platform_device samsung_dfl_bl_device __initdata = { |
| 80 | .name = "pwm-backlight", |
| 81 | }; |
| 82 | |
| 83 | /* samsung_bl_set - Set board specific data (if any) provided by user for |
| 84 | * PWM Backlight control and register specific PWM and backlight device. |
| 85 | * @gpio_info: structure containing GPIO info for PWM timer |
| 86 | * @bl_data: structure containing Backlight control data |
| 87 | */ |
Tushar Behera | 4db1721 | 2012-03-09 08:03:13 -0800 | [diff] [blame] | 88 | void __init samsung_bl_set(struct samsung_bl_gpio_info *gpio_info, |
Banajit Goswami | f00207b | 2011-07-20 23:44:21 +0900 | [diff] [blame] | 89 | struct platform_pwm_backlight_data *bl_data) |
| 90 | { |
| 91 | int ret = 0; |
| 92 | struct platform_device *samsung_bl_device; |
Tomasz Figa | d1a8d3c | 2013-03-09 15:27:10 +0100 | [diff] [blame] | 93 | struct samsung_bl_drvdata *samsung_bl_drvdata; |
Banajit Goswami | f00207b | 2011-07-20 23:44:21 +0900 | [diff] [blame] | 94 | struct platform_pwm_backlight_data *samsung_bl_data; |
| 95 | |
| 96 | samsung_bl_device = kmemdup(&samsung_dfl_bl_device, |
| 97 | sizeof(struct platform_device), GFP_KERNEL); |
| 98 | if (!samsung_bl_device) { |
| 99 | printk(KERN_ERR "%s: no memory for platform dev\n", __func__); |
| 100 | return; |
| 101 | } |
| 102 | |
Tomasz Figa | d1a8d3c | 2013-03-09 15:27:10 +0100 | [diff] [blame] | 103 | samsung_bl_drvdata = kmemdup(&samsung_dfl_bl_data, |
| 104 | sizeof(samsung_dfl_bl_data), GFP_KERNEL); |
| 105 | if (!samsung_bl_drvdata) { |
Banajit Goswami | f00207b | 2011-07-20 23:44:21 +0900 | [diff] [blame] | 106 | printk(KERN_ERR "%s: no memory for platform dev\n", __func__); |
| 107 | goto err_data; |
| 108 | } |
Tomasz Figa | d1a8d3c | 2013-03-09 15:27:10 +0100 | [diff] [blame] | 109 | samsung_bl_device->dev.platform_data = &samsung_bl_drvdata->plat_data; |
| 110 | samsung_bl_drvdata->gpio_info = gpio_info; |
| 111 | samsung_bl_data = &samsung_bl_drvdata->plat_data; |
Banajit Goswami | f00207b | 2011-07-20 23:44:21 +0900 | [diff] [blame] | 112 | |
| 113 | /* Copy board specific data provided by user */ |
| 114 | samsung_bl_data->pwm_id = bl_data->pwm_id; |
Tomasz Figa | d1a8d3c | 2013-03-09 15:27:10 +0100 | [diff] [blame] | 115 | samsung_bl_device->dev.parent = &samsung_device_pwm.dev; |
Banajit Goswami | f00207b | 2011-07-20 23:44:21 +0900 | [diff] [blame] | 116 | |
| 117 | if (bl_data->max_brightness) |
| 118 | samsung_bl_data->max_brightness = bl_data->max_brightness; |
| 119 | if (bl_data->dft_brightness) |
| 120 | samsung_bl_data->dft_brightness = bl_data->dft_brightness; |
| 121 | if (bl_data->lth_brightness) |
| 122 | samsung_bl_data->lth_brightness = bl_data->lth_brightness; |
| 123 | if (bl_data->pwm_period_ns) |
| 124 | samsung_bl_data->pwm_period_ns = bl_data->pwm_period_ns; |
Thierry Reding | a63652f | 2013-08-30 12:19:52 +0200 | [diff] [blame] | 125 | if (bl_data->enable_gpio >= 0) |
| 126 | samsung_bl_data->enable_gpio = bl_data->enable_gpio; |
Banajit Goswami | f00207b | 2011-07-20 23:44:21 +0900 | [diff] [blame] | 127 | if (bl_data->init) |
| 128 | samsung_bl_data->init = bl_data->init; |
| 129 | if (bl_data->notify) |
| 130 | samsung_bl_data->notify = bl_data->notify; |
Jingoo Han | 2374714 | 2011-12-26 20:29:31 +0900 | [diff] [blame] | 131 | if (bl_data->notify_after) |
| 132 | samsung_bl_data->notify_after = bl_data->notify_after; |
Banajit Goswami | f00207b | 2011-07-20 23:44:21 +0900 | [diff] [blame] | 133 | if (bl_data->exit) |
| 134 | samsung_bl_data->exit = bl_data->exit; |
| 135 | if (bl_data->check_fb) |
| 136 | samsung_bl_data->check_fb = bl_data->check_fb; |
| 137 | |
Banajit Goswami | f00207b | 2011-07-20 23:44:21 +0900 | [diff] [blame] | 138 | /* Register the Backlight dev */ |
| 139 | ret = platform_device_register(samsung_bl_device); |
| 140 | if (ret) { |
| 141 | printk(KERN_ERR "failed to register backlight device: %d\n", ret); |
| 142 | goto err_plat_reg2; |
| 143 | } |
| 144 | |
| 145 | return; |
| 146 | |
| 147 | err_plat_reg2: |
Banajit Goswami | f00207b | 2011-07-20 23:44:21 +0900 | [diff] [blame] | 148 | kfree(samsung_bl_data); |
| 149 | err_data: |
| 150 | kfree(samsung_bl_device); |
| 151 | return; |
| 152 | } |