Lines Matching refs:sl

101 #define SLAVE_SPECIFIC_FUNC(sl) \
102 (((struct w1_therm_family_data *)(sl->family_data))->specific_functions)
105 * return the power mode of the sl slave : 1-ext, 0-parasite, <0 unknown
108 #define SLAVE_POWERMODE(sl) \
109 (((struct w1_therm_family_data *)(sl->family_data))->external_powered)
112 * return the resolution in bit of the sl slave : <0 unknown
115 #define SLAVE_RESOLUTION(sl) \
116 (((struct w1_therm_family_data *)(sl->family_data))->resolution)
119 * return the conv_time_override of the sl slave
122 #define SLAVE_CONV_TIME_OVERRIDE(sl) \
123 (((struct w1_therm_family_data *)(sl->family_data))->conv_time_override)
126 * return the features of the sl slave
129 #define SLAVE_FEATURES(sl) \
130 (((struct w1_therm_family_data *)(sl->family_data))->features)
138 #define SLAVE_CONVERT_TRIGGERED(sl) \
139 (((struct w1_therm_family_data *)(sl->family_data))->convert_triggered)
164 int (*get_conversion_time)(struct w1_slave *sl);
165 int (*set_resolution)(struct w1_slave *sl, int val);
166 int (*get_resolution)(struct w1_slave *sl);
167 int (*write_data)(struct w1_slave *sl, const u8 *data);
211 * @sl: the slave to select
216 * At the beginning of the such process, sl->master->slave_count is 1 even if
223 static int reset_select_slave(struct w1_slave *sl);
227 * @sl: pointer to the slave to read
232 static int convert_t(struct w1_slave *sl, struct therm_info *info);
236 * @sl: pointer to the slave to read
241 static int read_scratchpad(struct w1_slave *sl, struct therm_info *info);
245 * @sl: pointer to the slave to write in
251 static int write_scratchpad(struct w1_slave *sl, const u8 *data, u8 nb_bytes);
255 * @sl: slave involved
259 static int copy_scratchpad(struct w1_slave *sl);
263 * @sl: slave involved
267 static int recall_eeprom(struct w1_slave *sl);
271 * @sl: slave to retrieve the power mode
281 static int read_powermode(struct w1_slave *sl);
364 * @sl: slave just discovered by the master.
371 static int w1_therm_add_slave(struct w1_slave *sl);
375 * @sl: slave to be removed.
380 static void w1_therm_remove_slave(struct w1_slave *sl);
528 static inline int w1_DS18B20_convert_time(struct w1_slave *sl)
532 if (!sl->family_data)
535 if (SLAVE_CONV_TIME_OVERRIDE(sl) != CONV_TIME_DEFAULT)
536 return SLAVE_CONV_TIME_OVERRIDE(sl);
541 switch (SLAVE_RESOLUTION(sl)) {
566 static inline int w1_DS18S20_convert_time(struct w1_slave *sl)
568 if (!sl->family_data)
571 if (SLAVE_CONV_TIME_OVERRIDE(sl) == CONV_TIME_DEFAULT)
574 return SLAVE_CONV_TIME_OVERRIDE(sl);
577 static inline int w1_DS1825_convert_time(struct w1_slave *sl)
581 if (!sl->family_data)
584 if (SLAVE_CONV_TIME_OVERRIDE(sl) != CONV_TIME_DEFAULT)
585 return SLAVE_CONV_TIME_OVERRIDE(sl);
590 switch (SLAVE_RESOLUTION(sl)) {
612 static inline int w1_DS18B20_write_data(struct w1_slave *sl,
615 return write_scratchpad(sl, data, 3);
618 static inline int w1_DS18S20_write_data(struct w1_slave *sl,
622 return write_scratchpad(sl, data, 2);
625 static inline int w1_DS18B20_set_resolution(struct w1_slave *sl, int val)
643 ret = read_scratchpad(sl, &info);
653 ret = w1_DS18B20_write_data(sl, info.rom + 2);
661 ret = read_scratchpad(sl, &info2);
673 static inline int w1_DS18B20_get_resolution(struct w1_slave *sl)
679 ret = read_scratchpad(sl, &info);
840 * @sl: slave to retrieve the device specific structure
844 static struct w1_therm_family_converter *device_family(struct w1_slave *sl)
850 if (w1_therm_families[i].f->fid == sl->family->fid) {
888 * @sl: W1 device data
892 static int check_family_data(struct w1_slave *sl)
894 if ((!sl->family_data) || (!SLAVE_SPECIFIC_FUNC(sl))) {
895 dev_info(&sl->dev,
904 * @sl: device to check the ability
908 static inline bool bulk_read_support(struct w1_slave *sl)
910 if (SLAVE_SPECIFIC_FUNC(sl))
911 return SLAVE_SPECIFIC_FUNC(sl)->bulk_read;
913 dev_info(&sl->dev,
921 * @sl: device to get the conversion time
929 static inline int conversion_time(struct w1_slave *sl)
931 if (SLAVE_SPECIFIC_FUNC(sl))
932 return SLAVE_SPECIFIC_FUNC(sl)->get_conversion_time(sl);
934 dev_info(&sl->dev,
942 * @sl: device that sent the RAM data
949 static inline int temperature_from_RAM(struct w1_slave *sl, u8 rom[9])
951 if (SLAVE_SPECIFIC_FUNC(sl))
952 return SLAVE_SPECIFIC_FUNC(sl)->convert(rom);
954 dev_info(&sl->dev,
981 static int w1_therm_add_slave(struct w1_slave *sl)
986 sl->family_data = kzalloc(sizeof(struct w1_therm_family_data),
988 if (!sl->family_data)
991 atomic_set(THERM_REFCNT(sl->family_data), 1);
994 sl_family_conv = device_family(sl);
996 kfree(sl->family_data);
1000 SLAVE_SPECIFIC_FUNC(sl) = sl_family_conv;
1002 if (bulk_read_support(sl)) {
1008 int err = device_create_file(&sl->master->dev,
1012 dev_warn(&sl->dev,
1021 SLAVE_POWERMODE(sl) = read_powermode(sl);
1023 if (SLAVE_POWERMODE(sl) < 0) {
1025 dev_warn(&sl->dev,
1027 __func__, SLAVE_POWERMODE(sl));
1031 if (SLAVE_SPECIFIC_FUNC(sl)->get_resolution) {
1032 SLAVE_RESOLUTION(sl) =
1033 SLAVE_SPECIFIC_FUNC(sl)->get_resolution(sl);
1034 if (SLAVE_RESOLUTION(sl) < 0) {
1036 dev_warn(&sl->dev,
1038 __func__, SLAVE_RESOLUTION(sl));
1043 SLAVE_CONVERT_TRIGGERED(sl) = 0;
1048 static void w1_therm_remove_slave(struct w1_slave *sl)
1050 int refcnt = atomic_sub_return(1, THERM_REFCNT(sl->family_data));
1052 if (bulk_read_support(sl)) {
1056 device_remove_file(&sl->master->dev,
1062 refcnt = atomic_read(THERM_REFCNT(sl->family_data));
1064 kfree(sl->family_data);
1065 sl->family_data = NULL;
1071 static int reset_select_slave(struct w1_slave *sl)
1074 u64 rn = le64_to_cpu(*((u64 *)&sl->reg_num));
1076 if (w1_reset_bus(sl->master))
1080 w1_write_block(sl->master, match, 9);
1113 static int convert_t(struct w1_slave *sl, struct therm_info *info)
1115 struct w1_master *dev_master = sl->master;
1121 if (!sl->family_data)
1125 (!SLAVE_POWERMODE(sl) &&
1128 if (strong_pullup && SLAVE_FEATURES(sl) & W1_THERM_POLL_COMPLETION) {
1129 dev_warn(&sl->dev,
1132 SLAVE_FEATURES(sl) &= ~W1_THERM_POLL_COMPLETION;
1136 t_conv = conversion_time(sl);
1141 atomic_inc(THERM_REFCNT(sl->family_data));
1153 if (!reset_select_slave(sl)) {
1162 if (SLAVE_FEATURES(sl) & W1_THERM_POLL_COMPLETION) {
1165 dev_dbg(&sl->dev, "%s: Timeout\n", __func__);
1184 ret = read_scratchpad(sl, info);
1187 if ((SLAVE_FEATURES(sl) & W1_THERM_CHECK_RESULT) &&
1207 atomic_dec(THERM_REFCNT(sl->family_data));
1212 static int conv_time_measure(struct w1_slave *sl, int *conv_time)
1216 struct w1_master *dev_master = sl->master;
1221 if (!sl->family_data)
1225 (!SLAVE_POWERMODE(sl) &&
1236 atomic_inc(THERM_REFCNT(sl->family_data));
1247 if (!reset_select_slave(sl)) {
1256 dev_dbg(&sl->dev, "%s: Timeout\n", __func__);
1269 ret = read_scratchpad(sl, info);
1277 atomic_dec(THERM_REFCNT(sl->family_data));
1282 static int read_scratchpad(struct w1_slave *sl, struct therm_info *info)
1284 struct w1_master *dev_master = sl->master;
1290 if (!sl->family_data)
1296 atomic_inc(THERM_REFCNT(sl->family_data));
1305 if (!reset_select_slave(sl)) {
1312 dev_warn(&sl->dev,
1331 atomic_dec(THERM_REFCNT(sl->family_data));
1336 static int write_scratchpad(struct w1_slave *sl, const u8 *data, u8 nb_bytes)
1338 struct w1_master *dev_master = sl->master;
1342 if (!sl->family_data)
1346 atomic_inc(THERM_REFCNT(sl->family_data));
1355 if (!reset_select_slave(sl)) {
1364 atomic_dec(THERM_REFCNT(sl->family_data));
1369 static int copy_scratchpad(struct w1_slave *sl)
1371 struct w1_master *dev_master = sl->master;
1376 if (!sl->family_data)
1381 (!SLAVE_POWERMODE(sl) &&
1385 atomic_inc(THERM_REFCNT(sl->family_data));
1394 if (!reset_select_slave(sl)) {
1418 atomic_dec(THERM_REFCNT(sl->family_data));
1423 static int recall_eeprom(struct w1_slave *sl)
1425 struct w1_master *dev_master = sl->master;
1429 if (!sl->family_data)
1433 atomic_inc(THERM_REFCNT(sl->family_data));
1442 if (!reset_select_slave(sl)) {
1453 atomic_dec(THERM_REFCNT(sl->family_data));
1458 static int read_powermode(struct w1_slave *sl)
1460 struct w1_master *dev_master = sl->master;
1464 if (!sl->family_data)
1468 atomic_inc(THERM_REFCNT(sl->family_data));
1477 if (!reset_select_slave(sl)) {
1491 atomic_dec(THERM_REFCNT(sl->family_data));
1498 struct w1_slave *sl = NULL; /* used to iterate through slaves */
1509 list_for_each_entry(sl, &dev_master->slist, w1_slave_entry) {
1510 if (!sl->family_data)
1512 if (bulk_read_support(sl)) {
1513 int t_cur = conversion_time(sl);
1518 (!SLAVE_POWERMODE(sl) &&
1548 list_for_each_entry(sl,
1550 if (bulk_read_support(sl))
1551 SLAVE_CONVERT_TRIGGERED(sl) = -1;
1578 list_for_each_entry(sl, &dev_master->slist, w1_slave_entry) {
1579 if (bulk_read_support(sl))
1580 SLAVE_CONVERT_TRIGGERED(sl) = 1;
1591 struct w1_slave *sl = dev_to_w1_slave(device);
1593 u8 *family_data = sl->family_data;
1597 if (bulk_read_support(sl)) {
1598 if (SLAVE_CONVERT_TRIGGERED(sl) < 0) {
1603 } else if (SLAVE_CONVERT_TRIGGERED(sl) > 0) {
1605 ret = read_scratchpad(sl, &info);
1606 SLAVE_CONVERT_TRIGGERED(sl) = 0;
1608 ret = convert_t(sl, &info);
1610 ret = convert_t(sl, &info);
1634 temperature_from_RAM(sl, info.rom));
1645 struct w1_slave *sl = dev_to_w1_slave(device);
1655 if ((!sl->family_data) || (!SLAVE_SPECIFIC_FUNC(sl))) {
1662 ret = copy_scratchpad(sl);
1664 if (SLAVE_SPECIFIC_FUNC(sl)->set_resolution)
1665 ret = SLAVE_SPECIFIC_FUNC(sl)->set_resolution(sl, val);
1673 SLAVE_RESOLUTION(sl) = val;
1675 SLAVE_CONV_TIME_OVERRIDE(sl) = CONV_TIME_DEFAULT;
1683 struct w1_slave *sl = dev_to_w1_slave(device);
1687 if ((!sl->family_data) || (!SLAVE_SPECIFIC_FUNC(sl))) {
1693 if (bulk_read_support(sl)) {
1694 if (SLAVE_CONVERT_TRIGGERED(sl) < 0) {
1699 } else if (SLAVE_CONVERT_TRIGGERED(sl) > 0) {
1701 ret = read_scratchpad(sl, &info);
1702 SLAVE_CONVERT_TRIGGERED(sl) = 0;
1704 ret = convert_t(sl, &info);
1706 ret = convert_t(sl, &info);
1715 return sprintf(buf, "%d\n", temperature_from_RAM(sl, info.rom));
1721 struct w1_slave *sl = dev_to_w1_slave(device);
1723 if (!sl->family_data) {
1730 SLAVE_POWERMODE(sl) = read_powermode(sl);
1732 if (SLAVE_POWERMODE(sl) < 0) {
1735 __func__, SLAVE_POWERMODE(sl));
1737 return sprintf(buf, "%d\n", SLAVE_POWERMODE(sl));
1743 struct w1_slave *sl = dev_to_w1_slave(device);
1745 if ((!sl->family_data) || (!SLAVE_SPECIFIC_FUNC(sl))) {
1752 SLAVE_RESOLUTION(sl) = SLAVE_SPECIFIC_FUNC(sl)->get_resolution(sl);
1753 if (SLAVE_RESOLUTION(sl) < 0) {
1756 __func__, SLAVE_RESOLUTION(sl));
1759 return sprintf(buf, "%d\n", SLAVE_RESOLUTION(sl));
1765 struct w1_slave *sl = dev_to_w1_slave(device);
1777 if ((!sl->family_data) || (!SLAVE_SPECIFIC_FUNC(sl))) {
1789 ret = SLAVE_SPECIFIC_FUNC(sl)->set_resolution(sl, val);
1794 SLAVE_RESOLUTION(sl) = val;
1796 SLAVE_CONV_TIME_OVERRIDE(sl) = CONV_TIME_DEFAULT;
1804 struct w1_slave *sl = dev_to_w1_slave(device);
1809 ret = copy_scratchpad(sl);
1812 ret = recall_eeprom(sl);
1824 struct w1_slave *sl = dev_to_w1_slave(device);
1829 ret = read_scratchpad(sl, &scratchpad);
1846 struct w1_slave *sl = dev_to_w1_slave(device);
1909 ret = read_scratchpad(sl, &info);
1922 if (!SLAVE_SPECIFIC_FUNC(sl)) {
1929 ret = SLAVE_SPECIFIC_FUNC(sl)->write_data(sl, new_config_register);
1965 struct w1_slave *sl = NULL;
1968 list_for_each_entry(sl, &dev_master->slist, w1_slave_entry) {
1969 if (sl->family_data) {
1970 if (bulk_read_support(sl)) {
1971 if (SLAVE_CONVERT_TRIGGERED(sl) == -1) {
1975 if (SLAVE_CONVERT_TRIGGERED(sl) == 1)
1988 struct w1_slave *sl = dev_to_w1_slave(device);
1990 if ((!sl->family_data) || (!SLAVE_SPECIFIC_FUNC(sl))) {
1995 return sprintf(buf, "%d\n", conversion_time(sl));
2002 struct w1_slave *sl = dev_to_w1_slave(device);
2007 if (check_family_data(sl))
2012 SLAVE_CONV_TIME_OVERRIDE(sl) = val;
2019 ret = conv_time_measure(sl, &conv_time);
2022 SLAVE_CONV_TIME_OVERRIDE(sl) = conv_time;
2030 struct w1_slave *sl = dev_to_w1_slave(device);
2032 if ((!sl->family_data) || (!SLAVE_SPECIFIC_FUNC(sl))) {
2037 return sprintf(buf, "%u\n", SLAVE_FEATURES(sl));
2045 struct w1_slave *sl = dev_to_w1_slave(device);
2051 if ((!sl->family_data) || (!SLAVE_SPECIFIC_FUNC(sl))) {
2059 SLAVE_FEATURES(sl) = val;
2062 (!SLAVE_POWERMODE(sl) &&
2065 if (strong_pullup && SLAVE_FEATURES(sl) & W1_THERM_POLL_COMPLETION) {
2066 dev_warn(&sl->dev,
2069 SLAVE_FEATURES(sl) &= ~W1_THERM_POLL_COMPLETION;
2079 struct w1_slave *sl = dev_get_drvdata(device);
2085 ret = convert_t(sl, &info);
2094 *val = temperature_from_RAM(sl, info.rom);
2119 struct w1_slave *sl = dev_to_w1_slave(device);
2127 mutex_lock(&sl->master->bus_mutex);
2129 if (w1_reset_bus(sl->master))
2131 w1_write_8(sl->master, W1_SKIP_ROM);
2132 w1_write_8(sl->master, W1_42_CHAIN);
2133 w1_write_8(sl->master, W1_42_CHAIN_ON);
2134 w1_write_8(sl->master, W1_42_CHAIN_ON_INV);
2135 msleep(sl->master->pullup_duration);
2138 ack = w1_read_8(sl->master);
2144 if (w1_reset_bus(sl->master))
2147 w1_write_8(sl->master, W1_42_COND_READ);
2148 w1_read_block(sl->master, (u8 *)&rn, 8);
2152 if (sl->reg_num.id == reg_num->id)
2155 if (w1_reset_bus(sl->master))
2159 w1_write_8(sl->master, W1_MATCH_ROM);
2160 w1_write_block(sl->master, (u8 *)&rn, 8);
2161 w1_write_8(sl->master, W1_42_CHAIN);
2162 w1_write_8(sl->master, W1_42_CHAIN_DONE);
2163 w1_write_8(sl->master, W1_42_CHAIN_DONE_INV);
2166 ack = w1_read_8(sl->master);
2172 if (w1_reset_bus(sl->master))
2174 w1_write_8(sl->master, W1_SKIP_ROM);
2175 w1_write_8(sl->master, W1_42_CHAIN);
2176 w1_write_8(sl->master, W1_42_CHAIN_OFF);
2177 w1_write_8(sl->master, W1_42_CHAIN_OFF_INV);
2180 ack = w1_read_8(sl->master);
2183 mutex_unlock(&sl->master->bus_mutex);
2188 mutex_unlock(&sl->master->bus_mutex);