From 067cfc1c2ea382b0820d995f476e2a26713a3200 Mon Sep 17 00:00:00 2001 From: Ivan Vozvakhov Date: Sat, 12 Mar 2022 13:03:14 +0300 Subject: led: led_pwm: Add a driver for LEDs connected to PWM Add a driver which allows to use of LEDs connected to PWM (Linux compatible). MAINTAINERS: add i.vozvakhov as a maintainer of leds-pwm C(required during new functionality adding). Signed-off-by: Ivan Vozvakhov --- drivers/led/Kconfig | 6 ++ drivers/led/Makefile | 1 + drivers/led/led_pwm.c | 192 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 199 insertions(+) create mode 100644 drivers/led/led_pwm.c (limited to 'drivers') diff --git a/drivers/led/Kconfig b/drivers/led/Kconfig index 430d0760ba5..418ed215c57 100644 --- a/drivers/led/Kconfig +++ b/drivers/led/Kconfig @@ -49,6 +49,12 @@ config LED_CORTINA This option enables support for LEDs connected to the Cortina Access CAxxxx SOCs. +config LED_PWM + bool "LED PWM" + depends on LED && DM_PWM + help + Enable support for LEDs connected to PWM. + Linux compatible ofdata. config LED_BLINK bool "Support LED blinking" diff --git a/drivers/led/Makefile b/drivers/led/Makefile index 2aa2c2173af..49ae91961d5 100644 --- a/drivers/led/Makefile +++ b/drivers/led/Makefile @@ -8,5 +8,6 @@ obj-$(CONFIG_LED_BCM6328) += led_bcm6328.o obj-$(CONFIG_LED_BCM6358) += led_bcm6358.o obj-$(CONFIG_LED_BCM6753) += led_bcm6753.o obj-$(CONFIG_LED_BCM6858) += led_bcm6858.o +obj-$(CONFIG_LED_PWM) += led_pwm.o obj-$(CONFIG_$(SPL_)LED_GPIO) += led_gpio.o obj-$(CONFIG_LED_CORTINA) += led_cortina.o diff --git a/drivers/led/led_pwm.c b/drivers/led/led_pwm.c new file mode 100644 index 00000000000..4e502722587 --- /dev/null +++ b/drivers/led/led_pwm.c @@ -0,0 +1,192 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2022 VK + * Author: Ivan Vozvakhov + */ + +#include +#include +#include +#include +#include +#include +#include + +#define LEDS_PWM_DRIVER_NAME "led_pwm" + +struct led_pwm_priv { + struct udevice *pwm; + uint period; /* period in ns */ + uint duty; /* duty cycle in ns */ + uint channel; /* pwm channel number */ + bool active_low; /* pwm polarity */ + bool enabled; +}; + +static int led_pwm_enable(struct udevice *dev) +{ + struct led_pwm_priv *priv = dev_get_priv(dev); + int ret; + + ret = pwm_set_invert(priv->pwm, priv->channel, priv->active_low); + if (ret) + return ret; + + ret = pwm_set_config(priv->pwm, priv->channel, priv->period, priv->duty); + if (ret) + return ret; + + ret = pwm_set_enable(priv->pwm, priv->channel, true); + if (ret) + return ret; + + priv->enabled = true; + + return 0; +} + +static int led_pwm_disable(struct udevice *dev) +{ + struct led_pwm_priv *priv = dev_get_priv(dev); + int ret; + + ret = pwm_set_config(priv->pwm, priv->channel, priv->period, 0); + if (ret) + return ret; + + ret = pwm_set_enable(priv->pwm, priv->channel, false); + if (ret) + return ret; + + priv->enabled = false; + + return 0; +} + +static int led_pwm_set_state(struct udevice *dev, enum led_state_t state) +{ + struct led_pwm_priv *priv = dev_get_priv(dev); + int ret; + + switch (state) { + case LEDST_OFF: + ret = led_pwm_disable(dev); + break; + case LEDST_ON: + ret = led_pwm_enable(dev); + break; + case LEDST_TOGGLE: + ret = (priv->enabled) ? led_pwm_disable(dev) : led_pwm_enable(dev); + break; + default: + ret = -ENOSYS; + } + + return ret; +} + +static enum led_state_t led_pwm_get_state(struct udevice *dev) +{ + struct led_pwm_priv *priv = dev_get_priv(dev); + + return (priv->enabled) ? LEDST_ON : LEDST_OFF; +} + +static int led_pwm_probe(struct udevice *dev) +{ + struct led_pwm_priv *priv = dev_get_priv(dev); + struct led_uc_plat *uc_plat = dev_get_uclass_plat(dev); + + /* Ignore the top-level LED node */ + if (!uc_plat->label) + return 0; + + return led_pwm_set_state(dev, (priv->enabled) ? LEDST_ON : LEDST_OFF); +} + +static int led_pwm_of_to_plat(struct udevice *dev) +{ + struct led_uc_plat *uc_plat = dev_get_uclass_plat(dev); + struct led_pwm_priv *priv = dev_get_priv(dev); + struct ofnode_phandle_args args; + uint def_brightness, max_brightness; + int ret; + + /* Ignore the top-level LED node */ + if (!uc_plat->label) + return 0; + + ret = dev_read_phandle_with_args(dev, "pwms", "#pwm-cells", 0, 0, &args); + if (ret) + return ret; + + ret = uclass_get_device_by_ofnode(UCLASS_PWM, args.node, &priv->pwm); + if (ret) + return ret; + + priv->channel = args.args[0]; + priv->period = args.args[1]; + priv->active_low = dev_read_bool(dev, "active-low"); + + def_brightness = dev_read_u32_default(dev, "u-boot,default-brightness", 0); + max_brightness = dev_read_u32_default(dev, "max-brightness", 255); + priv->enabled = !!def_brightness; + + /* + * No need to handle pwm iverted case (active_low) + * because of pwm_set_invert function + */ + if (def_brightness < max_brightness) + priv->duty = priv->period * def_brightness / max_brightness; + else + priv->duty = priv->period; + + return 0; +} + +static int led_pwm_bind(struct udevice *parent) +{ + struct udevice *dev; + ofnode node; + int ret; + + dev_for_each_subnode(node, parent) { + struct led_uc_plat *uc_plat; + const char *label; + + label = ofnode_read_string(node, "label"); + if (!label) + label = ofnode_get_name(node); + + ret = device_bind_driver_to_node(parent, LEDS_PWM_DRIVER_NAME, + ofnode_get_name(node), + node, &dev); + if (ret) + return ret; + + uc_plat = dev_get_uclass_plat(dev); + uc_plat->label = label; + } + return 0; +} + +static const struct led_ops led_pwm_ops = { + .set_state = led_pwm_set_state, + .get_state = led_pwm_get_state, +}; + +static const struct udevice_id led_pwm_ids[] = { + { .compatible = "pwm-leds" }, + { } +}; + +U_BOOT_DRIVER(led_pwm) = { + .name = LEDS_PWM_DRIVER_NAME, + .id = UCLASS_LED, + .of_match = led_pwm_ids, + .ops = &led_pwm_ops, + .priv_auto = sizeof(struct led_pwm_priv), + .bind = led_pwm_bind, + .probe = led_pwm_probe, + .of_to_plat = led_pwm_of_to_plat, +}; -- cgit v1.3.1 From 877de2a369aaeebe7fb0a2f8f1438255d249c6c0 Mon Sep 17 00:00:00 2001 From: Paul HENRYS Date: Thu, 17 Mar 2022 10:29:47 +0100 Subject: drivers: led: bcm6858: Set a default brightness when probing LEDs When probing the LEDs, a default brightness is set based on settings from the U-Boot device tree, i.e. the 'default-brightness' property of the LED nodes. If that property is not present, the default maximum brightness is set. This should make sure the LED controller's registers affecting the brightness are correctly initialized and should give a consistent behaviour. Signed-off-by: Paul HENRYS --- drivers/led/led_bcm6858.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'drivers') diff --git a/drivers/led/led_bcm6858.c b/drivers/led/led_bcm6858.c index fbf46a114c5..3ca6c5b8a9e 100644 --- a/drivers/led/led_bcm6858.c +++ b/drivers/led/led_bcm6858.c @@ -18,6 +18,7 @@ #define LEDS_MAX 32 #define LEDS_WAIT 100 +#define LEDS_MAX_BRIGHTNESS 7 /* LED Mode register */ #define LED_MODE_REG 0x0 @@ -38,6 +39,8 @@ #define LED_HW_LED_EN_REG 0x08 /* LED Flash control register0 */ #define LED_FLASH_RATE_CONTROL_REG0 0x10 +/* LED Brightness control register0 */ +#define LED_BRIGHTNESS_CONTROL_REG0 0x20 /* Soft LED input register */ #define LED_SW_LED_IP_REG 0xb8 /* Parallel LED Output Polarity Register */ @@ -96,6 +99,27 @@ static int bcm6858_led_set_period(struct udevice *dev, int period_ms) } #endif +static int led_set_brightness(struct udevice *dev, unsigned int brightness) +{ + struct bcm6858_led_priv *priv = dev_get_priv(dev); + u32 offset, shift, mask, value; + + offset = (priv->pin / 8) * 4; + shift = (priv->pin % 8) * 4; + mask = 0xf << shift; + + /* 8 levels of brightness achieved through PWM */ + value = (brightness > LEDS_MAX_BRIGHTNESS ? + LEDS_MAX_BRIGHTNESS : brightness) << shift; + + debug("%s: %s brightness set to %u\n", __func__, dev->name, value >> shift); + + clrbits_32(priv->regs + LED_BRIGHTNESS_CONTROL_REG0 + offset, mask); + setbits_32(priv->regs + LED_BRIGHTNESS_CONTROL_REG0 + offset, value); + + return 0; +} + static enum led_state_t bcm6858_led_get_state(struct udevice *dev) { struct bcm6858_led_priv *priv = dev_get_priv(dev); @@ -113,6 +137,8 @@ static int bcm6858_led_set_state(struct udevice *dev, enum led_state_t state) { struct bcm6858_led_priv *priv = dev_get_priv(dev); + debug("%s: Set led %s to %d\n", __func__, dev->name, state); + switch (state) { case LEDST_OFF: clrbits_32(priv->regs + LED_SW_LED_IP_REG, (1 << priv->pin)); @@ -180,7 +206,7 @@ static int bcm6858_led_probe(struct udevice *dev) } else { struct bcm6858_led_priv *priv = dev_get_priv(dev); void __iomem *regs; - unsigned int pin; + unsigned int pin, brightness; regs = dev_remap_addr(dev_get_parent(dev)); if (!regs) @@ -201,6 +227,10 @@ static int bcm6858_led_probe(struct udevice *dev) clrbits_32(regs + LED_PLED_OP_PPOL_REG, 1 << pin); else setbits_32(regs + LED_PLED_OP_PPOL_REG, 1 << pin); + + brightness = dev_read_u32_default(dev, "default-brightness", + LEDS_MAX_BRIGHTNESS); + led_set_brightness(dev, brightness); } return 0; -- cgit v1.3.1 From c86a4de8df611b58ec41ae6c42c6fec58e5ab54f Mon Sep 17 00:00:00 2001 From: Patrice Chotard Date: Mon, 21 Mar 2022 09:13:36 +0100 Subject: mtd: Add flash_node in struct mtd_info Currently, add_mtd_partitions_of() can be used only if dev field of mtd_info struct is populated. It's the case, for example, for a spi nor flash, which has a DT compatible "jedec,spi-nor" and an associated device. mtd->dev is populated in spi_nor_scan(). But in case of a raw nand node, mtd_info's dev field can't be populated as flash node has no compatible, so no associated device. add_mtd_partitions_of() can't be used to parse "partitions" subnode. To remove this constraint, add an ofnode field in mtd_info struct which reference the DT flash node. This new field is populated by nand_scan_tail(). This new field will be used by add_mtd_partitions_of() to parse the flash node for "partitions" defined in DT. Signed-off-by: Patrice Chotard Cc: Farhan Ali Cc: Heinrich Schuchardt Cc: Jagan Teki Cc: Marek Behun Cc: Miquel Raynal Cc: Simon Glass Cc: Wolfgang Denk --- drivers/mtd/nand/raw/nand_base.c | 1 + include/linux/mtd/mtd.h | 1 + 2 files changed, 2 insertions(+) (limited to 'drivers') diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c index f7616985d95..a007603df14 100644 --- a/drivers/mtd/nand/raw/nand_base.c +++ b/drivers/mtd/nand/raw/nand_base.c @@ -5257,6 +5257,7 @@ int nand_scan_tail(struct mtd_info *mtd) break; } + mtd->flash_node = chip->flash_node; /* Fill in remaining MTD driver data */ mtd->type = nand_is_slc(chip) ? MTD_NANDFLASH : MTD_MLCNANDFLASH; mtd->flags = (chip->options & NAND_ROM) ? MTD_CAP_ROM : diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h index 74554009815..af45e63bf9c 100644 --- a/include/linux/mtd/mtd.h +++ b/include/linux/mtd/mtd.h @@ -305,6 +305,7 @@ struct mtd_info { struct device dev; #else struct udevice *dev; + ofnode flash_node; #endif int usecount; -- cgit v1.3.1 From 7ab3364c6d1c17b8ee6da523d5729b0248ba63bf Mon Sep 17 00:00:00 2001 From: Patrice Chotard Date: Mon, 21 Mar 2022 09:13:37 +0100 Subject: mtd: Update the way partitions are parsed In case mtd_info's dev field is not populated (raw nand's case), use the flash_node new field which reference the DT flash node where can be found "partitions" node with "fixed-partitions" compatible. Signed-off-by: Patrice Chotard Cc: Farhan Ali Cc: Heinrich Schuchardt Cc: Jagan Teki Cc: Marek Behun Cc: Miquel Raynal Cc: Simon Glass Cc: Wolfgang Denk --- drivers/mtd/mtdpart.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'drivers') diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c index 4119ea4ff6b..d077897e4a7 100644 --- a/drivers/mtd/mtdpart.c +++ b/drivers/mtd/mtdpart.c @@ -887,10 +887,14 @@ int add_mtd_partitions_of(struct mtd_info *master) ofnode parts, child; int i = 0; - if (!master->dev) + if (!master->dev && !ofnode_valid(master->flash_node)) return 0; - parts = ofnode_find_subnode(mtd_get_ofnode(master), "partitions"); + if (master->dev) + parts = ofnode_find_subnode(mtd_get_ofnode(master), "partitions"); + else + parts = ofnode_find_subnode(master->flash_node, "partitions"); + if (!ofnode_valid(parts) || !ofnode_is_available(parts) || !ofnode_device_is_compatible(parts, "fixed-partitions")) return 0; -- cgit v1.3.1 From c3322a53f34f986ad9818df72707ebb59c9c8725 Mon Sep 17 00:00:00 2001 From: Hajo Noerenberg Date: Mon, 28 Mar 2022 15:49:08 +0200 Subject: ahci: add PCI bindings for Marvell 88SE6121/45 SATA controllers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add AHCI PCI bindings for Marvell 88SE6121/45 SATA controllers. The 88SE6121 controller is used, for example, in the Seagate Blackarmor NAS440 or the Iomega ix4-200d NAS. As Pali Rohár explained [1], these controllers do not match the standard AHCI class code and therefore require an explizit PCI binding. The Linux kernel also uses this approach [2]. [1] https://lists.denx.de/pipermail/u-boot/2022-March/479197.html [2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/ata/ahci.c?h=v5.17#n557 Signed-off-by: Hajo Noerenberg Reviewed-by: Pali Rohár --- drivers/ata/ahci-pci.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'drivers') diff --git a/drivers/ata/ahci-pci.c b/drivers/ata/ahci-pci.c index b1d231e0f9e..797e0d570e8 100644 --- a/drivers/ata/ahci-pci.c +++ b/drivers/ata/ahci-pci.c @@ -38,6 +38,8 @@ U_BOOT_DRIVER(ahci_pci) = { static struct pci_device_id ahci_pci_supported[] = { { PCI_DEVICE_CLASS(PCI_CLASS_STORAGE_SATA_AHCI, ~0) }, { PCI_DEVICE(0x1b21, 0x0611) }, + { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x6121) }, + { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x6145) }, {}, }; -- cgit v1.3.1