[ramips] initial support for RT288x/RT305x
[openwrt.git] / target / linux / ramips / files / arch / mips / ralink / rt288x / platform.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 #include <asm/mach-ralink/platform.h>
22
23 static struct resource rt288x_flash0_resources[] = {
24         {
25                 .flags  = IORESOURCE_MEM,
26                 .start  = KSEG1ADDR(RT2880_FLASH0_BASE),
27                 .end    = KSEG1ADDR(RT2880_FLASH0_BASE) +
28                           RT2880_FLASH0_SIZE - 1,
29         },
30 };
31
32 static struct platform_device rt288x_flash0_device = {
33         .name           = "physmap-flash",
34         .resource       = rt288x_flash0_resources,
35         .num_resources  = ARRAY_SIZE(rt288x_flash0_resources),
36 };
37
38 static struct resource rt288x_flash1_resources[] = {
39         {
40                 .flags  = IORESOURCE_MEM,
41                 .start  = KSEG1ADDR(RT2880_FLASH1_BASE),
42                 .end    = KSEG1ADDR(RT2880_FLASH1_BASE) +
43                           RT2880_FLASH1_SIZE - 1,
44         },
45 };
46
47 static struct platform_device rt288x_flash1_device = {
48         .name           = "physmap-flash",
49         .resource       = rt288x_flash1_resources,
50         .num_resources  = ARRAY_SIZE(rt288x_flash1_resources),
51 };
52
53 static int rt288x_flash_instance __initdata;
54 void __init rt288x_register_flash(unsigned int id,
55                                   struct physmap_flash_data *pdata)
56 {
57         struct platform_device *pdev;
58         u32 t;
59         int reg;
60
61         switch (id) {
62         case 0:
63                 pdev = &rt288x_flash0_device;
64                 reg = MEMC_REG_FLASH_CFG0;
65                 break;
66         case 1:
67                 pdev = &rt288x_flash1_device;
68                 reg = MEMC_REG_FLASH_CFG1;
69                 break;
70         default:
71                 return;
72         }
73
74         t = rt288x_memc_rr(reg);
75         t = (t >> FLASH_CFG_WIDTH_SHIFT) & FLASH_CFG_WIDTH_MASK;
76
77         switch (t) {
78         case FLASH_CFG_WIDTH_8BIT:
79                 pdata->width = 1;
80                 break;
81         case FLASH_CFG_WIDTH_16BIT:
82                 pdata->width = 2;
83                 break;
84         case FLASH_CFG_WIDTH_32BIT:
85                 pdata->width = 4;
86                 break;
87         default:
88                 printk(KERN_ERR "RT288x: flash bank%u witdh is invalid\n", id);
89                 return;
90         }
91
92         pdev->dev.platform_data = pdata;
93         pdev->id = rt288x_flash_instance;
94
95         platform_device_register(pdev);
96         rt288x_flash_instance++;
97 }