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/module.h>
14 #include <linux/version.h>
15 #include <linux/types.h>
16 #include <linux/init.h>
17 #include <linux/platform_device.h>
18 #include <linux/errno.h>
19 #include <linux/slab.h>
20 #include <linux/proc_fs.h>
21 #include <linux/seq_file.h>
23 struct easy98000_reg_cpld
{
24 u16 cmdreg1
; /* 0x1 */
25 u16 cmdreg0
; /* 0x0 */
31 u16 pcmconconfig
; /* 0x6 */
33 u16 ethledreg
; /* 0x8 */
34 u16 res1
[4]; /* 0xa-0xd */
38 static struct easy98000_reg_cpld
* const cpld
=
39 (struct easy98000_reg_cpld
*)(KSEG1
| 0x17c00000);
40 #define cpld_r8(reg) (__raw_readw(&cpld->reg) & 0xFF)
41 #define cpld_w8(val, reg) __raw_writew((val) & 0xFF, &cpld->reg)
43 int easy98000_addon_has_dm9000(void)
45 if ((cpld_r8(idreg0
) & 0xF) == 1)
50 #if defined(CONFIG_PROC_FS)
51 typedef void (*cpld_dump
) (struct seq_file
*s
);
57 static int cpld_proc_show ( struct seq_file
*s
, void *p
)
59 cpld_dump dump
= s
->private;
67 static int cpld_proc_open ( struct inode
*inode
, struct file
*file
)
69 return single_open ( file
, cpld_proc_show
, PDE(inode
)->data
);
72 static void cpld_versions_get ( struct seq_file
*s
)
74 seq_printf(s
, "CPLD1: V%d\n", cpld_r8(cpld1v
));
75 seq_printf(s
, "CPLD2: V%d\n", cpld_r8(cpld2v
));
78 static void cpld_ebu_module_get ( struct seq_file
*s
)
82 addon_id
= cpld_r8(idreg0
) & 0xF;
84 case 0xF: /* nothing connected */
87 seq_printf(s
, "Ethernet Controller module (dm9000)\n");
90 seq_printf(s
, "Unknown EBU module (EBU_ID=0x%02X)\n", addon_id
);
95 static void cpld_xmii_module_get ( struct seq_file
*s
)
100 addon_id
= cpld_r8(idreg1
) & 0xF;
106 mod
= "RGMII module";
109 mod
= "GMII MAC Mode (XWAY TANTOS-3G)";
112 mod
= "TMII MAC Mode (XWAY TANTOS-3G)";
115 mod
= "GMII PHY module";
118 mod
= "MII PHY module";
121 mod
= "RMII PHY module";
127 seq_printf(s
, "%s\n", mod
);
129 seq_printf(s
, "unknown xMII module (xMII_ID=0x%02X)\n", addon_id
);
132 static struct proc_entry proc_entries
[] = {
133 {"versions", cpld_versions_get
},
134 {"ebu", cpld_ebu_module_get
},
135 {"xmii", cpld_xmii_module_get
},
138 static struct file_operations ops
= {
139 .owner
= THIS_MODULE
,
140 .open
= cpld_proc_open
,
143 .release
= single_release
,
146 static void cpld_proc_entry_create(struct proc_dir_entry
*parent_node
,
147 struct proc_entry
*proc_entry
)
149 proc_create_data ( proc_entry
->name
, (S_IFREG
| S_IRUGO
), parent_node
,
150 &ops
, proc_entry
->callback
);
153 static int cpld_proc_install(void)
155 struct proc_dir_entry
*driver_proc_node
;
157 driver_proc_node
= proc_mkdir("cpld", NULL
);
158 if (driver_proc_node
!= NULL
) {
160 for (i
= 0; i
< ARRAY_SIZE(proc_entries
); i
++)
161 cpld_proc_entry_create(driver_proc_node
,
164 printk("cannot create proc entry");
170 static inline int cpld_proc_install(void) {}
173 static int easy98000_addon_probe(struct platform_device
*pdev
)
175 return cpld_proc_install();
178 static int easy98000_addon_remove(struct platform_device
*pdev
)
180 #if defined(CONFIG_PROC_FS)
184 for (i
= 0; i
< sizeof(proc_entries
) / sizeof(proc_entries
[0]); i
++) {
185 sprintf(buf
, "cpld/%s", proc_entries
[i
].name
);
186 remove_proc_entry(buf
, 0);
188 remove_proc_entry("cpld", 0);
193 static struct platform_driver easy98000_addon_driver
= {
194 .probe
= easy98000_addon_probe
,
195 .remove
= __devexit_p(easy98000_addon_remove
),
197 .name
= "easy98000_addon",
198 .owner
= THIS_MODULE
,
202 int __init
easy98000_addon_init(void)
204 return platform_driver_register(&easy98000_addon_driver
);
207 void __exit
easy98000_addon_exit(void)
209 platform_driver_unregister(&easy98000_addon_driver
);
212 module_init(easy98000_addon_init
);
213 module_exit(easy98000_addon_exit
);