2014-11-22 00:33:26 +01:00
|
|
|
/*
|
2014-12-06 19:44:58 +01:00
|
|
|
* This file is part of the coreboot project.
|
2014-11-22 00:33:26 +01:00
|
|
|
*
|
2015-02-19 12:13:26 +01:00
|
|
|
* Copyright (C) 2014 - 2015 The Linux Foundation. All rights reserved.
|
2014-11-22 00:33:26 +01:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2014-12-06 19:44:58 +01:00
|
|
|
#include <console/console.h>
|
2017-08-01 14:02:40 +02:00
|
|
|
#include <device/i2c_simple.h>
|
2014-12-06 19:44:58 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <soc/gsbi.h>
|
|
|
|
#include <soc/qup.h>
|
|
|
|
|
2015-02-19 12:13:26 +01:00
|
|
|
static qup_config_t gsbi1_qup_config = {
|
2014-12-06 19:44:58 +01:00
|
|
|
QUP_MINICORE_I2C_MASTER,
|
|
|
|
100000,
|
|
|
|
24000000,
|
2015-02-19 12:13:26 +01:00
|
|
|
QUP_MODE_FIFO,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
static qup_config_t gsbi4_qup_config = {
|
|
|
|
QUP_MINICORE_I2C_MASTER,
|
|
|
|
100000,
|
|
|
|
24000000,
|
|
|
|
QUP_MODE_FIFO,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
static qup_config_t gsbi7_qup_config = {
|
|
|
|
QUP_MINICORE_I2C_MASTER,
|
|
|
|
100000,
|
|
|
|
24000000,
|
|
|
|
QUP_MODE_FIFO,
|
|
|
|
0
|
2014-12-06 19:44:58 +01:00
|
|
|
};
|
2014-11-22 00:33:26 +01:00
|
|
|
|
|
|
|
static int i2c_read(uint32_t gsbi_id, uint8_t slave,
|
2014-12-06 19:44:58 +01:00
|
|
|
uint8_t *data, int data_len)
|
2014-11-22 00:33:26 +01:00
|
|
|
{
|
|
|
|
qup_data_t obj;
|
|
|
|
qup_return_t qup_ret = 0;
|
|
|
|
|
|
|
|
memset(&obj, 0, sizeof(obj));
|
|
|
|
obj.protocol = QUP_MINICORE_I2C_MASTER;
|
|
|
|
obj.p.iic.addr = slave;
|
|
|
|
obj.p.iic.data_len = data_len;
|
|
|
|
obj.p.iic.data = data;
|
|
|
|
qup_ret = qup_recv_data(gsbi_id, &obj);
|
|
|
|
|
|
|
|
if (QUP_SUCCESS != qup_ret)
|
|
|
|
return 1;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int i2c_write(uint32_t gsbi_id, uint8_t slave,
|
|
|
|
uint8_t *data, int data_len, uint8_t stop_seq)
|
|
|
|
{
|
|
|
|
qup_data_t obj;
|
|
|
|
qup_return_t qup_ret = 0;
|
|
|
|
|
|
|
|
memset(&obj, 0, sizeof(obj));
|
|
|
|
obj.protocol = QUP_MINICORE_I2C_MASTER;
|
|
|
|
obj.p.iic.addr = slave;
|
|
|
|
obj.p.iic.data_len = data_len;
|
|
|
|
obj.p.iic.data = data;
|
|
|
|
qup_ret = qup_send_data(gsbi_id, &obj, stop_seq);
|
|
|
|
|
|
|
|
if (QUP_SUCCESS != qup_ret)
|
|
|
|
return 1;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-12-06 19:44:58 +01:00
|
|
|
static int i2c_init(unsigned bus)
|
2014-11-22 00:33:26 +01:00
|
|
|
{
|
2014-12-06 19:44:58 +01:00
|
|
|
unsigned gsbi_id = bus;
|
2015-02-19 12:13:26 +01:00
|
|
|
qup_config_t *qup_config;
|
|
|
|
|
|
|
|
switch (gsbi_id) {
|
|
|
|
case GSBI_ID_1:
|
|
|
|
qup_config = &gsbi1_qup_config;
|
|
|
|
break;
|
|
|
|
case GSBI_ID_4:
|
|
|
|
qup_config = &gsbi4_qup_config;
|
|
|
|
break;
|
|
|
|
case GSBI_ID_7:
|
|
|
|
qup_config = &gsbi7_qup_config;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printk(BIOS_ERR, "QUP configuration not defind for GSBI%d.\n",
|
|
|
|
gsbi_id);
|
|
|
|
return 1;
|
|
|
|
}
|
2014-11-22 00:33:26 +01:00
|
|
|
|
2015-02-19 12:13:26 +01:00
|
|
|
if (qup_config->initialized)
|
2014-12-06 19:44:58 +01:00
|
|
|
return 0;
|
2014-11-22 00:33:26 +01:00
|
|
|
|
2014-12-06 19:44:58 +01:00
|
|
|
if (gsbi_init(gsbi_id, GSBI_PROTO_I2C_ONLY)) {
|
|
|
|
printk(BIOS_ERR, "failed to initialize gsbi\n");
|
|
|
|
return 1;
|
2014-11-22 00:33:26 +01:00
|
|
|
}
|
|
|
|
|
2015-02-19 12:13:26 +01:00
|
|
|
if (qup_init(gsbi_id, qup_config)) {
|
2014-12-06 19:44:58 +01:00
|
|
|
printk(BIOS_ERR, "failed to initialize qup\n");
|
2014-11-22 00:33:26 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-12-06 19:44:58 +01:00
|
|
|
if (qup_reset_i2c_master_status(gsbi_id)) {
|
|
|
|
printk(BIOS_ERR, "failed to reset i2c master status\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-02-19 12:13:26 +01:00
|
|
|
qup_config->initialized = 1;
|
2014-11-22 00:33:26 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
i2c: Move to Linux like `struct i2c_msg`
Our current struct for I2C segments `i2c_seg` was close to being compa-
tible to the Linux version `i2c_msg`, close to being compatible to SMBus
and close to being readable (e.g. what was `chip` supposed to mean?) but
turned out to be hard to fix.
Instead of extending it in a backwards compatible way (and not touching
current controller drivers), replace it with a Linux source compatible
`struct i2c_msg` and patch all the drivers and users with Coccinelle.
The new `struct i2c_msg` should ease porting drivers from Linux and help
to write SMBus compatible controller drivers.
Beside integer type changes, the field `read` is replaced with a generic
field `flags` and `chip` is renamed to `slave`.
Patched with Coccinelle using the clumsy spatch below and some manual
changes:
* Nested struct initializers and one field access skipped by Coccinelle.
* Removed assumption in the code that I2C_M_RD is 1.
* In `i2c.h`, changed all occurences of `chip` to `slave`.
@@ @@
-struct i2c_seg
+struct i2c_msg
@@ identifier msg; expression e; @@
(
struct i2c_msg msg = {
- .read = 0,
+ .flags = 0,
};
|
struct i2c_msg msg = {
- .read = 1,
+ .flags = I2C_M_RD,
};
|
struct i2c_msg msg = {
- .chip = e,
+ .slave = e,
};
)
@@ struct i2c_msg msg; statement S1, S2; @@
(
-if (msg.read)
+if (msg.flags & I2C_M_RD)
S1 else S2
|
-if (msg.read)
+if (msg.flags & I2C_M_RD)
S1
)
@@ struct i2c_msg *msg; statement S1, S2; @@
(
-if (msg->read)
+if (msg->flags & I2C_M_RD)
S1 else S2
|
-if (msg->read)
+if (msg->flags & I2C_M_RD)
S1
)
@@ struct i2c_msg msg; expression e; @@
(
-msg.read = 0;
+msg.flags = 0;
|
-msg.read = 1;
+msg.flags = I2C_M_RD;
|
-msg.read = e;
+msg.flags = e ? I2C_M_RD : 0;
|
-!!(msg.read)
+(msg.flags & I2C_M_RD)
|
-(msg.read)
+(msg.flags & I2C_M_RD)
)
@@ struct i2c_msg *msg; expression e; @@
(
-msg->read = 0;
+msg->flags = 0;
|
-msg->read = 1;
+msg->flags = I2C_M_RD;
|
-msg->read = e;
+msg->flags = e ? I2C_M_RD : 0;
|
-!!(msg->read)
+(msg->flags & I2C_M_RD)
|
-(msg->read)
+(msg->flags & I2C_M_RD)
)
@@ struct i2c_msg msg; @@
-msg.chip
+msg.slave
@@ struct i2c_msg *msg; expression e; @@
-msg[e].chip
+msg[e].slave
@ slave disable ptr_to_array @ struct i2c_msg *msg; @@
-msg->chip
+msg->slave
Change-Id: Ifd7cabf0a18ffd7a1def25d1d7059b713d0b7ea9
Signed-off-by: Nico Huber <nico.huber@secunet.com>
Reviewed-on: https://review.coreboot.org/20542
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
Reviewed-by: Werner Zeh <werner.zeh@siemens.com>
Reviewed-by: Kyösti Mälkki <kyosti.malkki@gmail.com>
Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net>
2017-07-12 17:59:16 +02:00
|
|
|
int platform_i2c_transfer(unsigned bus, struct i2c_msg *segments,
|
|
|
|
int seg_count)
|
2014-11-22 00:33:26 +01:00
|
|
|
{
|
i2c: Move to Linux like `struct i2c_msg`
Our current struct for I2C segments `i2c_seg` was close to being compa-
tible to the Linux version `i2c_msg`, close to being compatible to SMBus
and close to being readable (e.g. what was `chip` supposed to mean?) but
turned out to be hard to fix.
Instead of extending it in a backwards compatible way (and not touching
current controller drivers), replace it with a Linux source compatible
`struct i2c_msg` and patch all the drivers and users with Coccinelle.
The new `struct i2c_msg` should ease porting drivers from Linux and help
to write SMBus compatible controller drivers.
Beside integer type changes, the field `read` is replaced with a generic
field `flags` and `chip` is renamed to `slave`.
Patched with Coccinelle using the clumsy spatch below and some manual
changes:
* Nested struct initializers and one field access skipped by Coccinelle.
* Removed assumption in the code that I2C_M_RD is 1.
* In `i2c.h`, changed all occurences of `chip` to `slave`.
@@ @@
-struct i2c_seg
+struct i2c_msg
@@ identifier msg; expression e; @@
(
struct i2c_msg msg = {
- .read = 0,
+ .flags = 0,
};
|
struct i2c_msg msg = {
- .read = 1,
+ .flags = I2C_M_RD,
};
|
struct i2c_msg msg = {
- .chip = e,
+ .slave = e,
};
)
@@ struct i2c_msg msg; statement S1, S2; @@
(
-if (msg.read)
+if (msg.flags & I2C_M_RD)
S1 else S2
|
-if (msg.read)
+if (msg.flags & I2C_M_RD)
S1
)
@@ struct i2c_msg *msg; statement S1, S2; @@
(
-if (msg->read)
+if (msg->flags & I2C_M_RD)
S1 else S2
|
-if (msg->read)
+if (msg->flags & I2C_M_RD)
S1
)
@@ struct i2c_msg msg; expression e; @@
(
-msg.read = 0;
+msg.flags = 0;
|
-msg.read = 1;
+msg.flags = I2C_M_RD;
|
-msg.read = e;
+msg.flags = e ? I2C_M_RD : 0;
|
-!!(msg.read)
+(msg.flags & I2C_M_RD)
|
-(msg.read)
+(msg.flags & I2C_M_RD)
)
@@ struct i2c_msg *msg; expression e; @@
(
-msg->read = 0;
+msg->flags = 0;
|
-msg->read = 1;
+msg->flags = I2C_M_RD;
|
-msg->read = e;
+msg->flags = e ? I2C_M_RD : 0;
|
-!!(msg->read)
+(msg->flags & I2C_M_RD)
|
-(msg->read)
+(msg->flags & I2C_M_RD)
)
@@ struct i2c_msg msg; @@
-msg.chip
+msg.slave
@@ struct i2c_msg *msg; expression e; @@
-msg[e].chip
+msg[e].slave
@ slave disable ptr_to_array @ struct i2c_msg *msg; @@
-msg->chip
+msg->slave
Change-Id: Ifd7cabf0a18ffd7a1def25d1d7059b713d0b7ea9
Signed-off-by: Nico Huber <nico.huber@secunet.com>
Reviewed-on: https://review.coreboot.org/20542
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
Reviewed-by: Werner Zeh <werner.zeh@siemens.com>
Reviewed-by: Kyösti Mälkki <kyosti.malkki@gmail.com>
Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net>
2017-07-12 17:59:16 +02:00
|
|
|
struct i2c_msg *seg = segments;
|
2014-12-06 19:44:58 +01:00
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (i2c_init(bus))
|
|
|
|
return 1;
|
2014-11-22 00:33:26 +01:00
|
|
|
|
2015-02-27 14:41:19 +01:00
|
|
|
while (!ret && seg_count--) {
|
i2c: Move to Linux like `struct i2c_msg`
Our current struct for I2C segments `i2c_seg` was close to being compa-
tible to the Linux version `i2c_msg`, close to being compatible to SMBus
and close to being readable (e.g. what was `chip` supposed to mean?) but
turned out to be hard to fix.
Instead of extending it in a backwards compatible way (and not touching
current controller drivers), replace it with a Linux source compatible
`struct i2c_msg` and patch all the drivers and users with Coccinelle.
The new `struct i2c_msg` should ease porting drivers from Linux and help
to write SMBus compatible controller drivers.
Beside integer type changes, the field `read` is replaced with a generic
field `flags` and `chip` is renamed to `slave`.
Patched with Coccinelle using the clumsy spatch below and some manual
changes:
* Nested struct initializers and one field access skipped by Coccinelle.
* Removed assumption in the code that I2C_M_RD is 1.
* In `i2c.h`, changed all occurences of `chip` to `slave`.
@@ @@
-struct i2c_seg
+struct i2c_msg
@@ identifier msg; expression e; @@
(
struct i2c_msg msg = {
- .read = 0,
+ .flags = 0,
};
|
struct i2c_msg msg = {
- .read = 1,
+ .flags = I2C_M_RD,
};
|
struct i2c_msg msg = {
- .chip = e,
+ .slave = e,
};
)
@@ struct i2c_msg msg; statement S1, S2; @@
(
-if (msg.read)
+if (msg.flags & I2C_M_RD)
S1 else S2
|
-if (msg.read)
+if (msg.flags & I2C_M_RD)
S1
)
@@ struct i2c_msg *msg; statement S1, S2; @@
(
-if (msg->read)
+if (msg->flags & I2C_M_RD)
S1 else S2
|
-if (msg->read)
+if (msg->flags & I2C_M_RD)
S1
)
@@ struct i2c_msg msg; expression e; @@
(
-msg.read = 0;
+msg.flags = 0;
|
-msg.read = 1;
+msg.flags = I2C_M_RD;
|
-msg.read = e;
+msg.flags = e ? I2C_M_RD : 0;
|
-!!(msg.read)
+(msg.flags & I2C_M_RD)
|
-(msg.read)
+(msg.flags & I2C_M_RD)
)
@@ struct i2c_msg *msg; expression e; @@
(
-msg->read = 0;
+msg->flags = 0;
|
-msg->read = 1;
+msg->flags = I2C_M_RD;
|
-msg->read = e;
+msg->flags = e ? I2C_M_RD : 0;
|
-!!(msg->read)
+(msg->flags & I2C_M_RD)
|
-(msg->read)
+(msg->flags & I2C_M_RD)
)
@@ struct i2c_msg msg; @@
-msg.chip
+msg.slave
@@ struct i2c_msg *msg; expression e; @@
-msg[e].chip
+msg[e].slave
@ slave disable ptr_to_array @ struct i2c_msg *msg; @@
-msg->chip
+msg->slave
Change-Id: Ifd7cabf0a18ffd7a1def25d1d7059b713d0b7ea9
Signed-off-by: Nico Huber <nico.huber@secunet.com>
Reviewed-on: https://review.coreboot.org/20542
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
Reviewed-by: Werner Zeh <werner.zeh@siemens.com>
Reviewed-by: Kyösti Mälkki <kyosti.malkki@gmail.com>
Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net>
2017-07-12 17:59:16 +02:00
|
|
|
if (seg->flags & I2C_M_RD)
|
|
|
|
ret = i2c_read(bus, seg->slave, seg->buf, seg->len);
|
2014-12-06 19:44:58 +01:00
|
|
|
else
|
i2c: Move to Linux like `struct i2c_msg`
Our current struct for I2C segments `i2c_seg` was close to being compa-
tible to the Linux version `i2c_msg`, close to being compatible to SMBus
and close to being readable (e.g. what was `chip` supposed to mean?) but
turned out to be hard to fix.
Instead of extending it in a backwards compatible way (and not touching
current controller drivers), replace it with a Linux source compatible
`struct i2c_msg` and patch all the drivers and users with Coccinelle.
The new `struct i2c_msg` should ease porting drivers from Linux and help
to write SMBus compatible controller drivers.
Beside integer type changes, the field `read` is replaced with a generic
field `flags` and `chip` is renamed to `slave`.
Patched with Coccinelle using the clumsy spatch below and some manual
changes:
* Nested struct initializers and one field access skipped by Coccinelle.
* Removed assumption in the code that I2C_M_RD is 1.
* In `i2c.h`, changed all occurences of `chip` to `slave`.
@@ @@
-struct i2c_seg
+struct i2c_msg
@@ identifier msg; expression e; @@
(
struct i2c_msg msg = {
- .read = 0,
+ .flags = 0,
};
|
struct i2c_msg msg = {
- .read = 1,
+ .flags = I2C_M_RD,
};
|
struct i2c_msg msg = {
- .chip = e,
+ .slave = e,
};
)
@@ struct i2c_msg msg; statement S1, S2; @@
(
-if (msg.read)
+if (msg.flags & I2C_M_RD)
S1 else S2
|
-if (msg.read)
+if (msg.flags & I2C_M_RD)
S1
)
@@ struct i2c_msg *msg; statement S1, S2; @@
(
-if (msg->read)
+if (msg->flags & I2C_M_RD)
S1 else S2
|
-if (msg->read)
+if (msg->flags & I2C_M_RD)
S1
)
@@ struct i2c_msg msg; expression e; @@
(
-msg.read = 0;
+msg.flags = 0;
|
-msg.read = 1;
+msg.flags = I2C_M_RD;
|
-msg.read = e;
+msg.flags = e ? I2C_M_RD : 0;
|
-!!(msg.read)
+(msg.flags & I2C_M_RD)
|
-(msg.read)
+(msg.flags & I2C_M_RD)
)
@@ struct i2c_msg *msg; expression e; @@
(
-msg->read = 0;
+msg->flags = 0;
|
-msg->read = 1;
+msg->flags = I2C_M_RD;
|
-msg->read = e;
+msg->flags = e ? I2C_M_RD : 0;
|
-!!(msg->read)
+(msg->flags & I2C_M_RD)
|
-(msg->read)
+(msg->flags & I2C_M_RD)
)
@@ struct i2c_msg msg; @@
-msg.chip
+msg.slave
@@ struct i2c_msg *msg; expression e; @@
-msg[e].chip
+msg[e].slave
@ slave disable ptr_to_array @ struct i2c_msg *msg; @@
-msg->chip
+msg->slave
Change-Id: Ifd7cabf0a18ffd7a1def25d1d7059b713d0b7ea9
Signed-off-by: Nico Huber <nico.huber@secunet.com>
Reviewed-on: https://review.coreboot.org/20542
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
Reviewed-by: Werner Zeh <werner.zeh@siemens.com>
Reviewed-by: Kyösti Mälkki <kyosti.malkki@gmail.com>
Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net>
2017-07-12 17:59:16 +02:00
|
|
|
ret = i2c_write(bus, seg->slave, seg->buf, seg->len,
|
2014-12-06 19:44:58 +01:00
|
|
|
(seg_count ? 0 : 1));
|
|
|
|
seg++;
|
2014-11-22 00:33:26 +01:00
|
|
|
}
|
2014-12-06 19:44:58 +01:00
|
|
|
|
|
|
|
if (ret) {
|
|
|
|
qup_set_state(bus, QUP_STATE_RESET);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2014-11-22 00:33:26 +01:00
|
|
|
}
|