From 4d4edcd3aae0e9c262edda16ec5caf4fae793ba4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Noralf=20Tr=C3=B8nnes?= Date: Sat, 23 May 2015 23:30:36 +0200 Subject: [PATCH] BCM270x: Move power module MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Make the power module available on ARCH_BCM2835 by moving it. The module turns on USB power making it possible to boot ARCH_BCM2835 directly with the VC bootloader. Signed-off-by: Noralf Trønnes --- arch/arm/mach-bcm2708/Makefile | 2 +- arch/arm/mach-bcm2708/include/mach/power.h | 26 --- arch/arm/mach-bcm2709/Makefile | 2 +- .../arm/mach-bcm2709/include/mach/arm_power.h | 62 ------ arch/arm/mach-bcm2709/include/mach/power.h | 26 --- arch/arm/mach-bcm2709/power.c | 199 ------------------ drivers/soc/Kconfig | 1 + drivers/soc/Makefile | 1 + drivers/soc/bcm2835/Kconfig | 9 + drivers/soc/bcm2835/Makefile | 1 + .../soc/bcm2835/bcm2708-power.c | 3 +- .../soc/bcm2835/power.h | 29 ++- 12 files changed, 29 insertions(+), 332 deletions(-) delete mode 100644 arch/arm/mach-bcm2708/include/mach/power.h delete mode 100644 arch/arm/mach-bcm2709/include/mach/arm_power.h delete mode 100644 arch/arm/mach-bcm2709/include/mach/power.h delete mode 100644 arch/arm/mach-bcm2709/power.c create mode 100644 drivers/soc/bcm2835/Kconfig create mode 100644 drivers/soc/bcm2835/Makefile rename arch/arm/mach-bcm2708/power.c => drivers/soc/bcm2835/bcm2708-power.c (98%) rename arch/arm/mach-bcm2708/include/mach/arm_power.h => include/soc/bcm2835/power.h (61%) diff --git a/arch/arm/mach-bcm2708/Makefile b/arch/arm/mach-bcm2708/Makefile index c1e7d41d8f4c9..5552ae806e99b 100644 --- a/arch/arm/mach-bcm2708/Makefile +++ b/arch/arm/mach-bcm2708/Makefile @@ -2,6 +2,6 @@ # Makefile for the linux kernel. # -obj-$(CONFIG_MACH_BCM2708) += bcm2708.o armctrl.o power.o +obj-$(CONFIG_MACH_BCM2708) += bcm2708.o armctrl.o obj-$(CONFIG_BCM2708_GPIO) += bcm2708_gpio.o obj-$(CONFIG_BCM2708_VCMEM) += vc_mem.o diff --git a/arch/arm/mach-bcm2708/include/mach/power.h b/arch/arm/mach-bcm2708/include/mach/power.h deleted file mode 100644 index 52b3b02363b6f..0000000000000 --- a/arch/arm/mach-bcm2708/include/mach/power.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * linux/arch/arm/mach-bcm2708/power.h - * - * Copyright (C) 2010 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. - * - * This device provides a shared mechanism for controlling the power to - * VideoCore subsystems. - */ - -#ifndef _MACH_BCM2708_POWER_H -#define _MACH_BCM2708_POWER_H - -#include -#include - -typedef unsigned int BCM_POWER_HANDLE_T; - -extern int bcm_power_open(BCM_POWER_HANDLE_T *handle); -extern int bcm_power_request(BCM_POWER_HANDLE_T handle, uint32_t request); -extern int bcm_power_close(BCM_POWER_HANDLE_T handle); - -#endif diff --git a/arch/arm/mach-bcm2709/Makefile b/arch/arm/mach-bcm2709/Makefile index 77b8429450500..706116f77c899 100644 --- a/arch/arm/mach-bcm2709/Makefile +++ b/arch/arm/mach-bcm2709/Makefile @@ -2,6 +2,6 @@ # Makefile for the linux kernel. # -obj-$(CONFIG_MACH_BCM2709) += bcm2709.o armctrl.o power.o +obj-$(CONFIG_MACH_BCM2709) += bcm2709.o armctrl.o obj-$(CONFIG_BCM2708_GPIO) += bcm2708_gpio.o obj-$(CONFIG_BCM2708_VCMEM) += vc_mem.o diff --git a/arch/arm/mach-bcm2709/include/mach/arm_power.h b/arch/arm/mach-bcm2709/include/mach/arm_power.h deleted file mode 100644 index d3bf2457ede0a..0000000000000 --- a/arch/arm/mach-bcm2709/include/mach/arm_power.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * linux/arch/arm/mach-bcm2708/include/mach/arm_power.h - * - * Copyright (C) 2010 Broadcom - * - * 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; either version 2 of the License, or - * (at your option) any later version. - * - * 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef _ARM_POWER_H -#define _ARM_POWER_H - -/* Use meaningful names on each side */ -#ifdef __VIDEOCORE__ -#define PREFIX(x) ARM_##x -#else -#define PREFIX(x) BCM_##x -#endif - -enum { - PREFIX(POWER_SDCARD_BIT), - PREFIX(POWER_UART_BIT), - PREFIX(POWER_MINIUART_BIT), - PREFIX(POWER_USB_BIT), - PREFIX(POWER_I2C0_BIT), - PREFIX(POWER_I2C1_BIT), - PREFIX(POWER_I2C2_BIT), - PREFIX(POWER_SPI_BIT), - PREFIX(POWER_CCP2TX_BIT), - PREFIX(POWER_DSI_BIT), - - PREFIX(POWER_MAX) -}; - -enum { - PREFIX(POWER_SDCARD) = (1 << PREFIX(POWER_SDCARD_BIT)), - PREFIX(POWER_UART) = (1 << PREFIX(POWER_UART_BIT)), - PREFIX(POWER_MINIUART) = (1 << PREFIX(POWER_MINIUART_BIT)), - PREFIX(POWER_USB) = (1 << PREFIX(POWER_USB_BIT)), - PREFIX(POWER_I2C0) = (1 << PREFIX(POWER_I2C0_BIT)), - PREFIX(POWER_I2C1_MASK) = (1 << PREFIX(POWER_I2C1_BIT)), - PREFIX(POWER_I2C2_MASK) = (1 << PREFIX(POWER_I2C2_BIT)), - PREFIX(POWER_SPI_MASK) = (1 << PREFIX(POWER_SPI_BIT)), - PREFIX(POWER_CCP2TX_MASK) = (1 << PREFIX(POWER_CCP2TX_BIT)), - PREFIX(POWER_DSI) = (1 << PREFIX(POWER_DSI_BIT)), - - PREFIX(POWER_MASK) = (1 << PREFIX(POWER_MAX)) - 1, - PREFIX(POWER_NONE) = 0 -}; - -#endif diff --git a/arch/arm/mach-bcm2709/include/mach/power.h b/arch/arm/mach-bcm2709/include/mach/power.h deleted file mode 100644 index 52b3b02363b6f..0000000000000 --- a/arch/arm/mach-bcm2709/include/mach/power.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * linux/arch/arm/mach-bcm2708/power.h - * - * Copyright (C) 2010 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. - * - * This device provides a shared mechanism for controlling the power to - * VideoCore subsystems. - */ - -#ifndef _MACH_BCM2708_POWER_H -#define _MACH_BCM2708_POWER_H - -#include -#include - -typedef unsigned int BCM_POWER_HANDLE_T; - -extern int bcm_power_open(BCM_POWER_HANDLE_T *handle); -extern int bcm_power_request(BCM_POWER_HANDLE_T handle, uint32_t request); -extern int bcm_power_close(BCM_POWER_HANDLE_T handle); - -#endif diff --git a/arch/arm/mach-bcm2709/power.c b/arch/arm/mach-bcm2709/power.c deleted file mode 100644 index 960e4728ae57a..0000000000000 --- a/arch/arm/mach-bcm2709/power.c +++ /dev/null @@ -1,199 +0,0 @@ -/* - * linux/arch/arm/mach-bcm2708/power.c - * - * Copyright (C) 2010 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. - * - * This device provides a shared mechanism for controlling the power to - * VideoCore subsystems. - */ - -#include -#include -#include -#include -#include -#include - -#define DRIVER_NAME "bcm2708_power" - -#define BCM_POWER_MAXCLIENTS 4 -#define BCM_POWER_NOCLIENT (1<<31) - -/* Some drivers expect there devices to be permanently powered */ -#ifdef CONFIG_USB -#define BCM_POWER_ALWAYS_ON (BCM_POWER_USB) -#endif - -#if 1 -#define DPRINTK printk -#else -#define DPRINTK if (0) printk -#endif - -struct state_struct { - uint32_t global_request; - uint32_t client_request[BCM_POWER_MAXCLIENTS]; - struct semaphore client_mutex; - struct semaphore mutex; -} g_state; - -int bcm_power_open(BCM_POWER_HANDLE_T *handle) -{ - BCM_POWER_HANDLE_T i; - int ret = -EBUSY; - - down(&g_state.client_mutex); - - for (i = 0; i < BCM_POWER_MAXCLIENTS; i++) { - if (g_state.client_request[i] == BCM_POWER_NOCLIENT) { - g_state.client_request[i] = BCM_POWER_NONE; - *handle = i; - ret = 0; - break; - } - } - - up(&g_state.client_mutex); - - DPRINTK("bcm_power_open() -> %d\n", *handle); - - return ret; -} -EXPORT_SYMBOL_GPL(bcm_power_open); - -int bcm_power_request(BCM_POWER_HANDLE_T handle, uint32_t request) -{ - int rc = 0; - - DPRINTK("bcm_power_request(%d, %x)\n", handle, request); - - if ((handle < BCM_POWER_MAXCLIENTS) && - (g_state.client_request[handle] != BCM_POWER_NOCLIENT)) { - if (down_interruptible(&g_state.mutex) != 0) { - DPRINTK("bcm_power_request -> interrupted\n"); - return -EINTR; - } - - if (request != g_state.client_request[handle]) { - uint32_t others_request = 0; - uint32_t global_request; - BCM_POWER_HANDLE_T i; - - for (i = 0; i < BCM_POWER_MAXCLIENTS; i++) { - if (i != handle) - others_request |= - g_state.client_request[i]; - } - others_request &= ~BCM_POWER_NOCLIENT; - - global_request = request | others_request; - if (global_request != g_state.global_request) { - uint32_t actual; - - /* Send a request to VideoCore */ - bcm_mailbox_write(MBOX_CHAN_POWER, - global_request << 4); - - /* Wait for a response during power-up */ - if (global_request & ~g_state.global_request) { - rc = bcm_mailbox_read(MBOX_CHAN_POWER, - &actual); - DPRINTK - ("bcm_mailbox_read -> %08x, %d\n", - actual, rc); - actual >>= 4; - } else { - rc = 0; - actual = global_request; - } - - if (rc == 0) { - if (actual != global_request) { - printk(KERN_ERR - "%s: prev global %x, new global %x, actual %x, request %x, others_request %x\n", - __func__, - g_state.global_request, - global_request, actual, request, others_request); - /* A failure */ - BUG_ON((others_request & actual) - != others_request); - request &= actual; - rc = -EIO; - } - - g_state.global_request = actual; - g_state.client_request[handle] = - request; - } - } - } - up(&g_state.mutex); - } else { - rc = -EINVAL; - } - DPRINTK("bcm_power_request -> %d\n", rc); - return rc; -} -EXPORT_SYMBOL_GPL(bcm_power_request); - -int bcm_power_close(BCM_POWER_HANDLE_T handle) -{ - int rc; - - DPRINTK("bcm_power_close(%d)\n", handle); - - rc = bcm_power_request(handle, BCM_POWER_NONE); - if (rc == 0) - g_state.client_request[handle] = BCM_POWER_NOCLIENT; - - return rc; -} -EXPORT_SYMBOL_GPL(bcm_power_close); - -static int __init bcm_power_init(void) -{ -#if defined(BCM_POWER_ALWAYS_ON) - BCM_POWER_HANDLE_T always_on_handle; -#endif - int rc = 0; - int i; - - printk(KERN_INFO "bcm_power: Broadcom power driver\n"); - bcm_mailbox_write(MBOX_CHAN_POWER, 0); - - for (i = 0; i < BCM_POWER_MAXCLIENTS; i++) - g_state.client_request[i] = BCM_POWER_NOCLIENT; - - sema_init(&g_state.client_mutex, 1); - sema_init(&g_state.mutex, 1); - - g_state.global_request = 0; -#if defined(BCM_POWER_ALWAYS_ON) - if (BCM_POWER_ALWAYS_ON) { - bcm_power_open(&always_on_handle); - bcm_power_request(always_on_handle, BCM_POWER_ALWAYS_ON); - } -#endif - - return rc; -} - -static void __exit bcm_power_exit(void) -{ - bcm_mailbox_write(MBOX_CHAN_POWER, 0); -} - -/* - * Load after the mailbox driver is initialized (arch_initcall), - * but before depending drivers (module_init). - */ -subsys_initcall(bcm_power_init); -module_exit(bcm_power_exit); - -MODULE_AUTHOR("Phil Elwell"); -MODULE_DESCRIPTION("Interface to BCM2708 power management"); -MODULE_LICENSE("GPL"); diff --git a/drivers/soc/Kconfig b/drivers/soc/Kconfig index 76d6bd4da138f..aed58f480ff0b 100644 --- a/drivers/soc/Kconfig +++ b/drivers/soc/Kconfig @@ -1,5 +1,6 @@ menu "SOC (System On Chip) specific Drivers" +source "drivers/soc/bcm2835/Kconfig" source "drivers/soc/qcom/Kconfig" source "drivers/soc/ti/Kconfig" source "drivers/soc/versatile/Kconfig" diff --git a/drivers/soc/Makefile b/drivers/soc/Makefile index 063113d0bd387..897de0c54bdcb 100644 --- a/drivers/soc/Makefile +++ b/drivers/soc/Makefile @@ -2,6 +2,7 @@ # Makefile for the Linux Kernel SOC specific device drivers. # +obj-y += bcm2835/ obj-$(CONFIG_ARCH_QCOM) += qcom/ obj-$(CONFIG_ARCH_TEGRA) += tegra/ obj-$(CONFIG_SOC_TI) += ti/ diff --git a/drivers/soc/bcm2835/Kconfig b/drivers/soc/bcm2835/Kconfig new file mode 100644 index 0000000000000..c2980f3f8dc04 --- /dev/null +++ b/drivers/soc/bcm2835/Kconfig @@ -0,0 +1,9 @@ +# +# BCM2835 Soc drivers +# +config BCM2708_POWER + tristate "BCM2708 legacy power driver" + depends on (ARCH_BCM2708 || ARCH_BCM2709 || ARCH_BCM2835) && BCM2708_MBOX + default y + help + Turns on USB power and provides an API for controlling power. diff --git a/drivers/soc/bcm2835/Makefile b/drivers/soc/bcm2835/Makefile new file mode 100644 index 0000000000000..3614ad9c9d480 --- /dev/null +++ b/drivers/soc/bcm2835/Makefile @@ -0,0 +1 @@ +obj-$(CONFIG_BCM2708_POWER) += bcm2708-power.o diff --git a/arch/arm/mach-bcm2708/power.c b/drivers/soc/bcm2835/bcm2708-power.c similarity index 98% rename from arch/arm/mach-bcm2708/power.c rename to drivers/soc/bcm2835/bcm2708-power.c index 796837f2702c1..e7931a970b13d 100644 --- a/arch/arm/mach-bcm2708/power.c +++ b/drivers/soc/bcm2835/bcm2708-power.c @@ -15,8 +15,7 @@ #include #include #include -#include -#include +#include #define DRIVER_NAME "bcm2708_power" diff --git a/arch/arm/mach-bcm2708/include/mach/arm_power.h b/include/soc/bcm2835/power.h similarity index 61% rename from arch/arm/mach-bcm2708/include/mach/arm_power.h rename to include/soc/bcm2835/power.h index d3bf2457ede0a..bf22b2649092b 100644 --- a/arch/arm/mach-bcm2708/include/mach/arm_power.h +++ b/include/soc/bcm2835/power.h @@ -1,25 +1,18 @@ /* - * linux/arch/arm/mach-bcm2708/include/mach/arm_power.h - * * Copyright (C) 2010 Broadcom * * 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; either version 2 of the License, or - * (at your option) any later version. - * - * 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. + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * This device provides a shared mechanism for controlling the power to + * VideoCore subsystems. */ -#ifndef _ARM_POWER_H -#define _ARM_POWER_H +#ifndef _BCM2708_POWER_H +#define _BCM2708_POWER_H + +#include /* Use meaningful names on each side */ #ifdef __VIDEOCORE__ @@ -59,4 +52,10 @@ enum { PREFIX(POWER_NONE) = 0 }; +typedef unsigned int BCM_POWER_HANDLE_T; + +extern int bcm_power_open(BCM_POWER_HANDLE_T *handle); +extern int bcm_power_request(BCM_POWER_HANDLE_T handle, uint32_t request); +extern int bcm_power_close(BCM_POWER_HANDLE_T handle); + #endif