Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Evgeniy Polyakov | a801876 | 2011-08-25 15:59:06 -0700 | [diff] [blame] | 2 | * Copyright (c) 2004 Evgeniy Polyakov <zbr@ioremap.net> |
Evgeniy Polyakov | 7785925 | 2005-05-20 22:33:25 +0400 | [diff] [blame] | 3 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; either version 2 of the License, or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | */ |
| 14 | |
| 15 | #ifndef __W1_FAMILY_H |
| 16 | #define __W1_FAMILY_H |
| 17 | |
| 18 | #include <linux/types.h> |
| 19 | #include <linux/device.h> |
Arun Sharma | 60063497 | 2011-07-26 16:09:06 -0700 | [diff] [blame] | 20 | #include <linux/atomic.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | |
| 22 | #define W1_FAMILY_DEFAULT 0 |
NeilBrown | 4b7e4f8 | 2014-11-19 14:04:20 +1100 | [diff] [blame] | 23 | #define W1_FAMILY_BQ27000 0x01 |
Evgeniy Polyakov | 85e941c | 2005-05-02 14:26:42 +0400 | [diff] [blame] | 24 | #define W1_FAMILY_SMEM_01 0x01 |
| 25 | #define W1_FAMILY_SMEM_81 0x81 |
Maciej S. Szmigiero | dd6478d | 2017-01-19 21:26:51 +0100 | [diff] [blame] | 26 | #define W1_FAMILY_DS2405 0x05 |
Evgeniy Polyakov | 718a538 | 2005-04-17 22:58:14 +0400 | [diff] [blame] | 27 | #define W1_THERM_DS18S20 0x10 |
Markus Franke | fbf7f7b | 2012-05-26 00:45:12 +0200 | [diff] [blame] | 28 | #define W1_FAMILY_DS28E04 0x1C |
Mika Laitio | 17fecb5 | 2011-01-12 17:01:06 -0800 | [diff] [blame] | 29 | #define W1_COUNTER_DS2423 0x1D |
Evgeniy Polyakov | 718a538 | 2005-04-17 22:58:14 +0400 | [diff] [blame] | 30 | #define W1_THERM_DS1822 0x22 |
Evgeniy Polyakov | a3d65f2 | 2005-08-11 17:27:50 +0400 | [diff] [blame] | 31 | #define W1_EEPROM_DS2433 0x23 |
Evgeniy Polyakov | 718a538 | 2005-04-17 22:58:14 +0400 | [diff] [blame] | 32 | #define W1_THERM_DS18B20 0x28 |
Jean-François Dagenais | 8961027 | 2011-05-26 16:26:02 -0700 | [diff] [blame] | 33 | #define W1_FAMILY_DS2408 0x29 |
Bernhard Weirich | d827367 | 2008-10-15 22:05:11 -0700 | [diff] [blame] | 34 | #define W1_EEPROM_DS2431 0x2D |
Anton Vorontsov | d7ce6d1 | 2007-04-12 01:03:55 +0400 | [diff] [blame] | 35 | #define W1_FAMILY_DS2760 0x30 |
Clifton Barnes | 275ac74 | 2011-05-26 16:26:04 -0700 | [diff] [blame] | 36 | #define W1_FAMILY_DS2780 0x32 |
Mariusz Bialonczyk | 31b4ca3 | 2013-02-27 17:05:47 -0800 | [diff] [blame] | 37 | #define W1_FAMILY_DS2413 0x3A |
Scott Alfter | 94859308 | 2014-06-17 20:42:05 +0000 | [diff] [blame] | 38 | #define W1_FAMILY_DS2406 0x12 |
Raphael Assenat | f3261df | 2012-08-16 12:56:40 -0400 | [diff] [blame] | 39 | #define W1_THERM_DS1825 0x3B |
Renata Sayakhova | fef37e9 | 2012-02-29 14:58:53 +0100 | [diff] [blame] | 40 | #define W1_FAMILY_DS2781 0x3D |
Christian Glindkamp | f7b1371 | 2011-07-26 16:08:55 -0700 | [diff] [blame] | 41 | #define W1_THERM_DS28EA00 0x42 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | |
| 43 | #define MAXNAMELEN 32 |
| 44 | |
Evgeniy Polyakov | d2a4ef6 | 2005-08-11 17:27:50 +0400 | [diff] [blame] | 45 | struct w1_slave; |
| 46 | |
David Fries | b3be177 | 2014-01-15 22:29:25 -0600 | [diff] [blame] | 47 | /** |
| 48 | * struct w1_family_ops - operations for a family type |
| 49 | * @add_slave: add_slave |
| 50 | * @remove_slave: remove_slave |
| 51 | * @groups: sysfs group |
| 52 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | struct w1_family_ops |
| 54 | { |
Evgeniy Polyakov | d2a4ef6 | 2005-08-11 17:27:50 +0400 | [diff] [blame] | 55 | int (* add_slave)(struct w1_slave *); |
| 56 | void (* remove_slave)(struct w1_slave *); |
Greg Kroah-Hartman | 36c27a6 | 2013-08-21 15:44:55 -0700 | [diff] [blame] | 57 | const struct attribute_group **groups; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | }; |
| 59 | |
David Fries | b3be177 | 2014-01-15 22:29:25 -0600 | [diff] [blame] | 60 | /** |
| 61 | * struct w1_family - reference counted family structure. |
| 62 | * @family_entry: family linked list |
| 63 | * @fid: 8 bit family identifier |
| 64 | * @fops: operations for this family |
| 65 | * @refcnt: reference counter |
| 66 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | struct w1_family |
| 68 | { |
| 69 | struct list_head family_entry; |
| 70 | u8 fid; |
Evgeniy Polyakov | 7785925 | 2005-05-20 22:33:25 +0400 | [diff] [blame] | 71 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | struct w1_family_ops *fops; |
Evgeniy Polyakov | 7785925 | 2005-05-20 22:33:25 +0400 | [diff] [blame] | 73 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | atomic_t refcnt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | }; |
| 76 | |
| 77 | extern spinlock_t w1_flock; |
| 78 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | void w1_family_put(struct w1_family *); |
| 80 | void __w1_family_get(struct w1_family *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | struct w1_family * w1_family_registered(u8); |
| 82 | void w1_unregister_family(struct w1_family *); |
| 83 | int w1_register_family(struct w1_family *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | |
Andrew F. Davis | 939fc83 | 2016-08-02 14:07:09 -0700 | [diff] [blame] | 85 | /** |
| 86 | * module_w1_driver() - Helper macro for registering a 1-Wire families |
| 87 | * @__w1_family: w1_family struct |
| 88 | * |
| 89 | * Helper macro for 1-Wire families which do not do anything special in module |
| 90 | * init/exit. This eliminates a lot of boilerplate. Each module may only |
| 91 | * use this macro once, and calling it replaces module_init() and module_exit() |
| 92 | */ |
| 93 | #define module_w1_family(__w1_family) \ |
| 94 | module_driver(__w1_family, w1_register_family, \ |
| 95 | w1_unregister_family) |
| 96 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | #endif /* __W1_FAMILY_H */ |