Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * CTC / LCS ccw_device driver |
| 3 | * |
| 4 | * Copyright (C) 2002 IBM Deutschland Entwicklung GmbH, IBM Corporation |
| 5 | * Author(s): Arnd Bergmann <arndb@de.ibm.com> |
Cornelia Huck | 4ce3b30 | 2006-01-14 13:21:04 -0800 | [diff] [blame] | 6 | * Cornelia Huck <cornelia.huck@de.ibm.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2, or (at your option) |
| 11 | * any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 21 | * |
| 22 | */ |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame^] | 23 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <linux/init.h> |
| 25 | #include <linux/module.h> |
| 26 | #include <linux/err.h> |
| 27 | |
Carsten Otte | cfb1b55 | 2006-01-06 00:19:14 -0800 | [diff] [blame] | 28 | #include <asm/s390_rdev.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include <asm/ccwdev.h> |
| 30 | #include <asm/ccwgroup.h> |
| 31 | |
| 32 | #include "cu3088.h" |
| 33 | |
| 34 | const char *cu3088_type[] = { |
| 35 | "not a channel", |
| 36 | "CTC/A", |
| 37 | "ESCON channel", |
| 38 | "FICON channel", |
| 39 | "P390 LCS card", |
| 40 | "OSA LCS card", |
Frank Pavlic | 321de3c | 2005-05-12 20:17:46 +0200 | [diff] [blame] | 41 | "CLAW channel device", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | "unknown channel type", |
| 43 | "unsupported channel type", |
| 44 | }; |
| 45 | |
| 46 | /* static definitions */ |
| 47 | |
| 48 | static struct ccw_device_id cu3088_ids[] = { |
| 49 | { CCW_DEVICE(0x3088, 0x08), .driver_info = channel_type_parallel }, |
| 50 | { CCW_DEVICE(0x3088, 0x1f), .driver_info = channel_type_escon }, |
| 51 | { CCW_DEVICE(0x3088, 0x1e), .driver_info = channel_type_ficon }, |
| 52 | { CCW_DEVICE(0x3088, 0x01), .driver_info = channel_type_p390 }, |
| 53 | { CCW_DEVICE(0x3088, 0x60), .driver_info = channel_type_osa2 }, |
Frank Pavlic | 321de3c | 2005-05-12 20:17:46 +0200 | [diff] [blame] | 54 | { CCW_DEVICE(0x3088, 0x61), .driver_info = channel_type_claw }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | { /* end of list */ } |
| 56 | }; |
| 57 | |
| 58 | static struct ccw_driver cu3088_driver; |
| 59 | |
| 60 | struct device *cu3088_root_dev; |
| 61 | |
| 62 | static ssize_t |
| 63 | group_write(struct device_driver *drv, const char *buf, size_t count) |
| 64 | { |
| 65 | const char *start, *end; |
| 66 | char bus_ids[2][BUS_ID_SIZE], *argv[2]; |
| 67 | int i; |
| 68 | int ret; |
| 69 | struct ccwgroup_driver *cdrv; |
| 70 | |
| 71 | cdrv = to_ccwgroupdrv(drv); |
| 72 | if (!cdrv) |
| 73 | return -EINVAL; |
| 74 | start = buf; |
| 75 | for (i=0; i<2; i++) { |
| 76 | static const char delim[] = {',', '\n'}; |
| 77 | int len; |
| 78 | |
| 79 | if (!(end = strchr(start, delim[i]))) |
Cornelia Huck | 7401a46 | 2006-05-24 09:51:05 +0200 | [diff] [blame] | 80 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | len = min_t(ptrdiff_t, BUS_ID_SIZE, end - start + 1); |
| 82 | strlcpy (bus_ids[i], start, len); |
| 83 | argv[i] = bus_ids[i]; |
| 84 | start = end + 1; |
| 85 | } |
| 86 | |
| 87 | ret = ccwgroup_create(cu3088_root_dev, cdrv->driver_id, |
| 88 | &cu3088_driver, 2, argv); |
| 89 | |
| 90 | return (ret == 0) ? count : ret; |
| 91 | } |
| 92 | |
| 93 | static DRIVER_ATTR(group, 0200, NULL, group_write); |
| 94 | |
| 95 | /* Register-unregister for ctc&lcs */ |
| 96 | int |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame^] | 97 | register_cu3088_discipline(struct ccwgroup_driver *dcp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | { |
| 99 | int rc; |
| 100 | |
| 101 | if (!dcp) |
| 102 | return -EINVAL; |
| 103 | |
| 104 | /* Register discipline.*/ |
| 105 | rc = ccwgroup_driver_register(dcp); |
| 106 | if (rc) |
| 107 | return rc; |
| 108 | |
| 109 | rc = driver_create_file(&dcp->driver, &driver_attr_group); |
| 110 | if (rc) |
| 111 | ccwgroup_driver_unregister(dcp); |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame^] | 112 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | return rc; |
| 114 | |
| 115 | } |
| 116 | |
| 117 | void |
| 118 | unregister_cu3088_discipline(struct ccwgroup_driver *dcp) |
| 119 | { |
| 120 | if (!dcp) |
| 121 | return; |
| 122 | |
| 123 | driver_remove_file(&dcp->driver, &driver_attr_group); |
| 124 | ccwgroup_driver_unregister(dcp); |
| 125 | } |
| 126 | |
| 127 | static struct ccw_driver cu3088_driver = { |
| 128 | .owner = THIS_MODULE, |
| 129 | .ids = cu3088_ids, |
| 130 | .name = "cu3088", |
| 131 | .probe = ccwgroup_probe_ccwdev, |
| 132 | .remove = ccwgroup_remove_ccwdev, |
| 133 | }; |
| 134 | |
| 135 | /* module setup */ |
| 136 | static int __init |
| 137 | cu3088_init (void) |
| 138 | { |
| 139 | int rc; |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame^] | 140 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | cu3088_root_dev = s390_root_dev_register("cu3088"); |
| 142 | if (IS_ERR(cu3088_root_dev)) |
| 143 | return PTR_ERR(cu3088_root_dev); |
| 144 | rc = ccw_driver_register(&cu3088_driver); |
| 145 | if (rc) |
| 146 | s390_root_dev_unregister(cu3088_root_dev); |
| 147 | |
| 148 | return rc; |
| 149 | } |
| 150 | |
| 151 | static void __exit |
| 152 | cu3088_exit (void) |
| 153 | { |
| 154 | ccw_driver_unregister(&cu3088_driver); |
| 155 | s390_root_dev_unregister(cu3088_root_dev); |
| 156 | } |
| 157 | |
| 158 | MODULE_DEVICE_TABLE(ccw,cu3088_ids); |
| 159 | MODULE_AUTHOR("Arnd Bergmann <arndb@de.ibm.com>"); |
| 160 | MODULE_LICENSE("GPL"); |
| 161 | |
| 162 | module_init(cu3088_init); |
| 163 | module_exit(cu3088_exit); |
| 164 | |
| 165 | EXPORT_SYMBOL_GPL(cu3088_type); |
| 166 | EXPORT_SYMBOL_GPL(register_cu3088_discipline); |
| 167 | EXPORT_SYMBOL_GPL(unregister_cu3088_discipline); |