mirror of
https://github.com/Fishwaldo/build.git
synced 2025-03-22 23:01:56 +00:00
229 lines
6.4 KiB
Text
229 lines
6.4 KiB
Text
diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
|
|
index 44097a3e0..a0cbdbb2c 100644
|
|
--- a/drivers/leds/Kconfig
|
|
+++ b/drivers/leds/Kconfig
|
|
@@ -756,6 +756,14 @@ config LEDS_NIC78BX
|
|
To compile this driver as a module, choose M here: the module
|
|
will be called leds-nic78bx.
|
|
|
|
+config LEDS_AXP20X
|
|
+ tristate "LED support for AXP20X-like PMICs (AXP813, ...)"
|
|
+ depends on LEDS_CLASS && MFD_AXP20X
|
|
+ help
|
|
+ This option enables support for on-chip LED drivers on
|
|
+ AXP20X-like PMICs.
|
|
+
|
|
+
|
|
comment "LED Triggers"
|
|
source "drivers/leds/trigger/Kconfig"
|
|
|
|
diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
|
|
index 420b5d2cf..a8149fb6e 100644
|
|
--- a/drivers/leds/Makefile
|
|
+++ b/drivers/leds/Makefile
|
|
@@ -78,6 +78,7 @@ obj-$(CONFIG_LEDS_MT6323) += leds-mt6323.o
|
|
obj-$(CONFIG_LEDS_LM3692X) += leds-lm3692x.o
|
|
obj-$(CONFIG_LEDS_SC27XX_BLTC) += leds-sc27xx-bltc.o
|
|
obj-$(CONFIG_LEDS_LM3601X) += leds-lm3601x.o
|
|
+obj-$(CONFIG_LEDS_AXP20X) += leds-axp20x.o
|
|
|
|
# LED SPI Drivers
|
|
obj-$(CONFIG_LEDS_CR0014114) += leds-cr0014114.o
|
|
diff --git a/drivers/leds/leds-axp20x.c b/drivers/leds/leds-axp20x.c
|
|
new file mode 100644
|
|
index 000000000..de33c1d83
|
|
--- /dev/null
|
|
+++ b/drivers/leds/leds-axp20x.c
|
|
@@ -0,0 +1,138 @@
|
|
+/*
|
|
+ * LED Driver for X-Powers AXP813 PMIC.
|
|
+ *
|
|
+ * Copyright(c) 2017 Ondrej Jirman <megous@megous.com>
|
|
+ *
|
|
+ * This program is free software; you can redistribute it and/or modify it
|
|
+ * under the terms of the GNU General Public License as published by the
|
|
+ * Free Software Foundation; either version 2 of the License, or (at your
|
|
+ * option) any later version.
|
|
+ */
|
|
+
|
|
+#include <linux/module.h>
|
|
+#include <linux/kernel.h>
|
|
+#include <linux/platform_device.h>
|
|
+#include <linux/leds.h>
|
|
+#include <linux/slab.h>
|
|
+#include <linux/of.h>
|
|
+#include <linux/of_device.h>
|
|
+#include <linux/mfd/axp20x.h>
|
|
+
|
|
+#define AXP813_CHGLED_CTRL_MASK BIT(3)
|
|
+#define AXP813_CHGLED_CTRL_CHARGER BIT(3)
|
|
+#define AXP813_CHGLED_CTRL_USER 0
|
|
+
|
|
+#define AXP813_CHGLED_USER_STATE_MASK GENMASK(5, 4)
|
|
+#define AXP813_CHGLED_USER_STATE_OFFSET 4
|
|
+#define AXP813_CHGLED_USER_STATE_OFF 0
|
|
+#define AXP813_CHGLED_USER_STATE_BLINK_SLOW 1
|
|
+#define AXP813_CHGLED_USER_STATE_BLINK_FAST 2
|
|
+#define AXP813_CHGLED_USER_STATE_ON 3
|
|
+
|
|
+struct axp20x_led {
|
|
+ struct led_classdev cdev;
|
|
+ struct regmap *regmap;
|
|
+};
|
|
+
|
|
+static int axp20x_led_set(struct led_classdev *led_cdev,
|
|
+ enum led_brightness value)
|
|
+{
|
|
+ struct axp20x_led *led =
|
|
+ container_of(led_cdev, struct axp20x_led, cdev);
|
|
+ unsigned int val;
|
|
+
|
|
+ val = value == LED_OFF ? AXP813_CHGLED_USER_STATE_OFF :
|
|
+ AXP813_CHGLED_USER_STATE_ON;
|
|
+
|
|
+ return regmap_update_bits(led->regmap, AXP20X_OFF_CTRL,
|
|
+ AXP813_CHGLED_USER_STATE_MASK,
|
|
+ val << AXP813_CHGLED_USER_STATE_OFFSET);
|
|
+
|
|
+}
|
|
+
|
|
+static int axp20x_led_probe(struct platform_device *pdev)
|
|
+{
|
|
+ struct axp20x_dev *axp20x;
|
|
+ struct axp20x_led *led;
|
|
+ int ret;
|
|
+
|
|
+ if (!of_device_is_available(pdev->dev.of_node))
|
|
+ return -ENODEV;
|
|
+
|
|
+ axp20x = dev_get_drvdata(pdev->dev.parent);
|
|
+ if (!axp20x)
|
|
+ return -EINVAL;
|
|
+
|
|
+ led = devm_kzalloc(&pdev->dev,
|
|
+ sizeof(struct axp20x_led),
|
|
+ GFP_KERNEL);
|
|
+ if (!led)
|
|
+ return -ENOMEM;
|
|
+
|
|
+ led->regmap = axp20x->regmap;
|
|
+
|
|
+ led->cdev.name = "chgled";
|
|
+ led->cdev.brightness_set_blocking = axp20x_led_set;
|
|
+ led->cdev.brightness = LED_OFF;
|
|
+ led->cdev.max_brightness = 1;
|
|
+
|
|
+ ret = led_classdev_register(pdev->dev.parent, &led->cdev);
|
|
+ if (ret) {
|
|
+ dev_err(&pdev->dev, "Failed to register led %s\n",
|
|
+ led->cdev.name);
|
|
+ return ret;
|
|
+ }
|
|
+
|
|
+ ret = regmap_update_bits(led->regmap, AXP20X_OFF_CTRL,
|
|
+ AXP813_CHGLED_CTRL_MASK,
|
|
+ AXP813_CHGLED_CTRL_USER);
|
|
+ if (ret) {
|
|
+ dev_err(&pdev->dev, "Failed to enable user cnotrol\n");
|
|
+ }
|
|
+
|
|
+ ret = axp20x_led_set(&led->cdev, led->cdev.brightness);
|
|
+ if (ret) {
|
|
+ dev_err(&pdev->dev, "Failed to init led %s\n",
|
|
+ led->cdev.name);
|
|
+ }
|
|
+
|
|
+ platform_set_drvdata(pdev, led);
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+static int axp20x_led_remove(struct platform_device *pdev)
|
|
+{
|
|
+ struct axp20x_led *led = platform_get_drvdata(pdev);
|
|
+
|
|
+ axp20x_led_set(&led->cdev, LED_OFF);
|
|
+
|
|
+ regmap_update_bits(led->regmap, AXP20X_OFF_CTRL,
|
|
+ AXP813_CHGLED_CTRL_MASK,
|
|
+ AXP813_CHGLED_CTRL_CHARGER);
|
|
+
|
|
+ led_classdev_unregister(&led->cdev);
|
|
+
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+static const struct of_device_id axp20x_leds_of_match[] = {
|
|
+ { .compatible = "x-powers,axp813-leds", },
|
|
+ { },
|
|
+};
|
|
+MODULE_DEVICE_TABLE(of, axp20x_leds_of_match);
|
|
+
|
|
+static struct platform_driver axp20x_led_driver = {
|
|
+ .driver = {
|
|
+ .name = "axp20x-leds",
|
|
+ .of_match_table = axp20x_leds_of_match,
|
|
+ },
|
|
+ .probe = axp20x_led_probe,
|
|
+ .remove = axp20x_led_remove,
|
|
+};
|
|
+
|
|
+module_platform_driver(axp20x_led_driver);
|
|
+
|
|
+MODULE_AUTHOR("Ondrej Jirman <megous@megous.com>");
|
|
+MODULE_DESCRIPTION("LED driver for AXP813 PMIC");
|
|
+MODULE_LICENSE("GPL");
|
|
+MODULE_ALIAS("platform:leds-axp20x");
|
|
diff --git a/drivers/mfd/axp20x.c b/drivers/mfd/axp20x.c
|
|
index 0be511dd9..a9bdf3cdd 100644
|
|
--- a/drivers/mfd/axp20x.c
|
|
+++ b/drivers/mfd/axp20x.c
|
|
@@ -24,6 +24,7 @@
|
|
#include <linux/pm_runtime.h>
|
|
#include <linux/regmap.h>
|
|
#include <linux/regulator/consumer.h>
|
|
+#include <linux/regulator/userspace-consumer.h>
|
|
#include <linux/mfd/axp20x.h>
|
|
#include <linux/mfd/core.h>
|
|
#include <linux/of_device.h>
|
|
@@ -130,6 +131,7 @@ static const struct regmap_range axp288_volatile_ranges[] = {
|
|
regmap_reg_range(AXP288_BC_GLOBAL, AXP288_BC_GLOBAL),
|
|
regmap_reg_range(AXP288_BC_DET_STAT, AXP288_BC_DET_STAT),
|
|
regmap_reg_range(AXP20X_CHRG_BAK_CTRL, AXP20X_CHRG_BAK_CTRL),
|
|
+ regmap_reg_range(AXP22X_CHRG_CTRL3, AXP22X_CHRG_CTRL3),
|
|
regmap_reg_range(AXP20X_IRQ1_EN, AXP20X_IPSOUT_V_HIGH_L),
|
|
regmap_reg_range(AXP20X_TIMER_CTRL, AXP20X_TIMER_CTRL),
|
|
regmap_reg_range(AXP22X_GPIO_STATE, AXP22X_GPIO_STATE),
|
|
@@ -762,6 +764,16 @@ static const struct mfd_cell axp809_cells[] = {
|
|
},
|
|
};
|
|
|
|
+static struct regulator_bulk_data vcc_vb = {
|
|
+ .supply = "vcc-vb",
|
|
+};
|
|
+
|
|
+static struct regulator_userspace_consumer_data vcc_vb_data = {
|
|
+ .name = "vcc-vb",
|
|
+ .num_supplies = 1,
|
|
+ .supplies = &vcc_vb,
|
|
+};
|
|
+
|
|
static const struct mfd_cell axp813_cells[] = {
|
|
{
|
|
.name = "axp221-pek",
|
|
@@ -778,6 +790,16 @@ static const struct mfd_cell axp813_cells[] = {
|
|
}, {
|
|
.name = "axp20x-battery-power-supply",
|
|
.of_compatible = "x-powers,axp813-battery-power-supply",
|
|
+ }, {
|
|
+ .name = "axp20x-usb-power-supply",
|
|
+ .of_compatible = "x-powers,axp813-usb-power-supply",
|
|
+ }, {
|
|
+ .name = "axp20x-leds",
|
|
+ .of_compatible = "x-powers,axp813-leds",
|
|
+ }, {
|
|
+ .name = "reg-userspace-consumer",
|
|
+ .platform_data = &vcc_vb_data,
|
|
+ .pdata_size = sizeof(vcc_vb_data),
|
|
},
|
|
};
|
|
|