Skip to content

Commit dfb0a0b

Browse files
committed
Merge tag 'leds-5.18-rc1' of git://git.kernel.org/pub/scm/linux/kernel/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
2 parents 7b58b82 + e26557a commit dfb0a0b

File tree

6 files changed

+65
-53
lines changed

6 files changed

+65
-53
lines changed

Documentation/devicetree/bindings/leds/common.yaml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,11 @@ examples:
185185
};
186186
};
187187
188-
led-controller@0 {
188+
- |
189+
#include <dt-bindings/leds/common.h>
190+
191+
led-controller {
189192
compatible = "maxim,max77693-led";
190-
reg = <0 0x100>;
191193
192194
led {
193195
function = LED_FUNCTION_FLASH;
@@ -199,6 +201,9 @@ examples:
199201
};
200202
};
201203
204+
- |
205+
#include <dt-bindings/leds/common.h>
206+
202207
i2c {
203208
#address-cells = <1>;
204209
#size-cells = <0>;

Documentation/devicetree/bindings/vendor-prefixes.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,8 @@ patternProperties:
876876
description: NXP Semiconductors
877877
"^oceanic,.*":
878878
description: Oceanic Systems (UK) Ltd.
879+
"^ocs,.*":
880+
description: Orient Chip Technology Co., Ltd.
879881
"^oct,.*":
880882
description: Octavo Systems LLC
881883
"^okaya,.*":

drivers/leds/flash/leds-sgm3140.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ static int sgm3140_remove(struct platform_device *pdev)
290290
}
291291

292292
static const struct of_device_id sgm3140_dt_match[] = {
293+
{ .compatible = "ocs,ocp8110" },
293294
{ .compatible = "sgmicro,sgm3140" },
294295
{ /* sentinel */ }
295296
};

drivers/leds/leds-lm3692x.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -494,11 +494,8 @@ static int lm3692x_probe(struct i2c_client *client,
494494
static int lm3692x_remove(struct i2c_client *client)
495495
{
496496
struct lm3692x_led *led = i2c_get_clientdata(client);
497-
int ret;
498497

499-
ret = lm3692x_leds_disable(led);
500-
if (ret)
501-
return ret;
498+
lm3692x_leds_disable(led);
502499
mutex_destroy(&led->lock);
503500

504501
return 0;

drivers/leds/leds-pca955x.c

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
* bits the chip supports.
3838
*/
3939

40+
#include <linux/bitops.h>
4041
#include <linux/ctype.h>
4142
#include <linux/delay.h>
4243
#include <linux/err.h>
@@ -118,6 +119,7 @@ struct pca955x {
118119
struct pca955x_led *leds;
119120
struct pca955x_chipdef *chipdef;
120121
struct i2c_client *client;
122+
unsigned long active_pins;
121123
#ifdef CONFIG_LEDS_PCA955X_GPIO
122124
struct gpio_chip gpio;
123125
#endif
@@ -360,12 +362,15 @@ static int pca955x_read_input(struct i2c_client *client, int n, u8 *val)
360362
static int pca955x_gpio_request_pin(struct gpio_chip *gc, unsigned int offset)
361363
{
362364
struct pca955x *pca955x = gpiochip_get_data(gc);
363-
struct pca955x_led *led = &pca955x->leds[offset];
364365

365-
if (led->type == PCA955X_TYPE_GPIO)
366-
return 0;
366+
return test_and_set_bit(offset, &pca955x->active_pins) ? -EBUSY : 0;
367+
}
368+
369+
static void pca955x_gpio_free_pin(struct gpio_chip *gc, unsigned int offset)
370+
{
371+
struct pca955x *pca955x = gpiochip_get_data(gc);
367372

368-
return -EBUSY;
373+
clear_bit(offset, &pca955x->active_pins);
369374
}
370375

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

426431
count = device_get_child_node_count(&client->dev);
427-
if (!count || count > chip->bits)
432+
if (count > chip->bits)
428433
return ERR_PTR(-ENODEV);
429434

430435
pdata = devm_kzalloc(&client->dev, sizeof(*pdata), GFP_KERNEL);
@@ -489,7 +494,6 @@ static int pca955x_probe(struct i2c_client *client)
489494
struct i2c_adapter *adapter;
490495
int i, err;
491496
struct pca955x_platform_data *pdata;
492-
int ngpios = 0;
493497
bool set_default_label = false;
494498
bool keep_pwm = false;
495499
char default_label[8];
@@ -567,9 +571,7 @@ static int pca955x_probe(struct i2c_client *client)
567571

568572
switch (pca955x_led->type) {
569573
case PCA955X_TYPE_NONE:
570-
break;
571574
case PCA955X_TYPE_GPIO:
572-
ngpios++;
573575
break;
574576
case PCA955X_TYPE_LED:
575577
led = &pca955x_led->led_cdev;
@@ -613,6 +615,8 @@ static int pca955x_probe(struct i2c_client *client)
613615
if (err)
614616
return err;
615617

618+
set_bit(i, &pca955x->active_pins);
619+
616620
/*
617621
* For default-state == "keep", let the core update the
618622
* brightness from the hardware, then check the
@@ -650,31 +654,30 @@ static int pca955x_probe(struct i2c_client *client)
650654
return err;
651655

652656
#ifdef CONFIG_LEDS_PCA955X_GPIO
653-
if (ngpios) {
654-
pca955x->gpio.label = "gpio-pca955x";
655-
pca955x->gpio.direction_input = pca955x_gpio_direction_input;
656-
pca955x->gpio.direction_output = pca955x_gpio_direction_output;
657-
pca955x->gpio.set = pca955x_gpio_set_value;
658-
pca955x->gpio.get = pca955x_gpio_get_value;
659-
pca955x->gpio.request = pca955x_gpio_request_pin;
660-
pca955x->gpio.can_sleep = 1;
661-
pca955x->gpio.base = -1;
662-
pca955x->gpio.ngpio = ngpios;
663-
pca955x->gpio.parent = &client->dev;
664-
pca955x->gpio.owner = THIS_MODULE;
665-
666-
err = devm_gpiochip_add_data(&client->dev, &pca955x->gpio,
667-
pca955x);
668-
if (err) {
669-
/* Use data->gpio.dev as a flag for freeing gpiochip */
670-
pca955x->gpio.parent = NULL;
671-
dev_warn(&client->dev, "could not add gpiochip\n");
672-
return err;
673-
}
674-
dev_info(&client->dev, "gpios %i...%i\n",
675-
pca955x->gpio.base, pca955x->gpio.base +
676-
pca955x->gpio.ngpio - 1);
657+
pca955x->gpio.label = "gpio-pca955x";
658+
pca955x->gpio.direction_input = pca955x_gpio_direction_input;
659+
pca955x->gpio.direction_output = pca955x_gpio_direction_output;
660+
pca955x->gpio.set = pca955x_gpio_set_value;
661+
pca955x->gpio.get = pca955x_gpio_get_value;
662+
pca955x->gpio.request = pca955x_gpio_request_pin;
663+
pca955x->gpio.free = pca955x_gpio_free_pin;
664+
pca955x->gpio.can_sleep = 1;
665+
pca955x->gpio.base = -1;
666+
pca955x->gpio.ngpio = chip->bits;
667+
pca955x->gpio.parent = &client->dev;
668+
pca955x->gpio.owner = THIS_MODULE;
669+
670+
err = devm_gpiochip_add_data(&client->dev, &pca955x->gpio,
671+
pca955x);
672+
if (err) {
673+
/* Use data->gpio.dev as a flag for freeing gpiochip */
674+
pca955x->gpio.parent = NULL;
675+
dev_warn(&client->dev, "could not add gpiochip\n");
676+
return err;
677677
}
678+
dev_info(&client->dev, "gpios %i...%i\n",
679+
pca955x->gpio.base, pca955x->gpio.base +
680+
pca955x->gpio.ngpio - 1);
678681
#endif
679682

680683
return 0;

drivers/leds/simple/simatic-ipc-leds.c

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ static struct simatic_ipc_led simatic_ipc_leds_io[] = {
3939
};
4040

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

44-
static void *simatic_ipc_led_memory;
44+
static void __iomem *simatic_ipc_led_memory;
4545

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

96-
u32 *p;
97-
98-
p = simatic_ipc_led_memory + led->value;
99-
*p = (*p & ~1) | (brightness == LED_OFF);
98+
val = readl(reg);
99+
val = (val & ~1) | (brightness == LED_OFF);
100+
writel(val, reg);
100101
}
101102

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

106-
u32 *p;
107-
108-
p = simatic_ipc_led_memory + led->value;
109-
return (*p & 1) ? LED_OFF : led_cd->max_brightness;
109+
val = readl(reg);
110+
return (val & 1) ? LED_OFF : led_cd->max_brightness;
110111
}
111112

112113
static int simatic_ipc_leds_probe(struct platform_device *pdev)
@@ -116,8 +117,9 @@ static int simatic_ipc_leds_probe(struct platform_device *pdev)
116117
struct simatic_ipc_led *ipcled;
117118
struct led_classdev *cdev;
118119
struct resource *res;
120+
void __iomem *reg;
119121
int err, type;
120-
u32 *p;
122+
u32 val;
121123

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

159161
/* initialize power/watchdog LED */
160-
p = simatic_ipc_led_memory + 0x500 + 0x1D8; /* PM_WDT_OUT */
161-
*p = (*p & ~1);
162-
p = simatic_ipc_led_memory + 0x500 + 0x1C0; /* PM_BIOS_BOOT_N */
163-
*p = (*p | 1);
162+
reg = simatic_ipc_led_memory + 0x500 + 0x1D8; /* PM_WDT_OUT */
163+
val = readl(reg);
164+
writel(val & ~1, reg);
164165

166+
reg = simatic_ipc_led_memory + 0x500 + 0x1C0; /* PM_BIOS_BOOT_N */
167+
val = readl(reg);
168+
writel(val | 1, reg);
165169
break;
166170
default:
167171
return -ENODEV;

0 commit comments

Comments
 (0)