- 
                Notifications
    
You must be signed in to change notification settings  - Fork 8.2k
 
Atmel SAM: Introduce SMC driver #42739
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Merged
      
      
    
  
     Merged
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            6 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      f254a53
              
                soc: arm: atmel_sam: sam4s: add support for sam4sa16c
              
              
                pdgendt 3876142
              
                drivers: memc: Introduce Atmel SAM SMC/EBI driver
              
              
                pdgendt 634fbd7
              
                dts: sam4s: Add SMC peripheral
              
              
                pdgendt 6ea2196
              
                dts: sam4e: Add SMC peripheral
              
              
                pdgendt d40f544
              
                boards: arm: sam4s_xplained: Enable SRAM on SMC bus
              
              
                pdgendt d398163
              
                tests: drivers: memc: Rework S(D)RAM test with ztest
              
              
                pdgendt File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -8,6 +8,7 @@ toolchain: | |
| - xtools | ||
| supported: | ||
| - gpio | ||
| - memc | ||
| - spi | ||
| - watchdog | ||
| - xplained_gpio | ||
| 
          
            
          
           | 
    ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -25,4 +25,6 @@ source "drivers/memc/Kconfig.stm32" | |
| 
     | 
||
| source "drivers/memc/Kconfig.mcux" | ||
| 
     | 
||
| source "drivers/memc/Kconfig.sam" | ||
| 
     | 
||
| endif | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| # Copyright (c) 2022 Basalte bv | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
                
      
                  pdgendt marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
         | 
||
| 
     | 
||
| config MEMC_SAM_SMC | ||
| bool "Atmel Static Memory Controller (SMC)" | ||
| default y | ||
| depends on DT_HAS_ATMEL_SAM_SMC_ENABLED | ||
| help | ||
| Enable Atmel Static Memory Controller. | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| /* | ||
| * Copyright (c) 2022 Basalte bv | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
| 
     | 
||
| #define DT_DRV_COMPAT atmel_sam_smc | ||
| 
     | 
||
| #include <zephyr/device.h> | ||
| #include <zephyr/drivers/pinctrl.h> | ||
| #include <soc.h> | ||
| 
     | 
||
| #include <zephyr/logging/log.h> | ||
| LOG_MODULE_REGISTER(memc_sam, CONFIG_MEMC_LOG_LEVEL); | ||
| 
     | 
||
| struct memc_smc_bank_config { | ||
| uint32_t cs; | ||
| uint32_t mode; | ||
| uint32_t setup_timing; | ||
| uint32_t pulse_timing; | ||
| uint32_t cycle_timing; | ||
| }; | ||
| 
     | 
||
| struct memc_smc_config { | ||
| Smc *regs; | ||
| uint32_t periph_id; | ||
| 
     | 
||
| size_t banks_len; | ||
| const struct memc_smc_bank_config *banks; | ||
| 
     | 
||
| const struct pinctrl_dev_config *pcfg; | ||
| }; | ||
| 
     | 
||
| static int memc_smc_init(const struct device *dev) | ||
| { | ||
| int ret; | ||
| const struct memc_smc_config *cfg = dev->config; | ||
| SmcCs_number *bank; | ||
| 
     | 
||
| soc_pmc_peripheral_enable(cfg->periph_id); | ||
| 
     | 
||
| ret = pinctrl_apply_state(cfg->pcfg, PINCTRL_STATE_DEFAULT); | ||
| if (ret < 0) { | ||
| return ret; | ||
| } | ||
| 
     | 
||
| for (size_t i = 0U; i < cfg->banks_len; i++) { | ||
| if (cfg->banks[i].cs >= SMCCS_NUMBER_NUMBER) { | ||
| return -EINVAL; | ||
| } | ||
| 
     | 
||
| bank = &cfg->regs->SMC_CS_NUMBER[cfg->banks[i].cs]; | ||
| 
     | 
||
| bank->SMC_SETUP = cfg->banks[i].setup_timing; | ||
| bank->SMC_PULSE = cfg->banks[i].pulse_timing; | ||
| bank->SMC_CYCLE = cfg->banks[i].cycle_timing; | ||
| bank->SMC_MODE = cfg->banks[i].mode; | ||
| } | ||
| 
     | 
||
| return 0; | ||
| } | ||
| 
     | 
||
| #define SETUP_TIMING(node_id) \ | ||
| SMC_SETUP_NWE_SETUP(DT_PROP_BY_IDX(node_id, atmel_smc_setup_timing, 0)) \ | ||
| | SMC_SETUP_NCS_WR_SETUP(DT_PROP_BY_IDX(node_id, atmel_smc_setup_timing, 1)) \ | ||
| | SMC_SETUP_NRD_SETUP(DT_PROP_BY_IDX(node_id, atmel_smc_setup_timing, 2)) \ | ||
| | SMC_SETUP_NCS_RD_SETUP(DT_PROP_BY_IDX(node_id, atmel_smc_setup_timing, 3)) | ||
| #define PULSE_TIMING(node_id) \ | ||
| SMC_PULSE_NWE_PULSE(DT_PROP_BY_IDX(node_id, atmel_smc_pulse_timing, 0)) \ | ||
| | SMC_PULSE_NCS_WR_PULSE(DT_PROP_BY_IDX(node_id, atmel_smc_pulse_timing, 1)) \ | ||
| | SMC_PULSE_NRD_PULSE(DT_PROP_BY_IDX(node_id, atmel_smc_pulse_timing, 2)) \ | ||
| | SMC_PULSE_NCS_RD_PULSE(DT_PROP_BY_IDX(node_id, atmel_smc_pulse_timing, 3)) | ||
| #define CYCLE_TIMING(node_id) \ | ||
| SMC_CYCLE_NWE_CYCLE(DT_PROP_BY_IDX(node_id, atmel_smc_cycle_timing, 0)) \ | ||
| | SMC_CYCLE_NRD_CYCLE(DT_PROP_BY_IDX(node_id, atmel_smc_cycle_timing, 1)) | ||
| 
     | 
||
| #define BANK_CONFIG(node_id) \ | ||
| { \ | ||
| .cs = DT_REG_ADDR(node_id), \ | ||
| .mode = COND_CODE_1(DT_ENUM_IDX(node_id, atmel_smc_write_mode), \ | ||
| (SMC_MODE_WRITE_MODE), (0)) \ | ||
| | COND_CODE_1(DT_ENUM_IDX(node_id, atmel_smc_read_mode), \ | ||
| (SMC_MODE_READ_MODE), (0)), \ | ||
| .setup_timing = SETUP_TIMING(node_id), \ | ||
| .pulse_timing = PULSE_TIMING(node_id), \ | ||
| .cycle_timing = CYCLE_TIMING(node_id), \ | ||
| }, | ||
| 
     | 
||
| #define MEMC_SMC_DEFINE(inst) \ | ||
| static const struct memc_smc_bank_config smc_bank_config_##inst[] = { \ | ||
| DT_INST_FOREACH_CHILD(inst, BANK_CONFIG) \ | ||
| }; \ | ||
| PINCTRL_DT_INST_DEFINE(inst); \ | ||
| static const struct memc_smc_config smc_config_##inst = { \ | ||
| .regs = (Smc *)DT_INST_REG_ADDR(inst), \ | ||
| .periph_id = DT_INST_PROP(inst, peripheral_id), \ | ||
| .banks_len = ARRAY_SIZE(smc_bank_config_##inst), \ | ||
| .banks = smc_bank_config_##inst, \ | ||
| .pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(inst), \ | ||
| }; \ | ||
| DEVICE_DT_INST_DEFINE(inst, memc_smc_init, NULL, NULL, \ | ||
| &smc_config_##inst, POST_KERNEL, \ | ||
| CONFIG_MEMC_INIT_PRIORITY, NULL); | ||
| 
     | 
||
| DT_INST_FOREACH_STATUS_OKAY(MEMC_SMC_DEFINE) | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| /* | ||
| * Copyright (c) 2022 Basalte bv | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
| 
     | 
||
| #include <mem.h> | ||
| #include <atmel/sam4s.dtsi> | ||
| 
     | 
||
| / { | ||
| soc { | ||
| flash-controller@400e0a00 { | ||
| flash0: flash@400000 { | ||
| reg = <0x00400000 DT_SIZE_K(1024)>; | ||
| }; | ||
| }; | ||
| 
     | 
||
| sram0: memory@20100000 { | ||
| reg = <0x20100000 DT_SIZE_K(160)>; | ||
| }; | ||
| }; | ||
| }; | 
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.