1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
/*
* Phoenix Keypad LED Driver for the OMAP4430 SDP
*
* Copyright (C) 2010 Texas Instruments
*
* Author: Dan Murphy <DMurphy@ti.com>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <linux/gpio.h>
#include <linux/leds.h>
#include <linux/platform_device.h>
#include <linux/slab.h>
#include <linux/i2c/twl.h>
struct keypad_led_data {
struct led_classdev keypad_led_class_dev;
};
#define KP_LED_PWM1ON 0x00
#define KP_LED_PWM1OFF 0x01
#define KP_LED_TOGGLE3 0x92
static void omap4430_keypad_led_store(struct led_classdev *led_cdev,
enum led_brightness value)
{
u8 brightness = 0;
if (value > 1) {
if (value == LED_FULL)
brightness = 0x7f;
else
brightness = (~(value/2)) & 0x7f;
twl_i2c_write_u8(TWL_MODULE_PWM, brightness, KP_LED_PWM1ON);
twl_i2c_write_u8(TWL6030_MODULE_ID1, 0x36, KP_LED_TOGGLE3);
} else {
twl_i2c_write_u8(TWL6030_MODULE_ID1, 0x31, KP_LED_TOGGLE3);
twl_i2c_write_u8(TWL6030_MODULE_ID1, 0x37, KP_LED_TOGGLE3);
}
}
static int omap4430_keypad_led_probe(struct platform_device *pdev)
{
int ret;
struct keypad_led_data *info;
pr_info("%s:Enter\n", __func__);
info = kzalloc(sizeof(struct keypad_led_data), GFP_KERNEL);
if (info == NULL) {
ret = -ENOMEM;
return ret;
}
platform_set_drvdata(pdev, info);
info->keypad_led_class_dev.name = "keyboard-backlight";
info->keypad_led_class_dev.brightness_set =
omap4430_keypad_led_store;
info->keypad_led_class_dev.max_brightness = LED_FULL;
ret = led_classdev_register(&pdev->dev,
&info->keypad_led_class_dev);
if (ret < 0) {
pr_err("%s: Register led class failed\n", __func__);
kfree(info);
return ret;
}
/*TO DO pass in these values from the board file */
twl_i2c_write_u8(TWL_MODULE_PWM, 0xFF, KP_LED_PWM1ON);
twl_i2c_write_u8(TWL_MODULE_PWM, 0x7f, KP_LED_PWM1OFF);
twl_i2c_write_u8(TWL6030_MODULE_ID1, 0x06, KP_LED_TOGGLE3);
pr_info("%s:Exit\n", __func__);
return ret;
}
static int omap4430_keypad_led_remove(struct platform_device *pdev)
{
struct keypad_led_data *info = platform_get_drvdata(pdev);
led_classdev_unregister(&info->keypad_led_class_dev);
return 0;
}
static struct platform_driver omap4430_keypad_led_driver = {
.probe = omap4430_keypad_led_probe,
.remove = omap4430_keypad_led_remove,
.driver = {
.name = "keypad_led",
.owner = THIS_MODULE,
},
};
static int __init omap4430_keypad_led_init(void)
{
return platform_driver_register(&omap4430_keypad_led_driver);
}
static void __exit omap4430_keypad_led_exit(void)
{
platform_driver_unregister(&omap4430_keypad_led_driver);
}
module_init(omap4430_keypad_led_init);
module_exit(omap4430_keypad_led_exit);
MODULE_DESCRIPTION("OMAP4430 SDP Keypad Lighting driver");
MODULE_AUTHOR("Dan Murphy <dmurphy@ti.com");
MODULE_LICENSE("GPL");
|