forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mfd: Add support for UP board CPLD/FPGA
The UP Squared board <http://www.upboard.com> implements certain features (pin control, onboard LEDs or CEC) through an on-board FPGA. This mfd driver implements the line protocol to read and write registers from the FPGA through regmap. The register address map is also included. The UP boards come with a few FPGA-controlled onboard LEDs: * UP Board: yellow, green, red * UP Squared: blue, yellow, green, red The UP Boards provide a few I/O pin headers (for both GPIO and functions), including a 40-pin Raspberry Pi compatible header. This patch implements support for the FPGA-based pin controller that manages direction and enable state for those header pins. Signed-off-by: Javier Arteaga <javier@emutex.com> [merge various fixes] Signed-off-by: Nicola Lunghi <nicola.lunghi@emutex.com>
- Loading branch information
Showing
11 changed files
with
1,380 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* UP Board FPGA-based LED driver | ||
* | ||
* Copyright (c) 2017, Emutex Ltd. All rights reserved. | ||
* | ||
* Author: Javier Arteaga <javier@emutex.com> | ||
* | ||
* 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/kernel.h> | ||
#include <linux/leds.h> | ||
#include <linux/mfd/upboard-fpga.h> | ||
#include <linux/module.h> | ||
#include <linux/platform_device.h> | ||
#include <linux/regmap.h> | ||
|
||
struct upboard_led { | ||
struct regmap_field *field; | ||
struct led_classdev cdev; | ||
}; | ||
|
||
static enum led_brightness upboard_led_brightness_get(struct led_classdev | ||
*cdev) | ||
{ | ||
struct upboard_led *led = container_of(cdev, struct upboard_led, cdev); | ||
int brightness = 0; | ||
|
||
regmap_field_read(led->field, &brightness); | ||
|
||
return brightness; | ||
}; | ||
|
||
static void upboard_led_brightness_set(struct led_classdev *cdev, | ||
enum led_brightness brightness) | ||
{ | ||
struct upboard_led *led = container_of(cdev, struct upboard_led, cdev); | ||
|
||
regmap_field_write(led->field, brightness != LED_OFF); | ||
}; | ||
|
||
static int __init upboard_led_probe(struct platform_device *pdev) | ||
{ | ||
struct upboard_fpga * const fpga = dev_get_drvdata(pdev->dev.parent); | ||
struct reg_field fldconf = { | ||
.reg = UPFPGA_REG_FUNC_EN0, | ||
}; | ||
struct upboard_led_data * const pdata = pdev->dev.platform_data; | ||
struct upboard_led *led; | ||
|
||
if (!fpga || !pdata) | ||
return -EINVAL; | ||
|
||
led = devm_kzalloc(&pdev->dev, sizeof(*led), GFP_KERNEL); | ||
if (!led) | ||
return -ENOMEM; | ||
|
||
fldconf.lsb = pdata->bit; | ||
fldconf.msb = pdata->bit; | ||
led->field = devm_regmap_field_alloc(&pdev->dev, fpga->regmap, fldconf); | ||
if (IS_ERR(led->field)) | ||
return PTR_ERR(led->field); | ||
|
||
led->cdev.brightness_get = upboard_led_brightness_get; | ||
led->cdev.brightness_set = upboard_led_brightness_set; | ||
led->cdev.name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "upboard:%s:", | ||
pdata->colour); | ||
|
||
if (!led->cdev.name) | ||
return -ENOMEM; | ||
|
||
return devm_led_classdev_register(&pdev->dev, &led->cdev); | ||
}; | ||
|
||
static struct platform_driver upboard_led_driver = { | ||
.driver = { | ||
.name = "upboard-led", | ||
}, | ||
}; | ||
|
||
module_platform_driver_probe(upboard_led_driver, upboard_led_probe); | ||
|
||
MODULE_AUTHOR("Javier Arteaga <javier@emutex.com>"); | ||
MODULE_DESCRIPTION("UP Board LED driver"); | ||
MODULE_LICENSE("GPL v2"); | ||
MODULE_ALIAS("platform:upboard-led"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
b215ed9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is no go:
b215ed9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@andy-shev
b215ed9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(This patch was absolutely meant to be split and sent a series anyway. I'll make sure to rework this after the ongoing discussion.)
b215ed9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.