@@ -1615,132 +1615,6 @@ static bool pwm_ops_check(const struct pwm_chip *chip)
16151615 return true;
16161616}
16171617
1618- /**
1619- * __pwmchip_add() - register a new PWM chip
1620- * @chip: the PWM chip to add
1621- * @owner: reference to the module providing the chip.
1622- *
1623- * Register a new PWM chip. @owner is supposed to be THIS_MODULE, use the
1624- * pwmchip_add wrapper to do this right.
1625- *
1626- * Returns: 0 on success or a negative error code on failure.
1627- */
1628- int __pwmchip_add (struct pwm_chip * chip , struct module * owner )
1629- {
1630- int ret ;
1631-
1632- if (!chip || !pwmchip_parent (chip ) || !chip -> ops || !chip -> npwm )
1633- return - EINVAL ;
1634-
1635- /*
1636- * a struct pwm_chip must be allocated using (devm_)pwmchip_alloc,
1637- * otherwise the embedded struct device might disappear too early
1638- * resulting in memory corruption.
1639- * Catch drivers that were not converted appropriately.
1640- */
1641- if (!chip -> uses_pwmchip_alloc )
1642- return - EINVAL ;
1643-
1644- if (!pwm_ops_check (chip ))
1645- return - EINVAL ;
1646-
1647- chip -> owner = owner ;
1648-
1649- if (chip -> atomic )
1650- spin_lock_init (& chip -> atomic_lock );
1651- else
1652- mutex_init (& chip -> nonatomic_lock );
1653-
1654- guard (mutex )(& pwm_lock );
1655-
1656- ret = idr_alloc (& pwm_chips , chip , 0 , 0 , GFP_KERNEL );
1657- if (ret < 0 )
1658- return ret ;
1659-
1660- chip -> id = ret ;
1661-
1662- dev_set_name (& chip -> dev , "pwmchip%u" , chip -> id );
1663-
1664- if (IS_ENABLED (CONFIG_OF ))
1665- of_pwmchip_add (chip );
1666-
1667- scoped_guard (pwmchip , chip )
1668- chip -> operational = true;
1669-
1670- ret = device_add (& chip -> dev );
1671- if (ret )
1672- goto err_device_add ;
1673-
1674- return 0 ;
1675-
1676- err_device_add :
1677- scoped_guard (pwmchip , chip )
1678- chip -> operational = false;
1679-
1680- if (IS_ENABLED (CONFIG_OF ))
1681- of_pwmchip_remove (chip );
1682-
1683- idr_remove (& pwm_chips , chip -> id );
1684-
1685- return ret ;
1686- }
1687- EXPORT_SYMBOL_GPL (__pwmchip_add );
1688-
1689- /**
1690- * pwmchip_remove() - remove a PWM chip
1691- * @chip: the PWM chip to remove
1692- *
1693- * Removes a PWM chip.
1694- */
1695- void pwmchip_remove (struct pwm_chip * chip )
1696- {
1697- pwmchip_sysfs_unexport (chip );
1698-
1699- scoped_guard (mutex , & pwm_lock ) {
1700- unsigned int i ;
1701-
1702- scoped_guard (pwmchip , chip )
1703- chip -> operational = false;
1704-
1705- for (i = 0 ; i < chip -> npwm ; ++ i ) {
1706- struct pwm_device * pwm = & chip -> pwms [i ];
1707-
1708- if (test_and_clear_bit (PWMF_REQUESTED , & pwm -> flags )) {
1709- dev_warn (& chip -> dev , "Freeing requested PWM #%u\n" , i );
1710- if (pwm -> chip -> ops -> free )
1711- pwm -> chip -> ops -> free (pwm -> chip , pwm );
1712- }
1713- }
1714-
1715- if (IS_ENABLED (CONFIG_OF ))
1716- of_pwmchip_remove (chip );
1717-
1718- idr_remove (& pwm_chips , chip -> id );
1719- }
1720-
1721- device_del (& chip -> dev );
1722- }
1723- EXPORT_SYMBOL_GPL (pwmchip_remove );
1724-
1725- static void devm_pwmchip_remove (void * data )
1726- {
1727- struct pwm_chip * chip = data ;
1728-
1729- pwmchip_remove (chip );
1730- }
1731-
1732- int __devm_pwmchip_add (struct device * dev , struct pwm_chip * chip , struct module * owner )
1733- {
1734- int ret ;
1735-
1736- ret = __pwmchip_add (chip , owner );
1737- if (ret )
1738- return ret ;
1739-
1740- return devm_add_action_or_reset (dev , devm_pwmchip_remove , chip );
1741- }
1742- EXPORT_SYMBOL_GPL (__devm_pwmchip_add );
1743-
17441618static struct device_link * pwm_device_link_add (struct device * dev ,
17451619 struct pwm_device * pwm )
17461620{
@@ -1918,36 +1792,6 @@ static struct pwm_device *acpi_pwm_get(const struct fwnode_handle *fwnode)
19181792static DEFINE_MUTEX (pwm_lookup_lock );
19191793static LIST_HEAD (pwm_lookup_list );
19201794
1921- /**
1922- * pwm_add_table() - register PWM device consumers
1923- * @table: array of consumers to register
1924- * @num: number of consumers in table
1925- */
1926- void pwm_add_table (struct pwm_lookup * table , size_t num )
1927- {
1928- guard (mutex )(& pwm_lookup_lock );
1929-
1930- while (num -- ) {
1931- list_add_tail (& table -> list , & pwm_lookup_list );
1932- table ++ ;
1933- }
1934- }
1935-
1936- /**
1937- * pwm_remove_table() - unregister PWM device consumers
1938- * @table: array of consumers to unregister
1939- * @num: number of consumers in table
1940- */
1941- void pwm_remove_table (struct pwm_lookup * table , size_t num )
1942- {
1943- guard (mutex )(& pwm_lookup_lock );
1944-
1945- while (num -- ) {
1946- list_del (& table -> list );
1947- table ++ ;
1948- }
1949- }
1950-
19511795/**
19521796 * pwm_get() - look up and request a PWM device
19531797 * @dev: device for PWM consumer
@@ -2174,6 +2018,162 @@ struct pwm_device *devm_fwnode_pwm_get(struct device *dev,
21742018}
21752019EXPORT_SYMBOL_GPL (devm_fwnode_pwm_get );
21762020
2021+ /**
2022+ * __pwmchip_add() - register a new PWM chip
2023+ * @chip: the PWM chip to add
2024+ * @owner: reference to the module providing the chip.
2025+ *
2026+ * Register a new PWM chip. @owner is supposed to be THIS_MODULE, use the
2027+ * pwmchip_add wrapper to do this right.
2028+ *
2029+ * Returns: 0 on success or a negative error code on failure.
2030+ */
2031+ int __pwmchip_add (struct pwm_chip * chip , struct module * owner )
2032+ {
2033+ int ret ;
2034+
2035+ if (!chip || !pwmchip_parent (chip ) || !chip -> ops || !chip -> npwm )
2036+ return - EINVAL ;
2037+
2038+ /*
2039+ * a struct pwm_chip must be allocated using (devm_)pwmchip_alloc,
2040+ * otherwise the embedded struct device might disappear too early
2041+ * resulting in memory corruption.
2042+ * Catch drivers that were not converted appropriately.
2043+ */
2044+ if (!chip -> uses_pwmchip_alloc )
2045+ return - EINVAL ;
2046+
2047+ if (!pwm_ops_check (chip ))
2048+ return - EINVAL ;
2049+
2050+ chip -> owner = owner ;
2051+
2052+ if (chip -> atomic )
2053+ spin_lock_init (& chip -> atomic_lock );
2054+ else
2055+ mutex_init (& chip -> nonatomic_lock );
2056+
2057+ guard (mutex )(& pwm_lock );
2058+
2059+ ret = idr_alloc (& pwm_chips , chip , 0 , 0 , GFP_KERNEL );
2060+ if (ret < 0 )
2061+ return ret ;
2062+
2063+ chip -> id = ret ;
2064+
2065+ dev_set_name (& chip -> dev , "pwmchip%u" , chip -> id );
2066+
2067+ if (IS_ENABLED (CONFIG_OF ))
2068+ of_pwmchip_add (chip );
2069+
2070+ scoped_guard (pwmchip , chip )
2071+ chip -> operational = true;
2072+
2073+ ret = device_add (& chip -> dev );
2074+ if (ret )
2075+ goto err_device_add ;
2076+
2077+ return 0 ;
2078+
2079+ err_device_add :
2080+ scoped_guard (pwmchip , chip )
2081+ chip -> operational = false;
2082+
2083+ if (IS_ENABLED (CONFIG_OF ))
2084+ of_pwmchip_remove (chip );
2085+
2086+ idr_remove (& pwm_chips , chip -> id );
2087+
2088+ return ret ;
2089+ }
2090+ EXPORT_SYMBOL_GPL (__pwmchip_add );
2091+
2092+ /**
2093+ * pwmchip_remove() - remove a PWM chip
2094+ * @chip: the PWM chip to remove
2095+ *
2096+ * Removes a PWM chip.
2097+ */
2098+ void pwmchip_remove (struct pwm_chip * chip )
2099+ {
2100+ pwmchip_sysfs_unexport (chip );
2101+
2102+ scoped_guard (mutex , & pwm_lock ) {
2103+ unsigned int i ;
2104+
2105+ scoped_guard (pwmchip , chip )
2106+ chip -> operational = false;
2107+
2108+ for (i = 0 ; i < chip -> npwm ; ++ i ) {
2109+ struct pwm_device * pwm = & chip -> pwms [i ];
2110+
2111+ if (test_and_clear_bit (PWMF_REQUESTED , & pwm -> flags )) {
2112+ dev_warn (& chip -> dev , "Freeing requested PWM #%u\n" , i );
2113+ if (pwm -> chip -> ops -> free )
2114+ pwm -> chip -> ops -> free (pwm -> chip , pwm );
2115+ }
2116+ }
2117+
2118+ if (IS_ENABLED (CONFIG_OF ))
2119+ of_pwmchip_remove (chip );
2120+
2121+ idr_remove (& pwm_chips , chip -> id );
2122+ }
2123+
2124+ device_del (& chip -> dev );
2125+ }
2126+ EXPORT_SYMBOL_GPL (pwmchip_remove );
2127+
2128+ static void devm_pwmchip_remove (void * data )
2129+ {
2130+ struct pwm_chip * chip = data ;
2131+
2132+ pwmchip_remove (chip );
2133+ }
2134+
2135+ int __devm_pwmchip_add (struct device * dev , struct pwm_chip * chip , struct module * owner )
2136+ {
2137+ int ret ;
2138+
2139+ ret = __pwmchip_add (chip , owner );
2140+ if (ret )
2141+ return ret ;
2142+
2143+ return devm_add_action_or_reset (dev , devm_pwmchip_remove , chip );
2144+ }
2145+ EXPORT_SYMBOL_GPL (__devm_pwmchip_add );
2146+
2147+ /**
2148+ * pwm_add_table() - register PWM device consumers
2149+ * @table: array of consumers to register
2150+ * @num: number of consumers in table
2151+ */
2152+ void pwm_add_table (struct pwm_lookup * table , size_t num )
2153+ {
2154+ guard (mutex )(& pwm_lookup_lock );
2155+
2156+ while (num -- ) {
2157+ list_add_tail (& table -> list , & pwm_lookup_list );
2158+ table ++ ;
2159+ }
2160+ }
2161+
2162+ /**
2163+ * pwm_remove_table() - unregister PWM device consumers
2164+ * @table: array of consumers to unregister
2165+ * @num: number of consumers in table
2166+ */
2167+ void pwm_remove_table (struct pwm_lookup * table , size_t num )
2168+ {
2169+ guard (mutex )(& pwm_lookup_lock );
2170+
2171+ while (num -- ) {
2172+ list_del (& table -> list );
2173+ table ++ ;
2174+ }
2175+ }
2176+
21772177static void pwm_dbg_show (struct pwm_chip * chip , struct seq_file * s )
21782178{
21792179 unsigned int i ;
0 commit comments