xref: /linux/drivers/media/mmc/siano/smssdio.c (revision 6fd600d742744dc7ef7fc65ca26daa2b1163158a)
12874c5fdSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
20013ca8cSMauro Carvalho Chehab /*
30013ca8cSMauro Carvalho Chehab  *  smssdio.c - Siano 1xxx SDIO interface driver
40013ca8cSMauro Carvalho Chehab  *
50013ca8cSMauro Carvalho Chehab  *  Copyright 2008 Pierre Ossman
60013ca8cSMauro Carvalho Chehab  *
70013ca8cSMauro Carvalho Chehab  * Based on code by Siano Mobile Silicon, Inc.,
80013ca8cSMauro Carvalho Chehab  * Copyright (C) 2006-2008, Uri Shkolnik
90013ca8cSMauro Carvalho Chehab  *
100013ca8cSMauro Carvalho Chehab  * This hardware is a bit odd in that all transfers should be done
110013ca8cSMauro Carvalho Chehab  * to/from the SMSSDIO_DATA register, yet the "increase address" bit
120013ca8cSMauro Carvalho Chehab  * always needs to be set.
130013ca8cSMauro Carvalho Chehab  *
140013ca8cSMauro Carvalho Chehab  * Also, buffers from the card are always aligned to 128 byte
150013ca8cSMauro Carvalho Chehab  * boundaries.
160013ca8cSMauro Carvalho Chehab  */
170013ca8cSMauro Carvalho Chehab 
180013ca8cSMauro Carvalho Chehab /*
190013ca8cSMauro Carvalho Chehab  * General cleanup notes:
200013ca8cSMauro Carvalho Chehab  *
210013ca8cSMauro Carvalho Chehab  * - only typedefs should be name *_t
220013ca8cSMauro Carvalho Chehab  *
230013ca8cSMauro Carvalho Chehab  * - use ERR_PTR and friends for smscore_register_device()
240013ca8cSMauro Carvalho Chehab  *
250013ca8cSMauro Carvalho Chehab  * - smscore_getbuffer should zero fields
260013ca8cSMauro Carvalho Chehab  *
270013ca8cSMauro Carvalho Chehab  * Fix stop command
280013ca8cSMauro Carvalho Chehab  */
290013ca8cSMauro Carvalho Chehab 
305e022d1aSMauro Carvalho Chehab #include "smscoreapi.h"
315e022d1aSMauro Carvalho Chehab 
320013ca8cSMauro Carvalho Chehab #include <linux/moduleparam.h>
330013ca8cSMauro Carvalho Chehab #include <linux/slab.h>
340013ca8cSMauro Carvalho Chehab #include <linux/firmware.h>
350013ca8cSMauro Carvalho Chehab #include <linux/delay.h>
360013ca8cSMauro Carvalho Chehab #include <linux/mmc/card.h>
370013ca8cSMauro Carvalho Chehab #include <linux/mmc/sdio_func.h>
380013ca8cSMauro Carvalho Chehab #include <linux/mmc/sdio_ids.h>
390013ca8cSMauro Carvalho Chehab #include <linux/module.h>
400013ca8cSMauro Carvalho Chehab 
410013ca8cSMauro Carvalho Chehab #include "sms-cards.h"
4280ccb51aSMauro Carvalho Chehab #include "smsendian.h"
430013ca8cSMauro Carvalho Chehab 
440013ca8cSMauro Carvalho Chehab /* Registers */
450013ca8cSMauro Carvalho Chehab 
460013ca8cSMauro Carvalho Chehab #define SMSSDIO_DATA		0x00
470013ca8cSMauro Carvalho Chehab #define SMSSDIO_INT		0x04
480013ca8cSMauro Carvalho Chehab #define SMSSDIO_BLOCK_SIZE	128
490013ca8cSMauro Carvalho Chehab 
504c62e976SGreg Kroah-Hartman static const struct sdio_device_id smssdio_ids[] = {
510013ca8cSMauro Carvalho Chehab 	{SDIO_DEVICE(SDIO_VENDOR_ID_SIANO, SDIO_DEVICE_ID_SIANO_STELLAR),
520013ca8cSMauro Carvalho Chehab 	 .driver_data = SMS1XXX_BOARD_SIANO_STELLAR},
530013ca8cSMauro Carvalho Chehab 	{SDIO_DEVICE(SDIO_VENDOR_ID_SIANO, SDIO_DEVICE_ID_SIANO_NOVA_A0),
540013ca8cSMauro Carvalho Chehab 	 .driver_data = SMS1XXX_BOARD_SIANO_NOVA_A},
550013ca8cSMauro Carvalho Chehab 	{SDIO_DEVICE(SDIO_VENDOR_ID_SIANO, SDIO_DEVICE_ID_SIANO_NOVA_B0),
560013ca8cSMauro Carvalho Chehab 	 .driver_data = SMS1XXX_BOARD_SIANO_NOVA_B},
570013ca8cSMauro Carvalho Chehab 	{SDIO_DEVICE(SDIO_VENDOR_ID_SIANO, SDIO_DEVICE_ID_SIANO_VEGA_A0),
580013ca8cSMauro Carvalho Chehab 	 .driver_data = SMS1XXX_BOARD_SIANO_VEGA},
590013ca8cSMauro Carvalho Chehab 	{SDIO_DEVICE(SDIO_VENDOR_ID_SIANO, SDIO_DEVICE_ID_SIANO_VENICE),
600013ca8cSMauro Carvalho Chehab 	 .driver_data = SMS1XXX_BOARD_SIANO_VEGA},
61b8c26a96SPali Rohár 	{SDIO_DEVICE(SDIO_VENDOR_ID_SIANO, SDIO_DEVICE_ID_SIANO_MING),
62347d8f1fSMauro Carvalho Chehab 	.driver_data = SMS1XXX_BOARD_SIANO_MING},
63b8c26a96SPali Rohár 	{SDIO_DEVICE(SDIO_VENDOR_ID_SIANO, SDIO_DEVICE_ID_SIANO_PELE),
64347d8f1fSMauro Carvalho Chehab 	.driver_data = SMS1XXX_BOARD_SIANO_PELE},
65b8c26a96SPali Rohár 	{SDIO_DEVICE(SDIO_VENDOR_ID_SIANO, SDIO_DEVICE_ID_SIANO_RIO),
66347d8f1fSMauro Carvalho Chehab 	.driver_data = SMS1XXX_BOARD_SIANO_RIO},
67b8c26a96SPali Rohár 	{SDIO_DEVICE(SDIO_VENDOR_ID_SIANO, SDIO_DEVICE_ID_SIANO_DENVER_2160),
68347d8f1fSMauro Carvalho Chehab 	.driver_data = SMS1XXX_BOARD_SIANO_DENVER_2160},
69b8c26a96SPali Rohár 	{SDIO_DEVICE(SDIO_VENDOR_ID_SIANO, SDIO_DEVICE_ID_SIANO_DENVER_1530),
70347d8f1fSMauro Carvalho Chehab 	.driver_data = SMS1XXX_BOARD_SIANO_DENVER_1530},
710013ca8cSMauro Carvalho Chehab 	{ /* end: all zeroes */ },
720013ca8cSMauro Carvalho Chehab };
730013ca8cSMauro Carvalho Chehab 
740013ca8cSMauro Carvalho Chehab MODULE_DEVICE_TABLE(sdio, smssdio_ids);
750013ca8cSMauro Carvalho Chehab 
760013ca8cSMauro Carvalho Chehab struct smssdio_device {
770013ca8cSMauro Carvalho Chehab 	struct sdio_func *func;
780013ca8cSMauro Carvalho Chehab 
790013ca8cSMauro Carvalho Chehab 	struct smscore_device_t *coredev;
800013ca8cSMauro Carvalho Chehab 
810013ca8cSMauro Carvalho Chehab 	struct smscore_buffer_t *split_cb;
820013ca8cSMauro Carvalho Chehab };
830013ca8cSMauro Carvalho Chehab 
840013ca8cSMauro Carvalho Chehab /*******************************************************************/
850013ca8cSMauro Carvalho Chehab /* Siano core callbacks                                            */
860013ca8cSMauro Carvalho Chehab /*******************************************************************/
870013ca8cSMauro Carvalho Chehab 
smssdio_sendrequest(void * context,void * buffer,size_t size)880013ca8cSMauro Carvalho Chehab static int smssdio_sendrequest(void *context, void *buffer, size_t size)
890013ca8cSMauro Carvalho Chehab {
900013ca8cSMauro Carvalho Chehab 	int ret = 0;
910013ca8cSMauro Carvalho Chehab 	struct smssdio_device *smsdev;
920013ca8cSMauro Carvalho Chehab 
930013ca8cSMauro Carvalho Chehab 	smsdev = context;
940013ca8cSMauro Carvalho Chehab 
950013ca8cSMauro Carvalho Chehab 	sdio_claim_host(smsdev->func);
960013ca8cSMauro Carvalho Chehab 
97dfef84fcSMauro Carvalho Chehab 	smsendian_handle_tx_message((struct sms_msg_data *) buffer);
980013ca8cSMauro Carvalho Chehab 	while (size >= smsdev->func->cur_blksize) {
990013ca8cSMauro Carvalho Chehab 		ret = sdio_memcpy_toio(smsdev->func, SMSSDIO_DATA,
1000013ca8cSMauro Carvalho Chehab 					buffer, smsdev->func->cur_blksize);
1010013ca8cSMauro Carvalho Chehab 		if (ret)
1020013ca8cSMauro Carvalho Chehab 			goto out;
1030013ca8cSMauro Carvalho Chehab 
1040013ca8cSMauro Carvalho Chehab 		buffer += smsdev->func->cur_blksize;
1050013ca8cSMauro Carvalho Chehab 		size -= smsdev->func->cur_blksize;
1060013ca8cSMauro Carvalho Chehab 	}
1070013ca8cSMauro Carvalho Chehab 
1080013ca8cSMauro Carvalho Chehab 	if (size) {
1090013ca8cSMauro Carvalho Chehab 		ret = sdio_memcpy_toio(smsdev->func, SMSSDIO_DATA,
1100013ca8cSMauro Carvalho Chehab 					buffer, size);
1110013ca8cSMauro Carvalho Chehab 	}
1120013ca8cSMauro Carvalho Chehab 
1130013ca8cSMauro Carvalho Chehab out:
1140013ca8cSMauro Carvalho Chehab 	sdio_release_host(smsdev->func);
1150013ca8cSMauro Carvalho Chehab 
1160013ca8cSMauro Carvalho Chehab 	return ret;
1170013ca8cSMauro Carvalho Chehab }
1180013ca8cSMauro Carvalho Chehab 
1190013ca8cSMauro Carvalho Chehab /*******************************************************************/
1200013ca8cSMauro Carvalho Chehab /* SDIO callbacks                                                  */
1210013ca8cSMauro Carvalho Chehab /*******************************************************************/
1220013ca8cSMauro Carvalho Chehab 
smssdio_interrupt(struct sdio_func * func)1230013ca8cSMauro Carvalho Chehab static void smssdio_interrupt(struct sdio_func *func)
1240013ca8cSMauro Carvalho Chehab {
1250013ca8cSMauro Carvalho Chehab 	int ret;
1260013ca8cSMauro Carvalho Chehab 
1270013ca8cSMauro Carvalho Chehab 	struct smssdio_device *smsdev;
1280013ca8cSMauro Carvalho Chehab 	struct smscore_buffer_t *cb;
129dfef84fcSMauro Carvalho Chehab 	struct sms_msg_hdr *hdr;
1300013ca8cSMauro Carvalho Chehab 	size_t size;
1310013ca8cSMauro Carvalho Chehab 
1320013ca8cSMauro Carvalho Chehab 	smsdev = sdio_get_drvdata(func);
1330013ca8cSMauro Carvalho Chehab 
1340013ca8cSMauro Carvalho Chehab 	/*
1350013ca8cSMauro Carvalho Chehab 	 * The interrupt register has no defined meaning. It is just
1360013ca8cSMauro Carvalho Chehab 	 * a way of turning of the level triggered interrupt.
1370013ca8cSMauro Carvalho Chehab 	 */
1380013ca8cSMauro Carvalho Chehab 	(void)sdio_readb(func, SMSSDIO_INT, &ret);
1390013ca8cSMauro Carvalho Chehab 	if (ret) {
1405ed0a2c7SMauro Carvalho Chehab 		pr_err("Unable to read interrupt register!\n");
1410013ca8cSMauro Carvalho Chehab 		return;
1420013ca8cSMauro Carvalho Chehab 	}
1430013ca8cSMauro Carvalho Chehab 
1440013ca8cSMauro Carvalho Chehab 	if (smsdev->split_cb == NULL) {
1450013ca8cSMauro Carvalho Chehab 		cb = smscore_getbuffer(smsdev->coredev);
1460013ca8cSMauro Carvalho Chehab 		if (!cb) {
1475ed0a2c7SMauro Carvalho Chehab 			pr_err("Unable to allocate data buffer!\n");
1480013ca8cSMauro Carvalho Chehab 			return;
1490013ca8cSMauro Carvalho Chehab 		}
1500013ca8cSMauro Carvalho Chehab 
1510013ca8cSMauro Carvalho Chehab 		ret = sdio_memcpy_fromio(smsdev->func,
1520013ca8cSMauro Carvalho Chehab 					 cb->p,
1530013ca8cSMauro Carvalho Chehab 					 SMSSDIO_DATA,
1540013ca8cSMauro Carvalho Chehab 					 SMSSDIO_BLOCK_SIZE);
1550013ca8cSMauro Carvalho Chehab 		if (ret) {
1565ed0a2c7SMauro Carvalho Chehab 			pr_err("Error %d reading initial block!\n", ret);
1570013ca8cSMauro Carvalho Chehab 			return;
1580013ca8cSMauro Carvalho Chehab 		}
1590013ca8cSMauro Carvalho Chehab 
1600013ca8cSMauro Carvalho Chehab 		hdr = cb->p;
1610013ca8cSMauro Carvalho Chehab 
162dfef84fcSMauro Carvalho Chehab 		if (hdr->msg_flags & MSG_HDR_FLAG_SPLIT_MSG) {
1630013ca8cSMauro Carvalho Chehab 			smsdev->split_cb = cb;
1640013ca8cSMauro Carvalho Chehab 			return;
1650013ca8cSMauro Carvalho Chehab 		}
1660013ca8cSMauro Carvalho Chehab 
167dfef84fcSMauro Carvalho Chehab 		if (hdr->msg_length > smsdev->func->cur_blksize)
168dfef84fcSMauro Carvalho Chehab 			size = hdr->msg_length - smsdev->func->cur_blksize;
1690013ca8cSMauro Carvalho Chehab 		else
1700013ca8cSMauro Carvalho Chehab 			size = 0;
1710013ca8cSMauro Carvalho Chehab 	} else {
1720013ca8cSMauro Carvalho Chehab 		cb = smsdev->split_cb;
1730013ca8cSMauro Carvalho Chehab 		hdr = cb->p;
1740013ca8cSMauro Carvalho Chehab 
175dfef84fcSMauro Carvalho Chehab 		size = hdr->msg_length - sizeof(struct sms_msg_hdr);
1760013ca8cSMauro Carvalho Chehab 
1770013ca8cSMauro Carvalho Chehab 		smsdev->split_cb = NULL;
1780013ca8cSMauro Carvalho Chehab 	}
1790013ca8cSMauro Carvalho Chehab 
1800013ca8cSMauro Carvalho Chehab 	if (size) {
1810013ca8cSMauro Carvalho Chehab 		void *buffer;
1820013ca8cSMauro Carvalho Chehab 
183dfef84fcSMauro Carvalho Chehab 		buffer = cb->p + (hdr->msg_length - size);
1840013ca8cSMauro Carvalho Chehab 		size = ALIGN(size, SMSSDIO_BLOCK_SIZE);
1850013ca8cSMauro Carvalho Chehab 
1860013ca8cSMauro Carvalho Chehab 		BUG_ON(smsdev->func->cur_blksize != SMSSDIO_BLOCK_SIZE);
1870013ca8cSMauro Carvalho Chehab 
1880013ca8cSMauro Carvalho Chehab 		/*
1890013ca8cSMauro Carvalho Chehab 		 * First attempt to transfer all of it in one go...
1900013ca8cSMauro Carvalho Chehab 		 */
1910013ca8cSMauro Carvalho Chehab 		ret = sdio_memcpy_fromio(smsdev->func,
1920013ca8cSMauro Carvalho Chehab 					 buffer,
1930013ca8cSMauro Carvalho Chehab 					 SMSSDIO_DATA,
1940013ca8cSMauro Carvalho Chehab 					 size);
1950013ca8cSMauro Carvalho Chehab 		if (ret && ret != -EINVAL) {
1960013ca8cSMauro Carvalho Chehab 			smscore_putbuffer(smsdev->coredev, cb);
1975ed0a2c7SMauro Carvalho Chehab 			pr_err("Error %d reading data from card!\n", ret);
1980013ca8cSMauro Carvalho Chehab 			return;
1990013ca8cSMauro Carvalho Chehab 		}
2000013ca8cSMauro Carvalho Chehab 
2010013ca8cSMauro Carvalho Chehab 		/*
2020013ca8cSMauro Carvalho Chehab 		 * ..then fall back to one block at a time if that is
2030013ca8cSMauro Carvalho Chehab 		 * not possible...
2040013ca8cSMauro Carvalho Chehab 		 *
2050013ca8cSMauro Carvalho Chehab 		 * (we have to do this manually because of the
2060013ca8cSMauro Carvalho Chehab 		 * problem with the "increase address" bit)
2070013ca8cSMauro Carvalho Chehab 		 */
2080013ca8cSMauro Carvalho Chehab 		if (ret == -EINVAL) {
2090013ca8cSMauro Carvalho Chehab 			while (size) {
2100013ca8cSMauro Carvalho Chehab 				ret = sdio_memcpy_fromio(smsdev->func,
2110013ca8cSMauro Carvalho Chehab 						  buffer, SMSSDIO_DATA,
2120013ca8cSMauro Carvalho Chehab 						  smsdev->func->cur_blksize);
2130013ca8cSMauro Carvalho Chehab 				if (ret) {
2140013ca8cSMauro Carvalho Chehab 					smscore_putbuffer(smsdev->coredev, cb);
2155ed0a2c7SMauro Carvalho Chehab 					pr_err("Error %d reading data from card!\n",
2165ed0a2c7SMauro Carvalho Chehab 					       ret);
2170013ca8cSMauro Carvalho Chehab 					return;
2180013ca8cSMauro Carvalho Chehab 				}
2190013ca8cSMauro Carvalho Chehab 
2200013ca8cSMauro Carvalho Chehab 				buffer += smsdev->func->cur_blksize;
2210013ca8cSMauro Carvalho Chehab 				if (size > smsdev->func->cur_blksize)
2220013ca8cSMauro Carvalho Chehab 					size -= smsdev->func->cur_blksize;
2230013ca8cSMauro Carvalho Chehab 				else
2240013ca8cSMauro Carvalho Chehab 					size = 0;
2250013ca8cSMauro Carvalho Chehab 			}
2260013ca8cSMauro Carvalho Chehab 		}
2270013ca8cSMauro Carvalho Chehab 	}
2280013ca8cSMauro Carvalho Chehab 
229dfef84fcSMauro Carvalho Chehab 	cb->size = hdr->msg_length;
2300013ca8cSMauro Carvalho Chehab 	cb->offset = 0;
2310013ca8cSMauro Carvalho Chehab 
232dfef84fcSMauro Carvalho Chehab 	smsendian_handle_rx_message((struct sms_msg_data *) cb->p);
2330013ca8cSMauro Carvalho Chehab 	smscore_onresponse(smsdev->coredev, cb);
2340013ca8cSMauro Carvalho Chehab }
2350013ca8cSMauro Carvalho Chehab 
smssdio_probe(struct sdio_func * func,const struct sdio_device_id * id)2364c62e976SGreg Kroah-Hartman static int smssdio_probe(struct sdio_func *func,
2370013ca8cSMauro Carvalho Chehab 			 const struct sdio_device_id *id)
2380013ca8cSMauro Carvalho Chehab {
2390013ca8cSMauro Carvalho Chehab 	int ret;
2400013ca8cSMauro Carvalho Chehab 
2410013ca8cSMauro Carvalho Chehab 	int board_id;
2420013ca8cSMauro Carvalho Chehab 	struct smssdio_device *smsdev;
2430013ca8cSMauro Carvalho Chehab 	struct smsdevice_params_t params;
2440013ca8cSMauro Carvalho Chehab 
2450013ca8cSMauro Carvalho Chehab 	board_id = id->driver_data;
2460013ca8cSMauro Carvalho Chehab 
2470013ca8cSMauro Carvalho Chehab 	smsdev = kzalloc(sizeof(struct smssdio_device), GFP_KERNEL);
2480013ca8cSMauro Carvalho Chehab 	if (!smsdev)
2490013ca8cSMauro Carvalho Chehab 		return -ENOMEM;
2500013ca8cSMauro Carvalho Chehab 
2510013ca8cSMauro Carvalho Chehab 	smsdev->func = func;
2520013ca8cSMauro Carvalho Chehab 
2530013ca8cSMauro Carvalho Chehab 	memset(&params, 0, sizeof(struct smsdevice_params_t));
2540013ca8cSMauro Carvalho Chehab 
2550013ca8cSMauro Carvalho Chehab 	params.device = &func->dev;
2560013ca8cSMauro Carvalho Chehab 	params.buffer_size = 0x5000;	/* ?? */
2570013ca8cSMauro Carvalho Chehab 	params.num_buffers = 22;	/* ?? */
2580013ca8cSMauro Carvalho Chehab 	params.context = smsdev;
2590013ca8cSMauro Carvalho Chehab 
2600013ca8cSMauro Carvalho Chehab 	snprintf(params.devpath, sizeof(params.devpath),
2610013ca8cSMauro Carvalho Chehab 		 "sdio\\%s", sdio_func_id(func));
2620013ca8cSMauro Carvalho Chehab 
2630013ca8cSMauro Carvalho Chehab 	params.sendrequest_handler = smssdio_sendrequest;
2640013ca8cSMauro Carvalho Chehab 
2650013ca8cSMauro Carvalho Chehab 	params.device_type = sms_get_board(board_id)->type;
2660013ca8cSMauro Carvalho Chehab 
2670013ca8cSMauro Carvalho Chehab 	if (params.device_type != SMS_STELLAR)
2680013ca8cSMauro Carvalho Chehab 		params.flags |= SMS_DEVICE_FAMILY2;
2690013ca8cSMauro Carvalho Chehab 	else {
2700013ca8cSMauro Carvalho Chehab 		/*
2710013ca8cSMauro Carvalho Chehab 		 * FIXME: Stellar needs special handling...
2720013ca8cSMauro Carvalho Chehab 		 */
2730013ca8cSMauro Carvalho Chehab 		ret = -ENODEV;
2740013ca8cSMauro Carvalho Chehab 		goto free;
2750013ca8cSMauro Carvalho Chehab 	}
2760013ca8cSMauro Carvalho Chehab 
277782b9d20SMauro Carvalho Chehab 	ret = smscore_register_device(&params, &smsdev->coredev, GFP_DMA, NULL);
2780013ca8cSMauro Carvalho Chehab 	if (ret < 0)
2790013ca8cSMauro Carvalho Chehab 		goto free;
2800013ca8cSMauro Carvalho Chehab 
2810013ca8cSMauro Carvalho Chehab 	smscore_set_board_id(smsdev->coredev, board_id);
2820013ca8cSMauro Carvalho Chehab 
2830013ca8cSMauro Carvalho Chehab 	sdio_claim_host(func);
2840013ca8cSMauro Carvalho Chehab 
2850013ca8cSMauro Carvalho Chehab 	ret = sdio_enable_func(func);
2860013ca8cSMauro Carvalho Chehab 	if (ret)
2870013ca8cSMauro Carvalho Chehab 		goto release;
2880013ca8cSMauro Carvalho Chehab 
2890013ca8cSMauro Carvalho Chehab 	ret = sdio_set_block_size(func, SMSSDIO_BLOCK_SIZE);
2900013ca8cSMauro Carvalho Chehab 	if (ret)
2910013ca8cSMauro Carvalho Chehab 		goto disable;
2920013ca8cSMauro Carvalho Chehab 
2930013ca8cSMauro Carvalho Chehab 	ret = sdio_claim_irq(func, smssdio_interrupt);
2940013ca8cSMauro Carvalho Chehab 	if (ret)
2950013ca8cSMauro Carvalho Chehab 		goto disable;
2960013ca8cSMauro Carvalho Chehab 
2970013ca8cSMauro Carvalho Chehab 	sdio_set_drvdata(func, smsdev);
2980013ca8cSMauro Carvalho Chehab 
2990013ca8cSMauro Carvalho Chehab 	sdio_release_host(func);
3000013ca8cSMauro Carvalho Chehab 
3010013ca8cSMauro Carvalho Chehab 	ret = smscore_start_device(smsdev->coredev);
3020013ca8cSMauro Carvalho Chehab 	if (ret < 0)
3030013ca8cSMauro Carvalho Chehab 		goto reclaim;
3040013ca8cSMauro Carvalho Chehab 
3050013ca8cSMauro Carvalho Chehab 	return 0;
3060013ca8cSMauro Carvalho Chehab 
3070013ca8cSMauro Carvalho Chehab reclaim:
3080013ca8cSMauro Carvalho Chehab 	sdio_claim_host(func);
3090013ca8cSMauro Carvalho Chehab 	sdio_release_irq(func);
3100013ca8cSMauro Carvalho Chehab disable:
3110013ca8cSMauro Carvalho Chehab 	sdio_disable_func(func);
3120013ca8cSMauro Carvalho Chehab release:
3130013ca8cSMauro Carvalho Chehab 	sdio_release_host(func);
3140013ca8cSMauro Carvalho Chehab 	smscore_unregister_device(smsdev->coredev);
3150013ca8cSMauro Carvalho Chehab free:
3160013ca8cSMauro Carvalho Chehab 	kfree(smsdev);
3170013ca8cSMauro Carvalho Chehab 
3180013ca8cSMauro Carvalho Chehab 	return ret;
3190013ca8cSMauro Carvalho Chehab }
3200013ca8cSMauro Carvalho Chehab 
smssdio_remove(struct sdio_func * func)3210013ca8cSMauro Carvalho Chehab static void smssdio_remove(struct sdio_func *func)
3220013ca8cSMauro Carvalho Chehab {
3230013ca8cSMauro Carvalho Chehab 	struct smssdio_device *smsdev;
3240013ca8cSMauro Carvalho Chehab 
3250013ca8cSMauro Carvalho Chehab 	smsdev = sdio_get_drvdata(func);
3260013ca8cSMauro Carvalho Chehab 
3270013ca8cSMauro Carvalho Chehab 	/* FIXME: racy! */
3280013ca8cSMauro Carvalho Chehab 	if (smsdev->split_cb)
3290013ca8cSMauro Carvalho Chehab 		smscore_putbuffer(smsdev->coredev, smsdev->split_cb);
3300013ca8cSMauro Carvalho Chehab 
3310013ca8cSMauro Carvalho Chehab 	smscore_unregister_device(smsdev->coredev);
3320013ca8cSMauro Carvalho Chehab 
3330013ca8cSMauro Carvalho Chehab 	sdio_claim_host(func);
3340013ca8cSMauro Carvalho Chehab 	sdio_release_irq(func);
3350013ca8cSMauro Carvalho Chehab 	sdio_disable_func(func);
3360013ca8cSMauro Carvalho Chehab 	sdio_release_host(func);
3370013ca8cSMauro Carvalho Chehab 
3380013ca8cSMauro Carvalho Chehab 	kfree(smsdev);
3390013ca8cSMauro Carvalho Chehab }
3400013ca8cSMauro Carvalho Chehab 
3410013ca8cSMauro Carvalho Chehab static struct sdio_driver smssdio_driver = {
3420013ca8cSMauro Carvalho Chehab 	.name = "smssdio",
3430013ca8cSMauro Carvalho Chehab 	.id_table = smssdio_ids,
3440013ca8cSMauro Carvalho Chehab 	.probe = smssdio_probe,
3450013ca8cSMauro Carvalho Chehab 	.remove = smssdio_remove,
3460013ca8cSMauro Carvalho Chehab };
347*1a4a993cSKrzysztof Kozlowski module_sdio_driver(smssdio_driver);
3480013ca8cSMauro Carvalho Chehab 
3490013ca8cSMauro Carvalho Chehab MODULE_DESCRIPTION("Siano SMS1xxx SDIO driver");
3500013ca8cSMauro Carvalho Chehab MODULE_AUTHOR("Pierre Ossman");
3510013ca8cSMauro Carvalho Chehab MODULE_LICENSE("GPL");
352