From: Michael Hennerich <[email protected]>
Base driver for Analog Devices ADP5520/ADP5501 MFD PMICs
Subdevs:
LCD Backlight : drivers/video/backlight/adp5520_bl
LEDs : drivers/led/leds-adp5520
GPIO : drivers/gpio/adp5520-gpio (ADP5520 only)
Keys : drivers/input/keyboard/adp5520-keys (ADP5520 only)
Signed-off-by: Michael Hennerich <[email protected]>
Signed-off-by: Bryan Wu <[email protected]>
Signed-off-by: Mike Frysinger <[email protected]>
---
drivers/mfd/Kconfig | 10 ++
drivers/mfd/Makefile | 1 +
drivers/mfd/adp5520.c | 378 +++++++++++++++++++++++++++++++++++++++++++
include/linux/mfd/adp5520.h | 299 ++++++++++++++++++++++++++++++++++
4 files changed, 688 insertions(+), 0 deletions(-)
create mode 100644 drivers/mfd/adp5520.c
create mode 100644 include/linux/mfd/adp5520.h
diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index 570be13..34e8595 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -160,6 +160,16 @@ config PMIC_DA903X
individual components like LCD backlight, voltage regulators,
LEDs and battery-charger under the corresponding menus.
+config PMIC_ADP5520
+ bool "Analog Devices ADP5520/01 MFD PMIC Core Support"
+ depends on I2C=y
+ help
+ Say yes here to add support for Analog Devices AD5520 and ADP5501,
+ Multifunction Power Management IC. This includes
+ the I2C driver and the core APIs _only_, you have to select
+ individual components like LCD backlight, LEDs, GPIOs and Kepad
+ under the corresponding menus.
+
config MFD_WM8400
tristate "Support Wolfson Microelectronics WM8400"
select MFD_CORE
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index f3b277b..a42248e 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -50,3 +50,4 @@ obj-$(CONFIG_PCF50633_ADC) += pcf50633-adc.o
obj-$(CONFIG_PCF50633_GPIO) += pcf50633-gpio.o
obj-$(CONFIG_AB3100_CORE) += ab3100-core.o
obj-$(CONFIG_AB3100_OTP) += ab3100-otp.o
+obj-$(CONFIG_PMIC_ADP5520) += adp5520.o
diff --git a/drivers/mfd/adp5520.c b/drivers/mfd/adp5520.c
new file mode 100644
index 0000000..401a9b6
--- /dev/null
+++ b/drivers/mfd/adp5520.c
@@ -0,0 +1,378 @@
+/*
+ * Base driver for Analog Devices ADP5520/ADP5501 MFD PMICs
+ * LCD Backlight: drivers/video/backlight/adp5520_bl
+ * LEDs : drivers/led/leds-adp5520
+ * GPIO : drivers/gpio/adp5520-gpio (ADP5520 only)
+ * Keys : drivers/input/keyboard/adp5520-keys (ADP5520 only)
+ *
+ * Copyright 2009 Analog Devices Inc.
+ *
+ * Derived from da903x:
+ * Copyright (C) 2008 Compulab, Ltd.
+ * Mike Rapoport <[email protected]>
+ *
+ * Copyright (C) 2006-2008 Marvell International Ltd.
+ * Eric Miao <[email protected]>
+ *
+ * Licensed under the GPL-2 or later.
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/init.h>
+#include <linux/interrupt.h>
+#include <linux/irq.h>
+#include <linux/err.h>
+#include <linux/i2c.h>
+
+#include <linux/mfd/adp5520.h>
+
+struct adp5520_chip {
+ struct i2c_client *client;
+ struct device *dev;
+ struct mutex lock;
+ struct blocking_notifier_head notifier_list;
+ int irq;
+ unsigned long id;
+};
+
+static int __adp5520_read(struct i2c_client *client,
+ int reg, uint8_t *val)
+{
+ int ret;
+
+ ret = i2c_smbus_read_byte_data(client, reg);
+ if (ret < 0) {
+ dev_err(&client->dev, "failed reading at 0x%02x\n", reg);
+ return ret;
+ }
+
+ *val = (uint8_t)ret;
+ return 0;
+}
+
+static int __adp5520_write(struct i2c_client *client,
+ int reg, uint8_t val)
+{
+ int ret;
+
+ ret = i2c_smbus_write_byte_data(client, reg, val);
+ if (ret < 0) {
+ dev_err(&client->dev, "failed writing 0x%02x to 0x%02x\n",
+ val, reg);
+ return ret;
+ }
+ return 0;
+}
+
+int __adp5520_ack_bits(struct i2c_client *client, int reg, uint8_t bit_mask)
+{
+ struct adp5520_chip *chip = i2c_get_clientdata(client);
+ uint8_t reg_val;
+ int ret;
+
+ mutex_lock(&chip->lock);
+
+ ret = __adp5520_read(client, reg, ®_val);
+
+ if (!ret) {
+ reg_val |= bit_mask;
+ ret = __adp5520_write(client, reg, reg_val);
+ }
+
+ mutex_unlock(&chip->lock);
+ return ret;
+}
+
+int adp5520_write(struct device *dev, int reg, uint8_t val)
+{
+ return __adp5520_write(to_i2c_client(dev), reg, val);
+}
+EXPORT_SYMBOL_GPL(adp5520_write);
+
+int adp5520_read(struct device *dev, int reg, uint8_t *val)
+{
+ return __adp5520_read(to_i2c_client(dev), reg, val);
+}
+EXPORT_SYMBOL_GPL(adp5520_read);
+
+int adp5520_set_bits(struct device *dev, int reg, uint8_t bit_mask)
+{
+ struct adp5520_chip *chip = dev_get_drvdata(dev);
+ uint8_t reg_val;
+ int ret;
+
+ mutex_lock(&chip->lock);
+
+ ret = __adp5520_read(chip->client, reg, ®_val);
+
+ if (!ret && ((reg_val & bit_mask) == 0)) {
+ reg_val |= bit_mask;
+ ret = __adp5520_write(chip->client, reg, reg_val);
+ }
+
+ mutex_unlock(&chip->lock);
+ return ret;
+}
+EXPORT_SYMBOL_GPL(adp5520_set_bits);
+
+int adp5520_clr_bits(struct device *dev, int reg, uint8_t bit_mask)
+{
+ struct adp5520_chip *chip = dev_get_drvdata(dev);
+ uint8_t reg_val;
+ int ret;
+
+ mutex_lock(&chip->lock);
+
+ ret = __adp5520_read(chip->client, reg, ®_val);
+
+ if (!ret && (reg_val & bit_mask)) {
+ reg_val &= ~bit_mask;
+ ret = __adp5520_write(chip->client, reg, reg_val);
+ }
+
+ mutex_unlock(&chip->lock);
+ return ret;
+}
+EXPORT_SYMBOL_GPL(adp5520_clr_bits);
+
+int adp5520_register_notifier(struct device *dev, struct notifier_block *nb,
+ unsigned int events)
+{
+ struct adp5520_chip *chip = dev_get_drvdata(dev);
+
+ if (chip->irq) {
+ adp5520_set_bits(chip->dev, ADP5520_INTERRUPT_ENABLE,
+ events & (ADP5520_KP_IEN | ADP5520_KR_IEN |
+ ADP5520_OVP_IEN | ADP5520_CMPR_IEN));
+
+ return blocking_notifier_chain_register(&chip->notifier_list,
+ nb);
+ }
+
+ return -ENODEV;
+}
+EXPORT_SYMBOL_GPL(adp5520_register_notifier);
+
+int adp5520_unregister_notifier(struct device *dev, struct notifier_block *nb,
+ unsigned int events)
+{
+ struct adp5520_chip *chip = dev_get_drvdata(dev);
+
+ adp5520_clr_bits(chip->dev, ADP5520_INTERRUPT_ENABLE,
+ events & (ADP5520_KP_IEN | ADP5520_KR_IEN |
+ ADP5520_OVP_IEN | ADP5520_CMPR_IEN));
+
+ return blocking_notifier_chain_unregister(&chip->notifier_list, nb);
+}
+EXPORT_SYMBOL_GPL(adp5520_unregister_notifier);
+
+static irqreturn_t adp5520_irq_thread(int irq, void *data)
+{
+ struct adp5520_chip *chip = data;
+ unsigned int events;
+ uint8_t reg_val;
+ int ret;
+
+ ret = __adp5520_read(chip->client, ADP5520_MODE_STATUS, ®_val);
+ if (ret)
+ goto out;
+
+ events = reg_val & (ADP5520_OVP_INT | ADP5520_CMPR_INT |
+ ADP5520_GPI_INT | ADP5520_KR_INT | ADP5520_KP_INT);
+
+ blocking_notifier_call_chain(&chip->notifier_list, events, NULL);
+ /* ACK, Sticky bits are W1C */
+ __adp5520_ack_bits(chip->client, ADP5520_MODE_STATUS, events);
+
+out:
+ return IRQ_HANDLED;
+}
+
+static int __remove_subdev(struct device *dev, void *unused)
+{
+ platform_device_unregister(to_platform_device(dev));
+ return 0;
+}
+
+static int adp5520_remove_subdevs(struct adp5520_chip *chip)
+{
+ return device_for_each_child(chip->dev, NULL, __remove_subdev);
+}
+
+static int __devinit adp5520_probe(struct i2c_client *client,
+ const struct i2c_device_id *id)
+{
+ struct adp5520_platform_data *pdata = client->dev.platform_data;
+ struct platform_device *pdev;
+ struct adp5520_chip *chip;
+ int ret;
+
+ if (!i2c_check_functionality(client->adapter,
+ I2C_FUNC_SMBUS_BYTE_DATA)) {
+ dev_err(&client->dev, "SMBUS Word Data not Supported\n");
+ return -EIO;
+ }
+
+ if (pdata == NULL) {
+ dev_err(&client->dev, "missing platform data\n");
+ return -ENODEV;
+ }
+
+ chip = kzalloc(sizeof(*chip), GFP_KERNEL);
+ if (!chip)
+ return -ENOMEM;
+
+ i2c_set_clientdata(client, chip);
+ chip->client = client;
+
+ chip->dev = &client->dev;
+ chip->irq = client->irq;
+ chip->id = id->driver_data;
+ mutex_init(&chip->lock);
+
+ if (chip->irq) {
+ BLOCKING_INIT_NOTIFIER_HEAD(&chip->notifier_list);
+
+ ret = request_threaded_irq(chip->irq, NULL, adp5520_irq_thread,
+ IRQF_TRIGGER_LOW | IRQF_ONESHOT,
+ "adp5520", chip);
+ if (ret) {
+ dev_err(&client->dev, "failed to request irq %d\n",
+ chip->irq);
+ goto out_free_chip;
+ }
+ }
+
+ ret = adp5520_write(chip->dev, ADP5520_MODE_STATUS, ADP5520_nSTNBY);
+ if (ret) {
+ dev_err(&client->dev, "failed to write\n");
+ goto out_free_irq;
+ }
+
+ if (pdata->keys) {
+ pdev = platform_device_register_data(chip->dev, "adp5520-keys",
+ chip->id, pdata->keys, sizeof(*pdata->keys));
+ if (IS_ERR(pdev)) {
+ ret = PTR_ERR(pdev);
+ goto out_remove_subdevs;
+ }
+ }
+
+ if (pdata->gpio) {
+ pdev = platform_device_register_data(chip->dev, "adp5520-gpio",
+ chip->id, pdata->gpio, sizeof(*pdata->gpio));
+ if (IS_ERR(pdev)) {
+ ret = PTR_ERR(pdev);
+ goto out_remove_subdevs;
+ }
+ }
+
+ if (pdata->leds) {
+ pdev = platform_device_register_data(chip->dev, "adp5520-led",
+ chip->id, pdata->leds, sizeof(*pdata->leds));
+ if (IS_ERR(pdev)) {
+ ret = PTR_ERR(pdev);
+ goto out_remove_subdevs;
+ }
+ }
+
+ if (pdata->backlight) {
+ pdev = platform_device_register_data(chip->dev,
+ "adp5520-backlight",
+ chip->id,
+ pdata->backlight,
+ sizeof(*pdata->backlight));
+ if (IS_ERR(pdev)) {
+ ret = PTR_ERR(pdev);
+ goto out_remove_subdevs;
+ }
+ }
+
+ return 0;
+
+out_remove_subdevs:
+ adp5520_remove_subdevs(chip);
+
+out_free_irq:
+ if (chip->irq)
+ free_irq(chip->irq, chip);
+
+out_free_chip:
+ i2c_set_clientdata(client, NULL);
+ kfree(chip);
+
+ return ret;
+}
+
+static int __devexit adp5520_remove(struct i2c_client *client)
+{
+ struct adp5520_chip *chip = dev_get_drvdata(&client->dev);
+
+ if (chip->irq)
+ free_irq(chip->irq, chip);
+
+ adp5520_remove_subdevs(chip);
+ adp5520_write(chip->dev, ADP5520_MODE_STATUS, 0);
+ i2c_set_clientdata(client, NULL);
+ kfree(chip);
+ return 0;
+}
+
+#ifdef CONFIG_PM
+static int adp5520_suspend(struct i2c_client *client,
+ pm_message_t state)
+{
+ struct adp5520_chip *chip = dev_get_drvdata(&client->dev);
+
+ adp5520_clr_bits(chip->dev, ADP5520_MODE_STATUS, ADP5520_nSTNBY);
+ return 0;
+}
+
+static int adp5520_resume(struct i2c_client *client)
+{
+ struct adp5520_chip *chip = dev_get_drvdata(&client->dev);
+
+ adp5520_set_bits(chip->dev, ADP5520_MODE_STATUS, ADP5520_nSTNBY);
+ return 0;
+}
+#else
+#define adp5520_suspend NULL
+#define adp5520_resume NULL
+#endif
+
+static const struct i2c_device_id adp5520_id[] = {
+ { "pmic-adp5520", ID_ADP5520 },
+ { "pmic-adp5501", ID_ADP5501 },
+ { }
+};
+MODULE_DEVICE_TABLE(i2c, adp5520_id);
+
+static struct i2c_driver adp5520_driver = {
+ .driver = {
+ .name = "adp5520",
+ .owner = THIS_MODULE,
+ },
+ .probe = adp5520_probe,
+ .remove = __devexit_p(adp5520_remove),
+ .suspend = adp5520_suspend,
+ .resume = adp5520_resume,
+ .id_table = adp5520_id,
+};
+
+static int __init adp5520_init(void)
+{
+ return i2c_add_driver(&adp5520_driver);
+}
+module_init(adp5520_init);
+
+static void __exit adp5520_exit(void)
+{
+ i2c_del_driver(&adp5520_driver);
+}
+module_exit(adp5520_exit);
+
+MODULE_AUTHOR("Michael Hennerich <[email protected]>");
+MODULE_DESCRIPTION("ADP5520(01) PMIC-MFD Driver");
+MODULE_LICENSE("GPL");
diff --git a/include/linux/mfd/adp5520.h b/include/linux/mfd/adp5520.h
new file mode 100644
index 0000000..ac37558
--- /dev/null
+++ b/include/linux/mfd/adp5520.h
@@ -0,0 +1,299 @@
+/*
+ * Definitions and platform data for Analog Devices
+ * ADP5520/ADP5501 MFD PMICs (Backlight, LED, GPIO and Keys)
+ *
+ * Copyright 2009 Analog Devices Inc.
+ *
+ * Licensed under the GPL-2 or later.
+ */
+
+
+#ifndef __LINUX_MFD_ADP5520_H
+#define __LINUX_MFD_ADP5520_H
+
+#define ID_ADP5520 5520
+#define ID_ADP5501 5501
+
+/*
+ * ADP5520/ADP5501 Register Map
+ */
+
+#define ADP5520_MODE_STATUS 0x00
+#define ADP5520_INTERRUPT_ENABLE 0x01
+#define ADP5520_BL_CONTROL 0x02
+#define ADP5520_BL_TIME 0x03
+#define ADP5520_BL_FADE 0x04
+#define ADP5520_DAYLIGHT_MAX 0x05
+#define ADP5520_DAYLIGHT_DIM 0x06
+#define ADP5520_OFFICE_MAX 0x07
+#define ADP5520_OFFICE_DIM 0x08
+#define ADP5520_DARK_MAX 0x09
+#define ADP5520_DARK_DIM 0x0A
+#define ADP5520_BL_VALUE 0x0B
+#define ADP5520_ALS_CMPR_CFG 0x0C
+#define ADP5520_L2_TRIP 0x0D
+#define ADP5520_L2_HYS 0x0E
+#define ADP5520_L3_TRIP 0x0F
+#define ADP5520_L3_HYS 0x10
+#define ADP5520_LED_CONTROL 0x11
+#define ADP5520_LED_TIME 0x12
+#define ADP5520_LED_FADE 0x13
+#define ADP5520_LED1_CURRENT 0x14
+#define ADP5520_LED2_CURRENT 0x15
+#define ADP5520_LED3_CURRENT 0x16
+
+/*
+ * ADP5520 Register Map
+ */
+
+#define ADP5520_GPIO_CFG_1 0x17
+#define ADP5520_GPIO_CFG_2 0x18
+#define ADP5520_GPIO_IN 0x19
+#define ADP5520_GPIO_OUT 0x1A
+#define ADP5520_GPIO_INT_EN 0x1B
+#define ADP5520_GPIO_INT_STAT 0x1C
+#define ADP5520_GPIO_INT_LVL 0x1D
+#define ADP5520_GPIO_DEBOUNCE 0x1E
+#define ADP5520_GPIO_PULLUP 0x1F
+#define ADP5520_KP_INT_STAT_1 0x20
+#define ADP5520_KP_INT_STAT_2 0x21
+#define ADP5520_KR_INT_STAT_1 0x22
+#define ADP5520_KR_INT_STAT_2 0x23
+#define ADP5520_KEY_STAT_1 0x24
+#define ADP5520_KEY_STAT_2 0x25
+
+/*
+ * MODE_STATUS bits
+ */
+
+#define ADP5520_nSTNBY (1 << 7)
+#define ADP5520_BL_EN (1 << 6)
+#define ADP5520_DIM_EN (1 << 5)
+#define ADP5520_OVP_INT (1 << 4)
+#define ADP5520_CMPR_INT (1 << 3)
+#define ADP5520_GPI_INT (1 << 2)
+#define ADP5520_KR_INT (1 << 1)
+#define ADP5520_KP_INT (1 << 0)
+
+/*
+ * INTERRUPT_ENABLE bits
+ */
+
+#define ADP5520_AUTO_LD_EN (1 << 4)
+#define ADP5520_CMPR_IEN (1 << 3)
+#define ADP5520_OVP_IEN (1 << 2)
+#define ADP5520_KR_IEN (1 << 1)
+#define ADP5520_KP_IEN (1 << 0)
+
+/*
+ * BL_CONTROL bits
+ */
+
+#define ADP5520_BL_LVL ((x) << 5)
+#define ADP5520_BL_LAW ((x) << 4)
+#define ADP5520_BL_AUTO_ADJ (1 << 3)
+#define ADP5520_OVP_EN (1 << 2)
+#define ADP5520_FOVR (1 << 1)
+#define ADP5520_KP_BL_EN (1 << 0)
+
+/*
+ * ALS_CMPR_CFG bits
+ */
+
+#define ADP5520_L3_OUT (1 << 3)
+#define ADP5520_L2_OUT (1 << 2)
+#define ADP5520_L3_EN (1 << 1)
+
+#define ADP5020_MAX_BRIGHTNESS 0x7F
+
+#define FADE_VAL(in, out) ((0xF & (in)) | ((0xF & (out)) << 4))
+#define BL_CTRL_VAL(law, auto) (((1 & (auto)) << 3) | ((0x3 & (law)) << 4))
+#define ALS_CMPR_CFG_VAL(filt, l3_en) (((0x7 & filt) << 5) | l3_en)
+
+/*
+ * LEDs subdevice bits and masks
+ */
+
+#define ADP5520_01_MAXLEDS 3
+
+#define ADP5520_FLAG_LED_MASK 0x3
+#define ADP5520_FLAG_OFFT_SHIFT 8
+#define ADP5520_FLAG_OFFT_MASK 0x3
+
+#define ADP5520_R3_MODE (1 << 5)
+#define ADP5520_C3_MODE (1 << 4)
+#define ADP5520_LED_LAW (1 << 3)
+#define ADP5520_LED3_EN (1 << 2)
+#define ADP5520_LED2_EN (1 << 1)
+#define ADP5520_LED1_EN (1 << 0)
+
+/*
+ * GPIO subdevice bits and masks
+ */
+
+#define ADP5520_MAXGPIOS 8
+
+#define ADP5520_GPIO_C3 (1 << 7) /* LED2 or GPIO7 aka C3 */
+#define ADP5520_GPIO_C2 (1 << 6)
+#define ADP5520_GPIO_C1 (1 << 5)
+#define ADP5520_GPIO_C0 (1 << 4)
+#define ADP5520_GPIO_R3 (1 << 3) /* LED3 or GPIO3 aka R3 */
+#define ADP5520_GPIO_R2 (1 << 2)
+#define ADP5520_GPIO_R1 (1 << 1)
+#define ADP5520_GPIO_R0 (1 << 0)
+
+struct adp5520_gpio_platform_data {
+ unsigned gpio_start;
+ u8 gpio_en_mask;
+ u8 gpio_pullup_mask;
+};
+
+/*
+ * Keypad subdevice bits and masks
+ */
+
+#define ADP5520_MAXKEYS 16
+
+#define ADP5520_COL_C3 (1 << 7) /* LED2 or GPIO7 aka C3 */
+#define ADP5520_COL_C2 (1 << 6)
+#define ADP5520_COL_C1 (1 << 5)
+#define ADP5520_COL_C0 (1 << 4)
+#define ADP5520_ROW_R3 (1 << 3) /* LED3 or GPIO3 aka R3 */
+#define ADP5520_ROW_R2 (1 << 2)
+#define ADP5520_ROW_R1 (1 << 1)
+#define ADP5520_ROW_R0 (1 << 0)
+
+#define ADP5520_KEY(row, col) (col + row * 4)
+#define ADP5520_KEYMAPSIZE ADP5520_MAXKEYS
+
+struct adp5520_keys_platform_data {
+ int rows_en_mask; /* Number of rows */
+ int cols_en_mask; /* Number of columns */
+ const unsigned short *keymap; /* Pointer to keymap */
+ unsigned short keymapsize; /* Keymap size */
+ unsigned repeat:1; /* Enable key repeat */
+};
+
+
+/*
+ * LEDs subdevice platform data
+ */
+
+#define FLAG_ID_ADP5520_LED1_ADP5501_LED0 1 /* ADP5520 PIN ILED */
+#define FLAG_ID_ADP5520_LED2_ADP5501_LED1 2 /* ADP5520 PIN C3 */
+#define FLAG_ID_ADP5520_LED3_ADP5501_LED2 3 /* ADP5520 PIN R3 */
+
+#define ADP5520_LED_DIS_BLINK (0 << ADP5520_FLAG_OFFT_SHIFT)
+#define ADP5520_LED_OFFT_600ms (1 << ADP5520_FLAG_OFFT_SHIFT)
+#define ADP5520_LED_OFFT_800ms (2 << ADP5520_FLAG_OFFT_SHIFT)
+#define ADP5520_LED_OFFT_1200ms (3 << ADP5520_FLAG_OFFT_SHIFT)
+
+#define ADP5520_LED_ONT_200ms 0
+#define ADP5520_LED_ONT_600ms 1
+#define ADP5520_LED_ONT_800ms 2
+#define ADP5520_LED_ONT_1200ms 3
+
+struct adp5520_leds_platform_data {
+ int num_leds;
+ struct led_info *leds;
+ u8 fade_in; /* Backlight Fade-In Timer */
+ u8 fade_out; /* Backlight Fade-Out Timer */
+ u8 led_on_time;
+};
+
+/*
+ * Backlight subdevice platform data
+ */
+
+#define ADP5520_FADE_T_DIS 0 /* Fade Timer Disabled */
+#define ADP5520_FADE_T_300ms 1 /* 0.3 Sec */
+#define ADP5520_FADE_T_600ms 2
+#define ADP5520_FADE_T_900ms 3
+#define ADP5520_FADE_T_1200ms 4
+#define ADP5520_FADE_T_1500ms 5
+#define ADP5520_FADE_T_1800ms 6
+#define ADP5520_FADE_T_2100ms 7
+#define ADP5520_FADE_T_2400ms 8
+#define ADP5520_FADE_T_2700ms 9
+#define ADP5520_FADE_T_3000ms 10
+#define ADP5520_FADE_T_3500ms 11
+#define ADP5520_FADE_T_4000ms 12
+#define ADP5520_FADE_T_4500ms 13
+#define ADP5520_FADE_T_5000ms 14
+#define ADP5520_FADE_T_5500ms 15 /* 5.5 Sec */
+
+#define ADP5520_BL_LAW_LINEAR 0
+#define ADP5520_BL_LAW_SQUARE 1
+#define ADP5520_BL_LAW_CUBIC1 2
+#define ADP5520_BL_LAW_CUBIC2 3
+
+#define ADP5520_BL_AMBL_FILT_80ms 0 /* Light sensor filter time */
+#define ADP5520_BL_AMBL_FILT_160ms 1
+#define ADP5520_BL_AMBL_FILT_320ms 2
+#define ADP5520_BL_AMBL_FILT_640ms 3
+#define ADP5520_BL_AMBL_FILT_1280ms 4
+#define ADP5520_BL_AMBL_FILT_2560ms 5
+#define ADP5520_BL_AMBL_FILT_5120ms 6
+#define ADP5520_BL_AMBL_FILT_10240ms 7 /* 10.24 sec */
+
+ /*
+ * Blacklight current 0..30mA
+ */
+#define ADP5520_BL_CUR_mA(I) ((I * 127) / 30)
+
+ /*
+ * L2 comparator current 0..1000uA
+ */
+#define ADP5520_L2_COMP_CURR_uA(I) ((I * 255) / 1000)
+
+ /*
+ * L3 comparator current 0..127uA
+ */
+#define ADP5520_L3_COMP_CURR_uA(I) ((I * 255) / 127)
+
+struct adp5520_backlight_platform_data {
+ u8 fade_in; /* Backlight Fade-In Timer */
+ u8 fade_out; /* Backlight Fade-Out Timer */
+ u8 fade_led_law; /* fade-on/fade-off transfer characteristic */
+
+ u8 en_ambl_sens; /* 1 = enable ambient light sensor */
+ u8 abml_filt; /* Light sensor filter time */
+ u8 l1_daylight_max; /* use BL_CUR_mA(I) 0 <= I <= 30 mA */
+ u8 l1_daylight_dim; /* typ = 0, use BL_CUR_mA(I) 0 <= I <= 30 mA */
+ u8 l2_office_max; /* use BL_CUR_mA(I) 0 <= I <= 30 mA */
+ u8 l2_office_dim; /* typ = 0, use BL_CUR_mA(I) 0 <= I <= 30 mA */
+ u8 l3_dark_max; /* use BL_CUR_mA(I) 0 <= I <= 30 mA */
+ u8 l3_dark_dim; /* typ = 0, use BL_CUR_mA(I) 0 <= I <= 30 mA */
+ u8 l2_trip; /* use L2_COMP_CURR_uA(I) 0 <= I <= 1000 uA */
+ u8 l2_hyst; /* use L2_COMP_CURR_uA(I) 0 <= I <= 1000 uA */
+ u8 l3_trip; /* use L3_COMP_CURR_uA(I) 0 <= I <= 127 uA */
+ u8 l3_hyst; /* use L3_COMP_CURR_uA(I) 0 <= I <= 127 uA */
+};
+
+/*
+ * MFD chip platform data
+ */
+
+struct adp5520_platform_data {
+ struct adp5520_keys_platform_data *keys;
+ struct adp5520_gpio_platform_data *gpio;
+ struct adp5520_leds_platform_data *leds;
+ struct adp5520_backlight_platform_data *backlight;
+};
+
+/*
+ * MFD chip functions
+ */
+
+extern int adp5520_read(struct device *dev, int reg, uint8_t *val);
+extern int adp5520_write(struct device *dev, int reg, u8 val);
+extern int adp5520_clr_bits(struct device *dev, int reg, uint8_t bit_mask);
+extern int adp5520_set_bits(struct device *dev, int reg, uint8_t bit_mask);
+
+extern int adp5520_register_notifier(struct device *dev,
+ struct notifier_block *nb, unsigned int events);
+
+extern int adp5520_unregister_notifier(struct device *dev,
+ struct notifier_block *nb, unsigned int events);
+
+#endif /* __LINUX_MFD_ADP5520_H */
--
1.6.5.rc2
From: Michael Hennerich <[email protected]>
Signed-off-by: Michael Hennerich <[email protected]>
Signed-off-by: Bryan Wu <[email protected]>
Signed-off-by: Mike Frysinger <[email protected]>
---
drivers/leds/Kconfig | 10 ++
drivers/leds/Makefile | 1 +
drivers/leds/leds-adp5520.c | 230 +++++++++++++++++++++++++++++++++++++++++++
3 files changed, 241 insertions(+), 0 deletions(-)
create mode 100644 drivers/leds/leds-adp5520.c
diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
index e4f599f..33ac8dc 100644
--- a/drivers/leds/Kconfig
+++ b/drivers/leds/Kconfig
@@ -236,6 +236,16 @@ config LEDS_BD2802
This option enables support for BD2802GU RGB LED driver chips
accessed via the I2C bus.
+config LEDS_ADP5520
+ tristate "LED Support for ADP5520/ADP5501 PMIC"
+ depends on LEDS_CLASS && PMIC_ADP5520
+ help
+ This option enables support for on-chip LED drivers found
+ on Analog Devices ADP5520/ADP5501 PMICs.
+
+ To compile this driver as a module, choose M here: the module will
+ be called leds-adp5520.
+
comment "LED Triggers"
config LEDS_TRIGGERS
diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
index 46d7270..f7e17f4 100644
--- a/drivers/leds/Makefile
+++ b/drivers/leds/Makefile
@@ -29,6 +29,7 @@ obj-$(CONFIG_LEDS_DA903X) += leds-da903x.o
obj-$(CONFIG_LEDS_WM831X_STATUS) += leds-wm831x-status.o
obj-$(CONFIG_LEDS_WM8350) += leds-wm8350.o
obj-$(CONFIG_LEDS_PWM) += leds-pwm.o
+obj-$(CONFIG_LEDS_ADP5520) += leds-adp5520.o
# LED SPI Drivers
obj-$(CONFIG_LEDS_DAC124S085) += leds-dac124s085.o
diff --git a/drivers/leds/leds-adp5520.c b/drivers/leds/leds-adp5520.c
new file mode 100644
index 0000000..a8f3159
--- /dev/null
+++ b/drivers/leds/leds-adp5520.c
@@ -0,0 +1,230 @@
+/*
+ * LEDs driver for Analog Devices ADP5520/ADP5501 MFD PMICs
+ *
+ * Copyright 2009 Analog Devices Inc.
+ *
+ * Loosely derived from leds-da903x:
+ * Copyright (C) 2008 Compulab, Ltd.
+ * Mike Rapoport <[email protected]>
+ *
+ * Copyright (C) 2006-2008 Marvell International Ltd.
+ * Eric Miao <[email protected]>
+ *
+ * Licensed under the GPL-2 or later.
+ */
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/platform_device.h>
+#include <linux/leds.h>
+#include <linux/workqueue.h>
+#include <linux/mfd/adp5520.h>
+
+struct adp5520_led {
+ struct led_classdev cdev;
+ struct work_struct work;
+ struct device *master;
+ enum led_brightness new_brightness;
+ int id;
+ int flags;
+};
+
+static void adp5520_led_work(struct work_struct *work)
+{
+ struct adp5520_led *led = container_of(work, struct adp5520_led, work);
+ adp5520_write(led->master, ADP5520_LED1_CURRENT + led->id - 1,
+ led->new_brightness >> 2);
+}
+
+static void adp5520_led_set(struct led_classdev *led_cdev,
+ enum led_brightness value)
+{
+ struct adp5520_led *led;
+
+ led = container_of(led_cdev, struct adp5520_led, cdev);
+ led->new_brightness = value;
+ schedule_work(&led->work);
+}
+
+static int adp5520_led_setup(struct adp5520_led *led)
+{
+ struct device *dev = led->master;
+ int flags = led->flags;
+ int ret = 0;
+
+ switch (led->id) {
+ case FLAG_ID_ADP5520_LED1_ADP5501_LED0:
+ ret |= adp5520_set_bits(dev, ADP5520_LED_TIME,
+ (flags >> ADP5520_FLAG_OFFT_SHIFT) &
+ ADP5520_FLAG_OFFT_MASK);
+ ret |= adp5520_set_bits(dev, ADP5520_LED_CONTROL,
+ ADP5520_LED1_EN);
+ break;
+ case FLAG_ID_ADP5520_LED2_ADP5501_LED1:
+ ret |= adp5520_set_bits(dev, ADP5520_LED_TIME,
+ ((flags >> ADP5520_FLAG_OFFT_SHIFT) &
+ ADP5520_FLAG_OFFT_MASK) << 2);
+ ret |= adp5520_clr_bits(dev, ADP5520_LED_CONTROL,
+ ADP5520_R3_MODE);
+ ret |= adp5520_set_bits(dev, ADP5520_LED_CONTROL,
+ ADP5520_LED2_EN);
+ break;
+ case FLAG_ID_ADP5520_LED3_ADP5501_LED2:
+ ret |= adp5520_set_bits(dev, ADP5520_LED_TIME,
+ ((flags >> ADP5520_FLAG_OFFT_SHIFT) &
+ ADP5520_FLAG_OFFT_MASK) << 4);
+ ret |= adp5520_clr_bits(dev, ADP5520_LED_CONTROL,
+ ADP5520_C3_MODE);
+ ret |= adp5520_set_bits(dev, ADP5520_LED_CONTROL,
+ ADP5520_LED3_EN);
+ break;
+ }
+
+ return ret;
+}
+
+static int __devinit adp5520_led_prepare(struct platform_device *pdev)
+{
+ struct adp5520_leds_platform_data *pdata = pdev->dev.platform_data;
+ struct device *dev = pdev->dev.parent;
+ int ret = 0;
+
+ ret |= adp5520_write(dev, ADP5520_LED1_CURRENT, 0);
+ ret |= adp5520_write(dev, ADP5520_LED2_CURRENT, 0);
+ ret |= adp5520_write(dev, ADP5520_LED3_CURRENT, 0);
+ ret |= adp5520_write(dev, ADP5520_LED_TIME, pdata->led_on_time << 6);
+ ret |= adp5520_write(dev, ADP5520_LED_FADE, FADE_VAL(pdata->fade_in,
+ pdata->fade_out));
+
+ return ret;
+}
+
+static int __devinit adp5520_led_probe(struct platform_device *pdev)
+{
+ struct adp5520_leds_platform_data *pdata = pdev->dev.platform_data;
+ struct adp5520_led *led, *led_dat;
+ struct led_info *cur_led;
+ int ret, i;
+
+ if (pdata == NULL) {
+ dev_err(&pdev->dev, "missing platform data\n");
+ return -ENODEV;
+ }
+
+ if (pdata->num_leds > ADP5520_01_MAXLEDS) {
+ dev_err(&pdev->dev, "can't handle more than %d LEDS\n",
+ ADP5520_01_MAXLEDS);
+ return -EFAULT;
+ }
+
+ led = kzalloc(sizeof(*led) * pdata->num_leds, GFP_KERNEL);
+ if (led == NULL) {
+ dev_err(&pdev->dev, "failed to alloc memory\n");
+ return -ENOMEM;
+ }
+
+ ret = adp5520_led_prepare(pdev);
+
+ if (ret) {
+ dev_err(&pdev->dev, "failed to write\n");
+ goto err_free;
+ }
+
+ for (i = 0; i < pdata->num_leds; ++i) {
+ cur_led = &pdata->leds[i];
+ led_dat = &led[i];
+
+ led_dat->cdev.name = cur_led->name;
+ led_dat->cdev.default_trigger = cur_led->default_trigger;
+ led_dat->cdev.brightness_set = adp5520_led_set;
+ led_dat->cdev.brightness = LED_OFF;
+
+ if (cur_led->flags & ADP5520_FLAG_LED_MASK)
+ led_dat->flags = cur_led->flags;
+ else
+ led_dat->flags = i + 1;
+
+ led_dat->id = led_dat->flags & ADP5520_FLAG_LED_MASK;
+
+ led_dat->master = pdev->dev.parent;
+ led_dat->new_brightness = LED_OFF;
+
+ INIT_WORK(&led_dat->work, adp5520_led_work);
+
+ ret = led_classdev_register(led_dat->master, &led_dat->cdev);
+ if (ret) {
+ dev_err(&pdev->dev, "failed to register LED %d\n",
+ led_dat->id);
+ goto err;
+ }
+
+ ret = adp5520_led_setup(led_dat);
+ if (ret) {
+ dev_err(&pdev->dev, "failed to write\n");
+ i++;
+ goto err;
+ }
+ }
+
+ platform_set_drvdata(pdev, led);
+ return 0;
+
+err:
+ if (i > 0) {
+ for (i = i - 1; i >= 0; i--) {
+ led_classdev_unregister(&led[i].cdev);
+ cancel_work_sync(&led[i].work);
+ }
+ }
+
+err_free:
+ kfree(led);
+ return ret;
+}
+
+static int __devexit adp5520_led_remove(struct platform_device *pdev)
+{
+ struct adp5520_leds_platform_data *pdata = pdev->dev.platform_data;
+ struct adp5520_led *led;
+ int i;
+
+ led = platform_get_drvdata(pdev);
+
+ adp5520_clr_bits(led->master, ADP5520_LED_CONTROL,
+ ADP5520_LED1_EN | ADP5520_LED2_EN | ADP5520_LED3_EN);
+
+ for (i = 0; i < pdata->num_leds; i++) {
+ led_classdev_unregister(&led[i].cdev);
+ cancel_work_sync(&led[i].work);
+ }
+
+ kfree(led);
+ return 0;
+}
+
+static struct platform_driver adp5520_led_driver = {
+ .driver = {
+ .name = "adp5520-led",
+ .owner = THIS_MODULE,
+ },
+ .probe = adp5520_led_probe,
+ .remove = __devexit_p(adp5520_led_remove),
+};
+
+static int __init adp5520_led_init(void)
+{
+ return platform_driver_register(&adp5520_led_driver);
+}
+module_init(adp5520_led_init);
+
+static void __exit adp5520_led_exit(void)
+{
+ platform_driver_unregister(&adp5520_led_driver);
+}
+module_exit(adp5520_led_exit);
+
+MODULE_AUTHOR("Michael Hennerich <[email protected]>");
+MODULE_DESCRIPTION("LEDS ADP5520(01) Driver");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:adp5520-led");
--
1.6.5.rc2
From: Michael Hennerich <[email protected]>
Signed-off-by: Michael Hennerich <[email protected]>
Signed-off-by: Bryan Wu <[email protected]>
Signed-off-by: Mike Frysinger <[email protected]>
Acked-by: Dmitry Torokhov <[email protected]>
---
drivers/input/keyboard/Kconfig | 10 ++
drivers/input/keyboard/Makefile | 1 +
drivers/input/keyboard/adp5520-keys.c | 220 +++++++++++++++++++++++++++++++++
3 files changed, 231 insertions(+), 0 deletions(-)
create mode 100644 drivers/input/keyboard/adp5520-keys.c
diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
index ee98b1b..9337a35 100644
--- a/drivers/input/keyboard/Kconfig
+++ b/drivers/input/keyboard/Kconfig
@@ -24,6 +24,16 @@ config KEYBOARD_AAED2000
To compile this driver as a module, choose M here: the
module will be called aaed2000_kbd.
+config KEYBOARD_ADP5520
+ tristate "Keypad Support for ADP5520 PMIC"
+ depends on PMIC_ADP5520
+ help
+ This option enables support for the keypad scan matrix
+ on Analog Devices ADP5520 PMICs.
+
+ To compile this driver as a module, choose M here: the module will
+ be called adp5520-keys.
+
config KEYBOARD_ADP5588
tristate "ADP5588 I2C QWERTY Keypad and IO Expander"
depends on I2C
diff --git a/drivers/input/keyboard/Makefile b/drivers/input/keyboard/Makefile
index babad5e..8fb03c9 100644
--- a/drivers/input/keyboard/Makefile
+++ b/drivers/input/keyboard/Makefile
@@ -5,6 +5,7 @@
# Each configuration option enables a list of files.
obj-$(CONFIG_KEYBOARD_AAED2000) += aaed2000_kbd.o
+obj-$(CONFIG_KEYBOARD_ADP5520) += adp5520-keys.o
obj-$(CONFIG_KEYBOARD_ADP5588) += adp5588-keys.o
obj-$(CONFIG_KEYBOARD_AMIGA) += amikbd.o
obj-$(CONFIG_KEYBOARD_ATARI) += atakbd.o
diff --git a/drivers/input/keyboard/adp5520-keys.c b/drivers/input/keyboard/adp5520-keys.c
new file mode 100644
index 0000000..a7ba27f
--- /dev/null
+++ b/drivers/input/keyboard/adp5520-keys.c
@@ -0,0 +1,220 @@
+/*
+ * Keypad driver for Analog Devices ADP5520 MFD PMICs
+ *
+ * Copyright 2009 Analog Devices Inc.
+ *
+ * Licensed under the GPL-2 or later.
+ */
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/platform_device.h>
+#include <linux/input.h>
+#include <linux/mfd/adp5520.h>
+
+struct adp5520_keys {
+ struct input_dev *input;
+ struct notifier_block notifier;
+ struct device *master;
+ unsigned short keycode[ADP5520_KEYMAPSIZE];
+};
+
+static void adp5520_keys_report_event(struct adp5520_keys *dev,
+ unsigned short keymask, int value)
+{
+ int i;
+
+ for (i = 0; i < ADP5520_MAXKEYS; i++)
+ if (keymask & (1 << i))
+ input_report_key(dev->input, dev->keycode[i], value);
+
+ input_sync(dev->input);
+}
+
+static int adp5520_keys_notifier(struct notifier_block *nb,
+ unsigned long event, void *data)
+{
+ struct adp5520_keys *dev;
+ uint8_t reg_val_lo, reg_val_hi;
+ unsigned short keymask;
+
+ dev = container_of(nb, struct adp5520_keys, notifier);
+
+ if (event & ADP5520_KP_INT) {
+ adp5520_read(dev->master, ADP5520_KP_INT_STAT_1, ®_val_lo);
+ adp5520_read(dev->master, ADP5520_KP_INT_STAT_2, ®_val_hi);
+
+ keymask = (reg_val_hi << 8) | reg_val_lo;
+ /* Read twice to clear */
+ adp5520_read(dev->master, ADP5520_KP_INT_STAT_1, ®_val_lo);
+ adp5520_read(dev->master, ADP5520_KP_INT_STAT_2, ®_val_hi);
+ keymask |= (reg_val_hi << 8) | reg_val_lo;
+ adp5520_keys_report_event(dev, keymask, 1);
+ }
+
+ if (event & ADP5520_KR_INT) {
+ adp5520_read(dev->master, ADP5520_KR_INT_STAT_1, ®_val_lo);
+ adp5520_read(dev->master, ADP5520_KR_INT_STAT_2, ®_val_hi);
+
+ keymask = (reg_val_hi << 8) | reg_val_lo;
+ /* Read twice to clear */
+ adp5520_read(dev->master, ADP5520_KR_INT_STAT_1, ®_val_lo);
+ adp5520_read(dev->master, ADP5520_KR_INT_STAT_2, ®_val_hi);
+ keymask |= (reg_val_hi << 8) | reg_val_lo;
+ adp5520_keys_report_event(dev, keymask, 0);
+ }
+
+ return 0;
+}
+
+static int __devinit adp5520_keys_probe(struct platform_device *pdev)
+{
+ struct adp5520_keys_platform_data *pdata = pdev->dev.platform_data;
+ struct input_dev *input;
+ struct adp5520_keys *dev;
+ int ret, i;
+ unsigned char en_mask, ctl_mask = 0;
+
+ if (pdev->id != ID_ADP5520) {
+ dev_err(&pdev->dev, "only ADP5520 supports Keypad\n");
+ return -EINVAL;
+ }
+
+ if (pdata == NULL) {
+ dev_err(&pdev->dev, "missing platform data\n");
+ return -EINVAL;
+ }
+
+ if (!(pdata->rows_en_mask && pdata->cols_en_mask))
+ return -EINVAL;
+
+ dev = kzalloc(sizeof(*dev), GFP_KERNEL);
+ if (dev == NULL) {
+ dev_err(&pdev->dev, "failed to alloc memory\n");
+ return -ENOMEM;
+ }
+
+ input = input_allocate_device();
+ if (!input) {
+ ret = -ENOMEM;
+ goto err;
+ }
+
+ dev->master = pdev->dev.parent;
+ dev->input = input;
+
+ input->name = pdev->name;
+ input->phys = "adp5520-keys/input0";
+ input->dev.parent = &pdev->dev;
+
+ input_set_drvdata(input, dev);
+
+ input->id.bustype = BUS_I2C;
+ input->id.vendor = 0x0001;
+ input->id.product = 0x5520;
+ input->id.version = 0x0001;
+
+ input->keycodesize = sizeof(dev->keycode[0]);
+ input->keycodemax = pdata->keymapsize;
+ input->keycode = dev->keycode;
+
+ memcpy(dev->keycode, pdata->keymap,
+ pdata->keymapsize * input->keycodesize);
+
+ /* setup input device */
+ __set_bit(EV_KEY, input->evbit);
+
+ if (pdata->repeat)
+ __set_bit(EV_REP, input->evbit);
+
+ for (i = 0; i < input->keycodemax; i++)
+ __set_bit(dev->keycode[i], input->keybit);
+ __clear_bit(KEY_RESERVED, input->keybit);
+
+ ret = input_register_device(input);
+ if (ret) {
+ dev_err(&pdev->dev, "unable to register input device\n");
+ goto err;
+ }
+
+ en_mask = pdata->rows_en_mask | pdata->cols_en_mask;
+
+ ret = adp5520_set_bits(dev->master, ADP5520_GPIO_CFG_1, en_mask);
+
+ if (en_mask & ADP5520_COL_C3)
+ ctl_mask |= ADP5520_C3_MODE;
+
+ if (en_mask & ADP5520_ROW_R3)
+ ctl_mask |= ADP5520_R3_MODE;
+
+ if (ctl_mask)
+ ret |= adp5520_set_bits(dev->master, ADP5520_LED_CONTROL,
+ ctl_mask);
+
+ ret |= adp5520_set_bits(dev->master, ADP5520_GPIO_PULLUP,
+ pdata->rows_en_mask);
+
+ if (ret) {
+ dev_err(&pdev->dev, "failed to write\n");
+ ret = -EIO;
+ goto err1;
+ }
+
+ dev->notifier.notifier_call = adp5520_keys_notifier;
+ ret = adp5520_register_notifier(dev->master, &dev->notifier,
+ ADP5520_KP_IEN | ADP5520_KR_IEN);
+ if (ret) {
+ dev_err(&pdev->dev, "failed to register notifier\n");
+ goto err1;
+ }
+
+ platform_set_drvdata(pdev, dev);
+ return 0;
+
+err1:
+ input_unregister_device(input);
+ input = NULL;
+err:
+ input_free_device(input);
+ kfree(dev);
+ return ret;
+}
+
+static int __devexit adp5520_keys_remove(struct platform_device *pdev)
+{
+ struct adp5520_keys *dev = platform_get_drvdata(pdev);
+
+ adp5520_unregister_notifier(dev->master, &dev->notifier,
+ ADP5520_KP_IEN | ADP5520_KR_IEN);
+
+ input_unregister_device(dev->input);
+ kfree(dev);
+ return 0;
+}
+
+static struct platform_driver adp5520_keys_driver = {
+ .driver = {
+ .name = "adp5520-keys",
+ .owner = THIS_MODULE,
+ },
+ .probe = adp5520_keys_probe,
+ .remove = __devexit_p(adp5520_keys_remove),
+};
+
+static int __init adp5520_keys_init(void)
+{
+ return platform_driver_register(&adp5520_keys_driver);
+}
+module_init(adp5520_keys_init);
+
+static void __exit adp5520_keys_exit(void)
+{
+ platform_driver_unregister(&adp5520_keys_driver);
+}
+module_exit(adp5520_keys_exit);
+
+MODULE_AUTHOR("Michael Hennerich <[email protected]>");
+MODULE_DESCRIPTION("Keys ADP5520 Driver");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:adp5520-keys");
--
1.6.5.rc2
From: Michael Hennerich <[email protected]>
The common adp5520 mfd defines were namespaced to avoid collisions, so
update the define used in this driver accordingly. The structs were also
renamed to fix a spelling typo.
Signed-off-by: Michael Hennerich <[email protected]>
Signed-off-by: Mike Frysinger <[email protected]>
---
drivers/gpio/adp5520-gpio.c | 36 ++++++++++++++++++++----------------
1 files changed, 20 insertions(+), 16 deletions(-)
diff --git a/drivers/gpio/adp5520-gpio.c b/drivers/gpio/adp5520-gpio.c
index ad05bbc..0f93105 100644
--- a/drivers/gpio/adp5520-gpio.c
+++ b/drivers/gpio/adp5520-gpio.c
@@ -34,9 +34,9 @@ static int adp5520_gpio_get_value(struct gpio_chip *chip, unsigned off)
*/
if (test_bit(off, &dev->output))
- adp5520_read(dev->master, GPIO_OUT, ®_val);
+ adp5520_read(dev->master, ADP5520_GPIO_OUT, ®_val);
else
- adp5520_read(dev->master, GPIO_IN, ®_val);
+ adp5520_read(dev->master, ADP5520_GPIO_IN, ®_val);
return !!(reg_val & dev->lut[off]);
}
@@ -48,9 +48,9 @@ static void adp5520_gpio_set_value(struct gpio_chip *chip,
dev = container_of(chip, struct adp5520_gpio, gpio_chip);
if (val)
- adp5520_set_bits(dev->master, GPIO_OUT, dev->lut[off]);
+ adp5520_set_bits(dev->master, ADP5520_GPIO_OUT, dev->lut[off]);
else
- adp5520_clr_bits(dev->master, GPIO_OUT, dev->lut[off]);
+ adp5520_clr_bits(dev->master, ADP5520_GPIO_OUT, dev->lut[off]);
}
static int adp5520_gpio_direction_input(struct gpio_chip *chip, unsigned off)
@@ -60,7 +60,8 @@ static int adp5520_gpio_direction_input(struct gpio_chip *chip, unsigned off)
clear_bit(off, &dev->output);
- return adp5520_clr_bits(dev->master, GPIO_CFG_2, dev->lut[off]);
+ return adp5520_clr_bits(dev->master, ADP5520_GPIO_CFG_2,
+ dev->lut[off]);
}
static int adp5520_gpio_direction_output(struct gpio_chip *chip,
@@ -73,18 +74,21 @@ static int adp5520_gpio_direction_output(struct gpio_chip *chip,
set_bit(off, &dev->output);
if (val)
- ret |= adp5520_set_bits(dev->master, GPIO_OUT, dev->lut[off]);
+ ret |= adp5520_set_bits(dev->master, ADP5520_GPIO_OUT,
+ dev->lut[off]);
else
- ret |= adp5520_clr_bits(dev->master, GPIO_OUT, dev->lut[off]);
+ ret |= adp5520_clr_bits(dev->master, ADP5520_GPIO_OUT,
+ dev->lut[off]);
- ret |= adp5520_set_bits(dev->master, GPIO_CFG_2, dev->lut[off]);
+ ret |= adp5520_set_bits(dev->master, ADP5520_GPIO_CFG_2,
+ dev->lut[off]);
return ret;
}
static int __devinit adp5520_gpio_probe(struct platform_device *pdev)
{
- struct adp5520_gpio_platfrom_data *pdata = pdev->dev.platform_data;
+ struct adp5520_gpio_platform_data *pdata = pdev->dev.platform_data;
struct adp5520_gpio *dev;
struct gpio_chip *gc;
int ret, i, gpios;
@@ -129,20 +133,20 @@ static int __devinit adp5520_gpio_probe(struct platform_device *pdev)
gc->label = pdev->name;
gc->owner = THIS_MODULE;
- ret = adp5520_clr_bits(dev->master, GPIO_CFG_1,
+ ret = adp5520_clr_bits(dev->master, ADP5520_GPIO_CFG_1,
pdata->gpio_en_mask);
- if (pdata->gpio_en_mask & GPIO_C3)
- ctl_mask |= C3_MODE;
+ if (pdata->gpio_en_mask & ADP5520_GPIO_C3)
+ ctl_mask |= ADP5520_C3_MODE;
- if (pdata->gpio_en_mask & GPIO_R3)
- ctl_mask |= R3_MODE;
+ if (pdata->gpio_en_mask & ADP5520_GPIO_R3)
+ ctl_mask |= ADP5520_R3_MODE;
if (ctl_mask)
- ret = adp5520_set_bits(dev->master, LED_CONTROL,
+ ret = adp5520_set_bits(dev->master, ADP5520_LED_CONTROL,
ctl_mask);
- ret |= adp5520_set_bits(dev->master, GPIO_PULLUP,
+ ret |= adp5520_set_bits(dev->master, ADP5520_GPIO_PULLUP,
pdata->gpio_pullup_mask);
if (ret) {
--
1.6.5.rc2
From: Michael Hennerich <[email protected]>
The common adp5520 mfd defines were namespaced to avoid collisions, so
update the define used in this driver accordingly. The structs were also
renamed to fix a spelling typo.
Signed-off-by: Michael Hennerich <[email protected]>
Signed-off-by: Mike Frysinger <[email protected]>
---
drivers/video/backlight/adp5520_bl.c | 123 +++++++++++++++++++---------------
1 files changed, 70 insertions(+), 53 deletions(-)
diff --git a/drivers/video/backlight/adp5520_bl.c b/drivers/video/backlight/adp5520_bl.c
index ad05da5..4c10ede 100644
--- a/drivers/video/backlight/adp5520_bl.c
+++ b/drivers/video/backlight/adp5520_bl.c
@@ -15,7 +15,7 @@
struct adp5520_bl {
struct device *master;
- struct adp5520_backlight_platfrom_data *pdata;
+ struct adp5520_backlight_platform_data *pdata;
struct mutex lock;
unsigned long cached_daylight_max;
int id;
@@ -31,29 +31,30 @@ static int adp5520_bl_set(struct backlight_device *bl, int brightness)
if (data->pdata->en_ambl_sens) {
if ((brightness > 0) && (brightness < ADP5020_MAX_BRIGHTNESS)) {
/* Disable Ambient Light auto adjust */
- ret |= adp5520_clr_bits(master, BL_CONTROL,
- BL_AUTO_ADJ);
- ret |= adp5520_write(master, DAYLIGHT_MAX, brightness);
+ ret |= adp5520_clr_bits(master, ADP5520_BL_CONTROL,
+ ADP5520_BL_AUTO_ADJ);
+ ret |= adp5520_write(master, ADP5520_DAYLIGHT_MAX,
+ brightness);
} else {
/*
* MAX_BRIGHTNESS -> Enable Ambient Light auto adjust
* restore daylight l3 sysfs brightness
*/
- ret |= adp5520_write(master, DAYLIGHT_MAX,
+ ret |= adp5520_write(master, ADP5520_DAYLIGHT_MAX,
data->cached_daylight_max);
- ret |= adp5520_set_bits(master, BL_CONTROL,
- BL_AUTO_ADJ);
+ ret |= adp5520_set_bits(master, ADP5520_BL_CONTROL,
+ ADP5520_BL_AUTO_ADJ);
}
} else {
- ret |= adp5520_write(master, DAYLIGHT_MAX, brightness);
+ ret |= adp5520_write(master, ADP5520_DAYLIGHT_MAX, brightness);
}
if (data->current_brightness && brightness == 0)
ret |= adp5520_set_bits(master,
- MODE_STATUS, DIM_EN);
+ ADP5520_MODE_STATUS, ADP5520_DIM_EN);
else if (data->current_brightness == 0 && brightness)
ret |= adp5520_clr_bits(master,
- MODE_STATUS, DIM_EN);
+ ADP5520_MODE_STATUS, ADP5520_DIM_EN);
if (!ret)
data->current_brightness = brightness;
@@ -79,7 +80,7 @@ static int adp5520_bl_get_brightness(struct backlight_device *bl)
int error;
uint8_t reg_val;
- error = adp5520_read(data->master, BL_VALUE, ®_val);
+ error = adp5520_read(data->master, ADP5520_BL_VALUE, ®_val);
return error ? data->current_brightness : reg_val;
}
@@ -93,33 +94,46 @@ static int adp5520_bl_setup(struct backlight_device *bl)
{
struct adp5520_bl *data = bl_get_data(bl);
struct device *master = data->master;
- struct adp5520_backlight_platfrom_data *pdata = data->pdata;
+ struct adp5520_backlight_platform_data *pdata = data->pdata;
int ret = 0;
- ret |= adp5520_write(master, DAYLIGHT_MAX, pdata->l1_daylight_max);
- ret |= adp5520_write(master, DAYLIGHT_DIM, pdata->l1_daylight_dim);
+ ret |= adp5520_write(master, ADP5520_DAYLIGHT_MAX,
+ pdata->l1_daylight_max);
+ ret |= adp5520_write(master, ADP5520_DAYLIGHT_DIM,
+ pdata->l1_daylight_dim);
if (pdata->en_ambl_sens) {
data->cached_daylight_max = pdata->l1_daylight_max;
- ret |= adp5520_write(master, OFFICE_MAX, pdata->l2_office_max);
- ret |= adp5520_write(master, OFFICE_DIM, pdata->l2_office_dim);
- ret |= adp5520_write(master, DARK_MAX, pdata->l3_dark_max);
- ret |= adp5520_write(master, DARK_DIM, pdata->l3_dark_dim);
- ret |= adp5520_write(master, L2_TRIP, pdata->l2_trip);
- ret |= adp5520_write(master, L2_HYS, pdata->l2_hyst);
- ret |= adp5520_write(master, L3_TRIP, pdata->l3_trip);
- ret |= adp5520_write(master, L3_HYS, pdata->l3_hyst);
- ret |= adp5520_write(master, ALS_CMPR_CFG,
- ALS_CMPR_CFG_VAL(pdata->abml_filt, L3_EN));
+ ret |= adp5520_write(master, ADP5520_OFFICE_MAX,
+ pdata->l2_office_max);
+ ret |= adp5520_write(master, ADP5520_OFFICE_DIM,
+ pdata->l2_office_dim);
+ ret |= adp5520_write(master, ADP5520_DARK_MAX,
+ pdata->l3_dark_max);
+ ret |= adp5520_write(master, ADP5520_DARK_DIM,
+ pdata->l3_dark_dim);
+ ret |= adp5520_write(master, ADP5520_L2_TRIP,
+ pdata->l2_trip);
+ ret |= adp5520_write(master, ADP5520_L2_HYS,
+ pdata->l2_hyst);
+ ret |= adp5520_write(master, ADP5520_L3_TRIP,
+ pdata->l3_trip);
+ ret |= adp5520_write(master, ADP5520_L3_HYS,
+ pdata->l3_hyst);
+ ret |= adp5520_write(master, ADP5520_ALS_CMPR_CFG,
+ ALS_CMPR_CFG_VAL(pdata->abml_filt,
+ ADP5520_L3_EN));
}
- ret |= adp5520_write(master, BL_CONTROL,
- BL_CTRL_VAL(pdata->fade_led_law, pdata->en_ambl_sens));
+ ret |= adp5520_write(master, ADP5520_BL_CONTROL,
+ BL_CTRL_VAL(pdata->fade_led_law,
+ pdata->en_ambl_sens));
- ret |= adp5520_write(master, BL_FADE, FADE_VAL(pdata->fade_in,
+ ret |= adp5520_write(master, ADP5520_BL_FADE, FADE_VAL(pdata->fade_in,
pdata->fade_out));
- ret |= adp5520_set_bits(master, MODE_STATUS, BL_EN | DIM_EN);
+ ret |= adp5520_set_bits(master, ADP5520_MODE_STATUS,
+ ADP5520_BL_EN | ADP5520_DIM_EN);
return ret;
}
@@ -156,29 +170,31 @@ static ssize_t adp5520_store(struct device *dev, const char *buf,
}
static ssize_t adp5520_bl_dark_max_show(struct device *dev,
- struct device_attribute *attr, char *buf)
+ struct device_attribute *attr, char *buf)
{
- return adp5520_show(dev, buf, DARK_MAX);
+ return adp5520_show(dev, buf, ADP5520_DARK_MAX);
}
static ssize_t adp5520_bl_dark_max_store(struct device *dev,
- struct device_attribute *attr, const char *buf, size_t count)
+ struct device_attribute *attr,
+ const char *buf, size_t count)
{
- return adp5520_store(dev, buf, count, DARK_MAX);
+ return adp5520_store(dev, buf, count, ADP5520_DARK_MAX);
}
static DEVICE_ATTR(dark_max, 0664, adp5520_bl_dark_max_show,
adp5520_bl_dark_max_store);
static ssize_t adp5520_bl_office_max_show(struct device *dev,
- struct device_attribute *attr, char *buf)
+ struct device_attribute *attr, char *buf)
{
- return adp5520_show(dev, buf, OFFICE_MAX);
+ return adp5520_show(dev, buf, ADP5520_OFFICE_MAX);
}
static ssize_t adp5520_bl_office_max_store(struct device *dev,
- struct device_attribute *attr, const char *buf, size_t count)
+ struct device_attribute *attr,
+ const char *buf, size_t count)
{
- return adp5520_store(dev, buf, count, OFFICE_MAX);
+ return adp5520_store(dev, buf, count, ADP5520_OFFICE_MAX);
}
static DEVICE_ATTR(office_max, 0664, adp5520_bl_office_max_show,
adp5520_bl_office_max_store);
@@ -186,16 +202,17 @@ static DEVICE_ATTR(office_max, 0664, adp5520_bl_office_max_show,
static ssize_t adp5520_bl_daylight_max_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
- return adp5520_show(dev, buf, DAYLIGHT_MAX);
+ return adp5520_show(dev, buf, ADP5520_DAYLIGHT_MAX);
}
static ssize_t adp5520_bl_daylight_max_store(struct device *dev,
- struct device_attribute *attr, const char *buf, size_t count)
+ struct device_attribute *attr,
+ const char *buf, size_t count)
{
struct adp5520_bl *data = dev_get_drvdata(dev);
strict_strtoul(buf, 10, &data->cached_daylight_max);
- return adp5520_store(dev, buf, count, DAYLIGHT_MAX);
+ return adp5520_store(dev, buf, count, ADP5520_DAYLIGHT_MAX);
}
static DEVICE_ATTR(daylight_max, 0664, adp5520_bl_daylight_max_show,
adp5520_bl_daylight_max_store);
@@ -203,14 +220,14 @@ static DEVICE_ATTR(daylight_max, 0664, adp5520_bl_daylight_max_show,
static ssize_t adp5520_bl_dark_dim_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
- return adp5520_show(dev, buf, DARK_DIM);
+ return adp5520_show(dev, buf, ADP5520_DARK_DIM);
}
static ssize_t adp5520_bl_dark_dim_store(struct device *dev,
- struct device_attribute *attr,
- const char *buf, size_t count)
+ struct device_attribute *attr,
+ const char *buf, size_t count)
{
- return adp5520_store(dev, buf, count, DARK_DIM);
+ return adp5520_store(dev, buf, count, ADP5520_DARK_DIM);
}
static DEVICE_ATTR(dark_dim, 0664, adp5520_bl_dark_dim_show,
adp5520_bl_dark_dim_store);
@@ -218,29 +235,29 @@ static DEVICE_ATTR(dark_dim, 0664, adp5520_bl_dark_dim_show,
static ssize_t adp5520_bl_office_dim_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
- return adp5520_show(dev, buf, OFFICE_DIM);
+ return adp5520_show(dev, buf, ADP5520_OFFICE_DIM);
}
static ssize_t adp5520_bl_office_dim_store(struct device *dev,
- struct device_attribute *attr,
- const char *buf, size_t count)
+ struct device_attribute *attr,
+ const char *buf, size_t count)
{
- return adp5520_store(dev, buf, count, OFFICE_DIM);
+ return adp5520_store(dev, buf, count, ADP5520_OFFICE_DIM);
}
static DEVICE_ATTR(office_dim, 0664, adp5520_bl_office_dim_show,
adp5520_bl_office_dim_store);
static ssize_t adp5520_bl_daylight_dim_show(struct device *dev,
- struct device_attribute *attr, char *buf)
+ struct device_attribute *attr, char *buf)
{
- return adp5520_show(dev, buf, DAYLIGHT_DIM);
+ return adp5520_show(dev, buf, ADP5520_DAYLIGHT_DIM);
}
static ssize_t adp5520_bl_daylight_dim_store(struct device *dev,
- struct device_attribute *attr,
- const char *buf, size_t count)
+ struct device_attribute *attr,
+ const char *buf, size_t count)
{
- return adp5520_store(dev, buf, count, DAYLIGHT_DIM);
+ return adp5520_store(dev, buf, count, ADP5520_DAYLIGHT_DIM);
}
static DEVICE_ATTR(daylight_dim, 0664, adp5520_bl_daylight_dim_show,
adp5520_bl_daylight_dim_store);
@@ -316,7 +333,7 @@ static int __devexit adp5520_bl_remove(struct platform_device *pdev)
struct backlight_device *bl = platform_get_drvdata(pdev);
struct adp5520_bl *data = bl_get_data(bl);
- adp5520_clr_bits(data->master, MODE_STATUS, BL_EN);
+ adp5520_clr_bits(data->master, ADP5520_MODE_STATUS, ADP5520_BL_EN);
if (data->pdata->en_ambl_sens)
sysfs_remove_group(&bl->dev.kobj,
--
1.6.5.rc2
Hi Mike,
On Sat, Oct 10, 2009 at 01:54:00PM -0400, Mike Frysinger wrote:
> From: Michael Hennerich <[email protected]>
>
> Base driver for Analog Devices ADP5520/ADP5501 MFD PMICs
MFD and GPIO, backlight and input drivers applied, thanks.
About the LED one, I would really appreciate if you could have the LED
maintainer review it or/and ack it.
Cheers,
Samuel.
> Subdevs:
> LCD Backlight : drivers/video/backlight/adp5520_bl
> LEDs : drivers/led/leds-adp5520
> GPIO : drivers/gpio/adp5520-gpio (ADP5520 only)
> Keys : drivers/input/keyboard/adp5520-keys (ADP5520 only)
>
> Signed-off-by: Michael Hennerich <[email protected]>
> Signed-off-by: Bryan Wu <[email protected]>
> Signed-off-by: Mike Frysinger <[email protected]>
> ---
> drivers/mfd/Kconfig | 10 ++
> drivers/mfd/Makefile | 1 +
> drivers/mfd/adp5520.c | 378 +++++++++++++++++++++++++++++++++++++++++++
> include/linux/mfd/adp5520.h | 299 ++++++++++++++++++++++++++++++++++
> 4 files changed, 688 insertions(+), 0 deletions(-)
> create mode 100644 drivers/mfd/adp5520.c
> create mode 100644 include/linux/mfd/adp5520.h
>
> diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
> index 570be13..34e8595 100644
> --- a/drivers/mfd/Kconfig
> +++ b/drivers/mfd/Kconfig
> @@ -160,6 +160,16 @@ config PMIC_DA903X
> individual components like LCD backlight, voltage regulators,
> LEDs and battery-charger under the corresponding menus.
>
> +config PMIC_ADP5520
> + bool "Analog Devices ADP5520/01 MFD PMIC Core Support"
> + depends on I2C=y
> + help
> + Say yes here to add support for Analog Devices AD5520 and ADP5501,
> + Multifunction Power Management IC. This includes
> + the I2C driver and the core APIs _only_, you have to select
> + individual components like LCD backlight, LEDs, GPIOs and Kepad
> + under the corresponding menus.
> +
> config MFD_WM8400
> tristate "Support Wolfson Microelectronics WM8400"
> select MFD_CORE
> diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
> index f3b277b..a42248e 100644
> --- a/drivers/mfd/Makefile
> +++ b/drivers/mfd/Makefile
> @@ -50,3 +50,4 @@ obj-$(CONFIG_PCF50633_ADC) += pcf50633-adc.o
> obj-$(CONFIG_PCF50633_GPIO) += pcf50633-gpio.o
> obj-$(CONFIG_AB3100_CORE) += ab3100-core.o
> obj-$(CONFIG_AB3100_OTP) += ab3100-otp.o
> +obj-$(CONFIG_PMIC_ADP5520) += adp5520.o
> diff --git a/drivers/mfd/adp5520.c b/drivers/mfd/adp5520.c
> new file mode 100644
> index 0000000..401a9b6
> --- /dev/null
> +++ b/drivers/mfd/adp5520.c
> @@ -0,0 +1,378 @@
> +/*
> + * Base driver for Analog Devices ADP5520/ADP5501 MFD PMICs
> + * LCD Backlight: drivers/video/backlight/adp5520_bl
> + * LEDs : drivers/led/leds-adp5520
> + * GPIO : drivers/gpio/adp5520-gpio (ADP5520 only)
> + * Keys : drivers/input/keyboard/adp5520-keys (ADP5520 only)
> + *
> + * Copyright 2009 Analog Devices Inc.
> + *
> + * Derived from da903x:
> + * Copyright (C) 2008 Compulab, Ltd.
> + * Mike Rapoport <[email protected]>
> + *
> + * Copyright (C) 2006-2008 Marvell International Ltd.
> + * Eric Miao <[email protected]>
> + *
> + * Licensed under the GPL-2 or later.
> + */
> +
> +#include <linux/kernel.h>
> +#include <linux/module.h>
> +#include <linux/platform_device.h>
> +#include <linux/init.h>
> +#include <linux/interrupt.h>
> +#include <linux/irq.h>
> +#include <linux/err.h>
> +#include <linux/i2c.h>
> +
> +#include <linux/mfd/adp5520.h>
> +
> +struct adp5520_chip {
> + struct i2c_client *client;
> + struct device *dev;
> + struct mutex lock;
> + struct blocking_notifier_head notifier_list;
> + int irq;
> + unsigned long id;
> +};
> +
> +static int __adp5520_read(struct i2c_client *client,
> + int reg, uint8_t *val)
> +{
> + int ret;
> +
> + ret = i2c_smbus_read_byte_data(client, reg);
> + if (ret < 0) {
> + dev_err(&client->dev, "failed reading at 0x%02x\n", reg);
> + return ret;
> + }
> +
> + *val = (uint8_t)ret;
> + return 0;
> +}
> +
> +static int __adp5520_write(struct i2c_client *client,
> + int reg, uint8_t val)
> +{
> + int ret;
> +
> + ret = i2c_smbus_write_byte_data(client, reg, val);
> + if (ret < 0) {
> + dev_err(&client->dev, "failed writing 0x%02x to 0x%02x\n",
> + val, reg);
> + return ret;
> + }
> + return 0;
> +}
> +
> +int __adp5520_ack_bits(struct i2c_client *client, int reg, uint8_t bit_mask)
> +{
> + struct adp5520_chip *chip = i2c_get_clientdata(client);
> + uint8_t reg_val;
> + int ret;
> +
> + mutex_lock(&chip->lock);
> +
> + ret = __adp5520_read(client, reg, ®_val);
> +
> + if (!ret) {
> + reg_val |= bit_mask;
> + ret = __adp5520_write(client, reg, reg_val);
> + }
> +
> + mutex_unlock(&chip->lock);
> + return ret;
> +}
> +
> +int adp5520_write(struct device *dev, int reg, uint8_t val)
> +{
> + return __adp5520_write(to_i2c_client(dev), reg, val);
> +}
> +EXPORT_SYMBOL_GPL(adp5520_write);
> +
> +int adp5520_read(struct device *dev, int reg, uint8_t *val)
> +{
> + return __adp5520_read(to_i2c_client(dev), reg, val);
> +}
> +EXPORT_SYMBOL_GPL(adp5520_read);
> +
> +int adp5520_set_bits(struct device *dev, int reg, uint8_t bit_mask)
> +{
> + struct adp5520_chip *chip = dev_get_drvdata(dev);
> + uint8_t reg_val;
> + int ret;
> +
> + mutex_lock(&chip->lock);
> +
> + ret = __adp5520_read(chip->client, reg, ®_val);
> +
> + if (!ret && ((reg_val & bit_mask) == 0)) {
> + reg_val |= bit_mask;
> + ret = __adp5520_write(chip->client, reg, reg_val);
> + }
> +
> + mutex_unlock(&chip->lock);
> + return ret;
> +}
> +EXPORT_SYMBOL_GPL(adp5520_set_bits);
> +
> +int adp5520_clr_bits(struct device *dev, int reg, uint8_t bit_mask)
> +{
> + struct adp5520_chip *chip = dev_get_drvdata(dev);
> + uint8_t reg_val;
> + int ret;
> +
> + mutex_lock(&chip->lock);
> +
> + ret = __adp5520_read(chip->client, reg, ®_val);
> +
> + if (!ret && (reg_val & bit_mask)) {
> + reg_val &= ~bit_mask;
> + ret = __adp5520_write(chip->client, reg, reg_val);
> + }
> +
> + mutex_unlock(&chip->lock);
> + return ret;
> +}
> +EXPORT_SYMBOL_GPL(adp5520_clr_bits);
> +
> +int adp5520_register_notifier(struct device *dev, struct notifier_block *nb,
> + unsigned int events)
> +{
> + struct adp5520_chip *chip = dev_get_drvdata(dev);
> +
> + if (chip->irq) {
> + adp5520_set_bits(chip->dev, ADP5520_INTERRUPT_ENABLE,
> + events & (ADP5520_KP_IEN | ADP5520_KR_IEN |
> + ADP5520_OVP_IEN | ADP5520_CMPR_IEN));
> +
> + return blocking_notifier_chain_register(&chip->notifier_list,
> + nb);
> + }
> +
> + return -ENODEV;
> +}
> +EXPORT_SYMBOL_GPL(adp5520_register_notifier);
> +
> +int adp5520_unregister_notifier(struct device *dev, struct notifier_block *nb,
> + unsigned int events)
> +{
> + struct adp5520_chip *chip = dev_get_drvdata(dev);
> +
> + adp5520_clr_bits(chip->dev, ADP5520_INTERRUPT_ENABLE,
> + events & (ADP5520_KP_IEN | ADP5520_KR_IEN |
> + ADP5520_OVP_IEN | ADP5520_CMPR_IEN));
> +
> + return blocking_notifier_chain_unregister(&chip->notifier_list, nb);
> +}
> +EXPORT_SYMBOL_GPL(adp5520_unregister_notifier);
> +
> +static irqreturn_t adp5520_irq_thread(int irq, void *data)
> +{
> + struct adp5520_chip *chip = data;
> + unsigned int events;
> + uint8_t reg_val;
> + int ret;
> +
> + ret = __adp5520_read(chip->client, ADP5520_MODE_STATUS, ®_val);
> + if (ret)
> + goto out;
> +
> + events = reg_val & (ADP5520_OVP_INT | ADP5520_CMPR_INT |
> + ADP5520_GPI_INT | ADP5520_KR_INT | ADP5520_KP_INT);
> +
> + blocking_notifier_call_chain(&chip->notifier_list, events, NULL);
> + /* ACK, Sticky bits are W1C */
> + __adp5520_ack_bits(chip->client, ADP5520_MODE_STATUS, events);
> +
> +out:
> + return IRQ_HANDLED;
> +}
> +
> +static int __remove_subdev(struct device *dev, void *unused)
> +{
> + platform_device_unregister(to_platform_device(dev));
> + return 0;
> +}
> +
> +static int adp5520_remove_subdevs(struct adp5520_chip *chip)
> +{
> + return device_for_each_child(chip->dev, NULL, __remove_subdev);
> +}
> +
> +static int __devinit adp5520_probe(struct i2c_client *client,
> + const struct i2c_device_id *id)
> +{
> + struct adp5520_platform_data *pdata = client->dev.platform_data;
> + struct platform_device *pdev;
> + struct adp5520_chip *chip;
> + int ret;
> +
> + if (!i2c_check_functionality(client->adapter,
> + I2C_FUNC_SMBUS_BYTE_DATA)) {
> + dev_err(&client->dev, "SMBUS Word Data not Supported\n");
> + return -EIO;
> + }
> +
> + if (pdata == NULL) {
> + dev_err(&client->dev, "missing platform data\n");
> + return -ENODEV;
> + }
> +
> + chip = kzalloc(sizeof(*chip), GFP_KERNEL);
> + if (!chip)
> + return -ENOMEM;
> +
> + i2c_set_clientdata(client, chip);
> + chip->client = client;
> +
> + chip->dev = &client->dev;
> + chip->irq = client->irq;
> + chip->id = id->driver_data;
> + mutex_init(&chip->lock);
> +
> + if (chip->irq) {
> + BLOCKING_INIT_NOTIFIER_HEAD(&chip->notifier_list);
> +
> + ret = request_threaded_irq(chip->irq, NULL, adp5520_irq_thread,
> + IRQF_TRIGGER_LOW | IRQF_ONESHOT,
> + "adp5520", chip);
> + if (ret) {
> + dev_err(&client->dev, "failed to request irq %d\n",
> + chip->irq);
> + goto out_free_chip;
> + }
> + }
> +
> + ret = adp5520_write(chip->dev, ADP5520_MODE_STATUS, ADP5520_nSTNBY);
> + if (ret) {
> + dev_err(&client->dev, "failed to write\n");
> + goto out_free_irq;
> + }
> +
> + if (pdata->keys) {
> + pdev = platform_device_register_data(chip->dev, "adp5520-keys",
> + chip->id, pdata->keys, sizeof(*pdata->keys));
> + if (IS_ERR(pdev)) {
> + ret = PTR_ERR(pdev);
> + goto out_remove_subdevs;
> + }
> + }
> +
> + if (pdata->gpio) {
> + pdev = platform_device_register_data(chip->dev, "adp5520-gpio",
> + chip->id, pdata->gpio, sizeof(*pdata->gpio));
> + if (IS_ERR(pdev)) {
> + ret = PTR_ERR(pdev);
> + goto out_remove_subdevs;
> + }
> + }
> +
> + if (pdata->leds) {
> + pdev = platform_device_register_data(chip->dev, "adp5520-led",
> + chip->id, pdata->leds, sizeof(*pdata->leds));
> + if (IS_ERR(pdev)) {
> + ret = PTR_ERR(pdev);
> + goto out_remove_subdevs;
> + }
> + }
> +
> + if (pdata->backlight) {
> + pdev = platform_device_register_data(chip->dev,
> + "adp5520-backlight",
> + chip->id,
> + pdata->backlight,
> + sizeof(*pdata->backlight));
> + if (IS_ERR(pdev)) {
> + ret = PTR_ERR(pdev);
> + goto out_remove_subdevs;
> + }
> + }
> +
> + return 0;
> +
> +out_remove_subdevs:
> + adp5520_remove_subdevs(chip);
> +
> +out_free_irq:
> + if (chip->irq)
> + free_irq(chip->irq, chip);
> +
> +out_free_chip:
> + i2c_set_clientdata(client, NULL);
> + kfree(chip);
> +
> + return ret;
> +}
> +
> +static int __devexit adp5520_remove(struct i2c_client *client)
> +{
> + struct adp5520_chip *chip = dev_get_drvdata(&client->dev);
> +
> + if (chip->irq)
> + free_irq(chip->irq, chip);
> +
> + adp5520_remove_subdevs(chip);
> + adp5520_write(chip->dev, ADP5520_MODE_STATUS, 0);
> + i2c_set_clientdata(client, NULL);
> + kfree(chip);
> + return 0;
> +}
> +
> +#ifdef CONFIG_PM
> +static int adp5520_suspend(struct i2c_client *client,
> + pm_message_t state)
> +{
> + struct adp5520_chip *chip = dev_get_drvdata(&client->dev);
> +
> + adp5520_clr_bits(chip->dev, ADP5520_MODE_STATUS, ADP5520_nSTNBY);
> + return 0;
> +}
> +
> +static int adp5520_resume(struct i2c_client *client)
> +{
> + struct adp5520_chip *chip = dev_get_drvdata(&client->dev);
> +
> + adp5520_set_bits(chip->dev, ADP5520_MODE_STATUS, ADP5520_nSTNBY);
> + return 0;
> +}
> +#else
> +#define adp5520_suspend NULL
> +#define adp5520_resume NULL
> +#endif
> +
> +static const struct i2c_device_id adp5520_id[] = {
> + { "pmic-adp5520", ID_ADP5520 },
> + { "pmic-adp5501", ID_ADP5501 },
> + { }
> +};
> +MODULE_DEVICE_TABLE(i2c, adp5520_id);
> +
> +static struct i2c_driver adp5520_driver = {
> + .driver = {
> + .name = "adp5520",
> + .owner = THIS_MODULE,
> + },
> + .probe = adp5520_probe,
> + .remove = __devexit_p(adp5520_remove),
> + .suspend = adp5520_suspend,
> + .resume = adp5520_resume,
> + .id_table = adp5520_id,
> +};
> +
> +static int __init adp5520_init(void)
> +{
> + return i2c_add_driver(&adp5520_driver);
> +}
> +module_init(adp5520_init);
> +
> +static void __exit adp5520_exit(void)
> +{
> + i2c_del_driver(&adp5520_driver);
> +}
> +module_exit(adp5520_exit);
> +
> +MODULE_AUTHOR("Michael Hennerich <[email protected]>");
> +MODULE_DESCRIPTION("ADP5520(01) PMIC-MFD Driver");
> +MODULE_LICENSE("GPL");
> diff --git a/include/linux/mfd/adp5520.h b/include/linux/mfd/adp5520.h
> new file mode 100644
> index 0000000..ac37558
> --- /dev/null
> +++ b/include/linux/mfd/adp5520.h
> @@ -0,0 +1,299 @@
> +/*
> + * Definitions and platform data for Analog Devices
> + * ADP5520/ADP5501 MFD PMICs (Backlight, LED, GPIO and Keys)
> + *
> + * Copyright 2009 Analog Devices Inc.
> + *
> + * Licensed under the GPL-2 or later.
> + */
> +
> +
> +#ifndef __LINUX_MFD_ADP5520_H
> +#define __LINUX_MFD_ADP5520_H
> +
> +#define ID_ADP5520 5520
> +#define ID_ADP5501 5501
> +
> +/*
> + * ADP5520/ADP5501 Register Map
> + */
> +
> +#define ADP5520_MODE_STATUS 0x00
> +#define ADP5520_INTERRUPT_ENABLE 0x01
> +#define ADP5520_BL_CONTROL 0x02
> +#define ADP5520_BL_TIME 0x03
> +#define ADP5520_BL_FADE 0x04
> +#define ADP5520_DAYLIGHT_MAX 0x05
> +#define ADP5520_DAYLIGHT_DIM 0x06
> +#define ADP5520_OFFICE_MAX 0x07
> +#define ADP5520_OFFICE_DIM 0x08
> +#define ADP5520_DARK_MAX 0x09
> +#define ADP5520_DARK_DIM 0x0A
> +#define ADP5520_BL_VALUE 0x0B
> +#define ADP5520_ALS_CMPR_CFG 0x0C
> +#define ADP5520_L2_TRIP 0x0D
> +#define ADP5520_L2_HYS 0x0E
> +#define ADP5520_L3_TRIP 0x0F
> +#define ADP5520_L3_HYS 0x10
> +#define ADP5520_LED_CONTROL 0x11
> +#define ADP5520_LED_TIME 0x12
> +#define ADP5520_LED_FADE 0x13
> +#define ADP5520_LED1_CURRENT 0x14
> +#define ADP5520_LED2_CURRENT 0x15
> +#define ADP5520_LED3_CURRENT 0x16
> +
> +/*
> + * ADP5520 Register Map
> + */
> +
> +#define ADP5520_GPIO_CFG_1 0x17
> +#define ADP5520_GPIO_CFG_2 0x18
> +#define ADP5520_GPIO_IN 0x19
> +#define ADP5520_GPIO_OUT 0x1A
> +#define ADP5520_GPIO_INT_EN 0x1B
> +#define ADP5520_GPIO_INT_STAT 0x1C
> +#define ADP5520_GPIO_INT_LVL 0x1D
> +#define ADP5520_GPIO_DEBOUNCE 0x1E
> +#define ADP5520_GPIO_PULLUP 0x1F
> +#define ADP5520_KP_INT_STAT_1 0x20
> +#define ADP5520_KP_INT_STAT_2 0x21
> +#define ADP5520_KR_INT_STAT_1 0x22
> +#define ADP5520_KR_INT_STAT_2 0x23
> +#define ADP5520_KEY_STAT_1 0x24
> +#define ADP5520_KEY_STAT_2 0x25
> +
> +/*
> + * MODE_STATUS bits
> + */
> +
> +#define ADP5520_nSTNBY (1 << 7)
> +#define ADP5520_BL_EN (1 << 6)
> +#define ADP5520_DIM_EN (1 << 5)
> +#define ADP5520_OVP_INT (1 << 4)
> +#define ADP5520_CMPR_INT (1 << 3)
> +#define ADP5520_GPI_INT (1 << 2)
> +#define ADP5520_KR_INT (1 << 1)
> +#define ADP5520_KP_INT (1 << 0)
> +
> +/*
> + * INTERRUPT_ENABLE bits
> + */
> +
> +#define ADP5520_AUTO_LD_EN (1 << 4)
> +#define ADP5520_CMPR_IEN (1 << 3)
> +#define ADP5520_OVP_IEN (1 << 2)
> +#define ADP5520_KR_IEN (1 << 1)
> +#define ADP5520_KP_IEN (1 << 0)
> +
> +/*
> + * BL_CONTROL bits
> + */
> +
> +#define ADP5520_BL_LVL ((x) << 5)
> +#define ADP5520_BL_LAW ((x) << 4)
> +#define ADP5520_BL_AUTO_ADJ (1 << 3)
> +#define ADP5520_OVP_EN (1 << 2)
> +#define ADP5520_FOVR (1 << 1)
> +#define ADP5520_KP_BL_EN (1 << 0)
> +
> +/*
> + * ALS_CMPR_CFG bits
> + */
> +
> +#define ADP5520_L3_OUT (1 << 3)
> +#define ADP5520_L2_OUT (1 << 2)
> +#define ADP5520_L3_EN (1 << 1)
> +
> +#define ADP5020_MAX_BRIGHTNESS 0x7F
> +
> +#define FADE_VAL(in, out) ((0xF & (in)) | ((0xF & (out)) << 4))
> +#define BL_CTRL_VAL(law, auto) (((1 & (auto)) << 3) | ((0x3 & (law)) << 4))
> +#define ALS_CMPR_CFG_VAL(filt, l3_en) (((0x7 & filt) << 5) | l3_en)
> +
> +/*
> + * LEDs subdevice bits and masks
> + */
> +
> +#define ADP5520_01_MAXLEDS 3
> +
> +#define ADP5520_FLAG_LED_MASK 0x3
> +#define ADP5520_FLAG_OFFT_SHIFT 8
> +#define ADP5520_FLAG_OFFT_MASK 0x3
> +
> +#define ADP5520_R3_MODE (1 << 5)
> +#define ADP5520_C3_MODE (1 << 4)
> +#define ADP5520_LED_LAW (1 << 3)
> +#define ADP5520_LED3_EN (1 << 2)
> +#define ADP5520_LED2_EN (1 << 1)
> +#define ADP5520_LED1_EN (1 << 0)
> +
> +/*
> + * GPIO subdevice bits and masks
> + */
> +
> +#define ADP5520_MAXGPIOS 8
> +
> +#define ADP5520_GPIO_C3 (1 << 7) /* LED2 or GPIO7 aka C3 */
> +#define ADP5520_GPIO_C2 (1 << 6)
> +#define ADP5520_GPIO_C1 (1 << 5)
> +#define ADP5520_GPIO_C0 (1 << 4)
> +#define ADP5520_GPIO_R3 (1 << 3) /* LED3 or GPIO3 aka R3 */
> +#define ADP5520_GPIO_R2 (1 << 2)
> +#define ADP5520_GPIO_R1 (1 << 1)
> +#define ADP5520_GPIO_R0 (1 << 0)
> +
> +struct adp5520_gpio_platform_data {
> + unsigned gpio_start;
> + u8 gpio_en_mask;
> + u8 gpio_pullup_mask;
> +};
> +
> +/*
> + * Keypad subdevice bits and masks
> + */
> +
> +#define ADP5520_MAXKEYS 16
> +
> +#define ADP5520_COL_C3 (1 << 7) /* LED2 or GPIO7 aka C3 */
> +#define ADP5520_COL_C2 (1 << 6)
> +#define ADP5520_COL_C1 (1 << 5)
> +#define ADP5520_COL_C0 (1 << 4)
> +#define ADP5520_ROW_R3 (1 << 3) /* LED3 or GPIO3 aka R3 */
> +#define ADP5520_ROW_R2 (1 << 2)
> +#define ADP5520_ROW_R1 (1 << 1)
> +#define ADP5520_ROW_R0 (1 << 0)
> +
> +#define ADP5520_KEY(row, col) (col + row * 4)
> +#define ADP5520_KEYMAPSIZE ADP5520_MAXKEYS
> +
> +struct adp5520_keys_platform_data {
> + int rows_en_mask; /* Number of rows */
> + int cols_en_mask; /* Number of columns */
> + const unsigned short *keymap; /* Pointer to keymap */
> + unsigned short keymapsize; /* Keymap size */
> + unsigned repeat:1; /* Enable key repeat */
> +};
> +
> +
> +/*
> + * LEDs subdevice platform data
> + */
> +
> +#define FLAG_ID_ADP5520_LED1_ADP5501_LED0 1 /* ADP5520 PIN ILED */
> +#define FLAG_ID_ADP5520_LED2_ADP5501_LED1 2 /* ADP5520 PIN C3 */
> +#define FLAG_ID_ADP5520_LED3_ADP5501_LED2 3 /* ADP5520 PIN R3 */
> +
> +#define ADP5520_LED_DIS_BLINK (0 << ADP5520_FLAG_OFFT_SHIFT)
> +#define ADP5520_LED_OFFT_600ms (1 << ADP5520_FLAG_OFFT_SHIFT)
> +#define ADP5520_LED_OFFT_800ms (2 << ADP5520_FLAG_OFFT_SHIFT)
> +#define ADP5520_LED_OFFT_1200ms (3 << ADP5520_FLAG_OFFT_SHIFT)
> +
> +#define ADP5520_LED_ONT_200ms 0
> +#define ADP5520_LED_ONT_600ms 1
> +#define ADP5520_LED_ONT_800ms 2
> +#define ADP5520_LED_ONT_1200ms 3
> +
> +struct adp5520_leds_platform_data {
> + int num_leds;
> + struct led_info *leds;
> + u8 fade_in; /* Backlight Fade-In Timer */
> + u8 fade_out; /* Backlight Fade-Out Timer */
> + u8 led_on_time;
> +};
> +
> +/*
> + * Backlight subdevice platform data
> + */
> +
> +#define ADP5520_FADE_T_DIS 0 /* Fade Timer Disabled */
> +#define ADP5520_FADE_T_300ms 1 /* 0.3 Sec */
> +#define ADP5520_FADE_T_600ms 2
> +#define ADP5520_FADE_T_900ms 3
> +#define ADP5520_FADE_T_1200ms 4
> +#define ADP5520_FADE_T_1500ms 5
> +#define ADP5520_FADE_T_1800ms 6
> +#define ADP5520_FADE_T_2100ms 7
> +#define ADP5520_FADE_T_2400ms 8
> +#define ADP5520_FADE_T_2700ms 9
> +#define ADP5520_FADE_T_3000ms 10
> +#define ADP5520_FADE_T_3500ms 11
> +#define ADP5520_FADE_T_4000ms 12
> +#define ADP5520_FADE_T_4500ms 13
> +#define ADP5520_FADE_T_5000ms 14
> +#define ADP5520_FADE_T_5500ms 15 /* 5.5 Sec */
> +
> +#define ADP5520_BL_LAW_LINEAR 0
> +#define ADP5520_BL_LAW_SQUARE 1
> +#define ADP5520_BL_LAW_CUBIC1 2
> +#define ADP5520_BL_LAW_CUBIC2 3
> +
> +#define ADP5520_BL_AMBL_FILT_80ms 0 /* Light sensor filter time */
> +#define ADP5520_BL_AMBL_FILT_160ms 1
> +#define ADP5520_BL_AMBL_FILT_320ms 2
> +#define ADP5520_BL_AMBL_FILT_640ms 3
> +#define ADP5520_BL_AMBL_FILT_1280ms 4
> +#define ADP5520_BL_AMBL_FILT_2560ms 5
> +#define ADP5520_BL_AMBL_FILT_5120ms 6
> +#define ADP5520_BL_AMBL_FILT_10240ms 7 /* 10.24 sec */
> +
> + /*
> + * Blacklight current 0..30mA
> + */
> +#define ADP5520_BL_CUR_mA(I) ((I * 127) / 30)
> +
> + /*
> + * L2 comparator current 0..1000uA
> + */
> +#define ADP5520_L2_COMP_CURR_uA(I) ((I * 255) / 1000)
> +
> + /*
> + * L3 comparator current 0..127uA
> + */
> +#define ADP5520_L3_COMP_CURR_uA(I) ((I * 255) / 127)
> +
> +struct adp5520_backlight_platform_data {
> + u8 fade_in; /* Backlight Fade-In Timer */
> + u8 fade_out; /* Backlight Fade-Out Timer */
> + u8 fade_led_law; /* fade-on/fade-off transfer characteristic */
> +
> + u8 en_ambl_sens; /* 1 = enable ambient light sensor */
> + u8 abml_filt; /* Light sensor filter time */
> + u8 l1_daylight_max; /* use BL_CUR_mA(I) 0 <= I <= 30 mA */
> + u8 l1_daylight_dim; /* typ = 0, use BL_CUR_mA(I) 0 <= I <= 30 mA */
> + u8 l2_office_max; /* use BL_CUR_mA(I) 0 <= I <= 30 mA */
> + u8 l2_office_dim; /* typ = 0, use BL_CUR_mA(I) 0 <= I <= 30 mA */
> + u8 l3_dark_max; /* use BL_CUR_mA(I) 0 <= I <= 30 mA */
> + u8 l3_dark_dim; /* typ = 0, use BL_CUR_mA(I) 0 <= I <= 30 mA */
> + u8 l2_trip; /* use L2_COMP_CURR_uA(I) 0 <= I <= 1000 uA */
> + u8 l2_hyst; /* use L2_COMP_CURR_uA(I) 0 <= I <= 1000 uA */
> + u8 l3_trip; /* use L3_COMP_CURR_uA(I) 0 <= I <= 127 uA */
> + u8 l3_hyst; /* use L3_COMP_CURR_uA(I) 0 <= I <= 127 uA */
> +};
> +
> +/*
> + * MFD chip platform data
> + */
> +
> +struct adp5520_platform_data {
> + struct adp5520_keys_platform_data *keys;
> + struct adp5520_gpio_platform_data *gpio;
> + struct adp5520_leds_platform_data *leds;
> + struct adp5520_backlight_platform_data *backlight;
> +};
> +
> +/*
> + * MFD chip functions
> + */
> +
> +extern int adp5520_read(struct device *dev, int reg, uint8_t *val);
> +extern int adp5520_write(struct device *dev, int reg, u8 val);
> +extern int adp5520_clr_bits(struct device *dev, int reg, uint8_t bit_mask);
> +extern int adp5520_set_bits(struct device *dev, int reg, uint8_t bit_mask);
> +
> +extern int adp5520_register_notifier(struct device *dev,
> + struct notifier_block *nb, unsigned int events);
> +
> +extern int adp5520_unregister_notifier(struct device *dev,
> + struct notifier_block *nb, unsigned int events);
> +
> +#endif /* __LINUX_MFD_ADP5520_H */
> --
> 1.6.5.rc2
>
--
Intel Open Source Technology Centre
http://oss.intel.com/
Hi Richard,
On Sat, Oct 10, 2009 at 01:54:01PM -0400, Mike Frysinger wrote:
> From: Michael Hennerich <[email protected]>
Does this driver look fine to you ?
Cheers,
Samuel.
> Signed-off-by: Michael Hennerich <[email protected]>
> Signed-off-by: Bryan Wu <[email protected]>
> Signed-off-by: Mike Frysinger <[email protected]>
> ---
> drivers/leds/Kconfig | 10 ++
> drivers/leds/Makefile | 1 +
> drivers/leds/leds-adp5520.c | 230 +++++++++++++++++++++++++++++++++++++++++++
> 3 files changed, 241 insertions(+), 0 deletions(-)
> create mode 100644 drivers/leds/leds-adp5520.c
>
> diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
> index e4f599f..33ac8dc 100644
> --- a/drivers/leds/Kconfig
> +++ b/drivers/leds/Kconfig
> @@ -236,6 +236,16 @@ config LEDS_BD2802
> This option enables support for BD2802GU RGB LED driver chips
> accessed via the I2C bus.
>
> +config LEDS_ADP5520
> + tristate "LED Support for ADP5520/ADP5501 PMIC"
> + depends on LEDS_CLASS && PMIC_ADP5520
> + help
> + This option enables support for on-chip LED drivers found
> + on Analog Devices ADP5520/ADP5501 PMICs.
> +
> + To compile this driver as a module, choose M here: the module will
> + be called leds-adp5520.
> +
> comment "LED Triggers"
>
> config LEDS_TRIGGERS
> diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
> index 46d7270..f7e17f4 100644
> --- a/drivers/leds/Makefile
> +++ b/drivers/leds/Makefile
> @@ -29,6 +29,7 @@ obj-$(CONFIG_LEDS_DA903X) += leds-da903x.o
> obj-$(CONFIG_LEDS_WM831X_STATUS) += leds-wm831x-status.o
> obj-$(CONFIG_LEDS_WM8350) += leds-wm8350.o
> obj-$(CONFIG_LEDS_PWM) += leds-pwm.o
> +obj-$(CONFIG_LEDS_ADP5520) += leds-adp5520.o
>
> # LED SPI Drivers
> obj-$(CONFIG_LEDS_DAC124S085) += leds-dac124s085.o
> diff --git a/drivers/leds/leds-adp5520.c b/drivers/leds/leds-adp5520.c
> new file mode 100644
> index 0000000..a8f3159
> --- /dev/null
> +++ b/drivers/leds/leds-adp5520.c
> @@ -0,0 +1,230 @@
> +/*
> + * LEDs driver for Analog Devices ADP5520/ADP5501 MFD PMICs
> + *
> + * Copyright 2009 Analog Devices Inc.
> + *
> + * Loosely derived from leds-da903x:
> + * Copyright (C) 2008 Compulab, Ltd.
> + * Mike Rapoport <[email protected]>
> + *
> + * Copyright (C) 2006-2008 Marvell International Ltd.
> + * Eric Miao <[email protected]>
> + *
> + * Licensed under the GPL-2 or later.
> + */
> +
> +#include <linux/module.h>
> +#include <linux/kernel.h>
> +#include <linux/init.h>
> +#include <linux/platform_device.h>
> +#include <linux/leds.h>
> +#include <linux/workqueue.h>
> +#include <linux/mfd/adp5520.h>
> +
> +struct adp5520_led {
> + struct led_classdev cdev;
> + struct work_struct work;
> + struct device *master;
> + enum led_brightness new_brightness;
> + int id;
> + int flags;
> +};
> +
> +static void adp5520_led_work(struct work_struct *work)
> +{
> + struct adp5520_led *led = container_of(work, struct adp5520_led, work);
> + adp5520_write(led->master, ADP5520_LED1_CURRENT + led->id - 1,
> + led->new_brightness >> 2);
> +}
> +
> +static void adp5520_led_set(struct led_classdev *led_cdev,
> + enum led_brightness value)
> +{
> + struct adp5520_led *led;
> +
> + led = container_of(led_cdev, struct adp5520_led, cdev);
> + led->new_brightness = value;
> + schedule_work(&led->work);
> +}
> +
> +static int adp5520_led_setup(struct adp5520_led *led)
> +{
> + struct device *dev = led->master;
> + int flags = led->flags;
> + int ret = 0;
> +
> + switch (led->id) {
> + case FLAG_ID_ADP5520_LED1_ADP5501_LED0:
> + ret |= adp5520_set_bits(dev, ADP5520_LED_TIME,
> + (flags >> ADP5520_FLAG_OFFT_SHIFT) &
> + ADP5520_FLAG_OFFT_MASK);
> + ret |= adp5520_set_bits(dev, ADP5520_LED_CONTROL,
> + ADP5520_LED1_EN);
> + break;
> + case FLAG_ID_ADP5520_LED2_ADP5501_LED1:
> + ret |= adp5520_set_bits(dev, ADP5520_LED_TIME,
> + ((flags >> ADP5520_FLAG_OFFT_SHIFT) &
> + ADP5520_FLAG_OFFT_MASK) << 2);
> + ret |= adp5520_clr_bits(dev, ADP5520_LED_CONTROL,
> + ADP5520_R3_MODE);
> + ret |= adp5520_set_bits(dev, ADP5520_LED_CONTROL,
> + ADP5520_LED2_EN);
> + break;
> + case FLAG_ID_ADP5520_LED3_ADP5501_LED2:
> + ret |= adp5520_set_bits(dev, ADP5520_LED_TIME,
> + ((flags >> ADP5520_FLAG_OFFT_SHIFT) &
> + ADP5520_FLAG_OFFT_MASK) << 4);
> + ret |= adp5520_clr_bits(dev, ADP5520_LED_CONTROL,
> + ADP5520_C3_MODE);
> + ret |= adp5520_set_bits(dev, ADP5520_LED_CONTROL,
> + ADP5520_LED3_EN);
> + break;
> + }
> +
> + return ret;
> +}
> +
> +static int __devinit adp5520_led_prepare(struct platform_device *pdev)
> +{
> + struct adp5520_leds_platform_data *pdata = pdev->dev.platform_data;
> + struct device *dev = pdev->dev.parent;
> + int ret = 0;
> +
> + ret |= adp5520_write(dev, ADP5520_LED1_CURRENT, 0);
> + ret |= adp5520_write(dev, ADP5520_LED2_CURRENT, 0);
> + ret |= adp5520_write(dev, ADP5520_LED3_CURRENT, 0);
> + ret |= adp5520_write(dev, ADP5520_LED_TIME, pdata->led_on_time << 6);
> + ret |= adp5520_write(dev, ADP5520_LED_FADE, FADE_VAL(pdata->fade_in,
> + pdata->fade_out));
> +
> + return ret;
> +}
> +
> +static int __devinit adp5520_led_probe(struct platform_device *pdev)
> +{
> + struct adp5520_leds_platform_data *pdata = pdev->dev.platform_data;
> + struct adp5520_led *led, *led_dat;
> + struct led_info *cur_led;
> + int ret, i;
> +
> + if (pdata == NULL) {
> + dev_err(&pdev->dev, "missing platform data\n");
> + return -ENODEV;
> + }
> +
> + if (pdata->num_leds > ADP5520_01_MAXLEDS) {
> + dev_err(&pdev->dev, "can't handle more than %d LEDS\n",
> + ADP5520_01_MAXLEDS);
> + return -EFAULT;
> + }
> +
> + led = kzalloc(sizeof(*led) * pdata->num_leds, GFP_KERNEL);
> + if (led == NULL) {
> + dev_err(&pdev->dev, "failed to alloc memory\n");
> + return -ENOMEM;
> + }
> +
> + ret = adp5520_led_prepare(pdev);
> +
> + if (ret) {
> + dev_err(&pdev->dev, "failed to write\n");
> + goto err_free;
> + }
> +
> + for (i = 0; i < pdata->num_leds; ++i) {
> + cur_led = &pdata->leds[i];
> + led_dat = &led[i];
> +
> + led_dat->cdev.name = cur_led->name;
> + led_dat->cdev.default_trigger = cur_led->default_trigger;
> + led_dat->cdev.brightness_set = adp5520_led_set;
> + led_dat->cdev.brightness = LED_OFF;
> +
> + if (cur_led->flags & ADP5520_FLAG_LED_MASK)
> + led_dat->flags = cur_led->flags;
> + else
> + led_dat->flags = i + 1;
> +
> + led_dat->id = led_dat->flags & ADP5520_FLAG_LED_MASK;
> +
> + led_dat->master = pdev->dev.parent;
> + led_dat->new_brightness = LED_OFF;
> +
> + INIT_WORK(&led_dat->work, adp5520_led_work);
> +
> + ret = led_classdev_register(led_dat->master, &led_dat->cdev);
> + if (ret) {
> + dev_err(&pdev->dev, "failed to register LED %d\n",
> + led_dat->id);
> + goto err;
> + }
> +
> + ret = adp5520_led_setup(led_dat);
> + if (ret) {
> + dev_err(&pdev->dev, "failed to write\n");
> + i++;
> + goto err;
> + }
> + }
> +
> + platform_set_drvdata(pdev, led);
> + return 0;
> +
> +err:
> + if (i > 0) {
> + for (i = i - 1; i >= 0; i--) {
> + led_classdev_unregister(&led[i].cdev);
> + cancel_work_sync(&led[i].work);
> + }
> + }
> +
> +err_free:
> + kfree(led);
> + return ret;
> +}
> +
> +static int __devexit adp5520_led_remove(struct platform_device *pdev)
> +{
> + struct adp5520_leds_platform_data *pdata = pdev->dev.platform_data;
> + struct adp5520_led *led;
> + int i;
> +
> + led = platform_get_drvdata(pdev);
> +
> + adp5520_clr_bits(led->master, ADP5520_LED_CONTROL,
> + ADP5520_LED1_EN | ADP5520_LED2_EN | ADP5520_LED3_EN);
> +
> + for (i = 0; i < pdata->num_leds; i++) {
> + led_classdev_unregister(&led[i].cdev);
> + cancel_work_sync(&led[i].work);
> + }
> +
> + kfree(led);
> + return 0;
> +}
> +
> +static struct platform_driver adp5520_led_driver = {
> + .driver = {
> + .name = "adp5520-led",
> + .owner = THIS_MODULE,
> + },
> + .probe = adp5520_led_probe,
> + .remove = __devexit_p(adp5520_led_remove),
> +};
> +
> +static int __init adp5520_led_init(void)
> +{
> + return platform_driver_register(&adp5520_led_driver);
> +}
> +module_init(adp5520_led_init);
> +
> +static void __exit adp5520_led_exit(void)
> +{
> + platform_driver_unregister(&adp5520_led_driver);
> +}
> +module_exit(adp5520_led_exit);
> +
> +MODULE_AUTHOR("Michael Hennerich <[email protected]>");
> +MODULE_DESCRIPTION("LEDS ADP5520(01) Driver");
> +MODULE_LICENSE("GPL");
> +MODULE_ALIAS("platform:adp5520-led");
> --
> 1.6.5.rc2
>
--
Intel Open Source Technology Centre
http://oss.intel.com/
On Mon, Oct 12, 2009 at 12:38, Samuel Ortiz wrote:
> On Sat, Oct 10, 2009 at 01:54:01PM -0400, Mike Frysinger wrote:
>> From: Michael Hennerich <[email protected]>
>
> Does this driver look fine to you ?
note that this is the same one that was sent a month ago followed by
the define name tweaks a week ago
-mike
On Mon, Oct 12, 2009 at 12:36, Samuel Ortiz wrote:
> On Sat, Oct 10, 2009 at 01:54:00PM -0400, Mike Frysinger wrote:
>> From: Michael Hennerich <[email protected]>
>>
>> Base driver for Analog Devices ADP5520/ADP5501 MFD PMICs
>
> MFD and GPIO, backlight and input drivers applied, thanks.
awesome
> About the LED one, I would really appreciate if you could have the LED
> maintainer review it or/and ack it.
you and me both ;)
-mike
Hi Samuel,
On Mon, 2009-10-12 at 18:38 +0200, Samuel Ortiz wrote:
> On Sat, Oct 10, 2009 at 01:54:01PM -0400, Mike Frysinger wrote:
> > From: Michael Hennerich <[email protected]>
> Does this driver look fine to you ?
Yes, looks good to me. Do you want to take it with the others or should
I put it through the LEDs tree? The latter would avoid conflicts over
the Kconfig/Makefile I guess?
Cheers,
Richard
> Cheers,
> Samuel.
>
>
> > Signed-off-by: Michael Hennerich <[email protected]>
> > Signed-off-by: Bryan Wu <[email protected]>
> > Signed-off-by: Mike Frysinger <[email protected]>
> > ---
> > drivers/leds/Kconfig | 10 ++
> > drivers/leds/Makefile | 1 +
> > drivers/leds/leds-adp5520.c | 230 +++++++++++++++++++++++++++++++++++++++++++
> > 3 files changed, 241 insertions(+), 0 deletions(-)
> > create mode 100644 drivers/leds/leds-adp5520.c
> >
> > diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
> > index e4f599f..33ac8dc 100644
> > --- a/drivers/leds/Kconfig
> > +++ b/drivers/leds/Kconfig
> > @@ -236,6 +236,16 @@ config LEDS_BD2802
> > This option enables support for BD2802GU RGB LED driver chips
> > accessed via the I2C bus.
> >
> > +config LEDS_ADP5520
> > + tristate "LED Support for ADP5520/ADP5501 PMIC"
> > + depends on LEDS_CLASS && PMIC_ADP5520
> > + help
> > + This option enables support for on-chip LED drivers found
> > + on Analog Devices ADP5520/ADP5501 PMICs.
> > +
> > + To compile this driver as a module, choose M here: the module will
> > + be called leds-adp5520.
> > +
> > comment "LED Triggers"
> >
> > config LEDS_TRIGGERS
> > diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
> > index 46d7270..f7e17f4 100644
> > --- a/drivers/leds/Makefile
> > +++ b/drivers/leds/Makefile
> > @@ -29,6 +29,7 @@ obj-$(CONFIG_LEDS_DA903X) += leds-da903x.o
> > obj-$(CONFIG_LEDS_WM831X_STATUS) += leds-wm831x-status.o
> > obj-$(CONFIG_LEDS_WM8350) += leds-wm8350.o
> > obj-$(CONFIG_LEDS_PWM) += leds-pwm.o
> > +obj-$(CONFIG_LEDS_ADP5520) += leds-adp5520.o
> >
> > # LED SPI Drivers
> > obj-$(CONFIG_LEDS_DAC124S085) += leds-dac124s085.o
> > diff --git a/drivers/leds/leds-adp5520.c b/drivers/leds/leds-adp5520.c
> > new file mode 100644
> > index 0000000..a8f3159
> > --- /dev/null
> > +++ b/drivers/leds/leds-adp5520.c
> > @@ -0,0 +1,230 @@
> > +/*
> > + * LEDs driver for Analog Devices ADP5520/ADP5501 MFD PMICs
> > + *
> > + * Copyright 2009 Analog Devices Inc.
> > + *
> > + * Loosely derived from leds-da903x:
> > + * Copyright (C) 2008 Compulab, Ltd.
> > + * Mike Rapoport <[email protected]>
> > + *
> > + * Copyright (C) 2006-2008 Marvell International Ltd.
> > + * Eric Miao <[email protected]>
> > + *
> > + * Licensed under the GPL-2 or later.
> > + */
> > +
> > +#include <linux/module.h>
> > +#include <linux/kernel.h>
> > +#include <linux/init.h>
> > +#include <linux/platform_device.h>
> > +#include <linux/leds.h>
> > +#include <linux/workqueue.h>
> > +#include <linux/mfd/adp5520.h>
> > +
> > +struct adp5520_led {
> > + struct led_classdev cdev;
> > + struct work_struct work;
> > + struct device *master;
> > + enum led_brightness new_brightness;
> > + int id;
> > + int flags;
> > +};
> > +
> > +static void adp5520_led_work(struct work_struct *work)
> > +{
> > + struct adp5520_led *led = container_of(work, struct adp5520_led, work);
> > + adp5520_write(led->master, ADP5520_LED1_CURRENT + led->id - 1,
> > + led->new_brightness >> 2);
> > +}
> > +
> > +static void adp5520_led_set(struct led_classdev *led_cdev,
> > + enum led_brightness value)
> > +{
> > + struct adp5520_led *led;
> > +
> > + led = container_of(led_cdev, struct adp5520_led, cdev);
> > + led->new_brightness = value;
> > + schedule_work(&led->work);
> > +}
> > +
> > +static int adp5520_led_setup(struct adp5520_led *led)
> > +{
> > + struct device *dev = led->master;
> > + int flags = led->flags;
> > + int ret = 0;
> > +
> > + switch (led->id) {
> > + case FLAG_ID_ADP5520_LED1_ADP5501_LED0:
> > + ret |= adp5520_set_bits(dev, ADP5520_LED_TIME,
> > + (flags >> ADP5520_FLAG_OFFT_SHIFT) &
> > + ADP5520_FLAG_OFFT_MASK);
> > + ret |= adp5520_set_bits(dev, ADP5520_LED_CONTROL,
> > + ADP5520_LED1_EN);
> > + break;
> > + case FLAG_ID_ADP5520_LED2_ADP5501_LED1:
> > + ret |= adp5520_set_bits(dev, ADP5520_LED_TIME,
> > + ((flags >> ADP5520_FLAG_OFFT_SHIFT) &
> > + ADP5520_FLAG_OFFT_MASK) << 2);
> > + ret |= adp5520_clr_bits(dev, ADP5520_LED_CONTROL,
> > + ADP5520_R3_MODE);
> > + ret |= adp5520_set_bits(dev, ADP5520_LED_CONTROL,
> > + ADP5520_LED2_EN);
> > + break;
> > + case FLAG_ID_ADP5520_LED3_ADP5501_LED2:
> > + ret |= adp5520_set_bits(dev, ADP5520_LED_TIME,
> > + ((flags >> ADP5520_FLAG_OFFT_SHIFT) &
> > + ADP5520_FLAG_OFFT_MASK) << 4);
> > + ret |= adp5520_clr_bits(dev, ADP5520_LED_CONTROL,
> > + ADP5520_C3_MODE);
> > + ret |= adp5520_set_bits(dev, ADP5520_LED_CONTROL,
> > + ADP5520_LED3_EN);
> > + break;
> > + }
> > +
> > + return ret;
> > +}
> > +
> > +static int __devinit adp5520_led_prepare(struct platform_device *pdev)
> > +{
> > + struct adp5520_leds_platform_data *pdata = pdev->dev.platform_data;
> > + struct device *dev = pdev->dev.parent;
> > + int ret = 0;
> > +
> > + ret |= adp5520_write(dev, ADP5520_LED1_CURRENT, 0);
> > + ret |= adp5520_write(dev, ADP5520_LED2_CURRENT, 0);
> > + ret |= adp5520_write(dev, ADP5520_LED3_CURRENT, 0);
> > + ret |= adp5520_write(dev, ADP5520_LED_TIME, pdata->led_on_time << 6);
> > + ret |= adp5520_write(dev, ADP5520_LED_FADE, FADE_VAL(pdata->fade_in,
> > + pdata->fade_out));
> > +
> > + return ret;
> > +}
> > +
> > +static int __devinit adp5520_led_probe(struct platform_device *pdev)
> > +{
> > + struct adp5520_leds_platform_data *pdata = pdev->dev.platform_data;
> > + struct adp5520_led *led, *led_dat;
> > + struct led_info *cur_led;
> > + int ret, i;
> > +
> > + if (pdata == NULL) {
> > + dev_err(&pdev->dev, "missing platform data\n");
> > + return -ENODEV;
> > + }
> > +
> > + if (pdata->num_leds > ADP5520_01_MAXLEDS) {
> > + dev_err(&pdev->dev, "can't handle more than %d LEDS\n",
> > + ADP5520_01_MAXLEDS);
> > + return -EFAULT;
> > + }
> > +
> > + led = kzalloc(sizeof(*led) * pdata->num_leds, GFP_KERNEL);
> > + if (led == NULL) {
> > + dev_err(&pdev->dev, "failed to alloc memory\n");
> > + return -ENOMEM;
> > + }
> > +
> > + ret = adp5520_led_prepare(pdev);
> > +
> > + if (ret) {
> > + dev_err(&pdev->dev, "failed to write\n");
> > + goto err_free;
> > + }
> > +
> > + for (i = 0; i < pdata->num_leds; ++i) {
> > + cur_led = &pdata->leds[i];
> > + led_dat = &led[i];
> > +
> > + led_dat->cdev.name = cur_led->name;
> > + led_dat->cdev.default_trigger = cur_led->default_trigger;
> > + led_dat->cdev.brightness_set = adp5520_led_set;
> > + led_dat->cdev.brightness = LED_OFF;
> > +
> > + if (cur_led->flags & ADP5520_FLAG_LED_MASK)
> > + led_dat->flags = cur_led->flags;
> > + else
> > + led_dat->flags = i + 1;
> > +
> > + led_dat->id = led_dat->flags & ADP5520_FLAG_LED_MASK;
> > +
> > + led_dat->master = pdev->dev.parent;
> > + led_dat->new_brightness = LED_OFF;
> > +
> > + INIT_WORK(&led_dat->work, adp5520_led_work);
> > +
> > + ret = led_classdev_register(led_dat->master, &led_dat->cdev);
> > + if (ret) {
> > + dev_err(&pdev->dev, "failed to register LED %d\n",
> > + led_dat->id);
> > + goto err;
> > + }
> > +
> > + ret = adp5520_led_setup(led_dat);
> > + if (ret) {
> > + dev_err(&pdev->dev, "failed to write\n");
> > + i++;
> > + goto err;
> > + }
> > + }
> > +
> > + platform_set_drvdata(pdev, led);
> > + return 0;
> > +
> > +err:
> > + if (i > 0) {
> > + for (i = i - 1; i >= 0; i--) {
> > + led_classdev_unregister(&led[i].cdev);
> > + cancel_work_sync(&led[i].work);
> > + }
> > + }
> > +
> > +err_free:
> > + kfree(led);
> > + return ret;
> > +}
> > +
> > +static int __devexit adp5520_led_remove(struct platform_device *pdev)
> > +{
> > + struct adp5520_leds_platform_data *pdata = pdev->dev.platform_data;
> > + struct adp5520_led *led;
> > + int i;
> > +
> > + led = platform_get_drvdata(pdev);
> > +
> > + adp5520_clr_bits(led->master, ADP5520_LED_CONTROL,
> > + ADP5520_LED1_EN | ADP5520_LED2_EN | ADP5520_LED3_EN);
> > +
> > + for (i = 0; i < pdata->num_leds; i++) {
> > + led_classdev_unregister(&led[i].cdev);
> > + cancel_work_sync(&led[i].work);
> > + }
> > +
> > + kfree(led);
> > + return 0;
> > +}
> > +
> > +static struct platform_driver adp5520_led_driver = {
> > + .driver = {
> > + .name = "adp5520-led",
> > + .owner = THIS_MODULE,
> > + },
> > + .probe = adp5520_led_probe,
> > + .remove = __devexit_p(adp5520_led_remove),
> > +};
> > +
> > +static int __init adp5520_led_init(void)
> > +{
> > + return platform_driver_register(&adp5520_led_driver);
> > +}
> > +module_init(adp5520_led_init);
> > +
> > +static void __exit adp5520_led_exit(void)
> > +{
> > + platform_driver_unregister(&adp5520_led_driver);
> > +}
> > +module_exit(adp5520_led_exit);
> > +
> > +MODULE_AUTHOR("Michael Hennerich <[email protected]>");
> > +MODULE_DESCRIPTION("LEDS ADP5520(01) Driver");
> > +MODULE_LICENSE("GPL");
> > +MODULE_ALIAS("platform:adp5520-led");
> > --
> > 1.6.5.rc2
> >
>
Hi Richard,
On Wed, Oct 14, 2009 at 06:53:35PM +0100, Richard Purdie wrote:
> Hi Samuel,
>
> On Mon, 2009-10-12 at 18:38 +0200, Samuel Ortiz wrote:
> > On Sat, Oct 10, 2009 at 01:54:01PM -0400, Mike Frysinger wrote:
> > > From: Michael Hennerich <[email protected]>
> > Does this driver look fine to you ?
>
> Yes, looks good to me. Do you want to take it with the others or should
> I put it through the LEDs tree? The latter would avoid conflicts over
> the Kconfig/Makefile I guess?
I agree. Please go ahead and merge it through your LED tree, thanks in
advance.
Cheers,
Samuel.
> Cheers,
>
> Richard
>
> > Cheers,
> > Samuel.
> >
> >
> > > Signed-off-by: Michael Hennerich <[email protected]>
> > > Signed-off-by: Bryan Wu <[email protected]>
> > > Signed-off-by: Mike Frysinger <[email protected]>
> > > ---
> > > drivers/leds/Kconfig | 10 ++
> > > drivers/leds/Makefile | 1 +
> > > drivers/leds/leds-adp5520.c | 230 +++++++++++++++++++++++++++++++++++++++++++
> > > 3 files changed, 241 insertions(+), 0 deletions(-)
> > > create mode 100644 drivers/leds/leds-adp5520.c
> > >
> > > diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
> > > index e4f599f..33ac8dc 100644
> > > --- a/drivers/leds/Kconfig
> > > +++ b/drivers/leds/Kconfig
> > > @@ -236,6 +236,16 @@ config LEDS_BD2802
> > > This option enables support for BD2802GU RGB LED driver chips
> > > accessed via the I2C bus.
> > >
> > > +config LEDS_ADP5520
> > > + tristate "LED Support for ADP5520/ADP5501 PMIC"
> > > + depends on LEDS_CLASS && PMIC_ADP5520
> > > + help
> > > + This option enables support for on-chip LED drivers found
> > > + on Analog Devices ADP5520/ADP5501 PMICs.
> > > +
> > > + To compile this driver as a module, choose M here: the module will
> > > + be called leds-adp5520.
> > > +
> > > comment "LED Triggers"
> > >
> > > config LEDS_TRIGGERS
> > > diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
> > > index 46d7270..f7e17f4 100644
> > > --- a/drivers/leds/Makefile
> > > +++ b/drivers/leds/Makefile
> > > @@ -29,6 +29,7 @@ obj-$(CONFIG_LEDS_DA903X) += leds-da903x.o
> > > obj-$(CONFIG_LEDS_WM831X_STATUS) += leds-wm831x-status.o
> > > obj-$(CONFIG_LEDS_WM8350) += leds-wm8350.o
> > > obj-$(CONFIG_LEDS_PWM) += leds-pwm.o
> > > +obj-$(CONFIG_LEDS_ADP5520) += leds-adp5520.o
> > >
> > > # LED SPI Drivers
> > > obj-$(CONFIG_LEDS_DAC124S085) += leds-dac124s085.o
> > > diff --git a/drivers/leds/leds-adp5520.c b/drivers/leds/leds-adp5520.c
> > > new file mode 100644
> > > index 0000000..a8f3159
> > > --- /dev/null
> > > +++ b/drivers/leds/leds-adp5520.c
> > > @@ -0,0 +1,230 @@
> > > +/*
> > > + * LEDs driver for Analog Devices ADP5520/ADP5501 MFD PMICs
> > > + *
> > > + * Copyright 2009 Analog Devices Inc.
> > > + *
> > > + * Loosely derived from leds-da903x:
> > > + * Copyright (C) 2008 Compulab, Ltd.
> > > + * Mike Rapoport <[email protected]>
> > > + *
> > > + * Copyright (C) 2006-2008 Marvell International Ltd.
> > > + * Eric Miao <[email protected]>
> > > + *
> > > + * Licensed under the GPL-2 or later.
> > > + */
> > > +
> > > +#include <linux/module.h>
> > > +#include <linux/kernel.h>
> > > +#include <linux/init.h>
> > > +#include <linux/platform_device.h>
> > > +#include <linux/leds.h>
> > > +#include <linux/workqueue.h>
> > > +#include <linux/mfd/adp5520.h>
> > > +
> > > +struct adp5520_led {
> > > + struct led_classdev cdev;
> > > + struct work_struct work;
> > > + struct device *master;
> > > + enum led_brightness new_brightness;
> > > + int id;
> > > + int flags;
> > > +};
> > > +
> > > +static void adp5520_led_work(struct work_struct *work)
> > > +{
> > > + struct adp5520_led *led = container_of(work, struct adp5520_led, work);
> > > + adp5520_write(led->master, ADP5520_LED1_CURRENT + led->id - 1,
> > > + led->new_brightness >> 2);
> > > +}
> > > +
> > > +static void adp5520_led_set(struct led_classdev *led_cdev,
> > > + enum led_brightness value)
> > > +{
> > > + struct adp5520_led *led;
> > > +
> > > + led = container_of(led_cdev, struct adp5520_led, cdev);
> > > + led->new_brightness = value;
> > > + schedule_work(&led->work);
> > > +}
> > > +
> > > +static int adp5520_led_setup(struct adp5520_led *led)
> > > +{
> > > + struct device *dev = led->master;
> > > + int flags = led->flags;
> > > + int ret = 0;
> > > +
> > > + switch (led->id) {
> > > + case FLAG_ID_ADP5520_LED1_ADP5501_LED0:
> > > + ret |= adp5520_set_bits(dev, ADP5520_LED_TIME,
> > > + (flags >> ADP5520_FLAG_OFFT_SHIFT) &
> > > + ADP5520_FLAG_OFFT_MASK);
> > > + ret |= adp5520_set_bits(dev, ADP5520_LED_CONTROL,
> > > + ADP5520_LED1_EN);
> > > + break;
> > > + case FLAG_ID_ADP5520_LED2_ADP5501_LED1:
> > > + ret |= adp5520_set_bits(dev, ADP5520_LED_TIME,
> > > + ((flags >> ADP5520_FLAG_OFFT_SHIFT) &
> > > + ADP5520_FLAG_OFFT_MASK) << 2);
> > > + ret |= adp5520_clr_bits(dev, ADP5520_LED_CONTROL,
> > > + ADP5520_R3_MODE);
> > > + ret |= adp5520_set_bits(dev, ADP5520_LED_CONTROL,
> > > + ADP5520_LED2_EN);
> > > + break;
> > > + case FLAG_ID_ADP5520_LED3_ADP5501_LED2:
> > > + ret |= adp5520_set_bits(dev, ADP5520_LED_TIME,
> > > + ((flags >> ADP5520_FLAG_OFFT_SHIFT) &
> > > + ADP5520_FLAG_OFFT_MASK) << 4);
> > > + ret |= adp5520_clr_bits(dev, ADP5520_LED_CONTROL,
> > > + ADP5520_C3_MODE);
> > > + ret |= adp5520_set_bits(dev, ADP5520_LED_CONTROL,
> > > + ADP5520_LED3_EN);
> > > + break;
> > > + }
> > > +
> > > + return ret;
> > > +}
> > > +
> > > +static int __devinit adp5520_led_prepare(struct platform_device *pdev)
> > > +{
> > > + struct adp5520_leds_platform_data *pdata = pdev->dev.platform_data;
> > > + struct device *dev = pdev->dev.parent;
> > > + int ret = 0;
> > > +
> > > + ret |= adp5520_write(dev, ADP5520_LED1_CURRENT, 0);
> > > + ret |= adp5520_write(dev, ADP5520_LED2_CURRENT, 0);
> > > + ret |= adp5520_write(dev, ADP5520_LED3_CURRENT, 0);
> > > + ret |= adp5520_write(dev, ADP5520_LED_TIME, pdata->led_on_time << 6);
> > > + ret |= adp5520_write(dev, ADP5520_LED_FADE, FADE_VAL(pdata->fade_in,
> > > + pdata->fade_out));
> > > +
> > > + return ret;
> > > +}
> > > +
> > > +static int __devinit adp5520_led_probe(struct platform_device *pdev)
> > > +{
> > > + struct adp5520_leds_platform_data *pdata = pdev->dev.platform_data;
> > > + struct adp5520_led *led, *led_dat;
> > > + struct led_info *cur_led;
> > > + int ret, i;
> > > +
> > > + if (pdata == NULL) {
> > > + dev_err(&pdev->dev, "missing platform data\n");
> > > + return -ENODEV;
> > > + }
> > > +
> > > + if (pdata->num_leds > ADP5520_01_MAXLEDS) {
> > > + dev_err(&pdev->dev, "can't handle more than %d LEDS\n",
> > > + ADP5520_01_MAXLEDS);
> > > + return -EFAULT;
> > > + }
> > > +
> > > + led = kzalloc(sizeof(*led) * pdata->num_leds, GFP_KERNEL);
> > > + if (led == NULL) {
> > > + dev_err(&pdev->dev, "failed to alloc memory\n");
> > > + return -ENOMEM;
> > > + }
> > > +
> > > + ret = adp5520_led_prepare(pdev);
> > > +
> > > + if (ret) {
> > > + dev_err(&pdev->dev, "failed to write\n");
> > > + goto err_free;
> > > + }
> > > +
> > > + for (i = 0; i < pdata->num_leds; ++i) {
> > > + cur_led = &pdata->leds[i];
> > > + led_dat = &led[i];
> > > +
> > > + led_dat->cdev.name = cur_led->name;
> > > + led_dat->cdev.default_trigger = cur_led->default_trigger;
> > > + led_dat->cdev.brightness_set = adp5520_led_set;
> > > + led_dat->cdev.brightness = LED_OFF;
> > > +
> > > + if (cur_led->flags & ADP5520_FLAG_LED_MASK)
> > > + led_dat->flags = cur_led->flags;
> > > + else
> > > + led_dat->flags = i + 1;
> > > +
> > > + led_dat->id = led_dat->flags & ADP5520_FLAG_LED_MASK;
> > > +
> > > + led_dat->master = pdev->dev.parent;
> > > + led_dat->new_brightness = LED_OFF;
> > > +
> > > + INIT_WORK(&led_dat->work, adp5520_led_work);
> > > +
> > > + ret = led_classdev_register(led_dat->master, &led_dat->cdev);
> > > + if (ret) {
> > > + dev_err(&pdev->dev, "failed to register LED %d\n",
> > > + led_dat->id);
> > > + goto err;
> > > + }
> > > +
> > > + ret = adp5520_led_setup(led_dat);
> > > + if (ret) {
> > > + dev_err(&pdev->dev, "failed to write\n");
> > > + i++;
> > > + goto err;
> > > + }
> > > + }
> > > +
> > > + platform_set_drvdata(pdev, led);
> > > + return 0;
> > > +
> > > +err:
> > > + if (i > 0) {
> > > + for (i = i - 1; i >= 0; i--) {
> > > + led_classdev_unregister(&led[i].cdev);
> > > + cancel_work_sync(&led[i].work);
> > > + }
> > > + }
> > > +
> > > +err_free:
> > > + kfree(led);
> > > + return ret;
> > > +}
> > > +
> > > +static int __devexit adp5520_led_remove(struct platform_device *pdev)
> > > +{
> > > + struct adp5520_leds_platform_data *pdata = pdev->dev.platform_data;
> > > + struct adp5520_led *led;
> > > + int i;
> > > +
> > > + led = platform_get_drvdata(pdev);
> > > +
> > > + adp5520_clr_bits(led->master, ADP5520_LED_CONTROL,
> > > + ADP5520_LED1_EN | ADP5520_LED2_EN | ADP5520_LED3_EN);
> > > +
> > > + for (i = 0; i < pdata->num_leds; i++) {
> > > + led_classdev_unregister(&led[i].cdev);
> > > + cancel_work_sync(&led[i].work);
> > > + }
> > > +
> > > + kfree(led);
> > > + return 0;
> > > +}
> > > +
> > > +static struct platform_driver adp5520_led_driver = {
> > > + .driver = {
> > > + .name = "adp5520-led",
> > > + .owner = THIS_MODULE,
> > > + },
> > > + .probe = adp5520_led_probe,
> > > + .remove = __devexit_p(adp5520_led_remove),
> > > +};
> > > +
> > > +static int __init adp5520_led_init(void)
> > > +{
> > > + return platform_driver_register(&adp5520_led_driver);
> > > +}
> > > +module_init(adp5520_led_init);
> > > +
> > > +static void __exit adp5520_led_exit(void)
> > > +{
> > > + platform_driver_unregister(&adp5520_led_driver);
> > > +}
> > > +module_exit(adp5520_led_exit);
> > > +
> > > +MODULE_AUTHOR("Michael Hennerich <[email protected]>");
> > > +MODULE_DESCRIPTION("LEDS ADP5520(01) Driver");
> > > +MODULE_LICENSE("GPL");
> > > +MODULE_ALIAS("platform:adp5520-led");
> > > --
> > > 1.6.5.rc2
> > >
> >
>
--
Intel Open Source Technology Centre
http://oss.intel.com/