Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for configuring pin for w1-gpio kernel module #457

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 27 additions & 6 deletions drivers/w1/masters/w1-gpio.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* w1-gpio - GPIO w1 bus master driver
*
* Copyright (C) 2007 Ville Syrjala <[email protected]>
* Copyright (C) 2007 Ville Syrjala <[email protected]>, 2013 Dubravko Penezic <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
Expand All @@ -26,6 +26,12 @@
static int w1_gpio_pullup = 0;
module_param_named(pullup, w1_gpio_pullup, int, 0);

static int gpiopin = -1;
module_param(gpiopin, int, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
MODULE_PARM_DESC(gpiopin, "GPIO pin number");

static int w1_gpio_orig;

static void w1_gpio_write_bit_dir(void *data, u8 bit)
{
struct w1_gpio_platform_data *pdata = data;
Expand Down Expand Up @@ -119,6 +125,12 @@ static int w1_gpio_probe(struct platform_device *pdev)
return -ENOMEM;
}

if (gpiopin >= 0) {
printk(KERN_INFO "1-Wire GPIO pin is %d change to %d\n", pdata->pin,gpiopin);
w1_gpio_orig = pdata->pin;
pdata->pin = gpiopin;
}

err = gpio_request(pdata->pin, "w1");
if (err) {
dev_err(&pdev->dev, "gpio_request (pin) failed\n");
Expand Down Expand Up @@ -146,12 +158,14 @@ static int w1_gpio_probe(struct platform_device *pdev)
master->write_bit = w1_gpio_write_bit_dir;
}

if (w1_gpio_pullup)
if (pdata->is_open_drain)
if (w1_gpio_pullup) {
if (pdata->is_open_drain) {
printk(KERN_ERR "w1-gpio 'pullup' option "
"doesn't work with open drain GPIO\n");
else
"doesn't work with open drain GPIO\n");
} else {
master->bitbang_pullup = w1_gpio_bitbang_pullup;
}
}

err = w1_add_master_device(master);
if (err) {
Expand Down Expand Up @@ -192,6 +206,13 @@ static int w1_gpio_remove(struct platform_device *pdev)
gpio_set_value(pdata->ext_pullup_enable_pin, 0);

w1_remove_master_device(master);

if (gpiopin >= 0) {
printk(KERN_INFO "1-Wire GPIO pin is restored to %d\n", w1_gpio_orig);
pdata->pin = w1_gpio_orig;
}


gpio_free(pdata->pin);
kfree(master);

Expand Down Expand Up @@ -240,5 +261,5 @@ static struct platform_driver w1_gpio_driver = {
module_platform_driver(w1_gpio_driver);

MODULE_DESCRIPTION("GPIO w1 bus master driver");
MODULE_AUTHOR("Ville Syrjala <[email protected]>");
MODULE_AUTHOR("Ville Syrjala <[email protected]>, Dubravko Penezic <[email protected]>");
MODULE_LICENSE("GPL");