mirror of
https://github.com/torvalds/linux.git
synced 2024-11-08 21:21:47 +00:00
30304e5a79
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) iQIcBAABAgAGBQJPcXgCAAoJEIqAPN1PVmxKh2oP/2Ns+dr4oOF8z+uqYG1oisJd CxBTC1Bi9gYBtpiMztPiHZWiQtVXoDgLbLkx6ooWH5dpwCdvU6TVBZUJp4wpELtx mMk5vJy4/INHgI0nk5wUOr76rNlQfIcK04f+LHBSG1iljUkoVR3FefVKgoyIP+Wv oiCeuCyQcYIUmG1pVt1x43OoS+2xgjWQA67AalLLRj1DOA5OkvUL7NGsrZ1iZTUh YHQJsK6ER3MgbFFEImtn10NNFwAEG04o6vi42DFW1O0awm6kmVoLjo46wS+UiKoh Vx8t5ZGvlYOZ1ZM9N5ETgQnihBt7cOhA3ivZar8h+WiYVTRJs1ZSkpmnlpmM4YY9 RCZ5DRw3N39R0ezkNVGSr1Xn1vkysIiZI82frrJiPUYLKihsrBzj2Jq3O25iILCf Iyv7HBEJxAb3x0zlF6kPhaA8OW4dssaHTLNx5IJSOKwiwVLdm4RPyOHh9QVz++p/ p0hvSQWK1MUruBbBrjF/FN+FidgK2iU0iDW/GoDwI7OKymSxg7sauLtp0cZpo6nT F+Ep6yl/uR5vxih4LSYFJOjoeKuwIo/x92H0qJ3UroaUs9DNJ7UCKchXXiQ1Wtnz tAAsWP1YsMxMzlMxqW5J9w4LJynJ8bqrC0L8+HWzIUwikA8wv8/47Pmc/vPW0Y3N 5L7KMS8/iFCsS8rPmGeP =onDl -----END PGP SIGNATURE----- Merge tag 'mfd_3.4-1' of git://git.kernel.org/pub/scm/linux/kernel/git/sameo/mfd-2.6 Pull MFD changes from Samuel Ortiz: - 4 new drivers: Freescale i.MX on-chip Anatop, Ricoh's RC5T583 and TI's TPS65090 and TPS65217. - New variants support (8420, 8520 ab9540), cleanups and bug fixes for the abx500 and db8500 ST-E chipsets. - Some minor fixes and update for the wm8994 from Mark. - The beginning of a long term TWL cleanup effort coming from the TI folks. - Various fixes and cleanups for the s5m, TPS659xx, pm860x, and MAX8997 drivers. Fix up trivial conflicts due to duplicate patches and header file cleanups (<linux/device.h> removal etc). * tag 'mfd_3.4-1' of git://git.kernel.org/pub/scm/linux/kernel/git/sameo/mfd-2.6: (97 commits) gpio/twl: Add DT support to gpio-twl4030 driver gpio/twl: Allocate irq_desc dynamically for SPARSE_IRQ support mfd: Detach twl6040 from the pmic mfd driver mfd: Replace twl-* pr_ macros by the dev_ equivalent and do various cleanups mfd: Micro-optimization on twl4030 IRQ handler mfd: Make twl4030 SIH SPARSE_IRQ capable mfd: Move twl-core IRQ allocation into twl[4030|6030]-irq files mfd: Remove references already defineid in header file from twl-core mfd: Remove unneeded header from twl-core mfd: Make twl-core not depend on pdata->irq_base/end ARM: OMAP2+: board-omap4-*: Do not use anymore TWL6030_IRQ_BASE in board files mfd: Return twl6030_mmc_card_detect IRQ for board setup Revert "mfd: Add platform data for MAX8997 haptic driver" mfd: Add support for TPS65090 mfd: Add some da9052-i2c section annotations mfd: Build rtc5t583 only if I2C config is selected to y. mfd: Add anatop mfd driver mfd: Fix compilation error in tps65910.h mfd: Add 8420 variant to db8500-prcmu mfd: Add 8520 PRCMU variant to db8500-prcmu ...
282 lines
6.7 KiB
C
282 lines
6.7 KiB
C
/*
|
|
* Backlight driver for Marvell Semiconductor 88PM8606
|
|
*
|
|
* 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/init.h>
|
|
#include <linux/kernel.h>
|
|
#include <linux/platform_device.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/fb.h>
|
|
#include <linux/i2c.h>
|
|
#include <linux/backlight.h>
|
|
#include <linux/mfd/88pm860x.h>
|
|
#include <linux/module.h>
|
|
|
|
#define MAX_BRIGHTNESS (0xFF)
|
|
#define MIN_BRIGHTNESS (0)
|
|
|
|
#define CURRENT_BITMASK (0x1F << 1)
|
|
|
|
struct pm860x_backlight_data {
|
|
struct pm860x_chip *chip;
|
|
struct i2c_client *i2c;
|
|
int current_brightness;
|
|
int port;
|
|
int pwm;
|
|
int iset;
|
|
};
|
|
|
|
static inline int wled_a(int port)
|
|
{
|
|
int ret;
|
|
|
|
ret = ((port - PM8606_BACKLIGHT1) << 1) + 2;
|
|
return ret;
|
|
}
|
|
|
|
static inline int wled_b(int port)
|
|
{
|
|
int ret;
|
|
|
|
ret = ((port - PM8606_BACKLIGHT1) << 1) + 3;
|
|
return ret;
|
|
}
|
|
|
|
/* WLED2 & WLED3 share the same IDC */
|
|
static inline int wled_idc(int port)
|
|
{
|
|
int ret;
|
|
|
|
switch (port) {
|
|
case PM8606_BACKLIGHT1:
|
|
case PM8606_BACKLIGHT2:
|
|
ret = ((port - PM8606_BACKLIGHT1) << 1) + 3;
|
|
break;
|
|
case PM8606_BACKLIGHT3:
|
|
default:
|
|
ret = ((port - PM8606_BACKLIGHT2) << 1) + 3;
|
|
break;
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
static int backlight_power_set(struct pm860x_chip *chip, int port,
|
|
int on)
|
|
{
|
|
int ret = -EINVAL;
|
|
|
|
switch (port) {
|
|
case PM8606_BACKLIGHT1:
|
|
ret = on ? pm8606_osc_enable(chip, WLED1_DUTY) :
|
|
pm8606_osc_disable(chip, WLED1_DUTY);
|
|
break;
|
|
case PM8606_BACKLIGHT2:
|
|
ret = on ? pm8606_osc_enable(chip, WLED2_DUTY) :
|
|
pm8606_osc_disable(chip, WLED2_DUTY);
|
|
break;
|
|
case PM8606_BACKLIGHT3:
|
|
ret = on ? pm8606_osc_enable(chip, WLED3_DUTY) :
|
|
pm8606_osc_disable(chip, WLED3_DUTY);
|
|
break;
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
static int pm860x_backlight_set(struct backlight_device *bl, int brightness)
|
|
{
|
|
struct pm860x_backlight_data *data = bl_get_data(bl);
|
|
struct pm860x_chip *chip = data->chip;
|
|
unsigned char value;
|
|
int ret;
|
|
|
|
if (brightness > MAX_BRIGHTNESS)
|
|
value = MAX_BRIGHTNESS;
|
|
else
|
|
value = brightness;
|
|
|
|
if (brightness)
|
|
backlight_power_set(chip, data->port, 1);
|
|
|
|
ret = pm860x_reg_write(data->i2c, wled_a(data->port), value);
|
|
if (ret < 0)
|
|
goto out;
|
|
|
|
if ((data->current_brightness == 0) && brightness) {
|
|
if (data->iset) {
|
|
ret = pm860x_set_bits(data->i2c, wled_idc(data->port),
|
|
CURRENT_BITMASK, data->iset);
|
|
if (ret < 0)
|
|
goto out;
|
|
}
|
|
if (data->pwm) {
|
|
ret = pm860x_set_bits(data->i2c, PM8606_PWM,
|
|
PM8606_PWM_FREQ_MASK, data->pwm);
|
|
if (ret < 0)
|
|
goto out;
|
|
}
|
|
if (brightness == MAX_BRIGHTNESS) {
|
|
/* set WLED_ON bit as 100% */
|
|
ret = pm860x_set_bits(data->i2c, wled_b(data->port),
|
|
PM8606_WLED_ON, PM8606_WLED_ON);
|
|
}
|
|
} else {
|
|
if (brightness == MAX_BRIGHTNESS) {
|
|
/* set WLED_ON bit as 100% */
|
|
ret = pm860x_set_bits(data->i2c, wled_b(data->port),
|
|
PM8606_WLED_ON, PM8606_WLED_ON);
|
|
} else {
|
|
/* clear WLED_ON bit since it's not 100% */
|
|
ret = pm860x_set_bits(data->i2c, wled_b(data->port),
|
|
PM8606_WLED_ON, 0);
|
|
}
|
|
}
|
|
if (ret < 0)
|
|
goto out;
|
|
|
|
if (brightness == 0)
|
|
backlight_power_set(chip, data->port, 0);
|
|
|
|
dev_dbg(chip->dev, "set brightness %d\n", value);
|
|
data->current_brightness = value;
|
|
return 0;
|
|
out:
|
|
dev_dbg(chip->dev, "set brightness %d failure with return "
|
|
"value:%d\n", value, ret);
|
|
return ret;
|
|
}
|
|
|
|
static int pm860x_backlight_update_status(struct backlight_device *bl)
|
|
{
|
|
int brightness = bl->props.brightness;
|
|
|
|
if (bl->props.power != FB_BLANK_UNBLANK)
|
|
brightness = 0;
|
|
|
|
if (bl->props.fb_blank != FB_BLANK_UNBLANK)
|
|
brightness = 0;
|
|
|
|
if (bl->props.state & BL_CORE_SUSPENDED)
|
|
brightness = 0;
|
|
|
|
return pm860x_backlight_set(bl, brightness);
|
|
}
|
|
|
|
static int pm860x_backlight_get_brightness(struct backlight_device *bl)
|
|
{
|
|
struct pm860x_backlight_data *data = bl_get_data(bl);
|
|
struct pm860x_chip *chip = data->chip;
|
|
int ret;
|
|
|
|
ret = pm860x_reg_read(data->i2c, wled_a(data->port));
|
|
if (ret < 0)
|
|
goto out;
|
|
data->current_brightness = ret;
|
|
dev_dbg(chip->dev, "get brightness %d\n", data->current_brightness);
|
|
return data->current_brightness;
|
|
out:
|
|
return -EINVAL;
|
|
}
|
|
|
|
static const struct backlight_ops pm860x_backlight_ops = {
|
|
.options = BL_CORE_SUSPENDRESUME,
|
|
.update_status = pm860x_backlight_update_status,
|
|
.get_brightness = pm860x_backlight_get_brightness,
|
|
};
|
|
|
|
static int pm860x_backlight_probe(struct platform_device *pdev)
|
|
{
|
|
struct pm860x_chip *chip = dev_get_drvdata(pdev->dev.parent);
|
|
struct pm860x_backlight_pdata *pdata = NULL;
|
|
struct pm860x_backlight_data *data;
|
|
struct backlight_device *bl;
|
|
struct resource *res;
|
|
struct backlight_properties props;
|
|
char name[MFD_NAME_SIZE];
|
|
int ret;
|
|
|
|
res = platform_get_resource(pdev, IORESOURCE_IO, 0);
|
|
if (res == NULL) {
|
|
dev_err(&pdev->dev, "No I/O resource!\n");
|
|
return -EINVAL;
|
|
}
|
|
|
|
pdata = pdev->dev.platform_data;
|
|
if (pdata == NULL) {
|
|
dev_err(&pdev->dev, "platform data isn't assigned to "
|
|
"backlight\n");
|
|
return -EINVAL;
|
|
}
|
|
|
|
data = devm_kzalloc(&pdev->dev, sizeof(struct pm860x_backlight_data),
|
|
GFP_KERNEL);
|
|
if (data == NULL)
|
|
return -ENOMEM;
|
|
strncpy(name, res->name, MFD_NAME_SIZE);
|
|
data->chip = chip;
|
|
data->i2c = (chip->id == CHIP_PM8606) ? chip->client \
|
|
: chip->companion;
|
|
data->current_brightness = MAX_BRIGHTNESS;
|
|
data->pwm = pdata->pwm;
|
|
data->iset = pdata->iset;
|
|
data->port = pdata->flags;
|
|
if (data->port < 0) {
|
|
dev_err(&pdev->dev, "wrong platform data is assigned");
|
|
return -EINVAL;
|
|
}
|
|
|
|
memset(&props, 0, sizeof(struct backlight_properties));
|
|
props.type = BACKLIGHT_RAW;
|
|
props.max_brightness = MAX_BRIGHTNESS;
|
|
bl = backlight_device_register(name, &pdev->dev, data,
|
|
&pm860x_backlight_ops, &props);
|
|
if (IS_ERR(bl)) {
|
|
dev_err(&pdev->dev, "failed to register backlight\n");
|
|
return PTR_ERR(bl);
|
|
}
|
|
bl->props.brightness = MAX_BRIGHTNESS;
|
|
|
|
platform_set_drvdata(pdev, bl);
|
|
|
|
/* read current backlight */
|
|
ret = pm860x_backlight_get_brightness(bl);
|
|
if (ret < 0)
|
|
goto out;
|
|
|
|
backlight_update_status(bl);
|
|
return 0;
|
|
out:
|
|
backlight_device_unregister(bl);
|
|
return ret;
|
|
}
|
|
|
|
static int pm860x_backlight_remove(struct platform_device *pdev)
|
|
{
|
|
struct backlight_device *bl = platform_get_drvdata(pdev);
|
|
|
|
backlight_device_unregister(bl);
|
|
return 0;
|
|
}
|
|
|
|
static struct platform_driver pm860x_backlight_driver = {
|
|
.driver = {
|
|
.name = "88pm860x-backlight",
|
|
.owner = THIS_MODULE,
|
|
},
|
|
.probe = pm860x_backlight_probe,
|
|
.remove = pm860x_backlight_remove,
|
|
};
|
|
|
|
module_platform_driver(pm860x_backlight_driver);
|
|
|
|
MODULE_DESCRIPTION("Backlight Driver for Marvell Semiconductor 88PM8606");
|
|
MODULE_AUTHOR("Haojian Zhuang <haojian.zhuang@marvell.com>");
|
|
MODULE_LICENSE("GPL");
|
|
MODULE_ALIAS("platform:88pm860x-backlight");
|