Back to home page

OSCL-LXR

 
 

    


0001 ==================================
0002 PMBus core driver and internal API
0003 ==================================
0004 
0005 Introduction
0006 ============
0007 
0008 [from pmbus.org] The Power Management Bus (PMBus) is an open standard
0009 power-management protocol with a fully defined command language that facilitates
0010 communication with power converters and other devices in a power system. The
0011 protocol is implemented over the industry-standard SMBus serial interface and
0012 enables programming, control, and real-time monitoring of compliant power
0013 conversion products. This flexible and highly versatile standard allows for
0014 communication between devices based on both analog and digital technologies, and
0015 provides true interoperability which will reduce design complexity and shorten
0016 time to market for power system designers. Pioneered by leading power supply and
0017 semiconductor companies, this open power system standard is maintained and
0018 promoted by the PMBus Implementers Forum (PMBus-IF), comprising 30+ adopters
0019 with the objective to provide support to, and facilitate adoption among, users.
0020 
0021 Unfortunately, while PMBus commands are standardized, there are no mandatory
0022 commands, and manufacturers can add as many non-standard commands as they like.
0023 Also, different PMBUs devices act differently if non-supported commands are
0024 executed. Some devices return an error, some devices return 0xff or 0xffff and
0025 set a status error flag, and some devices may simply hang up.
0026 
0027 Despite all those difficulties, a generic PMBus device driver is still useful
0028 and supported since kernel version 2.6.39. However, it was necessary to support
0029 device specific extensions in addition to the core PMBus driver, since it is
0030 simply unknown what new device specific functionality PMBus device developers
0031 come up with next.
0032 
0033 To make device specific extensions as scalable as possible, and to avoid having
0034 to modify the core PMBus driver repeatedly for new devices, the PMBus driver was
0035 split into core, generic, and device specific code. The core code (in
0036 pmbus_core.c) provides generic functionality. The generic code (in pmbus.c)
0037 provides support for generic PMBus devices. Device specific code is responsible
0038 for device specific initialization and, if needed, maps device specific
0039 functionality into generic functionality. This is to some degree comparable
0040 to PCI code, where generic code is augmented as needed with quirks for all kinds
0041 of devices.
0042 
0043 PMBus device capabilities auto-detection
0044 ========================================
0045 
0046 For generic PMBus devices, code in pmbus.c attempts to auto-detect all supported
0047 PMBus commands. Auto-detection is somewhat limited, since there are simply too
0048 many variables to consider. For example, it is almost impossible to autodetect
0049 which PMBus commands are paged and which commands are replicated across all
0050 pages (see the PMBus specification for details on multi-page PMBus devices).
0051 
0052 For this reason, it often makes sense to provide a device specific driver if not
0053 all commands can be auto-detected. The data structures in this driver can be
0054 used to inform the core driver about functionality supported by individual
0055 chips.
0056 
0057 Some commands are always auto-detected. This applies to all limit commands
0058 (lcrit, min, max, and crit attributes) as well as associated alarm attributes.
0059 Limits and alarm attributes are auto-detected because there are simply too many
0060 possible combinations to provide a manual configuration interface.
0061 
0062 PMBus internal API
0063 ==================
0064 
0065 The API between core and device specific PMBus code is defined in
0066 drivers/hwmon/pmbus/pmbus.h. In addition to the internal API, pmbus.h defines
0067 standard PMBus commands and virtual PMBus commands.
0068 
0069 Standard PMBus commands
0070 -----------------------
0071 
0072 Standard PMBus commands (commands values 0x00 to 0xff) are defined in the PMBUs
0073 specification.
0074 
0075 Virtual PMBus commands
0076 ----------------------
0077 
0078 Virtual PMBus commands are provided to enable support for non-standard
0079 functionality which has been implemented by several chip vendors and is thus
0080 desirable to support.
0081 
0082 Virtual PMBus commands start with command value 0x100 and can thus easily be
0083 distinguished from standard PMBus commands (which can not have values larger
0084 than 0xff). Support for virtual PMBus commands is device specific and thus has
0085 to be implemented in device specific code.
0086 
0087 Virtual commands are named PMBUS_VIRT_xxx and start with PMBUS_VIRT_BASE. All
0088 virtual commands are word sized.
0089 
0090 There are currently two types of virtual commands.
0091 
0092 - READ commands are read-only; writes are either ignored or return an error.
0093 - RESET commands are read/write. Reading reset registers returns zero
0094   (used for detection), writing any value causes the associated history to be
0095   reset.
0096 
0097 Virtual commands have to be handled in device specific driver code. Chip driver
0098 code returns non-negative values if a virtual command is supported, or a
0099 negative error code if not. The chip driver may return -ENODATA or any other
0100 Linux error code in this case, though an error code other than -ENODATA is
0101 handled more efficiently and thus preferred. Either case, the calling PMBus
0102 core code will abort if the chip driver returns an error code when reading
0103 or writing virtual registers (in other words, the PMBus core code will never
0104 send a virtual command to a chip).
0105 
0106 PMBus driver information
0107 ------------------------
0108 
0109 PMBus driver information, defined in struct pmbus_driver_info, is the main means
0110 for device specific drivers to pass information to the core PMBus driver.
0111 Specifically, it provides the following information.
0112 
0113 - For devices supporting its data in Direct Data Format, it provides coefficients
0114   for converting register values into normalized data. This data is usually
0115   provided by chip manufacturers in device datasheets.
0116 - Supported chip functionality can be provided to the core driver. This may be
0117   necessary for chips which react badly if non-supported commands are executed,
0118   and/or to speed up device detection and initialization.
0119 - Several function entry points are provided to support overriding and/or
0120   augmenting generic command execution. This functionality can be used to map
0121   non-standard PMBus commands to standard commands, or to augment standard
0122   command return values with device specific information.
0123 
0124 PEC Support
0125 ===========
0126 
0127 Many PMBus devices support SMBus PEC (Packet Error Checking). If supported
0128 by both the I2C adapter and by the PMBus chip, it is by default enabled.
0129 If PEC is supported, the PMBus core driver adds an attribute named 'pec' to
0130 the I2C device. This attribute can be used to control PEC support in the
0131 communication with the PMBus chip.
0132 
0133 API functions
0134 =============
0135 
0136 Functions provided by chip driver
0137 ---------------------------------
0138 
0139 All functions return the command return value (read) or zero (write) if
0140 successful. A return value of -ENODATA indicates that there is no manufacturer
0141 specific command, but that a standard PMBus command may exist. Any other
0142 negative return value indicates that the commands does not exist for this
0143 chip, and that no attempt should be made to read or write the standard
0144 command.
0145 
0146 As mentioned above, an exception to this rule applies to virtual commands,
0147 which *must* be handled in driver specific code. See "Virtual PMBus Commands"
0148 above for more details.
0149 
0150 Command execution in the core PMBus driver code is as follows::
0151 
0152         if (chip_access_function) {
0153                 status = chip_access_function();
0154                 if (status != -ENODATA)
0155                         return status;
0156         }
0157         if (command >= PMBUS_VIRT_BASE) /* For word commands/registers only */
0158                 return -EINVAL;
0159         return generic_access();
0160 
0161 Chip drivers may provide pointers to the following functions in struct
0162 pmbus_driver_info. All functions are optional.
0163 
0164 ::
0165 
0166   int (*read_byte_data)(struct i2c_client *client, int page, int reg);
0167 
0168 Read byte from page <page>, register <reg>.
0169 <page> may be -1, which means "current page".
0170 
0171 
0172 ::
0173 
0174   int (*read_word_data)(struct i2c_client *client, int page, int phase,
0175                         int reg);
0176 
0177 Read word from page <page>, phase <pase>, register <reg>. If the chip does not
0178 support multiple phases, the phase parameter can be ignored. If the chip
0179 supports multiple phases, a phase value of 0xff indicates all phases.
0180 
0181 ::
0182 
0183   int (*write_word_data)(struct i2c_client *client, int page, int reg,
0184                          u16 word);
0185 
0186 Write word to page <page>, register <reg>.
0187 
0188 ::
0189 
0190   int (*write_byte)(struct i2c_client *client, int page, u8 value);
0191 
0192 Write byte to page <page>, register <reg>.
0193 <page> may be -1, which means "current page".
0194 
0195 ::
0196 
0197   int (*identify)(struct i2c_client *client, struct pmbus_driver_info *info);
0198 
0199 Determine supported PMBus functionality. This function is only necessary
0200 if a chip driver supports multiple chips, and the chip functionality is not
0201 pre-determined. It is currently only used by the generic pmbus driver
0202 (pmbus.c).
0203 
0204 Functions exported by core driver
0205 ---------------------------------
0206 
0207 Chip drivers are expected to use the following functions to read or write
0208 PMBus registers. Chip drivers may also use direct I2C commands. If direct I2C
0209 commands are used, the chip driver code must not directly modify the current
0210 page, since the selected page is cached in the core driver and the core driver
0211 will assume that it is selected. Using pmbus_set_page() to select a new page
0212 is mandatory.
0213 
0214 ::
0215 
0216   int pmbus_set_page(struct i2c_client *client, u8 page, u8 phase);
0217 
0218 Set PMBus page register to <page> and <phase> for subsequent commands.
0219 If the chip does not support multiple phases, the phase parameter is
0220 ignored. Otherwise, a phase value of 0xff selects all phases.
0221 
0222 ::
0223 
0224   int pmbus_read_word_data(struct i2c_client *client, u8 page, u8 phase,
0225                            u8 reg);
0226 
0227 Read word data from <page>, <phase>, <reg>. Similar to
0228 i2c_smbus_read_word_data(), but selects page and phase first. If the chip does
0229 not support multiple phases, the phase parameter is ignored. Otherwise, a phase
0230 value of 0xff selects all phases.
0231 
0232 ::
0233 
0234   int pmbus_write_word_data(struct i2c_client *client, u8 page, u8 reg,
0235                             u16 word);
0236 
0237 Write word data to <page>, <reg>. Similar to i2c_smbus_write_word_data(), but
0238 selects page first.
0239 
0240 ::
0241 
0242   int pmbus_read_byte_data(struct i2c_client *client, int page, u8 reg);
0243 
0244 Read byte data from <page>, <reg>. Similar to i2c_smbus_read_byte_data(), but
0245 selects page first. <page> may be -1, which means "current page".
0246 
0247 ::
0248 
0249   int pmbus_write_byte(struct i2c_client *client, int page, u8 value);
0250 
0251 Write byte data to <page>, <reg>. Similar to i2c_smbus_write_byte(), but
0252 selects page first. <page> may be -1, which means "current page".
0253 
0254 ::
0255 
0256   void pmbus_clear_faults(struct i2c_client *client);
0257 
0258 Execute PMBus "Clear Fault" command on all chip pages.
0259 This function calls the device specific write_byte function if defined.
0260 Therefore, it must _not_ be called from that function.
0261 
0262 ::
0263 
0264   bool pmbus_check_byte_register(struct i2c_client *client, int page, int reg);
0265 
0266 Check if byte register exists. Return true if the register exists, false
0267 otherwise.
0268 This function calls the device specific write_byte function if defined to
0269 obtain the chip status. Therefore, it must _not_ be called from that function.
0270 
0271 ::
0272 
0273   bool pmbus_check_word_register(struct i2c_client *client, int page, int reg);
0274 
0275 Check if word register exists. Return true if the register exists, false
0276 otherwise.
0277 This function calls the device specific write_byte function if defined to
0278 obtain the chip status. Therefore, it must _not_ be called from that function.
0279 
0280 ::
0281 
0282   int pmbus_do_probe(struct i2c_client *client, struct pmbus_driver_info *info);
0283 
0284 Execute probe function. Similar to standard probe function for other drivers,
0285 with the pointer to struct pmbus_driver_info as additional argument. Calls
0286 identify function if supported. Must only be called from device probe
0287 function.
0288 
0289 ::
0290 
0291   const struct pmbus_driver_info
0292         *pmbus_get_driver_info(struct i2c_client *client);
0293 
0294 Return pointer to struct pmbus_driver_info as passed to pmbus_do_probe().
0295 
0296 
0297 PMBus driver platform data
0298 ==========================
0299 
0300 PMBus platform data is defined in include/linux/pmbus.h. Platform data
0301 currently provides a flags field with four bits used::
0302 
0303         #define PMBUS_SKIP_STATUS_CHECK                 BIT(0)
0304 
0305         #define PMBUS_WRITE_PROTECTED                   BIT(1)
0306 
0307         #define PMBUS_NO_CAPABILITY                     BIT(2)
0308 
0309         #define PMBUS_READ_STATUS_AFTER_FAILED_CHECK    BIT(3)
0310 
0311         struct pmbus_platform_data {
0312                 u32 flags;              /* Device specific flags */
0313 
0314                 /* regulator support */
0315                 int num_regulators;
0316                 struct regulator_init_data *reg_init_data;
0317         };
0318 
0319 
0320 Flags
0321 -----
0322 
0323 PMBUS_SKIP_STATUS_CHECK
0324 
0325 During register detection, skip checking the status register for
0326 communication or command errors.
0327 
0328 Some PMBus chips respond with valid data when trying to read an unsupported
0329 register. For such chips, checking the status register is mandatory when
0330 trying to determine if a chip register exists or not.
0331 Other PMBus chips don't support the STATUS_CML register, or report
0332 communication errors for no explicable reason. For such chips, checking the
0333 status register must be disabled.
0334 
0335 Some i2c controllers do not support single-byte commands (write commands with
0336 no data, i2c_smbus_write_byte()). With such controllers, clearing the status
0337 register is impossible, and the PMBUS_SKIP_STATUS_CHECK flag must be set.
0338 
0339 PMBUS_WRITE_PROTECTED
0340 
0341 Set if the chip is write protected and write protection is not determined
0342 by the standard WRITE_PROTECT command.
0343 
0344 PMBUS_NO_CAPABILITY
0345 
0346 Some PMBus chips don't respond with valid data when reading the CAPABILITY
0347 register. For such chips, this flag should be set so that the PMBus core
0348 driver doesn't use CAPABILITY to determine it's behavior.
0349 
0350 PMBUS_READ_STATUS_AFTER_FAILED_CHECK
0351 
0352 Read the STATUS register after each failed register check.
0353 
0354 Some PMBus chips end up in an undefined state when trying to read an
0355 unsupported register. For such chips, it is necessary to reset the
0356 chip pmbus controller to a known state after a failed register check.
0357 This can be done by reading a known register. By setting this flag the
0358 driver will try to read the STATUS register after each failed
0359 register check. This read may fail, but it will put the chip into a
0360 known state.