Skip to content

Commit

Permalink
Merge tag 'leds-5.18-rc1' of git://git.kernel.org/pub/scm/linux/kerne…
Browse files Browse the repository at this point in the history
…l/git/pavel/linux-leds

Pull LED updates from Pavel Machek:
 "Nothing major here, there are two drivers that need review and did not
  make it into this round"

* tag 'leds-5.18-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/pavel/linux-leds:
  leds: pca955x: Allow zero LEDs to be specified
  leds: pca955x: Make the gpiochip always expose all pins
  leds: simatic-ipc-leds: Don't directly deref ioremap_resource() returned ptr
  leds: simatic-ipc-leds: Make simatic_ipc_led_mem_res static
  leds: lm3692x: Return 0 from remove callback
  leds: sgm3140: Add ocs,ocp8110 compatible
  dt-bindings: vendor-prefixes: Add ocs prefix
  dt-bindings: leds: common: fix unit address in max77693 example
  • Loading branch information
Linus Torvalds committed Mar 27, 2022
2 parents 7b58b82 + e26557a commit dfb0a0b
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 53 deletions.
9 changes: 7 additions & 2 deletions Documentation/devicetree/bindings/leds/common.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,11 @@ examples:
};
};
led-controller@0 {
- |
#include <dt-bindings/leds/common.h>
led-controller {
compatible = "maxim,max77693-led";
reg = <0 0x100>;
led {
function = LED_FUNCTION_FLASH;
Expand All @@ -199,6 +201,9 @@ examples:
};
};
- |
#include <dt-bindings/leds/common.h>
i2c {
#address-cells = <1>;
#size-cells = <0>;
Expand Down
2 changes: 2 additions & 0 deletions Documentation/devicetree/bindings/vendor-prefixes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,8 @@ patternProperties:
description: NXP Semiconductors
"^oceanic,.*":
description: Oceanic Systems (UK) Ltd.
"^ocs,.*":
description: Orient Chip Technology Co., Ltd.
"^oct,.*":
description: Octavo Systems LLC
"^okaya,.*":
Expand Down
1 change: 1 addition & 0 deletions drivers/leds/flash/leds-sgm3140.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ static int sgm3140_remove(struct platform_device *pdev)
}

static const struct of_device_id sgm3140_dt_match[] = {
{ .compatible = "ocs,ocp8110" },
{ .compatible = "sgmicro,sgm3140" },
{ /* sentinel */ }
};
Expand Down
5 changes: 1 addition & 4 deletions drivers/leds/leds-lm3692x.c
Original file line number Diff line number Diff line change
Expand Up @@ -494,11 +494,8 @@ static int lm3692x_probe(struct i2c_client *client,
static int lm3692x_remove(struct i2c_client *client)
{
struct lm3692x_led *led = i2c_get_clientdata(client);
int ret;

ret = lm3692x_leds_disable(led);
if (ret)
return ret;
lm3692x_leds_disable(led);
mutex_destroy(&led->lock);

return 0;
Expand Down
67 changes: 35 additions & 32 deletions drivers/leds/leds-pca955x.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
* bits the chip supports.
*/

#include <linux/bitops.h>
#include <linux/ctype.h>
#include <linux/delay.h>
#include <linux/err.h>
Expand Down Expand Up @@ -118,6 +119,7 @@ struct pca955x {
struct pca955x_led *leds;
struct pca955x_chipdef *chipdef;
struct i2c_client *client;
unsigned long active_pins;
#ifdef CONFIG_LEDS_PCA955X_GPIO
struct gpio_chip gpio;
#endif
Expand Down Expand Up @@ -360,12 +362,15 @@ static int pca955x_read_input(struct i2c_client *client, int n, u8 *val)
static int pca955x_gpio_request_pin(struct gpio_chip *gc, unsigned int offset)
{
struct pca955x *pca955x = gpiochip_get_data(gc);
struct pca955x_led *led = &pca955x->leds[offset];

if (led->type == PCA955X_TYPE_GPIO)
return 0;
return test_and_set_bit(offset, &pca955x->active_pins) ? -EBUSY : 0;
}

static void pca955x_gpio_free_pin(struct gpio_chip *gc, unsigned int offset)
{
struct pca955x *pca955x = gpiochip_get_data(gc);

return -EBUSY;
clear_bit(offset, &pca955x->active_pins);
}

static int pca955x_set_value(struct gpio_chip *gc, unsigned int offset,
Expand Down Expand Up @@ -424,7 +429,7 @@ pca955x_get_pdata(struct i2c_client *client, struct pca955x_chipdef *chip)
int count;

count = device_get_child_node_count(&client->dev);
if (!count || count > chip->bits)
if (count > chip->bits)
return ERR_PTR(-ENODEV);

pdata = devm_kzalloc(&client->dev, sizeof(*pdata), GFP_KERNEL);
Expand Down Expand Up @@ -489,7 +494,6 @@ static int pca955x_probe(struct i2c_client *client)
struct i2c_adapter *adapter;
int i, err;
struct pca955x_platform_data *pdata;
int ngpios = 0;
bool set_default_label = false;
bool keep_pwm = false;
char default_label[8];
Expand Down Expand Up @@ -567,9 +571,7 @@ static int pca955x_probe(struct i2c_client *client)

switch (pca955x_led->type) {
case PCA955X_TYPE_NONE:
break;
case PCA955X_TYPE_GPIO:
ngpios++;
break;
case PCA955X_TYPE_LED:
led = &pca955x_led->led_cdev;
Expand Down Expand Up @@ -613,6 +615,8 @@ static int pca955x_probe(struct i2c_client *client)
if (err)
return err;

set_bit(i, &pca955x->active_pins);

/*
* For default-state == "keep", let the core update the
* brightness from the hardware, then check the
Expand Down Expand Up @@ -650,31 +654,30 @@ static int pca955x_probe(struct i2c_client *client)
return err;

#ifdef CONFIG_LEDS_PCA955X_GPIO
if (ngpios) {
pca955x->gpio.label = "gpio-pca955x";
pca955x->gpio.direction_input = pca955x_gpio_direction_input;
pca955x->gpio.direction_output = pca955x_gpio_direction_output;
pca955x->gpio.set = pca955x_gpio_set_value;
pca955x->gpio.get = pca955x_gpio_get_value;
pca955x->gpio.request = pca955x_gpio_request_pin;
pca955x->gpio.can_sleep = 1;
pca955x->gpio.base = -1;
pca955x->gpio.ngpio = ngpios;
pca955x->gpio.parent = &client->dev;
pca955x->gpio.owner = THIS_MODULE;

err = devm_gpiochip_add_data(&client->dev, &pca955x->gpio,
pca955x);
if (err) {
/* Use data->gpio.dev as a flag for freeing gpiochip */
pca955x->gpio.parent = NULL;
dev_warn(&client->dev, "could not add gpiochip\n");
return err;
}
dev_info(&client->dev, "gpios %i...%i\n",
pca955x->gpio.base, pca955x->gpio.base +
pca955x->gpio.ngpio - 1);
pca955x->gpio.label = "gpio-pca955x";
pca955x->gpio.direction_input = pca955x_gpio_direction_input;
pca955x->gpio.direction_output = pca955x_gpio_direction_output;
pca955x->gpio.set = pca955x_gpio_set_value;
pca955x->gpio.get = pca955x_gpio_get_value;
pca955x->gpio.request = pca955x_gpio_request_pin;
pca955x->gpio.free = pca955x_gpio_free_pin;
pca955x->gpio.can_sleep = 1;
pca955x->gpio.base = -1;
pca955x->gpio.ngpio = chip->bits;
pca955x->gpio.parent = &client->dev;
pca955x->gpio.owner = THIS_MODULE;

err = devm_gpiochip_add_data(&client->dev, &pca955x->gpio,
pca955x);
if (err) {
/* Use data->gpio.dev as a flag for freeing gpiochip */
pca955x->gpio.parent = NULL;
dev_warn(&client->dev, "could not add gpiochip\n");
return err;
}
dev_info(&client->dev, "gpios %i...%i\n",
pca955x->gpio.base, pca955x->gpio.base +
pca955x->gpio.ngpio - 1);
#endif

return 0;
Expand Down
34 changes: 19 additions & 15 deletions drivers/leds/simple/simatic-ipc-leds.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ static struct simatic_ipc_led simatic_ipc_leds_io[] = {
};

/* the actual start will be discovered with PCI, 0 is a placeholder */
struct resource simatic_ipc_led_mem_res = DEFINE_RES_MEM_NAMED(0, SZ_4K, KBUILD_MODNAME);
static struct resource simatic_ipc_led_mem_res = DEFINE_RES_MEM_NAMED(0, SZ_4K, KBUILD_MODNAME);

static void *simatic_ipc_led_memory;
static void __iomem *simatic_ipc_led_memory;

static struct simatic_ipc_led simatic_ipc_leds_mem[] = {
{0x500 + 0x1A0, "red:" LED_FUNCTION_STATUS "-1"},
Expand Down Expand Up @@ -92,21 +92,22 @@ static void simatic_ipc_led_set_mem(struct led_classdev *led_cd,
enum led_brightness brightness)
{
struct simatic_ipc_led *led = cdev_to_led(led_cd);
void __iomem *reg = simatic_ipc_led_memory + led->value;
u32 val;

u32 *p;

p = simatic_ipc_led_memory + led->value;
*p = (*p & ~1) | (brightness == LED_OFF);
val = readl(reg);
val = (val & ~1) | (brightness == LED_OFF);
writel(val, reg);
}

static enum led_brightness simatic_ipc_led_get_mem(struct led_classdev *led_cd)
{
struct simatic_ipc_led *led = cdev_to_led(led_cd);
void __iomem *reg = simatic_ipc_led_memory + led->value;
u32 val;

u32 *p;

p = simatic_ipc_led_memory + led->value;
return (*p & 1) ? LED_OFF : led_cd->max_brightness;
val = readl(reg);
return (val & 1) ? LED_OFF : led_cd->max_brightness;
}

static int simatic_ipc_leds_probe(struct platform_device *pdev)
Expand All @@ -116,8 +117,9 @@ static int simatic_ipc_leds_probe(struct platform_device *pdev)
struct simatic_ipc_led *ipcled;
struct led_classdev *cdev;
struct resource *res;
void __iomem *reg;
int err, type;
u32 *p;
u32 val;

switch (plat->devmode) {
case SIMATIC_IPC_DEVICE_227D:
Expand Down Expand Up @@ -157,11 +159,13 @@ static int simatic_ipc_leds_probe(struct platform_device *pdev)
return PTR_ERR(simatic_ipc_led_memory);

/* initialize power/watchdog LED */
p = simatic_ipc_led_memory + 0x500 + 0x1D8; /* PM_WDT_OUT */
*p = (*p & ~1);
p = simatic_ipc_led_memory + 0x500 + 0x1C0; /* PM_BIOS_BOOT_N */
*p = (*p | 1);
reg = simatic_ipc_led_memory + 0x500 + 0x1D8; /* PM_WDT_OUT */
val = readl(reg);
writel(val & ~1, reg);

reg = simatic_ipc_led_memory + 0x500 + 0x1C0; /* PM_BIOS_BOOT_N */
val = readl(reg);
writel(val | 1, reg);
break;
default:
return -ENODEV;
Expand Down

0 comments on commit dfb0a0b

Please sign in to comment.