From patchwork Tue May 4 17:18:22 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: thomas.koeller@baslerweb.com X-Patchwork-Id: 96832 Received: from devils.ext.ti.com (devils.ext.ti.com [198.47.26.153]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o44HMBOf032527 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 4 May 2010 17:22:47 GMT Received: from dlep34.itg.ti.com ([157.170.170.115]) by devils.ext.ti.com (8.13.7/8.13.7) with ESMTP id o44HK2lj011518 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 4 May 2010 12:20:02 -0500 Received: from linux.omap.com (localhost [127.0.0.1]) by dlep34.itg.ti.com (8.13.7/8.13.7) with ESMTP id o44HK0b9025732; Tue, 4 May 2010 12:20:00 -0500 (CDT) Received: from linux.omap.com (localhost [127.0.0.1]) by linux.omap.com (Postfix) with ESMTP id AA08A80668; Tue, 4 May 2010 12:19:43 -0500 (CDT) X-Original-To: davinci-linux-open-source@linux.davincidsp.com Delivered-To: davinci-linux-open-source@linux.davincidsp.com Received: from dflp53.itg.ti.com (dflp53.itg.ti.com [128.247.5.6]) by linux.omap.com (Postfix) with ESMTP id 0888780627 for ; Tue, 4 May 2010 12:19:02 -0500 (CDT) Received: from red.ext.ti.com (localhost [127.0.0.1]) by dflp53.itg.ti.com (8.13.8/8.13.8) with ESMTP id o44HJ1HN008165 for ; Tue, 4 May 2010 12:19:01 -0500 (CDT) Received: from psmtp.com (na3sys009amx166.postini.com [74.125.149.92]) by red.ext.ti.com (8.13.7/8.13.7) with SMTP id o44HIxSv010014 for ; Tue, 4 May 2010 12:18:59 -0500 Received: from source ([80.156.24.166]) by na3sys009amx166.postini.com ([74.125.148.10]) with SMTP; Tue, 04 May 2010 12:18:59 CDT Received: from unknown (HELO AHR075S.basler.corp) ([172.16.20.75]) by mail01-out.baslerweb.com with ESMTP; 04 May 2010 19:18:55 +0200 Received: from localhost.localdomain ([172.16.13.131]) by AHR075S.basler.corp with Microsoft SMTPSVC(6.0.3790.4675); Tue, 4 May 2010 19:18:56 +0200 From: thomas.koeller@baslerweb.com To: davinci-linux-open-source@linux.davincidsp.com Subject: [PATCH 2/4] DM365: Add platform resource management Date: Tue, 4 May 2010 19:18:22 +0200 Message-Id: <1272993504-1189-3-git-send-email-thomas.koeller@baslerweb.com> X-Mailer: git-send-email 1.7.0.3 In-Reply-To: <1272993504-1189-1-git-send-email-thomas.koeller@baslerweb.com> References: <1272993504-1189-1-git-send-email-thomas.koeller@baslerweb.com> X-OriginalArrivalTime: 04 May 2010 17:18:56.0691 (UTC) FILETIME=[E0CD7030:01CAEBAD] X-pstn-neptune: 0/0/0.00/0 X-pstn-levels: (S:87.61423/99.90000 CV:99.9000 FC:95.5390 LC:95.5390 R:95.9108 P:95.9108 M:97.0282 C:98.6951 ) X-pstn-settings: 2 (0.5000:0.5000) s cv gt3 gt2 gt1 r p m c X-pstn-addresses: from [db-null] X-BeenThere: davinci-linux-open-source@linux.davincidsp.com X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: davinci-linux-open-source-bounces@linux.davincidsp.com Errors-To: davinci-linux-open-source-bounces@linux.davincidsp.com X-Greylist: Sender succeeded STARTTLS authentication, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Tue, 04 May 2010 17:22:48 +0000 (UTC) diff --git a/arch/arm/mach-davinci/Makefile b/arch/arm/mach-davinci/Makefile index b9c497c..2e3d4ff 100644 --- a/arch/arm/mach-davinci/Makefile +++ b/arch/arm/mach-davinci/Makefile @@ -11,10 +11,10 @@ obj-$(CONFIG_DAVINCI_MUX) += mux.o obj-$(CONFIG_PCI) += pci-generic.o # Chip specific -obj-$(CONFIG_ARCH_DAVINCI_DM644x) += dm644x.o devices.o -obj-$(CONFIG_ARCH_DAVINCI_DM355) += dm355.o devices.o -obj-$(CONFIG_ARCH_DAVINCI_DM646x) += dm646x.o devices.o -obj-$(CONFIG_ARCH_DAVINCI_DM365) += dm365.o devices.o +obj-$(CONFIG_ARCH_DAVINCI_DM644x) += dm644x.o devices.o platform-resources.o +obj-$(CONFIG_ARCH_DAVINCI_DM355) += dm355.o devices.o platform-resources.o +obj-$(CONFIG_ARCH_DAVINCI_DM646x) += dm646x.o devices.o platform-resources.o +obj-$(CONFIG_ARCH_DAVINCI_DM365) += dm365.o devices.o platform-resources.o obj-$(CONFIG_ARCH_DAVINCI_DA830) += da830.o devices-da8xx.o obj-$(CONFIG_ARCH_DAVINCI_DA850) += da850.o devices-da8xx.o diff --git a/arch/arm/mach-davinci/devices.c b/arch/arm/mach-davinci/devices.c index 34dc0e9..53aaeb5 100644 --- a/arch/arm/mach-davinci/devices.c +++ b/arch/arm/mach-davinci/devices.c @@ -27,6 +27,9 @@ #include #include +#include "clock.h" +#include "platform-resources.h" + #define DAVINCI_I2C_BASE 0x01C21000 #define DAVINCI_MMCSD0_BASE 0x01E10000 #define DM355_MMCSD0_BASE 0x01E11000 @@ -34,20 +37,27 @@ #define DM365_MMCSD0_BASE 0x01D11000 #define DM365_MMCSD1_BASE 0x01D00000 +static const char i2c_name[] = "i2c_davinci"; + static struct resource i2c_resources[] = { { + .parent = &resource_cfg_root, + .name = i2c_name, .start = DAVINCI_I2C_BASE, .end = DAVINCI_I2C_BASE + 0x40, .flags = IORESOURCE_MEM, }, { + .parent = &resource_irq_root, + .name = i2c_name, .start = IRQ_I2C, + .end = IRQ_I2C, .flags = IORESOURCE_IRQ, }, }; static struct platform_device davinci_i2c_device = { - .name = "i2c_davinci", + .name = i2c_name, .id = 1, .num_resources = ARRAY_SIZE(i2c_resources), .resource = i2c_resources, @@ -58,42 +68,59 @@ void __init davinci_init_i2c(struct davinci_i2c_platform_data *pdata) if (cpu_is_davinci_dm644x()) davinci_cfg_reg(DM644X_I2C); - davinci_i2c_device.dev.platform_data = pdata; - (void) platform_device_register(&davinci_i2c_device); + if (likely(!alloc_platform_resources(&davinci_i2c_device))) { + davinci_i2c_device.dev.platform_data = pdata; + (void) platform_device_register(&davinci_i2c_device); + } } #if defined(CONFIG_MMC_DAVINCI) || defined(CONFIG_MMC_DAVINCI_MODULE) static u64 mmcsd0_dma_mask = DMA_BIT_MASK(32); +static const char mmc_name[] = "davinci_mmc"; static struct resource mmcsd0_resources[] = { { /* different on dm355 */ - .start = DAVINCI_MMCSD0_BASE, - .end = DAVINCI_MMCSD0_BASE + SZ_4K - 1, - .flags = IORESOURCE_MEM, + .parent = &resource_cfg_root, + .name = mmc_name, + .start = DAVINCI_MMCSD0_BASE, + .end = DAVINCI_MMCSD0_BASE + SZ_4K - 1, + .flags = IORESOURCE_MEM, }, /* IRQs: MMC/SD, then SDIO */ { - .start = IRQ_MMCINT, - .flags = IORESOURCE_IRQ, + .parent = &resource_irq_root, + .name = mmc_name, + .start = IRQ_MMCINT, + .end = IRQ_MMCINT, + .flags = IORESOURCE_IRQ, }, { /* different on dm355 */ - .start = IRQ_SDIOINT, - .flags = IORESOURCE_IRQ, + .parent = &resource_irq_root, + .name = mmc_name, + .start = IRQ_SDIOINT, + .end = IRQ_SDIOINT, + .flags = IORESOURCE_IRQ, }, /* DMA channels: RX, then TX */ { - .start = EDMA_CTLR_CHAN(0, DAVINCI_DMA_MMCRXEVT), - .flags = IORESOURCE_DMA, + .parent = &resource_dma_root, + .name = mmc_name, + .start = EDMA_CTLR_CHAN(0, DAVINCI_DMA_MMCRXEVT), + .end = EDMA_CTLR_CHAN(0, DAVINCI_DMA_MMCRXEVT), + .flags = IORESOURCE_DMA, }, { - .start = EDMA_CTLR_CHAN(0, DAVINCI_DMA_MMCTXEVT), - .flags = IORESOURCE_DMA, + .parent = &resource_dma_root, + .name = mmc_name, + .start = EDMA_CTLR_CHAN(0, DAVINCI_DMA_MMCTXEVT), + .end = EDMA_CTLR_CHAN(0, DAVINCI_DMA_MMCTXEVT), + .flags = IORESOURCE_DMA, }, }; static struct platform_device davinci_mmcsd0_device = { - .name = "davinci_mmc", + .name = mmc_name, .id = 0, .dev = { .dma_mask = &mmcsd0_dma_mask, @@ -107,30 +134,42 @@ static u64 mmcsd1_dma_mask = DMA_BIT_MASK(32); static struct resource mmcsd1_resources[] = { { - .start = DM355_MMCSD1_BASE, - .end = DM355_MMCSD1_BASE + SZ_4K - 1, - .flags = IORESOURCE_MEM, + .parent = &resource_cfg_root, + .name = mmc_name, + .start = DM355_MMCSD1_BASE, + .end = DM355_MMCSD1_BASE + SZ_4K - 1, + .flags = IORESOURCE_MEM, }, /* IRQs: MMC/SD, then SDIO */ { - .start = IRQ_DM355_MMCINT1, - .flags = IORESOURCE_IRQ, + .parent = &resource_irq_root, + .name = mmc_name, + .start = IRQ_DM355_MMCINT1, + .end = IRQ_DM355_MMCINT1, + .flags = IORESOURCE_IRQ, }, { - .start = IRQ_DM355_SDIOINT1, - .flags = IORESOURCE_IRQ, + .parent = &resource_irq_root, + .name = mmc_name, + .start = IRQ_DM355_SDIOINT1, + .end = IRQ_DM355_SDIOINT1, + .flags = IORESOURCE_IRQ, }, /* DMA channels: RX, then TX */ { - .start = EDMA_CTLR_CHAN(0, 30), /* rx */ - .flags = IORESOURCE_DMA, + .parent = &resource_dma_root, + .name = mmc_name, + .start = EDMA_CTLR_CHAN(0, 30), /* rx */ + .flags = IORESOURCE_DMA, }, { - .start = EDMA_CTLR_CHAN(0, 31), /* tx */ - .flags = IORESOURCE_DMA, + .parent = &resource_dma_root, + .name = mmc_name, + .start = EDMA_CTLR_CHAN(0, 31), /* tx */ + .flags = IORESOURCE_DMA, }, }; static struct platform_device davinci_mmcsd1_device = { - .name = "davinci_mmc", + .name = mmc_name, .id = 1, .dev = { .dma_mask = &mmcsd1_dma_mask, @@ -217,8 +256,10 @@ void __init davinci_setup_mmc(int module, struct davinci_mmc_config *config) if (WARN_ON(!pdev)) return; - pdev->dev.platform_data = config; - platform_device_register(pdev); + if (likely(!alloc_platform_resources(pdev))) { + pdev->dev.platform_data = config; + platform_device_register(pdev); + } } #else @@ -231,8 +272,12 @@ void __init davinci_setup_mmc(int module, struct davinci_mmc_config *config) /*-------------------------------------------------------------------------*/ +static const char wdt_name[] = "watchdog"; + static struct resource wdt_resources[] = { { + .parent = &resource_cfg_root, + .name = wdt_name, .start = DAVINCI_WDOG_BASE, .end = DAVINCI_WDOG_BASE + SZ_1K - 1, .flags = IORESOURCE_MEM, @@ -240,7 +285,7 @@ static struct resource wdt_resources[] = { }; struct platform_device davinci_wdt_device = { - .name = "watchdog", + .name = wdt_name, .id = -1, .num_resources = ARRAY_SIZE(wdt_resources), .resource = wdt_resources, @@ -248,7 +293,8 @@ struct platform_device davinci_wdt_device = { static void davinci_init_wdt(void) { - platform_device_register(&davinci_wdt_device); + if (likely(!alloc_platform_resources(&davinci_wdt_device))) + platform_device_register(&davinci_wdt_device); } /*-------------------------------------------------------------------------*/ diff --git a/arch/arm/mach-davinci/dm365.c b/arch/arm/mach-davinci/dm365.c index 30c2327..0aea612 100644 --- a/arch/arm/mach-davinci/dm365.c +++ b/arch/arm/mach-davinci/dm365.c @@ -41,6 +41,7 @@ #include "clock.h" #include "mux.h" +#include "platform-resources.h" #define DM365_REF_FREQ 24000000 /* 24 MHz on the DM365 EVM */ @@ -621,6 +622,8 @@ EVT_CFG(DM365, EVT3_ASP_RX, 1, 1, 0, false) static u64 dm365_ipipeif_dma_mask = DMA_BIT_MASK(32); static struct resource dm365_ipipeif_resources[] = { { + .name = "IPIPEIF", + .parent = &resource_cfg_root, .start = 0x01C71200, .end = 0x01C71200 + 0x60, .flags = IORESOURCE_MEM, @@ -648,11 +651,13 @@ static struct davinci_osd_platform_data dm365_osd_pdata = { static struct resource dm365_osd_resources[] = { { + .parent = &resource_irq_root, .start = IRQ_VENCINT, .end = IRQ_VENCINT, .flags = IORESOURCE_IRQ, }, { + .parent = &resource_cfg_root, .start = DM365_OSD_REG_BASE, .end = DM365_OSD_REG_BASE + OSD_REG_SIZE, .flags = IORESOURCE_MEM, @@ -678,9 +683,12 @@ static struct davinci_venc_platform_data dm365_venc_pdata = { .soc = DM36x, }; +static const char venc_name[] = "davinci_venc"; static struct resource dm365_venc_resources[] = { { + .name = venc_name, + .parent = &resource_cfg_root, .start = DM365_VENC_REG_BASE, .end = DM365_VENC_REG_BASE + 0x180, .flags = IORESOURCE_MEM, @@ -688,7 +696,7 @@ static struct resource dm365_venc_resources[] = { }; static struct platform_device dm365_venc_dev = { - .name = "davinci_venc", + .name = venc_name, .id = -1, .num_resources = ARRAY_SIZE(dm365_venc_resources), .resource = dm365_venc_resources, @@ -708,28 +716,40 @@ static struct emac_platform_data dm365_emac_pdata = { .version = EMAC_VERSION_2, }; +static const char emac_name[] = "davinci_emac"; + static struct resource dm365_emac_resources[] = { { + .name = emac_name, + .parent = &resource_cfg_root, .start = DM365_EMAC_BASE, .end = DM365_EMAC_BASE + 0x47ff, .flags = IORESOURCE_MEM, }, { + .name = emac_name, + .parent = &resource_irq_root, .start = IRQ_DM365_EMAC_RXTHRESH, .end = IRQ_DM365_EMAC_RXTHRESH, .flags = IORESOURCE_IRQ, }, { + .name = emac_name, + .parent = &resource_irq_root, .start = IRQ_DM365_EMAC_RXPULSE, .end = IRQ_DM365_EMAC_RXPULSE, .flags = IORESOURCE_IRQ, }, { + .name = emac_name, + .parent = &resource_irq_root, .start = IRQ_DM365_EMAC_TXPULSE, .end = IRQ_DM365_EMAC_TXPULSE, .flags = IORESOURCE_IRQ, }, { + .name = emac_name, + .parent = &resource_irq_root, .start = IRQ_DM365_EMAC_MISCPULSE, .end = IRQ_DM365_EMAC_MISCPULSE, .flags = IORESOURCE_IRQ, @@ -737,7 +757,7 @@ static struct resource dm365_emac_resources[] = { }; static struct platform_device dm365_emac_device = { - .name = "davinci_emac", + .name = emac_name, .id = 1, .dev = { .platform_data = &dm365_emac_pdata, @@ -851,42 +871,51 @@ static struct edma_soc_info dm365_edma_info[] = { static struct resource edma_resources[] = { { .name = "edma_cc0", + .parent = &resource_cfg_root, .start = 0x01c00000, .end = 0x01c00000 + SZ_64K - 1, .flags = IORESOURCE_MEM, }, { .name = "edma_tc0", + .parent = &resource_cfg_root, .start = 0x01c10000, .end = 0x01c10000 + SZ_1K - 1, .flags = IORESOURCE_MEM, }, { .name = "edma_tc1", + .parent = &resource_cfg_root, .start = 0x01c10400, .end = 0x01c10400 + SZ_1K - 1, .flags = IORESOURCE_MEM, }, { .name = "edma_tc2", + .parent = &resource_cfg_root, .start = 0x01c10800, .end = 0x01c10800 + SZ_1K - 1, .flags = IORESOURCE_MEM, }, { .name = "edma_tc3", + .parent = &resource_cfg_root, .start = 0x01c10c00, .end = 0x01c10c00 + SZ_1K - 1, .flags = IORESOURCE_MEM, }, { .name = "edma0", + .parent = &resource_irq_root, .start = IRQ_CCINT0, + .end = IRQ_CCINT0, .flags = IORESOURCE_IRQ, }, { .name = "edma0_err", + .parent = &resource_irq_root, .start = IRQ_CCERRINT, + .end = IRQ_CCERRINT, .flags = IORESOURCE_IRQ, }, /* not using TC*_ERR */ @@ -900,18 +929,26 @@ static struct platform_device dm365_edma_device = { .resource = edma_resources, }; +static const char asp_name[] = "davinci-asp"; + static struct resource dm365_asp_resources[] = { { + .name = asp_name, + .parent = &resource_cfg_root, .start = DAVINCI_DM365_ASP0_BASE, .end = DAVINCI_DM365_ASP0_BASE + SZ_8K - 1, .flags = IORESOURCE_MEM, }, { + .name = asp_name, + .parent = &resource_dma_root, .start = DAVINCI_DMA_ASP0_TX, .end = DAVINCI_DMA_ASP0_TX, .flags = IORESOURCE_DMA, }, { + .name = asp_name, + .parent = &resource_dma_root, .start = DAVINCI_DMA_ASP0_RX, .end = DAVINCI_DMA_ASP0_RX, .flags = IORESOURCE_DMA, @@ -919,26 +956,33 @@ static struct resource dm365_asp_resources[] = { }; static struct platform_device dm365_asp_device = { - .name = "davinci-asp", + .name = asp_name, .id = 0, .num_resources = ARRAY_SIZE(dm365_asp_resources), .resource = dm365_asp_resources, }; +static const char rtc_name[] = "rtc_davinci"; + static struct resource dm365_rtc_resources[] = { { - .start = DM365_RTC_BASE, - .end = DM365_RTC_BASE + SZ_1K - 1, - .flags = IORESOURCE_MEM, + .name = rtc_name, + .parent = &resource_cfg_root, + .start = DM365_RTC_BASE, + .end = DM365_RTC_BASE + SZ_1K - 1, + .flags = IORESOURCE_MEM, }, { - .start = IRQ_DM365_RTCINT, - .flags = IORESOURCE_IRQ, + .name = rtc_name, + .parent = &resource_irq_root, + .start = IRQ_DM365_RTCINT, + .end = IRQ_DM365_RTCINT, + .flags = IORESOURCE_IRQ, }, }; static struct platform_device dm365_rtc_device = { - .name = "rtc_davinci", + .name = rtc_name, .id = 0, .num_resources = ARRAY_SIZE(dm365_rtc_resources), .resource = dm365_rtc_resources, @@ -960,23 +1004,29 @@ static struct map_desc dm365_io_desc[] = { }, }; +static const char ks_name[] = "davinci_keyscan"; + static struct resource dm365_ks_resources[] = { { /* registers */ - .start = DM365_KEYSCAN_BASE, - .end = DM365_KEYSCAN_BASE + SZ_1K - 1, - .flags = IORESOURCE_MEM, + .name = ks_name, + .parent = &resource_cfg_root, + .start = DM365_KEYSCAN_BASE, + .end = DM365_KEYSCAN_BASE + SZ_1K - 1, + .flags = IORESOURCE_MEM, }, { /* interrupt */ - .start = IRQ_DM365_KEYINT, - .end = IRQ_DM365_KEYINT, - .flags = IORESOURCE_IRQ, + .start = IRQ_DM365_KEYINT, + .parent = &resource_irq_root, + .start = IRQ_DM365_KEYINT, + .end = IRQ_DM365_KEYINT, + .flags = IORESOURCE_IRQ, }, }; static struct platform_device dm365_ks_device = { - .name = "davinci_keyscan", + .name = ks_name, .id = 0, .num_resources = ARRAY_SIZE(dm365_ks_resources), .resource = dm365_ks_resources, @@ -1004,7 +1054,7 @@ static void __iomem *dm365_psc_bases[] = { IO_ADDRESS(DAVINCI_PWR_SLEEP_CNTRL_BASE), }; -struct davinci_timer_info dm365_timer_info = { +static struct davinci_timer_info dm365_timer_info = { .timers = davinci_timer_instance, .clockevent_id = T0_BOT, .clocksource_id = T0_TOP, @@ -1078,7 +1128,8 @@ void __init dm365_init_asp(struct snd_platform_data *pdata) davinci_cfg_reg(DM365_EVT2_ASP_TX); davinci_cfg_reg(DM365_EVT3_ASP_RX); dm365_asp_device.dev.platform_data = pdata; - platform_device_register(&dm365_asp_device); + if (!alloc_platform_resources(&dm365_asp_device)) + platform_device_register(&dm365_asp_device); } void __init dm365_init_ks(struct davinci_ks_platform_data *pdata) @@ -1090,7 +1141,8 @@ void __init dm365_init_ks(struct davinci_ks_platform_data *pdata) void __init dm365_init_rtc(void) { davinci_cfg_reg(DM365_INT_PRTCSS); - platform_device_register(&dm365_rtc_device); + if (!alloc_platform_resources(&dm365_rtc_device)) + platform_device_register(&dm365_rtc_device); } void __init dm365_init(void) @@ -1098,17 +1150,21 @@ void __init dm365_init(void) davinci_common_init(&davinci_soc_info_dm365); } +static const char vpss_name[] = "vpss"; + static struct resource dm365_vpss_resources[] = { { /* VPSS ISP5 Base address */ - .name = "vpss", + .name = vpss_name, + .parent = &resource_cfg_root, .start = 0x01c70000, .end = 0x01c70000 + 0xff, .flags = IORESOURCE_MEM, }, { /* VPSS CLK Base address */ - .name = "vpss", + .name = vpss_name, + .parent = &resource_cfg_root, .start = 0x01c70200, .end = 0x01c70200 + 0xff, .flags = IORESOURCE_MEM, @@ -1116,20 +1172,26 @@ static struct resource dm365_vpss_resources[] = { }; static struct platform_device dm365_vpss_device = { - .name = "vpss", + .name = vpss_name, .id = -1, .dev.platform_data = "dm365_vpss", .num_resources = ARRAY_SIZE(dm365_vpss_resources), .resource = dm365_vpss_resources, }; +static const char cptr_name[] = CAPTURE_DRV_NAME; + static struct resource vpfe_resources[] = { { + .name = cptr_name, + .parent = &resource_irq_root, .start = IRQ_VDINT0, .end = IRQ_VDINT0, .flags = IORESOURCE_IRQ, }, { + .name = cptr_name, + .parent = &resource_irq_root, .start = IRQ_VDINT1, .end = IRQ_VDINT1, .flags = IORESOURCE_IRQ, @@ -1138,7 +1200,7 @@ static struct resource vpfe_resources[] = { static u64 vpfe_capture_dma_mask = DMA_BIT_MASK(32); static struct platform_device vpfe_capture_dev = { - .name = CAPTURE_DRV_NAME, + .name = cptr_name, .id = -1, .num_resources = ARRAY_SIZE(vpfe_resources), .resource = vpfe_resources, @@ -1148,28 +1210,36 @@ static struct platform_device vpfe_capture_dev = { }, }; +static const char isif_name[] = "dm365_isif"; + static struct resource isif_resource[] = { /* ISIF Base address */ { + .name = isif_name, + .parent = &resource_cfg_root, .start = 0x01c71000, .end = 0x01c71000 + 0x1ff, .flags = IORESOURCE_MEM, }, /* ISIF Linearization table 0 */ { + .name = isif_name, + .parent = &resource_cfg_root, .start = 0x1C7C000, .end = 0x1C7C000 + 0x2ff, .flags = IORESOURCE_MEM, }, /* ISIF Linearization table 1 */ { + .name = isif_name, + .parent = &resource_cfg_root, .start = 0x1C7C400, .end = 0x1C7C400 + 0x2ff, .flags = IORESOURCE_MEM, }, }; static struct platform_device dm365_isif_dev = { - .name = "dm365_isif", + .name = isif_name, .id = -1, .num_resources = ARRAY_SIZE(isif_resource), .resource = isif_resource, @@ -1184,24 +1254,35 @@ static int __init dm365_init_devices(void) if (!cpu_is_davinci_dm365()) return 0; + if (request_resource(&iomem_resource, &resource_cfg_root)) + BUG(); + davinci_cfg_reg(DM365_INT_EDMA_CC); - platform_device_register(&dm365_edma_device); - platform_device_register(&dm365_emac_device); + if (!alloc_platform_resources(&dm365_edma_device)) + platform_device_register(&dm365_edma_device); + if (!alloc_platform_resources(&dm365_emac_device)) + platform_device_register(&dm365_emac_device); /* * setup Mux configuration for vpfe input and register * vpfe capture platform device */ - platform_device_register(&dm365_vpss_device); - platform_device_register(&dm365_ipipeif_dev); - platform_device_register(&dm365_isif_dev); - platform_device_register(&vpfe_capture_dev); + if (!alloc_platform_resources(&dm365_vpss_device)) + platform_device_register(&dm365_vpss_device); + if (!alloc_platform_resources(&dm365_ipipeif_dev)) + platform_device_register(&dm365_ipipeif_dev); + if (!alloc_platform_resources(&dm365_isif_dev)) + platform_device_register(&dm365_isif_dev); + if (!alloc_platform_resources(&vpfe_capture_dev)) + platform_device_register(&vpfe_capture_dev); /* Register OSD device */ - platform_device_register(&dm365_osd_dev); + if (!alloc_platform_resources(&dm365_osd_dev)) + platform_device_register(&dm365_osd_dev); /* Register VENC device */ - platform_device_register(&dm365_venc_dev); + if (!alloc_platform_resources(&dm365_venc_dev)) + platform_device_register(&dm365_venc_dev); return 0; } diff --git a/arch/arm/mach-davinci/dm365_spi.c b/arch/arm/mach-davinci/dm365_spi.c index e1743d7..6aeba61 100644 --- a/arch/arm/mach-davinci/dm365_spi.c +++ b/arch/arm/mach-davinci/dm365_spi.c @@ -19,11 +19,12 @@ #include #include +#include "platform-resources.h" #include "spi.h" -static u64 davinci_spi_dma_mask = DMA_BIT_MASK(32); +static u64 dm365_spi_dma_mask = DMA_BIT_MASK(32); -enum davinci_spi_resource_index { +enum dm365_spi_resource_index { spirsrc_iomem, spirsrc_irq, spirsrc_rxdma, @@ -31,159 +32,217 @@ enum davinci_spi_resource_index { spirsrc_evqdma }; +static const char + spi0_name[] = "SPI0", + spi1_name[] = "SPI1", + spi2_name[] = "SPI2", + spi3_name[] = "SPI3", + spi4_name[] = "SPI4"; -static struct resource davinci_spi_resources[spirsrc_evqdma + 1][5] = { - { + +static struct resource +dm365_spi_resources[spirsrc_evqdma + 1][5] = { + [0] = { [spirsrc_iomem] = { + .name = spi0_name, + .parent = &resource_cfg_root, .start = 0x01c66000, .end = 0x01c667ff, .flags = IORESOURCE_MEM, }, [spirsrc_irq] = { + .name = spi0_name, + .parent = &resource_irq_root, .flags = IORESOURCE_IRQ, }, [spirsrc_rxdma] = { + .name = spi0_name, + .parent = &resource_dma_root, .flags = IORESOURCE_DMA | IORESOURCE_DMA_RX_CHAN, }, [spirsrc_txdma] = { + .name = spi0_name, + .parent = &resource_dma_root, .flags = IORESOURCE_DMA | IORESOURCE_DMA_TX_CHAN, }, [spirsrc_evqdma] = { + .name = spi0_name, + .parent = &resource_evq_root, .flags = IORESOURCE_DMA | IORESOURCE_DMA_EVENT_Q, } }, - { + [1] = { [spirsrc_iomem] = { + .name = spi1_name, + .parent = &resource_cfg_root, .start = 0x01c66800, .end = 0x01c66fff, .flags = IORESOURCE_MEM, }, [spirsrc_irq] = { + .name = spi1_name, + .parent = &resource_irq_root, .flags = IORESOURCE_IRQ, }, [spirsrc_rxdma] = { + .name = spi1_name, + .parent = &resource_dma_root, .flags = IORESOURCE_DMA | IORESOURCE_DMA_RX_CHAN, }, [spirsrc_txdma] = { + .name = spi1_name, + .parent = &resource_dma_root, .flags = IORESOURCE_DMA | IORESOURCE_DMA_TX_CHAN, }, [spirsrc_evqdma] = { + .name = spi1_name, + .parent = &resource_evq_root, .flags = IORESOURCE_DMA | IORESOURCE_DMA_EVENT_Q, } }, - { + [2] = { [spirsrc_iomem] = { + .name = spi2_name, + .parent = &resource_cfg_root, .start = 0x01c67800, .end = 0x01c67fff, .flags = IORESOURCE_MEM, }, [spirsrc_irq] = { + .name = spi2_name, + .parent = &resource_irq_root, .flags = IORESOURCE_IRQ, }, [spirsrc_rxdma] = { + .name = spi2_name, + .parent = &resource_dma_root, .flags = IORESOURCE_DMA | IORESOURCE_DMA_RX_CHAN, }, [spirsrc_txdma] = { + .name = spi2_name, + .parent = &resource_dma_root, .flags = IORESOURCE_DMA | IORESOURCE_DMA_TX_CHAN, }, [spirsrc_evqdma] = { + .name = spi2_name, + .parent = &resource_evq_root, .flags = IORESOURCE_DMA | IORESOURCE_DMA_EVENT_Q, } }, - { + [3] = { [spirsrc_iomem] = { + .name = spi3_name, + .parent = &resource_cfg_root, .start = 0x01c68000, .end = 0x01c687ff, .flags = IORESOURCE_MEM, }, [spirsrc_irq] = { + .name = spi3_name, + .parent = &resource_irq_root, .flags = IORESOURCE_IRQ, }, [spirsrc_rxdma] = { + .name = spi3_name, + .parent = &resource_dma_root, .flags = IORESOURCE_DMA | IORESOURCE_DMA_RX_CHAN, }, [spirsrc_txdma] = { + .name = spi3_name, + .parent = &resource_dma_root, .flags = IORESOURCE_DMA | IORESOURCE_DMA_TX_CHAN, }, [spirsrc_evqdma] = { + .name = spi3_name, + .parent = &resource_evq_root, .flags = IORESOURCE_DMA | IORESOURCE_DMA_EVENT_Q, } }, - { + [4] = { [spirsrc_iomem] = { + .name = spi4_name, + .parent = &resource_cfg_root, .start = 0x01c23000, .end = 0x01c237ff, .flags = IORESOURCE_MEM, }, [spirsrc_irq] = { + .name = spi4_name, + .parent = &resource_irq_root, .flags = IORESOURCE_IRQ, }, [spirsrc_rxdma] = { + .name = spi4_name, + .parent = &resource_dma_root, .flags = IORESOURCE_DMA | IORESOURCE_DMA_RX_CHAN, }, [spirsrc_txdma] = { + .name = spi4_name, + .parent = &resource_dma_root, .flags = IORESOURCE_DMA | IORESOURCE_DMA_TX_CHAN, }, [spirsrc_evqdma] = { + .name = spi4_name, + .parent = &resource_evq_root, .flags = IORESOURCE_DMA | IORESOURCE_DMA_EVENT_Q, } } }; -static struct platform_device davinci_spi_device[] = { +static struct platform_device dm365_spi_device[] = { { .name = "spi_davinci", .id = 0, .dev = { - .dma_mask = &davinci_spi_dma_mask, + .dma_mask = &dm365_spi_dma_mask, .coherent_dma_mask = DMA_BIT_MASK(32), }, - .num_resources = ARRAY_SIZE(davinci_spi_resources[0]), - .resource = davinci_spi_resources[0] + .num_resources = ARRAY_SIZE(dm365_spi_resources[0]), + .resource = dm365_spi_resources[0] }, { .name = "spi_davinci", .id = 1, .dev = { - .dma_mask = &davinci_spi_dma_mask, + .dma_mask = &dm365_spi_dma_mask, .coherent_dma_mask = DMA_BIT_MASK(32), }, - .num_resources = ARRAY_SIZE(davinci_spi_resources[1]), - .resource = davinci_spi_resources[1] + .num_resources = ARRAY_SIZE(dm365_spi_resources[1]), + .resource = dm365_spi_resources[1] }, { .name = "spi_davinci", .id = 2, .dev = { - .dma_mask = &davinci_spi_dma_mask, + .dma_mask = &dm365_spi_dma_mask, .coherent_dma_mask = DMA_BIT_MASK(32), }, - .num_resources = ARRAY_SIZE(davinci_spi_resources[2]), - .resource = davinci_spi_resources[2] + .num_resources = ARRAY_SIZE(dm365_spi_resources[2]), + .resource = dm365_spi_resources[2] }, { .name = "spi_davinci", .id = 3, .dev = { - .dma_mask = &davinci_spi_dma_mask, + .dma_mask = &dm365_spi_dma_mask, .coherent_dma_mask = DMA_BIT_MASK(32), }, - .num_resources = ARRAY_SIZE(davinci_spi_resources[3]), - .resource = davinci_spi_resources[3] + .num_resources = ARRAY_SIZE(dm365_spi_resources[3]), + .resource = dm365_spi_resources[3] }, { .name = "spi_davinci", .id = 4, .dev = { - .dma_mask = &davinci_spi_dma_mask, + .dma_mask = &dm365_spi_dma_mask, .coherent_dma_mask = DMA_BIT_MASK(32), }, - .num_resources = ARRAY_SIZE(davinci_spi_resources[4]), - .resource = davinci_spi_resources[4] + .num_resources = ARRAY_SIZE(dm365_spi_resources[4]), + .resource = dm365_spi_resources[4] } }; -struct davinci_spi_pins { +struct dm365_spi_pins { int sclk; int sdi; int sdo; @@ -191,7 +250,7 @@ struct davinci_spi_pins { int sdena1; }; -static const struct davinci_spi_pins davinci_spi_pinmap[] __initconst = { +static const struct dm365_spi_pins dm365_spi_pinmap[] __initconst = { { .sclk = DM365_SPI0_SCLK, .sdi = DM365_SPI0_SDI, @@ -230,13 +289,13 @@ static const struct davinci_spi_pins davinci_spi_pinmap[] __initconst = { }; void __init davinci_init_spi(struct davinci_spi_unit_desc *unit, - unsigned int ninfo, - const struct spi_board_info *info) + unsigned int ninfo, + const struct spi_board_info *info) { int err; const unsigned int hwunit = unit->spi_hwunit; - const struct davinci_spi_pins * const pins = &davinci_spi_pinmap[hwunit]; - struct platform_device * const pdev = &davinci_spi_device[hwunit]; + const struct dm365_spi_pins * const pins = &dm365_spi_pinmap[hwunit]; + struct platform_device * const pdev = &dm365_spi_device[hwunit]; struct davinci_spi_platform_data * const pdata = &unit->pdata; davinci_cfg_reg(pins->sclk); @@ -260,6 +319,11 @@ void __init davinci_init_spi(struct davinci_spi_unit_desc *unit, pdev->resource[spirsrc_evqdma].start = pdev->resource[spirsrc_evqdma].end = unit->dma_evtq; + if (alloc_platform_resources(pdev)) { + pr_err("Resource allocation failed for SPI%u\n", hwunit); + return; + }; + pr_debug("Creating SPI%u: irq = %u, dma_rx = %u, dma_tx = %u, " "dma_evq = %u", hwunit, unit->irq, unit->dma_rx_chan, unit->dma_tx_chan, @@ -272,5 +336,3 @@ void __init davinci_init_spi(struct davinci_spi_unit_desc *unit, spi_register_board_info(info, ninfo); } - - diff --git a/arch/arm/mach-davinci/dma.c b/arch/arm/mach-davinci/dma.c index 5cd48fa..8abc707 100644 --- a/arch/arm/mach-davinci/dma.c +++ b/arch/arm/mach-davinci/dma.c @@ -1430,14 +1430,6 @@ static int __init edma_probe(struct platform_device *pdev) found = 1; len[j] = resource_size(r[j]); - - r[j] = request_mem_region(r[j]->start, len[j], - dev_name(&pdev->dev)); - if (!r[j]) { - status = -EBUSY; - goto fail1; - } - edmacc_regs_base[j] = ioremap(r[j]->start, len[j]); if (!edmacc_regs_base[j]) { status = -EBUSY; diff --git a/arch/arm/mach-davinci/platform-resources.c b/arch/arm/mach-davinci/platform-resources.c new file mode 100644 index 0000000..90893d3 --- /dev/null +++ b/arch/arm/mach-davinci/platform-resources.c @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2010 Basler Vision Technologies AG + * + * 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 version 2. + * + * This program is distributed "as is" WITHOUT ANY WARRANTY of any + * kind, whether express or implied; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * Author: Thomas Koeller + */ + +#include "platform-resources.h" + +/* root resource for configuration register space */ +struct resource resource_cfg_root = { + .name = "DM365 peripherals", + .start = 0x01c00000, + .end = 0x01ffffff, + .flags = IORESOURCE_MEM +}; + +/* root resource for DMA channels */ +struct resource resource_dma_root = { + .name = "DM365 DMA", + .start = 0, + .end = 63, + .flags = IORESOURCE_DMA +}; + +/* root resource for DMA event queues */ +struct resource resource_evq_root = { + .name = "DM365 EVQ", + .start = 0, + .end = 3, + .flags = IORESOURCE_DMA +}; + +/* root resource for IRQ numbers */ +struct resource resource_irq_root = { + .name = "DM365 IRQ", + .start = 0, + .end = 63, + .flags = IORESOURCE_IRQ +}; + +/* Allocate resources for platform device */ +int alloc_platform_resources(const struct platform_device *dev) +{ + int n; + + for (n = 0; n < dev->num_resources; ++n) { + int res; + struct resource *rsrc = &dev->resource[n]; + struct resource *parent; + + /* + * Memory and I/O resources are automatically allocated + * by platform_device_add(), so do not allocate them + * here. + */ + if (resource_type(rsrc) == IORESOURCE_IO || + resource_type(rsrc) == IORESOURCE_MEM) + continue; + + parent = rsrc->parent; + res = request_resource(parent, rsrc); + if (likely(!res)) + continue; + + /* bail out */ + rsrc->parent = parent; + pr_warning("Failed to allocate resource '%s' from '%s'\n", + rsrc->name, parent->name); + while (--n >= 0) { + /* preserve the parent pointer */ + rsrc = &dev->resource[n]; + parent = rsrc->parent; + release_resource(rsrc); + rsrc->parent = parent; + } + + return res; + } + + return 0; +} diff --git a/arch/arm/mach-davinci/platform-resources.h b/arch/arm/mach-davinci/platform-resources.h new file mode 100644 index 0000000..0af3fe0 --- /dev/null +++ b/arch/arm/mach-davinci/platform-resources.h @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2010 Basler Vision Technologies AG + * + * 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 version 2. + * + * This program is distributed "as is" WITHOUT ANY WARRANTY of any + * kind, whether express or implied; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * Author: Thomas Koeller + */ +#ifndef DAVINCI_PLATFORM_RESOURCES_H +#define DAVINCI_PLATFORM_RESOURCES_H + +#include +#include + +/* Root resources */ +extern struct resource + resource_cfg_root, + resource_dma_root, + resource_irq_root, + resource_evq_root; + +int alloc_platform_resources(const struct platform_device *dev); + +#endif /* DAVINCI_PLATFORM_RESOURCES_H */ diff --git a/drivers/i2c/busses/i2c-davinci.c b/drivers/i2c/busses/i2c-davinci.c index 67d88cc..4327ad9 100755 --- a/drivers/i2c/busses/i2c-davinci.c +++ b/drivers/i2c/busses/i2c-davinci.c @@ -520,7 +520,7 @@ static int davinci_i2c_probe(struct platform_device *pdev) { struct davinci_i2c_dev *dev; struct i2c_adapter *adap; - struct resource *mem, *irq, *ioarea; + struct resource *mem, *irq; int r; /* NOTE: driver uses the static register mapping */ @@ -536,13 +536,6 @@ static int davinci_i2c_probe(struct platform_device *pdev) return -ENODEV; } - ioarea = request_mem_region(mem->start, resource_size(mem), - pdev->name); - if (!ioarea) { - dev_err(&pdev->dev, "I2C region already claimed\n"); - return -EBUSY; - } - dev = kzalloc(sizeof(struct davinci_i2c_dev), GFP_KERNEL); if (!dev) { r = -ENOMEM; diff --git a/drivers/mmc/host/davinci_mmc.c b/drivers/mmc/host/davinci_mmc.c index 1bf0587..cf69c2e 100644 --- a/drivers/mmc/host/davinci_mmc.c +++ b/drivers/mmc/host/davinci_mmc.c @@ -1183,9 +1183,7 @@ static int __init davinci_mmcsd_probe(struct platform_device *pdev) ret = -EBUSY; mem_size = resource_size(r); - mem = request_mem_region(r->start, mem_size, pdev->name); - if (!mem) - goto out; + mem = r; ret = -ENOMEM; mmc = mmc_alloc_host(sizeof(struct mmc_davinci_host), &pdev->dev); diff --git a/drivers/spi/davinci_spi.c b/drivers/spi/davinci_spi.c index 956f617..456a680 100644 --- a/drivers/spi/davinci_spi.c +++ b/drivers/spi/davinci_spi.c @@ -868,7 +868,7 @@ static irqreturn_t davinci_spi_irq(s32 irq, void *context_data) return ret; } -resource_size_t davinci_spi_get_dma_by_flag(struct platform_device *dev, +static resource_size_t davinci_spi_get_dma_by_flag(struct platform_device *dev, unsigned long flag) { struct resource *r; @@ -901,7 +901,7 @@ static int davinci_spi_probe(struct platform_device *pdev) struct spi_master *master; struct davinci_spi *davinci_spi; struct davinci_spi_platform_data *pdata; - struct resource *r, *mem; + struct resource *r; resource_size_t dma_rx_chan = DAVINCI_SPI_NO_RESOURCE; resource_size_t dma_tx_chan = DAVINCI_SPI_NO_RESOURCE; resource_size_t dma_eventq = DAVINCI_SPI_NO_RESOURCE; @@ -936,19 +936,11 @@ static int davinci_spi_probe(struct platform_device *pdev) davinci_spi->pbase = r->start; davinci_spi->region_size = resource_size(r); davinci_spi->pdata = pdata; - - mem = request_mem_region(r->start, davinci_spi->region_size, - pdev->name); - if (mem == NULL) { - ret = -EBUSY; - goto free_master; - } - davinci_spi->base = (struct davinci_spi_reg __iomem *) ioremap(r->start, davinci_spi->region_size); if (davinci_spi->base == NULL) { ret = -ENOMEM; - goto release_region; + goto free_master; } davinci_spi->irq = platform_get_irq(pdev, 0); @@ -1088,8 +1080,6 @@ err1: free_irq(davinci_spi->irq, davinci_spi); unmap_io: iounmap(davinci_spi->base); -release_region: - release_mem_region(davinci_spi->pbase, davinci_spi->region_size); free_master: kfree(master); err: diff --git a/drivers/watchdog/davinci_wdt.c b/drivers/watchdog/davinci_wdt.c index 9d7520f..2331750 100644 --- a/drivers/watchdog/davinci_wdt.c +++ b/drivers/watchdog/davinci_wdt.c @@ -68,7 +68,6 @@ static unsigned long wdt_status; #define WDT_REGION_INITED 2 #define WDT_DEVICE_INITED 3 -static struct resource *wdt_mem; static void __iomem *wdt_base; struct clk *wdt_clk; @@ -222,12 +221,6 @@ static int __devinit davinci_wdt_probe(struct platform_device *pdev) } size = res->end - res->start + 1; - wdt_mem = request_mem_region(res->start, size, pdev->name); - - if (wdt_mem == NULL) { - dev_err(dev, "failed to get memory region\n"); - return -ENOENT; - } wdt_base = ioremap(res->start, size); if (!wdt_base) { @@ -238,8 +231,6 @@ static int __devinit davinci_wdt_probe(struct platform_device *pdev) ret = misc_register(&davinci_wdt_miscdev); if (ret < 0) { dev_err(dev, "cannot register misc device\n"); - release_resource(wdt_mem); - kfree(wdt_mem); } else { set_bit(WDT_DEVICE_INITED, &wdt_status); } @@ -251,12 +242,6 @@ static int __devinit davinci_wdt_probe(struct platform_device *pdev) static int __devexit davinci_wdt_remove(struct platform_device *pdev) { misc_deregister(&davinci_wdt_miscdev); - if (wdt_mem) { - release_resource(wdt_mem); - kfree(wdt_mem); - wdt_mem = NULL; - } - clk_disable(wdt_clk); clk_put(wdt_clk);