Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  * 7 Segment LED routines
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Based on RBTX49xx patch from CELF patch archive.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * This file is subject to the terms and conditions of the GNU General Public
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * License.  See the file "COPYING" in the main directory of this archive
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * (C) Copyright TOSHIBA CORPORATION 2005-2007
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * All Rights Reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/map_to_7segment.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <asm/txx9/generic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) static unsigned int tx_7segled_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) static void (*tx_7segled_putc)(unsigned int pos, unsigned char val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) void __init txx9_7segled_init(unsigned int num,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 			      void (*putc)(unsigned int pos, unsigned char val))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	tx_7segled_num = num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	tx_7segled_putc = putc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) static SEG7_CONVERSION_MAP(txx9_seg7map, MAP_ASCII7SEG_ALPHANUM_LC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) int txx9_7segled_putc(unsigned int pos, char c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	if (pos >= tx_7segled_num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	c = map_to_seg7(&txx9_seg7map, c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	if (c < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 		return c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	tx_7segled_putc(pos, c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) static ssize_t ascii_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 			   struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 			   const char *buf, size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	unsigned int ch = dev->id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	txx9_7segled_putc(ch, buf[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	return size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) static ssize_t raw_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 			 struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 			 const char *buf, size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	unsigned int ch = dev->id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	tx_7segled_putc(ch, buf[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	return size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) static DEVICE_ATTR_WO(ascii);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) static DEVICE_ATTR_WO(raw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) static ssize_t map_seg7_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 			     struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 			     char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	memcpy(buf, &txx9_seg7map, sizeof(txx9_seg7map));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	return sizeof(txx9_seg7map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) static ssize_t map_seg7_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 			      struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 			      const char *buf, size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	if (size != sizeof(txx9_seg7map))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	memcpy(&txx9_seg7map, buf, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	return size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) static DEVICE_ATTR(map_seg7, 0600, map_seg7_show, map_seg7_store);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) static struct bus_type tx_7segled_subsys = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	.name		= "7segled",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	.dev_name	= "7segled",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) static void tx_7segled_release(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	kfree(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) static int __init tx_7segled_init_sysfs(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	int error, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	if (!tx_7segled_num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	error = subsys_system_register(&tx_7segled_subsys, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	error = device_create_file(tx_7segled_subsys.dev_root, &dev_attr_map_seg7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	for (i = 0; i < tx_7segled_num; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		struct device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 		dev = kzalloc(sizeof(*dev), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		if (!dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 			error = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		dev->id = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		dev->bus = &tx_7segled_subsys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		dev->release = &tx_7segled_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		error = device_register(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 			put_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 			return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 		device_create_file(dev, &dev_attr_ascii);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		device_create_file(dev, &dev_attr_raw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) device_initcall(tx_7segled_init_sysfs);