hc
2023-02-13 e440ec23c5a540cdd3f7464e8779219be6fd3d95
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
// SPDX-License-Identifier: GPL-2.0
/********************************************************************************
 *
 *  Copyright (C) 2017     NEXTCHIP Inc. All rights reserved.
 *  Module        : nvp6158_i2c.c
 *  Description    :
 *  Author        :
 *  Date         :
 *  Version        : Version 1.0
 *
 ********************************************************************************
 *  History      :
 *
 *
 ********************************************************************************/
#include <linux/string.h>
#include <linux/delay.h>
#include <linux/i2c.h>
#include <linux/i2c-dev.h>
#include "nvp6158_common.h"
 
extern struct i2c_client* nvp6158_client;
//origin
#if 0
void nvp6158_I2CWriteByte8(unsigned char chip_addr, unsigned char reg_addr, unsigned char value)
{
    int ret;
    unsigned char buf[2];
    struct i2c_client* client = nvp6158_client;
    
    nvp6158_client->addr = chip_addr;
 
    buf[0] = reg_addr;
    buf[1] = value;
 
    ret = i2c_master_send(client, buf, 2);
    udelay(300);
    //return ret;
}
 
unsigned char nvp6158_I2CReadByte8(unsigned char chip_addr, unsigned char reg_addr)
{
    int ret_data = 0xFF;
    int ret;
    struct i2c_client* client = nvp6158_client;
    unsigned char buf[2];
 
    nvp6158_client->addr = chip_addr;
 
    buf[0] = reg_addr;
    ret = i2c_master_recv(client, buf, 1);
    if (ret >= 0)
    {
        ret_data = buf[0];
    }
    return ret_data;
}
#endif
 
 
void nvp6158_I2CWriteByte8(unsigned char chip_addr, unsigned char reg_addr, unsigned char value)
{
   int ret;
   unsigned char buf[2];
   struct i2c_client* client = nvp6158_client;
 
   client->addr = chip_addr>>1;
 
   buf[0] = reg_addr;
   buf[1] = value;
 
   ret = i2c_master_send(client, buf, 2);
   udelay(300);
}
 
unsigned char nvp6158_I2CReadByte8(unsigned char chip_addr, unsigned char reg_addr)
{
   struct i2c_client* client = nvp6158_client;
 
   client->addr = chip_addr>>1;
 
   return i2c_smbus_read_byte_data(client, reg_addr);
}