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
b90edecf
Commit
b90edecf
authored
Aug 24, 2018
by
David Frey
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix i2c_get/put_adapter() in mangOH modules
parent
1166d736
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
70 additions
and
100 deletions
+70
-100
mangoh_green.c
linux_kernel_modules/mangoh/mangoh_green.c
+13
-13
mangoh_red.c
linux_kernel_modules/mangoh/mangoh_red.c
+31
-50
mangoh_yellow.c
linux_kernel_modules/mangoh/mangoh_yellow.c
+26
-37
No files found.
linux_kernel_modules/mangoh/mangoh_green.c
View file @
b90edecf
...
...
@@ -116,6 +116,7 @@ static void mangoh_green_release(struct device* dev)
static
int
mangoh_green_probe
(
struct
platform_device
*
pdev
)
{
int
ret
=
0
;
struct
i2c_adapter
*
adapter
;
dev_info
(
&
pdev
->
dev
,
"In the probe
\n
"
);
...
...
@@ -134,7 +135,8 @@ static int mangoh_green_probe(struct platform_device* pdev)
dev_err
(
&
pdev
->
dev
,
"Failed to get the primary I2C adapter (%d).
\n
"
,
PRIMARY_I2C_BUS
);
return
-
ENODEV
;
ret
=
-
ENODEV
;
goto
done
;
}
/* Map the I2C switch */
...
...
@@ -146,21 +148,18 @@ static int mangoh_green_probe(struct platform_device* pdev)
&
pdev
->
dev
,
"Failed to register %s
\n
"
,
mangoh_green_pca954x_device_info
.
type
);
return
-
ENODEV
;
ret
=
-
ENODEV
;
goto
cleanup
;
}
/* Map the accelerometer */
dev_dbg
(
&
pdev
->
dev
,
"mapping bmi160 accelerometer
\n
"
);
adapter
=
i2c_get_adapter
(
PRIMARY_I2C_BUS
);
if
(
!
adapter
)
{
dev_err
(
&
pdev
->
dev
,
"No I2C bus %d.
\n
"
,
0
);
return
-
ENODEV
;
}
mangoh_green_driver_data
.
accelerometer
=
i2c_new_device
(
adapter
,
&
mangoh_green_lsm6ds3_devinfo
);
if
(
!
mangoh_green_driver_data
.
accelerometer
)
{
dev_err
(
&
pdev
->
dev
,
"Accelerometer is missing
\n
"
);
return
-
ENODEV
;
ret
=
-
ENODEV
;
goto
cleanup
;
}
/*
...
...
@@ -185,18 +184,19 @@ static int mangoh_green_probe(struct platform_device* pdev)
* https://chromium.googlesource.com/chromiumos/platform/ec/+/master/driver/charger/bq24192.c
*/
return
0
;
cleanup:
i2c_put_adapter
(
adapter
);
if
(
ret
!=
0
)
mangoh_green_remove
(
pdev
);
done:
return
ret
;
}
static
int
mangoh_green_remove
(
struct
platform_device
*
pdev
)
{
dev_info
(
&
pdev
->
dev
,
"In the remove
\n
"
);
i2c_unregister_device
(
mangoh_green_driver_data
.
accelerometer
);
i2c_put_adapter
(
mangoh_green_driver_data
.
accelerometer
->
adapter
);
i2c_unregister_device
(
mangoh_green_driver_data
.
i2c_switch
);
i2c_put_adapter
(
mangoh_green_driver_data
.
i2c_switch
->
adapter
);
return
0
;
}
...
...
linux_kernel_modules/mangoh/mangoh_red.c
View file @
b90edecf
...
...
@@ -230,13 +230,13 @@ static int mangoh_red_probe(struct platform_device* pdev)
#endif
/* ENABLE_IOT_SLOT */
struct
gpio_chip
*
gpio_expander
;
struct
i2c_board_info
*
accelerometer_board_info
;
struct
i2c_adapter
*
other_adapter
=
NULL
;
struct
i2c_adapter
*
main_adapter
;
struct
i2c_adapter
*
i2c_adapter_primary
,
*
i2c_adapter_gpio_exp
=
NULL
,
*
i2c_adapter_batt_charger
=
NULL
;
dev_info
(
&
pdev
->
dev
,
"%s(): probe
\n
"
,
__func__
);
main_adapter
=
i2c_get_adapter
(
PRIMARY_I2C_BUS
);
if
(
!
main_adapter
)
{
i2c_adapter_primary
=
i2c_get_adapter
(
PRIMARY_I2C_BUS
);
if
(
!
i2c_adapter_primary
)
{
dev_err
(
&
pdev
->
dev
,
"Failed to get primary I2C adapter (%d).
\n
"
,
PRIMARY_I2C_BUS
);
ret
=
-
ENODEV
;
...
...
@@ -254,7 +254,7 @@ static int mangoh_red_probe(struct platform_device* pdev)
/* Map the I2C switch */
dev_dbg
(
&
pdev
->
dev
,
"mapping i2c switch
\n
"
);
mangoh_red_driver_data
.
i2c_switch
=
i2c_new_device
(
main_adapter
,
&
mangoh_red_pca954x_device_info
);
i2c_new_device
(
i2c_adapter_primary
,
&
mangoh_red_pca954x_device_info
);
if
(
!
mangoh_red_driver_data
.
i2c_switch
)
{
dev_err
(
&
pdev
->
dev
,
"Failed to register %s
\n
"
,
mangoh_red_pca954x_device_info
.
type
);
...
...
@@ -262,19 +262,22 @@ static int mangoh_red_probe(struct platform_device* pdev)
goto
cleanup
;
}
/* Map the GPIO expander */
dev_dbg
(
&
pdev
->
dev
,
"mapping gpio expander
\n
"
);
other_adapter
=
i2c_get_adapter
(
MANGOH_RED_I2C_BUS_GPIO_EXPANDER
);
if
(
!
other_adapter
)
{
/* Get other i2c adapters required for probe */
i2c_adapter_gpio_exp
=
i2c_get_adapter
(
MANGOH_RED_I2C_BUS_GPIO_EXPANDER
);
i2c_adapter_batt_charger
=
i2c_get_adapter
(
MANGOH_RED_I2C_BUS_BATTERY_CHARGER
);
if
(
!
i2c_adapter_gpio_exp
||
!
i2c_adapter_batt_charger
)
{
dev_err
(
&
pdev
->
dev
,
"Couldn't get I2C bus %d to add the GPIO expander.
\n
"
,
MANGOH_RED_I2C_BUS_GPIO_EXPANDER
);
"Couldn't get necessary I2C buses downstream of I2C switch
\n
"
);
ret
=
-
ENODEV
;
goto
cleanup
;
}
/* Map the GPIO expander */
dev_dbg
(
&
pdev
->
dev
,
"mapping gpio expander
\n
"
);
mangoh_red_driver_data
.
gpio_expander
=
i2c_new_device
(
other_adapter
,
&
mangoh_red_gpio_expander_devinfo
);
i2c_put_adapter
(
other_adapter
);
i2c_new_device
(
i2c_adapter_gpio_exp
,
&
mangoh_red_gpio_expander_devinfo
);
if
(
!
mangoh_red_driver_data
.
gpio_expander
)
{
dev_err
(
&
pdev
->
dev
,
"Failed to register %s
\n
"
,
mangoh_red_gpio_expander_devinfo
.
type
);
...
...
@@ -324,7 +327,7 @@ static int mangoh_red_probe(struct platform_device* pdev)
mangoh_red_pdata
.
board_rev
==
MANGOH_RED_BOARD_REV_DV2
?
&
mangoh_red_lsm6ds3_devinfo
:
&
mangoh_red_bmi160_devinfo
;
mangoh_red_driver_data
.
accelerometer
=
i2c_new_device
(
main_adapter
,
accelerometer_board_info
);
i2c_new_device
(
i2c_adapter_primary
,
accelerometer_board_info
);
if
(
!
mangoh_red_driver_data
.
accelerometer
)
{
dev_err
(
&
pdev
->
dev
,
"Accelerometer is missing
\n
"
);
return
-
ENODEV
;
...
...
@@ -333,7 +336,7 @@ static int mangoh_red_probe(struct platform_device* pdev)
/* Map the I2C BMP280 pressure sensor */
dev_dbg
(
&
pdev
->
dev
,
"mapping bmp280 pressure sensor
\n
"
);
mangoh_red_driver_data
.
pressure
=
i2c_new_device
(
main_adapter
,
&
mangoh_red_pressure_devinfo
);
i2c_new_device
(
i2c_adapter_primary
,
&
mangoh_red_pressure_devinfo
);
if
(
!
mangoh_red_driver_data
.
pressure
)
{
dev_err
(
&
pdev
->
dev
,
"Pressure sensor is missing
\n
"
);
return
-
ENODEV
;
...
...
@@ -341,42 +344,26 @@ static int mangoh_red_probe(struct platform_device* pdev)
/* 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
"
,
MANGOH_RED_I2C_BUS_BATTERY_CHARGER
);
ret
=
-
ENODEV
;
goto
cleanup
;
}
mangoh_red_driver_data
.
battery_charger
=
i2c_new_device
(
other_adapter
,
&
mangoh_red_battery_charger_devinfo
);
i2c_put_adapter
(
other_adapter
);
i2c_adapter_batt_charger
,
&
mangoh_red_battery_charger_devinfo
);
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
)
{
/* 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
);
if
(
!
other_adapter
)
{
dev_err
(
&
pdev
->
dev
,
"No I2C bus %d.
\n
"
,
MANGOH_RED_I2C_BUS_BATTERY_CHARGER
);
ret
=
-
ENODEV
;
goto
cleanup
;
}
mangoh_red_driver_data
.
battery_gauge
=
i2c_new_device
(
other_adapter
,
&
mangoh_red_battery_gauge_devinfo
);
i2c_put_adapter
(
other_adapter
);
i2c_adapter_batt_charger
,
&
mangoh_red_battery_gauge_devinfo
);
if
(
!
mangoh_red_driver_data
.
battery_gauge
)
{
dev_err
(
&
pdev
->
dev
,
"battery gauge is missing
\n
"
);
ret
=
-
ENODEV
;
goto
cleanup
;
}
}
/*
* TODO:
* 3503 USB Hub: 0x08
...
...
@@ -386,21 +373,15 @@ static int mangoh_red_probe(struct platform_device* pdev)
*/
cleanup:
i2c_put_adapter
(
main_adapter
);
i2c_put_adapter
(
i2c_adapter_primary
);
i2c_put_adapter
(
i2c_adapter_gpio_exp
);
i2c_put_adapter
(
i2c_adapter_batt_charger
);
if
(
ret
!=
0
)
mangoh_red_remove
(
pdev
);
done:
return
ret
;
}
static
void
try_unregister_i2c_device
(
struct
i2c_client
*
client
)
{
if
(
client
!=
NULL
)
{
i2c_unregister_device
(
client
);
i2c_put_adapter
(
client
->
adapter
);
}
}
static
int
mangoh_red_remove
(
struct
platform_device
*
pdev
)
{
struct
mangoh_red_driver_data
*
dd
=
platform_get_drvdata
(
pdev
);
...
...
@@ -408,11 +389,11 @@ 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
);
i2c_unregister
_device
(
dd
->
battery_gauge
);
try_unregister_i2c
_device
(
dd
->
battery_charger
);
try_unregister_i2c
_device
(
dd
->
pressure
);
try_unregister_i2c
_device
(
dd
->
accelerometer
);
i2c_unregister
_device
(
dd
->
battery_charger
);
i2c_unregister
_device
(
dd
->
pressure
);
i2c_unregister
_device
(
dd
->
accelerometer
);
if
(
dd
->
led_registered
)
platform_device_unregister
(
&
mangoh_red_led
);
...
...
@@ -425,8 +406,8 @@ static int mangoh_red_remove(struct platform_device* pdev)
mangoh_red_mux_deinit
();
#endif
/* ENABLE_IOT_SLOT */
try_unregister_i2c
_device
(
dd
->
gpio_expander
);
try_unregister_i2c
_device
(
dd
->
i2c_switch
);
i2c_unregister
_device
(
dd
->
gpio_expander
);
i2c_unregister
_device
(
dd
->
i2c_switch
);
return
0
;
}
...
...
linux_kernel_modules/mangoh/mangoh_yellow.c
View file @
b90edecf
...
...
@@ -13,7 +13,7 @@
*-----------------------------------------------------------------------------
*/
#define MANGOH_YELLOW_I2C_SW_BUS_BASE (PRIMARY_I2C_BUS + 1)
#define MANGOH_YELLOW_I2C_BUS_IOT0
(MANGOH_YELLOW_I2C_SW_BUS_BASE + 0)
#define MANGOH_YELLOW_I2C_BUS_IOT0
(MANGOH_YELLOW_I2C_SW_BUS_BASE + 0)
#define MANGOH_YELLOW_I2C_BUS_BATTERY_CHARGER (MANGOH_YELLOW_I2C_SW_BUS_BASE + 1)
#define MANGOH_YELLOW_I2C_BUS_USB_HUB (MANGOH_YELLOW_I2C_SW_BUS_BASE + 1)
#define MANGOH_YELLOW_I2C_BUS_GPIO_EXPANDER (MANGOH_YELLOW_I2C_SW_BUS_BASE + 2)
...
...
@@ -62,9 +62,9 @@ static struct mangoh_yellow_platform_data {
}
mangoh_yellow_pdata
;
static
struct
mangoh_yellow_driver_data
{
struct
i2c_client
*
bme680
;
struct
i2c_client
*
bmi088a
;
struct
i2c_client
*
bmi088g
;
struct
i2c_client
*
bme680
;
struct
i2c_client
*
bmi088a
;
struct
i2c_client
*
bmi088g
;
}
mangoh_yellow_driver_data
=
{
};
...
...
@@ -97,12 +97,12 @@ static void mangoh_yellow_release(struct device* dev)
static
int
mangoh_yellow_probe
(
struct
platform_device
*
pdev
)
{
int
ret
=
0
;
struct
i2c_adapter
*
main_adapter
;
struct
i2c_adapter
*
i2c_adapter_primary
;
dev_info
(
&
pdev
->
dev
,
"%s(): probe
\n
"
,
__func__
);
main_adapter
=
i2c_get_adapter
(
PRIMARY_I2C_BUS
);
if
(
!
main_adapter
)
{
i2c_adapter_primary
=
i2c_get_adapter
(
PRIMARY_I2C_BUS
);
if
(
!
i2c_adapter_primary
)
{
dev_err
(
&
pdev
->
dev
,
"Failed to get primary I2C adapter (%d).
\n
"
,
PRIMARY_I2C_BUS
);
ret
=
-
ENODEV
;
...
...
@@ -117,62 +117,51 @@ static int mangoh_yellow_probe(struct platform_device* pdev)
platform_set_drvdata
(
pdev
,
&
mangoh_yellow_driver_data
);
/* Map the I2C BME680 humidity/gas/temp/pressure sensor */
dev_dbg
(
&
pdev
->
dev
,
"mapping bme680 gas/temperature/pressure sensor
\n
"
);
/* Map the I2C BME680 humidity/gas/temp/pressure sensor */
dev_dbg
(
&
pdev
->
dev
,
"mapping bme680 gas/temperature/pressure sensor
\n
"
);
mangoh_yellow_driver_data
.
bme680
=
i2c_new_device
(
main_adapter
,
&
mangoh_yellow_bme680_devinfo
);
i2c_put_adapter
(
main_adapter
);
i2c_new_device
(
i2c_adapter_primary
,
&
mangoh_yellow_bme680_devinfo
);
if
(
!
mangoh_yellow_driver_data
.
bme680
)
{
dev_err
(
&
pdev
->
dev
,
"Gas/Humidity/Temp sensor is missing
\n
"
);
ret
=
-
ENODEV
;
goto
cleanup
;
}
/* Map the I2C BMI088 gyro/accel sensor */
dev_dbg
(
&
pdev
->
dev
,
"mapping bmi088 gyro/accel sensor
\n
"
);
mangoh_yellow_driver_data
.
bmi088a
=
i2c_new_device
(
main_adapter
,
&
mangoh_yellow_bmi088a_devinfo
);
i2c_put_adapter
(
main_adapter
);
goto
cleanup
;
}
/* Map the I2C BMI088 gyro/accel sensor */
dev_dbg
(
&
pdev
->
dev
,
"mapping bmi088 gyro/accel sensor
\n
"
);
mangoh_yellow_driver_data
.
bmi088a
=
i2c_new_device
(
i2c_adapter_primary
,
&
mangoh_yellow_bmi088a_devinfo
);
if
(
!
mangoh_yellow_driver_data
.
bmi088a
)
{
dev_err
(
&
pdev
->
dev
,
"bmi088 accel sensor is missing
\n
"
);
ret
=
-
ENODEV
;
goto
cleanup
;
}
goto
cleanup
;
}
mangoh_yellow_driver_data
.
bmi088g
=
i2c_new_device
(
main_adapter
,
&
mangoh_yellow_bmi088g_devinfo
);
i2c_put_adapter
(
main_adapter
);
mangoh_yellow_driver_data
.
bmi088g
=
i2c_new_device
(
i2c_adapter_primary
,
&
mangoh_yellow_bmi088g_devinfo
);
if
(
!
mangoh_yellow_driver_data
.
bmi088g
)
{
dev_err
(
&
pdev
->
dev
,
"bmi088 gyro sensor is missing
\n
"
);
ret
=
-
ENODEV
;
goto
cleanup
;
goto
cleanup
;
}
cleanup:
i2c_put_adapter
(
main_adapter
);
i2c_put_adapter
(
i2c_adapter_primary
);
if
(
ret
!=
0
)
mangoh_yellow_remove
(
pdev
);
done:
return
ret
;
}
static
void
try_unregister_i2c_device
(
struct
i2c_client
*
client
)
{
if
(
client
!=
NULL
)
{
i2c_unregister_device
(
client
);
i2c_put_adapter
(
client
->
adapter
);
}
}
static
int
mangoh_yellow_remove
(
struct
platform_device
*
pdev
)
{
struct
mangoh_yellow_driver_data
*
dd
=
platform_get_drvdata
(
pdev
);
dev_info
(
&
pdev
->
dev
,
"Removing mangoh red platform device
\n
"
);
try_unregister_i2c
_device
(
dd
->
bmi088a
);
try_unregister_i2c
_device
(
dd
->
bmi088g
);
try_unregister_i2c
_device
(
dd
->
bme680
);
i2c_unregister
_device
(
dd
->
bmi088a
);
i2c_unregister
_device
(
dd
->
bmi088g
);
i2c_unregister
_device
(
dd
->
bme680
);
return
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