mirror of
https://github.com/raspberrypi/linux.git
synced 2025-12-06 01:49:46 +00:00
enabling the realtime clock 1-wire chip DS1307 and 1-wire on GPIO4 (as a module)
1-wire: Add support for configuring pin for w1-gpio kernel module See: https://github.com/raspberrypi/linux/pull/457 Add bitbanging pullups, use them for w1-gpio Allows parasite power to work, uses module option pullup=1 bcm2708: Ensure 1-wire pullup is disabled by default, and expose as module parameter Signed-off-by: Alex J Lennon <ajlennon@dynamicdevices.co.uk> w1-gpio: Add gpiopin module parameter and correctly free up gpio pull-up pin, if set Signed-off-by: Alex J Lennon <ajlennon@dynamicdevices.co.uk>
This commit is contained in:
@@ -36,6 +36,7 @@
|
||||
#include <linux/of_platform.h>
|
||||
#include <linux/spi/spi.h>
|
||||
#include <linux/gpio/machine.h>
|
||||
#include <linux/w1-gpio.h>
|
||||
|
||||
#include <linux/version.h>
|
||||
#include <linux/clkdev.h>
|
||||
@@ -79,12 +80,19 @@
|
||||
*/
|
||||
#define DMA_MASK_BITS_COMMON 32
|
||||
|
||||
// use GPIO 4 for the one-wire GPIO pin, if enabled
|
||||
#define W1_GPIO 4
|
||||
// ensure one-wire GPIO pullup is disabled by default
|
||||
#define W1_PULLUP -1
|
||||
|
||||
/* command line parameters */
|
||||
static unsigned boardrev, serial;
|
||||
static unsigned uart_clock = UART0_CLOCK;
|
||||
static unsigned disk_led_gpio = 16;
|
||||
static unsigned disk_led_active_low = 1;
|
||||
static unsigned reboot_part = 0;
|
||||
static unsigned w1_gpio_pin = W1_GPIO;
|
||||
static unsigned w1_gpio_pullup = W1_PULLUP;
|
||||
|
||||
static unsigned use_dt = 0;
|
||||
|
||||
@@ -256,6 +264,20 @@ static struct platform_device bcm2708_dmaengine_device = {
|
||||
.id = -1,
|
||||
};
|
||||
|
||||
#if defined(CONFIG_W1_MASTER_GPIO) || defined(CONFIG_W1_MASTER_GPIO_MODULE)
|
||||
static struct w1_gpio_platform_data w1_gpio_pdata = {
|
||||
.pin = W1_GPIO,
|
||||
.ext_pullup_enable_pin = W1_PULLUP,
|
||||
.is_open_drain = 0,
|
||||
};
|
||||
|
||||
static struct platform_device w1_device = {
|
||||
.name = "w1-gpio",
|
||||
.id = -1,
|
||||
.dev.platform_data = &w1_gpio_pdata,
|
||||
};
|
||||
#endif
|
||||
|
||||
static u64 fb_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
|
||||
|
||||
static struct platform_device bcm2708_fb_device = {
|
||||
@@ -714,6 +736,11 @@ void __init bcm2708_init(void)
|
||||
bcm_register_device(&bcm2708_vcio_device);
|
||||
#ifdef CONFIG_BCM2708_GPIO
|
||||
bcm_register_device(&bcm2708_gpio_device);
|
||||
#endif
|
||||
#if defined(CONFIG_W1_MASTER_GPIO) || defined(CONFIG_W1_MASTER_GPIO_MODULE)
|
||||
w1_gpio_pdata.pin = w1_gpio_pin;
|
||||
w1_gpio_pdata.ext_pullup_enable_pin = w1_gpio_pullup;
|
||||
bcm_register_device_dt(&w1_device);
|
||||
#endif
|
||||
bcm_register_device(&bcm2708_systemtimer_device);
|
||||
bcm_register_device(&bcm2708_fb_device);
|
||||
@@ -925,3 +952,5 @@ module_param(uart_clock, uint, 0644);
|
||||
module_param(disk_led_gpio, uint, 0644);
|
||||
module_param(disk_led_active_low, uint, 0644);
|
||||
module_param(reboot_part, uint, 0644);
|
||||
module_param(w1_gpio_pin, uint, 0644);
|
||||
module_param(w1_gpio_pullup, uint, 0644);
|
||||
|
||||
@@ -23,6 +23,15 @@
|
||||
#include "../w1.h"
|
||||
#include "../w1_int.h"
|
||||
|
||||
static int w1_gpio_pullup = -1;
|
||||
static int w1_gpio_pullup_orig = -1;
|
||||
module_param_named(pullup, w1_gpio_pullup, int, 0);
|
||||
MODULE_PARM_DESC(pullup, "GPIO pin pullup number");
|
||||
static int w1_gpio_pin = -1;
|
||||
static int w1_gpio_pin_orig = -1;
|
||||
module_param_named(gpiopin, w1_gpio_pin, int, 0);
|
||||
MODULE_PARM_DESC(gpiopin, "GPIO pin number");
|
||||
|
||||
static u8 w1_gpio_set_pullup(void *data, int delay)
|
||||
{
|
||||
struct w1_gpio_platform_data *pdata = data;
|
||||
@@ -67,6 +76,16 @@ static u8 w1_gpio_read_bit(void *data)
|
||||
return gpio_get_value(pdata->pin) ? 1 : 0;
|
||||
}
|
||||
|
||||
static void w1_gpio_bitbang_pullup(void *data, u8 on)
|
||||
{
|
||||
struct w1_gpio_platform_data *pdata = data;
|
||||
|
||||
if (on)
|
||||
gpio_direction_output(pdata->pin, 1);
|
||||
else
|
||||
gpio_direction_input(pdata->pin);
|
||||
}
|
||||
|
||||
#if defined(CONFIG_OF)
|
||||
static struct of_device_id w1_gpio_dt_ids[] = {
|
||||
{ .compatible = "w1-gpio" },
|
||||
@@ -113,13 +132,15 @@ static int w1_gpio_probe_dt(struct platform_device *pdev)
|
||||
static int w1_gpio_probe(struct platform_device *pdev)
|
||||
{
|
||||
struct w1_bus_master *master;
|
||||
struct w1_gpio_platform_data *pdata;
|
||||
struct w1_gpio_platform_data *pdata = pdev->dev.platform_data;
|
||||
int err;
|
||||
|
||||
if (of_have_populated_dt()) {
|
||||
err = w1_gpio_probe_dt(pdev);
|
||||
if (err < 0)
|
||||
return err;
|
||||
if(pdata == NULL) {
|
||||
if (of_have_populated_dt()) {
|
||||
err = w1_gpio_probe_dt(pdev);
|
||||
if (err < 0)
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
pdata = dev_get_platdata(&pdev->dev);
|
||||
@@ -136,6 +157,19 @@ static int w1_gpio_probe(struct platform_device *pdev)
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
w1_gpio_pin_orig = pdata->pin;
|
||||
w1_gpio_pullup_orig = pdata->ext_pullup_enable_pin;
|
||||
|
||||
if(gpio_is_valid(w1_gpio_pin)) {
|
||||
pdata->pin = w1_gpio_pin;
|
||||
pdata->ext_pullup_enable_pin = -1;
|
||||
}
|
||||
if(gpio_is_valid(w1_gpio_pullup)) {
|
||||
pdata->ext_pullup_enable_pin = w1_gpio_pullup;
|
||||
}
|
||||
|
||||
dev_info(&pdev->dev, "gpio pin %d, gpio pullup pin %d\n", pdata->pin, pdata->ext_pullup_enable_pin);
|
||||
|
||||
err = devm_gpio_request(&pdev->dev, pdata->pin, "w1");
|
||||
if (err) {
|
||||
dev_err(&pdev->dev, "gpio_request (pin) failed\n");
|
||||
@@ -165,6 +199,14 @@ static int w1_gpio_probe(struct platform_device *pdev)
|
||||
master->set_pullup = w1_gpio_set_pullup;
|
||||
}
|
||||
|
||||
if (gpio_is_valid(w1_gpio_pullup)) {
|
||||
if (pdata->is_open_drain)
|
||||
printk(KERN_ERR "w1-gpio 'pullup' option "
|
||||
"doesn't work with open drain GPIO\n");
|
||||
else
|
||||
master->bitbang_pullup = w1_gpio_bitbang_pullup;
|
||||
}
|
||||
|
||||
err = w1_add_master_device(master);
|
||||
if (err) {
|
||||
dev_err(&pdev->dev, "w1_add_master device failed\n");
|
||||
@@ -195,6 +237,9 @@ static int w1_gpio_remove(struct platform_device *pdev)
|
||||
|
||||
w1_remove_master_device(master);
|
||||
|
||||
pdata->pin = w1_gpio_pin_orig;
|
||||
pdata->ext_pullup_enable_pin = w1_gpio_pullup_orig;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -171,6 +171,12 @@ struct w1_bus_master
|
||||
|
||||
u8 (*set_pullup)(void *, int);
|
||||
|
||||
/**
|
||||
* Turns the pullup on/off in bitbanging mode, takes an on/off argument.
|
||||
* @return -1=Error, 0=completed
|
||||
*/
|
||||
void (*bitbang_pullup) (void *, u8);
|
||||
|
||||
void (*search)(void *, struct w1_master *,
|
||||
u8, w1_slave_found_callback);
|
||||
};
|
||||
|
||||
@@ -123,6 +123,20 @@ int w1_add_master_device(struct w1_bus_master *master)
|
||||
return(-EINVAL);
|
||||
}
|
||||
|
||||
/* bitbanging hardware uses bitbang_pullup, other hardware uses set_pullup
|
||||
* and takes care of timing itself */
|
||||
if (!master->write_byte && !master->touch_bit && master->set_pullup) {
|
||||
printk(KERN_ERR "w1_add_master_device: set_pullup requires "
|
||||
"write_byte or touch_bit, disabling\n");
|
||||
master->set_pullup = NULL;
|
||||
}
|
||||
|
||||
if (master->set_pullup && master->bitbang_pullup) {
|
||||
printk(KERN_ERR "w1_add_master_device: set_pullup should not "
|
||||
"be set when bitbang_pullup is used, disabling\n");
|
||||
master->set_pullup = NULL;
|
||||
}
|
||||
|
||||
/* Lock until the device is added (or not) to w1_masters. */
|
||||
mutex_lock(&w1_mlock);
|
||||
/* Search for the first available id (starting at 1). */
|
||||
|
||||
@@ -134,10 +134,22 @@ static void w1_pre_write(struct w1_master *dev)
|
||||
static void w1_post_write(struct w1_master *dev)
|
||||
{
|
||||
if (dev->pullup_duration) {
|
||||
if (dev->enable_pullup && dev->bus_master->set_pullup)
|
||||
dev->bus_master->set_pullup(dev->bus_master->data, 0);
|
||||
else
|
||||
if (dev->enable_pullup) {
|
||||
if (dev->bus_master->set_pullup) {
|
||||
dev->bus_master->set_pullup(dev->
|
||||
bus_master->data,
|
||||
0);
|
||||
} else if (dev->bus_master->bitbang_pullup) {
|
||||
dev->bus_master->
|
||||
bitbang_pullup(dev->bus_master->data, 1);
|
||||
msleep(dev->pullup_duration);
|
||||
dev->bus_master->
|
||||
bitbang_pullup(dev->bus_master->data, 0);
|
||||
}
|
||||
} else {
|
||||
msleep(dev->pullup_duration);
|
||||
}
|
||||
|
||||
dev->pullup_duration = 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user