Root/target/linux/lantiq/files-3.0/arch/mips/lantiq/falcon/addon-easy98000.c

1/*
2 * EASY98000 CPLD Addon driver
3 *
4 * Copyright (C) 2011 Thomas Langer <thomas.langer@lantiq.com>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published
8 * by the Free Software Foundation.
9 *
10 */
11
12#include <linux/kernel.h>
13#include <linux/version.h>
14#include <linux/types.h>
15#include <linux/init.h>
16#include <linux/platform_device.h>
17#include <linux/errno.h>
18#include <linux/slab.h>
19#include <linux/proc_fs.h>
20#include <linux/seq_file.h>
21
22struct easy98000_reg_cpld {
23    u16 cmdreg1; /* 0x1 */
24    u16 cmdreg0; /* 0x0 */
25    u16 idreg0; /* 0x3 */
26    u16 resreg; /* 0x2 */
27    u16 intreg; /* 0x5 */
28    u16 idreg1; /* 0x4 */
29    u16 ledreg; /* 0x7 */
30    u16 pcmconconfig; /* 0x6 */
31    u16 res0; /* 0x9 */
32    u16 ethledreg; /* 0x8 */
33    u16 res1[4]; /* 0xa-0xd */
34    u16 cpld1v; /* 0xf */
35    u16 cpld2v; /* 0xe */
36};
37static struct easy98000_reg_cpld * const cpld =
38    (struct easy98000_reg_cpld *)(KSEG1 | 0x17c00000);
39#define cpld_r8(reg) (__raw_readw(&cpld->reg) & 0xFF)
40#define cpld_w8(val, reg) __raw_writew((val) & 0xFF, &cpld->reg)
41
42int easy98000_addon_has_dm9000(void)
43{
44    if ((cpld_r8(idreg0) & 0xF) == 1)
45        return 1;
46    return 0;
47}
48
49#if defined(CONFIG_PROC_FS)
50typedef void (*cpld_dump) (struct seq_file *s);
51struct proc_entry {
52    char *name;
53    void *callback;
54};
55
56static int cpld_proc_show ( struct seq_file *s, void *p )
57{
58    cpld_dump dump = s->private;
59
60    if ( dump != NULL )
61        dump(s);
62
63    return 0;
64}
65
66static int cpld_proc_open ( struct inode *inode, struct file *file )
67{
68    return single_open ( file, cpld_proc_show, PDE(inode)->data );
69}
70
71static void cpld_versions_get ( struct seq_file *s )
72{
73    seq_printf(s, "CPLD1: V%d\n", cpld_r8(cpld1v));
74    seq_printf(s, "CPLD2: V%d\n", cpld_r8(cpld2v));
75}
76
77static void cpld_ebu_module_get ( struct seq_file *s )
78{
79    u8 addon_id;
80
81    addon_id = cpld_r8(idreg0) & 0xF;
82    switch (addon_id) {
83    case 0xF: /* nothing connected */
84        break;
85    case 1:
86        seq_printf(s, "Ethernet Controller module (dm9000)\n");
87        break;
88    default:
89        seq_printf(s, "Unknown EBU module (EBU_ID=0x%02X)\n", addon_id);
90        break;
91    }
92}
93
94static void cpld_xmii_module_get ( struct seq_file *s )
95{
96    u8 addon_id;
97    char *mod = NULL;
98
99    addon_id = cpld_r8(idreg1) & 0xF;
100    switch (addon_id) {
101    case 0xF:
102        mod = "no module";
103        break;
104    case 0x1:
105        mod = "RGMII module";
106        break;
107    case 0x4:
108        mod = "GMII MAC Mode (XWAY TANTOS-3G)";
109        break;
110    case 0x6:
111        mod = "TMII MAC Mode (XWAY TANTOS-3G)";
112        break;
113    case 0x8:
114        mod = "GMII PHY module";
115        break;
116    case 0x9:
117        mod = "MII PHY module";
118        break;
119    case 0xA:
120        mod = "RMII PHY module";
121        break;
122    default:
123        break;
124    }
125    if (mod)
126        seq_printf(s, "%s\n", mod);
127    else
128        seq_printf(s, "unknown xMII module (xMII_ID=0x%02X)\n", addon_id);
129}
130
131static struct proc_entry proc_entries[] = {
132    {"versions", cpld_versions_get},
133    {"ebu", cpld_ebu_module_get},
134    {"xmii", cpld_xmii_module_get},
135};
136
137static struct file_operations ops = {
138    .owner = THIS_MODULE,
139    .open = cpld_proc_open,
140    .read = seq_read,
141    .llseek = seq_lseek,
142    .release = single_release,
143};
144
145static void cpld_proc_entry_create(struct proc_dir_entry *parent_node,
146                   struct proc_entry *proc_entry)
147{
148    proc_create_data ( proc_entry->name, (S_IFREG | S_IRUGO), parent_node,
149               &ops, proc_entry->callback);
150}
151
152static int cpld_proc_install(void)
153{
154    struct proc_dir_entry *driver_proc_node;
155
156    driver_proc_node = proc_mkdir("cpld", NULL);
157    if (driver_proc_node != NULL) {
158        int i;
159        for (i = 0; i < ARRAY_SIZE(proc_entries); i++)
160            cpld_proc_entry_create(driver_proc_node,
161                          &proc_entries[i]);
162    } else {
163        printk("cannot create proc entry");
164        return -1;
165    }
166    return 0;
167}
168#else
169static inline int cpld_proc_install(void) {}
170#endif
171
172static int easy98000_addon_probe(struct platform_device *pdev)
173{
174    return cpld_proc_install();
175}
176
177static int easy98000_addon_remove(struct platform_device *pdev)
178{
179#if defined(CONFIG_PROC_FS)
180    char buf[64];
181    int i;
182
183    for (i = 0; i < sizeof(proc_entries) / sizeof(proc_entries[0]); i++) {
184        sprintf(buf, "cpld/%s", proc_entries[i].name);
185        remove_proc_entry(buf, 0);
186    }
187    remove_proc_entry("cpld", 0);
188#endif
189    return 0;
190}
191
192static struct platform_driver easy98000_addon_driver = {
193    .probe = easy98000_addon_probe,
194    .remove = __devexit_p(easy98000_addon_remove),
195    .driver = {
196        .name = "easy98000_addon",
197        .owner = THIS_MODULE,
198    },
199};
200
201int __init easy98000_addon_init(void)
202{
203    return platform_driver_register(&easy98000_addon_driver);
204}
205
206void __exit easy98000_addon_exit(void)
207{
208    platform_driver_unregister(&easy98000_addon_driver);
209}
210
211module_init(easy98000_addon_init);
212module_exit(easy98000_addon_exit);
213

Archive Download this file



interactive