Skip to content

Commit d882762

Browse files
rockosovlag-linaro
authored andcommitted
leds: aw200xx: Support HWEN hardware control
HWEN is hardware control, which is used for enable/disable aw200xx chip. It's high active, internally pulled down to GND. After HWEN pin set high the chip begins to load the OTP information, which takes 200us to complete. About 200us wait time is needed for internal oscillator startup and display SRAM initialization. After display SRAM initialization, the registers in page 1 to page 5 can be configured via i2c interface. Signed-off-by: Dmitry Rokosov <ddrokosov@salutedevices.com> Link: https://lore.kernel.org/r/20231125200519.1750-3-ddrokosov@salutedevices.com Signed-off-by: Lee Jones <lee@kernel.org>
1 parent adfd462 commit d882762

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

drivers/leds/leds-aw200xx.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <linux/bitfield.h>
1111
#include <linux/bits.h>
1212
#include <linux/container_of.h>
13+
#include <linux/gpio/consumer.h>
1314
#include <linux/i2c.h>
1415
#include <linux/leds.h>
1516
#include <linux/mod_devicetable.h>
@@ -116,6 +117,7 @@ struct aw200xx {
116117
struct mutex mutex;
117118
u32 num_leds;
118119
u32 display_rows;
120+
struct gpio_desc *hwen;
119121
struct aw200xx_led leds[] __counted_by(num_leds);
120122
};
121123

@@ -358,6 +360,25 @@ static int aw200xx_chip_check(const struct aw200xx *const chip)
358360
return 0;
359361
}
360362

363+
static void aw200xx_enable(const struct aw200xx *const chip)
364+
{
365+
gpiod_set_value_cansleep(chip->hwen, 1);
366+
367+
/*
368+
* After HWEN pin set high the chip begins to load the OTP information,
369+
* which takes 200us to complete. About 200us wait time is needed for
370+
* internal oscillator startup and display SRAM initialization. After
371+
* display SRAM initialization, the registers in page1 to page5 can be
372+
* configured via i2c interface.
373+
*/
374+
fsleep(400);
375+
}
376+
377+
static void aw200xx_disable(const struct aw200xx *const chip)
378+
{
379+
return gpiod_set_value_cansleep(chip->hwen, 0);
380+
}
381+
361382
static int aw200xx_probe_fw(struct device *dev, struct aw200xx *chip)
362383
{
363384
struct fwnode_handle *child;
@@ -517,6 +538,14 @@ static int aw200xx_probe(struct i2c_client *client)
517538
if (IS_ERR(chip->regmap))
518539
return PTR_ERR(chip->regmap);
519540

541+
chip->hwen = devm_gpiod_get_optional(&client->dev, "enable",
542+
GPIOD_OUT_HIGH);
543+
if (IS_ERR(chip->hwen))
544+
return dev_err_probe(&client->dev, PTR_ERR(chip->hwen),
545+
"Cannot get enable GPIO");
546+
547+
aw200xx_enable(chip);
548+
520549
ret = aw200xx_chip_check(chip);
521550
if (ret)
522551
return ret;
@@ -537,6 +566,9 @@ static int aw200xx_probe(struct i2c_client *client)
537566
ret = aw200xx_chip_init(chip);
538567

539568
out_unlock:
569+
if (ret)
570+
aw200xx_disable(chip);
571+
540572
mutex_unlock(&chip->mutex);
541573
return ret;
542574
}
@@ -546,6 +578,7 @@ static void aw200xx_remove(struct i2c_client *client)
546578
struct aw200xx *chip = i2c_get_clientdata(client);
547579

548580
aw200xx_chip_reset(chip);
581+
aw200xx_disable(chip);
549582
mutex_destroy(&chip->mutex);
550583
}
551584

0 commit comments

Comments
 (0)