diff options
Diffstat (limited to 'driver/led')
-rw-r--r-- | driver/led/lm3509.c | 6 | ||||
-rw-r--r-- | driver/led/lm3509.h | 3 | ||||
-rw-r--r-- | driver/led/lm3630a.c | 10 | ||||
-rw-r--r-- | driver/led/lp5562.c | 4 | ||||
-rw-r--r-- | driver/led/max695x.h | 44 | ||||
-rw-r--r-- | driver/led/oz554.c | 145 |
6 files changed, 202 insertions, 10 deletions
diff --git a/driver/led/lm3509.c b/driver/led/lm3509.c index 0f44681659..c940dd69e2 100644 --- a/driver/led/lm3509.c +++ b/driver/led/lm3509.c @@ -12,12 +12,14 @@ static inline int lm3509_write(uint8_t reg, uint8_t val) { - return i2c_write8(I2C_PORT_KBLIGHT, LM3509_I2C_ADDR, reg, val); + return i2c_write8__7bf(I2C_PORT_KBLIGHT, LM3509_I2C_ADDR__7bf, + reg, val); } static inline int lm3509_read(uint8_t reg, int *val) { - return i2c_read8(I2C_PORT_KBLIGHT, LM3509_I2C_ADDR, reg, val); + return i2c_read8__7bf(I2C_PORT_KBLIGHT, LM3509_I2C_ADDR__7bf, + reg, val); } /* Brightness level (0.0 to 100.0%) to brightness register conversion table */ diff --git a/driver/led/lm3509.h b/driver/led/lm3509.h index 8318197a8e..fce0c993dc 100644 --- a/driver/led/lm3509.h +++ b/driver/led/lm3509.h @@ -8,8 +8,7 @@ #ifndef __CROS_EC_LM3509_H #define __CROS_EC_LM3509_H -/* 8-bit I2C address */ -#define LM3509_I2C_ADDR 0x6C +#define LM3509_I2C_ADDR__7bf 0x36 /* * General purpose register diff --git a/driver/led/lm3630a.c b/driver/led/lm3630a.c index 5515771ffa..10f850b09d 100644 --- a/driver/led/lm3630a.c +++ b/driver/led/lm3630a.c @@ -11,17 +11,19 @@ #include "timer.h" -/* 8-bit I2C address */ -#define LM3630A_I2C_ADDR (0x36 << 1) +/* I2C address */ +#define LM3630A_I2C_ADDR__7bf 0x36 static inline int lm3630a_write(uint8_t reg, uint8_t val) { - return i2c_write8(I2C_PORT_KBLIGHT, LM3630A_I2C_ADDR, reg, val); + return i2c_write8__7bf(I2C_PORT_KBLIGHT, LM3630A_I2C_ADDR__7bf, + reg, val); } static inline int lm3630a_read(uint8_t reg, int *val) { - return i2c_read8(I2C_PORT_KBLIGHT, LM3630A_I2C_ADDR, reg, val); + return i2c_read8__7bf(I2C_PORT_KBLIGHT, LM3630A_I2C_ADDR__7bf, + reg, val); } static void deferred_lm3630a_poweron(void) diff --git a/driver/led/lp5562.c b/driver/led/lp5562.c index 88efb72e7b..00cb5a9d43 100644 --- a/driver/led/lp5562.c +++ b/driver/led/lp5562.c @@ -11,8 +11,8 @@ #include "timer.h" #include "util.h" -/* 8-bit I2C address */ -#define LP5562_I2C_ADDR (0x30 << 1) +/* I2C address */ +#define LP5562_I2C_ADDR__7bf (0x30) inline int lp5562_write(uint8_t reg, uint8_t val) { diff --git a/driver/led/max695x.h b/driver/led/max695x.h new file mode 100644 index 0000000000..4bead04194 --- /dev/null +++ b/driver/led/max695x.h @@ -0,0 +1,44 @@ +/* Copyright 2019 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. + * + * MAX6958/MAX6959 7-Segment LED Display Driver header + */ + +#ifndef __CROS_EC_MAX656X_H +#define __CROS_EC_MAX656X_H + +/* I2C interface */ +#define MAX695X_I2C_ADDR1__7bf (0x38) +#define MAX695X_I2C_ADDR2__7bf (0x39) + +/* Decode mode register */ +#define MAX695X_REG_DECODE_MODE 0x01 +/* Hexadecimal decode for digits 3–0 */ +#define MAX695X_DECODE_MODE_HEX_DECODE 0x0f + +/* Intensity register */ +#define MAX695X_REG_INTENSITY 0x02 +/* Setting meduim intensity */ +#define MAX695X_INTENSITY_MEDIUM 0x20 + +/* Scan limit register value */ +#define MAX695X_REG_SCAN_LIMIT 0x03 + +/* Scanning digits 0-3 */ +#define MAX695X_SCAN_LIMIT_4 0x03 + +/* Configuration register */ +#define MAX695X_REG_CONFIG 0x04 +/* Shutdown seven segment display */ +#define MAX695X_CONFIG_OPR_SHUTDOWN 0x00 +/* Start seven segment display */ +#define MAX695X_CONFIG_OPR_NORMAL 0x01 + +/* Digit addresses */ +#define MAX695X_DIGIT0_ADDR 0x20 +#define MAX695X_DIGIT1_ADDR 0x21 +#define MAX695X_DIGIT2_ADDR 0x22 +#define MAX695X_DIGIT3_ADDR 0x23 + +#endif /* __CROS_EC_MAX656X_H */ diff --git a/driver/led/oz554.c b/driver/led/oz554.c new file mode 100644 index 0000000000..6369e064a3 --- /dev/null +++ b/driver/led/oz554.c @@ -0,0 +1,145 @@ +/* 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 "oz554.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__7bf 0x31 + +struct oz554_value { + uint8_t offset; + uint8_t data; +}; + +/* + * OZ554ALN asserts the interrupt when it's ready for writing settings, which + * are cleared when it's turned off. We enable the interrupt on HOOK_INIT and + * keep it enabled in S0/S3/S5. + * + * It's assumed the device doesn't have a lid and OZ554ALN is powered only in + * S0. For clamshell devices, different interrupt & power control scheme may be + * needed. + */ + +/* This ordering is suggested by vendor. */ +static struct oz554_value oz554_conf[] = { + /* + * 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}, +}; +static const int oz554_conf_size = ARRAY_SIZE(oz554_conf); + +static void set_oz554_reg(void) +{ + int i; + + for (i = 0; i < oz554_conf_size; ++i) { + int rv = i2c_write8__7bf(I2C_PORT_BACKLIGHT, + I2C_ADDR_OZ554__7bf, + oz554_conf[i].offset, oz554_conf[i].data); + if (rv) { + CPRINTS("Write OZ554 register %d failed rv=%d" , i, rv); + return; + } + } + CPRINTS("Wrote OZ554 settings"); +} + +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) +{ + /* + * 1. Spec says backlight should be turned on after 500ms + * after eDP signals are ready. + * + * 2. There's no way to get exact eDP ready time, therefore, + * give one second delay. + * + * power up __/---------------- + * eDP ______/------------ + * backlight _____________/----- + * |- t1 -| : >=500 ms + * |- t2 -| : 1 second is enough + */ + hook_call_deferred(&backlight_enable_deferred_data, + OZ554_POWER_BACKLIGHT_DELAY); +} + +int oz554_set_config(int offset, int data) +{ + int i; + for (i = 0; i < oz554_conf_size; i++) { + if (oz554_conf[i].offset == offset) + break; + } + if (i >= oz554_conf_size) + /* Matching offset not found */ + return EC_ERROR_INVAL; + oz554_conf[i].data = data; + return EC_SUCCESS; +} + +static void init_oz554(void) +{ + oz554_board_init(); + + gpio_enable_interrupt(GPIO_PANEL_BACKLIGHT_EN); +} +DECLARE_HOOK(HOOK_INIT, init_oz554, HOOK_PRIO_DEFAULT); + + +__overridable void oz554_board_init(void) +{ +} |