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) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * arch/sh/drivers/dma/dma-sysfs.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * sysfs interface for SH DMA API
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Copyright (C) 2004 - 2006  Paul Mundt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/stat.h>
^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/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <asm/dma.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) static struct bus_type dma_subsys = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 	.name = "dma",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 	.dev_name = "dma",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) static ssize_t dma_show_devices(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 				struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	ssize_t len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	for (i = 0; i < 16; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 		struct dma_info *info = get_dma_info(i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 		struct dma_channel *channel = get_dma_channel(i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 		if (unlikely(!info) || !channel)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 		len += sprintf(buf + len, "%2d: %14s    %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 			       channel->chan, info->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 			       channel->dev_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) static DEVICE_ATTR(devices, S_IRUGO, dma_show_devices, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) static int __init dma_subsys_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	ret = subsys_system_register(&dma_subsys, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	if (unlikely(ret))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	return device_create_file(dma_subsys.dev_root, &dev_attr_devices);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) postcore_initcall(dma_subsys_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) static ssize_t dma_show_dev_id(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 				struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	struct dma_channel *channel = to_dma_channel(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	return sprintf(buf, "%s\n", channel->dev_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) static ssize_t dma_store_dev_id(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 				struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 				const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	struct dma_channel *channel = to_dma_channel(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	strcpy(channel->dev_id, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) static DEVICE_ATTR(dev_id, S_IRUGO | S_IWUSR, dma_show_dev_id, dma_store_dev_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) static ssize_t dma_store_config(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 				struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 				const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	struct dma_channel *channel = to_dma_channel(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	unsigned long config;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	config = simple_strtoul(buf, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	dma_configure_channel(channel->vchan, config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) static DEVICE_ATTR(config, S_IWUSR, NULL, dma_store_config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) static ssize_t dma_show_mode(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 				struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	struct dma_channel *channel = to_dma_channel(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	return sprintf(buf, "0x%08x\n", channel->mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) static ssize_t dma_store_mode(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 			      struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 			      const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	struct dma_channel *channel = to_dma_channel(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	channel->mode = simple_strtoul(buf, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) static DEVICE_ATTR(mode, S_IRUGO | S_IWUSR, dma_show_mode, dma_store_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) #define dma_ro_attr(field, fmt)						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) static ssize_t dma_show_##field(struct device *dev,		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 				struct device_attribute *attr, char *buf)\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) {									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	struct dma_channel *channel = to_dma_channel(dev);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	return sprintf(buf, fmt, channel->field);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) }									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) static DEVICE_ATTR(field, S_IRUGO, dma_show_##field, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) dma_ro_attr(count, "0x%08x\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) dma_ro_attr(flags, "0x%08lx\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) int dma_create_sysfs_files(struct dma_channel *chan, struct dma_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	struct device *dev = &chan->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	char name[16];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	dev->id  = chan->vchan;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	dev->bus = &dma_subsys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	ret = device_register(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	ret |= device_create_file(dev, &dev_attr_dev_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	ret |= device_create_file(dev, &dev_attr_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	ret |= device_create_file(dev, &dev_attr_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	ret |= device_create_file(dev, &dev_attr_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	ret |= device_create_file(dev, &dev_attr_config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	if (unlikely(ret)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		dev_err(&info->pdev->dev, "Failed creating attrs\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	snprintf(name, sizeof(name), "dma%d", chan->chan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	return sysfs_create_link(&info->pdev->dev.kobj, &dev->kobj, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) void dma_remove_sysfs_files(struct dma_channel *chan, struct dma_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	struct device *dev = &chan->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	char name[16];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	device_remove_file(dev, &dev_attr_dev_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	device_remove_file(dev, &dev_attr_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	device_remove_file(dev, &dev_attr_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	device_remove_file(dev, &dev_attr_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	device_remove_file(dev, &dev_attr_config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	snprintf(name, sizeof(name), "dma%d", chan->chan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	sysfs_remove_link(&info->pdev->dev.kobj, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	device_unregister(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) }