drivers: usb: usb_dc_sam: Convert to DT_INST macros
Convert driver to use new DT_INST macros throughout. We also remove defines in dts_fixup.h as they are no longer needed. Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
This commit is contained in:
parent
86137c3a62
commit
085747e5fb
3 changed files with 36 additions and 42 deletions
|
@ -4,6 +4,8 @@
|
|||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#define DT_DRV_COMPAT atmel_sam_usbhs
|
||||
|
||||
#include <usb/usb_device.h>
|
||||
#include <soc.h>
|
||||
#include <string.h>
|
||||
|
@ -47,6 +49,11 @@ LOG_MODULE_REGISTER(usb_dc_sam);
|
|||
#define EP_ADDR2IDX(ep) ((ep) & ~USB_EP_DIR_MASK)
|
||||
#define EP_ADDR2DIR(ep) ((ep) & USB_EP_DIR_MASK)
|
||||
|
||||
#define NUM_OF_EP_MAX DT_INST_PROP(0, num_bidir_endpoints)
|
||||
#if DT_INST_NODE_HAS_PROP(0, maximum_speed)
|
||||
#define USB_MAXIMUM_SPEED DT_INST_PROP(0, maximum_speed)
|
||||
#endif
|
||||
|
||||
struct usb_device_ep_data {
|
||||
u16_t mps;
|
||||
usb_dc_ep_callback cb_in;
|
||||
|
@ -57,7 +64,7 @@ struct usb_device_ep_data {
|
|||
struct usb_device_data {
|
||||
bool addr_enabled;
|
||||
usb_dc_status_callback status_cb;
|
||||
struct usb_device_ep_data ep_data[DT_USBHS_NUM_BIDIR_EP];
|
||||
struct usb_device_ep_data ep_data[NUM_OF_EP_MAX];
|
||||
};
|
||||
|
||||
static struct usb_device_data dev_data;
|
||||
|
@ -279,7 +286,7 @@ static void usb_dc_isr(void)
|
|||
}
|
||||
|
||||
/* Other endpoints interrupt */
|
||||
for (int ep_idx = 1; ep_idx < DT_USBHS_NUM_BIDIR_EP; ep_idx++) {
|
||||
for (int ep_idx = 1; ep_idx < NUM_OF_EP_MAX; ep_idx++) {
|
||||
if (sr & BIT(USBHS_DEVISR_PEP_0_Pos + ep_idx)) {
|
||||
usb_dc_ep_isr(ep_idx);
|
||||
}
|
||||
|
@ -292,7 +299,7 @@ int usb_dc_attach(void)
|
|||
u32_t regval;
|
||||
|
||||
/* Start the peripheral clock */
|
||||
soc_pmc_peripheral_enable(DT_USBHS_PERIPHERAL_ID);
|
||||
soc_pmc_peripheral_enable(DT_INST_PROP(0, peripheral_id));
|
||||
|
||||
/* Enable the USB controller in device mode with the clock frozen */
|
||||
USBHS->USBHS_CTRL = USBHS_CTRL_UIMOD | USBHS_CTRL_USBE |
|
||||
|
@ -301,12 +308,12 @@ int usb_dc_attach(void)
|
|||
|
||||
/* Select the speed */
|
||||
regval = USBHS_DEVCTRL_DETACH;
|
||||
#ifdef DT_USBHS_MAXIMUM_SPEED
|
||||
if (!strncmp(DT_USBHS_MAXIMUM_SPEED, "high-speed", 10)) {
|
||||
#ifdef USB_MAXIMUM_SPEED
|
||||
if (!strncmp(USB_MAXIMUM_SPEED, "high-speed", 10)) {
|
||||
regval |= USBHS_DEVCTRL_SPDCONF_NORMAL;
|
||||
} else if (!strncmp(DT_USBHS_MAXIMUM_SPEED, "full-speed", 10)) {
|
||||
} else if (!strncmp(USB_MAXIMUM_SPEED, "full-speed", 10)) {
|
||||
regval |= USBHS_DEVCTRL_SPDCONF_LOW_POWER;
|
||||
} else if (!strncmp(DT_USBHS_MAXIMUM_SPEED, "low-speed", 9)) {
|
||||
} else if (!strncmp(USB_MAXIMUM_SPEED, "low-speed", 9)) {
|
||||
regval |= USBHS_DEVCTRL_LS;
|
||||
regval |= USBHS_DEVCTRL_SPDCONF_LOW_POWER;
|
||||
} else {
|
||||
|
@ -317,7 +324,7 @@ int usb_dc_attach(void)
|
|||
}
|
||||
#else
|
||||
regval |= USBHS_DEVCTRL_SPDCONF_NORMAL;
|
||||
#endif /* DT_USBHS_MAXIMUM_SPEED */
|
||||
#endif /* USB_MAXIMUM_SPEED */
|
||||
USBHS->USBHS_DEVCTRL = regval;
|
||||
|
||||
/* Enable the USB clock */
|
||||
|
@ -335,8 +342,9 @@ int usb_dc_attach(void)
|
|||
#endif
|
||||
|
||||
/* Connect and enable the interrupt */
|
||||
IRQ_CONNECT(DT_USBHS_IRQ, DT_USBHS_IRQ_PRI, usb_dc_isr, 0, 0);
|
||||
irq_enable(DT_USBHS_IRQ);
|
||||
IRQ_CONNECT(DT_INST_IRQN(0), DT_INST_IRQ(0, priority),
|
||||
usb_dc_isr, 0, 0);
|
||||
irq_enable(DT_INST_IRQN(0));
|
||||
|
||||
/* Attach the device */
|
||||
USBHS->USBHS_DEVCTRL &= ~USBHS_DEVCTRL_DETACH;
|
||||
|
@ -358,10 +366,10 @@ int usb_dc_detach(void)
|
|||
USBHS->USBHS_CTRL = USBHS_CTRL_UIMOD | USBHS_CTRL_FRZCLK;
|
||||
|
||||
/* Disable the peripheral clock */
|
||||
soc_pmc_peripheral_enable(DT_USBHS_PERIPHERAL_ID);
|
||||
soc_pmc_peripheral_enable(DT_INST_PROP(0, peripheral_id));
|
||||
|
||||
/* Disable interrupt */
|
||||
irq_disable(DT_USBHS_IRQ);
|
||||
irq_disable(DT_INST_IRQN(0));
|
||||
|
||||
LOG_DBG("");
|
||||
return 0;
|
||||
|
@ -407,7 +415,7 @@ int usb_dc_ep_check_cap(const struct usb_dc_ep_cfg_data * const cfg)
|
|||
{
|
||||
u8_t ep_idx = EP_ADDR2IDX(cfg->ep_addr);
|
||||
|
||||
if (ep_idx >= DT_USBHS_NUM_BIDIR_EP) {
|
||||
if (ep_idx >= NUM_OF_EP_MAX) {
|
||||
LOG_ERR("endpoint index/address out of range");
|
||||
return -1;
|
||||
}
|
||||
|
@ -442,8 +450,8 @@ int usb_dc_ep_check_cap(const struct usb_dc_ep_cfg_data * const cfg)
|
|||
int usb_dc_ep_configure(const struct usb_dc_ep_cfg_data *const cfg)
|
||||
{
|
||||
u8_t ep_idx = EP_ADDR2IDX(cfg->ep_addr);
|
||||
bool ep_configured[DT_USBHS_NUM_BIDIR_EP];
|
||||
bool ep_enabled[DT_USBHS_NUM_BIDIR_EP];
|
||||
bool ep_configured[NUM_OF_EP_MAX];
|
||||
bool ep_enabled[NUM_OF_EP_MAX];
|
||||
u32_t regval = 0U;
|
||||
int log2ceil_mps;
|
||||
|
||||
|
@ -518,7 +526,7 @@ int usb_dc_ep_configure(const struct usb_dc_ep_cfg_data *const cfg)
|
|||
* enabled, deallocate their memory if needed. Then loop again through
|
||||
* all the above endpoints to allocate and enabled them.
|
||||
*/
|
||||
for (int i = DT_USBHS_NUM_BIDIR_EP - 1; i > ep_idx; i--) {
|
||||
for (int i = NUM_OF_EP_MAX - 1; i > ep_idx; i--) {
|
||||
ep_configured[i] = usb_dc_ep_is_configured(i);
|
||||
ep_enabled[i] = usb_dc_ep_is_enabled(i);
|
||||
|
||||
|
@ -531,7 +539,7 @@ int usb_dc_ep_configure(const struct usb_dc_ep_cfg_data *const cfg)
|
|||
}
|
||||
ep_configured[ep_idx] = true;
|
||||
ep_enabled[ep_idx] = false;
|
||||
for (int i = ep_idx; i < DT_USBHS_NUM_BIDIR_EP; i++) {
|
||||
for (int i = ep_idx; i < NUM_OF_EP_MAX; i++) {
|
||||
if (ep_configured[i]) {
|
||||
USBHS->USBHS_DEVEPTCFG[i] |= USBHS_DEVEPTCFG_ALLOC;
|
||||
}
|
||||
|
@ -554,7 +562,7 @@ int usb_dc_ep_set_stall(u8_t ep)
|
|||
{
|
||||
u8_t ep_idx = EP_ADDR2IDX(ep);
|
||||
|
||||
if (ep_idx >= DT_USBHS_NUM_BIDIR_EP) {
|
||||
if (ep_idx >= NUM_OF_EP_MAX) {
|
||||
LOG_ERR("wrong endpoint index/address");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
@ -570,7 +578,7 @@ int usb_dc_ep_clear_stall(u8_t ep)
|
|||
{
|
||||
u8_t ep_idx = EP_ADDR2IDX(ep);
|
||||
|
||||
if (ep_idx >= DT_USBHS_NUM_BIDIR_EP) {
|
||||
if (ep_idx >= NUM_OF_EP_MAX) {
|
||||
LOG_ERR("wrong endpoint index/address");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
@ -586,7 +594,7 @@ int usb_dc_ep_is_stalled(u8_t ep, u8_t *stalled)
|
|||
{
|
||||
u8_t ep_idx = EP_ADDR2IDX(ep);
|
||||
|
||||
if (ep_idx >= DT_USBHS_NUM_BIDIR_EP) {
|
||||
if (ep_idx >= NUM_OF_EP_MAX) {
|
||||
LOG_ERR("wrong endpoint index/address");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
@ -613,7 +621,7 @@ int usb_dc_ep_enable(u8_t ep)
|
|||
{
|
||||
u8_t ep_idx = EP_ADDR2IDX(ep);
|
||||
|
||||
if (ep_idx >= DT_USBHS_NUM_BIDIR_EP) {
|
||||
if (ep_idx >= NUM_OF_EP_MAX) {
|
||||
LOG_ERR("wrong endpoint index/address");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
@ -641,7 +649,7 @@ int usb_dc_ep_disable(u8_t ep)
|
|||
{
|
||||
u8_t ep_idx = EP_ADDR2IDX(ep);
|
||||
|
||||
if (ep_idx >= DT_USBHS_NUM_BIDIR_EP) {
|
||||
if (ep_idx >= NUM_OF_EP_MAX) {
|
||||
LOG_ERR("wrong endpoint index/address");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
@ -661,7 +669,7 @@ int usb_dc_ep_flush(u8_t ep)
|
|||
{
|
||||
u8_t ep_idx = EP_ADDR2IDX(ep);
|
||||
|
||||
if (ep_idx >= DT_USBHS_NUM_BIDIR_EP) {
|
||||
if (ep_idx >= NUM_OF_EP_MAX) {
|
||||
LOG_ERR("wrong endpoint index/address");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
@ -700,7 +708,7 @@ int usb_dc_ep_write(u8_t ep, const u8_t *data, u32_t data_len, u32_t *ret_bytes)
|
|||
u8_t ep_idx = EP_ADDR2IDX(ep);
|
||||
u32_t packet_len;
|
||||
|
||||
if (ep_idx >= DT_USBHS_NUM_BIDIR_EP) {
|
||||
if (ep_idx >= NUM_OF_EP_MAX) {
|
||||
LOG_ERR("wrong endpoint index/address");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
@ -785,7 +793,7 @@ int usb_dc_ep_set_callback(u8_t ep, const usb_dc_ep_callback cb)
|
|||
{
|
||||
u8_t ep_idx = EP_ADDR2IDX(ep);
|
||||
|
||||
if (ep_idx >= DT_USBHS_NUM_BIDIR_EP) {
|
||||
if (ep_idx >= NUM_OF_EP_MAX) {
|
||||
LOG_ERR("wrong endpoint index/address");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
@ -808,7 +816,7 @@ int usb_dc_ep_read_wait(u8_t ep, u8_t *data, u32_t max_data_len,
|
|||
u32_t data_len = (USBHS->USBHS_DEVEPTISR[ep_idx] &
|
||||
USBHS_DEVEPTISR_BYCT_Msk) >> USBHS_DEVEPTISR_BYCT_Pos;
|
||||
|
||||
if (ep_idx >= DT_USBHS_NUM_BIDIR_EP) {
|
||||
if (ep_idx >= NUM_OF_EP_MAX) {
|
||||
LOG_ERR("wrong endpoint index/address");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
@ -864,7 +872,7 @@ int usb_dc_ep_read_continue(u8_t ep)
|
|||
{
|
||||
u8_t ep_idx = EP_ADDR2IDX(ep);
|
||||
|
||||
if (ep_idx >= DT_USBHS_NUM_BIDIR_EP) {
|
||||
if (ep_idx >= NUM_OF_EP_MAX) {
|
||||
LOG_ERR("wrong endpoint index/address");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
@ -904,7 +912,7 @@ int usb_dc_ep_mps(u8_t ep)
|
|||
{
|
||||
u8_t ep_idx = EP_ADDR2IDX(ep);
|
||||
|
||||
if (ep_idx >= DT_USBHS_NUM_BIDIR_EP) {
|
||||
if (ep_idx >= NUM_OF_EP_MAX) {
|
||||
LOG_ERR("wrong endpoint index/address");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
|
|
@ -34,13 +34,6 @@
|
|||
#define DT_ADC_1_NAME DT_ATMEL_SAM_AFEC_40064000_LABEL
|
||||
#define DT_ADC_1_PERIPHERAL_ID DT_ATMEL_SAM_AFEC_40064000_PERIPHERAL_ID
|
||||
|
||||
#define DT_USBHS_IRQ DT_ATMEL_SAM_USBHS_40038000_IRQ_0
|
||||
#define DT_USBHS_IRQ_PRI DT_ATMEL_SAM_USBHS_40038000_IRQ_0_PRIORITY
|
||||
#define DT_USBHS_MAXIMUM_SPEED DT_ATMEL_SAM_USBHS_40038000_MAXIMUM_SPEED
|
||||
#define DT_USBHS_NUM_BIDIR_EP DT_ATMEL_SAM_USBHS_40038000_NUM_BIDIR_ENDPOINTS
|
||||
#define DT_USBHS_PERIPHERAL_ID DT_ATMEL_SAM_USBHS_40038000_PERIPHERAL_ID
|
||||
#define DT_USBHS_RAM_BASE_ADDRESS DT_ATMEL_SAM_USBHS_40038000_RAM_0
|
||||
|
||||
#define DT_FLASH_DEV_BASE_ADDRESS DT_ATMEL_SAM_FLASH_CONTROLLER_400E0C00_BASE_ADDRESS
|
||||
#define DT_FLASH_DEV_NAME DT_ATMEL_SAM_FLASH_CONTROLLER_400E0C00_LABEL
|
||||
|
||||
|
|
|
@ -38,13 +38,6 @@
|
|||
#define DT_ADC_1_NAME DT_ATMEL_SAM_AFEC_40064000_LABEL
|
||||
#define DT_ADC_1_PERIPHERAL_ID DT_ATMEL_SAM_AFEC_40064000_PERIPHERAL_ID
|
||||
|
||||
#define DT_USBHS_IRQ DT_ATMEL_SAM_USBHS_40038000_IRQ_0
|
||||
#define DT_USBHS_IRQ_PRI DT_ATMEL_SAM_USBHS_40038000_IRQ_0_PRIORITY
|
||||
#define DT_USBHS_MAXIMUM_SPEED DT_ATMEL_SAM_USBHS_40038000_MAXIMUM_SPEED
|
||||
#define DT_USBHS_NUM_BIDIR_EP DT_ATMEL_SAM_USBHS_40038000_NUM_BIDIR_ENDPOINTS
|
||||
#define DT_USBHS_PERIPHERAL_ID DT_ATMEL_SAM_USBHS_40038000_PERIPHERAL_ID
|
||||
#define DT_USBHS_RAM_BASE_ADDRESS DT_ATMEL_SAM_USBHS_40038000_RAM_0
|
||||
|
||||
#define DT_FLASH_DEV_BASE_ADDRESS DT_ATMEL_SAM_FLASH_CONTROLLER_400E0C00_BASE_ADDRESS
|
||||
#define DT_FLASH_DEV_NAME DT_ATMEL_SAM_FLASH_CONTROLLER_400E0C00_LABEL
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue