blob: cb4ca640a2b30144ae5894cfa19c30a1d5a7ae19 [file] [log] [blame]
Archit Taneja2437e7c2016-06-15 16:24:03 +05301/*
2 * Copyright (c) 2016, The Linux Foundation. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 and
6 * only version 2 as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 */
13
14#include "adv7511.h"
15
16static const struct reg_sequence adv7533_fixed_registers[] = {
17 { 0x16, 0x20 },
18 { 0x9a, 0xe0 },
19 { 0xba, 0x70 },
20 { 0xde, 0x82 },
21 { 0xe4, 0x40 },
22 { 0xe5, 0x80 },
23};
24
25static const struct reg_sequence adv7533_cec_fixed_registers[] = {
26 { 0x15, 0xd0 },
27 { 0x17, 0xd0 },
28 { 0x24, 0x20 },
29 { 0x57, 0x11 },
30};
31
32static const struct regmap_config adv7533_cec_regmap_config = {
33 .reg_bits = 8,
34 .val_bits = 8,
35
36 .max_register = 0xff,
37 .cache_type = REGCACHE_RBTREE,
38};
39
40void adv7533_dsi_power_on(struct adv7511 *adv)
41{
42 /* set number of dsi lanes (hardcoded to 4 for now) */
43 regmap_write(adv->regmap_cec, 0x1c, 4 << 4);
44 /* disable internal timing generator */
45 regmap_write(adv->regmap_cec, 0x27, 0x0b);
46 /* enable hdmi */
47 regmap_write(adv->regmap_cec, 0x03, 0x89);
48 /* disable test mode */
49 regmap_write(adv->regmap_cec, 0x55, 0x00);
50
51 regmap_register_patch(adv->regmap_cec, adv7533_cec_fixed_registers,
52 ARRAY_SIZE(adv7533_cec_fixed_registers));
53}
54
55void adv7533_dsi_power_off(struct adv7511 *adv)
56{
57 /* disable hdmi */
58 regmap_write(adv->regmap_cec, 0x03, 0x0b);
59}
60
61int adv7533_patch_registers(struct adv7511 *adv)
62{
63 return regmap_register_patch(adv->regmap,
64 adv7533_fixed_registers,
65 ARRAY_SIZE(adv7533_fixed_registers));
66}
67
68void adv7533_uninit_cec(struct adv7511 *adv)
69{
70 i2c_unregister_device(adv->i2c_cec);
71}
72
73static const int cec_i2c_addr = 0x78;
74
75int adv7533_init_cec(struct adv7511 *adv)
76{
77 int ret;
78
79 adv->i2c_cec = i2c_new_dummy(adv->i2c_main->adapter, cec_i2c_addr >> 1);
80 if (!adv->i2c_cec)
81 return -ENOMEM;
82
83 adv->regmap_cec = devm_regmap_init_i2c(adv->i2c_cec,
84 &adv7533_cec_regmap_config);
85 if (IS_ERR(adv->regmap_cec)) {
86 ret = PTR_ERR(adv->regmap_cec);
87 goto err;
88 }
89
90 ret = regmap_register_patch(adv->regmap_cec,
91 adv7533_cec_fixed_registers,
92 ARRAY_SIZE(adv7533_cec_fixed_registers));
93 if (ret)
94 goto err;
95
96 return 0;
97err:
98 adv7533_uninit_cec(adv);
99 return ret;
100}