diff options
author | Daisuke Nojiri <dnojiri@chromium.org> | 2018-12-06 09:29:10 -0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-12-13 19:28:01 -0800 |
commit | 145f3271f7459f7a2fec6ba941f14c1ae00c14a6 (patch) | |
tree | c306cf327350892f1d8610858e55fc7c761f88c2 /driver | |
parent | 4bf4a6ab644b7217dffa0b31bb572db7e8409411 (diff) | |
download | chrome-ec-145f3271f7459f7a2fec6ba941f14c1ae00c14a6.tar.gz |
oz554: Move oz554 driver code to common directory
This patch moves oz554 LED driver code from Karma.
Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org>
BUG=none
BRANCH=none
TEST=buildall
Change-Id: Ia2808563b9c113e5ea3376f9327dff2578e20906
Reviewed-on: https://chromium-review.googlesource.com/1366015
Commit-Ready: Daisuke Nojiri <dnojiri@chromium.org>
Tested-by: Daisuke Nojiri <dnojiri@chromium.org>
Reviewed-by: Jett Rink <jettrink@chromium.org>
Diffstat (limited to 'driver')
-rw-r--r-- | driver/build.mk | 1 | ||||
-rw-r--r-- | driver/led/oz554.c | 104 | ||||
-rw-r--r-- | driver/led/oz554.h | 15 |
3 files changed, 120 insertions, 0 deletions
diff --git a/driver/build.mk b/driver/build.mk index 5d48edb242..592498d941 100644 --- a/driver/build.mk +++ b/driver/build.mk @@ -77,6 +77,7 @@ driver-$(CONFIG_LED_DRIVER_DS2413)+=led/ds2413.o driver-$(CONFIG_LED_DRIVER_LM3509)+=led/lm3509.o driver-$(CONFIG_LED_DRIVER_LM3630A)+=led/lm3630a.o driver-$(CONFIG_LED_DRIVER_LP5562)+=led/lp5562.o +driver-$(CONFIG_LED_DRIVER_OZ554)+=led/oz554.o # Voltage regulators driver-$(CONFIG_REGULATOR_IR357X)+=regulator_ir357x.o diff --git a/driver/led/oz554.c b/driver/led/oz554.c new file mode 100644 index 0000000000..f53b25f138 --- /dev/null +++ b/driver/led/oz554.c @@ -0,0 +1,104 @@ +/* Copyright 2018 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + * + * O2 Micro OZ554 LED driver. + */ + +#include "console.h" +#include "gpio.h" +#include "hooks.h" +#include "i2c.h" +#include "task.h" +#include "timer.h" + +#define CPRINTS(format, args...) cprints(CC_I2C, format, ## args) +#define CPRINTF(format, args...) cprintf(CC_I2C, format, ## args) + +#define I2C_ADDR_OZ554 0x62 +#define OZ554_DATA_SIZE 6 + +struct oz554_value { + uint8_t offset; + uint8_t data; +}; + +/* This ordering is suggested by vendor. */ +static const struct oz554_value order[] = { + /* + * Reigster 0x01: Operation frequency control + * Frequency selection: 300(KHz) + * Short circuit protection: 8(V) + */ + {.offset = 1, .data = 0x43}, + /* + * Reigster 0x02: LED current amplitude control + * ISET Resistor: 10.2(Kohm) + * Maximum LED current: 1636/10.2 = 160.4(mA) + * Setting LED current: 65(mA) + */ + {.offset = 2, .data = 0x65}, + /* + * Reigster 0x03: LED backlight Status + * Status function: Read only + */ + {.offset = 3, .data = 0x00}, + /* + * Reigster 0x04: LED current control with SMBus + * SMBus PWM function: None Use + */ + {.offset = 4, .data = 0x00}, + /* + * Reigster 0x05: OVP, OCP control + * Over Current Protection: 0.5(V) + * Panel LED Voltage(Max): 47.8(V) + * OVP setting: 54(V) + */ + {.offset = 5, .data = 0x97}, + /* + * Reigster 0x00: Dimming mode and string ON/OFF control + * String Selection: 4(Number) + * Interface Selection: 1 + * Brightness mode: 3 + */ + {.offset = 0, .data = 0xF2}, +}; +BUILD_ASSERT(ARRAY_SIZE(order) == OZ554_DATA_SIZE); + +static void set_oz554_reg(void) +{ + int i; + + for (i = 0; i < OZ554_DATA_SIZE; ++i) { + int rv = i2c_write8(I2C_PORT_BACKLIGHT, I2C_ADDR_OZ554, + order[i].offset, order[i].data); + if (rv) { + CPRINTS("Write OZ554 register %d failed rv=%d" , i, rv); + return; + } + } +} + +static void backlight_enable_deferred(void) +{ + if (gpio_get_level(GPIO_PANEL_BACKLIGHT_EN)) + set_oz554_reg(); +} +DECLARE_DEFERRED(backlight_enable_deferred); + +void backlight_enable_interrupt(enum gpio_signal signal) +{ + hook_call_deferred(&backlight_enable_deferred_data, 30 * MSEC); +} + +static void on_chipset_resume(void) +{ + gpio_enable_interrupt(GPIO_PANEL_BACKLIGHT_EN); +} +DECLARE_HOOK(HOOK_CHIPSET_RESUME, on_chipset_resume, HOOK_PRIO_DEFAULT); + +static void on_chipset_shutdown(void) +{ + gpio_disable_interrupt(GPIO_PANEL_BACKLIGHT_EN); +} +DECLARE_HOOK(HOOK_CHIPSET_SUSPEND, on_chipset_shutdown, HOOK_PRIO_DEFAULT); diff --git a/driver/led/oz554.h b/driver/led/oz554.h new file mode 100644 index 0000000000..d9b5400111 --- /dev/null +++ b/driver/led/oz554.h @@ -0,0 +1,15 @@ +/* Copyright 2018 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + * + * O2 Micro OZ554 LED driver. + */ + +#ifndef __CROS_EC_OZ554_H +#define __CROS_EC_OZ554_H + +#include "gpio.h" + +void backlight_enable_interrupt(enum gpio_signal signal); + +#endif |