net: rfkill: add generic gpio rfkill driver
PATCH v2 1/1 net: rfkill: add generic gpio rfkill driver
This adds a new generic gpio rfkill driver to support rfkill switches which are controlled by gpios. The driver also supports passing in data about the clock for the radio, so that when rfkill is blocking, it can disable the clock.
This driver assumes platform data is passed from the board files to configure it for specific devices.
Change-Id: I10bdce04c9d6e0489ad208ebbc6e78ab4424f4a8
From: Anantha Idapalapati <[email protected]>
---
v2:
- Moved to dynamic allocation for gpio names
- added state of clock enabled to prevent double disabling/enabling
- fixed Kconfig description
- removed setting initial state, as rfkill-core will do it
- enabled using this driver as a module
include/linux/rfkill-gpio.h | 43 ++++++++ net/rfkill/Kconfig | 8 ++ net/rfkill/Makefile | 1 + net/rfkill/rfkill-gpio.c | 227 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 279 insertions(+), 0 deletions(-) create mode 100644 include/linux/rfkill-gpio.h create mode 100644 net/rfkill/rfkill-gpio.c
include/linux/rfkill-gpio.h new file +43 -0
@@ -0,0 +1,43 @@ +/* +* Copyright (c) 2011, NVIDIA Corporation. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +* +* You should have received a copy of the GNU General Public License along +* with this program; if not, write to the Free Software Foundation, Inc., +* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + + +#ifndef __RFKILL_GPIO_H +#define __RFKILL_GPIO_H + +#include <linux/types.h> +#include <linux/rfkill.h> + +/** +* struct rfkill_gpio_platform_data - platform data for rfkill gpio device. +* for unused gpio's, the expected value is -1. +* @name: name for the gpio rf kill instance +* @reset_gpio: GPIO which is used for reseting rfkill switch +* @shutdown_gpio: GPIO which is used for shutdown of rfkill switch +* @power_clk_name: [optional] name of clk to turn off while blocked +*/ + +struct rfkill_gpio_platform_data { +char *name; +int reset_gpio; +int shutdown_gpio; +const char *power_clk_name; +enum rfkill_type type; +}; + +#endif /* __RFKILL_GPIO_H */
net/rfkill/Kconfig +8 -0
@@ -33,3 +33,11 @@ config RFKILL_REGULATOR To compile this driver as a module, choose M here: the module will be called rfkill-regulator. + +config RFKILL_GPIO + tristate "GPIO RFKILL driver" + depends on RFKILL && GPIOLIB + help + If you say yes here you get support of a generic gpio RFKILL + driver. The platform should fill in the appropriate fields in the + rfkill_gpio_platform_data structure and pass that to the driver.
net/rfkill/Makefile +1 -0
@@ -6,3 +6,4 @@ rfkill-y += core.o rfkill-$(CONFIG_RFKILL_INPUT) += input.o obj-$(CONFIG_RFKILL) += rfkill.o obj-$(CONFIG_RFKILL_REGULATOR) += rfkill-regulator.o +obj-$(CONFIG_RFKILL_GPIO) += rfkill-gpio.o
net/rfkill/rfkill-gpio.c new file +227 -0
227 lines not on this page · raw message
Signature · 1 line
1.7.5.1
Johannes Berg
maintainernet/rfkill/rfkill-gpio.c line 33
Quoted 4 lines · Rhyland Klein
net/rfkill/rfkill-gpio.c new file +4
-0+enum rfkill_gpio_clk_state { +UNSPECIFIED =0 , +PWR_ENABLED , +PWR_DISABLED
Are you sure starting out with UNSPECIFIED works? Then you'll always change, but if the clock was enabled already you still enable it on the first set_block() from rfkill, which still has the refcount problem, no? It seems to me that the original state has to be passed in from the platform?
johannes
Quoted 13 lines · Johannes Berg
net/rfkill/rfkill-gpio.c line 33
Quoted 4 lines · Rhyland Klein
net/rfkill/rfkill-gpio.c new file +4
-0+enum rfkill_gpio_clk_state { +UNSPECIFIED =0 , +PWR_ENABLED , +PWR_DISABLED Are you sure starting out with UNSPECIFIED works? Then you'll always change, but if the clock was enabled already you still enable it on the first
set_block()from rfkill, which still has the refcount problem, no? It seems to me that the original state has to be passed in from the platform?
Quoted 2 lines
johannes
I thought about that. But I decided the clock that it is possible to have the clock used for the radio used for something else right? in which case, the driver will leave the clk in whatever state it initially finds it. I.e. if the clock is disabled, then it will enable it only once and work, if it is enabled, it will add a refcount (only once) and then work and disable it again only once. It never changes the refcount in either direction by more than 1, and this way the initial setting of the clock is irrelevant. The board files can simply initialize the block as off if that is the initial clk state they want.
rhyland
Johannes Berg
maintainerQuoted 8 lines · Rhyland Klein
Quoted 5 lines
Are you sure starting out with UNSPECIFIED works? Then you'll always change, but if the clock was enabled already you still enable it on the first
set_block()from rfkill, which still has the refcount problem, no? It seems to me that the original state has to be passed in from the platform?I thought about that. But I decided the clock that it is possible to have the clock used for the radio used for something else right?
Sure.
Quoted 8 lines
in
which case, the driver will leave the clk in whatever state it initially finds it. I.e. if the clock is disabled, then it will enable it only once and work, if it is enabled, it will add a refcount (only once) and then work and disable it again only once. It never changes the refcount in either direction by more than 1, and this way the initial setting of the clock is irrelevant. The board files can simply initialize the block as off if that is the initial clk state they want.
The issue is that depending on how you boot, the first refcount change might be +1 or it might be -1.
If rfkill decides that at the time of loading wifi should be off, then the first change would be -1, and after that it would flip between 0 and -1.
If, on the other hand, rfkill decides that at the time of loading the driver wifi should be on, then the first change would be +1 and it'll flip between 0 and +1.
This seems like it'll cause issues at some point, so I think you should either allow the driver to set the initial state or hardcode one of these possibilities (so at least it's predictable)
johannes
Quoted 33 lines · Johannes Berg
Quoted 8 lines · Rhyland Klein
Quoted 5 lines
Are you sure starting out with UNSPECIFIED works? Then you'll always change, but if the clock was enabled already you still enable it on the first
set_block()from rfkill, which still has the refcount problem, no? It seems to me that the original state has to be passed in from the platform?I thought about that. But I decided the clock that it is possible to have the clock used for the radio used for something else right?
Sure.
Quoted 8 lines
in
which case, the driver will leave the clk in whatever state it initially finds it. I.e. if the clock is disabled, then it will enable it only once and work, if it is enabled, it will add a refcount (only once) and then work and disable it again only once. It never changes the refcount in either direction by more than 1, and this way the initial setting of the clock is irrelevant. The board files can simply initialize the block as off if that is the initial clk state they want.The issue is that depending on how you boot, the first refcount change might be +1 or it might be -1.
If rfkill decides that at the time of loading wifi should be off, then the first change would be -1, and after that it would flip between 0 and -1.
If, on the other hand, rfkill decides that at the time of loading the driver wifi should be on, then the first change would be +1 and it'll flip between 0 and +1.
Quoted 6 lines
This seems like it'll cause issues at some point, so I think you should either allow the driver to set the initial state or hardcode one of these possibilities (so at least it's predictable)
johannes
I won't go negative, if you look, it only will disable clock if it knows it has already enabled it.
rhyland
Johannes Berg
maintainerQuoted 10 lines · Rhyland Klein
Quoted 7 lines
If, on the other hand, rfkill decides that at the time of loading the driver wifi should be on, then the first change would be +1 and it'll flip between 0 and +1.
This seems like it'll cause issues at some point, so I think you should either allow the driver to set the initial state or hardcode one of these possibilities (so at least it's predictable)
I won't go negative, if you look, it only will disable clock if it knows it has already enabled it.
Ah, you're right, I misread the macros.
johannes
Quoted 10 lines · Johannes Berg
Quoted 7 lines · Rhyland Klein
Quoted 7 lines
If, on the other hand, rfkill decides that at the time of loading the driver wifi should be on, then the first change would be +1 and it'll flip between 0 and +1.
This seems like it'll cause issues at some point, so I think you should either allow the driver to set the initial state or hardcode one of these possibilities (so at least it's predictable)
Quoted 7 lines
Quoted 2 lines
I won't go negative, if you look, it only will disable clock if it knows it has already enabled it.
Ah, you're right, I misread the macros.
johannes
So the patch is good as is?
rhyland
Johannes Berg
maintainerQuoted 11 lines · Rhyland Klein
Quoted 10 lines · Johannes Berg
Quoted 7 lines · Rhyland Klein
Quoted 7 lines
If, on the other hand, rfkill decides that at the time of loading the driver wifi should be on, then the first change would be +1 and it'll flip between 0 and +1.
This seems like it'll cause issues at some point, so I think you should either allow the driver to set the initial state or hardcode one of these possibilities (so at least it's predictable)
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
I won't go negative, if you look, it only will disable clock if it knows it has already enabled it.
Ah, you're right, I misread the macros.
So the patch is good as is?
I think so, yes.
johannes
Quoted 15 lines · Johannes Berg
Quoted 14 lines · Rhyland Klein
Quoted 13 lines · Johannes Berg
Quoted 10 lines · Rhyland Klein
Quoted 7 lines
If, on the other hand, rfkill decides that at the time of loading the driver wifi should be on, then the first change would be +1 and it'll flip between 0 and +1.
This seems like it'll cause issues at some point, so I think you should either allow the driver to set the initial state or hardcode one of these possibilities (so at least it's predictable)
I won't go negative, if you look, it only will disable clock if it knows it has already enabled it.
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
Ah, you're right, I misread the macros.
So the patch is good as is?
I think so, yes.
johannes
John, Johannes suggested you are able to pull in this patch?
rhyland
Quoted 18 lines · Rhyland Klein
Quoted 17 lines · Johannes Berg
Quoted 15 lines · Rhyland Klein
Quoted 14 lines · Johannes Berg
Quoted 10 lines · Rhyland Klein
Quoted 7 lines
If, on the other hand, rfkill decides that at the time of loading the driver wifi should be on, then the first change would be +1 and it'll flip between 0 and +1.
This seems like it'll cause issues at some point, so I think you should either allow the driver to set the initial state or hardcode one of these possibilities (so at least it's predictable)
I won't go negative, if you look, it only will disable clock if it knows it has already enabled it.
Ah, you're right, I misread the macros.
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
So the patch is good as is?
I think so, yes.
johannes
John, Johannes suggested you are able to pull in this patch?
I've got it, thanks.
Signature · 2 lines
John W. Linville Someday the world will need a hero, and you [email protected] might be all we have. Be ready.
Quoted 21 lines · John W. Linville
Quoted 20 lines · Rhyland Klein
Quoted 19 lines · Johannes Berg
Quoted 17 lines · Rhyland Klein
Quoted 6 lines · Johannes Berg
Quoted 4 lines · Rhyland Klein
Quoted 4 lines
If, on the other hand, rfkill decides that at the time of loading the driver wifi should be on, then the first change would be +1 and it'll flip between 0 and +1.
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
This seems like it'll cause issues at some point, so I think you should either allow the driver to set the initial state or hardcode one of these possibilities (so at least it's predictable)
I won't go negative, if you look, it only will disable clock if it knows it has already enabled it.
Ah, you're right, I misread the macros.
So the patch is good as is?
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
I think so, yes.
johannes
John, Johannes suggested you are able to pull in this patch?
I've got it, thanks.
Building modules, stage 2.
MODPOST 2346 modules
ERROR: "clk_get" [net/rfkill/rfkill-gpio.ko] undefined!
ERROR: "clk_enable" [net/rfkill/rfkill-gpio.ko] undefined!
ERROR: "clk_put" [net/rfkill/rfkill-gpio.ko] undefined!
ERROR: "clk_disable" [net/rfkill/rfkill-gpio.ko] undefined!
WARNING: modpost: Found 5 section mismatch(es).
To see full details build your kernel with:
'make CONFIG_DEBUG_SECTION_MISMATCH=y'
make[1]: *** [__modpost] Error 1
make: *** [modules] Error 2
Is there something we should add to Kconfig to prevent this?
John
Signature · 2 lines
John W. Linville Someday the world will need a hero, and you [email protected] might be all we have. Be ready.
wireless-next-2.6 rebased -- Re: [PATCH v2] net: rfkill: add generic gpio rfkill driver
FYI, I'm rebasing wireless-next to avoid pushing this bad commit to net-next-2.6. If you pulled wireless-next-2.6.git over the weekend, you may experience some rebase-related problems.
John
Quoted 55 lines · John W. Linville
Quoted 21 lines · John W. Linville
Quoted 20 lines · Rhyland Klein
Quoted 19 lines · Johannes Berg
Quoted 17 lines · Rhyland Klein
Quoted 6 lines · Johannes Berg
Quoted 4 lines · Rhyland Klein
Quoted 4 lines
If, on the other hand, rfkill decides that at the time of loading the driver wifi should be on, then the first change would be +1 and it'll flip between 0 and +1.
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
This seems like it'll cause issues at some point, so I think you should either allow the driver to set the initial state or hardcode one of these possibilities (so at least it's predictable)
I won't go negative, if you look, it only will disable clock if it knows it has already enabled it.
Ah, you're right, I misread the macros.
So the patch is good as is?
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
I think so, yes.
johannes
John, Johannes suggested you are able to pull in this patch?
I've got it, thanks.
Building modules, stage 2.
MODPOST 2346 modules
ERROR: "clk_get" [net/rfkill/rfkill-gpio.ko] undefined!
ERROR: "clk_enable" [net/rfkill/rfkill-gpio.ko] undefined!
ERROR: "clk_put" [net/rfkill/rfkill-gpio.ko] undefined!
ERROR: "clk_disable" [net/rfkill/rfkill-gpio.ko] undefined!
WARNING: modpost: Found 5 section mismatch(es).
To see full details build your kernel with:
'makeCONFIG_DEBUG_SECTION_MISMATCH=y'
make[1]: *** [__modpost] Error 1
make: *** [modules] Error 2Is there something we should add to
Kconfigto prevent this?John
Signature · 7 lines
John W. Linville Someday the world will need a hero, and you [email protected] might be all we have. Be ready. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Signature · 2 lines
John W. Linville Someday the world will need a hero, and you [email protected] might be all we have. Be ready.