2008-09-01 07:26:48 +04:00
/* leds-sunfire.c: SUNW,Ultra-Enterprise LED driver.
*
* Copyright ( C ) 2008 David S . Miller < davem @ davemloft . net >
*/
2013-02-05 06:01:21 +04:00
# define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
2008-09-01 07:26:48 +04:00
# include <linux/kernel.h>
# include <linux/module.h>
# include <linux/init.h>
# include <linux/leds.h>
# include <linux/io.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 11:04:11 +03:00
# include <linux/slab.h>
2008-09-01 07:26:48 +04:00
# include <asm/fhc.h>
# include <asm/upa.h>
MODULE_AUTHOR ( " David S. Miller (davem@davemloft.net) " ) ;
MODULE_DESCRIPTION ( " Sun Fire LED driver " ) ;
MODULE_LICENSE ( " GPL " ) ;
struct sunfire_led {
struct led_classdev led_cdev ;
void __iomem * reg ;
} ;
# define to_sunfire_led(d) container_of(d, struct sunfire_led, led_cdev)
static void __clockboard_set ( struct led_classdev * led_cdev ,
enum led_brightness led_val , u8 bit )
{
struct sunfire_led * p = to_sunfire_led ( led_cdev ) ;
u8 reg = upa_readb ( p - > reg ) ;
switch ( bit ) {
case CLOCK_CTRL_LLED :
if ( led_val )
reg & = ~ bit ;
else
reg | = bit ;
break ;
default :
if ( led_val )
reg | = bit ;
else
reg & = ~ bit ;
break ;
}
upa_writeb ( reg , p - > reg ) ;
}
static void clockboard_left_set ( struct led_classdev * led_cdev ,
enum led_brightness led_val )
{
__clockboard_set ( led_cdev , led_val , CLOCK_CTRL_LLED ) ;
}
static void clockboard_middle_set ( struct led_classdev * led_cdev ,
enum led_brightness led_val )
{
__clockboard_set ( led_cdev , led_val , CLOCK_CTRL_MLED ) ;
}
static void clockboard_right_set ( struct led_classdev * led_cdev ,
enum led_brightness led_val )
{
__clockboard_set ( led_cdev , led_val , CLOCK_CTRL_RLED ) ;
}
static void __fhc_set ( struct led_classdev * led_cdev ,
enum led_brightness led_val , u32 bit )
{
struct sunfire_led * p = to_sunfire_led ( led_cdev ) ;
u32 reg = upa_readl ( p - > reg ) ;
switch ( bit ) {
case FHC_CONTROL_LLED :
if ( led_val )
reg & = ~ bit ;
else
reg | = bit ;
break ;
default :
if ( led_val )
reg | = bit ;
else
reg & = ~ bit ;
break ;
}
upa_writel ( reg , p - > reg ) ;
}
static void fhc_left_set ( struct led_classdev * led_cdev ,
enum led_brightness led_val )
{
__fhc_set ( led_cdev , led_val , FHC_CONTROL_LLED ) ;
}
static void fhc_middle_set ( struct led_classdev * led_cdev ,
enum led_brightness led_val )
{
__fhc_set ( led_cdev , led_val , FHC_CONTROL_MLED ) ;
}
static void fhc_right_set ( struct led_classdev * led_cdev ,
enum led_brightness led_val )
{
__fhc_set ( led_cdev , led_val , FHC_CONTROL_RLED ) ;
}
typedef void ( * set_handler ) ( struct led_classdev * , enum led_brightness ) ;
struct led_type {
const char * name ;
set_handler handler ;
const char * default_trigger ;
} ;
# define NUM_LEDS_PER_BOARD 3
struct sunfire_drvdata {
struct sunfire_led leds [ NUM_LEDS_PER_BOARD ] ;
} ;
2012-11-19 22:23:02 +04:00
static int sunfire_led_generic_probe ( struct platform_device * pdev ,
2008-09-01 07:26:48 +04:00
struct led_type * types )
{
struct sunfire_drvdata * p ;
2011-07-26 04:13:16 +04:00
int i , err ;
2008-09-01 07:26:48 +04:00
if ( pdev - > num_resources ! = 1 ) {
2013-02-05 06:01:21 +04:00
dev_err ( & pdev - > dev , " Wrong number of resources %d, should be 1 \n " ,
2008-09-01 07:26:48 +04:00
pdev - > num_resources ) ;
2012-07-04 08:04:48 +04:00
return - EINVAL ;
2008-09-01 07:26:48 +04:00
}
2012-07-04 08:04:48 +04:00
p = devm_kzalloc ( & pdev - > dev , sizeof ( * p ) , GFP_KERNEL ) ;
2014-05-08 07:25:52 +04:00
if ( ! p )
2012-07-04 08:04:48 +04:00
return - ENOMEM ;
2008-09-01 07:26:48 +04:00
for ( i = 0 ; i < NUM_LEDS_PER_BOARD ; i + + ) {
struct led_classdev * lp = & p - > leds [ i ] . led_cdev ;
p - > leds [ i ] . reg = ( void __iomem * ) pdev - > resource [ 0 ] . start ;
lp - > name = types [ i ] . name ;
lp - > brightness = LED_FULL ;
lp - > brightness_set = types [ i ] . handler ;
lp - > default_trigger = types [ i ] . default_trigger ;
err = led_classdev_register ( & pdev - > dev , lp ) ;
if ( err ) {
2013-02-05 06:01:21 +04:00
dev_err ( & pdev - > dev , " Could not register %s LED \n " ,
2008-09-01 07:26:48 +04:00
lp - > name ) ;
2012-07-04 08:04:48 +04:00
for ( i - - ; i > = 0 ; i - - )
led_classdev_unregister ( & p - > leds [ i ] . led_cdev ) ;
return err ;
2008-09-01 07:26:48 +04:00
}
}
2013-05-23 14:28:33 +04:00
platform_set_drvdata ( pdev , p ) ;
2008-09-01 07:26:48 +04:00
2011-07-26 04:13:16 +04:00
return 0 ;
2008-09-01 07:26:48 +04:00
}
2012-11-19 22:26:00 +04:00
static int sunfire_led_generic_remove ( struct platform_device * pdev )
2008-09-01 07:26:48 +04:00
{
2013-05-23 14:28:33 +04:00
struct sunfire_drvdata * p = platform_get_drvdata ( pdev ) ;
2008-09-01 07:26:48 +04:00
int i ;
for ( i = 0 ; i < NUM_LEDS_PER_BOARD ; i + + )
led_classdev_unregister ( & p - > leds [ i ] . led_cdev ) ;
return 0 ;
}
static struct led_type clockboard_led_types [ NUM_LEDS_PER_BOARD ] = {
{
. name = " clockboard-left " ,
. handler = clockboard_left_set ,
} ,
{
. name = " clockboard-middle " ,
. handler = clockboard_middle_set ,
} ,
{
. name = " clockboard-right " ,
. handler = clockboard_right_set ,
2013-02-05 06:01:21 +04:00
. default_trigger = " heartbeat " ,
2008-09-01 07:26:48 +04:00
} ,
} ;
2012-11-19 22:23:02 +04:00
static int sunfire_clockboard_led_probe ( struct platform_device * pdev )
2008-09-01 07:26:48 +04:00
{
return sunfire_led_generic_probe ( pdev , clockboard_led_types ) ;
}
static struct led_type fhc_led_types [ NUM_LEDS_PER_BOARD ] = {
{
. name = " fhc-left " ,
. handler = fhc_left_set ,
} ,
{
. name = " fhc-middle " ,
. handler = fhc_middle_set ,
} ,
{
. name = " fhc-right " ,
. handler = fhc_right_set ,
2013-02-05 06:01:21 +04:00
. default_trigger = " heartbeat " ,
2008-09-01 07:26:48 +04:00
} ,
} ;
2012-11-19 22:23:02 +04:00
static int sunfire_fhc_led_probe ( struct platform_device * pdev )
2008-09-01 07:26:48 +04:00
{
return sunfire_led_generic_probe ( pdev , fhc_led_types ) ;
}
MODULE_ALIAS ( " platform:sunfire-clockboard-leds " ) ;
MODULE_ALIAS ( " platform:sunfire-fhc-leds " ) ;
static struct platform_driver sunfire_clockboard_led_driver = {
. probe = sunfire_clockboard_led_probe ,
2012-11-19 22:20:20 +04:00
. remove = sunfire_led_generic_remove ,
2008-09-01 07:26:48 +04:00
. driver = {
. name = " sunfire-clockboard-leds " ,
} ,
} ;
static struct platform_driver sunfire_fhc_led_driver = {
. probe = sunfire_fhc_led_probe ,
2012-11-19 22:20:20 +04:00
. remove = sunfire_led_generic_remove ,
2008-09-01 07:26:48 +04:00
. driver = {
. name = " sunfire-fhc-leds " ,
} ,
} ;
static int __init sunfire_leds_init ( void )
{
int err = platform_driver_register ( & sunfire_clockboard_led_driver ) ;
if ( err ) {
2013-02-05 06:01:21 +04:00
pr_err ( " Could not register clock board LED driver \n " ) ;
2008-09-01 07:26:48 +04:00
return err ;
}
err = platform_driver_register ( & sunfire_fhc_led_driver ) ;
if ( err ) {
2013-02-05 06:01:21 +04:00
pr_err ( " Could not register FHC LED driver \n " ) ;
2008-09-01 07:26:48 +04:00
platform_driver_unregister ( & sunfire_clockboard_led_driver ) ;
}
return err ;
}
static void __exit sunfire_leds_exit ( void )
{
platform_driver_unregister ( & sunfire_clockboard_led_driver ) ;
platform_driver_unregister ( & sunfire_fhc_led_driver ) ;
}
module_init ( sunfire_leds_init ) ;
module_exit ( sunfire_leds_exit ) ;