1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (c) 2020 Rockchip Electronics Co. Ltd.
4 *
5 * Author: Zorro Liu <zorro.liu@rock-chips.com>
6 */
7
8 #include <linux/device.h>
9 #include <linux/module.h>
10 #include <linux/string.h>
11 #include <linux/soc/rockchip/rk_vendor_storage.h>
12 #include "ebc_pmic.h"
13
14 #define EINK_VCOM_MAX 64
15 static int vcom = 0;
16
ebc_pmic_set_vcom(struct ebc_pmic * pmic,int value)17 int ebc_pmic_set_vcom(struct ebc_pmic *pmic, int value)
18 {
19 int ret;
20 char data[EINK_VCOM_MAX] = { 0 };
21
22 /* check vcom value */
23 if (value <= VCOM_MIN_MV || value > VCOM_MAX_MV) {
24 dev_err(pmic->dev, "vcom value should be %d~%d\n", VCOM_MIN_MV, VCOM_MAX_MV);
25 return -1;
26 }
27 dev_info(pmic->dev, "set chip vcom to: %dmV\n", value);
28
29 /* set pmic vcom */
30 pmic->pmic_set_vcom(pmic, value);
31
32 /* store vendor storage */
33 memset(data, 0, EINK_VCOM_MAX);
34 sprintf(data, "%d", value);
35 dev_info(pmic->dev, "store vcom %d to vendor storage\n", value);
36
37 ret = rk_vendor_write(EINK_VCOM_ID, (void *)data, EINK_VCOM_MAX);
38 if (ret < 0) {
39 dev_err(pmic->dev, "%s failed to write vendor storage\n", __func__);
40 return ret;
41 }
42
43 return 0;
44 }
45
ebc_pmic_verity_vcom(struct ebc_pmic * pmic)46 void ebc_pmic_verity_vcom(struct ebc_pmic *pmic)
47 {
48 int ret;
49 int value_chip;
50 int value_vendor;
51
52 //check vcom value
53 value_vendor = vcom;
54 if (value_vendor <= VCOM_MIN_MV || value_vendor > VCOM_MAX_MV) {
55 dev_err(pmic->dev, "invaild vcom value %d from vendor storage\n", value_vendor);
56 return;
57 }
58 value_chip = pmic->pmic_get_vcom(pmic);
59 if (value_chip != value_vendor) {
60 dev_info(pmic->dev, "chip_vcom %d != vendor_vcom %d, set vcom from vendor\n", value_chip, value_vendor);
61 ret = pmic->pmic_set_vcom(pmic, value_vendor);
62 if (ret) {
63 dev_err(pmic->dev, "set vcom value failed\n");
64 }
65 }
66
67 return;
68 }
69
70 module_param(vcom, int, 0644);
71