2010-01-06 15:10:09 -07:00
|
|
|
/*
|
|
|
|
* LED driver for Marvell 88PM860x
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 Marvell International Ltd.
|
|
|
|
* Haojian Zhuang <haojian.zhuang@marvell.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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
2012-09-21 04:06:52 -06:00
|
|
|
#include <linux/of.h>
|
2010-01-06 15:10:09 -07:00
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/i2c.h>
|
|
|
|
#include <linux/leds.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 02:04:11 -06:00
|
|
|
#include <linux/slab.h>
|
2010-01-06 15:10:09 -07:00
|
|
|
#include <linux/workqueue.h>
|
|
|
|
#include <linux/mfd/88pm860x.h>
|
2011-07-03 11:56:03 -06:00
|
|
|
#include <linux/module.h>
|
2010-01-06 15:10:09 -07:00
|
|
|
|
|
|
|
#define LED_PWM_MASK (0x1F)
|
|
|
|
#define LED_CURRENT_MASK (0x07 << 5)
|
|
|
|
|
|
|
|
#define LED_BLINK_MASK (0x7F)
|
|
|
|
|
2010-09-08 07:44:33 -06:00
|
|
|
#define LED_ON_CONTINUOUS (0x0F << 3)
|
2010-01-06 15:10:09 -07:00
|
|
|
|
|
|
|
#define LED1_BLINK_EN (1 << 1)
|
|
|
|
#define LED2_BLINK_EN (1 << 2)
|
|
|
|
|
|
|
|
struct pm860x_led {
|
|
|
|
struct led_classdev cdev;
|
|
|
|
struct i2c_client *i2c;
|
|
|
|
struct work_struct work;
|
|
|
|
struct pm860x_chip *chip;
|
|
|
|
struct mutex lock;
|
|
|
|
char name[MFD_NAME_SIZE];
|
|
|
|
|
|
|
|
int port;
|
|
|
|
int iset;
|
|
|
|
unsigned char brightness;
|
|
|
|
unsigned char current_brightness;
|
|
|
|
|
2012-08-08 09:17:27 -06:00
|
|
|
int reg_control;
|
|
|
|
int reg_blink;
|
|
|
|
int blink_mask;
|
2010-01-06 15:10:09 -07:00
|
|
|
};
|
|
|
|
|
2012-02-27 19:59:29 -07:00
|
|
|
static int led_power_set(struct pm860x_chip *chip, int port, int on)
|
|
|
|
{
|
|
|
|
int ret = -EINVAL;
|
|
|
|
|
|
|
|
switch (port) {
|
2012-08-08 09:17:27 -06:00
|
|
|
case 0:
|
|
|
|
case 1:
|
|
|
|
case 2:
|
2012-02-27 19:59:29 -07:00
|
|
|
ret = on ? pm8606_osc_enable(chip, RGB1_ENABLE) :
|
|
|
|
pm8606_osc_disable(chip, RGB1_ENABLE);
|
|
|
|
break;
|
2012-08-08 09:17:27 -06:00
|
|
|
case 3:
|
|
|
|
case 4:
|
|
|
|
case 5:
|
2012-02-27 19:59:29 -07:00
|
|
|
ret = on ? pm8606_osc_enable(chip, RGB2_ENABLE) :
|
|
|
|
pm8606_osc_disable(chip, RGB2_ENABLE);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-09-08 07:44:33 -06:00
|
|
|
static void pm860x_led_work(struct work_struct *work)
|
2010-01-06 15:10:09 -07:00
|
|
|
{
|
|
|
|
|
2010-09-08 07:44:33 -06:00
|
|
|
struct pm860x_led *led;
|
|
|
|
struct pm860x_chip *chip;
|
2011-03-07 08:43:10 -07:00
|
|
|
unsigned char buf[3];
|
2012-08-08 09:17:27 -06:00
|
|
|
int ret;
|
2010-09-08 07:44:33 -06:00
|
|
|
|
|
|
|
led = container_of(work, struct pm860x_led, work);
|
|
|
|
chip = led->chip;
|
2010-01-06 15:10:09 -07:00
|
|
|
mutex_lock(&led->lock);
|
2010-09-08 07:44:33 -06:00
|
|
|
if ((led->current_brightness == 0) && led->brightness) {
|
2012-02-27 19:59:29 -07:00
|
|
|
led_power_set(chip, led->port, 1);
|
2010-09-08 07:44:33 -06:00
|
|
|
if (led->iset) {
|
2012-08-08 09:17:27 -06:00
|
|
|
pm860x_set_bits(led->i2c, led->reg_control,
|
2010-09-08 07:44:33 -06:00
|
|
|
LED_CURRENT_MASK, led->iset);
|
2010-01-06 15:10:09 -07:00
|
|
|
}
|
2012-08-08 09:17:27 -06:00
|
|
|
pm860x_set_bits(led->i2c, led->reg_blink,
|
2011-03-07 08:43:10 -07:00
|
|
|
LED_BLINK_MASK, LED_ON_CONTINUOUS);
|
2012-08-08 09:17:27 -06:00
|
|
|
pm860x_set_bits(led->i2c, PM8606_WLED3B, led->blink_mask,
|
|
|
|
led->blink_mask);
|
2010-01-06 15:10:09 -07:00
|
|
|
}
|
2012-08-08 09:17:27 -06:00
|
|
|
pm860x_set_bits(led->i2c, led->reg_control, LED_PWM_MASK,
|
2010-09-08 07:44:33 -06:00
|
|
|
led->brightness);
|
2011-03-07 08:43:10 -07:00
|
|
|
|
|
|
|
if (led->brightness == 0) {
|
2012-08-08 09:17:27 -06:00
|
|
|
pm860x_bulk_read(led->i2c, led->reg_control, 3, buf);
|
2011-03-07 08:43:10 -07:00
|
|
|
ret = buf[0] & LED_PWM_MASK;
|
|
|
|
ret |= buf[1] & LED_PWM_MASK;
|
|
|
|
ret |= buf[2] & LED_PWM_MASK;
|
|
|
|
if (ret == 0) {
|
|
|
|
/* unset current since no led is lighting */
|
2012-08-08 09:17:27 -06:00
|
|
|
pm860x_set_bits(led->i2c, led->reg_control,
|
2011-03-07 08:43:10 -07:00
|
|
|
LED_CURRENT_MASK, 0);
|
2012-08-08 09:17:27 -06:00
|
|
|
pm860x_set_bits(led->i2c, PM8606_WLED3B,
|
|
|
|
led->blink_mask, 0);
|
2012-02-27 19:59:29 -07:00
|
|
|
led_power_set(chip, led->port, 0);
|
2011-03-07 08:43:10 -07:00
|
|
|
}
|
|
|
|
}
|
2010-09-08 07:44:33 -06:00
|
|
|
led->current_brightness = led->brightness;
|
|
|
|
dev_dbg(chip->dev, "Update LED. (reg:%d, brightness:%d)\n",
|
2012-08-08 09:17:27 -06:00
|
|
|
led->reg_control, led->brightness);
|
2010-01-06 15:10:09 -07:00
|
|
|
mutex_unlock(&led->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pm860x_led_set(struct led_classdev *cdev,
|
|
|
|
enum led_brightness value)
|
|
|
|
{
|
|
|
|
struct pm860x_led *data = container_of(cdev, struct pm860x_led, cdev);
|
|
|
|
|
|
|
|
data->brightness = value >> 3;
|
|
|
|
schedule_work(&data->work);
|
|
|
|
}
|
|
|
|
|
2012-09-21 04:06:52 -06:00
|
|
|
#ifdef CONFIG_OF
|
|
|
|
static int pm860x_led_dt_init(struct platform_device *pdev,
|
|
|
|
struct pm860x_led *data)
|
|
|
|
{
|
2013-01-27 05:56:57 -07:00
|
|
|
struct device_node *nproot, *np;
|
2012-09-21 04:06:52 -06:00
|
|
|
int iset = 0;
|
2013-01-27 05:56:57 -07:00
|
|
|
|
|
|
|
nproot = of_node_get(pdev->dev.parent->of_node);
|
2012-09-21 04:06:52 -06:00
|
|
|
if (!nproot)
|
|
|
|
return -ENODEV;
|
2014-04-04 01:51:19 -06:00
|
|
|
nproot = of_get_child_by_name(nproot, "leds");
|
2012-09-21 04:06:52 -06:00
|
|
|
if (!nproot) {
|
|
|
|
dev_err(&pdev->dev, "failed to find leds node\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
for_each_child_of_node(nproot, np) {
|
|
|
|
if (!of_node_cmp(np->name, data->name)) {
|
|
|
|
of_property_read_u32(np, "marvell,88pm860x-iset",
|
|
|
|
&iset);
|
|
|
|
data->iset = PM8606_LED_CURRENT(iset);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-01-27 05:56:57 -07:00
|
|
|
of_node_put(nproot);
|
2012-09-21 04:06:52 -06:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define pm860x_led_dt_init(x, y) (-1)
|
|
|
|
#endif
|
|
|
|
|
2010-01-06 15:10:09 -07:00
|
|
|
static int pm860x_led_probe(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
struct pm860x_chip *chip = dev_get_drvdata(pdev->dev.parent);
|
2013-07-30 02:07:35 -06:00
|
|
|
struct pm860x_led_pdata *pdata = dev_get_platdata(&pdev->dev);
|
2010-01-06 15:10:09 -07:00
|
|
|
struct pm860x_led *data;
|
|
|
|
struct resource *res;
|
2012-08-08 09:17:27 -06:00
|
|
|
int ret = 0;
|
2010-01-06 15:10:09 -07:00
|
|
|
|
2012-07-02 04:15:43 -06:00
|
|
|
data = devm_kzalloc(&pdev->dev, sizeof(struct pm860x_led), GFP_KERNEL);
|
2010-01-06 15:10:09 -07:00
|
|
|
if (data == NULL)
|
|
|
|
return -ENOMEM;
|
2012-08-08 09:17:27 -06:00
|
|
|
res = platform_get_resource_byname(pdev, IORESOURCE_REG, "control");
|
|
|
|
if (!res) {
|
|
|
|
dev_err(&pdev->dev, "No REG resource for control\n");
|
2012-10-28 22:31:07 -06:00
|
|
|
return -ENXIO;
|
2012-08-08 09:17:27 -06:00
|
|
|
}
|
|
|
|
data->reg_control = res->start;
|
|
|
|
res = platform_get_resource_byname(pdev, IORESOURCE_REG, "blink");
|
|
|
|
if (!res) {
|
|
|
|
dev_err(&pdev->dev, "No REG resource for blink\n");
|
2012-10-28 22:31:07 -06:00
|
|
|
return -ENXIO;
|
2012-08-08 09:17:27 -06:00
|
|
|
}
|
|
|
|
data->reg_blink = res->start;
|
|
|
|
memset(data->name, 0, MFD_NAME_SIZE);
|
|
|
|
switch (pdev->id) {
|
|
|
|
case 0:
|
|
|
|
data->blink_mask = LED1_BLINK_EN;
|
|
|
|
sprintf(data->name, "led0-red");
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
data->blink_mask = LED1_BLINK_EN;
|
|
|
|
sprintf(data->name, "led0-green");
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
data->blink_mask = LED1_BLINK_EN;
|
|
|
|
sprintf(data->name, "led0-blue");
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
data->blink_mask = LED2_BLINK_EN;
|
|
|
|
sprintf(data->name, "led1-red");
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
data->blink_mask = LED2_BLINK_EN;
|
|
|
|
sprintf(data->name, "led1-green");
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
data->blink_mask = LED2_BLINK_EN;
|
|
|
|
sprintf(data->name, "led1-blue");
|
|
|
|
break;
|
|
|
|
}
|
2013-05-23 04:28:33 -06:00
|
|
|
platform_set_drvdata(pdev, data);
|
2010-01-06 15:10:09 -07:00
|
|
|
data->chip = chip;
|
|
|
|
data->i2c = (chip->id == CHIP_PM8606) ? chip->client : chip->companion;
|
2012-08-08 09:17:27 -06:00
|
|
|
data->port = pdev->id;
|
2012-09-21 04:06:52 -06:00
|
|
|
if (pm860x_led_dt_init(pdev, data))
|
|
|
|
if (pdata)
|
|
|
|
data->iset = pdata->iset;
|
2010-01-06 15:10:09 -07:00
|
|
|
|
|
|
|
data->current_brightness = 0;
|
|
|
|
data->cdev.name = data->name;
|
|
|
|
data->cdev.brightness_set = pm860x_led_set;
|
|
|
|
mutex_init(&data->lock);
|
|
|
|
INIT_WORK(&data->work, pm860x_led_work);
|
|
|
|
|
|
|
|
ret = led_classdev_register(chip->dev, &data->cdev);
|
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(&pdev->dev, "Failed to register LED: %d\n", ret);
|
2012-07-02 04:15:43 -06:00
|
|
|
return ret;
|
2010-01-06 15:10:09 -07:00
|
|
|
}
|
2011-03-07 08:43:10 -07:00
|
|
|
pm860x_led_set(&data->cdev, 0);
|
2010-01-06 15:10:09 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pm860x_led_remove(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
struct pm860x_led *data = platform_get_drvdata(pdev);
|
|
|
|
|
|
|
|
led_classdev_unregister(&data->cdev);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct platform_driver pm860x_led_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "88pm860x-led",
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
},
|
|
|
|
.probe = pm860x_led_probe,
|
|
|
|
.remove = pm860x_led_remove,
|
|
|
|
};
|
|
|
|
|
2012-01-10 16:09:24 -07:00
|
|
|
module_platform_driver(pm860x_led_driver);
|
2010-01-06 15:10:09 -07:00
|
|
|
|
|
|
|
MODULE_DESCRIPTION("LED driver for Marvell PM860x");
|
|
|
|
MODULE_AUTHOR("Haojian Zhuang <haojian.zhuang@marvell.com>");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_ALIAS("platform:88pm860x-led");
|