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_DS18B20_write_data(struct w1_slave *sl,
580 return write_scratchpad(sl, data, 3);
583 static inline int w1_DS18S20_write_data(struct w1_slave *sl,
587 return write_scratchpad(sl, data, 2);
590 static inline int w1_DS18B20_set_resolution(struct w1_slave *sl, int val)
607 ret = read_scratchpad(sl, &info);
617 ret = w1_DS18B20_write_data(sl, info.rom + 2);
625 ret = read_scratchpad(sl, &info2);
637 static inline int w1_DS18B20_get_resolution(struct w1_slave *sl)
643 ret = read_scratchpad(sl, &info);
774 * @sl: slave to retrieve the device specific structure
778 static struct w1_therm_family_converter *device_family(struct w1_slave *sl)
784 if (w1_therm_families[i].f->fid == sl->family->fid) {
822 * @sl: W1 device data
826 static int check_family_data(struct w1_slave *sl)
828 if ((!sl->family_data) || (!SLAVE_SPECIFIC_FUNC(sl))) {
829 dev_info(&sl->dev,
838 * @sl: device to check the ability
842 static inline bool bulk_read_support(struct w1_slave *sl)
844 if (SLAVE_SPECIFIC_FUNC(sl))
845 return SLAVE_SPECIFIC_FUNC(sl)->bulk_read;
847 dev_info(&sl->dev,
855 * @sl: device to get the conversion time
863 static inline int conversion_time(struct w1_slave *sl)
865 if (SLAVE_SPECIFIC_FUNC(sl))
866 return SLAVE_SPECIFIC_FUNC(sl)->get_conversion_time(sl);
868 dev_info(&sl->dev,
876 * @sl: device that sent the RAM data
883 static inline int temperature_from_RAM(struct w1_slave *sl, u8 rom[9])
885 if (SLAVE_SPECIFIC_FUNC(sl))
886 return SLAVE_SPECIFIC_FUNC(sl)->convert(rom);
888 dev_info(&sl->dev,
916 static int w1_therm_add_slave(struct w1_slave *sl)
921 sl->family_data = kzalloc(sizeof(struct w1_therm_family_data),
923 if (!sl->family_data)
926 atomic_set(THERM_REFCNT(sl->family_data), 1);
929 sl_family_conv = device_family(sl);
931 kfree(sl->family_data);
935 SLAVE_SPECIFIC_FUNC(sl) = sl_family_conv;
937 if (bulk_read_support(sl)) {
943 int err = device_create_file(&sl->master->dev,
947 dev_warn(&sl->dev,
956 SLAVE_POWERMODE(sl) = read_powermode(sl);
958 if (SLAVE_POWERMODE(sl) < 0) {
960 dev_warn(&sl->dev,
962 __func__, SLAVE_POWERMODE(sl));
966 if (SLAVE_SPECIFIC_FUNC(sl)->get_resolution) {
967 SLAVE_RESOLUTION(sl) =
968 SLAVE_SPECIFIC_FUNC(sl)->get_resolution(sl);
969 if (SLAVE_RESOLUTION(sl) < 0) {
971 dev_warn(&sl->dev,
973 __func__, SLAVE_RESOLUTION(sl));
978 SLAVE_CONVERT_TRIGGERED(sl) = 0;
983 static void w1_therm_remove_slave(struct w1_slave *sl)
985 int refcnt = atomic_sub_return(1, THERM_REFCNT(sl->family_data));
987 if (bulk_read_support(sl)) {
991 device_remove_file(&sl->master->dev,
997 refcnt = atomic_read(THERM_REFCNT(sl->family_data));
999 kfree(sl->family_data);
1000 sl->family_data = NULL;
1006 static int reset_select_slave(struct w1_slave *sl)
1009 u64 rn = le64_to_cpu(*((u64 *)&sl->reg_num));
1011 if (w1_reset_bus(sl->master))
1015 w1_write_block(sl->master, match, 9);
1048 static int convert_t(struct w1_slave *sl, struct therm_info *info)
1050 struct w1_master *dev_master = sl->master;
1056 if (!sl->family_data)
1060 (!SLAVE_POWERMODE(sl) &&
1063 if (strong_pullup && SLAVE_FEATURES(sl) & W1_THERM_POLL_COMPLETION) {
1064 dev_warn(&sl->dev,
1067 SLAVE_FEATURES(sl) &= ~W1_THERM_POLL_COMPLETION;
1071 t_conv = conversion_time(sl);
1076 atomic_inc(THERM_REFCNT(sl->family_data));
1088 if (!reset_select_slave(sl)) {
1097 if (SLAVE_FEATURES(sl) & W1_THERM_POLL_COMPLETION) {
1100 dev_dbg(&sl->dev, "%s: Timeout\n", __func__);
1119 ret = read_scratchpad(sl, info);
1122 if ((SLAVE_FEATURES(sl) & W1_THERM_CHECK_RESULT) &&
1142 atomic_dec(THERM_REFCNT(sl->family_data));
1147 static int conv_time_measure(struct w1_slave *sl, int *conv_time)
1151 struct w1_master *dev_master = sl->master;
1156 if (!sl->family_data)
1160 (!SLAVE_POWERMODE(sl) &&
1171 atomic_inc(THERM_REFCNT(sl->family_data));
1182 if (!reset_select_slave(sl)) {
1191 dev_dbg(&sl->dev, "%s: Timeout\n", __func__);
1204 ret = read_scratchpad(sl, info);
1212 atomic_dec(THERM_REFCNT(sl->family_data));
1217 static int read_scratchpad(struct w1_slave *sl, struct therm_info *info)
1219 struct w1_master *dev_master = sl->master;
1225 if (!sl->family_data)
1231 atomic_inc(THERM_REFCNT(sl->family_data));
1240 if (!reset_select_slave(sl)) {
1247 dev_warn(&sl->dev,
1266 atomic_dec(THERM_REFCNT(sl->family_data));
1271 static int write_scratchpad(struct w1_slave *sl, const u8 *data, u8 nb_bytes)
1273 struct w1_master *dev_master = sl->master;
1277 if (!sl->family_data)
1281 atomic_inc(THERM_REFCNT(sl->family_data));
1290 if (!reset_select_slave(sl)) {
1299 atomic_dec(THERM_REFCNT(sl->family_data));
1304 static int copy_scratchpad(struct w1_slave *sl)
1306 struct w1_master *dev_master = sl->master;
1311 if (!sl->family_data)
1316 (!SLAVE_POWERMODE(sl) &&
1320 atomic_inc(THERM_REFCNT(sl->family_data));
1329 if (!reset_select_slave(sl)) {
1353 atomic_dec(THERM_REFCNT(sl->family_data));
1358 static int recall_eeprom(struct w1_slave *sl)
1360 struct w1_master *dev_master = sl->master;
1364 if (!sl->family_data)
1368 atomic_inc(THERM_REFCNT(sl->family_data));
1377 if (!reset_select_slave(sl)) {
1388 atomic_dec(THERM_REFCNT(sl->family_data));
1393 static int read_powermode(struct w1_slave *sl)
1395 struct w1_master *dev_master = sl->master;
1399 if (!sl->family_data)
1403 atomic_inc(THERM_REFCNT(sl->family_data));
1412 if (!reset_select_slave(sl)) {
1426 atomic_dec(THERM_REFCNT(sl->family_data));
1433 struct w1_slave *sl = NULL; /* used to iterate through slaves */
1444 list_for_each_entry(sl, &dev_master->slist, w1_slave_entry) {
1445 if (!sl->family_data)
1447 if (bulk_read_support(sl)) {
1448 int t_cur = conversion_time(sl);
1453 (!SLAVE_POWERMODE(sl) &&
1483 list_for_each_entry(sl,
1485 if (bulk_read_support(sl))
1486 SLAVE_CONVERT_TRIGGERED(sl) = -1;
1513 list_for_each_entry(sl, &dev_master->slist, w1_slave_entry) {
1514 if (bulk_read_support(sl))
1515 SLAVE_CONVERT_TRIGGERED(sl) = 1;
1526 struct w1_slave *sl = dev_to_w1_slave(device);
1528 u8 *family_data = sl->family_data;
1532 if (bulk_read_support(sl)) {
1533 if (SLAVE_CONVERT_TRIGGERED(sl) < 0) {
1538 } else if (SLAVE_CONVERT_TRIGGERED(sl) > 0) {
1540 ret = read_scratchpad(sl, &info);
1541 SLAVE_CONVERT_TRIGGERED(sl) = 0;
1543 ret = convert_t(sl, &info);
1545 ret = convert_t(sl, &info);
1569 temperature_from_RAM(sl, info.rom));
1580 struct w1_slave *sl = dev_to_w1_slave(device);
1590 if ((!sl->family_data) || (!SLAVE_SPECIFIC_FUNC(sl))) {
1597 ret = copy_scratchpad(sl);
1599 if (SLAVE_SPECIFIC_FUNC(sl)->set_resolution)
1600 ret = SLAVE_SPECIFIC_FUNC(sl)->set_resolution(sl, val);
1608 SLAVE_RESOLUTION(sl) = val;
1610 SLAVE_CONV_TIME_OVERRIDE(sl) = CONV_TIME_DEFAULT;
1618 struct w1_slave *sl = dev_to_w1_slave(device);
1622 if ((!sl->family_data) || (!SLAVE_SPECIFIC_FUNC(sl))) {
1628 if (bulk_read_support(sl)) {
1629 if (SLAVE_CONVERT_TRIGGERED(sl) < 0) {
1634 } else if (SLAVE_CONVERT_TRIGGERED(sl) > 0) {
1636 ret = read_scratchpad(sl, &info);
1637 SLAVE_CONVERT_TRIGGERED(sl) = 0;
1639 ret = convert_t(sl, &info);
1641 ret = convert_t(sl, &info);
1650 return sprintf(buf, "%d\n", temperature_from_RAM(sl, info.rom));
1656 struct w1_slave *sl = dev_to_w1_slave(device);
1658 if (!sl->family_data) {
1665 SLAVE_POWERMODE(sl) = read_powermode(sl);
1667 if (SLAVE_POWERMODE(sl) < 0) {
1670 __func__, SLAVE_POWERMODE(sl));
1672 return sprintf(buf, "%d\n", SLAVE_POWERMODE(sl));
1678 struct w1_slave *sl = dev_to_w1_slave(device);
1680 if ((!sl->family_data) || (!SLAVE_SPECIFIC_FUNC(sl))) {
1687 SLAVE_RESOLUTION(sl) = SLAVE_SPECIFIC_FUNC(sl)->get_resolution(sl);
1688 if (SLAVE_RESOLUTION(sl) < 0) {
1691 __func__, SLAVE_RESOLUTION(sl));
1694 return sprintf(buf, "%d\n", SLAVE_RESOLUTION(sl));
1700 struct w1_slave *sl = dev_to_w1_slave(device);
1712 if ((!sl->family_data) || (!SLAVE_SPECIFIC_FUNC(sl))) {
1724 ret = SLAVE_SPECIFIC_FUNC(sl)->set_resolution(sl, val);
1729 SLAVE_RESOLUTION(sl) = val;
1731 SLAVE_CONV_TIME_OVERRIDE(sl) = CONV_TIME_DEFAULT;
1739 struct w1_slave *sl = dev_to_w1_slave(device);
1744 ret = copy_scratchpad(sl);
1747 ret = recall_eeprom(sl);
1759 struct w1_slave *sl = dev_to_w1_slave(device);
1764 ret = read_scratchpad(sl, &scratchpad);
1781 struct w1_slave *sl = dev_to_w1_slave(device);
1845 ret = read_scratchpad(sl, &info);
1858 if (!SLAVE_SPECIFIC_FUNC(sl)) {
1865 ret = SLAVE_SPECIFIC_FUNC(sl)->write_data(sl, new_config_register);
1901 struct w1_slave *sl = NULL;
1904 list_for_each_entry(sl, &dev_master->slist, w1_slave_entry) {
1905 if (sl->family_data) {
1906 if (bulk_read_support(sl)) {
1907 if (SLAVE_CONVERT_TRIGGERED(sl) == -1) {
1911 if (SLAVE_CONVERT_TRIGGERED(sl) == 1)
1924 struct w1_slave *sl = dev_to_w1_slave(device);
1926 if ((!sl->family_data) || (!SLAVE_SPECIFIC_FUNC(sl))) {
1931 return sprintf(buf, "%d\n", conversion_time(sl));
1938 struct w1_slave *sl = dev_to_w1_slave(device);
1943 if (check_family_data(sl))
1948 SLAVE_CONV_TIME_OVERRIDE(sl) = val;
1955 ret = conv_time_measure(sl, &conv_time);
1958 SLAVE_CONV_TIME_OVERRIDE(sl) = conv_time;
1966 struct w1_slave *sl = dev_to_w1_slave(device);
1968 if ((!sl->family_data) || (!SLAVE_SPECIFIC_FUNC(sl))) {
1973 return sprintf(buf, "%u\n", SLAVE_FEATURES(sl));
1981 struct w1_slave *sl = dev_to_w1_slave(device);
1987 if ((!sl->family_data) || (!SLAVE_SPECIFIC_FUNC(sl))) {
1995 SLAVE_FEATURES(sl) = val;
1998 (!SLAVE_POWERMODE(sl) &&
2001 if (strong_pullup && SLAVE_FEATURES(sl) & W1_THERM_POLL_COMPLETION) {
2002 dev_warn(&sl->dev,
2005 SLAVE_FEATURES(sl) &= ~W1_THERM_POLL_COMPLETION;
2015 struct w1_slave *sl = dev_get_drvdata(device);
2021 ret = convert_t(sl, &info);
2030 *val = temperature_from_RAM(sl, info.rom);
2055 struct w1_slave *sl = dev_to_w1_slave(device);
2064 mutex_lock(&sl->master->bus_mutex);
2066 if (w1_reset_bus(sl->master))
2068 w1_write_8(sl->master, W1_SKIP_ROM);
2069 w1_write_8(sl->master, W1_42_CHAIN);
2070 w1_write_8(sl->master, W1_42_CHAIN_ON);
2071 w1_write_8(sl->master, W1_42_CHAIN_ON_INV);
2072 msleep(sl->master->pullup_duration);
2075 ack = w1_read_8(sl->master);
2081 if (w1_reset_bus(sl->master))
2084 w1_write_8(sl->master, W1_42_COND_READ);
2085 rv = w1_read_block(sl->master, (u8 *)&rn, 8);
2089 if (sl->reg_num.id == reg_num->id)
2092 if (w1_reset_bus(sl->master))
2096 w1_write_8(sl->master, W1_MATCH_ROM);
2097 w1_write_block(sl->master, (u8 *)&rn, 8);
2098 w1_write_8(sl->master, W1_42_CHAIN);
2099 w1_write_8(sl->master, W1_42_CHAIN_DONE);
2100 w1_write_8(sl->master, W1_42_CHAIN_DONE_INV);
2103 ack = w1_read_8(sl->master);
2109 if (w1_reset_bus(sl->master))
2111 w1_write_8(sl->master, W1_SKIP_ROM);
2112 w1_write_8(sl->master, W1_42_CHAIN);
2113 w1_write_8(sl->master, W1_42_CHAIN_OFF);
2114 w1_write_8(sl->master, W1_42_CHAIN_OFF_INV);
2117 ack = w1_read_8(sl->master);
2120 mutex_unlock(&sl->master->bus_mutex);
2125 mutex_unlock(&sl->master->bus_mutex);