[PATCH v7 2/3] ARM: bcm2835: Add the Raspberry Pi firmware driver
This gives us a function for making mailbox property channel requests of the firmware, which is most notable in that it will let us get and set clock rates. Signed-off-by: Eric Anholt Acked-by: Stephen Warren --- v2: Drop power-domains stuff for now since we don't have the driver core support to make it useful. Move to drivers/firmware/. Capitalize the enums. De-global the firmware variable. Use the firmware device to allocate our DMA buffer, so that the dma-ranges DT property gets respected. Simplify the property tag transaction interface even more, leaving a multi-tag interface still available. For conciseness, rename "raspberrypi" to "rpi" on all functions/enums/structs, and the "firmware" variable to "fw". Print when the driver is probed successfully, since debugging -EPROBE_DEFER handling is such a big part of bcm2835 development. Drop -EBUSY mailbox handling since the mailbox core has been fixed to return -EPROBE_DEFER in -next. v3: Use kernel-doc style for big comments (from Noralf), drop stale comment, use "dev" when freeing DMA as well. v4: Move description comment into copyright comment, drop a dead initialization of "ret", and print the firmware revision at probe time. v5: Rename the compatible to "raspberrypi,bcm2835-firmware", move include to not say "property", add functions to get struct rpi_firmware from the device_node and put when done, make property functions take the rpi_firmware instead and never return -EPROBE_DEFER, put the driver under its own RASPBERRYPI_FIRMWARE Kconfig. v6: Drop the try_module_get/module_put stuff, since all clients will be referencing our symbols in order to call those functions, anyway. Fix the kerneldoc comments for the changes in v5. drivers/firmware/Kconfig | 7 + drivers/firmware/Makefile | 1 + drivers/firmware/raspberrypi.c | 260 + include/soc/bcm2835/raspberrypi-firmware.h | 115 + 4 files changed, 383 insertions(+) create mode 100644 drivers/firmware/raspberrypi.c create mode 100644 include/soc/bcm2835/raspberrypi-firmware.h diff --git a/drivers/firmware/Kconfig b/drivers/firmware/Kconfig index 99c69a3..1faf511 100644 --- a/drivers/firmware/Kconfig +++ b/drivers/firmware/Kconfig @@ -136,6 +136,13 @@ config QCOM_SCM bool depends on ARM || ARM64 +config RASPBERRYPI_FIRMWARE + tristate "Raspberry Pi Firmware Driver" + depends on BCM2835_MBOX + help + This option enables support for communicating with the firmware on the + Raspberry Pi. + source "drivers/firmware/broadcom/Kconfig" source "drivers/firmware/google/Kconfig" source "drivers/firmware/efi/Kconfig" diff --git a/drivers/firmware/Makefile b/drivers/firmware/Makefile index 4a4b897..95efc8f 100644 --- a/drivers/firmware/Makefile +++ b/drivers/firmware/Makefile @@ -14,6 +14,7 @@ obj-$(CONFIG_FIRMWARE_MEMMAP) += memmap.o obj-$(CONFIG_QCOM_SCM) += qcom_scm.o obj-$(CONFIG_QCOM_SCM) += qcom_scm-32.o CFLAGS_qcom_scm-32.o :=$(call as-instr,.arch_extension sec,-DREQUIRES_SEC=1) +obj-$(CONFIG_RASPBERRYPI_FIRMWARE) += raspberrypi.o obj-y += broadcom/ obj-$(CONFIG_GOOGLE_FIRMWARE) += google/ diff --git a/drivers/firmware/raspberrypi.c b/drivers/firmware/raspberrypi.c new file mode 100644 index 000..dd506cd3 --- /dev/null +++ b/drivers/firmware/raspberrypi.c @@ -0,0 +1,260 @@ +/* + * Defines interfaces for interacting wtih the Raspberry Pi firmware's + * property channel. + * + * Copyright © 2015 Broadcom + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#include +#include +#include +#include +#include +#include + +#define MBOX_MSG(chan, data28) (((data28) & ~0xf) | ((chan) & 0xf)) +#define MBOX_CHAN(msg) ((msg) & 0xf) +#define MBOX_DATA28(msg) ((msg) & ~0xf) +#define MBOX_CHAN_PROPERTY 8 + +struct rpi_firmware { + struct mbox_client cl; + struct mbox_chan *chan; /* The property channel. */ + struct completion c; + u32 enabled; +}; + +static DEFINE_MUTEX(transaction_lock); + +static void response_callback(struct mbox_client *cl, void *msg) +{ + struct rpi_firmware *fw = container_of(cl, struct rpi_firmware, cl); + complete(>c); +} + +/* + * Sends a request to the firmware through the BCM2835 mailbox driver, + * and synchronously waits for the reply. + */ +static int +rpi_firmware_transaction(struct rpi_firmware *fw, u32 chan, u32 data) +{ + u32 message = MBOX_MSG(chan, data); + int ret; + + WARN_ON(data & 0xf); + + mutex_lock(_lock); + reinit_completion(>c); + ret = mbox_send_message(fw->chan, ); + if (ret >= 0) { +
[PATCH v7 2/3] ARM: bcm2835: Add the Raspberry Pi firmware driver
This gives us a function for making mailbox property channel requests of the firmware, which is most notable in that it will let us get and set clock rates. Signed-off-by: Eric Anholt e...@anholt.net Acked-by: Stephen Warren swar...@wwwdotorg.org --- v2: Drop power-domains stuff for now since we don't have the driver core support to make it useful. Move to drivers/firmware/. Capitalize the enums. De-global the firmware variable. Use the firmware device to allocate our DMA buffer, so that the dma-ranges DT property gets respected. Simplify the property tag transaction interface even more, leaving a multi-tag interface still available. For conciseness, rename raspberrypi to rpi on all functions/enums/structs, and the firmware variable to fw. Print when the driver is probed successfully, since debugging -EPROBE_DEFER handling is such a big part of bcm2835 development. Drop -EBUSY mailbox handling since the mailbox core has been fixed to return -EPROBE_DEFER in -next. v3: Use kernel-doc style for big comments (from Noralf), drop stale comment, use dev when freeing DMA as well. v4: Move description comment into copyright comment, drop a dead initialization of ret, and print the firmware revision at probe time. v5: Rename the compatible to raspberrypi,bcm2835-firmware, move include to not say property, add functions to get struct rpi_firmware from the device_node and put when done, make property functions take the rpi_firmware instead and never return -EPROBE_DEFER, put the driver under its own RASPBERRYPI_FIRMWARE Kconfig. v6: Drop the try_module_get/module_put stuff, since all clients will be referencing our symbols in order to call those functions, anyway. Fix the kerneldoc comments for the changes in v5. drivers/firmware/Kconfig | 7 + drivers/firmware/Makefile | 1 + drivers/firmware/raspberrypi.c | 260 + include/soc/bcm2835/raspberrypi-firmware.h | 115 + 4 files changed, 383 insertions(+) create mode 100644 drivers/firmware/raspberrypi.c create mode 100644 include/soc/bcm2835/raspberrypi-firmware.h diff --git a/drivers/firmware/Kconfig b/drivers/firmware/Kconfig index 99c69a3..1faf511 100644 --- a/drivers/firmware/Kconfig +++ b/drivers/firmware/Kconfig @@ -136,6 +136,13 @@ config QCOM_SCM bool depends on ARM || ARM64 +config RASPBERRYPI_FIRMWARE + tristate Raspberry Pi Firmware Driver + depends on BCM2835_MBOX + help + This option enables support for communicating with the firmware on the + Raspberry Pi. + source drivers/firmware/broadcom/Kconfig source drivers/firmware/google/Kconfig source drivers/firmware/efi/Kconfig diff --git a/drivers/firmware/Makefile b/drivers/firmware/Makefile index 4a4b897..95efc8f 100644 --- a/drivers/firmware/Makefile +++ b/drivers/firmware/Makefile @@ -14,6 +14,7 @@ obj-$(CONFIG_FIRMWARE_MEMMAP) += memmap.o obj-$(CONFIG_QCOM_SCM) += qcom_scm.o obj-$(CONFIG_QCOM_SCM) += qcom_scm-32.o CFLAGS_qcom_scm-32.o :=$(call as-instr,.arch_extension sec,-DREQUIRES_SEC=1) +obj-$(CONFIG_RASPBERRYPI_FIRMWARE) += raspberrypi.o obj-y += broadcom/ obj-$(CONFIG_GOOGLE_FIRMWARE) += google/ diff --git a/drivers/firmware/raspberrypi.c b/drivers/firmware/raspberrypi.c new file mode 100644 index 000..dd506cd3 --- /dev/null +++ b/drivers/firmware/raspberrypi.c @@ -0,0 +1,260 @@ +/* + * Defines interfaces for interacting wtih the Raspberry Pi firmware's + * property channel. + * + * Copyright © 2015 Broadcom + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#include linux/dma-mapping.h +#include linux/mailbox_client.h +#include linux/module.h +#include linux/of_platform.h +#include linux/platform_device.h +#include soc/bcm2835/raspberrypi-firmware.h + +#define MBOX_MSG(chan, data28) (((data28) ~0xf) | ((chan) 0xf)) +#define MBOX_CHAN(msg) ((msg) 0xf) +#define MBOX_DATA28(msg) ((msg) ~0xf) +#define MBOX_CHAN_PROPERTY 8 + +struct rpi_firmware { + struct mbox_client cl; + struct mbox_chan *chan; /* The property channel. */ + struct completion c; + u32 enabled; +}; + +static DEFINE_MUTEX(transaction_lock); + +static void response_callback(struct mbox_client *cl, void *msg) +{ + struct rpi_firmware *fw = container_of(cl, struct rpi_firmware, cl); + complete(fw-c); +} + +/* + * Sends a request to the firmware through the BCM2835 mailbox driver, + * and synchronously waits for the reply. + */ +static int +rpi_firmware_transaction(struct rpi_firmware *fw, u32 chan, u32 data) +{ + u32 message = MBOX_MSG(chan, data); + int ret; + + WARN_ON(data 0xf); + +
Re: [PATCH v7 2/3] ARM: bcm2835: Add the Raspberry Pi firmware driver
On 06/05/2015 01:21 PM, Lee Jones wrote: On Thu, 04 Jun 2015, Stephen Warren wrote: On 06/04/2015 02:11 PM, Eric Anholt wrote: This gives us a function for making mailbox property channel requests of the firmware, which is most notable in that it will let us get and set clock rates. Acked-by: Stephen Warren Does anyone know how drivers/firmware/ is managed? I don't seem to be able to find a maintainer/supporter listed in MAINTAINERS. git log implies lots of different committers. I'd suggest send it through arm-soc with the rest of the series. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH v7 2/3] ARM: bcm2835: Add the Raspberry Pi firmware driver
On Thu, 04 Jun 2015, Stephen Warren wrote: > On 06/04/2015 02:11 PM, Eric Anholt wrote: > > This gives us a function for making mailbox property channel requests > > of the firmware, which is most notable in that it will let us get and > > set clock rates. > > Acked-by: Stephen Warren Does anyone know how drivers/firmware/ is managed? I don't seem to be able to find a maintainer/supporter listed in MAINTAINERS. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH v7 2/3] ARM: bcm2835: Add the Raspberry Pi firmware driver
On Thu, 04 Jun 2015, Stephen Warren wrote: On 06/04/2015 02:11 PM, Eric Anholt wrote: This gives us a function for making mailbox property channel requests of the firmware, which is most notable in that it will let us get and set clock rates. Acked-by: Stephen Warren swar...@wwwdotorg.org Does anyone know how drivers/firmware/ is managed? I don't seem to be able to find a maintainer/supporter listed in MAINTAINERS. -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH v7 2/3] ARM: bcm2835: Add the Raspberry Pi firmware driver
On 06/05/2015 01:21 PM, Lee Jones wrote: On Thu, 04 Jun 2015, Stephen Warren wrote: On 06/04/2015 02:11 PM, Eric Anholt wrote: This gives us a function for making mailbox property channel requests of the firmware, which is most notable in that it will let us get and set clock rates. Acked-by: Stephen Warren swar...@wwwdotorg.org Does anyone know how drivers/firmware/ is managed? I don't seem to be able to find a maintainer/supporter listed in MAINTAINERS. git log implies lots of different committers. I'd suggest send it through arm-soc with the rest of the series. -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH v7 2/3] ARM: bcm2835: Add the Raspberry Pi firmware driver
On 06/04/2015 02:11 PM, Eric Anholt wrote: > This gives us a function for making mailbox property channel requests > of the firmware, which is most notable in that it will let us get and > set clock rates. Acked-by: Stephen Warren -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[PATCH v7 2/3] ARM: bcm2835: Add the Raspberry Pi firmware driver
This gives us a function for making mailbox property channel requests of the firmware, which is most notable in that it will let us get and set clock rates. Signed-off-by: Eric Anholt --- v2: Drop power-domains stuff for now since we don't have the driver core support to make it useful. Move to drivers/firmware/. Capitalize the enums. De-global the firmware variable. Use the firmware device to allocate our DMA buffer, so that the dma-ranges DT property gets respected. Simplify the property tag transaction interface even more, leaving a multi-tag interface still available. For conciseness, rename "raspberrypi" to "rpi" on all functions/enums/structs, and the "firmware" variable to "fw". Print when the driver is probed successfully, since debugging -EPROBE_DEFER handling is such a big part of bcm2835 development. Drop -EBUSY mailbox handling since the mailbox core has been fixed to return -EPROBE_DEFER in -next. v3: Use kernel-doc style for big comments (from Noralf), drop stale comment, use "dev" when freeing DMA as well. v4: Move description comment into copyright comment, drop a dead initialization of "ret", and print the firmware revision at probe time. v5: Rename the compatible to "raspberrypi,bcm2835-firmware", move include to not say "property", add functions to get struct rpi_firmware from the device_node and put when done, make property functions take the rpi_firmware instead and never return -EPROBE_DEFER, put the driver under its own RASPBERRYPI_FIRMWARE Kconfig. v6: Drop the try_module_get/module_put stuff, since all clients will be referencing our symbols in order to call those functions, anyway. Fix the kerneldoc comments for the changes in v5. drivers/firmware/Kconfig | 7 + drivers/firmware/Makefile | 1 + drivers/firmware/raspberrypi.c | 260 + include/soc/bcm2835/raspberrypi-firmware.h | 115 + 4 files changed, 383 insertions(+) create mode 100644 drivers/firmware/raspberrypi.c create mode 100644 include/soc/bcm2835/raspberrypi-firmware.h diff --git a/drivers/firmware/Kconfig b/drivers/firmware/Kconfig index 6517132..564aa5b 100644 --- a/drivers/firmware/Kconfig +++ b/drivers/firmware/Kconfig @@ -136,6 +136,13 @@ config QCOM_SCM bool depends on ARM || ARM64 +config RASPBERRYPI_FIRMWARE + tristate "Raspberry Pi Firmware Driver" + depends on BCM2835_MBOX + help + This option enables support for communicating with the firmware on the + Raspberry Pi. + source "drivers/firmware/google/Kconfig" source "drivers/firmware/efi/Kconfig" diff --git a/drivers/firmware/Makefile b/drivers/firmware/Makefile index 3fdd391..ee101a2 100644 --- a/drivers/firmware/Makefile +++ b/drivers/firmware/Makefile @@ -13,6 +13,7 @@ obj-$(CONFIG_ISCSI_IBFT) += iscsi_ibft.o obj-$(CONFIG_FIRMWARE_MEMMAP) += memmap.o obj-$(CONFIG_QCOM_SCM) += qcom_scm.o CFLAGS_qcom_scm.o :=$(call as-instr,.arch_extension sec,-DREQUIRES_SEC=1) +obj-$(CONFIG_RASPBERRYPI_FIRMWARE) += raspberrypi.o obj-$(CONFIG_GOOGLE_FIRMWARE) += google/ obj-$(CONFIG_EFI) += efi/ diff --git a/drivers/firmware/raspberrypi.c b/drivers/firmware/raspberrypi.c new file mode 100644 index 000..dd506cd --- /dev/null +++ b/drivers/firmware/raspberrypi.c @@ -0,0 +1,260 @@ +/* + * Defines interfaces for interacting wtih the Raspberry Pi firmware's + * property channel. + * + * Copyright © 2015 Broadcom + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#include +#include +#include +#include +#include +#include + +#define MBOX_MSG(chan, data28) (((data28) & ~0xf) | ((chan) & 0xf)) +#define MBOX_CHAN(msg) ((msg) & 0xf) +#define MBOX_DATA28(msg) ((msg) & ~0xf) +#define MBOX_CHAN_PROPERTY 8 + +struct rpi_firmware { + struct mbox_client cl; + struct mbox_chan *chan; /* The property channel. */ + struct completion c; + u32 enabled; +}; + +static DEFINE_MUTEX(transaction_lock); + +static void response_callback(struct mbox_client *cl, void *msg) +{ + struct rpi_firmware *fw = container_of(cl, struct rpi_firmware, cl); + complete(>c); +} + +/* + * Sends a request to the firmware through the BCM2835 mailbox driver, + * and synchronously waits for the reply. + */ +static int +rpi_firmware_transaction(struct rpi_firmware *fw, u32 chan, u32 data) +{ + u32 message = MBOX_MSG(chan, data); + int ret; + + WARN_ON(data & 0xf); + + mutex_lock(_lock); + reinit_completion(>c); + ret = mbox_send_message(fw->chan, ); + if (ret >= 0) { + wait_for_completion(>c); + ret = 0; + } else { +
Re: [PATCH v7 2/3] ARM: bcm2835: Add the Raspberry Pi firmware driver
On 06/04/2015 02:11 PM, Eric Anholt wrote: This gives us a function for making mailbox property channel requests of the firmware, which is most notable in that it will let us get and set clock rates. Acked-by: Stephen Warren swar...@wwwdotorg.org -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[PATCH v7 2/3] ARM: bcm2835: Add the Raspberry Pi firmware driver
This gives us a function for making mailbox property channel requests of the firmware, which is most notable in that it will let us get and set clock rates. Signed-off-by: Eric Anholt e...@anholt.net --- v2: Drop power-domains stuff for now since we don't have the driver core support to make it useful. Move to drivers/firmware/. Capitalize the enums. De-global the firmware variable. Use the firmware device to allocate our DMA buffer, so that the dma-ranges DT property gets respected. Simplify the property tag transaction interface even more, leaving a multi-tag interface still available. For conciseness, rename raspberrypi to rpi on all functions/enums/structs, and the firmware variable to fw. Print when the driver is probed successfully, since debugging -EPROBE_DEFER handling is such a big part of bcm2835 development. Drop -EBUSY mailbox handling since the mailbox core has been fixed to return -EPROBE_DEFER in -next. v3: Use kernel-doc style for big comments (from Noralf), drop stale comment, use dev when freeing DMA as well. v4: Move description comment into copyright comment, drop a dead initialization of ret, and print the firmware revision at probe time. v5: Rename the compatible to raspberrypi,bcm2835-firmware, move include to not say property, add functions to get struct rpi_firmware from the device_node and put when done, make property functions take the rpi_firmware instead and never return -EPROBE_DEFER, put the driver under its own RASPBERRYPI_FIRMWARE Kconfig. v6: Drop the try_module_get/module_put stuff, since all clients will be referencing our symbols in order to call those functions, anyway. Fix the kerneldoc comments for the changes in v5. drivers/firmware/Kconfig | 7 + drivers/firmware/Makefile | 1 + drivers/firmware/raspberrypi.c | 260 + include/soc/bcm2835/raspberrypi-firmware.h | 115 + 4 files changed, 383 insertions(+) create mode 100644 drivers/firmware/raspberrypi.c create mode 100644 include/soc/bcm2835/raspberrypi-firmware.h diff --git a/drivers/firmware/Kconfig b/drivers/firmware/Kconfig index 6517132..564aa5b 100644 --- a/drivers/firmware/Kconfig +++ b/drivers/firmware/Kconfig @@ -136,6 +136,13 @@ config QCOM_SCM bool depends on ARM || ARM64 +config RASPBERRYPI_FIRMWARE + tristate Raspberry Pi Firmware Driver + depends on BCM2835_MBOX + help + This option enables support for communicating with the firmware on the + Raspberry Pi. + source drivers/firmware/google/Kconfig source drivers/firmware/efi/Kconfig diff --git a/drivers/firmware/Makefile b/drivers/firmware/Makefile index 3fdd391..ee101a2 100644 --- a/drivers/firmware/Makefile +++ b/drivers/firmware/Makefile @@ -13,6 +13,7 @@ obj-$(CONFIG_ISCSI_IBFT) += iscsi_ibft.o obj-$(CONFIG_FIRMWARE_MEMMAP) += memmap.o obj-$(CONFIG_QCOM_SCM) += qcom_scm.o CFLAGS_qcom_scm.o :=$(call as-instr,.arch_extension sec,-DREQUIRES_SEC=1) +obj-$(CONFIG_RASPBERRYPI_FIRMWARE) += raspberrypi.o obj-$(CONFIG_GOOGLE_FIRMWARE) += google/ obj-$(CONFIG_EFI) += efi/ diff --git a/drivers/firmware/raspberrypi.c b/drivers/firmware/raspberrypi.c new file mode 100644 index 000..dd506cd --- /dev/null +++ b/drivers/firmware/raspberrypi.c @@ -0,0 +1,260 @@ +/* + * Defines interfaces for interacting wtih the Raspberry Pi firmware's + * property channel. + * + * Copyright © 2015 Broadcom + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#include linux/dma-mapping.h +#include linux/mailbox_client.h +#include linux/module.h +#include linux/of_platform.h +#include linux/platform_device.h +#include soc/bcm2835/raspberrypi-firmware.h + +#define MBOX_MSG(chan, data28) (((data28) ~0xf) | ((chan) 0xf)) +#define MBOX_CHAN(msg) ((msg) 0xf) +#define MBOX_DATA28(msg) ((msg) ~0xf) +#define MBOX_CHAN_PROPERTY 8 + +struct rpi_firmware { + struct mbox_client cl; + struct mbox_chan *chan; /* The property channel. */ + struct completion c; + u32 enabled; +}; + +static DEFINE_MUTEX(transaction_lock); + +static void response_callback(struct mbox_client *cl, void *msg) +{ + struct rpi_firmware *fw = container_of(cl, struct rpi_firmware, cl); + complete(fw-c); +} + +/* + * Sends a request to the firmware through the BCM2835 mailbox driver, + * and synchronously waits for the reply. + */ +static int +rpi_firmware_transaction(struct rpi_firmware *fw, u32 chan, u32 data) +{ + u32 message = MBOX_MSG(chan, data); + int ret; + + WARN_ON(data 0xf); + + mutex_lock(transaction_lock); + reinit_completion(fw-c); + ret =