Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * File Attributes for Zorro Devices |
| 3 | * |
| 4 | * Copyright (C) 2003 Geert Uytterhoeven |
| 5 | * |
| 6 | * Loosely based on drivers/pci/pci-sysfs.c |
| 7 | * |
| 8 | * This file is subject to the terms and conditions of the GNU General Public |
| 9 | * License. See the file COPYING in the main directory of this archive |
| 10 | * for more details. |
| 11 | */ |
| 12 | |
| 13 | |
| 14 | #include <linux/kernel.h> |
| 15 | #include <linux/zorro.h> |
| 16 | #include <linux/stat.h> |
Tim Schmielau | 4e57b68 | 2005-10-30 15:03:48 -0800 | [diff] [blame] | 17 | #include <linux/string.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | |
| 19 | #include "zorro.h" |
| 20 | |
| 21 | |
| 22 | /* show configuration fields */ |
| 23 | #define zorro_config_attr(name, field, format_string) \ |
| 24 | static ssize_t \ |
Yani Ioannou | 060b884 | 2005-05-17 06:44:04 -0400 | [diff] [blame] | 25 | show_##name(struct device *dev, struct device_attribute *attr, char *buf) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | { \ |
| 27 | struct zorro_dev *z; \ |
| 28 | \ |
| 29 | z = to_zorro_dev(dev); \ |
| 30 | return sprintf(buf, format_string, z->field); \ |
| 31 | } \ |
| 32 | static DEVICE_ATTR(name, S_IRUGO, show_##name, NULL); |
| 33 | |
| 34 | zorro_config_attr(id, id, "0x%08x\n"); |
| 35 | zorro_config_attr(type, rom.er_Type, "0x%02x\n"); |
| 36 | zorro_config_attr(serial, rom.er_SerialNumber, "0x%08x\n"); |
| 37 | zorro_config_attr(slotaddr, slotaddr, "0x%04x\n"); |
| 38 | zorro_config_attr(slotsize, slotsize, "0x%04x\n"); |
| 39 | |
Yani Ioannou | 060b884 | 2005-05-17 06:44:04 -0400 | [diff] [blame] | 40 | static ssize_t zorro_show_resource(struct device *dev, struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | { |
| 42 | struct zorro_dev *z = to_zorro_dev(dev); |
| 43 | |
| 44 | return sprintf(buf, "0x%08lx 0x%08lx 0x%08lx\n", |
Geert Uytterhoeven | 3181757 | 2007-05-01 22:33:04 +0200 | [diff] [blame] | 45 | (unsigned long)zorro_resource_start(z), |
| 46 | (unsigned long)zorro_resource_end(z), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | zorro_resource_flags(z)); |
| 48 | } |
| 49 | |
| 50 | static DEVICE_ATTR(resource, S_IRUGO, zorro_show_resource, NULL); |
| 51 | |
Chris Wright | 2c3c8be | 2010-05-12 18:28:57 -0700 | [diff] [blame] | 52 | static ssize_t zorro_read_config(struct file *filp, struct kobject *kobj, |
Zhang Rui | 91a6902 | 2007-06-09 13:57:22 +0800 | [diff] [blame] | 53 | struct bin_attribute *bin_attr, |
| 54 | char *buf, loff_t off, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | { |
| 56 | struct zorro_dev *z = to_zorro_dev(container_of(kobj, struct device, |
| 57 | kobj)); |
| 58 | struct ConfigDev cd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | |
| 60 | /* Construct a ConfigDev */ |
| 61 | memset(&cd, 0, sizeof(cd)); |
| 62 | cd.cd_Rom = z->rom; |
| 63 | cd.cd_SlotAddr = z->slotaddr; |
| 64 | cd.cd_SlotSize = z->slotsize; |
| 65 | cd.cd_BoardAddr = (void *)zorro_resource_start(z); |
| 66 | cd.cd_BoardSize = zorro_resource_len(z); |
| 67 | |
akinobu.mita@gmail.com | fa7f289 | 2008-07-17 21:16:17 +0200 | [diff] [blame] | 68 | return memory_read_from_buffer(buf, count, &off, &cd, sizeof(cd)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | static struct bin_attribute zorro_config_attr = { |
| 72 | .attr = { |
| 73 | .name = "config", |
Geert Uytterhoeven | a010866 | 2007-08-22 14:01:34 -0700 | [diff] [blame] | 74 | .mode = S_IRUGO, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | }, |
| 76 | .size = sizeof(struct ConfigDev), |
| 77 | .read = zorro_read_config, |
| 78 | }; |
| 79 | |
Geert Uytterhoeven | bf54a2b | 2008-11-18 21:13:53 +0100 | [diff] [blame] | 80 | static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, |
| 81 | char *buf) |
| 82 | { |
| 83 | struct zorro_dev *z = to_zorro_dev(dev); |
| 84 | |
| 85 | return sprintf(buf, ZORRO_DEVICE_MODALIAS_FMT "\n", z->id); |
| 86 | } |
| 87 | |
| 88 | static DEVICE_ATTR(modalias, S_IRUGO, modalias_show, NULL); |
| 89 | |
Geert Uytterhoeven | 11a8b2c | 2008-12-30 14:21:19 +0100 | [diff] [blame] | 90 | int zorro_create_sysfs_dev_files(struct zorro_dev *z) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | { |
| 92 | struct device *dev = &z->dev; |
Geert Uytterhoeven | 11a8b2c | 2008-12-30 14:21:19 +0100 | [diff] [blame] | 93 | int error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | |
| 95 | /* current configuration's attributes */ |
Geert Uytterhoeven | 11a8b2c | 2008-12-30 14:21:19 +0100 | [diff] [blame] | 96 | if ((error = device_create_file(dev, &dev_attr_id)) || |
| 97 | (error = device_create_file(dev, &dev_attr_type)) || |
| 98 | (error = device_create_file(dev, &dev_attr_serial)) || |
| 99 | (error = device_create_file(dev, &dev_attr_slotaddr)) || |
| 100 | (error = device_create_file(dev, &dev_attr_slotsize)) || |
| 101 | (error = device_create_file(dev, &dev_attr_resource)) || |
Geert Uytterhoeven | bf54a2b | 2008-11-18 21:13:53 +0100 | [diff] [blame] | 102 | (error = device_create_file(dev, &dev_attr_modalias)) || |
Geert Uytterhoeven | 11a8b2c | 2008-12-30 14:21:19 +0100 | [diff] [blame] | 103 | (error = sysfs_create_bin_file(&dev->kobj, &zorro_config_attr))) |
| 104 | return error; |
| 105 | |
| 106 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | } |
| 108 | |