BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mangoh-drivers
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
mangoh-drivers
Commits
e6a4b2d0
Commit
e6a4b2d0
authored
Feb 15, 2018
by
David Clark
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
ssh://github.com/mangOH/mangOH
parents
d9a8c9ff
3cd13e52
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
89 additions
and
92 deletions
+89
-92
led.c
linux_kernel_modules/led/led.c
+58
-69
mangoh_red.c
linux_kernel_modules/mangoh/mangoh_red.c
+31
-23
No files found.
linux_kernel_modules/led/led.c
View file @
e6a4b2d0
...
...
@@ -7,106 +7,95 @@
struct
led_device
{
struct
platform_device
*
pdev
;
atomic_t
val
;
int
gpio
;
atomic_t
val
;
int
gpio
;
};
static
ssize_t
led_show
(
struct
device
*
dev
,
struct
device_attribute
*
attr
,
char
*
buf
)
static
ssize_t
led_show
(
struct
device
*
dev
,
struct
device_attribute
*
attr
,
char
*
buf
)
{
struct
led_device
*
led
=
dev_get_drvdata
(
dev
);
return
sprintf
(
buf
,
"%d
\n
"
,
atomic_read
(
&
led
->
val
));
struct
led_device
*
led
=
dev_get_drvdata
(
dev
);
return
sprintf
(
buf
,
"%d
\n
"
,
atomic_read
(
&
led
->
val
));
}
static
int
led_store
(
struct
device
*
dev
,
struct
device_attribute
*
attr
,
const
char
*
buf
,
size_t
count
)
static
int
led_store
(
struct
device
*
dev
,
struct
device_attribute
*
attr
,
const
char
*
buf
,
size_t
count
)
{
struct
led_device
*
led
=
dev_get_drvdata
(
dev
);
unsigned
int
val
;
int
ret
;
struct
led_device
*
led
=
dev_get_drvdata
(
dev
);
u8
val
;
int
ret
;
ret
=
kstrtoint
(
buf
,
10
,
&
val
);
if
(
ret
||
val
>
1
)
ret
=
kstrtou8
(
buf
,
10
,
&
val
);
if
(
ret
||
val
>
1
)
return
-
EINVAL
;
gpio_set_value_cansleep
(
led
->
gpio
,
val
);
atomic_set
(
&
led
->
val
,
val
);
return
count
;
gpio_set_value_cansleep
(
led
->
gpio
,
val
);
atomic_set
(
&
led
->
val
,
val
);
return
count
;
}
static
DEVICE_ATTR_RW
(
led
);
static
int
led_probe
(
struct
platform_device
*
pdev
)
{
struct
led_platform_data
*
pdata
=
dev_get_platdata
(
&
pdev
->
dev
);
struct
led_device
*
dev
;
struct
led_device
*
dev
;
int
ret
=
0
;
struct
led_platform_data
*
pdata
=
dev_get_platdata
(
&
pdev
->
dev
);
dev_info
(
&
pdev
->
dev
,
"%s(): probe
\n
"
,
__func__
);
dev_info
(
&
pdev
->
dev
,
"%s(): probe
\n
"
,
__func__
);
dev
=
kzalloc
(
sizeof
(
struct
led_device
),
GFP_KERNEL
);
if
(
!
dev
)
goto
err_out
;
if
(
!
pdata
)
{
ret
=
-
EINVAL
;
dev_err
(
&
pdev
->
dev
,
"Required platform data not provided
\n
"
);
goto
done
;
}
dev
=
devm_kzalloc
(
&
pdev
->
dev
,
sizeof
(
*
dev
),
GFP_KERNEL
);
if
(
!
dev
)
{
ret
=
-
ENOMEM
;
goto
done
;
}
dev
->
pdev
=
pdev
;
atomic_set
(
&
dev
->
val
,
0
);
pdata
=
dev_get_platdata
(
&
pdev
->
dev
);
dev
->
gpio
=
pdata
->
gpio
;
ret
=
gpio_request
(
dev
->
gpio
,
dev_name
(
&
pdev
->
dev
));
if
(
ret
)
{
dev_err
(
&
pdev
->
dev
,
"failed to request LED gpio
\n
"
);
goto
err_out
;
}
ret
=
gpio_direction_output
(
dev
->
gpio
,
atomic_read
(
&
dev
->
val
));
if
(
ret
)
{
dev_err
(
&
pdev
->
dev
,
"failed to set LED gpio as output
\n
"
);
goto
free_gpio
;
}
ret
=
device_create_file
(
&
pdev
->
dev
,
&
dev_attr_led
);
atomic_set
(
&
dev
->
val
,
0
);
dev
->
gpio
=
pdata
->
gpio
;
ret
=
devm_gpio_request
(
&
pdev
->
dev
,
dev
->
gpio
,
dev_name
(
&
pdev
->
dev
));
if
(
ret
)
{
dev_err
(
&
pdev
->
dev
,
"failed to create led sysfs entry
\n
"
);
goto
free_gpio
;
}
dev_err
(
&
pdev
->
dev
,
"failed to request LED gpio
\n
"
);
goto
done
;
}
platform_set_drvdata
(
pdev
,
dev
);
return
0
;
ret
=
gpio_direction_output
(
dev
->
gpio
,
atomic_read
(
&
dev
->
val
));
if
(
ret
)
{
dev_err
(
&
pdev
->
dev
,
"failed to set LED gpio as output
\n
"
);
goto
done
;
}
free_gpio:
gpio_direction_input
(
dev
->
gpio
);
gpio_free
(
dev
->
gpio
);
ret
=
device_create_file
(
&
pdev
->
dev
,
&
dev_attr_led
);
if
(
ret
)
{
dev_err
(
&
pdev
->
dev
,
"failed to create led sysfs entry
\n
"
);
goto
done
;
}
err_out:
if
(
dev
)
kfree
(
dev
);
platform_set_drvdata
(
pdev
,
dev
);
return
ret
;
done:
return
ret
;
}
static
int
led_remove
(
struct
platform_device
*
pdev
)
{
struct
led_device
*
dev
=
platform_get_drvdata
(
pdev
);
int
ret
;
dev_info
(
&
pdev
->
dev
,
"%s(): remove
\n
"
,
__func__
);
struct
led_device
*
led
=
dev_get_drvdata
(
&
pdev
->
dev
);
dev_info
(
&
pdev
->
dev
,
"%s(): remove
\n
"
,
__func__
);
/* remove sysfs files */
/* remove sysfs files */
device_remove_file
(
&
pdev
->
dev
,
&
dev_attr_led
);
ret
=
gpio_direction_input
(
dev
->
gpio
);
if
(
ret
)
{
dev_err
(
&
pdev
->
dev
,
"failed to set LED gpio as input
\n
"
);
}
gpio_free
(
dev
->
gpio
);
kfree
(
dev
);
/* Turn off the LED as the device is removed */
gpio_set_value_cansleep
(
led
->
gpio
,
0
);
return
0
;
}
...
...
linux_kernel_modules/mangoh/mangoh_red.c
View file @
e6a4b2d0
...
...
@@ -53,7 +53,8 @@ static void mangoh_red_led_release(struct device *dev);
static
void
mangoh_red_iot_slot_release
(
struct
device
*
dev
);
static
int
mangoh_red_iot_slot_request_i2c
(
struct
i2c_adapter
**
adapter
);
static
int
mangoh_red_iot_slot_release_i2c
(
struct
i2c_adapter
**
adapter
);
static
int
mangoh_red_iot_slot_request_spi
(
struct
spi_master
**
spi_master
,
int
*
cs
);
static
int
mangoh_red_iot_slot_request_spi
(
struct
spi_master
**
spi_master
,
int
*
cs
);
static
int
mangoh_red_iot_slot_release_spi
(
void
);
static
int
mangoh_red_iot_slot_request_sdio
(
void
);
static
int
mangoh_red_iot_slot_release_sdio
(
void
);
...
...
@@ -97,11 +98,11 @@ static struct mangoh_red_driver_data {
struct
i2c_client
*
gpio_expander
;
bool
mux_initialized
;
bool
iot_slot_registered
;
bool
led_registered
;
bool
led_registered
;
}
mangoh_red_driver_data
=
{
.
mux_initialized
=
false
,
.
iot_slot_registered
=
false
,
.
led_registered
=
false
,
.
led_registered
=
false
,
};
static
struct
platform_device
mangoh_red_device
=
{
...
...
@@ -161,17 +162,19 @@ static struct i2c_board_info mangoh_red_lsm6ds3_devinfo = {
static
struct
i2c_board_info
mangoh_red_pressure_devinfo
=
{
I2C_BOARD_INFO
(
"bmp280"
,
0x76
),
};
/*
#if 0
static struct ltc294x_platform_data mangoh_red_battery_gauge_platform_data = {
.r_sense = 18,
.prescaler_exp = 32,
.name = "LTC2942",
.name = "LTC2942",
};
static struct i2c_board_info mangoh_red_battery_gauge_devinfo = {
I2C_BOARD_INFO("ltc2942", 0x64),
.platform_data = &mangoh_red_battery_gauge_platform_data,
};
*/
#endif
static
struct
i2c_board_info
mangoh_red_battery_charger_devinfo
=
{
I2C_BOARD_INFO
(
"bq24190"
,
0x6B
),
};
...
...
@@ -226,9 +229,9 @@ static int mangoh_red_probe(struct platform_device* pdev)
struct
i2c_adapter
*
other_adapter
=
NULL
;
struct
i2c_adapter
*
main_adapter
;
dev_info
(
&
pdev
->
dev
,
"%s(): probe
\n
"
,
__func__
);
dev_info
(
&
pdev
->
dev
,
"%s(): probe
\n
"
,
__func__
);
main_adapter
=
i2c_get_adapter
(
PRIMARY_I2C_BUS
);
main_adapter
=
i2c_get_adapter
(
PRIMARY_I2C_BUS
);
if
(
!
main_adapter
)
{
dev_err
(
&
pdev
->
dev
,
"Failed to get primary I2C adapter (%d).
\n
"
,
PRIMARY_I2C_BUS
);
...
...
@@ -295,8 +298,8 @@ static int mangoh_red_probe(struct platform_device* pdev)
}
mangoh_red_driver_data
.
iot_slot_registered
=
true
;
/* Map the LED */
mangoh_red_led_pdata
.
gpio
=
gpio_expander
->
base
+
8
;
/* Map the LED */
mangoh_red_led_pdata
.
gpio
=
gpio_expander
->
base
+
8
;
ret
=
platform_device_register
(
&
mangoh_red_led
);
if
(
ret
!=
0
)
{
dev_err
(
&
pdev
->
dev
,
"Failed to register LED device
\n
"
);
...
...
@@ -330,8 +333,8 @@ static int mangoh_red_probe(struct platform_device* pdev)
return
-
ENODEV
;
}
/* Map the I2C BQ24296 driver: for now use the BQ24190 driver code */
dev_dbg
(
&
pdev
->
dev
,
"mapping bq24296 driver
\n
"
);
/* Map the I2C BQ24296 driver: for now use the BQ24190 driver code */
dev_dbg
(
&
pdev
->
dev
,
"mapping bq24296 driver
\n
"
);
other_adapter
=
i2c_get_adapter
(
MANGOH_RED_I2C_BUS_BATTERY_CHARGER
);
if
(
!
other_adapter
)
{
dev_err
(
&
pdev
->
dev
,
"No I2C bus %d.
\n
"
,
...
...
@@ -339,22 +342,24 @@ static int mangoh_red_probe(struct platform_device* pdev)
ret
=
-
ENODEV
;
goto
cleanup
;
}
mangoh_red_driver_data
.
battery_charger
=
i2c_new_device
(
mangoh_red_driver_data
.
battery_charger
=
i2c_new_device
(
other_adapter
,
&
mangoh_red_battery_charger_devinfo
);
i2c_put_adapter
(
other_adapter
);
if
(
!
mangoh_red_driver_data
.
battery_charger
)
{
if
(
!
mangoh_red_driver_data
.
battery_charger
)
{
dev_err
(
&
pdev
->
dev
,
"battery charger is missing
\n
"
);
ret
=
-
ENODEV
;
goto
cleanup
;
}
// if (mangoh_red_pdata.board_rev != MANGOH_RED_BOARD_REV_DV3) {
#if 0
if (mangoh_red_pdata.board_rev != MANGOH_RED_BOARD_REV_DV3) {
/* Map the I2C ltc2942 battery gauge */
/* dev_dbg(&pdev->dev, "mapping ltc2942 battery gauge\n");
other_adapter = i2c_get_adapter(MANGOH_RED_I2C_BUS_BATTERY_CHARGER);
dev_dbg(&pdev->dev, "mapping ltc2942 battery gauge\n");
other_adapter =
i2c_get_adapter(MANGOH_RED_I2C_BUS_BATTERY_CHARGER);
if (!other_adapter) {
dev_err(&pdev->dev, "No I2C bus %d.\n",
MANGOH_RED_I2C_BUS_BATTERY_CHARGER);
MANGOH_RED_I2C_BUS_BATTERY_CHARGER);
ret = -ENODEV;
goto cleanup;
}
...
...
@@ -367,7 +372,7 @@ static int mangoh_red_probe(struct platform_device* pdev)
goto cleanup;
}
}
*/
#endif
/*
* TODO:
* 3503 USB Hub: 0x08
...
...
@@ -398,8 +403,10 @@ static int mangoh_red_remove(struct platform_device* pdev)
dev_info
(
&
pdev
->
dev
,
"Removing mangoh red platform device
\n
"
);
// if (mangoh_red_pdata.board_rev != MANGOH_RED_BOARD_REV_DV3)
// try_unregister_i2c_device(dd->battery_gauge);
#if 0
if (mangoh_red_pdata.board_rev != MANGOH_RED_BOARD_REV_DV3)
try_unregister_i2c_device(dd->battery_gauge);
#endif
try_unregister_i2c_device
(
dd
->
battery_charger
);
try_unregister_i2c_device
(
dd
->
pressure
);
...
...
@@ -408,7 +415,7 @@ static int mangoh_red_remove(struct platform_device* pdev)
if
(
dd
->
led_registered
)
platform_device_unregister
(
&
mangoh_red_led
);
if
(
dd
->
iot_slot_registered
)
if
(
dd
->
iot_slot_registered
)
platform_device_unregister
(
&
mangoh_red_iot_slot
);
if
(
dd
->
mux_initialized
)
...
...
@@ -437,7 +444,8 @@ static int mangoh_red_iot_slot_release_i2c(struct i2c_adapter **adapter)
return
0
;
}
static
int
mangoh_red_iot_slot_request_spi
(
struct
spi_master
**
spi_master
,
int
*
cs
)
static
int
mangoh_red_iot_slot_request_spi
(
struct
spi_master
**
spi_master
,
int
*
cs
)
{
*
spi_master
=
spi_busnum_to_master
(
PRIMARY_SPI_BUS
);
*
cs
=
0
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment