Path: blob/master/arch/mips/txx9/generic/7segled.c
10818 views
/*1* 7 Segment LED routines2* Based on RBTX49xx patch from CELF patch archive.3*4* This file is subject to the terms and conditions of the GNU General Public5* License. See the file "COPYING" in the main directory of this archive6* for more details.7*8* (C) Copyright TOSHIBA CORPORATION 2005-20079* All Rights Reserved.10*/11#include <linux/sysdev.h>12#include <linux/slab.h>13#include <linux/map_to_7segment.h>14#include <asm/txx9/generic.h>1516static unsigned int tx_7segled_num;17static void (*tx_7segled_putc)(unsigned int pos, unsigned char val);1819void __init txx9_7segled_init(unsigned int num,20void (*putc)(unsigned int pos, unsigned char val))21{22tx_7segled_num = num;23tx_7segled_putc = putc;24}2526static SEG7_CONVERSION_MAP(txx9_seg7map, MAP_ASCII7SEG_ALPHANUM_LC);2728int txx9_7segled_putc(unsigned int pos, char c)29{30if (pos >= tx_7segled_num)31return -EINVAL;32c = map_to_seg7(&txx9_seg7map, c);33if (c < 0)34return c;35tx_7segled_putc(pos, c);36return 0;37}3839static ssize_t ascii_store(struct sys_device *dev,40struct sysdev_attribute *attr,41const char *buf, size_t size)42{43unsigned int ch = dev->id;44txx9_7segled_putc(ch, buf[0]);45return size;46}4748static ssize_t raw_store(struct sys_device *dev,49struct sysdev_attribute *attr,50const char *buf, size_t size)51{52unsigned int ch = dev->id;53tx_7segled_putc(ch, buf[0]);54return size;55}5657static SYSDEV_ATTR(ascii, 0200, NULL, ascii_store);58static SYSDEV_ATTR(raw, 0200, NULL, raw_store);5960static ssize_t map_seg7_show(struct sysdev_class *class,61struct sysdev_class_attribute *attr,62char *buf)63{64memcpy(buf, &txx9_seg7map, sizeof(txx9_seg7map));65return sizeof(txx9_seg7map);66}6768static ssize_t map_seg7_store(struct sysdev_class *class,69struct sysdev_class_attribute *attr,70const char *buf, size_t size)71{72if (size != sizeof(txx9_seg7map))73return -EINVAL;74memcpy(&txx9_seg7map, buf, size);75return size;76}7778static SYSDEV_CLASS_ATTR(map_seg7, 0600, map_seg7_show, map_seg7_store);7980static struct sysdev_class tx_7segled_sysdev_class = {81.name = "7segled",82};8384static int __init tx_7segled_init_sysfs(void)85{86int error, i;87if (!tx_7segled_num)88return -ENODEV;89error = sysdev_class_register(&tx_7segled_sysdev_class);90if (error)91return error;92error = sysdev_class_create_file(&tx_7segled_sysdev_class,93&attr_map_seg7);94if (error)95return error;96for (i = 0; i < tx_7segled_num; i++) {97struct sys_device *dev;98dev = kzalloc(sizeof(*dev), GFP_KERNEL);99if (!dev) {100error = -ENODEV;101break;102}103dev->id = i;104dev->cls = &tx_7segled_sysdev_class;105error = sysdev_register(dev);106if (!error) {107sysdev_create_file(dev, &attr_ascii);108sysdev_create_file(dev, &attr_raw);109}110}111return error;112}113114device_initcall(tx_7segled_init_sysfs);115116117