2008-02-06 02:39:01 -07: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 02:04:11 -06:00
|
|
|
#include <linux/slab.h>
|
2008-02-06 02:39:01 -07:00
|
|
|
#include <linux/w1-gpio.h>
|
2012-02-04 09:33:55 -07:00
|
|
|
#include <linux/gpio.h>
|
2012-07-23 08:36:35 -06:00
|
|
|
#include <linux/of_platform.h>
|
|
|
|
#include <linux/of_gpio.h>
|
2012-11-21 14:13:29 -07:00
|
|
|
#include <linux/pinctrl/consumer.h>
|
|
|
|
#include <linux/err.h>
|
2012-11-21 14:13:47 -07:00
|
|
|
#include <linux/of.h>
|
2008-02-06 02:39:01 -07:00
|
|
|
|
|
|
|
#include "../w1.h"
|
|
|
|
#include "../w1_int.h"
|
|
|
|
|
|
|
|
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-12 15:31:25 -06:00
|
|
|
return gpio_get_value(pdata->pin) ? 1 : 0;
|
2008-02-06 02:39:01 -07:00
|
|
|
}
|
|
|
|
|
2013-03-08 03:08:00 -07:00
|
|
|
#if defined(CONFIG_OF)
|
2012-07-23 08:36:35 -06:00
|
|
|
static struct of_device_id w1_gpio_dt_ids[] = {
|
|
|
|
{ .compatible = "w1-gpio" },
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, w1_gpio_dt_ids);
|
2013-03-08 03:08:00 -07:00
|
|
|
#endif
|
2012-07-23 08:36:35 -06:00
|
|
|
|
|
|
|
static int w1_gpio_probe_dt(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
struct w1_gpio_platform_data *pdata = pdev->dev.platform_data;
|
|
|
|
struct device_node *np = pdev->dev.of_node;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
pdata->pin = of_get_gpio(np, 0);
|
|
|
|
pdata->ext_pullup_enable_pin = of_get_gpio(np, 1);
|
|
|
|
pdev->dev.platform_data = pdata;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-01-27 13:07:57 -07:00
|
|
|
static int w1_gpio_probe(struct platform_device *pdev)
|
2008-02-06 02:39:01 -07:00
|
|
|
{
|
|
|
|
struct w1_bus_master *master;
|
2012-07-23 08:36:35 -06:00
|
|
|
struct w1_gpio_platform_data *pdata;
|
2012-11-21 14:13:29 -07:00
|
|
|
struct pinctrl *pinctrl;
|
2008-02-06 02:39:01 -07:00
|
|
|
int err;
|
|
|
|
|
2012-11-21 14:13:29 -07:00
|
|
|
pinctrl = devm_pinctrl_get_select_default(&pdev->dev);
|
|
|
|
if (IS_ERR(pinctrl))
|
|
|
|
dev_warn(&pdev->dev, "unable to select pin group\n");
|
|
|
|
|
2012-11-21 14:13:47 -07:00
|
|
|
if (of_have_populated_dt()) {
|
|
|
|
err = w1_gpio_probe_dt(pdev);
|
|
|
|
if (err < 0) {
|
|
|
|
dev_err(&pdev->dev, "Failed to parse DT\n");
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
}
|
2012-07-23 08:36:35 -06:00
|
|
|
|
|
|
|
pdata = pdev->dev.platform_data;
|
|
|
|
|
2012-11-21 14:13:47 -07:00
|
|
|
if (!pdata) {
|
|
|
|
dev_err(&pdev->dev, "No configuration data\n");
|
2008-02-06 02:39:01 -07:00
|
|
|
return -ENXIO;
|
2012-11-21 14:13:47 -07:00
|
|
|
}
|
2008-02-06 02:39:01 -07:00
|
|
|
|
|
|
|
master = kzalloc(sizeof(struct w1_bus_master), GFP_KERNEL);
|
2012-11-21 14:13:47 -07:00
|
|
|
if (!master) {
|
|
|
|
dev_err(&pdev->dev, "Out of memory\n");
|
2008-02-06 02:39:01 -07:00
|
|
|
return -ENOMEM;
|
2012-11-21 14:13:47 -07:00
|
|
|
}
|
2008-02-06 02:39:01 -07:00
|
|
|
|
|
|
|
err = gpio_request(pdata->pin, "w1");
|
2012-11-21 14:13:47 -07:00
|
|
|
if (err) {
|
|
|
|
dev_err(&pdev->dev, "gpio_request (pin) failed\n");
|
2008-02-06 02:39:01 -07:00
|
|
|
goto free_master;
|
2012-11-21 14:13:47 -07:00
|
|
|
}
|
2008-02-06 02:39:01 -07:00
|
|
|
|
2012-07-25 14:54:29 -06:00
|
|
|
if (gpio_is_valid(pdata->ext_pullup_enable_pin)) {
|
|
|
|
err = gpio_request_one(pdata->ext_pullup_enable_pin,
|
|
|
|
GPIOF_INIT_LOW, "w1 pullup");
|
2012-11-21 14:13:47 -07:00
|
|
|
if (err < 0) {
|
|
|
|
dev_err(&pdev->dev, "gpio_request_one "
|
|
|
|
"(ext_pullup_enable_pin) failed\n");
|
2012-07-25 14:54:29 -06:00
|
|
|
goto free_gpio;
|
2012-11-21 14:13:47 -07:00
|
|
|
}
|
2012-07-25 14:54:29 -06:00
|
|
|
}
|
|
|
|
|
2008-02-06 02:39:01 -07: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;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = w1_add_master_device(master);
|
2012-11-21 14:13:47 -07:00
|
|
|
if (err) {
|
|
|
|
dev_err(&pdev->dev, "w1_add_master device failed\n");
|
2012-07-25 14:54:29 -06:00
|
|
|
goto free_gpio_ext_pu;
|
2012-11-21 14:13:47 -07:00
|
|
|
}
|
2008-02-06 02:39:01 -07:00
|
|
|
|
2009-06-17 17:28:15 -06:00
|
|
|
if (pdata->enable_external_pullup)
|
|
|
|
pdata->enable_external_pullup(1);
|
|
|
|
|
2012-07-25 14:54:29 -06:00
|
|
|
if (gpio_is_valid(pdata->ext_pullup_enable_pin))
|
|
|
|
gpio_set_value(pdata->ext_pullup_enable_pin, 1);
|
|
|
|
|
2008-02-06 02:39:01 -07:00
|
|
|
platform_set_drvdata(pdev, master);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
2012-07-25 14:54:29 -06:00
|
|
|
free_gpio_ext_pu:
|
|
|
|
if (gpio_is_valid(pdata->ext_pullup_enable_pin))
|
|
|
|
gpio_free(pdata->ext_pullup_enable_pin);
|
2008-02-06 02:39:01 -07:00
|
|
|
free_gpio:
|
|
|
|
gpio_free(pdata->pin);
|
|
|
|
free_master:
|
|
|
|
kfree(master);
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2013-03-08 03:07:59 -07:00
|
|
|
static int w1_gpio_remove(struct platform_device *pdev)
|
2008-02-06 02:39:01 -07:00
|
|
|
{
|
|
|
|
struct w1_bus_master *master = platform_get_drvdata(pdev);
|
|
|
|
struct w1_gpio_platform_data *pdata = pdev->dev.platform_data;
|
|
|
|
|
2009-06-17 17:28:15 -06:00
|
|
|
if (pdata->enable_external_pullup)
|
|
|
|
pdata->enable_external_pullup(0);
|
|
|
|
|
2012-07-25 14:54:29 -06:00
|
|
|
if (gpio_is_valid(pdata->ext_pullup_enable_pin))
|
|
|
|
gpio_set_value(pdata->ext_pullup_enable_pin, 0);
|
|
|
|
|
2008-02-06 02:39:01 -07:00
|
|
|
w1_remove_master_device(master);
|
|
|
|
gpio_free(pdata->pin);
|
|
|
|
kfree(master);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-06-17 17:28:15 -06:00
|
|
|
#ifdef CONFIG_PM
|
|
|
|
|
|
|
|
static int w1_gpio_suspend(struct platform_device *pdev, pm_message_t state)
|
|
|
|
{
|
|
|
|
struct w1_gpio_platform_data *pdata = pdev->dev.platform_data;
|
|
|
|
|
|
|
|
if (pdata->enable_external_pullup)
|
|
|
|
pdata->enable_external_pullup(0);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int w1_gpio_resume(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
struct w1_gpio_platform_data *pdata = pdev->dev.platform_data;
|
|
|
|
|
|
|
|
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 02:39:01 -07:00
|
|
|
static struct platform_driver w1_gpio_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "w1-gpio",
|
|
|
|
.owner = THIS_MODULE,
|
2012-07-23 08:36:35 -06:00
|
|
|
.of_match_table = of_match_ptr(w1_gpio_dt_ids),
|
2008-02-06 02:39:01 -07:00
|
|
|
},
|
2012-11-21 14:13:47 -07:00
|
|
|
.probe = w1_gpio_probe,
|
2013-03-08 03:07:59 -07:00
|
|
|
.remove = w1_gpio_remove,
|
2009-06-17 17:28:15 -06:00
|
|
|
.suspend = w1_gpio_suspend,
|
|
|
|
.resume = w1_gpio_resume,
|
2008-02-06 02:39:01 -07:00
|
|
|
};
|
|
|
|
|
2012-11-21 14:13:47 -07:00
|
|
|
module_platform_driver(w1_gpio_driver);
|
2008-02-06 02:39:01 -07:00
|
|
|
|
|
|
|
MODULE_DESCRIPTION("GPIO w1 bus master driver");
|
|
|
|
MODULE_AUTHOR("Ville Syrjala <syrjala@sci.fi>");
|
|
|
|
MODULE_LICENSE("GPL");
|