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>
|
2012-02-05 00:33:55 +08:00
|
|
|
#include <linux/gpio.h>
|
2012-07-23 22:36:35 +08:00
|
|
|
#include <linux/of_platform.h>
|
|
|
|
#include <linux/of_gpio.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
|
|
|
|
|
|
|
#include "../w1.h"
|
|
|
|
#include "../w1_int.h"
|
|
|
|
|
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) {
|
|
|
|
gpio_direction_output(pdata->pin, 1);
|
|
|
|
|
|
|
|
msleep(pdata->pullup_duration);
|
|
|
|
|
|
|
|
gpio_direction_input(pdata->pin);
|
|
|
|
}
|
|
|
|
pdata->pullup_duration = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-02-06 17:39:01 +08:00
|
|
|
static void w1_gpio_write_bit_dir(void *data, u8 bit)
|
|
|
|
{
|
|
|
|
struct w1_gpio_platform_data *pdata = data;
|
|
|
|
|
|
|
|
if (bit)
|
|
|
|
gpio_direction_input(pdata->pin);
|
|
|
|
else
|
|
|
|
gpio_direction_output(pdata->pin, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void w1_gpio_write_bit_val(void *data, u8 bit)
|
|
|
|
{
|
|
|
|
struct w1_gpio_platform_data *pdata = data;
|
|
|
|
|
|
|
|
gpio_set_value(pdata->pin, bit);
|
|
|
|
}
|
|
|
|
|
|
|
|
static u8 w1_gpio_read_bit(void *data)
|
|
|
|
{
|
|
|
|
struct w1_gpio_platform_data *pdata = data;
|
|
|
|
|
2009-03-13 05:31:25 +08:00
|
|
|
return gpio_get_value(pdata->pin) ? 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
|
|
|
|
|
|
|
static int w1_gpio_probe_dt(struct platform_device *pdev)
|
|
|
|
{
|
2013-11-15 06:32:04 +08:00
|
|
|
struct w1_gpio_platform_data *pdata = dev_get_platdata(&pdev->dev);
|
2012-07-23 22:36:35 +08:00
|
|
|
struct device_node *np = pdev->dev.of_node;
|
2013-10-29 16:19:23 +08:00
|
|
|
int gpio;
|
2012-07-23 22:36:35 +08:00
|
|
|
|
|
|
|
pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
|
|
|
|
if (!pdata)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
if (of_get_property(np, "linux,open-drain", NULL))
|
|
|
|
pdata->is_open_drain = 1;
|
|
|
|
|
2013-10-29 16:19:23 +08:00
|
|
|
gpio = of_get_gpio(np, 0);
|
2014-02-14 06:05:28 +08:00
|
|
|
if (gpio < 0) {
|
|
|
|
if (gpio != -EPROBE_DEFER)
|
|
|
|
dev_err(&pdev->dev,
|
|
|
|
"Failed to parse gpio property for data pin (%d)\n",
|
|
|
|
gpio);
|
|
|
|
|
2013-10-29 16:19:23 +08:00
|
|
|
return gpio;
|
2014-02-14 06:05:28 +08:00
|
|
|
}
|
2013-10-29 16:19:23 +08:00
|
|
|
pdata->pin = gpio;
|
|
|
|
|
2014-02-14 06:05:28 +08:00
|
|
|
gpio = of_get_gpio(np, 1);
|
|
|
|
if (gpio == -EPROBE_DEFER)
|
|
|
|
return gpio;
|
|
|
|
/* ignore other errors as the pullup gpio is optional */
|
|
|
|
pdata->ext_pullup_enable_pin = gpio;
|
|
|
|
|
2012-07-23 22:36:35 +08:00
|
|
|
pdev->dev.platform_data = pdata;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
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;
|
2008-02-06 17:39:01 +08:00
|
|
|
int err;
|
|
|
|
|
2012-11-22 05:13:47 +08:00
|
|
|
if (of_have_populated_dt()) {
|
|
|
|
err = w1_gpio_probe_dt(pdev);
|
2014-02-14 06:05:28 +08:00
|
|
|
if (err < 0)
|
2012-11-22 05:13:47 +08:00
|
|
|
return err;
|
|
|
|
}
|
2012-07-23 22:36:35 +08:00
|
|
|
|
2013-11-15 06:32:04 +08:00
|
|
|
pdata = dev_get_platdata(&pdev->dev);
|
2012-07-23 22:36:35 +08:00
|
|
|
|
2012-11-22 05:13:47 +08:00
|
|
|
if (!pdata) {
|
|
|
|
dev_err(&pdev->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
|
|
|
|
2013-10-29 16:19:24 +08:00
|
|
|
master = devm_kzalloc(&pdev->dev, sizeof(struct w1_bus_master),
|
|
|
|
GFP_KERNEL);
|
2012-11-22 05:13:47 +08:00
|
|
|
if (!master) {
|
|
|
|
dev_err(&pdev->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
|
|
|
|
2013-10-29 16:19:24 +08:00
|
|
|
err = devm_gpio_request(&pdev->dev, pdata->pin, "w1");
|
2012-11-22 05:13:47 +08:00
|
|
|
if (err) {
|
|
|
|
dev_err(&pdev->dev, "gpio_request (pin) 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
|
|
|
|
2012-07-26 04:54:29 +08:00
|
|
|
if (gpio_is_valid(pdata->ext_pullup_enable_pin)) {
|
2013-10-29 16:19:24 +08:00
|
|
|
err = devm_gpio_request_one(&pdev->dev,
|
|
|
|
pdata->ext_pullup_enable_pin, GPIOF_INIT_LOW,
|
|
|
|
"w1 pullup");
|
2012-11-22 05:13:47 +08:00
|
|
|
if (err < 0) {
|
|
|
|
dev_err(&pdev->dev, "gpio_request_one "
|
|
|
|
"(ext_pullup_enable_pin) failed\n");
|
2013-10-29 16:19:24 +08:00
|
|
|
return err;
|
2012-11-22 05:13:47 +08:00
|
|
|
}
|
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;
|
|
|
|
|
|
|
|
if (pdata->is_open_drain) {
|
|
|
|
gpio_direction_output(pdata->pin, 1);
|
|
|
|
master->write_bit = w1_gpio_write_bit_val;
|
|
|
|
} else {
|
|
|
|
gpio_direction_input(pdata->pin);
|
|
|
|
master->write_bit = w1_gpio_write_bit_dir;
|
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) {
|
|
|
|
dev_err(&pdev->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);
|
|
|
|
|
2012-07-26 04:54:29 +08:00
|
|
|
if (gpio_is_valid(pdata->ext_pullup_enable_pin))
|
|
|
|
gpio_set_value(pdata->ext_pullup_enable_pin, 1);
|
|
|
|
|
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);
|
|
|
|
|
2012-07-26 04:54:29 +08:00
|
|
|
if (gpio_is_valid(pdata->ext_pullup_enable_pin))
|
|
|
|
gpio_set_value(pdata->ext_pullup_enable_pin, 0);
|
|
|
|
|
2008-02-06 17:39:01 +08:00
|
|
|
w1_remove_master_device(master);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-06-18 07:28:15 +08:00
|
|
|
#ifdef CONFIG_PM
|
|
|
|
|
|
|
|
static int w1_gpio_suspend(struct platform_device *pdev, pm_message_t state)
|
|
|
|
{
|
2013-11-15 06:32:04 +08:00
|
|
|
struct w1_gpio_platform_data *pdata = dev_get_platdata(&pdev->dev);
|
2009-06-18 07:28:15 +08:00
|
|
|
|
|
|
|
if (pdata->enable_external_pullup)
|
|
|
|
pdata->enable_external_pullup(0);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int w1_gpio_resume(struct platform_device *pdev)
|
|
|
|
{
|
2013-11-15 06:32:04 +08:00
|
|
|
struct w1_gpio_platform_data *pdata = dev_get_platdata(&pdev->dev);
|
2009-06-18 07:28:15 +08:00
|
|
|
|
|
|
|
if (pdata->enable_external_pullup)
|
|
|
|
pdata->enable_external_pullup(1);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
#define w1_gpio_suspend NULL
|
|
|
|
#define w1_gpio_resume NULL
|
|
|
|
#endif
|
|
|
|
|
2008-02-06 17:39:01 +08:00
|
|
|
static struct platform_driver w1_gpio_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "w1-gpio",
|
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,
|
2013-03-08 18:07:59 +08:00
|
|
|
.remove = w1_gpio_remove,
|
2009-06-18 07:28:15 +08:00
|
|
|
.suspend = w1_gpio_suspend,
|
|
|
|
.resume = w1_gpio_resume,
|
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");
|