 Today I'll speak about poor management integrated circuits The goal is to present Why you would want some thing like that in your board or why not? I'll take a few example on some MIC I actually developed the drivers for So yeah, I'm content shows Quentin for English-speaking person I'm an embedded Linux and kernel engineer at Freelictron's for six months now We're mainly doing work on the on the upstream Linux kernel We have a lot of contributors in our company and also maintainers For myself I worked on drivers for the XP 209 and XP 208 to 23 sorry for the chip of next thing company and Also for another customer we have which is working with Orinor a 33 so see so Are they a little summary of what I will present today, so basically what is pay PMIC? That's the main point of it, and then you will discover they are mainly Common features in all PMICs, but some have really funny and Misc features in it and I'll present I'll try to present a bit An often overview of the PMICs So what's actually a PMIC what you want to get from it what you can get from it So PMIC is a poor management integrated circuits It handles the poor sequence of the board. So for example, this is actually the critical part of the PMIC Maybe you don't know but your So see needs to have some of Poor sequence we call it so regulator to be in for to be on for Four millisecond then another regulator for four millisecond also But then you have to turn it off and turn another regulator. So it's poor sequence to get your SOC Getting on this is really if you don't get this poor sequence, right? Your board will not boot So you have two ways to do it with a PMIC or two hardware hard-coded The PMIC also supplies port to the different components inside your board so for example you can have five Ten twelve whatever number of different components with different voltages as inputs The PMIC handles all that It also protects the board from unsupported of a voltage and under voltage That's quite nice because if you have a faulty charger Maybe for some milliseconds some even some seconds will just output seven volts instead of five That will just burn your board, but the PMIC tries to Protect your board it does really the best it can You can also have multiple poor supplies inputs in a board so for example on the tip You have an AC poor supply the battery poor supply and also the USB poor supply So I can just choose the best one So as I said, there are also different mix features so for example GPIOs or ADCs or LED strips or whatever you can think of It's usually software control war so for The X powers XP 20 X for example, it's an a square C devices or proprietary Bus, but it's usually software control. That's the main point of PMIC But actually the PMIC is not mandatory. So for example on the Raspberry Pi or the orange orange pie. It's not there So you cannot have multiple Examples to play at the same time or you will just burn your Raspberry Pi for example That's not mandatory actually you can do a Successful board like the Raspberry Pi with that one for example, so Here we have a board without a PMIC You have three different components requiring different input voltages So for example three three point three one point eight volts so your external pulse supply supplies five volts, but you Want a different one different voltage in each of your components? It will just go through DC DC converters or what we call it the regulators and that's it so everything is hard-coded hardware hard-coded and It just works But of course there is nicer way to do it. So for example on the at most summer 5d3 explained You have the PMIC in darker gray Which can actually turn on off or Control the voltage The voltage value you want the DC DC converter to output The PMIC does that it handles everything so switching on Controlling the voltage and you have also buttons. So for example the power reset button if you Press the probe button for let's say two seconds. It will ask the system to reboot But if you press it for four seconds, then it's an it's how are hard-coded you just reset manually the poor supply So this is a First kind of PMICs and you can see there are three difference by three Poor supply sorry, so battery AC and USB and he calls it can also handle the recharging of the battery Then we have another one. So for the bigger bone black Still the same components Still the DC DC converters which are controllable with the PMIC the LEDs. So this is quite a Funny feature so you can actually control a lead strip. So Yeah, why not? You have also the poor reset buttons and still the poor supplies and Then you have the overall kill PMIC from X powers the XP 20 X and XP 22 X So you have also GPIOs which can Be used either I as GPIOs or as ADC's you have also ADC's to get current values For example the current current your poor supply is delivering or the voltage Currently supplied by your poor supply You have also RTCs with the backup poor supply so you can have you can keep the time during the reboots Between reboots. So, yeah, that's quite an overview of what you can do without and with a PMIC PMIC. Sorry So as you could actually See there are Commonly integrated features so mainly the the main point of PMIC is to control your regulators The regulators are in the regulator subsystems the drivers which is located in drivers regulators The point is to Still to control if it's on off And also the voltage control I will I will get into that later So the PMIC supplies power to components requiring different input voltages So I controls the regulator actually the DC-DC converters and LDO regulators handle these different voltages So the main both main point of regulators is that you can save power with them So for example, you can decide the components your regulators is supplying for two They are unused or useless for your case for your board. So you just turn them off. So you I mean there is a whole number of components you don't supply for two then you of course you save power Some components also Support a range of input voltages. For example, you have GPS which can have as input As boring put between 1.8 and 2.8 volts You want the most power when you want it to fix maybe quicker But if you want to save power, then you will just send it the less power you can handle So the PMIC actually handles all that So the range of input voltages if you want to switch in or switch it on or off The the point of regulators it's it's really the core of the poor consumption and also the poor The raw power With the undervolting and overvolting. This is how you can actually achieve achieve CPU or GPU DVFS So dynamic voltage and frequency scaling. So if you want to really overvolt your CPU to be really fast Then you will need this regulator to adapt and so you can set a really Higher frequency also But if you want really a poor efficient board, you will need to lower at the maximum level of the poor your SOC can handle So without PMIC you cannot actually do it nicely It's so as I said, it's the core of battery life and poor consumption So I'll just give some example of each driver each subsystem impacted by the the PMIC and To illustrate that I will take mostly example from the XP 20 X drivers These one are all mainline instead one. I'll Tell you when it Goes on the slides So here, I will just quickly present the XP 20 X regulators driver So you have a regulator operation structure You set you give him the functions used to set a voltage get the current voltage How to get the list of available voltages how to enable disable and check if the regulator is enabled So Then you will describe your regulator actually you will give it a name. Oh, you cannot see my point Okay, I will give it a name With Oathmatch you will Tell the regulator framework where to find your regulator in the device tree and Regulators node is also the node the parent node of your regulators in a device tree so for example if you have a DC DC to in the root of your Device tree it will not match it because it needs to pound Divide three node to be regulators. So we'll have regulators and then DC DC to So the type is of course voltage regulator for us the idea to match against your code in the driver the number of voltage available voltages so here we have the maximum which is 2.275 volts minus the minimum which is 700 millivolts divided by the steps, which is 25 micro volts So yeah the minimum micro Microvolts you can get to 700 and and go on so then after you have the the register for which you can select the voltages of V cell reg its mask and the enabling register is max mask as well and at the last one is the Structure we defined earlier. So this one so That's it for the description of the regulator then we will have to actually map things together to register and you know the framework the subsystem so here we use a rack map in the regulator config so it's nicely We just take care of the Writing and reading on the same registers at the same time by different regulators so we don't get things messed up and then at the end we just Register all the regulator in the regulator subsystem So that's actually a really strict example, but only the remain part of the code are remained here So next one with the commonly integrated features are the poor supplies, of course need one So here we have three different sports supplies. So the battery the AC and usb The poor supply subsystem is in driver slash post slash your supply The PMIC actually takes care of all possible supported external supply. So here you have the AC so socket USB battery, maybe you can have Solar panel or whatever you can think of It defines as I said the poor sequence of the board It also protects from overvoltage and the voltage for for example a xp's Explorer's PMICs are designed mostly designed for five volts boards, but can handle from 0.3 to 11 volts It chooses actually the most suitable one depending on a study of status of each so for example if your AC but poor supply is plugged in but does not Output enough Current you'll need And there's an USB for supply plugged in and it will just switch over to the years to the USB poor supply And if either of them have an enough current Output it was just mixed them together to have enough current going on in the going in the board It also may handle the battery so recharging taking care of the recharging cycle of the battery So that's actually a nice feature So I will just present quickly the poor supply subsystem as I say it's located in poor slash drivers slash poor slash supply It has typically typically one driver per physical input Poor supplies or for example one driver for the AC one driver for the battery one driver for the USB That's the case actually for the XP 20x It can expose so I'm talking about the subsystem here You can expose really a lot of different data So you have for example the current voltage the current current the current battery capacity the battery type the temperature the Whatever you can think of and if it's missing one then you just can hide it at it, sorry You can set as many data. So for example, it's really interesting to tell the PMIC What is the? The voltage of your battery when it's full fully charged You can also say which which voltage is the highest supported one etc The the information you are Exposing it's really specific to a PMIC. So of course you will you cannot invent an Information your PMIC can give so you have we'll have to check in the data sheet to check if it's supported or not So for example, even in series of the same Vendor so the X powers you have the X XP 20 X which can read the current current and the current voltage of The AC and USB for supply, but the XP 20 X 22 X cannot do it So here we will go with a small example of the XP 20 X USB driver. So for the poor supply driver example it's quite Straightforward and it's already in mainline for a number of release already. So on top you have The properties your PMIC support For this particular Poor supply so for example here we can say if the poor supply present or not So if if it's plugged in your board, what is the minimal voltage allowed for your board and For for this poor supply, sorry And what is the current? voltage of this board of this poor supply Then just at the bottom you have the description of your poor supply so its name its type So for example here, it's USB, but it can be main for AC or battery for the battery poor supply the properties is it is the the structure you defined on the NMU defined on top and an interesting part is that You can say which property is actually writable. So which one you can set That's the function in the middle You just have to say I want here I want the vote the minimum voltage to be set setable by the user from ccfs Then the last two functions or get property and set property are the Function called by ccfs when you ask to read or write to file in ccfs Here is the structure which will be used just after so don't worry You can this is the structure you will fill in or get from ccfs when you write or read to a file so Here is actually the get and set property from What which will be called from ccfs? So get is called when you actually echo to Sorry got a file and set property when you echo to a file So as you can see the union on top of the last argument of the two Functions This is where you will get so in get property get set Sorry your values of involve involve you will put The status of your battery for supply for example USB for supply So here was just call a function in set property you will get the Integrity you put in the file. So you were called in a file. You can get it with with a well in va Then you will have to allocate your Custom structure and put it into driver data so it can be used along the driver codes and Of course where you register your USB for supply driver in the sports supply subsystem So now we can get a little bit more Into miss features So You have to know that all these features are really Specific to some PMICs The the two I presented before so regulators of post supply are really common things among PMICs, but this one are really Specific so for example You have the buttons so they are present in the one In the 8 mil some of 5d3 explained the big old bone black and the for example the chip and This is used to shut down your system based on how long you press your button Dpio so for example the XP PMICs have several pins you can use either either as a Dpio or ADC RTC with backup battery a few goals. I'll get more deeply into that later more deeper and the ADC to get actually current data value for the poor supplies present in the system So I'll just present the two main Miss features in the XP drivers. So here we have the ADCs and I'll also present The fuel gauge So ADC is the way to get current data values So the current current the current voltage the internal temperature the consumed current the discharging or charging current The battery percentage whatever you PMIC can tell you It's often stored in registers of an embedded ADC So within the PMIC the proper way to do it is to have a driver specific to this part of the PMIC so for the ADC and impacted subsystem is the ADC in IO so drivers slash IO slash ADC So a small example of the XP 20x ADC driver So here we have the small define which will be using the next slide. So you set Actually the type of your ADC channel. So if it's temperature voltage current Power whatever and if you have many different Channel of the same type you will have to index them. So that's why there is indexed equal one equals one If it indexed you have to tell him which index it is. So channel is here for that Well, how will you will also have address which is the registers in register in which you will have to write or read to get the value and also the Data you can get from these ADC channel. So for example here you have the raw values and the scale But you can also have the offset for example. So it's everything you need to compute process value and of course you have the datasheet name so everyone can Understand better your the relation between your driver and the datasheet so then after you just have indexes so the The one which will be put in channel actually so then We'll use the define I've Briefly presented before so XP 20 x ADC channel and you will do you will create an array With all the channels you can Get from the the PMIC So here you have VBS V from the USB for supply Which gives the IO voltage the current IO voltage of your poor supply and the register is here Which will be read to get the values or XP 20 x Phoebus V ADC H and Then you will define ADC scale which I will call in the next slide to tell How to compute or what is the for the scale for your channel? So here the scale for the Vibs for the current of your USB poor supply is 0.375 and you return the actual Way to compute your scale. So here it's the first value to the point of all will store the the number before the comma and fall to will Store the number after the comma which but in micro Scale and if you don't have any scale for For channel just return minus a nva So here here are the the functions which will be called when you read from ccfs So read row when you write to the ccfs so write row you have to unlike the poor supply framework there is no mean to say this Property is writable this Channel is you can get it. You can set scale offset. You have to check all the the the channel you added to your driver you have to Check if you want it to be writable or not So here in read row it will be called either for the raw values to get one to get the scale or the offset so here we get the raw values for the USB poor supply and the scale as well and at the end you have the IO infrastructure which stored the Function used to read or write from ccfs Then of course your I Said that your To get actually current values for your poor supply driver So not this one the poor supply driver with read your ADC driver Which in turn will read the register so there is no direct access from the poor supply to the register storing the ADC values So of course the you need a way to map the ADC driver and the poor supply driver So there is to it. There are two ways to do that. The first one is to use IO map structures So as it's presented here and the second one is to use device three P handles and Yeah, so We went with this one for particular reason which is explained in the mailing list So, oh, I forgot this this driver is still pending. It's close to be merged, but still not So here you map actually your driver, so you say the consumer Dev name is the poor supply driver. So here it's a XP 20 X dash USB dash poor dash supply and and You give him the consumer channel. So the name under which your poor supply driver. So your consumer will ask for the The channel and Also the ADC channel level. So it's the name within this driver. So the ADC driver. So for example Here you have V bus V But maybe we can call it USB voltage. Then you will have to say ADC channel level is USB ADC voltage So we also map the current for the USB poor supply and then We just have to register it. So here are a lot of different settings. So You set the name You set the parent node and also the mode. So on top on the top right You have the modes. So here it's direct mode. So it directly access the value, but you can have hardware or software buffer mode and Info is a customer structure You have also the channels. So the the channels we declared before so Here XP 20x ADC channels on top and Then after you just register it in a map So and you register of course your ADC driver in the IO subsystem So now with this your poor supply driver can actually get the values directly from the ADC driver so Here we have in your Get property. So when you read a ccfs file, you will ask the ADC driver to get the process value. So the Row value times the scale plus the offset and It's worth noting that the ADC subsystem expose values as Micro units while the poor supply Framework as for No, sorry Millie units for the for the ADC driver and micro units for the poor supply driver. So of course you have to do times a thousand Then you set the poor supply Provol so if it's an integer you just put it in involve So now to actually get your ADC channel You just need to do IO channel get and You put here Vibus V which is the name you put in your I am on IO map structure So for example here, it was Vibus V So consumer channel, but maybe we can put any other Name so this if I remember well, this is System-wide so For example, if you you can have in ADC channel Amongst all the ADC drivers any name for your For so the name in the datasheet But if you have to have different Unique name for the the consumer channel so you can get actually the right one With IO channel get because you don't need to know which is the ADC drivers feeding you data So you just have to get the channel before registering in the poor supply framework so a small word on fuel gauge because that's a trick pot So the battery percentage is actually approximated from its voltage. So for example, you say a battery at four volts it's it's equals to a battery charge at 40 percent and Battery at 3.6 volts. It's 20 percent of charge So the battery voltage does not linearly decrease in time or load So it's rather a curve which we call the open circuit voltage curve or CV curve The curve is battery specific. This is really important to get so It might be given by the battery vendors. You might have to actually Do it yourself so to charge and discharge a battery fully a battery It also depends on the environment if the room is hot cold humid try The number of charges you have done with the battery the age of the battery the usage you have How you use your battery The battery percentage Approximation by software must be done in user space. We don't want any computation hard compensation approximation in the kernel But some PMICs like the XP 20 X Have some register in which you can put the points of your or CV curve So the PMIC will actually do itself the approximation and return you the the I mean right almost right battery percentage So this is fine for us So you use poor supply pro voltage OCV so if software approximated you only give the points of the OCV curve and Then after with a user space application you approximate the actual battery percentage If it's hardware approximated like it's in the X powers XP 20 X or XP 22 X You can actually get and set the points defining OCV curve used in the PMIC So you give him the points so he can actually compute and approximate battery percentage by itself So I'll just I pointed a small Explanation by TI here So It's really fast Quick overview of this why it's important to get your OCV curve right so for example, you have a battery of the red OCV curve and Your PMIC returns your batteries at 3.6 volts So normally your charge would be 20% so we'd have Your battery which is your system should return 20% of battery left But actually you have inputted the the green OCV curve so your battery is at 3.6 volts and You have your system returns your battery is actually at 60% of battery That's not That's not good. I mean you cannot have a really efficient poor consumption I mean You get it you you have to you to have the right OCV curve or it's really a useless Data you get from the PMIC So normally the vendor will give it to you, but you might have to take With a constant load get the curve by yourself So as I said, there are a lot of different drivers And also there are drivers which are Linked together so the ADC and the post-applied drivers and The nice way to do it to have everything Probed together is to use an MFD so a multifunction device It will probe the different drivers of the PMIC so-called MFD cells will maps the interrupts to the driver which needs them. So for example, you want the Plug-in interruption of your USB power supply Only in your USB power supply driver, so we'll just map them It usually passes a right map to the MFD cells So it makes sure that the different drivers do not write at the same Register or read the same register at the same time So a small example on this So we have a little bit of the overview of the PMIC in the ball itself. So we have here the regulators ADCs to the buttons to pull different poor supplies and the MFD will actually Probes every single one of them. So the regulators drivers the battery for supply AC for supply USB for supply drivers The ADC driver buttons driver GPO driver. Let's trip driver. Whatever driver there is in there are in your PMIC So here is a little example on the MFD for the XP 20x So first you define your resource for your here for your USB poor supply so you want to get to Define the resource which is the interruption you get from plugging in your USB poor supply and After that you define which Drivers you want to probe so inside the MFD cell array You have the name of your Driver so here the XP 20x USB poor supply driver the OF compatible So for example some drivers need Information from the device tree, so you have the same driver, but some property are different between PMICs between boards and That will do the mapping between the device tree and the MFD cells So it's always the same device The then you just define the resources you will affect to your drivers so to your MFD cell and in the device probing of your MFD driver You just add the devices So here with we use the parent parent node we use the automatic ID selection and we Tell I want to add all these MFD cells So I think that's all yes So that was all for the PMICs with some examples on the XP 20x PMICs So if you have any question You can ask them now or hit me with a mail or whatever I'll be glad to answer them. Is there any question? Okay. All right. Thank you. Have a good day