summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZick Wei <zick.wei@quanta.corp-partner.google.com>2021-12-07 11:03:42 +0800
committerCommit Bot <commit-bot@chromium.org>2021-12-21 02:55:10 +0000
commit4a3a3f8bca6de22dd69a8242eef3b592666f0851 (patch)
tree7863a7ebd6f073ddaa2eb78de6c457eb3b65b725
parent4a0e8255cb8823f9a32d8791b0dd1d9ce1787594 (diff)
downloadchrome-ec-4a3a3f8bca6de22dd69a8242eef3b592666f0851.tar.gz
driver/led: add mp3385 low level driver
Add led driver ic mp3385 low level driver. BUG=b:208722790 BRANCH=none TEST=make buildall Signed-off-by: Zick Wei <zick.wei@quanta.corp-partner.google.com> Change-Id: If6dc272f2420fd7c0bfcd98274a1dcdb35c45748 (cherry picked from commit 1e40ebebf5de09c119812521b1d10f7c42241f51) Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3347356 Reviewed-by: Andrew McRae <amcrae@google.com>
-rw-r--r--driver/build.mk1
-rw-r--r--driver/led/mp3385.c132
-rw-r--r--driver/led/mp3385.h35
-rw-r--r--include/config.h1
4 files changed, 169 insertions, 0 deletions
diff --git a/driver/build.mk b/driver/build.mk
index 368f392ed5..ade5c6f3f7 100644
--- a/driver/build.mk
+++ b/driver/build.mk
@@ -91,6 +91,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_MP3385)+=led/mp3385.o
driver-$(CONFIG_LED_DRIVER_OZ554)+=led/oz554.o
# 7-segment display
diff --git a/driver/led/mp3385.c b/driver/led/mp3385.c
new file mode 100644
index 0000000000..825412e647
--- /dev/null
+++ b/driver/led/mp3385.c
@@ -0,0 +1,132 @@
+/* Copyright 2021 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.
+ *
+ * MPS MP3385 LED driver.
+ */
+
+#include "console.h"
+#include "gpio.h"
+#include "hooks.h"
+#include "i2c.h"
+#include "mp3385.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_MP3385_FLAGS 0x31
+
+struct mp3385_value {
+ uint8_t offset;
+ uint8_t data;
+};
+
+/*
+ * MP3385 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 MP3385 is powered only in
+ * S0. For clamshell devices, different interrupt & power control scheme may be
+ * needed.
+ */
+
+/* This ordering is suggested by vendor. */
+static struct mp3385_value mp3385_conf[] = {
+ /*
+ * Register 0x01: Operation frequency control
+ * Frequency selection: 300(KHz)
+ * Short circuit protection: 8(V)
+ */
+ {.offset = 1, .data = 0x43},
+ /*
+ * Register 0x02: LED current Full-Scale Register
+ * ISET Resistor: 127(Kohm)
+ * Maximum LED current: 20196/127 = 159(mA)
+ * Setting LED current: 62(mA)
+ */
+ {.offset = 2, .data = 0x65},
+
+ /* Register 0x03: RO - ignored */
+
+ /*
+ * Register 0x04: Internal LED Dimming Brightness Register
+ * SMBus PWM function: None Use
+ */
+ {.offset = 4, .data = 0x00},
+ /*
+ * Register 0x05: OVP, OCP Threshold Register
+ * Over Current Protection: 0.5(V)
+ * Panel LED Voltage(Max): 47.8(V)
+ * OVP setting: 54(V)
+ */
+ {.offset = 5, .data = 0x97},
+ /*
+ * Register 0x00: Dimming mode Register
+ * String Selection: 4(Number)
+ * Interface Selection: 1
+ * Brightness mode: 3
+ */
+ {.offset = 0, .data = 0xF2},
+};
+static const int mp3385_conf_size = ARRAY_SIZE(mp3385_conf);
+
+static void set_mp3385_reg(void)
+{
+ int i;
+
+ for (i = 0; i < mp3385_conf_size; ++i) {
+ int rv = i2c_write8(I2C_PORT_BACKLIGHT,
+ I2C_ADDR_MP3385_FLAGS,
+ mp3385_conf[i].offset, mp3385_conf[i].data);
+ if (rv) {
+ CPRINTS("Write MP3385 register %d "
+ "failed rv=%d", i, rv);
+ return;
+ }
+ }
+ CPRINTS("Wrote MP3385 settings");
+}
+
+static void mp3385_backlight_enable_deferred(void)
+{
+ if (gpio_get_level(GPIO_PANEL_BACKLIGHT_EN))
+ set_mp3385_reg();
+}
+DECLARE_DEFERRED(mp3385_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(&mp3385_backlight_enable_deferred_data,
+ MP3385_POWER_BACKLIGHT_DELAY);
+}
+
+int mp3385_set_config(int offset, int data)
+{
+ int i;
+
+ for (i = 0; i < mp3385_conf_size; i++) {
+ if (mp3385_conf[i].offset == offset) {
+ mp3385_conf[i].data = data;
+ return EC_SUCCESS;
+ }
+ }
+
+ CPRINTS("mp3385: offset %d not found", i);
+ return EC_ERROR_INVAL;
+}
diff --git a/driver/led/mp3385.h b/driver/led/mp3385.h
new file mode 100644
index 0000000000..74d796ad3a
--- /dev/null
+++ b/driver/led/mp3385.h
@@ -0,0 +1,35 @@
+/* Copyright 2021 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.
+ *
+ * MPS MP3385 LED driver.
+ */
+
+#ifndef __CROS_EC_MP3385_H
+#define __CROS_EC_MP3385_H
+
+#include "gpio.h"
+#include "common.h"
+
+/*
+ * Overridable board initialization. Should be overridden by a board
+ * specific function if the default is not appropriate
+ */
+void mp3385_board_init(void);
+
+/**
+ * Update mp3385 configuration array (mp3385_conf).
+ *
+ * @param offset: Offset of the register to be set.
+ * @param data: Value to be set.
+ * @return EC_SUCCESS or EC_ERROR_* for errors.
+ */
+int mp3385_set_config(int offset, int data);
+
+#ifndef MP3385_POWER_BACKLIGHT_DELAY
+#define MP3385_POWER_BACKLIGHT_DELAY SECOND
+#endif
+
+void backlight_enable_interrupt(enum gpio_signal signal);
+
+#endif
diff --git a/include/config.h b/include/config.h
index 2d13bb550c..1feccfff47 100644
--- a/include/config.h
+++ b/include/config.h
@@ -2608,6 +2608,7 @@
#undef CONFIG_LED_DRIVER_LM3509 /* LM3509, on I2C interface */
#undef CONFIG_LED_DRIVER_LM3630A /* LM3630A, on I2C interface */
#undef CONFIG_LED_DRIVER_LP5562 /* LP5562, on I2C interface */
+#undef CONFIG_LED_DRIVER_MP3385 /* MPS MP3385, on I2C */
#undef CONFIG_LED_DRIVER_OZ554 /* O2Micro OZ554, on I2C */
/* Offset in flash where little firmware will live. */