2 * RapidIO Tsi568 switch support
4 * Copyright 2009-2010 Integrated Device Technology, Inc.
7 * - Modified switch operations initialization.
9 * Copyright 2005 MontaVista Software, Inc.
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version.
18 #include <linux/rio.h>
19 #include <linux/rio_drv.h>
20 #include <linux/rio_ids.h>
21 #include <linux/delay.h>
22 #include <linux/module.h>
25 /* Global (broadcast) route registers */
26 #define SPBC_ROUTE_CFG_DESTID 0x10070
27 #define SPBC_ROUTE_CFG_PORT 0x10074
29 /* Per port route registers */
30 #define SPP_ROUTE_CFG_DESTID(n) (0x11070 + 0x100*n)
31 #define SPP_ROUTE_CFG_PORT(n) (0x11074 + 0x100*n)
33 #define TSI568_SP_MODE(n) (0x11004 + 0x100*n)
34 #define TSI568_SP_MODE_PW_DIS 0x08000000
37 tsi568_route_add_entry(struct rio_mport *mport, u16 destid, u8 hopcount,
38 u16 table, u16 route_destid, u8 route_port)
40 if (table == RIO_GLOBAL_TABLE) {
41 rio_mport_write_config_32(mport, destid, hopcount,
42 SPBC_ROUTE_CFG_DESTID, route_destid);
43 rio_mport_write_config_32(mport, destid, hopcount,
44 SPBC_ROUTE_CFG_PORT, route_port);
46 rio_mport_write_config_32(mport, destid, hopcount,
47 SPP_ROUTE_CFG_DESTID(table),
49 rio_mport_write_config_32(mport, destid, hopcount,
50 SPP_ROUTE_CFG_PORT(table), route_port);
59 tsi568_route_get_entry(struct rio_mport *mport, u16 destid, u8 hopcount,
60 u16 table, u16 route_destid, u8 *route_port)
65 if (table == RIO_GLOBAL_TABLE) {
66 rio_mport_write_config_32(mport, destid, hopcount,
67 SPBC_ROUTE_CFG_DESTID, route_destid);
68 rio_mport_read_config_32(mport, destid, hopcount,
69 SPBC_ROUTE_CFG_PORT, &result);
71 rio_mport_write_config_32(mport, destid, hopcount,
72 SPP_ROUTE_CFG_DESTID(table),
74 rio_mport_read_config_32(mport, destid, hopcount,
75 SPP_ROUTE_CFG_PORT(table), &result);
86 tsi568_route_clr_table(struct rio_mport *mport, u16 destid, u8 hopcount,
92 lut_size = (mport->sys_size) ? 0x1ff : 0xff;
94 if (table == RIO_GLOBAL_TABLE) {
95 rio_mport_write_config_32(mport, destid, hopcount,
96 SPBC_ROUTE_CFG_DESTID, 0x80000000);
97 for (route_idx = 0; route_idx <= lut_size; route_idx++)
98 rio_mport_write_config_32(mport, destid, hopcount,
102 rio_mport_write_config_32(mport, destid, hopcount,
103 SPP_ROUTE_CFG_DESTID(table),
105 for (route_idx = 0; route_idx <= lut_size; route_idx++)
106 rio_mport_write_config_32(mport, destid, hopcount,
107 SPP_ROUTE_CFG_PORT(table),
115 tsi568_em_init(struct rio_dev *rdev)
120 pr_debug("TSI568 %s [%d:%d]\n", __func__, rdev->destid, rdev->hopcount);
122 /* Make sure that Port-Writes are disabled (for all ports) */
124 portnum < RIO_GET_TOTAL_PORTS(rdev->swpinfo); portnum++) {
125 rio_read_config_32(rdev, TSI568_SP_MODE(portnum), ®val);
126 rio_write_config_32(rdev, TSI568_SP_MODE(portnum),
127 regval | TSI568_SP_MODE_PW_DIS);
133 static struct rio_switch_ops tsi568_switch_ops = {
134 .owner = THIS_MODULE,
135 .add_entry = tsi568_route_add_entry,
136 .get_entry = tsi568_route_get_entry,
137 .clr_table = tsi568_route_clr_table,
140 .em_init = tsi568_em_init,
144 static int tsi568_probe(struct rio_dev *rdev, const struct rio_device_id *id)
146 pr_debug("RIO: %s for %s\n", __func__, rio_name(rdev));
148 spin_lock(&rdev->rswitch->lock);
150 if (rdev->rswitch->ops) {
151 spin_unlock(&rdev->rswitch->lock);
155 rdev->rswitch->ops = &tsi568_switch_ops;
156 spin_unlock(&rdev->rswitch->lock);
160 static void tsi568_remove(struct rio_dev *rdev)
162 pr_debug("RIO: %s for %s\n", __func__, rio_name(rdev));
163 spin_lock(&rdev->rswitch->lock);
164 if (rdev->rswitch->ops != &tsi568_switch_ops) {
165 spin_unlock(&rdev->rswitch->lock);
168 rdev->rswitch->ops = NULL;
169 spin_unlock(&rdev->rswitch->lock);
172 static const struct rio_device_id tsi568_id_table[] = {
173 {RIO_DEVICE(RIO_DID_TSI568, RIO_VID_TUNDRA)},
174 { 0, } /* terminate list */
177 static struct rio_driver tsi568_driver = {
179 .id_table = tsi568_id_table,
180 .probe = tsi568_probe,
181 .remove = tsi568_remove,
184 static int __init tsi568_init(void)
186 return rio_register_driver(&tsi568_driver);
189 static void __exit tsi568_exit(void)
191 rio_unregister_driver(&tsi568_driver);
194 device_initcall(tsi568_init);
195 module_exit(tsi568_exit);
197 MODULE_DESCRIPTION("IDT Tsi568 Serial RapidIO switch driver");
198 MODULE_AUTHOR("Integrated Device Technology, Inc.");
199 MODULE_LICENSE("GPL");