2020-04-04 18:51:23 +02:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2015-02-10 02:40:58 +01:00
|
|
|
|
2019-03-03 07:01:05 +01:00
|
|
|
#include <device/mmio.h>
|
2015-02-10 02:40:58 +01:00
|
|
|
#include <console/console.h>
|
2017-08-01 14:02:40 +02:00
|
|
|
#include <device/i2c_simple.h>
|
2015-02-10 02:40:58 +01:00
|
|
|
#include <gpio.h>
|
|
|
|
#include <soc/grf.h>
|
|
|
|
#include <soc/i2c.h>
|
|
|
|
#include <soc/pmu.h>
|
|
|
|
|
|
|
|
static struct {
|
|
|
|
gpio_t scl;
|
|
|
|
gpio_t sda;
|
|
|
|
} pins[] = {
|
|
|
|
[0]{.scl = GPIO(0, C, 0), .sda = GPIO(0, B, 7)},
|
|
|
|
[1]{.scl = GPIO(8, A, 5), .sda = GPIO(8, A, 4)},
|
|
|
|
[2]{.scl = GPIO(6, B, 2), .sda = GPIO(6, B, 1)},
|
|
|
|
[3]{.scl = GPIO(2, C, 0), .sda = GPIO(2, C, 1)},
|
|
|
|
[4]{.scl = GPIO(7, C, 2), .sda = GPIO(7, C, 1)},
|
|
|
|
[5]{.scl = GPIO(7, C, 4), .sda = GPIO(7, C, 3)},
|
|
|
|
};
|
|
|
|
|
2019-10-24 05:45:23 +02:00
|
|
|
static int get_scl(unsigned int bus)
|
2015-02-10 02:40:58 +01:00
|
|
|
{
|
|
|
|
return gpio_get(pins[bus].scl);
|
|
|
|
}
|
|
|
|
|
2019-10-24 05:45:23 +02:00
|
|
|
static int get_sda(unsigned int bus)
|
2015-02-10 02:40:58 +01:00
|
|
|
{
|
|
|
|
return gpio_get(pins[bus].sda);
|
|
|
|
}
|
|
|
|
|
2019-10-24 05:45:23 +02:00
|
|
|
static void set_scl(unsigned int bus, int high)
|
2015-02-10 02:40:58 +01:00
|
|
|
{
|
|
|
|
if (high)
|
|
|
|
gpio_input_pullup(pins[bus].scl);
|
|
|
|
else
|
|
|
|
gpio_output(pins[bus].scl, 0);
|
|
|
|
}
|
|
|
|
|
2019-10-24 05:45:23 +02:00
|
|
|
static void set_sda(unsigned int bus, int high)
|
2015-02-10 02:40:58 +01:00
|
|
|
{
|
|
|
|
if (high)
|
|
|
|
gpio_input_pullup(pins[bus].sda);
|
|
|
|
else
|
|
|
|
gpio_output(pins[bus].sda, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct software_i2c_ops rk_ops = {
|
|
|
|
.get_scl = get_scl,
|
|
|
|
.get_sda = get_sda,
|
|
|
|
.set_scl = set_scl,
|
|
|
|
.set_sda = set_sda,
|
|
|
|
};
|
|
|
|
|
2019-10-24 05:45:23 +02:00
|
|
|
void software_i2c_attach(unsigned int bus)
|
2015-02-10 02:40:58 +01:00
|
|
|
{
|
|
|
|
software_i2c[bus] = &rk_ops;
|
|
|
|
|
|
|
|
/* Mux pins to GPIO function for software I2C emulation. */
|
|
|
|
switch (bus) {
|
|
|
|
case 0:
|
2019-12-03 07:03:27 +01:00
|
|
|
clrbits32(&rk3288_pmu->iomux_i2c0scl, IOMUX_I2C0SCL);
|
|
|
|
clrbits32(&rk3288_pmu->iomux_i2c0sda, IOMUX_I2C0SDA);
|
2015-02-10 02:40:58 +01:00
|
|
|
break;
|
|
|
|
case 1:
|
arm(64): Globally replace writel(v, a) with write32(a, v)
This patch is a raw application of the following spatch to src/:
@@
expression A, V;
@@
- writel(V, A)
+ write32(A, V)
@@
expression A, V;
@@
- writew(V, A)
+ write16(A, V)
@@
expression A, V;
@@
- writeb(V, A)
+ write8(A, V)
@@
expression A;
@@
- readl(A)
+ read32(A)
@@
expression A;
@@
- readb(A)
+ read8(A)
BRANCH=none
BUG=chromium:444723
TEST=None (depends on next patch)
Change-Id: I5dd96490c85ee2bcbc669f08bc6fff0ecc0f9e27
Signed-off-by: Patrick Georgi <pgeorgi@chromium.org>
Original-Commit-Id: 64f643da95d85954c4d4ea91c34a5c69b9b08eb6
Original-Change-Id: I366a2eb5b3a0df2279ebcce572fe814894791c42
Original-Signed-off-by: Julius Werner <jwerner@chromium.org>
Original-Reviewed-on: https://chromium-review.googlesource.com/254864
Reviewed-on: http://review.coreboot.org/9836
Tested-by: build bot (Jenkins)
Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
2015-02-19 23:51:15 +01:00
|
|
|
write32(&rk3288_grf->iomux_i2c1, IOMUX_GPIO(IOMUX_I2C1));
|
2015-02-10 02:40:58 +01:00
|
|
|
break;
|
|
|
|
case 2:
|
arm(64): Globally replace writel(v, a) with write32(a, v)
This patch is a raw application of the following spatch to src/:
@@
expression A, V;
@@
- writel(V, A)
+ write32(A, V)
@@
expression A, V;
@@
- writew(V, A)
+ write16(A, V)
@@
expression A, V;
@@
- writeb(V, A)
+ write8(A, V)
@@
expression A;
@@
- readl(A)
+ read32(A)
@@
expression A;
@@
- readb(A)
+ read8(A)
BRANCH=none
BUG=chromium:444723
TEST=None (depends on next patch)
Change-Id: I5dd96490c85ee2bcbc669f08bc6fff0ecc0f9e27
Signed-off-by: Patrick Georgi <pgeorgi@chromium.org>
Original-Commit-Id: 64f643da95d85954c4d4ea91c34a5c69b9b08eb6
Original-Change-Id: I366a2eb5b3a0df2279ebcce572fe814894791c42
Original-Signed-off-by: Julius Werner <jwerner@chromium.org>
Original-Reviewed-on: https://chromium-review.googlesource.com/254864
Reviewed-on: http://review.coreboot.org/9836
Tested-by: build bot (Jenkins)
Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
2015-02-19 23:51:15 +01:00
|
|
|
write32(&rk3288_grf->iomux_i2c2, IOMUX_GPIO(IOMUX_I2C2));
|
2015-02-10 02:40:58 +01:00
|
|
|
break;
|
|
|
|
case 3:
|
arm(64): Globally replace writel(v, a) with write32(a, v)
This patch is a raw application of the following spatch to src/:
@@
expression A, V;
@@
- writel(V, A)
+ write32(A, V)
@@
expression A, V;
@@
- writew(V, A)
+ write16(A, V)
@@
expression A, V;
@@
- writeb(V, A)
+ write8(A, V)
@@
expression A;
@@
- readl(A)
+ read32(A)
@@
expression A;
@@
- readb(A)
+ read8(A)
BRANCH=none
BUG=chromium:444723
TEST=None (depends on next patch)
Change-Id: I5dd96490c85ee2bcbc669f08bc6fff0ecc0f9e27
Signed-off-by: Patrick Georgi <pgeorgi@chromium.org>
Original-Commit-Id: 64f643da95d85954c4d4ea91c34a5c69b9b08eb6
Original-Change-Id: I366a2eb5b3a0df2279ebcce572fe814894791c42
Original-Signed-off-by: Julius Werner <jwerner@chromium.org>
Original-Reviewed-on: https://chromium-review.googlesource.com/254864
Reviewed-on: http://review.coreboot.org/9836
Tested-by: build bot (Jenkins)
Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
2015-02-19 23:51:15 +01:00
|
|
|
write32(&rk3288_grf->iomux_i2c3, IOMUX_GPIO(IOMUX_I2C3));
|
2015-02-10 02:40:58 +01:00
|
|
|
break;
|
|
|
|
case 4:
|
arm(64): Globally replace writel(v, a) with write32(a, v)
This patch is a raw application of the following spatch to src/:
@@
expression A, V;
@@
- writel(V, A)
+ write32(A, V)
@@
expression A, V;
@@
- writew(V, A)
+ write16(A, V)
@@
expression A, V;
@@
- writeb(V, A)
+ write8(A, V)
@@
expression A;
@@
- readl(A)
+ read32(A)
@@
expression A;
@@
- readb(A)
+ read8(A)
BRANCH=none
BUG=chromium:444723
TEST=None (depends on next patch)
Change-Id: I5dd96490c85ee2bcbc669f08bc6fff0ecc0f9e27
Signed-off-by: Patrick Georgi <pgeorgi@chromium.org>
Original-Commit-Id: 64f643da95d85954c4d4ea91c34a5c69b9b08eb6
Original-Change-Id: I366a2eb5b3a0df2279ebcce572fe814894791c42
Original-Signed-off-by: Julius Werner <jwerner@chromium.org>
Original-Reviewed-on: https://chromium-review.googlesource.com/254864
Reviewed-on: http://review.coreboot.org/9836
Tested-by: build bot (Jenkins)
Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
2015-02-19 23:51:15 +01:00
|
|
|
write32(&rk3288_grf->iomux_i2c4, IOMUX_GPIO(IOMUX_I2C4));
|
2015-02-10 02:40:58 +01:00
|
|
|
break;
|
|
|
|
case 5:
|
arm(64): Globally replace writel(v, a) with write32(a, v)
This patch is a raw application of the following spatch to src/:
@@
expression A, V;
@@
- writel(V, A)
+ write32(A, V)
@@
expression A, V;
@@
- writew(V, A)
+ write16(A, V)
@@
expression A, V;
@@
- writeb(V, A)
+ write8(A, V)
@@
expression A;
@@
- readl(A)
+ read32(A)
@@
expression A;
@@
- readb(A)
+ read8(A)
BRANCH=none
BUG=chromium:444723
TEST=None (depends on next patch)
Change-Id: I5dd96490c85ee2bcbc669f08bc6fff0ecc0f9e27
Signed-off-by: Patrick Georgi <pgeorgi@chromium.org>
Original-Commit-Id: 64f643da95d85954c4d4ea91c34a5c69b9b08eb6
Original-Change-Id: I366a2eb5b3a0df2279ebcce572fe814894791c42
Original-Signed-off-by: Julius Werner <jwerner@chromium.org>
Original-Reviewed-on: https://chromium-review.googlesource.com/254864
Reviewed-on: http://review.coreboot.org/9836
Tested-by: build bot (Jenkins)
Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
2015-02-19 23:51:15 +01:00
|
|
|
write32(&rk3288_grf->iomux_i2c5scl, IOMUX_GPIO(IOMUX_I2C5SCL));
|
|
|
|
write32(&rk3288_grf->iomux_i2c5sda, IOMUX_GPIO(IOMUX_I2C5SDA));
|
2015-02-10 02:40:58 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
die("Unknown I2C bus number!");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize bus to idle state. */
|
|
|
|
set_scl(bus, 1);
|
|
|
|
set_sda(bus, 1);
|
|
|
|
}
|
|
|
|
|
2019-10-24 05:45:23 +02:00
|
|
|
void software_i2c_detach(unsigned int bus)
|
2015-02-10 02:40:58 +01:00
|
|
|
{
|
|
|
|
software_i2c[bus] = NULL;
|
|
|
|
|
|
|
|
/* Mux pins back to hardware I2C controller. */
|
|
|
|
switch (bus) {
|
|
|
|
case 0:
|
2019-12-03 07:03:27 +01:00
|
|
|
setbits32(&rk3288_pmu->iomux_i2c0scl, IOMUX_I2C0SCL);
|
|
|
|
setbits32(&rk3288_pmu->iomux_i2c0sda, IOMUX_I2C0SDA);
|
2015-02-10 02:40:58 +01:00
|
|
|
break;
|
|
|
|
case 1:
|
arm(64): Globally replace writel(v, a) with write32(a, v)
This patch is a raw application of the following spatch to src/:
@@
expression A, V;
@@
- writel(V, A)
+ write32(A, V)
@@
expression A, V;
@@
- writew(V, A)
+ write16(A, V)
@@
expression A, V;
@@
- writeb(V, A)
+ write8(A, V)
@@
expression A;
@@
- readl(A)
+ read32(A)
@@
expression A;
@@
- readb(A)
+ read8(A)
BRANCH=none
BUG=chromium:444723
TEST=None (depends on next patch)
Change-Id: I5dd96490c85ee2bcbc669f08bc6fff0ecc0f9e27
Signed-off-by: Patrick Georgi <pgeorgi@chromium.org>
Original-Commit-Id: 64f643da95d85954c4d4ea91c34a5c69b9b08eb6
Original-Change-Id: I366a2eb5b3a0df2279ebcce572fe814894791c42
Original-Signed-off-by: Julius Werner <jwerner@chromium.org>
Original-Reviewed-on: https://chromium-review.googlesource.com/254864
Reviewed-on: http://review.coreboot.org/9836
Tested-by: build bot (Jenkins)
Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
2015-02-19 23:51:15 +01:00
|
|
|
write32(&rk3288_grf->iomux_i2c1, IOMUX_I2C1);
|
2015-02-10 02:40:58 +01:00
|
|
|
break;
|
|
|
|
case 2:
|
arm(64): Globally replace writel(v, a) with write32(a, v)
This patch is a raw application of the following spatch to src/:
@@
expression A, V;
@@
- writel(V, A)
+ write32(A, V)
@@
expression A, V;
@@
- writew(V, A)
+ write16(A, V)
@@
expression A, V;
@@
- writeb(V, A)
+ write8(A, V)
@@
expression A;
@@
- readl(A)
+ read32(A)
@@
expression A;
@@
- readb(A)
+ read8(A)
BRANCH=none
BUG=chromium:444723
TEST=None (depends on next patch)
Change-Id: I5dd96490c85ee2bcbc669f08bc6fff0ecc0f9e27
Signed-off-by: Patrick Georgi <pgeorgi@chromium.org>
Original-Commit-Id: 64f643da95d85954c4d4ea91c34a5c69b9b08eb6
Original-Change-Id: I366a2eb5b3a0df2279ebcce572fe814894791c42
Original-Signed-off-by: Julius Werner <jwerner@chromium.org>
Original-Reviewed-on: https://chromium-review.googlesource.com/254864
Reviewed-on: http://review.coreboot.org/9836
Tested-by: build bot (Jenkins)
Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
2015-02-19 23:51:15 +01:00
|
|
|
write32(&rk3288_grf->iomux_i2c2, IOMUX_I2C2);
|
2015-02-10 02:40:58 +01:00
|
|
|
break;
|
|
|
|
case 3:
|
arm(64): Globally replace writel(v, a) with write32(a, v)
This patch is a raw application of the following spatch to src/:
@@
expression A, V;
@@
- writel(V, A)
+ write32(A, V)
@@
expression A, V;
@@
- writew(V, A)
+ write16(A, V)
@@
expression A, V;
@@
- writeb(V, A)
+ write8(A, V)
@@
expression A;
@@
- readl(A)
+ read32(A)
@@
expression A;
@@
- readb(A)
+ read8(A)
BRANCH=none
BUG=chromium:444723
TEST=None (depends on next patch)
Change-Id: I5dd96490c85ee2bcbc669f08bc6fff0ecc0f9e27
Signed-off-by: Patrick Georgi <pgeorgi@chromium.org>
Original-Commit-Id: 64f643da95d85954c4d4ea91c34a5c69b9b08eb6
Original-Change-Id: I366a2eb5b3a0df2279ebcce572fe814894791c42
Original-Signed-off-by: Julius Werner <jwerner@chromium.org>
Original-Reviewed-on: https://chromium-review.googlesource.com/254864
Reviewed-on: http://review.coreboot.org/9836
Tested-by: build bot (Jenkins)
Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
2015-02-19 23:51:15 +01:00
|
|
|
write32(&rk3288_grf->iomux_i2c3, IOMUX_I2C3);
|
2015-02-10 02:40:58 +01:00
|
|
|
break;
|
|
|
|
case 4:
|
arm(64): Globally replace writel(v, a) with write32(a, v)
This patch is a raw application of the following spatch to src/:
@@
expression A, V;
@@
- writel(V, A)
+ write32(A, V)
@@
expression A, V;
@@
- writew(V, A)
+ write16(A, V)
@@
expression A, V;
@@
- writeb(V, A)
+ write8(A, V)
@@
expression A;
@@
- readl(A)
+ read32(A)
@@
expression A;
@@
- readb(A)
+ read8(A)
BRANCH=none
BUG=chromium:444723
TEST=None (depends on next patch)
Change-Id: I5dd96490c85ee2bcbc669f08bc6fff0ecc0f9e27
Signed-off-by: Patrick Georgi <pgeorgi@chromium.org>
Original-Commit-Id: 64f643da95d85954c4d4ea91c34a5c69b9b08eb6
Original-Change-Id: I366a2eb5b3a0df2279ebcce572fe814894791c42
Original-Signed-off-by: Julius Werner <jwerner@chromium.org>
Original-Reviewed-on: https://chromium-review.googlesource.com/254864
Reviewed-on: http://review.coreboot.org/9836
Tested-by: build bot (Jenkins)
Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
2015-02-19 23:51:15 +01:00
|
|
|
write32(&rk3288_grf->iomux_i2c4, IOMUX_I2C4);
|
2015-02-10 02:40:58 +01:00
|
|
|
break;
|
|
|
|
case 5:
|
arm(64): Globally replace writel(v, a) with write32(a, v)
This patch is a raw application of the following spatch to src/:
@@
expression A, V;
@@
- writel(V, A)
+ write32(A, V)
@@
expression A, V;
@@
- writew(V, A)
+ write16(A, V)
@@
expression A, V;
@@
- writeb(V, A)
+ write8(A, V)
@@
expression A;
@@
- readl(A)
+ read32(A)
@@
expression A;
@@
- readb(A)
+ read8(A)
BRANCH=none
BUG=chromium:444723
TEST=None (depends on next patch)
Change-Id: I5dd96490c85ee2bcbc669f08bc6fff0ecc0f9e27
Signed-off-by: Patrick Georgi <pgeorgi@chromium.org>
Original-Commit-Id: 64f643da95d85954c4d4ea91c34a5c69b9b08eb6
Original-Change-Id: I366a2eb5b3a0df2279ebcce572fe814894791c42
Original-Signed-off-by: Julius Werner <jwerner@chromium.org>
Original-Reviewed-on: https://chromium-review.googlesource.com/254864
Reviewed-on: http://review.coreboot.org/9836
Tested-by: build bot (Jenkins)
Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
2015-02-19 23:51:15 +01:00
|
|
|
write32(&rk3288_grf->iomux_i2c5scl, IOMUX_I2C5SCL);
|
|
|
|
write32(&rk3288_grf->iomux_i2c5sda, IOMUX_I2C5SDA);
|
2015-02-10 02:40:58 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
die("Unknown I2C bus number!");
|
|
|
|
}
|
|
|
|
}
|