18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * 7 Segment LED routines 38c2ecf20Sopenharmony_ci * Based on RBTX49xx patch from CELF patch archive. 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * This file is subject to the terms and conditions of the GNU General Public 68c2ecf20Sopenharmony_ci * License. See the file "COPYING" in the main directory of this archive 78c2ecf20Sopenharmony_ci * for more details. 88c2ecf20Sopenharmony_ci * 98c2ecf20Sopenharmony_ci * (C) Copyright TOSHIBA CORPORATION 2005-2007 108c2ecf20Sopenharmony_ci * All Rights Reserved. 118c2ecf20Sopenharmony_ci */ 128c2ecf20Sopenharmony_ci#include <linux/device.h> 138c2ecf20Sopenharmony_ci#include <linux/slab.h> 148c2ecf20Sopenharmony_ci#include <linux/map_to_7segment.h> 158c2ecf20Sopenharmony_ci#include <asm/txx9/generic.h> 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_cistatic unsigned int tx_7segled_num; 188c2ecf20Sopenharmony_cistatic void (*tx_7segled_putc)(unsigned int pos, unsigned char val); 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_civoid __init txx9_7segled_init(unsigned int num, 218c2ecf20Sopenharmony_ci void (*putc)(unsigned int pos, unsigned char val)) 228c2ecf20Sopenharmony_ci{ 238c2ecf20Sopenharmony_ci tx_7segled_num = num; 248c2ecf20Sopenharmony_ci tx_7segled_putc = putc; 258c2ecf20Sopenharmony_ci} 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_cistatic SEG7_CONVERSION_MAP(txx9_seg7map, MAP_ASCII7SEG_ALPHANUM_LC); 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_ciint txx9_7segled_putc(unsigned int pos, char c) 308c2ecf20Sopenharmony_ci{ 318c2ecf20Sopenharmony_ci if (pos >= tx_7segled_num) 328c2ecf20Sopenharmony_ci return -EINVAL; 338c2ecf20Sopenharmony_ci c = map_to_seg7(&txx9_seg7map, c); 348c2ecf20Sopenharmony_ci if (c < 0) 358c2ecf20Sopenharmony_ci return c; 368c2ecf20Sopenharmony_ci tx_7segled_putc(pos, c); 378c2ecf20Sopenharmony_ci return 0; 388c2ecf20Sopenharmony_ci} 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_cistatic ssize_t ascii_store(struct device *dev, 418c2ecf20Sopenharmony_ci struct device_attribute *attr, 428c2ecf20Sopenharmony_ci const char *buf, size_t size) 438c2ecf20Sopenharmony_ci{ 448c2ecf20Sopenharmony_ci unsigned int ch = dev->id; 458c2ecf20Sopenharmony_ci txx9_7segled_putc(ch, buf[0]); 468c2ecf20Sopenharmony_ci return size; 478c2ecf20Sopenharmony_ci} 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_cistatic ssize_t raw_store(struct device *dev, 508c2ecf20Sopenharmony_ci struct device_attribute *attr, 518c2ecf20Sopenharmony_ci const char *buf, size_t size) 528c2ecf20Sopenharmony_ci{ 538c2ecf20Sopenharmony_ci unsigned int ch = dev->id; 548c2ecf20Sopenharmony_ci tx_7segled_putc(ch, buf[0]); 558c2ecf20Sopenharmony_ci return size; 568c2ecf20Sopenharmony_ci} 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_cistatic DEVICE_ATTR_WO(ascii); 598c2ecf20Sopenharmony_cistatic DEVICE_ATTR_WO(raw); 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_cistatic ssize_t map_seg7_show(struct device *dev, 628c2ecf20Sopenharmony_ci struct device_attribute *attr, 638c2ecf20Sopenharmony_ci char *buf) 648c2ecf20Sopenharmony_ci{ 658c2ecf20Sopenharmony_ci memcpy(buf, &txx9_seg7map, sizeof(txx9_seg7map)); 668c2ecf20Sopenharmony_ci return sizeof(txx9_seg7map); 678c2ecf20Sopenharmony_ci} 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_cistatic ssize_t map_seg7_store(struct device *dev, 708c2ecf20Sopenharmony_ci struct device_attribute *attr, 718c2ecf20Sopenharmony_ci const char *buf, size_t size) 728c2ecf20Sopenharmony_ci{ 738c2ecf20Sopenharmony_ci if (size != sizeof(txx9_seg7map)) 748c2ecf20Sopenharmony_ci return -EINVAL; 758c2ecf20Sopenharmony_ci memcpy(&txx9_seg7map, buf, size); 768c2ecf20Sopenharmony_ci return size; 778c2ecf20Sopenharmony_ci} 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_cistatic DEVICE_ATTR(map_seg7, 0600, map_seg7_show, map_seg7_store); 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_cistatic struct bus_type tx_7segled_subsys = { 828c2ecf20Sopenharmony_ci .name = "7segled", 838c2ecf20Sopenharmony_ci .dev_name = "7segled", 848c2ecf20Sopenharmony_ci}; 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_cistatic void tx_7segled_release(struct device *dev) 878c2ecf20Sopenharmony_ci{ 888c2ecf20Sopenharmony_ci kfree(dev); 898c2ecf20Sopenharmony_ci} 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_cistatic int __init tx_7segled_init_sysfs(void) 928c2ecf20Sopenharmony_ci{ 938c2ecf20Sopenharmony_ci int error, i; 948c2ecf20Sopenharmony_ci if (!tx_7segled_num) 958c2ecf20Sopenharmony_ci return -ENODEV; 968c2ecf20Sopenharmony_ci error = subsys_system_register(&tx_7segled_subsys, NULL); 978c2ecf20Sopenharmony_ci if (error) 988c2ecf20Sopenharmony_ci return error; 998c2ecf20Sopenharmony_ci error = device_create_file(tx_7segled_subsys.dev_root, &dev_attr_map_seg7); 1008c2ecf20Sopenharmony_ci if (error) 1018c2ecf20Sopenharmony_ci return error; 1028c2ecf20Sopenharmony_ci for (i = 0; i < tx_7segled_num; i++) { 1038c2ecf20Sopenharmony_ci struct device *dev; 1048c2ecf20Sopenharmony_ci dev = kzalloc(sizeof(*dev), GFP_KERNEL); 1058c2ecf20Sopenharmony_ci if (!dev) { 1068c2ecf20Sopenharmony_ci error = -ENODEV; 1078c2ecf20Sopenharmony_ci break; 1088c2ecf20Sopenharmony_ci } 1098c2ecf20Sopenharmony_ci dev->id = i; 1108c2ecf20Sopenharmony_ci dev->bus = &tx_7segled_subsys; 1118c2ecf20Sopenharmony_ci dev->release = &tx_7segled_release; 1128c2ecf20Sopenharmony_ci error = device_register(dev); 1138c2ecf20Sopenharmony_ci if (error) { 1148c2ecf20Sopenharmony_ci put_device(dev); 1158c2ecf20Sopenharmony_ci return error; 1168c2ecf20Sopenharmony_ci } 1178c2ecf20Sopenharmony_ci device_create_file(dev, &dev_attr_ascii); 1188c2ecf20Sopenharmony_ci device_create_file(dev, &dev_attr_raw); 1198c2ecf20Sopenharmony_ci } 1208c2ecf20Sopenharmony_ci return error; 1218c2ecf20Sopenharmony_ci} 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_cidevice_initcall(tx_7segled_init_sysfs); 124