[ramips] platform.h is rt288x specific, move it
[15.05/openwrt.git] / target / linux / ramips / files / arch / mips / ralink / rt288x / devices.c
1 /*
2  *  Ralink RT288x SoC platform device registration
3  *
4  *  Copyright (C) 2008 Gabor Juhos <juhosg@openwrt.org>
5  *  Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
6  *
7  *  This program is free software; you can redistribute it and/or modify it
8  *  under the terms of the GNU General Public License version 2 as published
9  *  by the Free Software Foundation.
10  */
11
12 #include <linux/kernel.h>
13 #include <linux/platform_device.h>
14 #include <linux/mtd/mtd.h>
15 #include <linux/mtd/physmap.h>
16
17 #include <asm/addrspace.h>
18
19 #include <asm/mach-ralink/rt288x.h>
20 #include <asm/mach-ralink/rt288x_regs.h>
21
22 #include "devices.h"
23
24 static struct resource rt288x_flash0_resources[] = {
25         {
26                 .flags  = IORESOURCE_MEM,
27                 .start  = KSEG1ADDR(RT2880_FLASH0_BASE),
28                 .end    = KSEG1ADDR(RT2880_FLASH0_BASE) +
29                           RT2880_FLASH0_SIZE - 1,
30         },
31 };
32
33 static struct platform_device rt288x_flash0_device = {
34         .name           = "physmap-flash",
35         .resource       = rt288x_flash0_resources,
36         .num_resources  = ARRAY_SIZE(rt288x_flash0_resources),
37 };
38
39 static struct resource rt288x_flash1_resources[] = {
40         {
41                 .flags  = IORESOURCE_MEM,
42                 .start  = KSEG1ADDR(RT2880_FLASH1_BASE),
43                 .end    = KSEG1ADDR(RT2880_FLASH1_BASE) +
44                           RT2880_FLASH1_SIZE - 1,
45         },
46 };
47
48 static struct platform_device rt288x_flash1_device = {
49         .name           = "physmap-flash",
50         .resource       = rt288x_flash1_resources,
51         .num_resources  = ARRAY_SIZE(rt288x_flash1_resources),
52 };
53
54 static int rt288x_flash_instance __initdata;
55 void __init rt288x_register_flash(unsigned int id,
56                                   struct physmap_flash_data *pdata)
57 {
58         struct platform_device *pdev;
59         u32 t;
60         int reg;
61
62         switch (id) {
63         case 0:
64                 pdev = &rt288x_flash0_device;
65                 reg = MEMC_REG_FLASH_CFG0;
66                 break;
67         case 1:
68                 pdev = &rt288x_flash1_device;
69                 reg = MEMC_REG_FLASH_CFG1;
70                 break;
71         default:
72                 return;
73         }
74
75         t = rt288x_memc_rr(reg);
76         t = (t >> FLASH_CFG_WIDTH_SHIFT) & FLASH_CFG_WIDTH_MASK;
77
78         switch (t) {
79         case FLASH_CFG_WIDTH_8BIT:
80                 pdata->width = 1;
81                 break;
82         case FLASH_CFG_WIDTH_16BIT:
83                 pdata->width = 2;
84                 break;
85         case FLASH_CFG_WIDTH_32BIT:
86                 pdata->width = 4;
87                 break;
88         default:
89                 printk(KERN_ERR "RT288x: flash bank%u witdh is invalid\n", id);
90                 return;
91         }
92
93         pdev->dev.platform_data = pdata;
94         pdev->id = rt288x_flash_instance;
95
96         platform_device_register(pdev);
97         rt288x_flash_instance++;
98 }