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
e76da17b
Commit
e76da17b
authored
Nov 21, 2018
by
Ashish Syal
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed opt300x bugs to enable operation of driver for opt3002
parent
b9812146
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
20 deletions
+42
-20
mangoh_common.h
linux_kernel_modules/mangoh/mangoh_common.h
+1
-1
mangoh_yellow.c
linux_kernel_modules/mangoh/mangoh_yellow.c
+9
-0
opt300x.c
linux_kernel_modules/opt300x/opt300x.c
+32
-19
No files found.
linux_kernel_modules/mangoh/mangoh_common.h
View file @
e76da17b
...
...
@@ -35,7 +35,7 @@
#define CF3_GPIO8 (58)
#define CF3_GPIO2 (38)
#define CF3_GPIO33 (78)
#define CF3_GPIO36 SWIMCU_GPIO_TO_SYS(
2
)
#define CF3_GPIO36 SWIMCU_GPIO_TO_SYS(
0
)
#endif
#endif
/* MANGOH_COMMON_H */
linux_kernel_modules/mangoh/mangoh_yellow.c
View file @
e76da17b
...
...
@@ -155,8 +155,11 @@ static struct i2c_board_info mangoh_yellow_battery_gauge_devinfo = {
static
struct
i2c_board_info
mangoh_yellow_magnetometer_devinfo
=
{
I2C_BOARD_INFO
(
"bmm150"
,
0x10
),
};
static
struct
i2c_board_info
mangoh_yellow_light_devinfo
=
{
I2C_BOARD_INFO
(
"opt3002"
,
0x44
),
.
irq
=
0
,
};
static
struct
expander_platform_data
mangoh_yellow_expander_platform_data
=
{
.
gpio_expander_base
=
-
1
,
...
...
@@ -357,6 +360,12 @@ static int mangoh_yellow_probe(struct platform_device* pdev)
/* Map the I2C Light Sensor */
dev_dbg
(
&
pdev
->
dev
,
"mapping Light Sensor
\n
"
);
if
(
devm_gpio_request_one
(
&
pdev
->
dev
,
CF3_GPIO36
,
GPIOF_DIR_IN
,
"CF3 opt300x gpio interrupt"
))
{
dev_err
(
&
pdev
->
dev
,
"Couldn't request CF3 gpio36"
);
ret
=
-
ENODEV
;
goto
cleanup
;
}
mangoh_yellow_light_devinfo
.
irq
=
gpio_to_irq
(
CF3_GPIO36
);
mangoh_yellow_driver_data
.
light
=
i2c_new_device
(
i2c_adapter_port2
,
&
mangoh_yellow_light_devinfo
);
...
...
linux_kernel_modules/opt300x/opt300x.c
View file @
e76da17b
...
...
@@ -37,7 +37,7 @@
#define OPT300x_LOW_LIMIT 0x02
#define OPT300x_HIGH_LIMIT 0x03
#define OPT300x_MANUFACTURER_ID 0x7e
#define OPT300
x
_DEVICE_ID 0x7f
#define OPT300
1
_DEVICE_ID 0x7f
#define MANUFACTURER_ID_TI 0x5449
...
...
@@ -192,10 +192,6 @@ static const struct opt300x_scale opt3002_scales[] = {
struct
opt300x_chip
{
int
device_id
;
u16
multiplier_numerator
;
...
...
@@ -205,7 +201,7 @@ struct opt300x_chip {
};
static
const
struct
opt300x_chip
opt3001_chip
=
{
.
device_id
=
0x3001
,
.
device_id
=
OPT3001_DEVICE_ID
,
.
multiplier_numerator
=
1
,
.
multiplier_denominator
=
100
,
.
table
=
opt3001_scales
,
...
...
@@ -216,7 +212,7 @@ static const struct opt300x_chip opt3002_chip = {
.
device_id
=
-
1
,
.
multiplier_numerator
=
6
,
.
multiplier_denominator
=
5
,
.
table
=
opt300
1
_scales
,
.
table
=
opt300
2
_scales
,
.
table_num_entries
=
ARRAY_SIZE
(
opt3002_scales
),
};
...
...
@@ -247,17 +243,18 @@ static int opt300x_find_scale(const struct opt300x *opt, int val,
int
val2
,
u8
*
exponent
)
{
int
i
;
int
val_tmp
=
(
val
*
1000ll
+
val2
/
1000
);
for
(
i
=
0
;
i
<
opt
->
chip
->
table_num_entries
;
i
++
)
{
const
struct
opt300x_scale
*
scale
=
&
opt
->
chip
->
table
[
i
];
int
scale_tmp
=
(
scale
->
val
*
1000ll
+
scale
->
val2
/
1000
);
/*
* Combine the integer and micro parts for comparison
* purposes. Use milli lux precision to avoid 32-bit integer
* overflows.
*/
if
((
val
*
1000
+
val2
/
1000
)
<=
(
scale
->
val
*
1000
+
scale
->
val2
/
1000
))
{
if
(
val_tmp
<=
scale_tmp
)
{
*
exponent
=
i
;
return
0
;
}
...
...
@@ -269,12 +266,17 @@ static int opt300x_find_scale(const struct opt300x *opt, int val,
static
void
opt300x_to_iio_ret
(
struct
opt300x
*
opt
,
u8
exponent
,
u16
mantissa
,
int
*
val
,
int
*
val2
)
{
int
lux
;
u64
lux
;
u64
tmp
;
u16
multiplier1
=
opt
->
chip
->
multiplier_numerator
;
u16
multiplier2
=
opt
->
chip
->
multiplier_denominator
;
lux
=
(
1000000
/
multiplier2
)
*
(
mantissa
<<
exponent
)
*
multiplier1
;
*
val
=
lux
/
1000000
;
*
val2
=
lux
-
(
1000000
*
(
*
val
));
tmp
=
1000000ull
;
do_div
(
tmp
,
multiplier2
);
lux
=
tmp
*
(
mantissa
<<
exponent
)
*
multiplier1
;
tmp
=
lux
;
do_div
(
tmp
,
1000000
);
*
val
=
tmp
;
*
val2
=
lux
-
(
1000000ull
*
(
*
val
));
}
static
void
opt300x_set_mode
(
struct
opt300x
*
opt
,
u16
*
reg
,
u16
mode
)
...
...
@@ -581,6 +583,11 @@ static int opt300x_write_event_value(struct iio_dev *iio,
u16
reg
;
u8
exponent
;
u64
tmp
;
u16
multiplier1
=
opt
->
chip
->
multiplier_numerator
;
u16
multiplier2
=
opt
->
chip
->
multiplier_denominator
;
if
(
val
<
0
)
return
-
EINVAL
;
...
...
@@ -593,7 +600,10 @@ static int opt300x_write_event_value(struct iio_dev *iio,
goto
err
;
}
mantissa
=
(((
val
*
1000
)
+
(
val2
/
1000
))
/
10
)
>>
exponent
;
tmp
=
((
val
*
1000000ull
)
+
val2
)
*
multiplier2
;
do_div
(
tmp
,
multiplier1
*
1000000ull
);
mantissa
=
tmp
>>
exponent
;
value
=
(
exponent
<<
12
)
|
mantissa
;
switch
(
dir
)
{
...
...
@@ -706,13 +716,13 @@ static int opt300x_read_id(struct opt300x *opt)
manufacturer
);
return
-
ENODEV
;
}
dev_info
(
opt
->
dev
,
"manufacturer id (%u)
\n
"
,
manufacturer
);
if
(
opt
->
chip
->
device_id
>=
0
)
{
ret
=
i2c_smbus_read_word_swapped
(
opt
->
client
,
OPT300
x
_DEVICE_ID
);
ret
=
i2c_smbus_read_word_swapped
(
opt
->
client
,
OPT300
1
_DEVICE_ID
);
if
(
ret
<
0
)
{
dev_err
(
opt
->
dev
,
"failed to read register %02x
\n
"
,
OPT300
x
_DEVICE_ID
);
OPT300
1
_DEVICE_ID
);
return
ret
;
}
device_id
=
ret
;
...
...
@@ -846,9 +856,10 @@ static int opt300x_probe(struct i2c_client *client,
struct
opt300x_chip
*
c
=
(
struct
opt300x_chip
*
)
id
->
driver_data
;
struct
iio_dev
*
iio
;
struct
opt300x
*
opt
;
int
irq
=
client
->
irq
;
int
ret
;
int
irq
=
client
->
irq
;
iio
=
devm_iio_device_alloc
(
dev
,
sizeof
(
*
opt
));
if
(
!
iio
)
return
-
ENOMEM
;
...
...
@@ -864,6 +875,7 @@ static int opt300x_probe(struct i2c_client *client,
ret
=
opt300x_read_id
(
opt
);
if
(
ret
)
return
ret
;
dev_info
(
dev
,
"Found %s
\n
"
,
id
->
name
);
ret
=
opt300x_configure
(
opt
);
...
...
@@ -893,8 +905,9 @@ static int opt300x_probe(struct i2c_client *client,
return
ret
;
}
opt
->
use_irq
=
true
;
dev_info
(
opt
->
dev
,
"enabling interrupt based operation"
);
}
else
{
dev_
dbg
(
opt
->
dev
,
"enabling interrupt-less operation
\n
"
);
dev_
info
(
opt
->
dev
,
"enabling interrupt-less operation
\n
"
);
}
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