+
     vi0  c                   s   R t ^ RIt^ RIt^ RIt^ RIHt ^ RIHt ^ RIH	t	H
t
Ht ^ RIHtHt ]P                  ! ]4      t]P$                  R8X  d%   ^ RIHt ]! RR	4      t ! R
 R]
4      t ! R R4      t ! R R]	4      tR# )zBase SMBus bus and driver APIs.

For now, these are unstable APIs, and only Linux is supported.

Copyright Jonas Malaco and contributors
SPDX-License-Identifier: GPL-3.0-or-later
N)
namedtuple)Path)
BaseDriverBaseBusfind_all_subclasses)check_unsafeLazyHexReprlinux)SMBusLinuxEepromz	name datac                   s8   a  ] tR t^t o RtRR ltRR ltRtV tR# )LinuxI2cu$   The Linux I²C (`/sys/bus/i2c`) bus.c                s&    \        V4      V n        R # N)r   	_i2c_root)selfZi2c_root   &&;/usr/lib/python3.14/site-packages/liquidctl/driver/smbus.py__init__ZLinuxI2c.__init__"   s    !(^DN    Nc           
   +  s  "   V'       d   R# V P                   P                  R4      pVP                  4       '       g.   \        P	                  RV P
                  P                  V4       R# \        \        \        4      R R7      p\        P	                  RV P
                  P                  4       \        P	                  RV P
                  P                  RP                  \        R	 V4      4      4       VP                  4        Fy  p \        V4      pT'       d   YP                  8w  d   K)  \        P	                  RTP                  TP                   ;'       g    R4       TP"                  ! T3/ TB  Rj  xL
  K{  	  R#   \         d-   p\        P	                  R
TP                  T4        Rp?K  Rp?ii ; i LD5i)zFind compatible SMBus devices.Ndeviceszskipping %s, %s not availablec                     V P                   # r   __name__x   &r   <lambda>'LinuxI2c.find_devices.<locals>.<lambda>3   s    1::r   )Zkeyzsearching %sz%s drivers: %sz, c                 r   r   r   r   r   r   r   r   9   s    

r   u   I²C adapter: %s skipped: %su   I²C adapter: %s (%s)zN/A)r   joinpathexists_LOGGERdebug	__class__r   Zsortedr   SmbusDriverZjoinZmapZiterdirLinuxI2cBus
ValueErrornamedescriptionfind_devices)	r   busZusb_portkwargsr   driversi2c_devZi2c_buserrs	   &&&,     r   r%   ZLinuxI2c.find_devices%   sP     nn--i8G>>##="nn55w@0=!57G MM.$..*A*ABMM ''		#2G<= #??,)'2G
 3,,.5w||WEXEXEaEa\ab"//B6BBB - " MM"@',,PST CsM   ;G C
G 	FG ?G G 9F>:
G F;!F60G 6F;;G )r   )z/sys/bus/i2c)NN)	r   
__module____qualname____firstlineno____doc__r   r%   __static_attributes____classdictcell__Z__classdict__   @r   r
   r
      s     2	,"	C "	Cr   r
   c                   s
  a  ] tR t^It o RtR tR tR tR tR t	R t
R tR	 tR
 tR tR tR tR t]R 4       t]R 4       t]R 4       t]R 4       t]R 4       t]R 4       t]R 4       tR tR tRR/R ltRR/R ltRtV tR# )r!   u  A Linux I²C device, which is itself an I²C bus.

Should not be instantiated directly; use `LinuxI2c.find_devices`
instead.

This type mimics the `smbus.SMBus` read/write/close APIs.  However,
`open` does not take any parameters, and not all APIs are available.
c                s    VP                   P                  R 4      '       g   \        R4      hWn        RV n        \        VP                   R,          4      V n        R# )zi2c-z not a bus or unsupported adapterN:i   NN)r#   Z
startswithr"   _i2c_dev_smbusint_number)r   r)   r   r   r   ZLinuxI2cBus.__init__V   sD    <<**622 !CDD#MDKw||B/0DLr   c              +  sZ   "   V F  pVP                   ! V 3/ VB  Rj  xL
  K   	  R#  L
5i)z6Probe drivers and find compatible devices in this bus.N)probe)r   r(   r'   Zdrvs   &&, r   r%   ZLinuxI2cBus.find_devices^   s)     99T4V444 4s   +)+c                s    V P                   '       g    \        V P                  4      V n         R# R#   \         d.    \	        R4      P                  4       '       d   h \        R4      Rhi ; i)u   Open the I²C bus.z/sys/class/i2c-devz kernel module i2c-dev not loadedN)r4   r   r6   FileNotFoundErrorr   r   OSErrorr   r   r   openZLinuxI2cBus.openc   s_    ;;;P"'"5DK  ) P0188::!"DE4OPs	   2 8A*c                sh    V P                   P                  V4      p\        P                  RW4       V# )z!Read a single byte from a device.zread byte @ 0x%02x:0x%02x)r4   	read_byter   r   r   addressvalues   && r   r<   ZLinuxI2cBus.read_bytem   s*    KK))'2EMM5wFLr   c                j    V P                   P                  W4      p\        P                  RWV4       V# )z.Read a single byte from a designated register.z%read byte data @ 0x%02x:0x%02x 0x%02x)r4   read_byte_datar   r   r   r>   registerr?      &&& r   rA   ZLinuxI2cBus.read_byte_datas   /    KK..wAEMMA!U4Lr   c                r@   )z0Read a single 2-byte word from a given register.z%read word data @ 0x%02x:0x%02x 0x%02x)r4   read_word_datar   r   rB   rD   r   rF   ZLinuxI2cBus.read_word_dataz   rE   r   c                s|    V P                   P                  W4      p\        P                  RW\	        V4      4       V# )z6Read a block of up to  32 bytes from a given register.z#read block data @ 0x%02x:0x%02x: %r)r4   read_block_datar   r   r   r   r>   rC   ZdatarD   r   rG   ZLinuxI2cBus.read_block_data   s5    ;;..wADMM?![->@Kr   c                sd    \         P                  RW4       V P                  P                  W4      # )z Write a single byte to a device.zwriting byte @ 0x%02x: 0x%02x)r   r   r4   
write_byter=   s   &&&r   rI   ZLinuxI2cBus.write_byte   s&    MM97J;;))'99r   c                h    \         P                  RWV4       V P                  P                  WV4      # )z-Write a single byte to a designated register.z(writing byte data @ 0x%02x:0x%02x 0x%02x)r   r   r4   write_byte_datarB      &&&&r   rK   ZLinuxI2cBus.write_byte_data   -    MMD!U4;;..w%HHr   c                rJ   )z4Write a single 2-byte word to a designated register.z(writing word data @ 0x%02x:0x%02x 0x%02x)r   r   r4   write_word_datarB   rL   r   rN   ZLinuxI2cBus.write_word_data   rM   r   c                sz    \         P                  RW\        V4      4       V P                  P	                  WV4      # )z/Write a block of byte data to a given register.z%writing block data @ 0x%02x:0x%02x %r)r   r   r   r4   write_block_datarH   rL   r   rO   ZLinuxI2cBus.write_block_data   s3    MMA![->@;;//4HHr   c                sp    V P                   '       d$   V P                   P                  4        RV n         R# R# )u   Close the I²C connection.Nr4   closer:   r   r   rQ   ZLinuxI2cBus.close   s'    {{{!!#" r   c                s   V P                    RVR 2p V P                  P                  VR4      P                  4       P	                  4       pV P                  P                  VR4      P                  4       p\        W44      #   \         d     R# \         d=   p\        P                  RT P                  P                  TR4      T4        Rp?R# Rp?ii ; i)z9Return EEPROM name and data in `address`, or None if N/A.Z-Z04xr#   eepromNz%s exists but not readable: %r)r6   r3   r   	read_textZstripZ
read_bytesr	   r8   r9   r   r   )r   r>   Zdevr#   rR   r*   s   &&    r   load_eepromZLinuxI2cBus.load_eeprom   s     \\N!GC=1C	}}--c6:DDFLLN//X>IIK"400$  >"mm44S(CSJs$   A,B CCC1CCc                .    V P                   P                  # r   )r3   r#   r:   r   r   r#   ZLinuxI2cBus.name   s    ==%%%r   c                $    V P                  R 4      # )r#   )_try_sysfs_readr:   r   r   r$   ZLinuxI2cBus.description   s    ''//r   c                rV   )zdevice/vendor_try_sysfs_read_hexr:   r   r   parent_vendorZLinuxI2cBus.parent_vendor       ++O<<r   c                rV   )zdevice/devicerX   r:   r   r   parent_deviceZLinuxI2cBus.parent_device   r[   r   c                rV   )zdevice/subsystem_vendorrX   r:   r   r   parent_subsystem_vendorZ#LinuxI2cBus.parent_subsystem_vendor       ++,EFFr   c                rV   )zdevice/subsystem_devicerX   r:   r   r   parent_subsystem_deviceZ#LinuxI2cBus.parent_subsystem_device   r^   r   c                s     \        \        P                  ! V P                  P	                  R 4      4      4      P
                  #   \         d     R# i ; i)zdevice/driverN)r   osZreadlinkr3   r   r#   r8   r:   r   r   parent_driverZLinuxI2cBus.parent_driver   sB    BKK(>(>(OPQVVV$ s   AA AAc                st    V P                   '       d   V P                   R V P                    2# V P                  # )z: )r$   r#   r:   r   r   __str__ZLinuxI2cBus.__str__   s4    ))Bt'7'7&89999r   c                s$   R  pV P                   P                   RV P                  : RV P                  : RV! V P                  4       RV! V P
                  4       RV! V P                  4       RV! V P                  4       RV P                  : 2# )c                 s    V e   V R # R# )Nz#06xZNone )Zmayber   r   hexidZ#LinuxI2cBus.__repr__.<locals>.hexid   s    $#D\*r   z: name: z, description: z, parent_vendor: z, parent_device: z, parent_subsystem_vendor: z, parent_subsystem_device: z, parent_driver: )	r   r   r#   r$   rZ   r\   r]   r_   ra   )r   rd   s   & r   __repr__ZLinuxI2cBus.__repr__   s    
 nn--.htyym D''**;E$BTBT<U;V W&&+D,>,>&?%@ AT99:; <005d6R6R0S/T U&&*&8&8%;= =r   defaultNc               s     V P                   P                  ! V!  P                  4       P                  4       #   \         d    Tu # i ; ir   )r3   r   rS   Zrstripr8   r   rf   Zsub   &$*r   rW   ZLinuxI2cBus._try_sysfs_read   sB    }}--s3==?FFHH$ s   58 AAc               s     \        V P                  P                  ! V!  P                  4       ^R7      #   \         d    Tu # i ; i)i   )Zbase)r5   r3   r   rS   r8   rg   rh   r   rY   ZLinuxI2cBus._try_sysfs_read_hex   s@    4==1137AAC"MM$ s   25 AA)r3   r6   r4   ) r   r+   r,   r-   r.   r   r%   r;   r<   rA   rF   rG   rI   rK   rN   rO   rQ   rT   propertyr#   r$   rZ   r\   r]   r_   ra   rb   re   rW   rY   r/   r0   r1   r2   r   r!   r!   I   s    		1	5
	P					:
	I	I	I	#	$ 
	& 
	& 
	0 
	0 
	= 
	= 
	= 
	= 
	G 
	G 
	G 
	G 
	 
		
	=	 		D 	 	r   r!   c                   s   a  ] tR t^t o Rt]R 4       t]RR l4       tRR ltR t	R t
]R 4       t]R	 4       t]R
 4       t]R 4       t]R 4       t]R 4       t]R 4       t]R 4       tRtV tR# )r    z$Base driver class for SMBus devices.c                s    \        4       hr   )ZNotImplementedError)clssmbusr'   s   &&,r   r7   ZSmbusDriver.probe   s    !##r   Nc                s   a  \         P                  R8w  d   . # V'       g   \        4       p\        V 3R lVP                  ! R/ VB 4      p\        V4      # )z6Find devices specifically compatible with this driver.r   c                 s   < \        V S4      # r   )Z
isinstance)r   rj   s   &r   r   Z4SmbusDriver.find_supported_devices.<locals>.<lambda>  s    
1c 2r   rc   )sysplatformr
   Zfilterr%   Zlist)rj   Zroot_busr'   Zdevss   f&, r   find_supported_devicesZ"SmbusDriver.find_supported_devices   sH     <<7"IzH2++5f57Dzr   c                sN    Vf   Q hWn         W n        W0n        W@n        WPn        R # r   )r4   _description
_vendor_id_product_id_address)r   rk   r$   	vendor_id
product_idr>   r'   s   &&&&&&,r   r   ZSmbusDriver.__init__	  s+     """'#%r   c                s    \        R/ VB '       d   V P                  P                  4        V # \        P	                  R4       V # )zConnect to the device.z.SMBus disabled, missing unsafe feature 'smbus')rk   )r   r4   r;   r   r   r   r'      &,r   connectZSmbusDriver.connect  s;    *6**KK  MMJKr   c                s:    V P                   P                  4        R# )zDisconnect from the device.NrP   ru   rv   r   
disconnectZSmbusDriver.disconnect(  s    r   c                r   )z7Human readable description of the corresponding device.)ro   r:   r   r   r$   ZSmbusDriver.description,  s        r   c                r   )z*Numeric vendor identifier, or None if N/A.)rp   r:   r   r   rs   ZSmbusDriver.vendor_id1  s     r   c                r   )z+Numeric product identifier, or None if N/A.)rq   r:   r   r   rt   ZSmbusDriver.product_id6  s     r   c                    R# )zMDevice versioning number, or None if N/A.

In USB devices this is bcdDevice.
Nrc   r:   r   r   release_numberZSmbusDriver.release_number;  s     r   c                ry   )z5Serial number reported by the device, or None if N/A.Nrc   r:   r   r   serial_numberZSmbusDriver.serial_numberC       r   c                rU   )z/Bus the device is connected to, or None if N/A.)r4   r#   r:   r   r   r&   ZSmbusDriver.busH  s     {{r   c                s    V P                   R # )z?Address of the device on the corresponding bus, or None if N/A.z#04x)rr   r:   r   r   r>   ZSmbusDriver.addressM  s     --%&r   c                ry   )z0Physical location of the device, or None if N/A.Nrc   r:   r   r   portZSmbusDriver.portR  r|   r   )rr   ro   rq   r4   rp   r   )NNN)r   r+   r,   r-   r.   Zclassmethodr7   rn   r   rw   rx   ri   r$   rs   rt   rz   r{   r&   r>   r}   r/   r0   r1   r2   r   r    r       s     .$ $ 
 
 " ! !               ' '  r   r    )r.   Zloggingr`   rl   Zcollectionsr    Zpathlibr   Zliquidctl.driver.baser   r   r   Zliquidctl.utilr   r   Z	getLoggerr   r   rm   rk   r   r	   r
   r!   r    rc   r   r   <module>r~      s}     	 
 "  J J 4


H
% <<7 ]K8K(C7 (CTi iX`* `r   