summaryrefslogtreecommitdiff
path: root/src/drivers/i2c
diff options
context:
space:
mode:
authorArthur Heymans <arthur@aheymans.xyz>2017-06-06 09:46:01 +0200
committerMartin Roth <martinroth@google.com>2017-08-30 15:46:55 +0000
commit24231aceacd46a6b5f1c29dda6c97a436495555d (patch)
tree46918bcc6a05bb4999903c3e971aaad64fe59a77 /src/drivers/i2c
parent4f62d165dfb1824c40e7501b27c0f7dccb8323a6 (diff)
drivers/i2c/ck505: Add generic driver to configure clockgen
Replaces the ics/954309 driver with a more generic version to accommodate clockgens with a different amount of registers. It also features a mask to only touch certain bits of the clockgen. TODO: set appropriate mask for X60/T60 since the datasheets for their clockgens can be found. Change-Id: Ie43c4de7891a39f2f443e78213ecd688134e68d7 Signed-off-by: Arthur Heymans <arthur@aheymans.xyz> Reviewed-on: https://review.coreboot.org/20042 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Kyösti Mälkki <kyosti.malkki@gmail.com>
Diffstat (limited to 'src/drivers/i2c')
-rw-r--r--src/drivers/i2c/ck505/Kconfig2
-rw-r--r--src/drivers/i2c/ck505/Makefile.inc1
-rw-r--r--src/drivers/i2c/ck505/chip.h26
-rw-r--r--src/drivers/i2c/ck505/ck505.c81
4 files changed, 110 insertions, 0 deletions
diff --git a/src/drivers/i2c/ck505/Kconfig b/src/drivers/i2c/ck505/Kconfig
new file mode 100644
index 0000000000..43826a0fe9
--- /dev/null
+++ b/src/drivers/i2c/ck505/Kconfig
@@ -0,0 +1,2 @@
+config DRIVERS_I2C_CK505
+ bool
diff --git a/src/drivers/i2c/ck505/Makefile.inc b/src/drivers/i2c/ck505/Makefile.inc
new file mode 100644
index 0000000000..5ccf4a86cd
--- /dev/null
+++ b/src/drivers/i2c/ck505/Makefile.inc
@@ -0,0 +1 @@
+ramstage-$(CONFIG_DRIVERS_I2C_CK505) += ck505.c
diff --git a/src/drivers/i2c/ck505/chip.h b/src/drivers/i2c/ck505/chip.h
new file mode 100644
index 0000000000..8ce297cb53
--- /dev/null
+++ b/src/drivers/i2c/ck505/chip.h
@@ -0,0 +1,26 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright (C) 2011 Sven Schnelle <svens@stackframe.org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; version 2 of
+ * the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#ifndef DRIVERS_CK505_CHIP_H
+#define DRIVERS_CK505_CHIP_H
+
+struct drivers_i2c_ck505_config {
+ const int nregs;
+ const u8 regs[32];
+ const u8 mask[32];
+};
+
+#endif
diff --git a/src/drivers/i2c/ck505/ck505.c b/src/drivers/i2c/ck505/ck505.c
new file mode 100644
index 0000000000..4f1e51e02a
--- /dev/null
+++ b/src/drivers/i2c/ck505/ck505.c
@@ -0,0 +1,81 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright (C) 2011 Sven Schnelle <svens@stackframe.org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; version 2 of
+ * the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#include <assert.h>
+#include <console/console.h>
+#include <device/device.h>
+#include <device/smbus.h>
+#include <device/pci.h>
+#include <device/pci_ids.h>
+#include <device/pci_ops.h>
+#include <cpu/x86/msr.h>
+#include "chip.h"
+#include <string.h>
+
+#define SMBUS_BLOCK_SIZE 32
+
+static void ck505_init(struct device *dev)
+{
+ struct drivers_i2c_ck505_config *config;
+ int dev_nregs, nregs;
+ u8 block[SMBUS_BLOCK_SIZE];
+ int i;
+
+ if (!dev->enabled || dev->path.type != DEVICE_PATH_I2C)
+ return;
+
+ config = dev->chip_info;
+
+ dev_nregs = smbus_block_read(dev, 0, sizeof(block), block);
+
+ if (dev_nregs < 0) {
+ printk(BIOS_ERR, "Failed reading ck505 configuration!\n");
+ return;
+ }
+
+ /* This means that the devicetree doesn't have to specify nregs */
+ nregs = MIN(MIN(dev_nregs, config->nregs == 0 ? SMBUS_BLOCK_SIZE
+ : config->nregs), ARRAY_SIZE(config->mask));
+
+
+ printk(BIOS_DEBUG, "Changing %d of the %d ck505 config bytes.\n",
+ nregs, dev_nregs);
+
+ assert(ARRAY_SIZE(config->mask) == ARRAY_SIZE(config->regs));
+
+ for (i = 0; i < nregs && i < SMBUS_BLOCK_SIZE; i++)
+ block[i] = (block[i] & ~config->mask[i]) | config->regs[i];
+
+ if (smbus_block_write(dev, 0, dev_nregs, block) < 0)
+ printk(BIOS_ERR, "Failed writing ck505 configuration!\n");
+}
+
+static struct device_operations ck505_operations = {
+ .read_resources = DEVICE_NOOP,
+ .set_resources = DEVICE_NOOP,
+ .enable_resources = DEVICE_NOOP,
+ .init = ck505_init,
+};
+
+static void enable_dev(struct device *dev)
+{
+ dev->ops = &ck505_operations;
+}
+
+struct chip_operations drivers_i2c_ck505_ops = {
+ CHIP_NAME("CK505 Clock generator")
+ .enable_dev = enable_dev,
+};