2008-02-06 17:39:01 +08:00
|
|
|
/*
|
|
|
|
* w1-gpio - GPIO w1 bus master driver
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 Ville Syrjala <syrjala@sci.fi>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/platform_device.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 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2008-02-06 17:39:01 +08:00
|
|
|
#include <linux/w1-gpio.h>
|
2017-09-27 02:27:09 +08:00
|
|
|
#include <linux/gpio/consumer.h>
|
2012-07-23 22:36:35 +08:00
|
|
|
#include <linux/of_platform.h>
|
2012-11-22 05:13:29 +08:00
|
|
|
#include <linux/err.h>
|
2012-11-22 05:13:47 +08:00
|
|
|
#include <linux/of.h>
|
2014-01-24 07:56:18 +08:00
|
|
|
#include <linux/delay.h>
|
2008-02-06 17:39:01 +08:00
|
|
|
|
2017-06-05 21:52:08 +08:00
|
|
|
#include <linux/w1.h>
|
2008-02-06 17:39:01 +08:00
|
|
|
|
2014-01-24 07:56:18 +08:00
|
|
|
static u8 w1_gpio_set_pullup(void *data, int delay)
|
|
|
|
{
|
|
|
|
struct w1_gpio_platform_data *pdata = data;
|
|
|
|
|
|
|
|
if (delay) {
|
|
|
|
pdata->pullup_duration = delay;
|
|
|
|
} else {
|
|
|
|
if (pdata->pullup_duration) {
|
2017-09-27 02:27:09 +08:00
|
|
|
/*
|
|
|
|
* This will OVERRIDE open drain emulation and force-pull
|
|
|
|
* the line high for some time.
|
|
|
|
*/
|
|
|
|
gpiod_set_raw_value(pdata->gpiod, 1);
|
2014-01-24 07:56:18 +08:00
|
|
|
msleep(pdata->pullup_duration);
|
2017-09-27 02:27:09 +08:00
|
|
|
/*
|
|
|
|
* This will simply set the line as input since we are doing
|
|
|
|
* open drain emulation in the GPIO library.
|
|
|
|
*/
|
|
|
|
gpiod_set_value(pdata->gpiod, 1);
|
2014-01-24 07:56:18 +08:00
|
|
|
}
|
|
|
|
pdata->pullup_duration = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-09-27 02:27:09 +08:00
|
|
|
static void w1_gpio_write_bit(void *data, u8 bit)
|
2008-02-06 17:39:01 +08:00
|
|
|
{
|
|
|
|
struct w1_gpio_platform_data *pdata = data;
|
|
|
|
|
2017-09-27 02:27:09 +08:00
|
|
|
gpiod_set_value(pdata->gpiod, bit);
|
2008-02-06 17:39:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static u8 w1_gpio_read_bit(void *data)
|
|
|
|
{
|
|
|
|
struct w1_gpio_platform_data *pdata = data;
|
|
|
|
|
2017-09-27 02:27:09 +08:00
|
|
|
return gpiod_get_value(pdata->gpiod) ? 1 : 0;
|
2008-02-06 17:39:01 +08:00
|
|
|
}
|
|
|
|
|
2013-03-08 18:08:00 +08:00
|
|
|
#if defined(CONFIG_OF)
|
2015-03-17 03:20:29 +08:00
|
|
|
static const struct of_device_id w1_gpio_dt_ids[] = {
|
2012-07-23 22:36:35 +08:00
|
|
|
{ .compatible = "w1-gpio" },
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, w1_gpio_dt_ids);
|
2013-03-08 18:08:00 +08:00
|
|
|
#endif
|
2012-07-23 22:36:35 +08:00
|
|
|
|
2013-01-28 04:07:57 +08:00
|
|
|
static int w1_gpio_probe(struct platform_device *pdev)
|
2008-02-06 17:39:01 +08:00
|
|
|
{
|
|
|
|
struct w1_bus_master *master;
|
2012-07-23 22:36:35 +08:00
|
|
|
struct w1_gpio_platform_data *pdata;
|
2017-09-27 02:27:09 +08:00
|
|
|
struct device *dev = &pdev->dev;
|
|
|
|
struct device_node *np = dev->of_node;
|
|
|
|
/* Enforce open drain mode by default */
|
|
|
|
enum gpiod_flags gflags = GPIOD_OUT_LOW_OPEN_DRAIN;
|
2008-02-06 17:39:01 +08:00
|
|
|
int err;
|
|
|
|
|
2012-11-22 05:13:47 +08:00
|
|
|
if (of_have_populated_dt()) {
|
2017-09-27 02:27:09 +08:00
|
|
|
pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
|
|
|
|
if (!pdata)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This parameter means that something else than the gpiolib has
|
|
|
|
* already set the line into open drain mode, so we should just
|
|
|
|
* driver it high/low like we are in full control of the line and
|
|
|
|
* open drain will happen transparently.
|
|
|
|
*/
|
|
|
|
if (of_get_property(np, "linux,open-drain", NULL))
|
|
|
|
gflags = GPIOD_OUT_LOW;
|
|
|
|
|
|
|
|
pdev->dev.platform_data = pdata;
|
2012-11-22 05:13:47 +08:00
|
|
|
}
|
2017-09-27 02:27:09 +08:00
|
|
|
pdata = dev_get_platdata(dev);
|
2012-07-23 22:36:35 +08:00
|
|
|
|
2012-11-22 05:13:47 +08:00
|
|
|
if (!pdata) {
|
2017-09-27 02:27:09 +08:00
|
|
|
dev_err(dev, "No configuration data\n");
|
2008-02-06 17:39:01 +08:00
|
|
|
return -ENXIO;
|
2012-11-22 05:13:47 +08:00
|
|
|
}
|
2008-02-06 17:39:01 +08:00
|
|
|
|
2017-09-27 02:27:09 +08:00
|
|
|
master = devm_kzalloc(dev, sizeof(struct w1_bus_master),
|
2013-10-29 16:19:24 +08:00
|
|
|
GFP_KERNEL);
|
2012-11-22 05:13:47 +08:00
|
|
|
if (!master) {
|
2017-09-27 02:27:09 +08:00
|
|
|
dev_err(dev, "Out of memory\n");
|
2008-02-06 17:39:01 +08:00
|
|
|
return -ENOMEM;
|
2012-11-22 05:13:47 +08:00
|
|
|
}
|
2008-02-06 17:39:01 +08:00
|
|
|
|
2017-09-27 02:27:09 +08:00
|
|
|
pdata->gpiod = devm_gpiod_get_index(dev, NULL, 0, gflags);
|
|
|
|
if (IS_ERR(pdata->gpiod)) {
|
|
|
|
dev_err(dev, "gpio_request (pin) failed\n");
|
|
|
|
return PTR_ERR(pdata->gpiod);
|
2012-11-22 05:13:47 +08:00
|
|
|
}
|
2008-02-06 17:39:01 +08:00
|
|
|
|
2017-09-27 02:27:09 +08:00
|
|
|
pdata->pullup_gpiod =
|
|
|
|
devm_gpiod_get_index_optional(dev, NULL, 1, GPIOD_OUT_LOW);
|
|
|
|
if (IS_ERR(pdata->pullup_gpiod)) {
|
|
|
|
dev_err(dev, "gpio_request_one "
|
|
|
|
"(ext_pullup_enable_pin) failed\n");
|
|
|
|
return PTR_ERR(pdata->pullup_gpiod);
|
2012-07-26 04:54:29 +08:00
|
|
|
}
|
|
|
|
|
2008-02-06 17:39:01 +08:00
|
|
|
master->data = pdata;
|
|
|
|
master->read_bit = w1_gpio_read_bit;
|
2017-09-27 02:27:09 +08:00
|
|
|
gpiod_direction_output(pdata->gpiod, 1);
|
|
|
|
master->write_bit = w1_gpio_write_bit;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we are using open drain emulation from the GPIO library,
|
|
|
|
* we need to use this pullup function that hammers the line
|
|
|
|
* high using a raw accessor to provide pull-up for the w1
|
|
|
|
* line.
|
|
|
|
*/
|
|
|
|
if (gflags == GPIOD_OUT_LOW_OPEN_DRAIN)
|
2014-01-24 07:56:18 +08:00
|
|
|
master->set_pullup = w1_gpio_set_pullup;
|
2008-02-06 17:39:01 +08:00
|
|
|
|
|
|
|
err = w1_add_master_device(master);
|
2012-11-22 05:13:47 +08:00
|
|
|
if (err) {
|
2017-09-27 02:27:09 +08:00
|
|
|
dev_err(dev, "w1_add_master device failed\n");
|
2013-10-29 16:19:24 +08:00
|
|
|
return err;
|
2012-11-22 05:13:47 +08:00
|
|
|
}
|
2008-02-06 17:39:01 +08:00
|
|
|
|
2009-06-18 07:28:15 +08:00
|
|
|
if (pdata->enable_external_pullup)
|
|
|
|
pdata->enable_external_pullup(1);
|
|
|
|
|
2017-09-27 02:27:09 +08:00
|
|
|
if (pdata->pullup_gpiod)
|
|
|
|
gpiod_set_value(pdata->pullup_gpiod, 1);
|
2012-07-26 04:54:29 +08:00
|
|
|
|
2008-02-06 17:39:01 +08:00
|
|
|
platform_set_drvdata(pdev, master);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-03-08 18:07:59 +08:00
|
|
|
static int w1_gpio_remove(struct platform_device *pdev)
|
2008-02-06 17:39:01 +08:00
|
|
|
{
|
|
|
|
struct w1_bus_master *master = platform_get_drvdata(pdev);
|
2013-11-15 06:32:04 +08:00
|
|
|
struct w1_gpio_platform_data *pdata = dev_get_platdata(&pdev->dev);
|
2008-02-06 17:39:01 +08:00
|
|
|
|
2009-06-18 07:28:15 +08:00
|
|
|
if (pdata->enable_external_pullup)
|
|
|
|
pdata->enable_external_pullup(0);
|
|
|
|
|
2017-09-27 02:27:09 +08:00
|
|
|
if (pdata->pullup_gpiod)
|
|
|
|
gpiod_set_value(pdata->pullup_gpiod, 0);
|
2012-07-26 04:54:29 +08:00
|
|
|
|
2008-02-06 17:39:01 +08:00
|
|
|
w1_remove_master_device(master);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-10-18 02:39:40 +08:00
|
|
|
static int __maybe_unused w1_gpio_suspend(struct device *dev)
|
2009-06-18 07:28:15 +08:00
|
|
|
{
|
2015-10-18 02:39:40 +08:00
|
|
|
struct w1_gpio_platform_data *pdata = dev_get_platdata(dev);
|
2009-06-18 07:28:15 +08:00
|
|
|
|
|
|
|
if (pdata->enable_external_pullup)
|
|
|
|
pdata->enable_external_pullup(0);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-10-18 02:39:40 +08:00
|
|
|
static int __maybe_unused w1_gpio_resume(struct device *dev)
|
2009-06-18 07:28:15 +08:00
|
|
|
{
|
2015-10-18 02:39:40 +08:00
|
|
|
struct w1_gpio_platform_data *pdata = dev_get_platdata(dev);
|
2009-06-18 07:28:15 +08:00
|
|
|
|
|
|
|
if (pdata->enable_external_pullup)
|
|
|
|
pdata->enable_external_pullup(1);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-10-18 02:39:40 +08:00
|
|
|
static SIMPLE_DEV_PM_OPS(w1_gpio_pm_ops, w1_gpio_suspend, w1_gpio_resume);
|
2009-06-18 07:28:15 +08:00
|
|
|
|
2008-02-06 17:39:01 +08:00
|
|
|
static struct platform_driver w1_gpio_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "w1-gpio",
|
2015-10-18 02:39:40 +08:00
|
|
|
.pm = &w1_gpio_pm_ops,
|
2012-07-23 22:36:35 +08:00
|
|
|
.of_match_table = of_match_ptr(w1_gpio_dt_ids),
|
2008-02-06 17:39:01 +08:00
|
|
|
},
|
2012-11-22 05:13:47 +08:00
|
|
|
.probe = w1_gpio_probe,
|
2015-10-18 02:39:40 +08:00
|
|
|
.remove = w1_gpio_remove,
|
2008-02-06 17:39:01 +08:00
|
|
|
};
|
|
|
|
|
2012-11-22 05:13:47 +08:00
|
|
|
module_platform_driver(w1_gpio_driver);
|
2008-02-06 17:39:01 +08:00
|
|
|
|
|
|
|
MODULE_DESCRIPTION("GPIO w1 bus master driver");
|
|
|
|
MODULE_AUTHOR("Ville Syrjala <syrjala@sci.fi>");
|
|
|
|
MODULE_LICENSE("GPL");
|