1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Driver for the NXP SAA7164 PCIe bridge
5 * Copyright (c) 2010-2015 Steven Toth <stoth@kernellabs.com>
8 #include <linux/module.h>
9 #include <linux/moduleparam.h>
10 #include <linux/init.h>
11 #include <linux/delay.h>
16 static int i2c_xfer(struct i2c_adapter
*i2c_adap
, struct i2c_msg
*msgs
, int num
)
18 struct saa7164_i2c
*bus
= i2c_adap
->algo_data
;
19 struct saa7164_dev
*dev
= bus
->dev
;
22 dprintk(DBGLVL_I2C
, "%s(num = %d)\n", __func__
, num
);
24 for (i
= 0 ; i
< num
; i
++) {
25 dprintk(DBGLVL_I2C
, "%s(num = %d) addr = 0x%02x len = 0x%x\n",
26 __func__
, num
, msgs
[i
].addr
, msgs
[i
].len
);
27 if (msgs
[i
].flags
& I2C_M_RD
) {
28 retval
= saa7164_api_i2c_read(bus
,
31 NULL
/* reg */, msgs
[i
].len
, msgs
[i
].buf
);
32 } else if (i
+ 1 < num
&& (msgs
[i
+ 1].flags
& I2C_M_RD
) &&
33 msgs
[i
].addr
== msgs
[i
+ 1].addr
) {
34 /* write then read from same address */
36 retval
= saa7164_api_i2c_read(bus
, msgs
[i
].addr
,
37 msgs
[i
].len
, msgs
[i
].buf
,
38 msgs
[i
+1].len
, msgs
[i
+1].buf
47 retval
= saa7164_api_i2c_write(bus
, msgs
[i
].addr
,
48 msgs
[i
].len
, msgs
[i
].buf
);
59 static u32
saa7164_functionality(struct i2c_adapter
*adap
)
64 static const struct i2c_algorithm saa7164_i2c_algo_template
= {
65 .master_xfer
= i2c_xfer
,
66 .functionality
= saa7164_functionality
,
69 /* ----------------------------------------------------------------------- */
71 static const struct i2c_adapter saa7164_i2c_adap_template
= {
74 .algo
= &saa7164_i2c_algo_template
,
77 static const struct i2c_client saa7164_i2c_client_template
= {
78 .name
= "saa7164 internal",
81 int saa7164_i2c_register(struct saa7164_i2c
*bus
)
83 struct saa7164_dev
*dev
= bus
->dev
;
85 dprintk(DBGLVL_I2C
, "%s(bus = %d)\n", __func__
, bus
->nr
);
87 bus
->i2c_adap
= saa7164_i2c_adap_template
;
88 bus
->i2c_client
= saa7164_i2c_client_template
;
90 bus
->i2c_adap
.dev
.parent
= &dev
->pci
->dev
;
92 strscpy(bus
->i2c_adap
.name
, bus
->dev
->name
,
93 sizeof(bus
->i2c_adap
.name
));
95 bus
->i2c_adap
.algo_data
= bus
;
96 i2c_set_adapdata(&bus
->i2c_adap
, bus
);
97 i2c_add_adapter(&bus
->i2c_adap
);
99 bus
->i2c_client
.adapter
= &bus
->i2c_adap
;
101 if (0 != bus
->i2c_rc
)
102 printk(KERN_ERR
"%s: i2c bus %d register FAILED\n",
108 int saa7164_i2c_unregister(struct saa7164_i2c
*bus
)
110 i2c_del_adapter(&bus
->i2c_adap
);