Mike Frysinger | c8f36dc | 2009-05-14 14:55:50 +0000 | [diff] [blame] | 1 | /* Load firmware into Core B on a BF561 |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 2 | * |
Paul Gortmaker | 2d4d3b5 | 2016-10-29 16:38:42 -0400 | [diff] [blame] | 3 | * Author: Bas Vermeulen <bvermeul@blackstar.xs4all.nl> |
| 4 | * |
Mike Frysinger | c8f36dc | 2009-05-14 14:55:50 +0000 | [diff] [blame] | 5 | * Copyright 2004-2009 Analog Devices Inc. |
| 6 | * Licensed under the GPL-2 or later. |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 7 | */ |
| 8 | |
Mike Frysinger | c8f36dc | 2009-05-14 14:55:50 +0000 | [diff] [blame] | 9 | /* The Core B reset func requires code in the application that is loaded into |
| 10 | * Core B. In order to reset, the application needs to install an interrupt |
| 11 | * handler for Supplemental Interrupt 0, that sets RETI to 0xff600000 and |
| 12 | * writes bit 11 of SICB_SYSCR when bit 5 of SICA_SYSCR is 0. This causes Core |
| 13 | * B to stall when Supplemental Interrupt 0 is set, and will reset PC to |
| 14 | * 0xff600000 when COREB_SRAM_INIT is cleared. |
| 15 | */ |
| 16 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 17 | #include <linux/device.h> |
Enrik Berkhan | 76a7f40 | 2007-12-24 19:51:31 +0800 | [diff] [blame] | 18 | #include <linux/fs.h> |
Paul Gortmaker | 2d4d3b5 | 2016-10-29 16:38:42 -0400 | [diff] [blame] | 19 | #include <linux/init.h> |
Mike Frysinger | c8f36dc | 2009-05-14 14:55:50 +0000 | [diff] [blame] | 20 | #include <linux/kernel.h> |
| 21 | #include <linux/miscdevice.h> |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 22 | |
Mike Frysinger | 7696eec | 2010-10-06 06:33:08 +0000 | [diff] [blame] | 23 | #define CMD_COREB_START _IO('b', 0) |
| 24 | #define CMD_COREB_STOP _IO('b', 1) |
| 25 | #define CMD_COREB_RESET _IO('b', 2) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 26 | |
Mike Frysinger | 17a1b5e | 2009-10-13 12:50:05 +0000 | [diff] [blame] | 27 | static long |
| 28 | coreb_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 29 | { |
Mike Frysinger | c8f36dc | 2009-05-14 14:55:50 +0000 | [diff] [blame] | 30 | int ret = 0; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 31 | |
Mike Frysinger | c8f36dc | 2009-05-14 14:55:50 +0000 | [diff] [blame] | 32 | switch (cmd) { |
| 33 | case CMD_COREB_START: |
Mike Frysinger | 39c9996 | 2010-10-19 18:44:23 +0000 | [diff] [blame] | 34 | bfin_write_SYSCR(bfin_read_SYSCR() & ~0x0020); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 35 | break; |
Mike Frysinger | c8f36dc | 2009-05-14 14:55:50 +0000 | [diff] [blame] | 36 | case CMD_COREB_STOP: |
Mike Frysinger | 39c9996 | 2010-10-19 18:44:23 +0000 | [diff] [blame] | 37 | bfin_write_SYSCR(bfin_read_SYSCR() | 0x0020); |
Mike Frysinger | c8f36dc | 2009-05-14 14:55:50 +0000 | [diff] [blame] | 38 | bfin_write_SICB_SYSCR(bfin_read_SICB_SYSCR() | 0x0080); |
| 39 | break; |
| 40 | case CMD_COREB_RESET: |
| 41 | bfin_write_SICB_SYSCR(bfin_read_SICB_SYSCR() | 0x0080); |
| 42 | break; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 43 | default: |
| 44 | ret = -EINVAL; |
Mike Frysinger | c8f36dc | 2009-05-14 14:55:50 +0000 | [diff] [blame] | 45 | break; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 46 | } |
Mike Frysinger | c8f36dc | 2009-05-14 14:55:50 +0000 | [diff] [blame] | 47 | |
| 48 | CSYNC(); |
| 49 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 50 | return ret; |
| 51 | } |
| 52 | |
Alexey Dobriyan | 828c095 | 2009-10-01 15:43:56 -0700 | [diff] [blame] | 53 | static const struct file_operations coreb_fops = { |
Mike Frysinger | 17a1b5e | 2009-10-13 12:50:05 +0000 | [diff] [blame] | 54 | .owner = THIS_MODULE, |
| 55 | .unlocked_ioctl = coreb_ioctl, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 56 | .llseek = noop_llseek, |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 57 | }; |
| 58 | |
| 59 | static struct miscdevice coreb_dev = { |
Mike Frysinger | c8f36dc | 2009-05-14 14:55:50 +0000 | [diff] [blame] | 60 | .minor = MISC_DYNAMIC_MINOR, |
| 61 | .name = "coreb", |
| 62 | .fops = &coreb_fops, |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 63 | }; |
Paul Gortmaker | 2d4d3b5 | 2016-10-29 16:38:42 -0400 | [diff] [blame] | 64 | builtin_misc_device(coreb_dev); |