1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
/* 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 0x62
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(I2C_PORT_BACKLIGHT, I2C_ADDR_OZ554,
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)
{
hook_call_deferred(&backlight_enable_deferred_data, 30 * MSEC);
}
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);
|