2018-12-17 14:23:36 +02:00
// SPDX-License-Identifier: GPL-2.0
2011-02-22 21:46:18 +01:00
/*
* AD7606 Parallel Interface ADC driver
*
* Copyright 2011 Analog Devices Inc .
*/
# include <linux/module.h>
# include <linux/platform_device.h>
# include <linux/types.h>
# include <linux/err.h>
# include <linux/io.h>
2012-04-25 15:54:58 +01:00
# include <linux/iio/iio.h>
2011-02-22 21:46:18 +01:00
# include "ad7606.h"
static int ad7606_par16_read_block ( struct device * dev ,
2015-10-14 21:14:13 +03:00
int count , void * buf )
2011-02-22 21:46:18 +01:00
{
2018-04-19 16:06:18 +02:00
struct iio_dev * indio_dev = dev_get_drvdata ( dev ) ;
2011-05-18 14:42:01 +01:00
struct ad7606_state * st = iio_priv ( indio_dev ) ;
2011-02-22 21:46:18 +01:00
2015-10-14 21:14:15 +03:00
insw ( ( unsigned long ) st - > base_address , buf , count ) ;
2011-02-22 21:46:18 +01:00
return 0 ;
}
static const struct ad7606_bus_ops ad7606_par16_bops = {
2018-12-17 14:23:38 +02:00
. read_block = ad7606_par16_read_block ,
2011-02-22 21:46:18 +01:00
} ;
static int ad7606_par8_read_block ( struct device * dev ,
2015-10-14 21:14:13 +03:00
int count , void * buf )
2011-02-22 21:46:18 +01:00
{
2018-04-19 16:06:18 +02:00
struct iio_dev * indio_dev = dev_get_drvdata ( dev ) ;
2011-05-18 14:42:01 +01:00
struct ad7606_state * st = iio_priv ( indio_dev ) ;
2011-02-22 21:46:18 +01:00
2015-10-14 21:14:15 +03:00
insb ( ( unsigned long ) st - > base_address , buf , count * 2 ) ;
2011-02-22 21:46:18 +01:00
return 0 ;
}
static const struct ad7606_bus_ops ad7606_par8_bops = {
2018-12-17 14:23:38 +02:00
. read_block = ad7606_par8_read_block ,
2011-02-22 21:46:18 +01:00
} ;
2012-11-19 13:21:57 -05:00
static int ad7606_par_probe ( struct platform_device * pdev )
2011-02-22 21:46:18 +01:00
{
2016-10-19 19:06:57 +02:00
const struct platform_device_id * id = platform_get_device_id ( pdev ) ;
2011-02-22 21:46:18 +01:00
struct resource * res ;
void __iomem * addr ;
resource_size_t remap_size ;
2014-01-07 19:44:00 +00:00
int irq ;
2011-02-22 21:46:18 +01:00
irq = platform_get_irq ( pdev , 0 ) ;
2019-07-30 11:15:19 -07:00
if ( irq < 0 )
2017-08-09 10:38:56 -05:00
return irq ;
2011-02-22 21:46:18 +01:00
res = platform_get_resource ( pdev , IORESOURCE_MEM , 0 ) ;
2014-01-07 19:44:00 +00:00
addr = devm_ioremap_resource ( & pdev - > dev , res ) ;
if ( IS_ERR ( addr ) )
return PTR_ERR ( addr ) ;
2011-02-22 21:46:18 +01:00
remap_size = resource_size ( res ) ;
2016-10-19 19:07:04 +02:00
return ad7606_probe ( & pdev - > dev , irq , addr ,
id - > name , id - > driver_data ,
remap_size > 1 ? & ad7606_par16_bops :
& ad7606_par8_bops ) ;
2011-02-22 21:46:18 +01:00
}
2015-05-02 00:43:22 +09:00
static const struct platform_device_id ad7606_driver_ids [ ] = {
2018-12-17 14:23:38 +02:00
{ . name = " ad7605-4 " , . driver_data = ID_AD7605_4 , } ,
{ . name = " ad7606-4 " , . driver_data = ID_AD7606_4 , } ,
{ . name = " ad7606-6 " , . driver_data = ID_AD7606_6 , } ,
{ . name = " ad7606-8 " , . driver_data = ID_AD7606_8 , } ,
2011-02-22 21:46:18 +01:00
{ }
} ;
MODULE_DEVICE_TABLE ( platform , ad7606_driver_ids ) ;
2018-12-13 14:46:20 +02:00
static const struct of_device_id ad7606_of_match [ ] = {
{ . compatible = " adi,ad7605-4 " } ,
{ . compatible = " adi,ad7606-4 " } ,
{ . compatible = " adi,ad7606-6 " } ,
{ . compatible = " adi,ad7606-8 " } ,
{ } ,
} ;
MODULE_DEVICE_TABLE ( of , ad7606_of_match ) ;
2011-02-22 21:46:18 +01:00
static struct platform_driver ad7606_driver = {
. probe = ad7606_par_probe ,
. id_table = ad7606_driver_ids ,
. driver = {
2018-12-17 14:23:38 +02:00
. name = " ad7606 " ,
. pm = AD7606_PM_OPS ,
2018-12-13 14:46:20 +02:00
. of_match_table = ad7606_of_match ,
2011-02-22 21:46:18 +01:00
} ,
} ;
2012-03-01 10:51:05 +01:00
module_platform_driver ( ad7606_driver ) ;
2011-02-22 21:46:18 +01:00
2018-08-14 13:23:17 +02:00
MODULE_AUTHOR ( " Michael Hennerich <michael.hennerich@analog.com> " ) ;
2011-02-22 21:46:18 +01:00
MODULE_DESCRIPTION ( " Analog Devices AD7606 ADC " ) ;
MODULE_LICENSE ( " GPL v2 " ) ;