mirror of
https://github.com/followmsi/android_kernel_google_msm.git
synced 2024-11-06 23:17:41 +00:00
leds: leds-pmic-mpp: Add support for MPP connected LED
Add support for LEDs which are connected to PMIC MPPs. Change-Id: Ib53510dbcb745e92e2100c1afc6dc2d94938fc85 CRs-fixed: 354967 Signed-off-by: Mohan Pallaka <mpallaka@codeaurora.org>
This commit is contained in:
parent
406324fb62
commit
425bca22ad
3 changed files with 154 additions and 0 deletions
|
@ -169,6 +169,18 @@ config LEDS_MSM_PDM
|
|||
To compile this driver as a module, choose M here: the
|
||||
module will be called leds-msm-pdm.
|
||||
|
||||
config LEDS_PMIC_MPP
|
||||
tristate "LED Support for Qualcomm PMIC MPP connected LEDs"
|
||||
depends on LEDS_CLASS && MSM_SMD
|
||||
help
|
||||
This option enables support for LEDs connected to PMIC MPPs
|
||||
on Qualcomm reference boards.
|
||||
|
||||
If unsure, say N.
|
||||
|
||||
To compile this driver as a module, choose M here: the
|
||||
module will be called leds-pmic-mpp.
|
||||
|
||||
config LEDS_LP3944
|
||||
tristate "LED Support for N.S. LP3944 (Fun Light) I2C chip"
|
||||
depends on LEDS_CLASS
|
||||
|
|
|
@ -48,6 +48,7 @@ obj-$(CONFIG_LEDS_NETXBIG) += leds-netxbig.o
|
|||
obj-$(CONFIG_LEDS_ASIC3) += leds-asic3.o
|
||||
obj-$(CONFIG_LEDS_RENESAS_TPU) += leds-renesas-tpu.o
|
||||
obj-$(CONFIG_LEDS_MAX8997) += leds-max8997.o
|
||||
obj-$(CONFIG_LEDS_PMIC_MPP) += leds-pmic-mpp.o
|
||||
obj-$(CONFIG_LEDS_MSM_PDM) += leds-msm-pdm.o
|
||||
|
||||
# LED SPI Drivers
|
||||
|
|
141
drivers/leds/leds-pmic-mpp.c
Normal file
141
drivers/leds/leds-pmic-mpp.c
Normal file
|
@ -0,0 +1,141 @@
|
|||
/* Copyright (c) 2012, Code Aurora Forum. All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 and
|
||||
* only 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.
|
||||
*/
|
||||
|
||||
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/leds.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/module.h>
|
||||
|
||||
#include <mach/pmic.h>
|
||||
|
||||
#define LED_MPP(x) ((x) & 0xFF)
|
||||
#define LED_CURR(x) ((x) >> 16)
|
||||
|
||||
struct pmic_mpp_led_data {
|
||||
struct led_classdev cdev;
|
||||
int curr;
|
||||
int mpp;
|
||||
};
|
||||
|
||||
static void pm_mpp_led_set(struct led_classdev *led_cdev,
|
||||
enum led_brightness value)
|
||||
{
|
||||
struct pmic_mpp_led_data *led;
|
||||
int ret;
|
||||
|
||||
led = container_of(led_cdev, struct pmic_mpp_led_data, cdev);
|
||||
|
||||
if (value < LED_OFF || value > led->cdev.max_brightness) {
|
||||
dev_err(led->cdev.dev, "Invalid brightness value");
|
||||
return;
|
||||
}
|
||||
|
||||
ret = pmic_secure_mpp_config_i_sink(led->mpp, led->curr,
|
||||
value ? PM_MPP__I_SINK__SWITCH_ENA :
|
||||
PM_MPP__I_SINK__SWITCH_DIS);
|
||||
if (ret)
|
||||
dev_err(led_cdev->dev, "can't set mpp led\n");
|
||||
}
|
||||
|
||||
static int pmic_mpp_led_probe(struct platform_device *pdev)
|
||||
{
|
||||
const struct led_platform_data *pdata = pdev->dev.platform_data;
|
||||
struct pmic_mpp_led_data *led, *tmp_led;
|
||||
int i, rc;
|
||||
|
||||
if (!pdata) {
|
||||
dev_err(&pdev->dev, "platform data not supplied\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
led = kcalloc(pdata->num_leds, sizeof(*led), GFP_KERNEL);
|
||||
if (!led) {
|
||||
dev_err(&pdev->dev, "failed to alloc memory\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
platform_set_drvdata(pdev, led);
|
||||
|
||||
for (i = 0; i < pdata->num_leds; i++) {
|
||||
tmp_led = &led[i];
|
||||
tmp_led->cdev.name = pdata->leds[i].name;
|
||||
tmp_led->cdev.brightness_set = pm_mpp_led_set;
|
||||
tmp_led->cdev.brightness = LED_OFF;
|
||||
tmp_led->cdev.max_brightness = LED_FULL;
|
||||
tmp_led->mpp = LED_MPP(pdata->leds[i].flags);
|
||||
tmp_led->curr = LED_CURR(pdata->leds[i].flags);
|
||||
|
||||
if (tmp_led->curr < PM_MPP__I_SINK__LEVEL_5mA ||
|
||||
tmp_led->curr > PM_MPP__I_SINK__LEVEL_40mA) {
|
||||
dev_err(&pdev->dev, "invalid current\n");
|
||||
goto unreg_led_cdev;
|
||||
}
|
||||
|
||||
rc = led_classdev_register(&pdev->dev, &tmp_led->cdev);
|
||||
if (rc) {
|
||||
dev_err(&pdev->dev, "failed to register led\n");
|
||||
goto unreg_led_cdev;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
unreg_led_cdev:
|
||||
while (i)
|
||||
led_classdev_unregister(&led[--i].cdev);
|
||||
|
||||
kfree(led);
|
||||
return rc;
|
||||
|
||||
}
|
||||
|
||||
static int __devexit pmic_mpp_led_remove(struct platform_device *pdev)
|
||||
{
|
||||
const struct led_platform_data *pdata = pdev->dev.platform_data;
|
||||
struct pmic_mpp_led_data *led = platform_get_drvdata(pdev);
|
||||
int i;
|
||||
|
||||
for (i = 0; i < pdata->num_leds; i++)
|
||||
led_classdev_unregister(&led[i].cdev);
|
||||
|
||||
kfree(led);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct platform_driver pmic_mpp_led_driver = {
|
||||
.probe = pmic_mpp_led_probe,
|
||||
.remove = __devexit_p(pmic_mpp_led_remove),
|
||||
.driver = {
|
||||
.name = "pmic-mpp-leds",
|
||||
.owner = THIS_MODULE,
|
||||
},
|
||||
};
|
||||
|
||||
static int __init pmic_mpp_led_init(void)
|
||||
{
|
||||
return platform_driver_register(&pmic_mpp_led_driver);
|
||||
}
|
||||
module_init(pmic_mpp_led_init);
|
||||
|
||||
static void __exit pmic_mpp_led_exit(void)
|
||||
{
|
||||
platform_driver_unregister(&pmic_mpp_led_driver);
|
||||
}
|
||||
module_exit(pmic_mpp_led_exit);
|
||||
|
||||
MODULE_DESCRIPTION("PMIC MPP LEDs driver");
|
||||
MODULE_LICENSE("GPL v2");
|
||||
MODULE_ALIAS("platform:pmic-mpp-leds");
|
Loading…
Reference in a new issue