2 * arch/ubicom32/mach-common/switch-bcm539x.c
3 * BCM539X switch driver, SPI mode
5 * (C) Copyright 2009, Ubicom, Inc.
7 * This file is part of the Ubicom32 Linux Kernel Port.
9 * The Ubicom32 Linux Kernel Port is free software: you can redistribute
10 * it and/or modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation, either version 2 of the
12 * License, or (at your option) any later version.
14 * The Ubicom32 Linux Kernel Port is distributed in the hope that it
15 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
16 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
17 * the GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with the Ubicom32 Linux Kernel Port. If not,
21 * see <http://www.gnu.org/licenses/>.
23 * Ubicom32 implementation derived from (with many thanks):
29 #include <linux/platform_device.h>
30 #include <linux/spi/spi.h>
31 #include <linux/gpio.h>
32 #include <linux/delay.h>
33 #include <linux/mii.h>
35 #include <asm/switch-dev.h>
36 #include <asm/ubicom32-spi-gpio.h>
37 #include "switch-core.h"
38 #include "switch-bcm539x-reg.h"
40 #define DRIVER_NAME "bcm539x-spi"
41 #define DRIVER_VERSION "1.0"
44 #define BCM539X_SPI_RETRIES 100
47 struct switch_device *switch_dev;
52 struct spi_device *spi;
53 struct switch_core_platform_data *pdata;
56 * Last page we accessed
68 * Waits for the specified bit in the status register to be set/cleared.
70 static int bcm539x_wait_status(struct bcm539x_data *bd, u8_t mask, int set)
77 txbuf[0] = BCM539X_CMD_READ;
78 txbuf[1] = BCM539X_GLOBAL_SPI_STATUS;
79 for (i = 0; i < BCM539X_SPI_RETRIES; i++) {
80 ret = spi_write_then_read(bd->spi, txbuf, 2, &rxbuf, 1);
82 if ((set && rxbuf) || (!set && !rxbuf)) {
93 * Sets the register page for access (only if necessary)
95 static int bcm539x_set_page(struct bcm539x_data *bd, u8_t page)
99 if (page == bd->last_page) {
103 bd->last_page = page;
105 txbuf[0] = BCM539X_CMD_WRITE;
106 txbuf[1] = BCM539X_GLOBAL_PAGE;
109 return spi_write(bd->spi, txbuf, 3);
113 * bcm539x_write_bytes
114 * Writes a number of bytes to a given page and register
116 static int bcm539x_write_bytes(struct bcm539x_data *bd, u8_t page,
117 u8_t reg, void *buf, u8_t len)
122 txbuf = kmalloc(2 + len, GFP_KERNEL);
128 * Make sure the chip has finished processing our previous request
130 ret = bcm539x_wait_status(bd, BCM539X_GLOBAL_SPI_ST_SPIF, 0);
138 ret = bcm539x_set_page(bd, page);
146 txbuf[0] = BCM539X_CMD_WRITE;
148 memcpy(&txbuf[2], buf, len);
153 printk("write page %02x reg %02x len=%d buf=", page, reg, len);
154 for (i = 0; i < len + 2; i++) {
155 printk("%02x ", txbuf[i]);
161 ret = spi_write(bd->spi, txbuf, 2 + len);
170 * Writes 32 bits of data to the given page and register
172 static inline int bcm539x_write_32(struct bcm539x_data *bd, u8_t page,
173 u8_t reg, u32_t data)
175 data = cpu_to_le32(data);
176 return bcm539x_write_bytes(bd, page, reg, &data, 4);
181 * Writes 16 bits of data to the given page and register
183 static inline int bcm539x_write_16(struct bcm539x_data *bd, u8_t page,
184 u8_t reg, u16_t data)
186 data = cpu_to_le16(data);
187 return bcm539x_write_bytes(bd, page, reg, &data, 2);
192 * Writes 8 bits of data to the given page and register
194 static inline int bcm539x_write_8(struct bcm539x_data *bd, u8_t page,
197 return bcm539x_write_bytes(bd, page, reg, &data, 1);
202 * Reads a number of bytes from a given page and register
204 static int bcm539x_read_bytes(struct bcm539x_data *bd, u8_t page,
205 u8_t reg, void *buf, u8_t len)
211 * (1) Make sure the chip has finished processing our previous request
213 ret = bcm539x_wait_status(bd, BCM539X_GLOBAL_SPI_ST_SPIF, 0);
221 ret = bcm539x_set_page(bd, page);
227 * (3) Kick off the register read
229 txbuf[0] = BCM539X_CMD_READ;
231 ret = spi_write_then_read(bd->spi, txbuf, 2, txbuf, 1);
239 ret = bcm539x_wait_status(bd, BCM539X_GLOBAL_SPI_ST_RACK, 1);
247 txbuf[0] = BCM539X_CMD_READ;
248 txbuf[1] = BCM539X_GLOBAL_SPI_DATA0;
250 ret = spi_write_then_read(bd->spi, txbuf, 2, buf, len);
255 printk("read page %02x reg %02x len=%d rxbuf=",
257 for (i = 0; i < len; i++) {
258 printk("%02x ", ((u8_t *)buf)[i]);
269 * Reads an 32 bit number from a given page and register
271 static int bcm539x_read_32(struct bcm539x_data *bd, u8_t page,
272 u8_t reg, u32_t *buf)
274 int ret = bcm539x_read_bytes(bd, page, reg, buf, 4);
275 *buf = le32_to_cpu(*buf);
281 * Reads an 16 bit number from a given page and register
283 static int bcm539x_read_16(struct bcm539x_data *bd, u8_t page,
284 u8_t reg, u16_t *buf)
286 int ret = bcm539x_read_bytes(bd, page, reg, buf, 2);
287 *buf = le16_to_cpu(*buf);
293 * Reads an 8 bit number from a given page and register
295 static int bcm539x_read_8(struct bcm539x_data *bd, u8_t page,
298 return bcm539x_read_bytes(bd, page, reg, buf, 1);
304 static int bcm539x_set_mode(struct bcm539x_data *bd, int state)
309 ret = bcm539x_read_8(bd, PAGE_PORT_TC, REG_CTRL_MODE, &buf);
315 buf |= state ? (1 << 1) : 0;
317 ret = bcm539x_write_8(bd, PAGE_PORT_TC, REG_CTRL_MODE, buf);
322 * bcm539x_handle_reset
324 static int bcm539x_handle_reset(struct switch_device *dev, char *buf, int inst)
326 struct bcm539x_data *bd =
327 (struct bcm539x_data *)switch_get_drvdata(dev);
330 ret = bcm539x_write_8(bd, PAGE_PORT_TC, REG_CTRL_SRST,
331 (1 << 7) | (1 << 4));
338 ret = bcm539x_write_8(bd, PAGE_PORT_TC, REG_CTRL_SRST, 0);
343 * bcm539x_handle_vlan_ports_read
345 static int bcm539x_handle_vlan_ports_read(struct switch_device *dev,
348 struct bcm539x_data *bd =
349 (struct bcm539x_data *)switch_get_drvdata(dev);
356 ret = bcm539x_write_16(bd, PAGE_VTBL, REG_VTBL_INDX_5395, inst);
361 ret = bcm539x_write_8(bd, PAGE_VTBL, REG_VTBL_ACCESS_5395,
368 * Wait for completion
370 for (j = 0; j < BCM539X_SPI_RETRIES; j++) {
371 ret = bcm539x_read_8(bd, PAGE_VTBL, REG_VTBL_ACCESS_5395,
376 if (!(rxbuf8 & (1 << 7))) {
381 if (j == BCM539X_SPI_RETRIES) {
386 * Read the table entry
388 ret = bcm539x_read_32(bd, PAGE_VTBL, REG_VTBL_ENTRY_5395, &rxbuf32);
393 for (j = 0; j < 9; j++) {
394 if (rxbuf32 & (1 << j)) {
396 len += sprintf(buf + len, "%d", j);
397 if (rxbuf32 & (1 << (j + 9))) {
402 ret = bcm539x_read_16(bd, PAGE_VLAN,
403 REG_VLAN_PTAG0 + (j << 1),
408 if (rxbuf16 == inst) {
415 len += sprintf(buf + len, "\n");
422 * bcm539x_handle_vlan_ports_write
424 static int bcm539x_handle_vlan_ports_write(struct switch_device *dev,
427 struct bcm539x_data *bd =
428 (struct bcm539x_data *)switch_get_drvdata(dev);
438 switch_parse_vlan_ports(dev, buf, &untag, &ports, &def);
441 printk(KERN_DEBUG "'%s' inst=%d untag=%08x ports=%08x def=%08x\n",
442 buf, inst, untag, ports, def);
450 * Change default vlan tag
452 for (j = 0; j < 9; j++) {
453 if ((untag | def) & (1 << j)) {
454 ret = bcm539x_write_16(bd, PAGE_VLAN,
455 REG_VLAN_PTAG0 + (j << 1),
463 if (!(dev->port_mask[0] & (1 << j))) {
468 * Remove any ports which are not listed anymore as members of
471 ret = bcm539x_read_16(bd, PAGE_VLAN,
472 REG_VLAN_PTAG0 + (j << 1), &rxbuf16);
476 if (rxbuf16 == inst) {
477 ret = bcm539x_write_16(bd, PAGE_VLAN,
478 REG_VLAN_PTAG0 + (j << 1), 0);
486 * Write the VLAN table
488 ret = bcm539x_write_16(bd, PAGE_VTBL, REG_VTBL_INDX_5395, inst);
493 ret = bcm539x_write_32(bd, PAGE_VTBL, REG_VTBL_ENTRY_5395,
494 (untag << 9) | ports);
499 ret = bcm539x_write_8(bd, PAGE_VTBL, REG_VTBL_ACCESS_5395,
506 * Wait for completion
508 for (j = 0; j < BCM539X_SPI_RETRIES; j++) {
509 ret = bcm539x_read_bytes(bd, PAGE_VTBL, REG_VTBL_ACCESS_5395,
514 if (!(rxbuf8 & (1 << 7))) {
519 return (j < BCM539X_SPI_RETRIES) ? 0 : -EIO;
523 * Handlers for <this_driver>/vlan/<vlan_id>
525 static const struct switch_handler bcm539x_switch_handlers_vlan_dir[] = {
528 .read = bcm539x_handle_vlan_ports_read,
529 .write = bcm539x_handle_vlan_ports_write,
536 * bcm539x_handle_vlan_delete_write
538 static int bcm539x_handle_vlan_delete_write(struct switch_device *dev,
541 struct bcm539x_data *bd =
542 (struct bcm539x_data *)switch_get_drvdata(dev);
549 vid = simple_strtoul(buf, NULL, 0);
557 * Go through the port-based vlan registers and clear the appropriate
560 for (j = 0; j < 9; j++) {
562 ret = bcm539x_read_16(bd, PAGE_VLAN, REG_VLAN_PTAG0 + (j << 1),
567 if (rxbuf16 == vid) {
569 ret = bcm539x_write_16(bd, PAGE_VLAN,
570 REG_VLAN_PTAG0 + (j << 1),
579 * Write the VLAN table
582 ret = bcm539x_write_16(bd, PAGE_VTBL, REG_VTBL_INDX_5395, txbuf);
588 ret = bcm539x_write_32(bd, PAGE_VTBL, REG_VTBL_ENTRY_5395, txbuf);
593 txbuf = (1 << 7) | (0);
594 ret = bcm539x_write_8(bd, PAGE_VTBL, REG_VTBL_ACCESS_5395, txbuf);
600 * Wait for completion
602 for (j = 0; j < BCM539X_SPI_RETRIES; j++) {
603 ret = bcm539x_read_bytes(bd, PAGE_VTBL, REG_VTBL_ACCESS_5395,
608 if (!(rxbuf8 & (1 << 7))) {
613 if (j == BCM539X_SPI_RETRIES) {
617 return switch_remove_vlan_dir(dev, vid);
621 * bcm539x_handle_vlan_create_write
623 static int bcm539x_handle_vlan_create_write(struct switch_device *dev,
628 vid = simple_strtoul(buf, NULL, 0);
633 return switch_create_vlan_dir(dev, vid,
634 bcm539x_switch_handlers_vlan_dir);
638 * bcm539x_handle_enable_read
640 static int bcm539x_handle_enable_read(struct switch_device *dev,
643 struct bcm539x_data *bd =
644 (struct bcm539x_data *)switch_get_drvdata(dev);
648 ret = bcm539x_read_8(bd, PAGE_PORT_TC, REG_CTRL_MODE, &rxbuf);
652 rxbuf = (rxbuf & (1 << 1)) ? 1 : 0;
654 return sprintf(buf, "%d\n", rxbuf);
658 * bcm539x_handle_enable_write
660 static int bcm539x_handle_enable_write(struct switch_device *dev,
663 struct bcm539x_data *bd =
664 (struct bcm539x_data *)switch_get_drvdata(dev);
666 return bcm539x_set_mode(bd, buf[0] == '1');
670 * bcm539x_handle_enable_vlan_read
672 static int bcm539x_handle_enable_vlan_read(struct switch_device *dev,
675 struct bcm539x_data *bd =
676 (struct bcm539x_data *)switch_get_drvdata(dev);
680 ret = bcm539x_read_8(bd, PAGE_VLAN, REG_VLAN_CTRL0, &rxbuf);
684 rxbuf = (rxbuf & (1 << 7)) ? 1 : 0;
686 return sprintf(buf, "%d\n", rxbuf);
690 * bcm539x_handle_enable_vlan_write
692 static int bcm539x_handle_enable_vlan_write(struct switch_device *dev,
695 struct bcm539x_data *bd =
696 (struct bcm539x_data *)switch_get_drvdata(dev);
700 * disable 802.1Q VLANs
703 ret = bcm539x_write_8(bd, PAGE_VLAN, REG_VLAN_CTRL0, 0);
708 * enable 802.1Q VLANs
710 * Enable 802.1Q | IVL learning
712 ret = bcm539x_write_8(bd, PAGE_VLAN, REG_VLAN_CTRL0,
713 (1 << 7) | (3 << 5));
719 * RSV multicast fwd | RSV multicast chk
721 ret = bcm539x_write_8(bd, PAGE_VLAN, REG_VLAN_CTRL1,
722 (1 << 2) | (1 << 3));
730 ret = bcm539x_write_16(bd, PAGE_VLAN, REG_VLAN_CTRL3, 0x00FF);
739 * bcm539x_handle_port_enable_read
741 static int bcm539x_handle_port_enable_read(struct switch_device *dev,
744 return sprintf(buf, "%d\n", 1);
748 * bcm539x_handle_port_enable_write
750 static int bcm539x_handle_port_enable_write(struct switch_device *dev,
756 if (!(dev->port_mask[0] & (1 << inst))) {
761 printk(KERN_WARNING "switch port[%d] disabling is not supported\n", inst);
767 * bcm539x_handle_port_state_read
769 static int bcm539x_handle_port_state_read(struct switch_device *dev,
772 struct bcm539x_data *bd =
773 (struct bcm539x_data *)switch_get_drvdata(dev);
780 if (!(dev->port_mask[0] & (1 << inst))) {
785 * check PHY link state - CPU port (port 8) is always up
787 ret = bcm539x_read_16(bd, PAGE_STATUS, REG_LINK_STATUS, &link);
793 return sprintf(buf, "%d\n", (link & (1 << inst)) ? 1 : 0);
797 * bcm539x_handle_port_media_read
799 static int bcm539x_handle_port_media_read(struct switch_device *dev,
802 struct bcm539x_data *bd =
803 (struct bcm539x_data *)switch_get_drvdata(dev);
811 if (!(dev->port_mask[0] & (1 << inst))) {
816 * check PHY link state first - CPU port (port 8) is always up
818 ret = bcm539x_read_16(bd, PAGE_STATUS, REG_LINK_STATUS, &link);
824 if (!(link & (1 << inst))) {
825 return sprintf(buf, "UNKNOWN\n");
829 * get link speeda dn duplex - CPU port (port 8) is 1000/full
831 ret = bcm539x_read_32(bd, PAGE_STATUS, 4, &speed);
836 speed = (speed >> (2 * inst)) & 3;
838 ret = bcm539x_read_16(bd, PAGE_STATUS, 8, &duplex);
843 duplex = (duplex >> inst) & 1;
845 return sprintf(buf, "%d%cD\n",
846 (speed == 0) ? 10 : ((speed == 1) ? 100 : 1000),
851 * bcm539x_handle_port_meida_write
853 static int bcm539x_handle_port_meida_write(struct switch_device *dev,
856 struct bcm539x_data *bd =
857 (struct bcm539x_data *)switch_get_drvdata(dev);
859 u16_t ctrl_word, local_cap, local_giga_cap;
862 * validate port (not for CPU port)
864 if (!(dev->port_mask[0] & (1 << inst) & ~(1 << 8))) {
869 * Get the maximum capability from status
870 * SPI reg[0x00] = PHY[0x0] --- MII control
871 * SPI reg[0x08] = PHY[0x4] --- MII local capability
872 * SPI reg[0x12] = PHY[0x9] --- GMII control
874 ret = bcm539x_read_16(bd, REG_MII_PAGE + inst, (MII_ADVERTISE << 1), &local_cap);
878 ret = bcm539x_read_16(bd, REG_MII_PAGE + inst, (MII_CTRL1000 << 1), &local_giga_cap);
883 /* Configure to the requested speed */
884 if (strncmp(buf, "1000FD", 6) == 0) {
886 local_cap &= ~(ADVERTISE_10HALF | ADVERTISE_10FULL);
887 local_cap &= ~(ADVERTISE_100HALF | ADVERTISE_100FULL);
888 local_giga_cap |= (ADVERTISE_1000HALF | ADVERTISE_1000FULL);
890 } else if (strncmp(buf, "100FD", 5) == 0) {
892 local_cap &= ~(ADVERTISE_10HALF | ADVERTISE_10FULL);
893 local_cap |= (ADVERTISE_100HALF | ADVERTISE_100FULL);
894 local_giga_cap &= ~(ADVERTISE_1000HALF | ADVERTISE_1000FULL);
896 local_cap &= ~(ADVERTISE_100HALF);
897 } else if (strncmp(buf, "100HD", 5) == 0) {
899 local_cap &= ~(ADVERTISE_10HALF | ADVERTISE_10FULL);
900 local_cap |= (ADVERTISE_100HALF | ADVERTISE_100FULL);
901 local_giga_cap &= ~(ADVERTISE_1000HALF | ADVERTISE_1000FULL);
903 local_cap &= ~(ADVERTISE_100FULL);
904 } else if (strncmp(buf, "10FD", 4) == 0) {
906 local_cap |= (ADVERTISE_10HALF | ADVERTISE_10FULL);
907 local_cap &= ~(ADVERTISE_100HALF | ADVERTISE_100FULL);
908 local_giga_cap &= ~(ADVERTISE_1000HALF | ADVERTISE_1000FULL);
910 local_cap &= ~(ADVERTISE_10HALF);
911 } else if (strncmp(buf, "10HD", 4) == 0) {
913 local_cap |= (ADVERTISE_10HALF | ADVERTISE_10FULL);
914 local_cap &= ~(ADVERTISE_100HALF | ADVERTISE_100FULL);
915 local_giga_cap &= ~(ADVERTISE_1000HALF | ADVERTISE_1000FULL);
917 local_cap &= ~(ADVERTISE_10FULL);
918 } else if (strncmp(buf, "AUTO", 4) == 0) {
920 local_cap |= (ADVERTISE_10HALF | ADVERTISE_10FULL);
921 local_cap |= (ADVERTISE_100HALF | ADVERTISE_100FULL);
922 local_giga_cap |= (ADVERTISE_1000HALF | ADVERTISE_1000FULL);
927 /* Active PHY with the requested speed for auto-negotiation */
928 ret = bcm539x_write_16(bd, REG_MII_PAGE + inst, (MII_ADVERTISE << 1), local_cap);
932 ret = bcm539x_write_16(bd, REG_MII_PAGE + inst, (MII_CTRL1000 << 1), local_giga_cap);
937 ret = bcm539x_read_16(bd, REG_MII_PAGE + inst, (MII_BMCR << 1), &ctrl_word);
941 ctrl_word |= (BMCR_ANENABLE | BMCR_ANRESTART);
942 ret = bcm539x_write_16(bd, REG_MII_PAGE + inst, (MII_BMCR << 1), ctrl_word);
951 * proc_fs entries for this switch
953 static const struct switch_handler bcm539x_switch_handlers[] = {
956 .read = bcm539x_handle_enable_read,
957 .write = bcm539x_handle_enable_write,
960 .name = "enable_vlan",
961 .read = bcm539x_handle_enable_vlan_read,
962 .write = bcm539x_handle_enable_vlan_write,
966 .write = bcm539x_handle_reset,
973 * Handlers for <this_driver>/vlan
975 static const struct switch_handler bcm539x_switch_handlers_vlan[] = {
978 .write = bcm539x_handle_vlan_delete_write,
982 .write = bcm539x_handle_vlan_create_write,
989 * Handlers for <this_driver>/port/<port number>
991 static const struct switch_handler bcm539x_switch_handlers_port[] = {
994 .read = bcm539x_handle_port_enable_read,
995 .write = bcm539x_handle_port_enable_write,
999 .read = bcm539x_handle_port_state_read,
1003 .read = bcm539x_handle_port_media_read,
1004 .write = bcm539x_handle_port_meida_write,
1013 static int __devinit bcm539x_probe(struct spi_device *spi)
1015 struct bcm539x_data *bd;
1016 struct switch_core_platform_data *pdata;
1017 struct switch_device *switch_dev = NULL;
1021 pdata = spi->dev.platform_data;
1026 ret = spi_setup(spi);
1032 * Reset the chip if requested
1034 if (pdata->flags & SWITCH_DEV_FLAG_HW_RESET) {
1035 ret = gpio_request(pdata->pin_reset, "switch-bcm539x-reset");
1037 printk(KERN_WARNING "Could not request reset\n");
1041 gpio_direction_output(pdata->pin_reset, 0);
1043 gpio_set_value(pdata->pin_reset, 1);
1048 * Allocate our private data structure
1050 bd = kzalloc(sizeof(struct bcm539x_data), GFP_KERNEL);
1055 dev_set_drvdata(&spi->dev, bd);
1058 bd->last_page = 0xFF;
1061 * First perform SW reset if needed
1063 if (pdata->flags & SWITCH_DEV_FLAG_SW_RESET) {
1064 txbuf[0] = (1 << 7) | (1 << 4);
1065 ret = bcm539x_write_bytes(bd, PAGE_PORT_TC,
1066 REG_CTRL_SRST, txbuf, 1);
1074 ret = bcm539x_write_bytes(bd, PAGE_PORT_TC,
1075 REG_CTRL_SRST, txbuf, 1);
1082 * See if we can see the chip
1084 for (i = 0; i < 10; i++) {
1085 ret = bcm539x_read_bytes(bd, PAGE_MMR, REG_DEVICE_ID,
1096 * We only support 5395, 5397, 5398
1098 if ((bd->device_id != 0x95) && (bd->device_id != 0x97) &&
1099 (bd->device_id != 0x98)) {
1105 * Override CPU port config: fixed link @1000 with flow control
1107 ret = bcm539x_read_8(bd, PAGE_PORT_TC, REG_CTRL_MIIPO, txbuf);
1108 bcm539x_write_8(bd, PAGE_PORT_TC, REG_CTRL_MIIPO, 0xbb); // Override IMP port config
1109 printk("Broadcom SW CPU port setting: 0x%x -> 0xbb\n", txbuf[0]);
1112 * Setup the switch driver structure
1114 switch_dev = switch_alloc();
1119 switch_dev->name = pdata->name;
1121 switch_dev->ports = (bd->device_id == 0x98) ? 9 : 6;
1122 switch_dev->port_mask[0] = (bd->device_id == 0x98) ? 0x1FF : 0x11F;
1123 switch_dev->driver_handlers = bcm539x_switch_handlers;
1124 switch_dev->reg_handlers = NULL;
1125 switch_dev->vlan_handlers = bcm539x_switch_handlers_vlan;
1126 switch_dev->port_handlers = bcm539x_switch_handlers_port;
1128 bd->switch_dev = switch_dev;
1129 switch_set_drvdata(switch_dev, (void *)bd);
1131 ret = switch_register(bd->switch_dev);
1136 printk(KERN_INFO "bcm53%02x switch chip initialized\n", bd->device_id);
1142 switch_release(switch_dev);
1144 dev_set_drvdata(&spi->dev, NULL);
1149 static int __attribute__((unused)) bcm539x_remove(struct spi_device *spi)
1151 struct bcm539x_data *bd;
1153 bd = dev_get_drvdata(&spi->dev);
1155 if (bd->pdata->flags & SWITCH_DEV_FLAG_HW_RESET) {
1156 gpio_free(bd->pdata->pin_reset);
1159 if (bd->switch_dev) {
1160 switch_unregister(bd->switch_dev);
1161 switch_release(bd->switch_dev);
1164 dev_set_drvdata(&spi->dev, NULL);
1171 static struct spi_driver bcm539x_driver = {
1173 .name = DRIVER_NAME,
1174 .owner = THIS_MODULE,
1176 .probe = bcm539x_probe,
1177 .remove = __devexit_p(bcm539x_remove),
1180 static int __init bcm539x_init(void)
1182 return spi_register_driver(&bcm539x_driver);
1185 module_init(bcm539x_init);
1187 static void __exit bcm539x_exit(void)
1189 spi_unregister_driver(&bcm539x_driver);
1191 module_exit(bcm539x_exit);
1193 MODULE_AUTHOR("Pat Tjin");
1194 MODULE_LICENSE("GPL v2");
1195 MODULE_DESCRIPTION("bcm539x SPI switch chip driver");