SlideShare ist ein Scribd-Unternehmen logo
1 von 21
Downloaden Sie, um offline zu lesen
regmap
                                          The power of subsystems and abstractions




1   © 2012 Wolfson Microelectronics plc                      November 2012   www.wolfsonmicro.com
Overview

    •    The quality of the subsystems is key to Linux
           •    Factor common code out of drivers
           •    Simplify driver development
           •    Encourage best practice
           •    Maximise the impact of features


    •    regmap provides a good case study
           •    Register I/O for I2C and SPI
           •    Originally in ASoC for audio CODECs
           •    Traditionally open coded in drivers
           •    Now provides benefits for totally different device classes
           •    Nothing like it in other operating systems



2   © 2012 Wolfson Microelectronics plc                        November 2012   www.wolfsonmicro.com
In the beginning…

•       ASoC CODEC drivers need to provide configuration to users
•       Saw that there were lots of register bitfields like:
        •    R0 INL_VOL [5:0]: Left input PGA Volume -23.25dB to +24.00dB in 0.75dB
             steps
        •    R1 INR_VOL [5:0]: Right input PGA Volume -23.25dB to +24.00dB in 0.75dB
             steps
•       Factored this out into standard helpers for drivers:
        •    SOC_DOUBLE_R_TLV("Capture Volume",
             WM8962_LEFT_INPUT_VOLUME,
             WM8962_RIGHT_INPUT_VOLUME, 0, 63, 0, inpga_tlv),
        •    Supported with CODEC callbacks:
              • int read(struct snd_soc_codec *codec, int reg);
              • int write(struct snd_soc_codec *codec, int reg, int value);



    3   © 2012 Wolfson Microelectronics plc                  November 2012   www.wolfsonmicro.com
Quick wins

    •    Save some boilerplate
    •    Simple factor out of one very common operation
           •    snd_soc_update_bits(struct snd_soc_codec *codec, int reg,
                int mask, int val);

    •    Can suppress no op changes
    •    Make best practice clear and obvious




4   © 2012 Wolfson Microelectronics plc                November 2012   www.wolfsonmicro.com
Register dumps

    •    Using:
           •    Register read and write operations
           •    Ideally also the maximum register address
    •    The subsystem can provide register dumps as a standard
         feature:
           0000: abcd
           0001: 5e32


    •    Common output format
    •    Support for reading only specific registers
    •    Write support
    •    Enabled by previous factoring out

5   © 2012 Wolfson Microelectronics plc                     November 2012   www.wolfsonmicro.com
Register caches

    •    Had been open coded in drivers

    •    Layered in with a little bit more data
           •    Register default values
           •    Volatile registers


    •    Really nice feature
           •    Many devices don’t support readback
           •    Performance improvement
           •    Simplifies suspend and resume




6   © 2012 Wolfson Microelectronics plc               November 2012   www.wolfsonmicro.com
Physical I/O

    •    The hardware interface is very consistent over devices:

           SCLK


            SDA            D7          D1    R/W              A6             A0   B8         B7              B1       B0



                   START        device ID   (Write)    ACK     register address   B8   ACK        data bits B7 – B0        ACK     STOP



                                                      Note: The SDA pin is used as input for the control register address and data; SDA
                                                       is pulled low by the receiving device to provide the acknowledge (ACK) response



           •      Register followed by value, big endian
    •    Standard implementation of read and write
    •    Subsystem ensures all drivers get the fiddly bits right
           •      Byte swapping
           •      Interoperability with controller features
           •      Performance tricks

7   © 2012 Wolfson Microelectronics plc                                                                    November 2012         www.wolfsonmicro.com
Factoring out regmap

    •    These patterns are present in many other devices
           •    PMICs
           •    Input controllers
           •    GPIO expanders
    •    Move the code out of ASoC
           •    drivers/base/regmap
    •    Gradual merge
           •    v3.1: simple register I/O functionality for I2C and SPI
           •    v3.2: caches, tracepoints and debugfs




8   © 2012 Wolfson Microelectronics plc                          November 2012   www.wolfsonmicro.com
Device description

    struct        regmap_config {
       int        reg_bits;
       int        pad_bits;
       int        val_bits;

          bool      (*writeable_reg)(struct device *dev, unsigned int reg);
          bool      (*readable_reg)(struct device *dev, unsigned int reg);
          bool      (*volatile_reg)(struct device *dev, unsigned int reg);
          bool      (*precious_reg)(struct device *dev, unsigned int reg);

          unsigned int max_register;
          const struct reg_default *reg_defaults;
          unsigned int num_reg_defaults;
    };




9   © 2012 Wolfson Microelectronics plc                  November 2012   www.wolfsonmicro.com
Core API

     struct regmap *devm_regmap_init_i2c(struct i2c_client *i2c,
                                const struct regmap_config *config);

     int regmap_read(struct regmap *map, unsigned int reg,
                     unsigned int *val);
     int regmap_write(struct regmap *map, unsigned int reg,
                      unsigned int val);
     int regmap_update_bits(struct regmap *map, unsigned int reg,
                            unsigned int mask, unsigned int val);

     int regcache_sync(struct regmap *map);
     void regcache_cache_only(struct regmap *map, bool enable);
     void regcache_mark_dirty(struct regmap *map);




10   © 2012 Wolfson Microelectronics plc          November 2012   www.wolfsonmicro.com
Complex register caches

     •    Initially caches just used a flat array
     •    Not so good when caching devices with 32 bit addresses
     •    Solved with better cache types
            •    rbtree stores blocks of contiguous registers in a red/black tree (436
                 lines)
            •    Compressed stores blocks of compressed data (380 lines)
     •    Both rely on existing kernel libraries

                    enum regcache_type cache_type;




11   © 2012 Wolfson Microelectronics plc                         November 2012   www.wolfsonmicro.com
Tracepoints/Logging

     •    Simple, low overhead logging subsystem
     •    Can be built in all the time and running all the time
     •    Standard format allows reusable tooling in userspace
     •    Key tracepoints for regmap:
            •    regmap_reg_write 0-001a reg=1a val=3c
            •    regmap_reg_read 0-001a reg=1 val=3c


     •    See more in debugfs/trace/events/regmap/

     •    Also a simple define LOG_DEVICE for early init logging



12   © 2012 Wolfson Microelectronics plc                 November 2012   www.wolfsonmicro.com
Register patches

     •    Magic register writes done at device startup
            •    Performance tuning
            •    Workarounds
     •    Integrated into cache sync

     int regmap_register_patch(struct regmap *map,
           const struct reg_default *regs,
           int num_regs);




13   © 2012 Wolfson Microelectronics plc           November 2012   www.wolfsonmicro.com
Paging support

     •    Common hardware pattern, adds another level of
          addressing
     •    Supported in regmap by creating virtual registers
     •    Standard interface allows upper level code to ignore
          paging

     struct regmap_range_cfg {
            const char *name;
            unsigned int range_min; unsigned int range_max;
            unsigned int selector_reg; unsigned int selector_mask;
            int selector_shift;
            unsigned int window_start; unsigned int window_len;
     };




14   © 2012 Wolfson Microelectronics plc           November 2012   www.wolfsonmicro.com
MMIO support

     •    Cache and diagnostic infrastructure isn’t just useful to I2C
          and SPI
     •    Allows really simple integration with runtime PM




15   © 2012 Wolfson Microelectronics plc             November 2012   www.wolfsonmicro.com
Interrupt controller

     •    Common patterns in interrupt controllers
            •    Status register
            •    Mask register
     •    Lots of fiddly stuff with interrupt core due to blocking in
          “interrupt” context
     •    Frequently cut’n’pasted
            •    Including the comments!




16   © 2012 Wolfson Microelectronics plc             November 2012   www.wolfsonmicro.com
Interrupt controller

     struct regmap_irq {
            unsigned int reg_offset; unsigned int mask;
     };

     struct regmap_irq_chip {
            const char *name;
            unsigned int status_base;
            unsigned int mask_base;
            unsigned int ack_base;
            unsigned int wake_base;
            unsigned int irq_reg_stride;
            unsigned int mask_invert;
            bool runtime_pm;

                    const struct regmap_irq *irqs;
                    int num_irqs;
     };

17   © 2012 Wolfson Microelectronics plc             November 2012   www.wolfsonmicro.com
Feature summary

     •    v3.1: simple register I/O functionality for I2C and SPI
     •    v3.2: caches, tracepoints and debugfs
     •    v3.3: interrupt controller
     •    v3.4: patches
     •    v3.5: MMIO bus
     •    v3.6: paging support

     •    regmap based helpers for ASoC, regulator and IRQ




18   © 2012 Wolfson Microelectronics plc             November 2012   www.wolfsonmicro.com
Future work

     •    Support for devices providing their own set and get
          register operations without formatting (eg, for USB)
     •    Performance improvements in cache sync
     •    Combine rbtree and compressed into a single cache type
     •    Common helpers for register access patterns
     •    Simplify chips with dense interrupt controller bitfields
     •    More helpers for subsystems




19   © 2012 Wolfson Microelectronics plc          November 2012   www.wolfsonmicro.com
Thanks

     •    Liam Girdwood, ASoC comaintainer and original author
     •    Dimitris Papastamos, contributed advanced caches
     •    Lars-Peter Clausen, early adopter & bug fixer
     •    Stephen Warren, contributed regmap-mmio
     •    Krystian Garbaciak, contributed paging support
     •    Laxman Dewangan, contributed a bunch of improvements




20   © 2012 Wolfson Microelectronics plc       November 2012   www.wolfsonmicro.com
Summary

     •    Small abstractions pave the way for bigger ones
     •    Solving things at the right level saves time and effort
     •    Register I/O is very simple on Linux




21   © 2012 Wolfson Microelectronics plc             November 2012   www.wolfsonmicro.com

Weitere ähnliche Inhalte

Was ist angesagt?

Arista @ HPC on Wall Street 2012
Arista @ HPC on Wall Street 2012Arista @ HPC on Wall Street 2012
Arista @ HPC on Wall Street 2012Kazunori Sato
 
MPU and MCU IP Cores from CAST
MPU and MCU IP Cores from CASTMPU and MCU IP Cores from CAST
MPU and MCU IP Cores from CASTCAST, Inc.
 
The Microarchitecure Of FPGA Based Soft Processor
The Microarchitecure Of FPGA Based Soft ProcessorThe Microarchitecure Of FPGA Based Soft Processor
The Microarchitecure Of FPGA Based Soft ProcessorDeepak Tomar
 
AMD Catalyst Software
AMD Catalyst Software  AMD Catalyst Software
AMD Catalyst Software AMD
 
VVDN Presentation
VVDN PresentationVVDN Presentation
VVDN Presentationvibansal
 
CHARMED Upgrading the UT Pickle Separations to DeltaV v11
CHARMED Upgrading the UT Pickle Separations to DeltaV v11CHARMED Upgrading the UT Pickle Separations to DeltaV v11
CHARMED Upgrading the UT Pickle Separations to DeltaV v11Emerson Exchange
 
Trinity press deck 10 2 2012
Trinity press deck 10 2 2012Trinity press deck 10 2 2012
Trinity press deck 10 2 2012AMD
 
SOC Chip Basics
SOC Chip BasicsSOC Chip Basics
SOC Chip BasicsA B Shinde
 
Track B- Advanced ESL verification - Mentor
Track B- Advanced ESL verification - MentorTrack B- Advanced ESL verification - Mentor
Track B- Advanced ESL verification - Mentorchiportal
 
CAST BA22 32-bit Processor Design Seminar, 2/1/12
CAST BA22 32-bit Processor Design Seminar, 2/1/12CAST BA22 32-bit Processor Design Seminar, 2/1/12
CAST BA22 32-bit Processor Design Seminar, 2/1/12CAST, Inc.
 
Soc architecture and design
Soc architecture and designSoc architecture and design
Soc architecture and designSatya Harish
 
System on Chip (SoC) for mobile phones
System on Chip (SoC) for mobile phonesSystem on Chip (SoC) for mobile phones
System on Chip (SoC) for mobile phonesJeffrey Funk
 
Software hardware co-design using xilinx zynq soc
Software hardware co-design using xilinx zynq socSoftware hardware co-design using xilinx zynq soc
Software hardware co-design using xilinx zynq socHossam Hassan
 
OpenEye IP Video Basics
OpenEye IP Video BasicsOpenEye IP Video Basics
OpenEye IP Video Basicsopeneyevideo
 
Fpga asic technologies_flow
Fpga asic technologies_flowFpga asic technologies_flow
Fpga asic technologies_flowravi4all
 

Was ist angesagt? (20)

Arista @ HPC on Wall Street 2012
Arista @ HPC on Wall Street 2012Arista @ HPC on Wall Street 2012
Arista @ HPC on Wall Street 2012
 
SoC: System On Chip
SoC: System On ChipSoC: System On Chip
SoC: System On Chip
 
MPU and MCU IP Cores from CAST
MPU and MCU IP Cores from CASTMPU and MCU IP Cores from CAST
MPU and MCU IP Cores from CAST
 
The Microarchitecure Of FPGA Based Soft Processor
The Microarchitecure Of FPGA Based Soft ProcessorThe Microarchitecure Of FPGA Based Soft Processor
The Microarchitecure Of FPGA Based Soft Processor
 
AMD Catalyst Software
AMD Catalyst Software  AMD Catalyst Software
AMD Catalyst Software
 
XS Japan 2008 BitVisor English
XS Japan 2008 BitVisor EnglishXS Japan 2008 BitVisor English
XS Japan 2008 BitVisor English
 
VVDN Presentation
VVDN PresentationVVDN Presentation
VVDN Presentation
 
CHARMED Upgrading the UT Pickle Separations to DeltaV v11
CHARMED Upgrading the UT Pickle Separations to DeltaV v11CHARMED Upgrading the UT Pickle Separations to DeltaV v11
CHARMED Upgrading the UT Pickle Separations to DeltaV v11
 
Trinity press deck 10 2 2012
Trinity press deck 10 2 2012Trinity press deck 10 2 2012
Trinity press deck 10 2 2012
 
SudheerV_resume_a
SudheerV_resume_aSudheerV_resume_a
SudheerV_resume_a
 
SOC Chip Basics
SOC Chip BasicsSOC Chip Basics
SOC Chip Basics
 
Track B- Advanced ESL verification - Mentor
Track B- Advanced ESL verification - MentorTrack B- Advanced ESL verification - Mentor
Track B- Advanced ESL verification - Mentor
 
CAST BA22 32-bit Processor Design Seminar, 2/1/12
CAST BA22 32-bit Processor Design Seminar, 2/1/12CAST BA22 32-bit Processor Design Seminar, 2/1/12
CAST BA22 32-bit Processor Design Seminar, 2/1/12
 
SoC Design
SoC DesignSoC Design
SoC Design
 
Soc architecture and design
Soc architecture and designSoc architecture and design
Soc architecture and design
 
System on Chip (SoC) for mobile phones
System on Chip (SoC) for mobile phonesSystem on Chip (SoC) for mobile phones
System on Chip (SoC) for mobile phones
 
ASIC vs SOC vs FPGA
ASIC  vs SOC  vs FPGAASIC  vs SOC  vs FPGA
ASIC vs SOC vs FPGA
 
Software hardware co-design using xilinx zynq soc
Software hardware co-design using xilinx zynq socSoftware hardware co-design using xilinx zynq soc
Software hardware co-design using xilinx zynq soc
 
OpenEye IP Video Basics
OpenEye IP Video BasicsOpenEye IP Video Basics
OpenEye IP Video Basics
 
Fpga asic technologies_flow
Fpga asic technologies_flowFpga asic technologies_flow
Fpga asic technologies_flow
 

Andere mochten auch

Regulators learning to play with others
Regulators  learning to play with othersRegulators  learning to play with others
Regulators learning to play with othersMark Brown
 
Kernelci.org needs you!
Kernelci.org needs you!Kernelci.org needs you!
Kernelci.org needs you!Mark Brown
 
Linux audio for smartphones
Linux audio for smartphonesLinux audio for smartphones
Linux audio for smartphonesMark Brown
 
LCU13: Linaro Stable Kernel
LCU13: Linaro Stable KernelLCU13: Linaro Stable Kernel
LCU13: Linaro Stable KernelMark Brown
 
What's going on with SPI
What's going on with SPI What's going on with SPI
What's going on with SPI Mark Brown
 
I2C Subsystem In Linux-2.6.24
I2C Subsystem In Linux-2.6.24I2C Subsystem In Linux-2.6.24
I2C Subsystem In Linux-2.6.24Varun Mahajan
 

Andere mochten auch (6)

Regulators learning to play with others
Regulators  learning to play with othersRegulators  learning to play with others
Regulators learning to play with others
 
Kernelci.org needs you!
Kernelci.org needs you!Kernelci.org needs you!
Kernelci.org needs you!
 
Linux audio for smartphones
Linux audio for smartphonesLinux audio for smartphones
Linux audio for smartphones
 
LCU13: Linaro Stable Kernel
LCU13: Linaro Stable KernelLCU13: Linaro Stable Kernel
LCU13: Linaro Stable Kernel
 
What's going on with SPI
What's going on with SPI What's going on with SPI
What's going on with SPI
 
I2C Subsystem In Linux-2.6.24
I2C Subsystem In Linux-2.6.24I2C Subsystem In Linux-2.6.24
I2C Subsystem In Linux-2.6.24
 

Ähnlich wie regmap: The power of subsystems and abstractions

SYBSC IT SEM IV EMBEDDED SYSTEMS UNIT I Core of Embedded Systems
SYBSC IT SEM IV EMBEDDED SYSTEMS UNIT I   Core of Embedded SystemsSYBSC IT SEM IV EMBEDDED SYSTEMS UNIT I   Core of Embedded Systems
SYBSC IT SEM IV EMBEDDED SYSTEMS UNIT I Core of Embedded SystemsArti Parab Academics
 
Summer training embedded system and its scope
Summer training  embedded system and its scopeSummer training  embedded system and its scope
Summer training embedded system and its scopeArshit Rai
 
Summer training embedded system and its scope
Summer training  embedded system and its scopeSummer training  embedded system and its scope
Summer training embedded system and its scopeArshit Rai
 
RTOS based Confidential Area Security System
RTOS based Confidential Area Security SystemRTOS based Confidential Area Security System
RTOS based Confidential Area Security Systemajinky gadewar
 
POLYTEDA: Power DRC/LVS, June 2017
POLYTEDA: Power DRC/LVS, June 2017POLYTEDA: Power DRC/LVS, June 2017
POLYTEDA: Power DRC/LVS, June 2017Oleksandra Nazola
 
Schneider Electric Scada Global Support Provides Troubleshooting and Technica...
Schneider Electric Scada Global Support Provides Troubleshooting and Technica...Schneider Electric Scada Global Support Provides Troubleshooting and Technica...
Schneider Electric Scada Global Support Provides Troubleshooting and Technica...Preeya Selvarajah
 
Polyteda Power DRC/LVS July 2016
Polyteda Power DRC/LVS July 2016Polyteda Power DRC/LVS July 2016
Polyteda Power DRC/LVS July 2016Oleksandra Nazola
 
High Performance Computing Infrastructure: Past, Present, and Future
High Performance Computing Infrastructure: Past, Present, and FutureHigh Performance Computing Infrastructure: Past, Present, and Future
High Performance Computing Infrastructure: Past, Present, and Futurekarl.barnes
 
Introduction to embedded System.pptx
Introduction to embedded System.pptxIntroduction to embedded System.pptx
Introduction to embedded System.pptxPratik Gohel
 
Polyteda: Power DRC/LVS, October 2016
Polyteda: Power DRC/LVS, October 2016Polyteda: Power DRC/LVS, October 2016
Polyteda: Power DRC/LVS, October 2016Oleksandra Nazola
 
Developing micro controller applications
Developing micro controller applicationsDeveloping micro controller applications
Developing micro controller applicationsSteve Mylroie
 
PowerDRC/LVS 2.2 released by POLYTEDA
PowerDRC/LVS 2.2 released by POLYTEDAPowerDRC/LVS 2.2 released by POLYTEDA
PowerDRC/LVS 2.2 released by POLYTEDAAlexander Grudanov
 
Ramprasad-CV_3+yrs
Ramprasad-CV_3+yrsRamprasad-CV_3+yrs
Ramprasad-CV_3+yrsRamprasad B
 
“High-Efficiency Edge Vision Processing Based on Dynamically Reconfigurable T...
“High-Efficiency Edge Vision Processing Based on Dynamically Reconfigurable T...“High-Efficiency Edge Vision Processing Based on Dynamically Reconfigurable T...
“High-Efficiency Edge Vision Processing Based on Dynamically Reconfigurable T...Edge AI and Vision Alliance
 

Ähnlich wie regmap: The power of subsystems and abstractions (20)

SYBSC IT SEM IV EMBEDDED SYSTEMS UNIT I Core of Embedded Systems
SYBSC IT SEM IV EMBEDDED SYSTEMS UNIT I   Core of Embedded SystemsSYBSC IT SEM IV EMBEDDED SYSTEMS UNIT I   Core of Embedded Systems
SYBSC IT SEM IV EMBEDDED SYSTEMS UNIT I Core of Embedded Systems
 
Summer training embedded system and its scope
Summer training  embedded system and its scopeSummer training  embedded system and its scope
Summer training embedded system and its scope
 
Summer training embedded system and its scope
Summer training  embedded system and its scopeSummer training  embedded system and its scope
Summer training embedded system and its scope
 
RTOS based Confidential Area Security System
RTOS based Confidential Area Security SystemRTOS based Confidential Area Security System
RTOS based Confidential Area Security System
 
POLYTEDA: Power DRC/LVS, June 2017
POLYTEDA: Power DRC/LVS, June 2017POLYTEDA: Power DRC/LVS, June 2017
POLYTEDA: Power DRC/LVS, June 2017
 
Schneider Electric Scada Global Support Provides Troubleshooting and Technica...
Schneider Electric Scada Global Support Provides Troubleshooting and Technica...Schneider Electric Scada Global Support Provides Troubleshooting and Technica...
Schneider Electric Scada Global Support Provides Troubleshooting and Technica...
 
Project_updated
Project_updatedProject_updated
Project_updated
 
Polyteda Power DRC/LVS July 2016
Polyteda Power DRC/LVS July 2016Polyteda Power DRC/LVS July 2016
Polyteda Power DRC/LVS July 2016
 
High Performance Computing Infrastructure: Past, Present, and Future
High Performance Computing Infrastructure: Past, Present, and FutureHigh Performance Computing Infrastructure: Past, Present, and Future
High Performance Computing Infrastructure: Past, Present, and Future
 
Introduction to embedded System.pptx
Introduction to embedded System.pptxIntroduction to embedded System.pptx
Introduction to embedded System.pptx
 
Polyteda: Power DRC/LVS, October 2016
Polyteda: Power DRC/LVS, October 2016Polyteda: Power DRC/LVS, October 2016
Polyteda: Power DRC/LVS, October 2016
 
Linux on System z debugging with Valgrind
Linux on System z debugging with ValgrindLinux on System z debugging with Valgrind
Linux on System z debugging with Valgrind
 
MÁY KIỂM KHO DATALOGIC Dh60
MÁY KIỂM KHO DATALOGIC Dh60 MÁY KIỂM KHO DATALOGIC Dh60
MÁY KIỂM KHO DATALOGIC Dh60
 
Developing micro controller applications
Developing micro controller applicationsDeveloping micro controller applications
Developing micro controller applications
 
Embedded systems
Embedded systemsEmbedded systems
Embedded systems
 
ankit
ankitankit
ankit
 
PowerDRC/LVS 2.2 released by POLYTEDA
PowerDRC/LVS 2.2 released by POLYTEDAPowerDRC/LVS 2.2 released by POLYTEDA
PowerDRC/LVS 2.2 released by POLYTEDA
 
Ramprasad-CV_3+yrs
Ramprasad-CV_3+yrsRamprasad-CV_3+yrs
Ramprasad-CV_3+yrs
 
Vlsi lab
Vlsi labVlsi lab
Vlsi lab
 
“High-Efficiency Edge Vision Processing Based on Dynamically Reconfigurable T...
“High-Efficiency Edge Vision Processing Based on Dynamically Reconfigurable T...“High-Efficiency Edge Vision Processing Based on Dynamically Reconfigurable T...
“High-Efficiency Edge Vision Processing Based on Dynamically Reconfigurable T...
 

Kürzlich hochgeladen

08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 

Kürzlich hochgeladen (20)

08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 

regmap: The power of subsystems and abstractions

  • 1. regmap The power of subsystems and abstractions 1 © 2012 Wolfson Microelectronics plc November 2012 www.wolfsonmicro.com
  • 2. Overview • The quality of the subsystems is key to Linux • Factor common code out of drivers • Simplify driver development • Encourage best practice • Maximise the impact of features • regmap provides a good case study • Register I/O for I2C and SPI • Originally in ASoC for audio CODECs • Traditionally open coded in drivers • Now provides benefits for totally different device classes • Nothing like it in other operating systems 2 © 2012 Wolfson Microelectronics plc November 2012 www.wolfsonmicro.com
  • 3. In the beginning… • ASoC CODEC drivers need to provide configuration to users • Saw that there were lots of register bitfields like: • R0 INL_VOL [5:0]: Left input PGA Volume -23.25dB to +24.00dB in 0.75dB steps • R1 INR_VOL [5:0]: Right input PGA Volume -23.25dB to +24.00dB in 0.75dB steps • Factored this out into standard helpers for drivers: • SOC_DOUBLE_R_TLV("Capture Volume", WM8962_LEFT_INPUT_VOLUME, WM8962_RIGHT_INPUT_VOLUME, 0, 63, 0, inpga_tlv), • Supported with CODEC callbacks: • int read(struct snd_soc_codec *codec, int reg); • int write(struct snd_soc_codec *codec, int reg, int value); 3 © 2012 Wolfson Microelectronics plc November 2012 www.wolfsonmicro.com
  • 4. Quick wins • Save some boilerplate • Simple factor out of one very common operation • snd_soc_update_bits(struct snd_soc_codec *codec, int reg, int mask, int val); • Can suppress no op changes • Make best practice clear and obvious 4 © 2012 Wolfson Microelectronics plc November 2012 www.wolfsonmicro.com
  • 5. Register dumps • Using: • Register read and write operations • Ideally also the maximum register address • The subsystem can provide register dumps as a standard feature: 0000: abcd 0001: 5e32 • Common output format • Support for reading only specific registers • Write support • Enabled by previous factoring out 5 © 2012 Wolfson Microelectronics plc November 2012 www.wolfsonmicro.com
  • 6. Register caches • Had been open coded in drivers • Layered in with a little bit more data • Register default values • Volatile registers • Really nice feature • Many devices don’t support readback • Performance improvement • Simplifies suspend and resume 6 © 2012 Wolfson Microelectronics plc November 2012 www.wolfsonmicro.com
  • 7. Physical I/O • The hardware interface is very consistent over devices: SCLK SDA D7 D1 R/W A6 A0 B8 B7 B1 B0 START device ID (Write) ACK register address B8 ACK data bits B7 – B0 ACK STOP Note: The SDA pin is used as input for the control register address and data; SDA is pulled low by the receiving device to provide the acknowledge (ACK) response • Register followed by value, big endian • Standard implementation of read and write • Subsystem ensures all drivers get the fiddly bits right • Byte swapping • Interoperability with controller features • Performance tricks 7 © 2012 Wolfson Microelectronics plc November 2012 www.wolfsonmicro.com
  • 8. Factoring out regmap • These patterns are present in many other devices • PMICs • Input controllers • GPIO expanders • Move the code out of ASoC • drivers/base/regmap • Gradual merge • v3.1: simple register I/O functionality for I2C and SPI • v3.2: caches, tracepoints and debugfs 8 © 2012 Wolfson Microelectronics plc November 2012 www.wolfsonmicro.com
  • 9. Device description struct regmap_config { int reg_bits; int pad_bits; int val_bits; bool (*writeable_reg)(struct device *dev, unsigned int reg); bool (*readable_reg)(struct device *dev, unsigned int reg); bool (*volatile_reg)(struct device *dev, unsigned int reg); bool (*precious_reg)(struct device *dev, unsigned int reg); unsigned int max_register; const struct reg_default *reg_defaults; unsigned int num_reg_defaults; }; 9 © 2012 Wolfson Microelectronics plc November 2012 www.wolfsonmicro.com
  • 10. Core API struct regmap *devm_regmap_init_i2c(struct i2c_client *i2c, const struct regmap_config *config); int regmap_read(struct regmap *map, unsigned int reg, unsigned int *val); int regmap_write(struct regmap *map, unsigned int reg, unsigned int val); int regmap_update_bits(struct regmap *map, unsigned int reg, unsigned int mask, unsigned int val); int regcache_sync(struct regmap *map); void regcache_cache_only(struct regmap *map, bool enable); void regcache_mark_dirty(struct regmap *map); 10 © 2012 Wolfson Microelectronics plc November 2012 www.wolfsonmicro.com
  • 11. Complex register caches • Initially caches just used a flat array • Not so good when caching devices with 32 bit addresses • Solved with better cache types • rbtree stores blocks of contiguous registers in a red/black tree (436 lines) • Compressed stores blocks of compressed data (380 lines) • Both rely on existing kernel libraries enum regcache_type cache_type; 11 © 2012 Wolfson Microelectronics plc November 2012 www.wolfsonmicro.com
  • 12. Tracepoints/Logging • Simple, low overhead logging subsystem • Can be built in all the time and running all the time • Standard format allows reusable tooling in userspace • Key tracepoints for regmap: • regmap_reg_write 0-001a reg=1a val=3c • regmap_reg_read 0-001a reg=1 val=3c • See more in debugfs/trace/events/regmap/ • Also a simple define LOG_DEVICE for early init logging 12 © 2012 Wolfson Microelectronics plc November 2012 www.wolfsonmicro.com
  • 13. Register patches • Magic register writes done at device startup • Performance tuning • Workarounds • Integrated into cache sync int regmap_register_patch(struct regmap *map, const struct reg_default *regs, int num_regs); 13 © 2012 Wolfson Microelectronics plc November 2012 www.wolfsonmicro.com
  • 14. Paging support • Common hardware pattern, adds another level of addressing • Supported in regmap by creating virtual registers • Standard interface allows upper level code to ignore paging struct regmap_range_cfg { const char *name; unsigned int range_min; unsigned int range_max; unsigned int selector_reg; unsigned int selector_mask; int selector_shift; unsigned int window_start; unsigned int window_len; }; 14 © 2012 Wolfson Microelectronics plc November 2012 www.wolfsonmicro.com
  • 15. MMIO support • Cache and diagnostic infrastructure isn’t just useful to I2C and SPI • Allows really simple integration with runtime PM 15 © 2012 Wolfson Microelectronics plc November 2012 www.wolfsonmicro.com
  • 16. Interrupt controller • Common patterns in interrupt controllers • Status register • Mask register • Lots of fiddly stuff with interrupt core due to blocking in “interrupt” context • Frequently cut’n’pasted • Including the comments! 16 © 2012 Wolfson Microelectronics plc November 2012 www.wolfsonmicro.com
  • 17. Interrupt controller struct regmap_irq { unsigned int reg_offset; unsigned int mask; }; struct regmap_irq_chip { const char *name; unsigned int status_base; unsigned int mask_base; unsigned int ack_base; unsigned int wake_base; unsigned int irq_reg_stride; unsigned int mask_invert; bool runtime_pm; const struct regmap_irq *irqs; int num_irqs; }; 17 © 2012 Wolfson Microelectronics plc November 2012 www.wolfsonmicro.com
  • 18. Feature summary • v3.1: simple register I/O functionality for I2C and SPI • v3.2: caches, tracepoints and debugfs • v3.3: interrupt controller • v3.4: patches • v3.5: MMIO bus • v3.6: paging support • regmap based helpers for ASoC, regulator and IRQ 18 © 2012 Wolfson Microelectronics plc November 2012 www.wolfsonmicro.com
  • 19. Future work • Support for devices providing their own set and get register operations without formatting (eg, for USB) • Performance improvements in cache sync • Combine rbtree and compressed into a single cache type • Common helpers for register access patterns • Simplify chips with dense interrupt controller bitfields • More helpers for subsystems 19 © 2012 Wolfson Microelectronics plc November 2012 www.wolfsonmicro.com
  • 20. Thanks • Liam Girdwood, ASoC comaintainer and original author • Dimitris Papastamos, contributed advanced caches • Lars-Peter Clausen, early adopter & bug fixer • Stephen Warren, contributed regmap-mmio • Krystian Garbaciak, contributed paging support • Laxman Dewangan, contributed a bunch of improvements 20 © 2012 Wolfson Microelectronics plc November 2012 www.wolfsonmicro.com
  • 21. Summary • Small abstractions pave the way for bigger ones • Solving things at the right level saves time and effort • Register I/O is very simple on Linux 21 © 2012 Wolfson Microelectronics plc November 2012 www.wolfsonmicro.com