summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTrent Piepho <tpiepho@kymetacorp.com>2015-11-10 22:27:23 +0000
committerSascha Hauer <s.hauer@pengutronix.de>2015-11-11 09:05:20 +0100
commit48aecb409dcbff1d13008de72a2c42af8069aec6 (patch)
tree30e633ad276ebd96d2335a0ffad738664e01e82a
parentd9c2cfd534d2ebda662f2656b2e8076b255b4987 (diff)
downloadbarebox-48aecb409dcbff1d13008de72a2c42af8069aec6.tar.gz
barebox-48aecb409dcbff1d13008de72a2c42af8069aec6.tar.xz
firmware: socfpga: Add parameter "programmed" to fpgamgr driver
This boolean parameter tells you if the FPGA is programmed or not. It can be accessed from the shell as "$fpga.programmed". One could use this to not program the FPGA if it's already programmed. There is an annoying limitation of the way barebox puts parameters into the shell env: it requires they have no periods in the device name. It uses the first period to divide the variable name into a device and parameter name, which doesn't work correctly if the device name has a period in it. Since the names of any devices created from the OF device tree have a period in them, this is a problem. So what I did here was create a new device. Its parent will be the OF device for the fpgamgr and it will in turn be the parent of the firmware cdev. Previously the cdev's parent was the OF device. This device won't have period in the name and the parameter is attached to it. Even without the period limitation, doing this gives a nicer name "fpga.programmed" instead of "ff706000.fpgamgr.programmed". The fpgamgr code had a pointer to the OF device in its private state. I changed this to be a struct for the new "fpga" device, which is then used in all the places the former pointer was (nothing but dev_dbg, etc. calls). Signed-off-by: Trent Piepho <tpiepho@kymetacorp.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--drivers/firmware/socfpga.c46
1 files changed, 35 insertions, 11 deletions
diff --git a/drivers/firmware/socfpga.c b/drivers/firmware/socfpga.c
index 14a7a14c64..159644bbfb 100644
--- a/drivers/firmware/socfpga.c
+++ b/drivers/firmware/socfpga.c
@@ -79,9 +79,10 @@
struct fpgamgr {
struct firmware_handler fh;
- struct device_d *dev;
+ struct device_d dev;
void __iomem *regs;
void __iomem *regs_data;
+ int programmed;
};
/* Get the FPGA mode */
@@ -303,12 +304,12 @@ static int fpgamgr_program_start(struct firmware_handler *fh)
/* unmap the bridges from NIC-301 */
writel(0x1, CYCLONE5_L3REGS_ADDRESS);
- dev_dbg(mgr->dev, "start programming...\n");
+ dev_dbg(&mgr->dev, "start programming...\n");
/* initialize the FPGA Manager */
status = fpgamgr_program_init(mgr);
if (status) {
- dev_err(mgr->dev, "program init failed with: %s\n",
+ dev_err(&mgr->dev, "program init failed with: %s\n",
strerror(-status));
return status;
}
@@ -356,27 +357,27 @@ static int fpgamgr_program_finish(struct firmware_handler *fh)
/* Ensure the FPGA entering config done */
status = fpgamgr_program_poll_cd(mgr);
if (status) {
- dev_err(mgr->dev, "poll for config done failed with: %s\n",
+ dev_err(&mgr->dev, "poll for config done failed with: %s\n",
strerror(-status));
return status;
}
- dev_dbg(mgr->dev, "waiting for init phase...\n");
+ dev_dbg(&mgr->dev, "waiting for init phase...\n");
/* Ensure the FPGA entering init phase */
status = fpgamgr_program_poll_initphase(mgr);
if (status) {
- dev_err(mgr->dev, "poll for init phase failed with: %s\n",
+ dev_err(&mgr->dev, "poll for init phase failed with: %s\n",
strerror(-status));
return status;
}
- dev_dbg(mgr->dev, "waiting for user mode...\n");
+ dev_dbg(&mgr->dev, "waiting for user mode...\n");
/* Ensure the FPGA entering user mode */
status = fpgamgr_program_poll_usermode(mgr);
if (status) {
- dev_err(mgr->dev, "poll for user mode with: %s\n",
+ dev_err(&mgr->dev, "poll for user mode with: %s\n",
strerror(-status));
return status;
}
@@ -384,12 +385,21 @@ static int fpgamgr_program_finish(struct firmware_handler *fh)
return 0;
}
+/* Get current programmed state of fpga and put in "programmed" parameter */
+static int programmed_get(struct param_d *p, void *priv)
+{
+ struct fpgamgr *mgr = priv;
+ mgr->programmed = fpgamgr_get_mode(mgr) == FPGAMGRREGS_MODE_USERMODE;
+ return 0;
+}
+
static int fpgamgr_probe(struct device_d *dev)
{
struct fpgamgr *mgr;
struct firmware_handler *fh;
const char *alias = of_alias_get(dev->device_node);
const char *model = NULL;
+ struct param_d *p;
int ret;
dev_dbg(dev, "Probing FPGA firmware programmer\n");
@@ -422,17 +432,31 @@ static int fpgamgr_probe(struct device_d *dev)
fh->model = xstrdup(model);
fh->dev = dev;
- mgr->dev = dev;
-
dev_dbg(dev, "Registering FPGA firmware programmer\n");
+ mgr->dev.id = DEVICE_ID_SINGLE;
+ strcpy(mgr->dev.name, "fpga");
+ mgr->dev.parent = dev;
+ ret = register_device(&mgr->dev);
+ if (ret)
+ goto out;
+
+ p = dev_add_param_bool(&mgr->dev, "programmed", NULL, programmed_get, &mgr->programmed, mgr);
+ if (IS_ERR(p)) {
+ ret = PTR_ERR(p);
+ goto out_unreg;
+ }
+
+ fh->dev = &mgr->dev;
ret = firmwaremgr_register(fh);
if (ret != 0) {
free(mgr);
- goto out;
+ goto out_unreg;
}
return 0;
+out_unreg:
+ unregister_device(&mgr->dev);
out:
free(fh->id);
free(mgr);