2019-05-29 17:18:02 +03:00
// SPDX-License-Identifier: GPL-2.0-only
2009-12-15 01:20:22 +03:00
/*
2011-06-06 11:16:30 +04:00
* PCI interface driver for DW SPI Core
2009-12-15 01:20:22 +03:00
*
2014-08-29 13:41:43 +04:00
* Copyright ( c ) 2009 , 2014 Intel Corporation .
2009-12-15 01:20:22 +03:00
*/
# include <linux/pci.h>
2019-10-18 16:21:30 +03:00
# include <linux/pm_runtime.h>
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 11:04:11 +03:00
# include <linux/slab.h>
2009-12-15 01:20:22 +03:00
# include <linux/spi/spi.h>
2011-07-03 23:44:29 +04:00
# include <linux/module.h>
2009-12-15 01:20:22 +03:00
2011-06-06 11:16:30 +04:00
# include "spi-dw.h"
2011-02-28 22:47:12 +03:00
2009-12-15 01:20:22 +03:00
# define DRIVER_NAME "dw_spi_pci"
2020-05-29 16:11:59 +03:00
/* HW info for MRST Clk Control Unit, 32b reg per controller */
# define MRST_SPI_CLK_BASE 100000000 /* 100m */
# define MRST_CLK_SPI_REG 0xff11d86c
# define CLK_SPI_BDIV_OFFSET 0
# define CLK_SPI_BDIV_MASK 0x00000007
# define CLK_SPI_CDIV_OFFSET 9
# define CLK_SPI_CDIV_MASK 0x00000e00
# define CLK_SPI_DISABLE_OFFSET 8
2021-11-15 21:19:13 +03:00
struct dw_spi_pci_desc {
2014-08-29 13:41:42 +04:00
int ( * setup ) ( struct dw_spi * ) ;
2015-01-07 18:15:00 +03:00
u16 num_cs ;
u16 bus_num ;
2019-08-12 13:13:44 +03:00
u32 max_freq ;
2014-08-29 13:41:42 +04:00
} ;
2021-11-15 21:19:13 +03:00
static int dw_spi_pci_mid_init ( struct dw_spi * dws )
2020-05-29 16:11:59 +03:00
{
void __iomem * clk_reg ;
u32 clk_cdiv ;
clk_reg = ioremap ( MRST_CLK_SPI_REG , 16 ) ;
if ( ! clk_reg )
return - ENOMEM ;
/* Get SPI controller operating freq info */
clk_cdiv = readl ( clk_reg + dws - > bus_num * sizeof ( u32 ) ) ;
clk_cdiv & = CLK_SPI_CDIV_MASK ;
clk_cdiv > > = CLK_SPI_CDIV_OFFSET ;
dws - > max_freq = MRST_SPI_CLK_BASE / ( clk_cdiv + 1 ) ;
iounmap ( clk_reg ) ;
2020-05-29 16:12:02 +03:00
dw_spi_dma_setup_mfld ( dws ) ;
2020-05-29 16:11:59 +03:00
return 0 ;
}
2021-11-15 21:19:13 +03:00
static int dw_spi_pci_generic_init ( struct dw_spi * dws )
2020-05-29 16:11:59 +03:00
{
2020-05-29 16:12:02 +03:00
dw_spi_dma_setup_generic ( dws ) ;
2020-05-29 16:11:59 +03:00
return 0 ;
}
2021-11-15 21:19:13 +03:00
static struct dw_spi_pci_desc dw_spi_pci_mid_desc_1 = {
. setup = dw_spi_pci_mid_init ,
2015-02-23 18:55:54 +03:00
. num_cs = 5 ,
2015-01-07 18:15:00 +03:00
. bus_num = 0 ,
} ;
2021-11-15 21:19:13 +03:00
static struct dw_spi_pci_desc dw_spi_pci_mid_desc_2 = {
. setup = dw_spi_pci_mid_init ,
2015-02-23 18:55:54 +03:00
. num_cs = 2 ,
2015-01-07 18:15:00 +03:00
. bus_num = 1 ,
2014-08-29 13:41:42 +04:00
} ;
2021-11-15 21:19:13 +03:00
static struct dw_spi_pci_desc dw_spi_pci_ehl_desc = {
. setup = dw_spi_pci_generic_init ,
2019-10-18 16:21:31 +03:00
. num_cs = 2 ,
2019-08-12 13:13:44 +03:00
. bus_num = - 1 ,
. max_freq = 100000000 ,
} ;
2021-11-15 21:19:13 +03:00
static int dw_spi_pci_probe ( struct pci_dev * pdev , const struct pci_device_id * ent )
2009-12-15 01:20:22 +03:00
{
2021-11-15 21:19:13 +03:00
struct dw_spi_pci_desc * desc = ( struct dw_spi_pci_desc * ) ent - > driver_data ;
2009-12-15 01:20:22 +03:00
struct dw_spi * dws ;
int pci_bar = 0 ;
int ret ;
2013-12-30 22:30:44 +04:00
ret = pcim_enable_device ( pdev ) ;
2009-12-15 01:20:22 +03:00
if ( ret )
return ret ;
2015-10-14 23:12:24 +03:00
dws = devm_kzalloc ( & pdev - > dev , sizeof ( * dws ) , GFP_KERNEL ) ;
if ( ! dws )
2013-12-30 22:30:44 +04:00
return - ENOMEM ;
2009-12-15 01:20:22 +03:00
/* Get basic io resource and map it */
dws - > paddr = pci_resource_start ( pdev , pci_bar ) ;
2019-10-01 11:14:05 +03:00
pci_set_master ( pdev ) ;
2009-12-15 01:20:22 +03:00
2014-08-29 13:41:40 +04:00
ret = pcim_iomap_regions ( pdev , 1 < < pci_bar , pci_name ( pdev ) ) ;
2009-12-15 01:20:22 +03:00
if ( ret )
2013-12-30 22:30:44 +04:00
return ret ;
2009-12-15 01:20:22 +03:00
2019-10-01 11:14:05 +03:00
ret = pci_alloc_irq_vectors ( pdev , 1 , 1 , PCI_IRQ_ALL_TYPES ) ;
if ( ret < 0 )
return ret ;
2014-08-27 17:21:12 +04:00
dws - > regs = pcim_iomap_table ( pdev ) [ pci_bar ] ;
2019-10-01 11:14:05 +03:00
dws - > irq = pci_irq_vector ( pdev , 0 ) ;
2010-12-24 08:59:11 +03:00
/*
2016-05-10 21:59:58 +03:00
* Specific handling for platforms , like dma setup ,
2010-12-24 08:59:11 +03:00
* clock rate , FIFO depth .
*/
2015-01-07 18:15:00 +03:00
if ( desc ) {
2015-01-22 18:59:34 +03:00
dws - > num_cs = desc - > num_cs ;
dws - > bus_num = desc - > bus_num ;
2019-08-12 13:13:44 +03:00
dws - > max_freq = desc - > max_freq ;
2015-01-22 18:59:34 +03:00
2015-01-07 18:15:00 +03:00
if ( desc - > setup ) {
ret = desc - > setup ( dws ) ;
if ( ret )
2020-09-15 04:22:49 +03:00
goto err_free_irq_vectors ;
2015-01-07 18:15:00 +03:00
}
} else {
2020-09-15 04:22:49 +03:00
ret = - ENODEV ;
goto err_free_irq_vectors ;
2010-12-24 08:59:11 +03:00
}
2009-12-15 01:20:22 +03:00
2013-12-30 22:30:44 +04:00
ret = dw_spi_add_host ( & pdev - > dev , dws ) ;
2020-09-15 04:22:49 +03:00
if ( ret )
goto err_free_irq_vectors ;
2009-12-15 01:20:22 +03:00
/* PCI hook and SPI hook use the same drv data */
2015-10-14 23:12:24 +03:00
pci_set_drvdata ( pdev , dws ) ;
2009-12-15 01:20:22 +03:00
2014-08-29 13:41:39 +04:00
dev_info ( & pdev - > dev , " found PCI SPI controller(ID: %04x:%04x) \n " ,
pdev - > vendor , pdev - > device ) ;
2019-10-18 16:21:30 +03:00
pm_runtime_set_autosuspend_delay ( & pdev - > dev , 1000 ) ;
pm_runtime_use_autosuspend ( & pdev - > dev ) ;
pm_runtime_put_autosuspend ( & pdev - > dev ) ;
pm_runtime_allow ( & pdev - > dev ) ;
2013-12-30 22:30:44 +04:00
return 0 ;
2020-09-15 04:22:49 +03:00
err_free_irq_vectors :
pci_free_irq_vectors ( pdev ) ;
return ret ;
2009-12-15 01:20:22 +03:00
}
2021-11-15 21:19:13 +03:00
static void dw_spi_pci_remove ( struct pci_dev * pdev )
2009-12-15 01:20:22 +03:00
{
2015-10-14 23:12:24 +03:00
struct dw_spi * dws = pci_get_drvdata ( pdev ) ;
2009-12-15 01:20:22 +03:00
2019-10-18 16:21:30 +03:00
pm_runtime_forbid ( & pdev - > dev ) ;
pm_runtime_get_noresume ( & pdev - > dev ) ;
2015-10-14 23:12:24 +03:00
dw_spi_remove_host ( dws ) ;
2019-10-01 11:14:05 +03:00
pci_free_irq_vectors ( pdev ) ;
2009-12-15 01:20:22 +03:00
}
2014-08-29 13:41:41 +04:00
# ifdef CONFIG_PM_SLEEP
2021-11-15 21:19:13 +03:00
static int dw_spi_pci_suspend ( struct device * dev )
2009-12-15 01:20:22 +03:00
{
2019-07-24 15:23:31 +03:00
struct dw_spi * dws = dev_get_drvdata ( dev ) ;
2009-12-15 01:20:22 +03:00
2015-10-14 23:12:24 +03:00
return dw_spi_suspend_host ( dws ) ;
2009-12-15 01:20:22 +03:00
}
2021-11-15 21:19:13 +03:00
static int dw_spi_pci_resume ( struct device * dev )
2009-12-15 01:20:22 +03:00
{
2019-07-24 15:23:31 +03:00
struct dw_spi * dws = dev_get_drvdata ( dev ) ;
2009-12-15 01:20:22 +03:00
2015-10-14 23:12:24 +03:00
return dw_spi_resume_host ( dws ) ;
2009-12-15 01:20:22 +03:00
}
# endif
2021-11-15 21:19:13 +03:00
static SIMPLE_DEV_PM_OPS ( dw_spi_pci_pm_ops , dw_spi_pci_suspend , dw_spi_pci_resume ) ;
2014-08-29 13:41:41 +04:00
2021-11-15 21:19:13 +03:00
static const struct pci_device_id dw_spi_pci_ids [ ] = {
2010-12-24 08:59:11 +03:00
/* Intel MID platform SPI controller 0 */
2015-01-07 18:15:00 +03:00
/*
* The access to the device 8086 : 0801 is disabled by HW , since it ' s
* exclusively used by SCU to communicate with MSIC .
*/
/* Intel MID platform SPI controller 1 */
2021-11-15 21:19:13 +03:00
{ PCI_VDEVICE ( INTEL , 0x0800 ) , ( kernel_ulong_t ) & dw_spi_pci_mid_desc_1 } ,
2015-01-07 18:15:00 +03:00
/* Intel MID platform SPI controller 2 */
2021-11-15 21:19:13 +03:00
{ PCI_VDEVICE ( INTEL , 0x0812 ) , ( kernel_ulong_t ) & dw_spi_pci_mid_desc_2 } ,
2019-08-12 13:13:44 +03:00
/* Intel Elkhart Lake PSE SPI controllers */
2021-11-15 21:19:13 +03:00
{ PCI_VDEVICE ( INTEL , 0x4b84 ) , ( kernel_ulong_t ) & dw_spi_pci_ehl_desc } ,
{ PCI_VDEVICE ( INTEL , 0x4b85 ) , ( kernel_ulong_t ) & dw_spi_pci_ehl_desc } ,
{ PCI_VDEVICE ( INTEL , 0x4b86 ) , ( kernel_ulong_t ) & dw_spi_pci_ehl_desc } ,
{ PCI_VDEVICE ( INTEL , 0x4b87 ) , ( kernel_ulong_t ) & dw_spi_pci_ehl_desc } ,
2009-12-15 01:20:22 +03:00
{ } ,
} ;
2021-11-15 21:19:13 +03:00
MODULE_DEVICE_TABLE ( pci , dw_spi_pci_ids ) ;
2009-12-15 01:20:22 +03:00
2021-11-15 21:19:13 +03:00
static struct pci_driver dw_spi_pci_driver = {
2009-12-15 01:20:22 +03:00
. name = DRIVER_NAME ,
2021-11-15 21:19:13 +03:00
. id_table = dw_spi_pci_ids ,
. probe = dw_spi_pci_probe ,
. remove = dw_spi_pci_remove ,
2014-08-29 13:41:41 +04:00
. driver = {
2021-11-15 21:19:13 +03:00
. pm = & dw_spi_pci_pm_ops ,
2014-08-29 13:41:41 +04:00
} ,
2009-12-15 01:20:22 +03:00
} ;
2021-11-15 21:19:13 +03:00
module_pci_driver ( dw_spi_pci_driver ) ;
2009-12-15 01:20:22 +03:00
MODULE_AUTHOR ( " Feng Tang <feng.tang@intel.com> " ) ;
MODULE_DESCRIPTION ( " PCI interface driver for DW SPI Core " ) ;
MODULE_LICENSE ( " GPL v2 " ) ;
2021-11-15 21:19:11 +03:00
MODULE_IMPORT_NS ( SPI_DW_CORE ) ;