2 * EASY98000 CPLD Addon driver
4 * Copyright (C) 2011 Thomas Langer <thomas.langer@lantiq.com>
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.
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>
22 struct easy98000_reg_cpld
{
23 u16 cmdreg1
; /* 0x1 */
24 u16 cmdreg0
; /* 0x0 */
30 u16 pcmconconfig
; /* 0x6 */
32 u16 ethledreg
; /* 0x8 */
33 u16 res1
[4]; /* 0xa-0xd */
37 static 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)
42 int easy98000_addon_has_dm9000(void)
44 if ((cpld_r8(idreg0
) & 0xF) == 1)
49 #if defined(CONFIG_PROC_FS)
50 typedef void (*cpld_dump
) (struct seq_file
*s
);
56 static int cpld_proc_show ( struct seq_file
*s
, void *p
)
58 cpld_dump dump
= s
->private;
66 static int cpld_proc_open ( struct inode
*inode
, struct file
*file
)
68 return single_open ( file
, cpld_proc_show
, PDE(inode
)->data
);
71 static void cpld_versions_get ( struct seq_file
*s
)
73 seq_printf(s
, "CPLD1: V%d\n", cpld_r8(cpld1v
));
74 seq_printf(s
, "CPLD2: V%d\n", cpld_r8(cpld2v
));
77 static void cpld_ebu_module_get ( struct seq_file
*s
)
81 addon_id
= cpld_r8(idreg0
) & 0xF;
83 case 0xF: /* nothing connected */
86 seq_printf(s
, "Ethernet Controller module (dm9000)\n");
89 seq_printf(s
, "Unknown EBU module (EBU_ID=0x%02X)\n", addon_id
);
94 static void cpld_xmii_module_get ( struct seq_file
*s
)
99 addon_id
= cpld_r8(idreg1
) & 0xF;
105 mod
= "RGMII module";
108 mod
= "GMII MAC Mode (XWAY TANTOS-3G)";
111 mod
= "TMII MAC Mode (XWAY TANTOS-3G)";
114 mod
= "GMII PHY module";
117 mod
= "MII PHY module";
120 mod
= "RMII PHY module";
126 seq_printf(s
, "%s\n", mod
);
128 seq_printf(s
, "unknown xMII module (xMII_ID=0x%02X)\n", addon_id
);
131 static struct proc_entry proc_entries
[] = {
132 {"versions", cpld_versions_get
},
133 {"ebu", cpld_ebu_module_get
},
134 {"xmii", cpld_xmii_module_get
},
137 static struct file_operations ops
= {
138 .owner
= THIS_MODULE
,
139 .open
= cpld_proc_open
,
142 .release
= single_release
,
145 static void cpld_proc_entry_create(struct proc_dir_entry
*parent_node
,
146 struct proc_entry
*proc_entry
)
148 proc_create_data ( proc_entry
->name
, (S_IFREG
| S_IRUGO
), parent_node
,
149 &ops
, proc_entry
->callback
);
152 static int cpld_proc_install(void)
154 struct proc_dir_entry
*driver_proc_node
;
156 driver_proc_node
= proc_mkdir("cpld", NULL
);
157 if (driver_proc_node
!= NULL
) {
159 for (i
= 0; i
< ARRAY_SIZE(proc_entries
); i
++)
160 cpld_proc_entry_create(driver_proc_node
,
163 printk("cannot create proc entry");
169 static inline int cpld_proc_install(void) {}
172 static int easy98000_addon_probe(struct platform_device
*pdev
)
174 return cpld_proc_install();
177 static int easy98000_addon_remove(struct platform_device
*pdev
)
179 #if defined(CONFIG_PROC_FS)
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);
187 remove_proc_entry("cpld", 0);
192 static struct platform_driver easy98000_addon_driver
= {
193 .probe
= easy98000_addon_probe
,
194 .remove
= __devexit_p(easy98000_addon_remove
),
196 .name
= "easy98000_addon",
197 .owner
= THIS_MODULE
,
201 int __init
easy98000_addon_init(void)
203 return platform_driver_register(&easy98000_addon_driver
);
206 void __exit
easy98000_addon_exit(void)
208 platform_driver_unregister(&easy98000_addon_driver
);
211 module_init(easy98000_addon_init
);
212 module_exit(easy98000_addon_exit
);