summaryrefslogtreecommitdiff
path: root/drivers/misc
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/misc')
-rw-r--r--drivers/misc/Kconfig16
-rw-r--r--drivers/misc/Makefile2
-rw-r--r--drivers/misc/altera_sysid.c101
-rw-r--r--drivers/misc/gpio_led.c54
-rw-r--r--drivers/misc/misc-uclass.c51
-rw-r--r--drivers/misc/pca9551_led.c6
-rw-r--r--drivers/misc/status_led.c2
7 files changed, 230 insertions, 2 deletions
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index 8b38a84..101a619 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -4,6 +4,22 @@
menu "Multifunction device drivers"
+config MISC
+ bool "Enable Driver Model for Misc drivers"
+ depends on DM
+ help
+ Enable driver model for miscellaneous devices. This class is
+ used only for those do not fit other more general classes. A
+ set of generic read, write and ioctl methods may be used to
+ access the device.
+
+config ALTERA_SYSID
+ bool "Altera Sysid support"
+ depends on MISC
+ help
+ Select this to enable a sysid for Altera devices. Please find
+ details on the "Embedded Peripherals IP User Guide" of Altera.
+
config CMD_CROS_EC
bool "Enable crosec command"
depends on CROS_EC
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index 8d0fc3c..aa137f5 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -5,7 +5,9 @@
# SPDX-License-Identifier: GPL-2.0+
#
+obj-$(CONFIG_MISC) += misc-uclass.o
obj-$(CONFIG_ALI152X) += ali512x.o
+obj-$(CONFIG_ALTERA_SYSID) += altera_sysid.o
obj-$(CONFIG_DS4510) += ds4510.o
obj-$(CONFIG_CBMEM_CONSOLE) += cbmem_console.o
obj-$(CONFIG_CROS_EC) += cros_ec.o
diff --git a/drivers/misc/altera_sysid.c b/drivers/misc/altera_sysid.c
new file mode 100644
index 0000000..249b273
--- /dev/null
+++ b/drivers/misc/altera_sysid.c
@@ -0,0 +1,101 @@
+/*
+ * (C) Copyright 2004, Psyent Corporation <www.psyent.com>
+ * Scott McNutt <smcnutt@psyent.com>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include <common.h>
+#include <command.h>
+#include <dm.h>
+#include <errno.h>
+#include <misc.h>
+#include <linux/time.h>
+#include <asm/io.h>
+
+struct altera_sysid_regs {
+ u32 id; /* The system build id */
+ u32 timestamp; /* Timestamp */
+};
+
+struct altera_sysid_platdata {
+ struct altera_sysid_regs *regs;
+};
+
+void display_sysid(void)
+{
+ struct udevice *dev;
+ u32 sysid[2];
+ struct tm t;
+ char asc[32];
+ time_t stamp;
+ int ret;
+
+ /* the first misc device will be used */
+ ret = uclass_first_device(UCLASS_MISC, &dev);
+ if (ret)
+ return;
+ if (!dev)
+ return;
+ ret = misc_read(dev, 0, &sysid, sizeof(sysid));
+ if (ret)
+ return;
+
+ stamp = sysid[1];
+ localtime_r(&stamp, &t);
+ asctime_r(&t, asc);
+ printf("SYSID: %08x, %s", sysid[0], asc);
+}
+
+int do_sysid(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+ display_sysid();
+ return 0;
+}
+
+U_BOOT_CMD(
+ sysid, 1, 1, do_sysid,
+ "display Nios-II system id",
+ ""
+);
+
+static int altera_sysid_read(struct udevice *dev,
+ int offset, void *buf, int size)
+{
+ struct altera_sysid_platdata *plat = dev->platdata;
+ struct altera_sysid_regs *const regs = plat->regs;
+ u32 *sysid = buf;
+
+ sysid[0] = readl(&regs->id);
+ sysid[1] = readl(&regs->timestamp);
+
+ return 0;
+}
+
+static int altera_sysid_ofdata_to_platdata(struct udevice *dev)
+{
+ struct altera_sysid_platdata *plat = dev_get_platdata(dev);
+
+ plat->regs = ioremap(dev_get_addr(dev),
+ sizeof(struct altera_sysid_regs));
+
+ return 0;
+}
+
+static const struct misc_ops altera_sysid_ops = {
+ .read = altera_sysid_read,
+};
+
+static const struct udevice_id altera_sysid_ids[] = {
+ { .compatible = "altr,sysid-1.0", },
+ { }
+};
+
+U_BOOT_DRIVER(altera_sysid) = {
+ .name = "altera_sysid",
+ .id = UCLASS_MISC,
+ .of_match = altera_sysid_ids,
+ .ofdata_to_platdata = altera_sysid_ofdata_to_platdata,
+ .platdata_auto_alloc_size = sizeof(struct altera_sysid_platdata),
+ .ops = &altera_sysid_ops,
+};
diff --git a/drivers/misc/gpio_led.c b/drivers/misc/gpio_led.c
index 3e95727..164c30d 100644
--- a/drivers/misc/gpio_led.c
+++ b/drivers/misc/gpio_led.c
@@ -51,3 +51,57 @@ void __led_toggle(led_id_t mask)
{
gpio_set_value(mask, !gpio_get_value(mask));
}
+
+#ifdef CONFIG_GPIO_LED_STUBS
+
+/* 'generic' override of colored LED stubs, to use GPIO functions instead */
+
+#ifdef STATUS_LED_RED
+void red_led_on(void)
+{
+ __led_set(STATUS_LED_RED, STATUS_LED_ON);
+}
+
+void red_led_off(void)
+{
+ __led_set(STATUS_LED_RED, STATUS_LED_OFF);
+}
+#endif
+
+#ifdef STATUS_LED_GREEN
+void green_led_on(void)
+{
+ __led_set(STATUS_LED_GREEN, STATUS_LED_ON);
+}
+
+void green_led_off(void)
+{
+ __led_set(STATUS_LED_GREEN, STATUS_LED_OFF);
+}
+#endif
+
+#ifdef STATUS_LED_YELLOW
+void yellow_led_on(void)
+{
+ __led_set(STATUS_LED_YELLOW, STATUS_LED_ON);
+}
+
+void yellow_led_off(void)
+{
+ __led_set(STATUS_LED_YELLOW, STATUS_LED_OFF);
+}
+#endif
+
+#ifdef STATUS_LED_BLUE
+void blue_led_on(void)
+{
+ __led_set(STATUS_LED_BLUE, STATUS_LED_ON);
+}
+
+void blue_led_off(void)
+{
+ __led_set(STATUS_LED_BLUE, STATUS_LED_OFF);
+}
+#endif
+
+#endif /* CONFIG_GPIO_LED_STUBS */
diff --git a/drivers/misc/misc-uclass.c b/drivers/misc/misc-uclass.c
new file mode 100644
index 0000000..13a6ea5
--- /dev/null
+++ b/drivers/misc/misc-uclass.c
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2010 Thomas Chou <thomas@wytron.com.tw>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <errno.h>
+#include <misc.h>
+
+/*
+ * Implement a miscellaneous uclass for those do not fit other more
+ * general classes. A set of generic read, write and ioctl methods may
+ * be used to access the device.
+ */
+
+int misc_read(struct udevice *dev, int offset, void *buf, int size)
+{
+ const struct misc_ops *ops = device_get_ops(dev);
+
+ if (!ops->read)
+ return -ENOSYS;
+
+ return ops->read(dev, offset, buf, size);
+}
+
+int misc_write(struct udevice *dev, int offset, void *buf, int size)
+{
+ const struct misc_ops *ops = device_get_ops(dev);
+
+ if (!ops->write)
+ return -ENOSYS;
+
+ return ops->write(dev, offset, buf, size);
+}
+
+int misc_ioctl(struct udevice *dev, unsigned long request, void *buf)
+{
+ const struct misc_ops *ops = device_get_ops(dev);
+
+ if (!ops->ioctl)
+ return -ENOSYS;
+
+ return ops->ioctl(dev, request, buf);
+}
+
+UCLASS_DRIVER(misc) = {
+ .id = UCLASS_MISC,
+ .name = "misc",
+};
diff --git a/drivers/misc/pca9551_led.c b/drivers/misc/pca9551_led.c
index d4034f6..4da0319 100644
--- a/drivers/misc/pca9551_led.c
+++ b/drivers/misc/pca9551_led.c
@@ -116,8 +116,12 @@ static int pca9551_led_set_blink_rate(int idx, struct pca9551_blink_rate rate)
}
/*
- * Functions referenced by cmd_led.c
+ * Functions referenced by cmd_led.c or status_led.c
*/
+void __led_init(led_id_t id, int state)
+{
+}
+
void __led_set(led_id_t mask, int state)
{
if (state == STATUS_LED_OFF)
diff --git a/drivers/misc/status_led.c b/drivers/misc/status_led.c
index 9869d98..31e8831 100644
--- a/drivers/misc/status_led.c
+++ b/drivers/misc/status_led.c
@@ -73,7 +73,7 @@ led_dev_t led_dev[] = {
static int status_led_init_done = 0;
-static void status_led_init (void)
+void status_led_init(void)
{
led_dev_t *ld;
int i;