siano: add high level SDIO interface driver for SMS based cards
PATCH 1/1 siano: add high level SDIO interface driver for SMS based cards
# HG changeset patch
# User Uri Shkolnik <[email protected]>
# Date 1236865697 -7200
# Node ID 7352ee1288f651d19d58c7bb479a98f070ad98e6
# Parent 3392722cc5b687586c4d898b73050ab6e59bf401
siano: add high level SDIO interface driver for SMS based cards
From: Uri Shkolnik <[email protected]>
This patch provides SDIO interface driver for SMS (Siano Mobile Silicon) based devices. The patch includes SMS high level SDIO driver and requires patching the kernel SDIO stack, those stack patches had been provided previously.
I would like to thank Pierre Ossman, MMC maintainer, who wrote this driver.
Priority: normal
linux/drivers/media/dvb/siano/smssdio.c new file +356 -0
@@ -0,0 +1,356 @@ +/* +* smssdio.c - Siano 1xxx SDIO interface driver +* +* Copyright 2008 Pierre Ossman +* +* Based on code by Siano Mobile Silicon, Inc., +* Copyright (C) 2006-2008, Uri Shkolnik +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. +* +* +* This hardware is a bit odd in that all transfers should be done +* to/from the SMSSDIO_DATA register, yet the "increase address" bit +* always needs to be set. +* +* Also, buffers from the card are always aligned to 128 byte +* boundaries. +*/ + +/* +* General cleanup notes: +* +* - only typedefs should be name *_t +* +* - use ERR_PTR and friends for smscore_register_device() +* +* - smscore_getbuffer should zero fields +* +* Fix stop command +*/ + +#include <linux/moduleparam.h> +#include <linux/firmware.h> +#include <linux/delay.h> +#include <linux/mmc/card.h> +#include <linux/mmc/sdio_func.h> +#include <linux/mmc/sdio_ids.h> + +#include "smscoreapi.h" +#include "sms-cards.h" + +/* Registers */ + +#define SMSSDIO_DATA 0x00 +#define SMSSDIO_INT 0x04 + +static const struct sdio_device_id smssdio_ids[] = { + {SDIO_DEVICE (SDIO_VENDOR_ID_SIANO ,SDIO_DEVICE_ID_SIANO_STELLAR ), + .driver_data =SMS1XXX_BOARD_SIANO_STELLAR }, + {SDIO_DEVICE (SDIO_VENDOR_ID_SIANO ,SDIO_DEVICE_ID_SIANO_NOVA_A0 ), + .driver_data =SMS1XXX_BOARD_SIANO_NOVA_A }, + {SDIO_DEVICE (SDIO_VENDOR_ID_SIANO ,SDIO_DEVICE_ID_SIANO_NOVA_B0 ), + .driver_data =SMS1XXX_BOARD_SIANO_NOVA_B }, + {SDIO_DEVICE (SDIO_VENDOR_ID_SIANO ,SDIO_DEVICE_ID_SIANO_VEGA_A0 ), + .driver_data =SMS1XXX_BOARD_SIANO_VEGA }, + {SDIO_DEVICE (SDIO_VENDOR_ID_SIANO ,SDIO_DEVICE_ID_SIANO_VENICE ), + .driver_data =SMS1XXX_BOARD_SIANO_VEGA }, + {/* end: all zeroes */ }, +}; + +MODULE_DEVICE_TABLE (sdio, smssdio_ids); + +struct smssdio_device { +struct sdio_func *func; + +struct smscore_device_t *coredev; + +struct smscore_buffer_t *split_cb; +}; + +/*******************************************************************/ +/* Siano core callbacks */ +/*******************************************************************/ + +static int smssdio_sendrequest (void *context,void *buffer,size_t size) +{ +int ret; +struct smssdio_device *smsdev; + + smsdev = context; + +sdio_claim_host (smsdev->func); + +while (size >= smsdev->func->cur_blksize) { + ret =sdio_write_blocks (smsdev->func,SMSSDIO_DATA , buffer,1 ); +if (ret) + goto out; + + buffer += smsdev->func->cur_blksize; + size -= smsdev->func->cur_blksize; + } + +if (size) { + ret =sdio_write_bytes (smsdev->func,SMSSDIO_DATA , + buffer, size); +if (ret) + goto out; + } + +out: +sdio_release_host (smsdev->func); + +return ret; +} + +/*******************************************************************/ +/* SDIO callbacks */ +/*******************************************************************/ + +static void smssdio_interrupt (struct sdio_func *func) +{ +int ret, isr; + +struct smssdio_device *smsdev; +struct smscore_buffer_t *cb; +struct SmsMsgHdr_ST *hdr; +size_t size; + + smsdev =sdio_get_drvdata (func); + +/* +* The interrupt register has no defined meaning. It is just +* a way of turning of the level triggered interrupt. +*/ + isr =sdio_readb (func,SMSSDIO_INT , &ret); +if (ret) { +dev_err (&smsdev->func->dev, +"Unable to read interrupt register!\n" ); +return ; + } + +if (smsdev->split_cb ==NULL ) { + cb =smscore_getbuffer (smsdev->coredev); +if (!cb) { +dev_err (&smsdev->func->dev, +"Unable to allocate data buffer!\n" ); +return ; + } + + ret =sdio_read_blocks (smsdev->func, cb->p,SMSSDIO_DATA ,1 ); +if (ret) { +dev_err (&smsdev->func->dev, +"Error %d reading initial block!\n" , ret); +return ; + } + + hdr = cb->p; + +if (hdr->msgFlags &MSG_HDR_FLAG_SPLIT_MSG ) { + smsdev->split_cb = cb; +return ; + } + + size = hdr->msgLength - smsdev->func->cur_blksize; + }else { + cb = smsdev->split_cb; + hdr = cb->p; + + size = hdr->msgLength -sizeof (struct SmsMsgHdr_ST ); + + smsdev->split_cb =NULL ; + } + +if (hdr->msgLength > smsdev->func->cur_blksize) { +void *buffer; + + size =ALIGN (size,128 ); + buffer = cb->p + hdr->msgLength; + +BUG_ON (smsdev->func->cur_blksize !=128 ); + +/* +* First attempt to transfer all of it in one go... +*/ + ret =sdio_read_blocks (smsdev->func, buffer, +SMSSDIO_DATA , size /128 ); +if (ret && ret != -EINVAL ) { +smscore_putbuffer (smsdev->coredev, cb); +dev_err (&smsdev->func->dev, +"Error %d reading data from card!\n" , ret); +return ; + } + +/* +* ..then fall back to one block at a time if that is +* not possible... +* +* (we have to do this manually because of the +* problem with the "increase address" bit) +*/ +if (ret == -EINVAL ) { +while (size) { + ret =sdio_read_blocks (smsdev->func, + buffer,SMSSDIO_DATA ,1 ); +if (ret) { +smscore_putbuffer (smsdev->coredev, cb); +dev_err (&smsdev->func->dev, +"Error %d reading " +"data from card!\n" , ret); +return ; + } + + buffer += smsdev->func->cur_blksize; +if (size > smsdev->func->cur_blksize) + size -= smsdev->func->cur_blksize; +else + size =0 ; + } + } + } + + cb->size = hdr->msgLength; + cb->offset =0 ; + +smscore_onresponse (smsdev->coredev, cb); +} + +static int smssdio_probe (struct sdio_func *func, +const struct sdio_device_id *id) +{ +int ret; + +int board_id; +struct smssdio_device *smsdev; +struct smsdevice_params_t params; + + board_id = id->driver_data; + + smsdev =kzalloc (sizeof (struct smssdio_device ),GFP_KERNEL ); +if (!smsdev) +return -ENOMEM ; + + smsdev->func = func; + +memset (¶ms,0 ,sizeof (struct smsdevice_params_t )); + + params.device = &func->dev; + params.buffer_size =0x5000 ;/* ?? */ + params.num_buffers =22 ;/* ?? */ + params.context = smsdev; + +snprintf (params.devpath,sizeof (params.devpath), +"sdio\\%s" ,sdio_func_id (func)); + + params.sendrequest_handler = smssdio_sendrequest; + + params.device_type =sms_get_board (board_id)->type; + +if (params.device_type !=SMS_STELLAR ) + params.flags |=SMS_DEVICE_FAMILY2 ; +else { +/* +* FIXME: Stellar needs special handling... +*/ + ret = -ENODEV ; + goto free; + } + + ret =smscore_register_device (¶ms, &smsdev->coredev); +if (ret <0 ) + goto free; + +smscore_set_board_id (smsdev->coredev, board_id); + +sdio_claim_host (func); + + ret =sdio_enable_func (func); +if (ret) + goto release; + + ret =sdio_set_block_size (func,128 ); +if (ret) + goto disable; + + ret =sdio_claim_irq (func, smssdio_interrupt); +if (ret) + goto disable; + +sdio_set_drvdata (func, smsdev); + +sdio_release_host (func); + + ret =smscore_start_device (smsdev->coredev); +if (ret <0 ) + goto reclaim; + +return 0 ; + +reclaim: +sdio_claim_host (func); +sdio_release_irq (func); +disable: +sdio_disable_func (func); +release: +sdio_release_host (func); +smscore_unregister_device (smsdev->coredev); +free: +kfree (smsdev); + +return ret; +} + +static void smssdio_remove (struct sdio_func *func) +{ +struct smssdio_device *smsdev; + + smsdev =sdio_get_drvdata (func); + +/* FIXME: racy! */ +if (smsdev->split_cb) +smscore_putbuffer (smsdev->coredev, smsdev->split_cb); + +smscore_unregister_device (smsdev->coredev); + +sdio_claim_host (func); +sdio_release_irq (func); +sdio_disable_func (func); +sdio_release_host (func); + +kfree (smsdev); +} + +static struct sdio_driver smssdio_driver = { + .name ="smssdio" , + .id_table = smssdio_ids, + .probe = smssdio_probe, + .remove = smssdio_remove, +}; + +/*******************************************************************/ +/* Module functions */ +/*******************************************************************/ + +int smssdio_register (void ) +{ +int ret =0 ; + +printk (KERN_INFO "smssdio: Siano SMS1xxx SDIO driver\n" ); +printk (KERN_INFO "smssdio: Copyright Pierre Ossman\n" ); + + ret =sdio_register_driver (&smssdio_driver); + +return ret; +} + +void smssdio_unregister (void ) +{ +sdio_unregister_driver (&smssdio_driver); +} + +MODULE_DESCRIPTION ("Siano SMS1xxx SDIO driver" ); +MODULE_AUTHOR ("Pierre Ossman" ); +MODULE_LICENSE ("GPL" );
Hello, Uri
Quoted 27 lines · Uri Shkolnik
# HG changeset patch
# User Uri Shkolnik <[email protected]>
# Date 1236865697 -7200
# Node ID7352ee1288f651d19d58c7bb479a98f070ad98e6
# Parent3392722cc5b687586c4d898b73050ab6e59bf401
siano: add high level SDIO interface driver for SMS based cardsFrom: Uri Shkolnik <[email protected]>
This patch provides SDIO interface driver for SMS (Siano Mobile Silicon) based devices. The patch includes SMS high level SDIO driver and requires patching the kernel SDIO stack, those stack patches had been provided previously.
I would like to thank Pierre Ossman, MMC maintainer, who wrote this driver.
Priority: normal
Signed-off-by Pierre Ossman <[email protected]>Signed-off-by Uri Shkolnik <[email protected]>diff -r
3392722cc5b6-r7352ee1288f6linux/drivers/media/dvb/siano/smssdio.c
linux/drivers/media/dvb/siano/smssdio.c line 4
Quoted 4 lines
linux/drivers/media/dvb/siano/smssdio.c new file +4
-0@@ -0,0 +1,356 @@ +/* +* smssdio.c - Siano 1xxx SDIO interface driver +* +* Copyright 2008 Pierre Ossman
I'm sorry, but may be 2009 ?
Quoted 87 lines
linux/drivers/media/dvb/siano/smssdio.c new file +87
-0+* +* Based on code by Siano Mobile Silicon, Inc., +* Copyright (C) 2006-2008, Uri Shkolnik +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. +* +* +* This hardware is a bit odd in that all transfers should be done +* to/from the SMSSDIO_DATA register, yet the "increase address" bit +* always needs to be set. +* +* Also, buffers from the card are always aligned to 128 byte +* boundaries. +*/ + +/* +* General cleanup notes: +* +* - only typedefs should be name *_t +* +* - use ERR_PTR and friends for smscore_register_device() +* +* - smscore_getbuffer should zero fields +* +* Fix stop command +*/ + +#include <linux/moduleparam.h> +#include <linux/firmware.h> +#include <linux/delay.h> +#include <linux/mmc/card.h> +#include <linux/mmc/sdio_func.h> +#include <linux/mmc/sdio_ids.h> + +#include "smscoreapi.h" +#include "sms-cards.h" + +/* Registers */ + +#define SMSSDIO_DATA 0x00 +#define SMSSDIO_INT 0x04 + +static const struct sdio_device_id smssdio_ids[] = { + {SDIO_DEVICE (SDIO_VENDOR_ID_SIANO ,SDIO_DEVICE_ID_SIANO_STELLAR ), + .driver_data =SMS1XXX_BOARD_SIANO_STELLAR }, + {SDIO_DEVICE (SDIO_VENDOR_ID_SIANO ,SDIO_DEVICE_ID_SIANO_NOVA_A0 ), + .driver_data =SMS1XXX_BOARD_SIANO_NOVA_A }, + {SDIO_DEVICE (SDIO_VENDOR_ID_SIANO ,SDIO_DEVICE_ID_SIANO_NOVA_B0 ), + .driver_data =SMS1XXX_BOARD_SIANO_NOVA_B }, + {SDIO_DEVICE (SDIO_VENDOR_ID_SIANO ,SDIO_DEVICE_ID_SIANO_VEGA_A0 ), + .driver_data =SMS1XXX_BOARD_SIANO_VEGA }, + {SDIO_DEVICE (SDIO_VENDOR_ID_SIANO ,SDIO_DEVICE_ID_SIANO_VENICE ), + .driver_data =SMS1XXX_BOARD_SIANO_VEGA }, + {/* end: all zeroes */ }, +}; + +MODULE_DEVICE_TABLE (sdio, smssdio_ids); + +struct smssdio_device { +struct sdio_func *func; + +struct smscore_device_t *coredev; + +struct smscore_buffer_t *split_cb; +}; + +/*******************************************************************/ +/* Siano core callbacks */ +/*******************************************************************/ + +static int smssdio_sendrequest (void *context,void *buffer,size_t size) +{ +int ret; +struct smssdio_device *smsdev; + + smsdev = context; + +sdio_claim_host (smsdev->func); + +while (size >= smsdev->func->cur_blksize) { + ret =sdio_write_blocks (smsdev->func,SMSSDIO_DATA , buffer,1 ); +if (ret) + goto out; +
linux/drivers/media/dvb/siano/smssdio.c line 101
Quoted 10 lines
linux/drivers/media/dvb/siano/smssdio.c new file +10
-0+ buffer += smsdev->func->cur_blksize; + size -= smsdev->func->cur_blksize; + } + +if (size) { + ret =sdio_write_bytes (smsdev->func,SMSSDIO_DATA , + buffer, size); +if (ret) + goto out; + }
Do you really need this check and goto ? Without them, as i see, the algorithm will do the same.
Quoted 203 lines
linux/drivers/media/dvb/siano/smssdio.c new file +203
-0+ +out: +sdio_release_host (smsdev->func); + +return ret; +} + +/*******************************************************************/ +/* SDIO callbacks */ +/*******************************************************************/ + +static void smssdio_interrupt (struct sdio_func *func) +{ +int ret, isr; + +struct smssdio_device *smsdev; +struct smscore_buffer_t *cb; +struct SmsMsgHdr_ST *hdr; +size_t size; + + smsdev =sdio_get_drvdata (func); + +/* +* The interrupt register has no defined meaning. It is just +* a way of turning of the level triggered interrupt. +*/ + isr =sdio_readb (func,SMSSDIO_INT , &ret); +if (ret) { +dev_err (&smsdev->func->dev, +"Unable to read interrupt register!\n" ); +return ; + } + +if (smsdev->split_cb ==NULL ) { + cb =smscore_getbuffer (smsdev->coredev); +if (!cb) { +dev_err (&smsdev->func->dev, +"Unable to allocate data buffer!\n" ); +return ; + } + + ret =sdio_read_blocks (smsdev->func, cb->p,SMSSDIO_DATA ,1 ); +if (ret) { +dev_err (&smsdev->func->dev, +"Error %d reading initial block!\n" , ret); +return ; + } + + hdr = cb->p; + +if (hdr->msgFlags &MSG_HDR_FLAG_SPLIT_MSG ) { + smsdev->split_cb = cb; +return ; + } + + size = hdr->msgLength - smsdev->func->cur_blksize; + }else { + cb = smsdev->split_cb; + hdr = cb->p; + + size = hdr->msgLength -sizeof (struct SmsMsgHdr_ST ); + + smsdev->split_cb =NULL ; + } + +if (hdr->msgLength > smsdev->func->cur_blksize) { +void *buffer; + + size =ALIGN (size,128 ); + buffer = cb->p + hdr->msgLength; + +BUG_ON (smsdev->func->cur_blksize !=128 ); + +/* +* First attempt to transfer all of it in one go... +*/ + ret =sdio_read_blocks (smsdev->func, buffer, +SMSSDIO_DATA , size /128 ); +if (ret && ret != -EINVAL ) { +smscore_putbuffer (smsdev->coredev, cb); +dev_err (&smsdev->func->dev, +"Error %d reading data from card!\n" , ret); +return ; + } + +/* +* ..then fall back to one block at a time if that is +* not possible... +* +* (we have to do this manually because of the +* problem with the "increase address" bit) +*/ +if (ret == -EINVAL ) { +while (size) { + ret =sdio_read_blocks (smsdev->func, + buffer,SMSSDIO_DATA ,1 ); +if (ret) { +smscore_putbuffer (smsdev->coredev, cb); +dev_err (&smsdev->func->dev, +"Error %d reading " +"data from card!\n" , ret); +return ; + } + + buffer += smsdev->func->cur_blksize; +if (size > smsdev->func->cur_blksize) + size -= smsdev->func->cur_blksize; +else + size =0 ; + } + } + } + + cb->size = hdr->msgLength; + cb->offset =0 ; + +smscore_onresponse (smsdev->coredev, cb); +} + +static int smssdio_probe (struct sdio_func *func, +const struct sdio_device_id *id) +{ +int ret; + +int board_id; +struct smssdio_device *smsdev; +struct smsdevice_params_t params; + + board_id = id->driver_data; + + smsdev =kzalloc (sizeof (struct smssdio_device ),GFP_KERNEL ); +if (!smsdev) +return -ENOMEM ; + + smsdev->func = func; + +memset (¶ms,0 ,sizeof (struct smsdevice_params_t )); + + params.device = &func->dev; + params.buffer_size =0x5000 ;/* ?? */ + params.num_buffers =22 ;/* ?? */ + params.context = smsdev; + +snprintf (params.devpath,sizeof (params.devpath), +"sdio\\%s" ,sdio_func_id (func)); + + params.sendrequest_handler = smssdio_sendrequest; + + params.device_type =sms_get_board (board_id)->type; + +if (params.device_type !=SMS_STELLAR ) + params.flags |=SMS_DEVICE_FAMILY2 ; +else { +/* +* FIXME: Stellar needs special handling... +*/ + ret = -ENODEV ; + goto free; + } + + ret =smscore_register_device (¶ms, &smsdev->coredev); +if (ret <0 ) + goto free; + +smscore_set_board_id (smsdev->coredev, board_id); + +sdio_claim_host (func); + + ret =sdio_enable_func (func); +if (ret) + goto release; + + ret =sdio_set_block_size (func,128 ); +if (ret) + goto disable; + + ret =sdio_claim_irq (func, smssdio_interrupt); +if (ret) + goto disable; + +sdio_set_drvdata (func, smsdev); + +sdio_release_host (func); + + ret =smscore_start_device (smsdev->coredev); +if (ret <0 ) + goto reclaim; + +return 0 ; + +reclaim: +sdio_claim_host (func); +sdio_release_irq (func); +disable: +sdio_disable_func (func); +release: +sdio_release_host (func); +smscore_unregister_device (smsdev->coredev); +free: +kfree (smsdev); + +return ret; +}
linux/drivers/media/dvb/siano/smssdio.c line 314
Quoted 10 lines
linux/drivers/media/dvb/siano/smssdio.c new file +10
-0+ +static void smssdio_remove (struct sdio_func *func) +{ +struct smssdio_device *smsdev; + + smsdev =sdio_get_drvdata (func); + +/* FIXME: racy! */ +if (smsdev->split_cb) +smscore_putbuffer (smsdev->coredev, smsdev->split_cb);
May be you want to introduce mutex lock or even spinlock to prevent race condition ?
Quoted 13 lines
linux/drivers/media/dvb/siano/smssdio.c new file +13
-0+ +smscore_unregister_device (smsdev->coredev); + +sdio_claim_host (func); +sdio_release_irq (func); +sdio_disable_func (func); +sdio_release_host (func); + +kfree (smsdev); +} + +static struct sdio_driver smssdio_driver = { + .name ="smssdio" ,
linux/drivers/media/dvb/siano/smssdio.c line 337
Quoted 10 lines
linux/drivers/media/dvb/siano/smssdio.c new file +10
-0+ .id_table = smssdio_ids, + .probe = smssdio_probe, + .remove = smssdio_remove, +}; + +/*******************************************************************/ +/* Module functions */ +/*******************************************************************/ + +int smssdio_register (void )
Dont you want to make this function static int __init ?
linux/drivers/media/dvb/siano/smssdio.c line 349
Quoted 12 lines
linux/drivers/media/dvb/siano/smssdio.c new file +12
-0+{ +int ret =0 ; + +printk (KERN_INFO "smssdio: Siano SMS1xxx SDIO driver\n" ); +printk (KERN_INFO "smssdio: Copyright Pierre Ossman\n" ); + + ret =sdio_register_driver (&smssdio_driver); + +return ret; +} + +void smssdio_unregister (void )
And the same here - static void __exit ?
linux/drivers/media/dvb/siano/smssdio.c line 356
Quoted 7 lines
linux/drivers/media/dvb/siano/smssdio.c new file +7
-0+{ +sdio_unregister_driver (&smssdio_driver); +} + +MODULE_DESCRIPTION ("Siano SMS1xxx SDIO driver" ); +MODULE_AUTHOR ("Pierre Ossman" ); +MODULE_LICENSE ("GPL" );
Good luck,
Signature · 1 line
best regards, Klimov Alexey
Hi Uri,
The patch looks sane, but I'd like to have a better picture of the Siano device, to better understand this interface.
The basic question is: why do we need an SDIO interface for a DVB device? For what reason this interface is needed?
It helps if you could forward me some information about the architecture of Siano, to help me to understand the requirements.
Cheers,
Mauro.
Quoted 378 lines · On Thu, 12 Mar 2009 06:52:59 -0700 (PDT) Uri Shkolnik <[email protected]> wrote:
# HG changeset patch
# User Uri Shkolnik <[email protected]>
# Date 1236865697 -7200
# Node ID7352ee1288f651d19d58c7bb479a98f070ad98e6
# Parent3392722cc5b687586c4d898b73050ab6e59bf401
siano: add high level SDIO interface driver for SMS based cardsFrom: Uri Shkolnik <[email protected]>
This patch provides SDIO interface driver for SMS (Siano Mobile Silicon) based devices. The patch includes SMS high level SDIO driver and requires patching the kernel SDIO stack, those stack patches had been provided previously.
I would like to thank Pierre Ossman, MMC maintainer, who wrote this driver.
Priority: normal
Signed-off-by Pierre Ossman <[email protected]>Signed-off-by Uri Shkolnik <[email protected]>diff -r
3392722cc5b6-r7352ee1288f6linux/drivers/media/dvb/siano/smssdio.clinux/drivers/media/dvb/siano/smssdio.c new file +346
-0@@ -0,0 +1,356 @@ +/* +* smssdio.c - Siano 1xxx SDIO interface driver +* +* Copyright 2008 Pierre Ossman +* +* Based on code by Siano Mobile Silicon, Inc., +* Copyright (C) 2006-2008, Uri Shkolnik +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. +* +* +* This hardware is a bit odd in that all transfers should be done +* to/from the SMSSDIO_DATA register, yet the "increase address" bit +* always needs to be set. +* +* Also, buffers from the card are always aligned to 128 byte +* boundaries. +*/ + +/* +* General cleanup notes: +* +* - only typedefs should be name *_t +* +* - use ERR_PTR and friends for smscore_register_device() +* +* - smscore_getbuffer should zero fields +* +* Fix stop command +*/ + +#include <linux/moduleparam.h> +#include <linux/firmware.h> +#include <linux/delay.h> +#include <linux/mmc/card.h> +#include <linux/mmc/sdio_func.h> +#include <linux/mmc/sdio_ids.h> + +#include "smscoreapi.h" +#include "sms-cards.h" + +/* Registers */ + +#define SMSSDIO_DATA 0x00 +#define SMSSDIO_INT 0x04 + +static const struct sdio_device_id smssdio_ids[] = { + {SDIO_DEVICE (SDIO_VENDOR_ID_SIANO ,SDIO_DEVICE_ID_SIANO_STELLAR ), + .driver_data =SMS1XXX_BOARD_SIANO_STELLAR }, + {SDIO_DEVICE (SDIO_VENDOR_ID_SIANO ,SDIO_DEVICE_ID_SIANO_NOVA_A0 ), + .driver_data =SMS1XXX_BOARD_SIANO_NOVA_A }, + {SDIO_DEVICE (SDIO_VENDOR_ID_SIANO ,SDIO_DEVICE_ID_SIANO_NOVA_B0 ), + .driver_data =SMS1XXX_BOARD_SIANO_NOVA_B }, + {SDIO_DEVICE (SDIO_VENDOR_ID_SIANO ,SDIO_DEVICE_ID_SIANO_VEGA_A0 ), + .driver_data =SMS1XXX_BOARD_SIANO_VEGA }, + {SDIO_DEVICE (SDIO_VENDOR_ID_SIANO ,SDIO_DEVICE_ID_SIANO_VENICE ), + .driver_data =SMS1XXX_BOARD_SIANO_VEGA }, + {/* end: all zeroes */ }, +}; + +MODULE_DEVICE_TABLE (sdio, smssdio_ids); + +struct smssdio_device { +struct sdio_func *func; + +struct smscore_device_t *coredev; + +struct smscore_buffer_t *split_cb; +}; + +/*******************************************************************/ +/* Siano core callbacks */ +/*******************************************************************/ + +static int smssdio_sendrequest (void *context,void *buffer,size_t size) +{ +int ret; +struct smssdio_device *smsdev; + + smsdev = context; + +sdio_claim_host (smsdev->func); + +while (size >= smsdev->func->cur_blksize) { + ret =sdio_write_blocks (smsdev->func,SMSSDIO_DATA , buffer,1 ); +if (ret) + goto out; + + buffer += smsdev->func->cur_blksize; + size -= smsdev->func->cur_blksize; + } + +if (size) { + ret =sdio_write_bytes (smsdev->func,SMSSDIO_DATA , + buffer, size); +if (ret) + goto out; + } + +out: +sdio_release_host (smsdev->func); + +return ret; +} + +/*******************************************************************/ +/* SDIO callbacks */ +/*******************************************************************/ + +static void smssdio_interrupt (struct sdio_func *func) +{ +int ret, isr; + +struct smssdio_device *smsdev; +struct smscore_buffer_t *cb; +struct SmsMsgHdr_ST *hdr; +size_t size; + + smsdev =sdio_get_drvdata (func); + +/* +* The interrupt register has no defined meaning. It is just +* a way of turning of the level triggered interrupt. +*/ + isr =sdio_readb (func,SMSSDIO_INT , &ret); +if (ret) { +dev_err (&smsdev->func->dev, +"Unable to read interrupt register!\n" ); +return ; + } + +if (smsdev->split_cb ==NULL ) { + cb =smscore_getbuffer (smsdev->coredev); +if (!cb) { +dev_err (&smsdev->func->dev, +"Unable to allocate data buffer!\n" ); +return ; + } + + ret =sdio_read_blocks (smsdev->func, cb->p,SMSSDIO_DATA ,1 ); +if (ret) { +dev_err (&smsdev->func->dev, +"Error %d reading initial block!\n" , ret); +return ; + } + + hdr = cb->p; + +if (hdr->msgFlags &MSG_HDR_FLAG_SPLIT_MSG ) { + smsdev->split_cb = cb; +return ; + } + + size = hdr->msgLength - smsdev->func->cur_blksize; + }else { + cb = smsdev->split_cb; + hdr = cb->p; + + size = hdr->msgLength -sizeof (struct SmsMsgHdr_ST ); + + smsdev->split_cb =NULL ; + } + +if (hdr->msgLength > smsdev->func->cur_blksize) { +void *buffer; + + size =ALIGN (size,128 ); + buffer = cb->p + hdr->msgLength; + +BUG_ON (smsdev->func->cur_blksize !=128 ); + +/* +* First attempt to transfer all of it in one go... +*/ + ret =sdio_read_blocks (smsdev->func, buffer, +SMSSDIO_DATA , size /128 ); +if (ret && ret != -EINVAL ) { +smscore_putbuffer (smsdev->coredev, cb); +dev_err (&smsdev->func->dev, +"Error %d reading data from card!\n" , ret); +return ; + } + +/* +* ..then fall back to one block at a time if that is +* not possible... +* +* (we have to do this manually because of the +* problem with the "increase address" bit) +*/ +if (ret == -EINVAL ) { +while (size) { + ret =sdio_read_blocks (smsdev->func, + buffer,SMSSDIO_DATA ,1 ); +if (ret) { +smscore_putbuffer (smsdev->coredev, cb); +dev_err (&smsdev->func->dev, +"Error %d reading " +"data from card!\n" , ret); +return ; + } + + buffer += smsdev->func->cur_blksize; +if (size > smsdev->func->cur_blksize) + size -= smsdev->func->cur_blksize; +else + size =0 ; + } + } + } + + cb->size = hdr->msgLength; + cb->offset =0 ; + +smscore_onresponse (smsdev->coredev, cb); +} + +static int smssdio_probe (struct sdio_func *func, +const struct sdio_device_id *id) +{ +int ret; + +int board_id; +struct smssdio_device *smsdev; +struct smsdevice_params_t params; + + board_id = id->driver_data; + + smsdev =kzalloc (sizeof (struct smssdio_device ),GFP_KERNEL ); +if (!smsdev) +return -ENOMEM ; + + smsdev->func = func; + +memset (¶ms,0 ,sizeof (struct smsdevice_params_t )); + + params.device = &func->dev; + params.buffer_size =0x5000 ;/* ?? */ + params.num_buffers =22 ;/* ?? */ + params.context = smsdev; + +snprintf (params.devpath,sizeof (params.devpath), +"sdio\\%s" ,sdio_func_id (func)); + + params.sendrequest_handler = smssdio_sendrequest; + + params.device_type =sms_get_board (board_id)->type; + +if (params.device_type !=SMS_STELLAR ) + params.flags |=SMS_DEVICE_FAMILY2 ; +else { +/* +* FIXME: Stellar needs special handling... +*/ + ret = -ENODEV ; + goto free; + } + + ret =smscore_register_device (¶ms, &smsdev->coredev); +if (ret <0 ) + goto free; + +smscore_set_board_id (smsdev->coredev, board_id); + +sdio_claim_host (func); + + ret =sdio_enable_func (func); +if (ret) + goto release; + + ret =sdio_set_block_size (func,128 ); +if (ret) + goto disable; + + ret =sdio_claim_irq (func, smssdio_interrupt); +if (ret) + goto disable; + +sdio_set_drvdata (func, smsdev); + +sdio_release_host (func); + + ret =smscore_start_device (smsdev->coredev); +if (ret <0 ) + goto reclaim; + +return 0 ; + +reclaim: +sdio_claim_host (func); +sdio_release_irq (func); +disable: +sdio_disable_func (func); +release: +sdio_release_host (func); +smscore_unregister_device (smsdev->coredev); +free: +kfree (smsdev); + +return ret; +} + +static void smssdio_remove (struct sdio_func *func) +{ +struct smssdio_device *smsdev; + + smsdev =sdio_get_drvdata (func); + +/* FIXME: racy! */ +if (smsdev->split_cb) +smscore_putbuffer (smsdev->coredev, smsdev->split_cb); + +smscore_unregister_device (smsdev->coredev); + +sdio_claim_host (func); +sdio_release_irq (func); +sdio_disable_func (func); +sdio_release_host (func); + +kfree (smsdev); +} + +static struct sdio_driver smssdio_driver = { + .name ="smssdio" , + .id_table = smssdio_ids, + .probe = smssdio_probe, + .remove = smssdio_remove, +}; + +/*******************************************************************/ +/* Module functions */ +/*******************************************************************/ + +int smssdio_register (void ) +{ +int ret =0 ; + +printk (KERN_INFO "smssdio: Siano SMS1xxx SDIO driver\n" ); +printk (KERN_INFO "smssdio: Copyright Pierre Ossman\n" ); + + ret =sdio_register_driver (&smssdio_driver); + +return ret;
linux/drivers/media/dvb/siano/smssdio.c line 356
Quoted 10 lines
linux/drivers/media/dvb/siano/smssdio.c new file +10
-0+} + +void smssdio_unregister (void ) +{ +sdio_unregister_driver (&smssdio_driver); +} + +MODULE_DESCRIPTION ("Siano SMS1xxx SDIO driver" ); +MODULE_AUTHOR ("Pierre Ossman" ); +MODULE_LICENSE ("GPL" );
Cheers,
Mauro
Hi Mauro,
(sorry for hijacking) (since when do we like top-posts ? ;) )
Quoted 7 lines · Mauro Carvalho Chehab
Hi Uri,
The patch looks sane, but I'd like to have a better picture of the Siano device, to better understand this interface.
The basic question is: why do we need an SDIO interface for a DVB device? For what reason this interface is needed?
The answer is relatively easy: Some hosts only have a SDIO interface, so no USB, no PCI, no I2C, no MPEG2-streaming interface. So, the device has to provide a SDIO interface in order to read and write register and to make DMAs to get the data to the host. Think of your cell-phone, or your PDA.
There are some/a lot of vendors who use Linux in their commercial mobile-TV product and there are some component-makers like Siano, who are supporting those vendors through GPL drivers.
regards,
Patrick.
Quoted 3 lines · On Sat, 14 Mar 2009 12:02:02 +0100 (CET) Patrick Boettcher…
Hi Mauro,
(sorry for hijacking) (since when do we like top-posts ? ;) )
You're welcome.
Quoted 16 lines · Mauro Carvalho Chehab
Quoted 8 lines
Hi Uri,
The patch looks sane, but I'd like to have a better picture of the Siano device, to better understand this interface.
The basic question is: why do we need an SDIO interface for a DVB device? For what reason this interface is needed?
The answer is relatively easy: Some hosts only have a SDIO interface, so no USB, no PCI, no I2C, no MPEG2-streaming interface. So, the device has to provide a SDIO interface in order to read and write register and to make DMAs to get the data to the host. Think of your cell-phone, or your PDA.
Quoted 3 lines
There are some/a lot of vendors who use Linux in their commercial mobile-TV product and there are some component-makers like Siano, who are supporting those vendors through GPL drivers.
Ok, so, if I understand well, the SDIO interface will be used just like we currently use the I2C or USB bus, right?
So, we should create some glue between DVB and SDIO bus just like we have with PCI, USB, I2C, etc.
Ideally something like (using the design we currently have with dvb-usb):
+------------+
| DVB driver |
+------------+
|
V
+----------+
| DVB SDIO |
+----------+
|
V
+----------+
| DVB Core |
+----------+Is that what you're thinking?
Cheers,
Mauro
Quoted 9 lines · Mauro Carvalho Chehab
Quoted 5 lines
The answer is relatively easy: Some hosts only have a SDIO interface, so no USB, no PCI, no I2C, no MPEG2-streaming interface. So, the device has to provide a SDIO interface in order to read and write register and to make DMAs to get the data to the host. Think of your cell-phone, or your PDA.
Ok, so, if I understand well, the SDIO interface will be used just like we currently use the I2C or USB bus, right?
Quoted 6 lines
So, we should create some glue between DVB and SDIO bus just like we have with PCI, USB, I2C, etc.
Ideally something like (using the design we currently have with dvb-usb):
[...]
Actually, when I created dvb-usb with the help of a lot of contributors, it served the purpose (and still serves) that there is a lot of different USB-based DVB devices which are delivering data. Bascially every DVB-USB-box/card-vendor is using a generic or specific USB-device-controller which implements some kind of high-level interface to do e.g. I2C and streaming. Those implementations, the USB protocol and its Linux-HAL requires some overhead to implement a driver. It was useful to create some common module and interface.
With SDIO I can't really see the same right now. First of all, SDIO should be much simpler as USB from the HAL point of view. Correct me if I'm wrong, but the SDIO-host controller should give "simple" DMA access to the device?.
Another thing for me is, there isn't many SDIO DVB devices out there right now, where Linux support is required (the latter is a pity ;) ). Also, the major part of supported DVB devices in Linux is PC-based and for PC (as of today) there is PCI(e) and USB working quite well, no one needs a SDIO device.
Having an SDIO device filling in to the DVB-API is rather straight forward, which makes me think that right now there is no need for a dvb-sdio.ko .
Patrick.
PS: please check the date of this email, when reading it in an archive in 2 years ;)