device: Const-ify all device driver instance pointers

Now that device_api attribute is unmodified at runtime, as well as all
the other attributes, it is possible to switch all device driver
instance to be constant.

A coccinelle rule is used for this:

@r_const_dev_1
  disable optional_qualifier
@
@@
-struct device *
+const struct device *

@r_const_dev_2
 disable optional_qualifier
@
@@
-struct device * const
+const struct device *

Fixes #27399

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
This commit is contained in:
Tomasz Bursztyka 2020-04-30 20:33:38 +02:00 committed by Carles Cufí
commit e18fcbba5a
1426 changed files with 9356 additions and 8368 deletions

View file

@ -42,7 +42,8 @@ LOG_MODULE_REGISTER(uart_stm32);
#define TIMEOUT 1000
static inline void uart_stm32_set_baudrate(struct device *dev, uint32_t baud_rate)
static inline void uart_stm32_set_baudrate(const struct device *dev,
uint32_t baud_rate)
{
const struct uart_stm32_config *config = DEV_CFG(dev);
struct uart_stm32_data *data = DEV_DATA(dev);
@ -85,56 +86,60 @@ static inline void uart_stm32_set_baudrate(struct device *dev, uint32_t baud_rat
#endif /* HAS_LPUART_1 */
}
static inline void uart_stm32_set_parity(struct device *dev, uint32_t parity)
static inline void uart_stm32_set_parity(const struct device *dev,
uint32_t parity)
{
USART_TypeDef *UartInstance = UART_STRUCT(dev);
LL_USART_SetParity(UartInstance, parity);
}
static inline uint32_t uart_stm32_get_parity(struct device *dev)
static inline uint32_t uart_stm32_get_parity(const struct device *dev)
{
USART_TypeDef *UartInstance = UART_STRUCT(dev);
return LL_USART_GetParity(UartInstance);
}
static inline void uart_stm32_set_stopbits(struct device *dev, uint32_t stopbits)
static inline void uart_stm32_set_stopbits(const struct device *dev,
uint32_t stopbits)
{
USART_TypeDef *UartInstance = UART_STRUCT(dev);
LL_USART_SetStopBitsLength(UartInstance, stopbits);
}
static inline uint32_t uart_stm32_get_stopbits(struct device *dev)
static inline uint32_t uart_stm32_get_stopbits(const struct device *dev)
{
USART_TypeDef *UartInstance = UART_STRUCT(dev);
return LL_USART_GetStopBitsLength(UartInstance);
}
static inline void uart_stm32_set_databits(struct device *dev, uint32_t databits)
static inline void uart_stm32_set_databits(const struct device *dev,
uint32_t databits)
{
USART_TypeDef *UartInstance = UART_STRUCT(dev);
LL_USART_SetDataWidth(UartInstance, databits);
}
static inline uint32_t uart_stm32_get_databits(struct device *dev)
static inline uint32_t uart_stm32_get_databits(const struct device *dev)
{
USART_TypeDef *UartInstance = UART_STRUCT(dev);
return LL_USART_GetDataWidth(UartInstance);
}
static inline void uart_stm32_set_hwctrl(struct device *dev, uint32_t hwctrl)
static inline void uart_stm32_set_hwctrl(const struct device *dev,
uint32_t hwctrl)
{
USART_TypeDef *UartInstance = UART_STRUCT(dev);
LL_USART_SetHWFlowCtrl(UartInstance, hwctrl);
}
static inline uint32_t uart_stm32_get_hwctrl(struct device *dev)
static inline uint32_t uart_stm32_get_hwctrl(const struct device *dev)
{
USART_TypeDef *UartInstance = UART_STRUCT(dev);
@ -277,7 +282,7 @@ static inline enum uart_config_flow_control uart_stm32_ll2cfg_hwctrl(uint32_t fc
return UART_CFG_FLOW_CTRL_NONE;
}
static int uart_stm32_configure(struct device *dev,
static int uart_stm32_configure(const struct device *dev,
const struct uart_config *cfg)
{
struct uart_stm32_data *data = DEV_DATA(dev);
@ -363,7 +368,8 @@ static int uart_stm32_configure(struct device *dev,
return 0;
};
static int uart_stm32_config_get(struct device *dev, struct uart_config *cfg)
static int uart_stm32_config_get(const struct device *dev,
struct uart_config *cfg)
{
struct uart_stm32_data *data = DEV_DATA(dev);
@ -378,7 +384,7 @@ static int uart_stm32_config_get(struct device *dev, struct uart_config *cfg)
return 0;
}
static int uart_stm32_poll_in(struct device *dev, unsigned char *c)
static int uart_stm32_poll_in(const struct device *dev, unsigned char *c)
{
USART_TypeDef *UartInstance = UART_STRUCT(dev);
@ -396,7 +402,7 @@ static int uart_stm32_poll_in(struct device *dev, unsigned char *c)
return 0;
}
static void uart_stm32_poll_out(struct device *dev,
static void uart_stm32_poll_out(const struct device *dev,
unsigned char c)
{
USART_TypeDef *UartInstance = UART_STRUCT(dev);
@ -410,7 +416,7 @@ static void uart_stm32_poll_out(struct device *dev,
LL_USART_TransmitData8(UartInstance, (uint8_t)c);
}
static int uart_stm32_err_check(struct device *dev)
static int uart_stm32_err_check(const struct device *dev)
{
USART_TypeDef *UartInstance = UART_STRUCT(dev);
uint32_t err = 0U;
@ -451,10 +457,10 @@ static int uart_stm32_err_check(struct device *dev)
return err;
}
static inline void __uart_stm32_get_clock(struct device *dev)
static inline void __uart_stm32_get_clock(const struct device *dev)
{
struct uart_stm32_data *data = DEV_DATA(dev);
struct device *clk =
const struct device *clk =
device_get_binding(STM32_CLOCK_CONTROL_NAME);
__ASSERT_NO_MSG(clk);
@ -464,7 +470,8 @@ static inline void __uart_stm32_get_clock(struct device *dev)
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
static int uart_stm32_fifo_fill(struct device *dev, const uint8_t *tx_data,
static int uart_stm32_fifo_fill(const struct device *dev,
const uint8_t *tx_data,
int size)
{
USART_TypeDef *UartInstance = UART_STRUCT(dev);
@ -481,7 +488,7 @@ static int uart_stm32_fifo_fill(struct device *dev, const uint8_t *tx_data,
return num_tx;
}
static int uart_stm32_fifo_read(struct device *dev, uint8_t *rx_data,
static int uart_stm32_fifo_read(const struct device *dev, uint8_t *rx_data,
const int size)
{
USART_TypeDef *UartInstance = UART_STRUCT(dev);
@ -503,56 +510,56 @@ static int uart_stm32_fifo_read(struct device *dev, uint8_t *rx_data,
return num_rx;
}
static void uart_stm32_irq_tx_enable(struct device *dev)
static void uart_stm32_irq_tx_enable(const struct device *dev)
{
USART_TypeDef *UartInstance = UART_STRUCT(dev);
LL_USART_EnableIT_TC(UartInstance);
}
static void uart_stm32_irq_tx_disable(struct device *dev)
static void uart_stm32_irq_tx_disable(const struct device *dev)
{
USART_TypeDef *UartInstance = UART_STRUCT(dev);
LL_USART_DisableIT_TC(UartInstance);
}
static int uart_stm32_irq_tx_ready(struct device *dev)
static int uart_stm32_irq_tx_ready(const struct device *dev)
{
USART_TypeDef *UartInstance = UART_STRUCT(dev);
return LL_USART_IsActiveFlag_TXE(UartInstance);
}
static int uart_stm32_irq_tx_complete(struct device *dev)
static int uart_stm32_irq_tx_complete(const struct device *dev)
{
USART_TypeDef *UartInstance = UART_STRUCT(dev);
return LL_USART_IsActiveFlag_TC(UartInstance);
}
static void uart_stm32_irq_rx_enable(struct device *dev)
static void uart_stm32_irq_rx_enable(const struct device *dev)
{
USART_TypeDef *UartInstance = UART_STRUCT(dev);
LL_USART_EnableIT_RXNE(UartInstance);
}
static void uart_stm32_irq_rx_disable(struct device *dev)
static void uart_stm32_irq_rx_disable(const struct device *dev)
{
USART_TypeDef *UartInstance = UART_STRUCT(dev);
LL_USART_DisableIT_RXNE(UartInstance);
}
static int uart_stm32_irq_rx_ready(struct device *dev)
static int uart_stm32_irq_rx_ready(const struct device *dev)
{
USART_TypeDef *UartInstance = UART_STRUCT(dev);
return LL_USART_IsActiveFlag_RXNE(UartInstance);
}
static void uart_stm32_irq_err_enable(struct device *dev)
static void uart_stm32_irq_err_enable(const struct device *dev)
{
USART_TypeDef *UartInstance = UART_STRUCT(dev);
@ -568,7 +575,7 @@ static void uart_stm32_irq_err_enable(struct device *dev)
LL_USART_EnableIT_PE(UartInstance);
}
static void uart_stm32_irq_err_disable(struct device *dev)
static void uart_stm32_irq_err_disable(const struct device *dev)
{
USART_TypeDef *UartInstance = UART_STRUCT(dev);
@ -584,7 +591,7 @@ static void uart_stm32_irq_err_disable(struct device *dev)
LL_USART_DisableIT_PE(UartInstance);
}
static int uart_stm32_irq_is_pending(struct device *dev)
static int uart_stm32_irq_is_pending(const struct device *dev)
{
USART_TypeDef *UartInstance = UART_STRUCT(dev);
@ -594,12 +601,12 @@ static int uart_stm32_irq_is_pending(struct device *dev)
LL_USART_IsEnabledIT_TC(UartInstance)));
}
static int uart_stm32_irq_update(struct device *dev)
static int uart_stm32_irq_update(const struct device *dev)
{
return 1;
}
static void uart_stm32_irq_callback_set(struct device *dev,
static void uart_stm32_irq_callback_set(const struct device *dev,
uart_irq_callback_user_data_t cb,
void *cb_data)
{
@ -611,7 +618,7 @@ static void uart_stm32_irq_callback_set(struct device *dev,
static void uart_stm32_isr(void *arg)
{
struct device *dev = arg;
const struct device *dev = arg;
struct uart_stm32_data *data = DEV_DATA(dev);
if (data->user_cb) {
@ -655,7 +662,7 @@ static const struct uart_driver_api uart_stm32_driver_api = {
*
* @return 0
*/
static int uart_stm32_init(struct device *dev)
static int uart_stm32_init(const struct device *dev)
{
const struct uart_stm32_config *config = DEV_CFG(dev);
struct uart_stm32_data *data = DEV_DATA(dev);
@ -737,7 +744,7 @@ static int uart_stm32_init(struct device *dev)
#define STM32_UART_IRQ_HANDLER_FUNC(index) \
.irq_config_func = uart_stm32_irq_config_func_##index,
#define STM32_UART_IRQ_HANDLER(index) \
static void uart_stm32_irq_config_func_##index(struct device *dev) \
static void uart_stm32_irq_config_func_##index(const struct device *dev) \
{ \
IRQ_CONNECT(DT_INST_IRQN(index), \
DT_INST_IRQ(index, priority), \