1 // SPDX-License-Identifier: GPL-2.0
2 /********************************************************************************
3 *
4 * Copyright (C) 2017 NEXTCHIP Inc. All rights reserved.
5 * Module : nvp6158_i2c.c
6 * Description :
7 * Author :
8 * Date :
9 * Version : Version 1.0
10 *
11 ********************************************************************************
12 * History :
13 *
14 *
15 ********************************************************************************/
16 #include <linux/string.h>
17 #include <linux/delay.h>
18 #include <linux/i2c.h>
19 #include <linux/i2c-dev.h>
20 #include "nvp6158_common.h"
21
22 extern struct i2c_client* nvp6158_client;
23 //origin
24 #if 0
25 void nvp6158_I2CWriteByte8(unsigned char chip_addr, unsigned char reg_addr, unsigned char value)
26 {
27 int ret;
28 unsigned char buf[2];
29 struct i2c_client* client = nvp6158_client;
30
31 nvp6158_client->addr = chip_addr;
32
33 buf[0] = reg_addr;
34 buf[1] = value;
35
36 ret = i2c_master_send(client, buf, 2);
37 udelay(300);
38 //return ret;
39 }
40
41 unsigned char nvp6158_I2CReadByte8(unsigned char chip_addr, unsigned char reg_addr)
42 {
43 int ret_data = 0xFF;
44 int ret;
45 struct i2c_client* client = nvp6158_client;
46 unsigned char buf[2];
47
48 nvp6158_client->addr = chip_addr;
49
50 buf[0] = reg_addr;
51 ret = i2c_master_recv(client, buf, 1);
52 if (ret >= 0)
53 {
54 ret_data = buf[0];
55 }
56 return ret_data;
57 }
58 #endif
59
60
nvp6158_I2CWriteByte8(unsigned char chip_addr,unsigned char reg_addr,unsigned char value)61 void nvp6158_I2CWriteByte8(unsigned char chip_addr, unsigned char reg_addr, unsigned char value)
62 {
63 int ret;
64 unsigned char buf[2];
65 struct i2c_client* client = nvp6158_client;
66
67 client->addr = chip_addr>>1;
68
69 buf[0] = reg_addr;
70 buf[1] = value;
71
72 ret = i2c_master_send(client, buf, 2);
73 udelay(300);
74 }
75
nvp6158_I2CReadByte8(unsigned char chip_addr,unsigned char reg_addr)76 unsigned char nvp6158_I2CReadByte8(unsigned char chip_addr, unsigned char reg_addr)
77 {
78 struct i2c_client* client = nvp6158_client;
79
80 client->addr = chip_addr>>1;
81
82 return i2c_smbus_read_byte_data(client, reg_addr);
83 }
84