2008-07-15 19:02:21 +04:00
/*
2011-03-23 14:42:44 +03:00
* linux / drivers / mmc / host / tmio_mmc . c
2008-07-15 19:02:21 +04:00
*
2011-03-23 14:42:44 +03:00
* Copyright ( C ) 2007 Ian Molton
* Copyright ( C ) 2004 Ian Molton
2008-07-15 19:02:21 +04:00
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation .
*
* Driver for the MMC / SD / SDIO cell found in :
*
2009-06-04 22:12:37 +04:00
* TC6393XB TC6391XB TC6387XB T7L66XB ASIC3
2008-07-15 19:02:21 +04:00
*/
2010-11-23 19:24:11 +03:00
# include <linux/device.h>
2008-07-15 19:02:21 +04:00
# include <linux/mfd/core.h>
# include <linux/mfd/tmio.h>
2010-11-23 19:24:11 +03:00
# include <linux/mmc/host.h>
# include <linux/module.h>
# include <linux/pagemap.h>
# include <linux/scatterlist.h>
2011-01-06 01:36:14 +03:00
2011-03-23 14:42:44 +03:00
# include "tmio_mmc.h"
2008-07-15 19:02:21 +04:00
2013-10-23 16:57:50 +04:00
# ifdef CONFIG_PM_SLEEP
static int tmio_mmc_suspend ( struct device * dev )
2008-07-15 19:02:21 +04:00
{
2013-10-23 16:57:50 +04:00
struct platform_device * pdev = to_platform_device ( dev ) ;
const struct mfd_cell * cell = mfd_get_cell ( pdev ) ;
2008-07-15 19:02:21 +04:00
int ret ;
2014-08-25 14:28:20 +04:00
ret = pm_runtime_force_suspend ( dev ) ;
2008-07-15 19:02:21 +04:00
/* Tell MFD core it can disable us now.*/
if ( ! ret & & cell - > disable )
2013-10-23 16:57:50 +04:00
cell - > disable ( pdev ) ;
2008-07-15 19:02:21 +04:00
return ret ;
}
2013-10-23 16:57:50 +04:00
static int tmio_mmc_resume ( struct device * dev )
2008-07-15 19:02:21 +04:00
{
2013-10-23 16:57:50 +04:00
struct platform_device * pdev = to_platform_device ( dev ) ;
const struct mfd_cell * cell = mfd_get_cell ( pdev ) ;
2008-07-15 19:02:21 +04:00
int ret = 0 ;
/* Tell the MFD core we are ready to be enabled */
2011-05-05 20:13:12 +04:00
if ( cell - > resume )
2013-10-23 16:57:50 +04:00
ret = cell - > resume ( pdev ) ;
2008-07-15 19:02:21 +04:00
2011-05-05 20:13:12 +04:00
if ( ! ret )
2014-08-25 14:28:20 +04:00
ret = pm_runtime_force_resume ( dev ) ;
2008-07-15 19:02:21 +04:00
return ret ;
}
# endif
2012-11-19 22:23:06 +04:00
static int tmio_mmc_probe ( struct platform_device * pdev )
2008-07-15 19:02:21 +04:00
{
2011-03-23 14:42:44 +03:00
const struct mfd_cell * cell = mfd_get_cell ( pdev ) ;
2009-06-04 22:12:31 +04:00
struct tmio_mmc_data * pdata ;
2008-07-15 19:02:21 +04:00
struct tmio_mmc_host * host ;
2013-11-20 12:30:55 +04:00
struct resource * res ;
2011-05-06 15:02:33 +04:00
int ret = - EINVAL , irq ;
2008-07-15 19:02:21 +04:00
2011-03-23 14:42:44 +03:00
if ( pdev - > num_resources ! = 2 )
2008-07-15 19:02:21 +04:00
goto out ;
2011-04-06 13:38:14 +04:00
pdata = pdev - > dev . platform_data ;
2009-06-04 22:12:34 +04:00
if ( ! pdata | | ! pdata - > hclk )
2009-06-04 22:12:31 +04:00
goto out ;
2009-06-04 22:12:34 +04:00
2011-05-06 15:02:33 +04:00
irq = platform_get_irq ( pdev , 0 ) ;
if ( irq < 0 ) {
ret = irq ;
goto out ;
}
2008-07-15 19:02:21 +04:00
/* Tell the MFD core we are ready to be enabled */
if ( cell - > enable ) {
2011-03-23 14:42:44 +03:00
ret = cell - > enable ( pdev ) ;
2008-07-15 19:02:21 +04:00
if ( ret )
2011-03-23 14:42:44 +03:00
goto out ;
2008-07-15 19:02:21 +04:00
}
2013-11-20 12:30:55 +04:00
res = platform_get_resource ( pdev , IORESOURCE_MEM , 0 ) ;
if ( ! res )
return - EINVAL ;
/* SD control register space size is 0x200, 0x400 for bus_shift=1 */
2014-01-08 05:33:51 +04:00
pdata - > bus_shift = resource_size ( res ) > > 10 ;
2013-11-20 12:31:06 +04:00
pdata - > flags | = TMIO_MMC_HAVE_HIGH_REG ;
2013-11-20 12:30:55 +04:00
2011-03-23 14:42:44 +03:00
ret = tmio_mmc_host_probe ( & host , pdev , pdata ) ;
2008-07-15 19:02:21 +04:00
if ( ret )
2010-02-17 10:38:23 +03:00
goto cell_disable ;
2008-07-15 19:02:21 +04:00
2011-09-22 12:59:04 +04:00
ret = request_irq ( irq , tmio_mmc_irq , IRQF_TRIGGER_FALLING ,
dev_name ( & pdev - > dev ) , host ) ;
2011-05-06 15:02:33 +04:00
if ( ret )
goto host_remove ;
2010-05-19 22:34:22 +04:00
pr_info ( " %s at 0x%08lx irq %d \n " , mmc_hostname ( host - > mmc ) ,
2011-05-06 15:02:33 +04:00
( unsigned long ) host - > ctl , irq ) ;
2008-07-15 19:02:21 +04:00
return 0 ;
2011-05-06 15:02:33 +04:00
host_remove :
tmio_mmc_host_remove ( host ) ;
2010-02-17 10:38:23 +03:00
cell_disable :
if ( cell - > disable )
2011-03-23 14:42:44 +03:00
cell - > disable ( pdev ) ;
2008-07-15 19:02:21 +04:00
out :
return ret ;
}
2012-11-19 22:26:03 +04:00
static int tmio_mmc_remove ( struct platform_device * pdev )
2008-07-15 19:02:21 +04:00
{
2011-03-23 14:42:44 +03:00
const struct mfd_cell * cell = mfd_get_cell ( pdev ) ;
struct mmc_host * mmc = platform_get_drvdata ( pdev ) ;
2008-07-15 19:02:21 +04:00
if ( mmc ) {
2011-05-06 15:02:33 +04:00
struct tmio_mmc_host * host = mmc_priv ( mmc ) ;
free_irq ( platform_get_irq ( pdev , 0 ) , host ) ;
tmio_mmc_host_remove ( host ) ;
2010-02-17 10:38:23 +03:00
if ( cell - > disable )
2011-03-23 14:42:44 +03:00
cell - > disable ( pdev ) ;
2008-07-15 19:02:21 +04:00
}
return 0 ;
}
/* ------------------- device registration ----------------------- */
2013-10-23 16:57:50 +04:00
static const struct dev_pm_ops tmio_mmc_dev_pm_ops = {
SET_SYSTEM_SLEEP_PM_OPS ( tmio_mmc_suspend , tmio_mmc_resume )
2014-12-04 02:34:11 +03:00
SET_RUNTIME_PM_OPS ( tmio_mmc_host_runtime_suspend ,
2014-08-25 14:12:02 +04:00
tmio_mmc_host_runtime_resume ,
NULL )
2013-10-23 16:57:50 +04:00
} ;
2008-07-15 19:02:21 +04:00
static struct platform_driver tmio_mmc_driver = {
. driver = {
. name = " tmio-mmc " ,
. owner = THIS_MODULE ,
2013-10-23 16:57:50 +04:00
. pm = & tmio_mmc_dev_pm_ops ,
2008-07-15 19:02:21 +04:00
} ,
. probe = tmio_mmc_probe ,
2012-11-19 22:20:26 +04:00
. remove = tmio_mmc_remove ,
2008-07-15 19:02:21 +04:00
} ;
2011-11-26 08:55:43 +04:00
module_platform_driver ( tmio_mmc_driver ) ;
2008-07-15 19:02:21 +04:00
MODULE_DESCRIPTION ( " Toshiba TMIO SD/MMC driver " ) ;
MODULE_AUTHOR ( " Ian Molton <spyro@f2s.com> " ) ;
MODULE_LICENSE ( " GPL v2 " ) ;
MODULE_ALIAS ( " platform:tmio-mmc " ) ;