aboutsummaryrefslogtreecommitdiffstats
path: root/arch/mips/txx9/generic/7segled.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/mips/txx9/generic/7segled.c')
-rw-r--r--arch/mips/txx9/generic/7segled.c112
1 files changed, 112 insertions, 0 deletions
diff --git a/arch/mips/txx9/generic/7segled.c b/arch/mips/txx9/generic/7segled.c
new file mode 100644
index 000000000000..727ab21b6618
--- /dev/null
+++ b/arch/mips/txx9/generic/7segled.c
@@ -0,0 +1,112 @@
1/*
2 * 7 Segment LED routines
3 * Based on RBTX49xx patch from CELF patch archive.
4 *
5 * This file is subject to the terms and conditions of the GNU General Public
6 * License. See the file "COPYING" in the main directory of this archive
7 * for more details.
8 *
9 * (C) Copyright TOSHIBA CORPORATION 2005-2007
10 * All Rights Reserved.
11 */
12#include <linux/sysdev.h>
13#include <linux/slab.h>
14#include <linux/map_to_7segment.h>
15#include <asm/txx9/generic.h>
16
17static unsigned int tx_7segled_num;
18static void (*tx_7segled_putc)(unsigned int pos, unsigned char val);
19
20void __init txx9_7segled_init(unsigned int num,
21 void (*putc)(unsigned int pos, unsigned char val))
22{
23 tx_7segled_num = num;
24 tx_7segled_putc = putc;
25}
26
27static SEG7_CONVERSION_MAP(txx9_seg7map, MAP_ASCII7SEG_ALPHANUM_LC);
28
29int txx9_7segled_putc(unsigned int pos, char c)
30{
31 if (pos >= tx_7segled_num)
32 return -EINVAL;
33 c = map_to_seg7(&txx9_seg7map, c);
34 if (c < 0)
35 return c;
36 tx_7segled_putc(pos, c);
37 return 0;
38}
39
40static ssize_t ascii_store(struct sys_device *dev,
41 struct sysdev_attribute *attr,
42 const char *buf, size_t size)
43{
44 unsigned int ch = dev->id;
45 txx9_7segled_putc(ch, buf[0]);
46 return size;
47}
48
49static ssize_t raw_store(struct sys_device *dev,
50 struct sysdev_attribute *attr,
51 const char *buf, size_t size)
52{
53 unsigned int ch = dev->id;
54 tx_7segled_putc(ch, buf[0]);
55 return size;
56}
57
58static SYSDEV_ATTR(ascii, 0200, NULL, ascii_store);
59static SYSDEV_ATTR(raw, 0200, NULL, raw_store);
60
61static ssize_t map_seg7_show(struct sysdev_class *class, char *buf)
62{
63 memcpy(buf, &txx9_seg7map, sizeof(txx9_seg7map));
64 return sizeof(txx9_seg7map);
65}
66
67static ssize_t map_seg7_store(struct sysdev_class *class,
68 const char *buf, size_t size)
69{
70 if (size != sizeof(txx9_seg7map))
71 return -EINVAL;
72 memcpy(&txx9_seg7map, buf, size);
73 return size;
74}
75
76static SYSDEV_CLASS_ATTR(map_seg7, 0600, map_seg7_show, map_seg7_store);
77
78static struct sysdev_class tx_7segled_sysdev_class = {
79 .name = "7segled",
80};
81
82static int __init tx_7segled_init_sysfs(void)
83{
84 int error, i;
85 if (!tx_7segled_num)
86 return -ENODEV;
87 error = sysdev_class_register(&tx_7segled_sysdev_class);
88 if (error)
89 return error;
90 error = sysdev_class_create_file(&tx_7segled_sysdev_class,
91 &attr_map_seg7);
92 if (error)
93 return error;
94 for (i = 0; i < tx_7segled_num; i++) {
95 struct sys_device *dev;
96 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
97 if (!dev) {
98 error = -ENODEV;
99 break;
100 }
101 dev->id = i;
102 dev->cls = &tx_7segled_sysdev_class;
103 error = sysdev_register(dev);
104 if (!error) {
105 sysdev_create_file(dev, &attr_ascii);
106 sysdev_create_file(dev, &attr_raw);
107 }
108 }
109 return error;
110}
111
112device_initcall(tx_7segled_init_sysfs);