-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add sysfs interface for 7 segment LED and implement access routine for RBTX4939. Signed-off-by: Atsushi Nemoto <anemo@mba.ocn.ne.jp> Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
- Loading branch information
Atsushi Nemoto
authored and
Ralf Baechle
committed
Oct 27, 2008
1 parent
f591eb1
commit bc89b2b
Showing
5 changed files
with
153 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/* | ||
* 7 Segment LED routines | ||
* Based on RBTX49xx patch from CELF patch archive. | ||
* | ||
* This file is subject to the terms and conditions of the GNU General Public | ||
* License. See the file "COPYING" in the main directory of this archive | ||
* for more details. | ||
* | ||
* (C) Copyright TOSHIBA CORPORATION 2005-2007 | ||
* All Rights Reserved. | ||
*/ | ||
#include <linux/sysdev.h> | ||
#include <linux/slab.h> | ||
#include <linux/map_to_7segment.h> | ||
#include <asm/txx9/generic.h> | ||
|
||
static unsigned int tx_7segled_num; | ||
static void (*tx_7segled_putc)(unsigned int pos, unsigned char val); | ||
|
||
void __init txx9_7segled_init(unsigned int num, | ||
void (*putc)(unsigned int pos, unsigned char val)) | ||
{ | ||
tx_7segled_num = num; | ||
tx_7segled_putc = putc; | ||
} | ||
|
||
static SEG7_CONVERSION_MAP(txx9_seg7map, MAP_ASCII7SEG_ALPHANUM_LC); | ||
|
||
int txx9_7segled_putc(unsigned int pos, char c) | ||
{ | ||
if (pos >= tx_7segled_num) | ||
return -EINVAL; | ||
c = map_to_seg7(&txx9_seg7map, c); | ||
if (c < 0) | ||
return c; | ||
tx_7segled_putc(pos, c); | ||
return 0; | ||
} | ||
|
||
static ssize_t ascii_store(struct sys_device *dev, | ||
struct sysdev_attribute *attr, | ||
const char *buf, size_t size) | ||
{ | ||
unsigned int ch = dev->id; | ||
txx9_7segled_putc(ch, buf[0]); | ||
return size; | ||
} | ||
|
||
static ssize_t raw_store(struct sys_device *dev, | ||
struct sysdev_attribute *attr, | ||
const char *buf, size_t size) | ||
{ | ||
unsigned int ch = dev->id; | ||
tx_7segled_putc(ch, buf[0]); | ||
return size; | ||
} | ||
|
||
static SYSDEV_ATTR(ascii, 0200, NULL, ascii_store); | ||
static SYSDEV_ATTR(raw, 0200, NULL, raw_store); | ||
|
||
static ssize_t map_seg7_show(struct sysdev_class *class, char *buf) | ||
{ | ||
memcpy(buf, &txx9_seg7map, sizeof(txx9_seg7map)); | ||
return sizeof(txx9_seg7map); | ||
} | ||
|
||
static ssize_t map_seg7_store(struct sysdev_class *class, | ||
const char *buf, size_t size) | ||
{ | ||
if (size != sizeof(txx9_seg7map)) | ||
return -EINVAL; | ||
memcpy(&txx9_seg7map, buf, size); | ||
return size; | ||
} | ||
|
||
static SYSDEV_CLASS_ATTR(map_seg7, 0600, map_seg7_show, map_seg7_store); | ||
|
||
static struct sysdev_class tx_7segled_sysdev_class = { | ||
.name = "7segled", | ||
}; | ||
|
||
static int __init tx_7segled_init_sysfs(void) | ||
{ | ||
int error, i; | ||
if (!tx_7segled_num) | ||
return -ENODEV; | ||
error = sysdev_class_register(&tx_7segled_sysdev_class); | ||
if (error) | ||
return error; | ||
error = sysdev_class_create_file(&tx_7segled_sysdev_class, | ||
&attr_map_seg7); | ||
if (error) | ||
return error; | ||
for (i = 0; i < tx_7segled_num; i++) { | ||
struct sys_device *dev; | ||
dev = kzalloc(sizeof(*dev), GFP_KERNEL); | ||
if (!dev) { | ||
error = -ENODEV; | ||
break; | ||
} | ||
dev->id = i; | ||
dev->cls = &tx_7segled_sysdev_class; | ||
error = sysdev_register(dev); | ||
if (!error) { | ||
sysdev_create_file(dev, &attr_ascii); | ||
sysdev_create_file(dev, &attr_raw); | ||
} | ||
} | ||
return error; | ||
} | ||
|
||
device_initcall(tx_7segled_init_sysfs); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters