summaryrefstree
path: root/kernel/drivers/sensorhub/brcm/st_vl53l5/Makefile
blob: ea893fe1fef3a3276664c8042e926c59691009b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
#
# Copyright (c) 2020, STMicroelectronics - All Rights Reserved
# This file is part of VL53L5 Kernel Driver and is dual licensed,
# either 'STMicroelectronics Proprietary license'
# or 'BSD 3-clause "New" or "Revised" License' , at your option.
#
# 'STMicroelectronics Proprietary license'
#
# License terms: STMicroelectronics Proprietary in accordance with licensing
# terms at www.st.com/sla0081
#
# STMicroelectronics confidential
# Reproduction and Communication of this document is strictly prohibited unless
# specifically authorized in writing by STMicroelectronics.
#
# Alternatively, VL53L5 Kernel Driver may be distributed under the terms of
# 'BSD 3-clause "New" or "Revised" License', in which case the following
# provisions apply instead of the ones mentioned above :
#
# License terms: BSD 3-clause "New" or "Revised" License.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.



# Parameters
# Configure the build type : RELEASE, DEBUG
BUILD_TYPE = RELEASE
# Specify the comms type : SPI, I2C
COMMS_TYPE = SPI
# Specify the I2C bus adapter number for use with COMMS_TYPE=I2C
I2C_ADAPTER_NUM := 1
# Specify the SPI comms speed in KHz for use with COMMS_TYPE=SPI
COMMS_SPEED_KHZ := 7000
# Specify the GPIO pin number for SPI chip select.
GPIO_CHIP_SELECT := 2
# Specify the GPIO pin number for VL53L5 comms select. Set to -1 to ignore.
GPIO_COMMS_SELECT := 23
# Specify the GPIO pin number for VL53L5 power enable. Set to -1 to ignore.
GPIO_POWER_ENABLE := 12
# Specify the GPIO pin number for VL53L5 low power. Set to -1 to ignore.
# Note: Low power mode is not currently available. However, this pin must be
#       set high in order to enable power.
GPIO_LOW_POWER := 19

# Sets the servicing mode to use i.e. INTERRUPT, WORKER or DEFAULT
RANGE_SERVICING = DEFAULT

# Set to TRUE to enable TCDM dump
TCDM_DUMP_ENABLE = FALSE

# Set to TRUE to enable offset calibration
OFFSET_CAL_ENABLE = FALSE

# Set to TRUE to enable code for internal testing
LEGACY_CODE = FALSE

# Set to TRUE to enable logging functions.
LOG_ENABLE = TRUE

# Set to TRUE to enable stress test functions.
TEST_ENABLE = FALSE

ifeq "$(RANGE_SERVICING)" "INTERRUPT"
GPIO_INTERRUPT := 16
else
GPIO_INTERRUPT := -1
endif

# Set to TRUE to enable logging functions.
LOG_ENABLE = TRUE

ifeq "$(LOG_ENABLE)" "TRUE"
  $(warning LOG_ENABLE=$(LOG_ENABLE))
  ccflags-y += -DVL53L5_KERNEL_LOG
endif

KDIR = /lib/modules/$(shell uname -r)/build

ccflags-y	+= -I$(src)/inc
ccflags-y	+= -I$(src)/bare_driver/common/inc
ccflags-y	+= -I$(src)/bare_driver/api/inc
ccflags-y	+= -I$(src)/bare_driver/dci/inc
ccflags-y	+= -I$(src)/platform/inc
ccflags-y	+= -Wall -Werror -Wno-missing-braces

ifeq "$(RANGE_SERVICING)" "INTERRUPT"
ccflags-y += -DVL53L5_INTERRUPT
endif

ifeq "$(OFFSET_CAL_ENABLE)" "TRUE"
  $(warning OFFSET_CAL_ENABLE=$(OFFSET_CAL_ENABLE))
  ccflags-y += -DVL53L5_OFFSET_CAL
endif

ifeq "$(RANGE_SERVICING)" "WORKER"
ccflags-y += -DVL53L5_WORKER
endif

ifeq "$(BUILD_TYPE)" "DEBUG"
  $(warning BUILD_TYPE=$(BUILD_TYPE))
  ccflags-y += -DDEBUG
endif

ifeq "$(BUILD_TYPE)" "RELEASE"
  $(warning BUILD_TYPE=$(BUILD_TYPE))
endif


KERNEL_DRIVER_OBJS = \
			src/vl53l5_k_ioctl_controls.o \
			src/vl53l5_k_gpio_utils.o \
			src/vl53l5_k_error_converter.o \
			src/vl53l5_k_range_wait_handler.o \
			src/vl53l5_k_range_rotation.o

PLATFORM_OBJS =		platform/src/vl53l5_platform.o \
			platform/src/vl53l5_platform_init.o \
			platform/src/vl53l5_platform_log.o

BARE_DRIVER_OBJS = \
			bare_driver/api/src/vl53l5_api_core.o \
			bare_driver/api/src/vl53l5_api_power.o \
			bare_driver/api/src/vl53l5_api_ranging.o \
			bare_driver/api/src/vl53l5_api_range_decode.o \
			bare_driver/dci/src/vl53l5_core_decode.o\
			bare_driver/dci/src/vl53l5_calibration_decode.o\
			bare_driver/dci/src/vl53l5_dci_core.o \
			bare_driver/dci/src/vl53l5_dci_decode.o \
			bare_driver/dci/src/vl53l5_dci_helpers.o \
			bare_driver/dci/src/vl53l5_dci_ranging.o \
			bare_driver/dci/src/vl53l5_dci_utils.o \
			bare_driver/dci/src/vl53l5_decode_switch.o\
			bare_driver/dci/src/vl53l5_results_decode.o \
			bare_driver/common/src/vl53l5_checks.o \
			bare_driver/common/src/vl53l5_commands.o \
			bare_driver/common/src/vl53l5_error_handler.o \
			bare_driver/common/src/vl53l5_load_firmware.o \
			bare_driver/common/src/vl53l5_register_utils.o \
			bare_driver/common/src/vl53l5_rom_boot.o

SIMULATION_OBJS =	simulation/wrapper/vl53l5_api.o

ifeq "$(RANGE_SERVICING)" "INTERRUPT"
  $(warning RANGE_SERVICING=$(RANGE_SERVICING))
  ccflags-y	+= -DVL53L5_INTERRUPT
  KERNEL_DRIVER_OBJS += src/vl53l5_k_interrupt.o
endif

ifeq "$(RANGE_SERVICING)" "WORKER"
  $(warning RANGE_SERVICING=$(RANGE_SERVICING))
  ccflags-y	+= -DVL53L5_WORKER
  KERNEL_DRIVER_OBJS += src/vl53l5_k_work_handler.o
endif

ifeq "$(LOG_ENABLE)" "TRUE"
  $(warning LOG_ENABLE=$(LOG_ENABLE))
  ccflags-y += -DVL53L5_KERNEL_LOG

endif

ifeq "$(TCDM_DUMP_ENABLE)" "TRUE"
  $(warning TCDM_DUMP_ENABLE=$(TCDM_DUMP_ENABLE))
  ccflags-y += -DVL53L5_TCDM_DUMP
  BARE_DRIVER_OBJS += bare_driver/common/src/vl53l5_tcdm_dump.o
endif

ifeq "$(LEGACY_CODE)" "TRUE"
  $(warning LEGACY_CODE=$(LEGACY_CODE))
  ccflags-y += -DSTM_VL53L5_SUPPORT_LEGACY_CODE
endif

ifeq "$(TEST_ENABLE)" "TRUE"
  $(warning TEST_ENABLE=$(TEST_ENABLE))
  ccflags-y += -DVL53L5_TEST_ENABLE

endif

MODULE := vl53l5

obj-$(CONFIG_SENSORS_VL53L5)	+= $(MODULE).o
$(MODULE)-objs		:= src/vl53l5_k_module.o

# # Kernel level objects
$(MODULE)-objs	+= 	$(KERNEL_DRIVER_OBJS)

# Bare driver objects
$(MODULE)-objs +=	$(BARE_DRIVER_OBJS)
# Bare driver platform objects
$(MODULE)-objs +=	$(PLATFORM_OBJS)

all:
	make -C $(KDIR) M=$(PWD) modules

clean:
	make -C $(KDIR) M=$(PWD) clean

# Added any pre-insertion setup to this target. The primary usage is to unexport
# GPIO's from userspace so they are free for the kernel.
setup:
	-sudo echo ${GPIO_POWER_ENABLE} > /sys/class/gpio/unexport
	-sudo echo ${GPIO_LOW_POWER} > /sys/class/gpio/unexport
	-sudo echo ${GPIO_COMMS_SELECT} > /sys/class/gpio/unexport
ifeq "$(RANGE_SERVICING)" "INTERRUPT"
	-sudo echo ${GPIO_INTERRUPT} > /sys/class/gpio/unexport
endif

# Added any post-removal reset to this target. The primary usage is to export
# GPIO's to userspace after they are no longer required by the kernel so as to
# allow any userspace drivers/applications to interface to the device.
reset:
	-sudo echo ${GPIO_POWER_ENABLE} > /sys/class/gpio/export
	-sudo echo ${GPIO_LOW_POWER} > /sys/class/gpio/export
	-sudo echo ${GPIO_COMMS_SELECT} > /sys/class/gpio/export
ifeq "$(RANGE_SERVICING)" "INTERRUPT"
	-sudo echo ${GPIO_INTERRUPT} > /sys/class/gpio/export
endif

# Insert the module using insmod with the configured module parameters
insert:
	sudo insmod $(MODULE).ko

dtb:
	dtc -I dts -O dtb -o $(MODULE).dtb $(MODULE).dts
	sudo cp $(MODULE).dtb /boot/overlays/

clean_dtb:
	sudo rm $(MODULE).dtb
	sudo rm /boot/overlays/$(MODULE).dtb
# Remove the module using rmmod
remove:
	-sudo rmmod $(MODULE)