1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */ 2*4882a593Smuzhiyun /* 3*4882a593Smuzhiyun * Counter interface 4*4882a593Smuzhiyun * Copyright (C) 2018 William Breathitt Gray 5*4882a593Smuzhiyun */ 6*4882a593Smuzhiyun #ifndef _COUNTER_H_ 7*4882a593Smuzhiyun #define _COUNTER_H_ 8*4882a593Smuzhiyun 9*4882a593Smuzhiyun #include <linux/counter_enum.h> 10*4882a593Smuzhiyun #include <linux/device.h> 11*4882a593Smuzhiyun #include <linux/types.h> 12*4882a593Smuzhiyun 13*4882a593Smuzhiyun enum counter_count_direction { 14*4882a593Smuzhiyun COUNTER_COUNT_DIRECTION_FORWARD = 0, 15*4882a593Smuzhiyun COUNTER_COUNT_DIRECTION_BACKWARD 16*4882a593Smuzhiyun }; 17*4882a593Smuzhiyun extern const char *const counter_count_direction_str[2]; 18*4882a593Smuzhiyun 19*4882a593Smuzhiyun enum counter_count_mode { 20*4882a593Smuzhiyun COUNTER_COUNT_MODE_NORMAL = 0, 21*4882a593Smuzhiyun COUNTER_COUNT_MODE_RANGE_LIMIT, 22*4882a593Smuzhiyun COUNTER_COUNT_MODE_NON_RECYCLE, 23*4882a593Smuzhiyun COUNTER_COUNT_MODE_MODULO_N 24*4882a593Smuzhiyun }; 25*4882a593Smuzhiyun extern const char *const counter_count_mode_str[4]; 26*4882a593Smuzhiyun 27*4882a593Smuzhiyun struct counter_device; 28*4882a593Smuzhiyun struct counter_signal; 29*4882a593Smuzhiyun 30*4882a593Smuzhiyun /** 31*4882a593Smuzhiyun * struct counter_signal_ext - Counter Signal extensions 32*4882a593Smuzhiyun * @name: attribute name 33*4882a593Smuzhiyun * @read: read callback for this attribute; may be NULL 34*4882a593Smuzhiyun * @write: write callback for this attribute; may be NULL 35*4882a593Smuzhiyun * @priv: data private to the driver 36*4882a593Smuzhiyun */ 37*4882a593Smuzhiyun struct counter_signal_ext { 38*4882a593Smuzhiyun const char *name; 39*4882a593Smuzhiyun ssize_t (*read)(struct counter_device *counter, 40*4882a593Smuzhiyun struct counter_signal *signal, void *priv, char *buf); 41*4882a593Smuzhiyun ssize_t (*write)(struct counter_device *counter, 42*4882a593Smuzhiyun struct counter_signal *signal, void *priv, 43*4882a593Smuzhiyun const char *buf, size_t len); 44*4882a593Smuzhiyun void *priv; 45*4882a593Smuzhiyun }; 46*4882a593Smuzhiyun 47*4882a593Smuzhiyun /** 48*4882a593Smuzhiyun * struct counter_signal - Counter Signal node 49*4882a593Smuzhiyun * @id: unique ID used to identify signal 50*4882a593Smuzhiyun * @name: device-specific Signal name; ideally, this should match the name 51*4882a593Smuzhiyun * as it appears in the datasheet documentation 52*4882a593Smuzhiyun * @ext: optional array of Counter Signal extensions 53*4882a593Smuzhiyun * @num_ext: number of Counter Signal extensions specified in @ext 54*4882a593Smuzhiyun * @priv: optional private data supplied by driver 55*4882a593Smuzhiyun */ 56*4882a593Smuzhiyun struct counter_signal { 57*4882a593Smuzhiyun int id; 58*4882a593Smuzhiyun const char *name; 59*4882a593Smuzhiyun 60*4882a593Smuzhiyun const struct counter_signal_ext *ext; 61*4882a593Smuzhiyun size_t num_ext; 62*4882a593Smuzhiyun 63*4882a593Smuzhiyun void *priv; 64*4882a593Smuzhiyun }; 65*4882a593Smuzhiyun 66*4882a593Smuzhiyun /** 67*4882a593Smuzhiyun * struct counter_signal_enum_ext - Signal enum extension attribute 68*4882a593Smuzhiyun * @items: Array of strings 69*4882a593Smuzhiyun * @num_items: Number of items specified in @items 70*4882a593Smuzhiyun * @set: Set callback function; may be NULL 71*4882a593Smuzhiyun * @get: Get callback function; may be NULL 72*4882a593Smuzhiyun * 73*4882a593Smuzhiyun * The counter_signal_enum_ext structure can be used to implement enum style 74*4882a593Smuzhiyun * Signal extension attributes. Enum style attributes are those which have a set 75*4882a593Smuzhiyun * of strings that map to unsigned integer values. The Generic Counter Signal 76*4882a593Smuzhiyun * enum extension helper code takes care of mapping between value and string, as 77*4882a593Smuzhiyun * well as generating a "_available" file which contains a list of all available 78*4882a593Smuzhiyun * items. The get callback is used to query the currently active item; the index 79*4882a593Smuzhiyun * of the item within the respective items array is returned via the 'item' 80*4882a593Smuzhiyun * parameter. The set callback is called when the attribute is updated; the 81*4882a593Smuzhiyun * 'item' parameter contains the index of the newly activated item within the 82*4882a593Smuzhiyun * respective items array. 83*4882a593Smuzhiyun */ 84*4882a593Smuzhiyun struct counter_signal_enum_ext { 85*4882a593Smuzhiyun const char * const *items; 86*4882a593Smuzhiyun size_t num_items; 87*4882a593Smuzhiyun int (*get)(struct counter_device *counter, 88*4882a593Smuzhiyun struct counter_signal *signal, size_t *item); 89*4882a593Smuzhiyun int (*set)(struct counter_device *counter, 90*4882a593Smuzhiyun struct counter_signal *signal, size_t item); 91*4882a593Smuzhiyun }; 92*4882a593Smuzhiyun 93*4882a593Smuzhiyun /** 94*4882a593Smuzhiyun * COUNTER_SIGNAL_ENUM() - Initialize Signal enum extension 95*4882a593Smuzhiyun * @_name: Attribute name 96*4882a593Smuzhiyun * @_e: Pointer to a counter_signal_enum_ext structure 97*4882a593Smuzhiyun * 98*4882a593Smuzhiyun * This should usually be used together with COUNTER_SIGNAL_ENUM_AVAILABLE() 99*4882a593Smuzhiyun */ 100*4882a593Smuzhiyun #define COUNTER_SIGNAL_ENUM(_name, _e) \ 101*4882a593Smuzhiyun { \ 102*4882a593Smuzhiyun .name = (_name), \ 103*4882a593Smuzhiyun .read = counter_signal_enum_read, \ 104*4882a593Smuzhiyun .write = counter_signal_enum_write, \ 105*4882a593Smuzhiyun .priv = (_e) \ 106*4882a593Smuzhiyun } 107*4882a593Smuzhiyun 108*4882a593Smuzhiyun /** 109*4882a593Smuzhiyun * COUNTER_SIGNAL_ENUM_AVAILABLE() - Initialize Signal enum available extension 110*4882a593Smuzhiyun * @_name: Attribute name ("_available" will be appended to the name) 111*4882a593Smuzhiyun * @_e: Pointer to a counter_signal_enum_ext structure 112*4882a593Smuzhiyun * 113*4882a593Smuzhiyun * Creates a read only attribute that lists all the available enum items in a 114*4882a593Smuzhiyun * newline separated list. This should usually be used together with 115*4882a593Smuzhiyun * COUNTER_SIGNAL_ENUM() 116*4882a593Smuzhiyun */ 117*4882a593Smuzhiyun #define COUNTER_SIGNAL_ENUM_AVAILABLE(_name, _e) \ 118*4882a593Smuzhiyun { \ 119*4882a593Smuzhiyun .name = (_name "_available"), \ 120*4882a593Smuzhiyun .read = counter_signal_enum_available_read, \ 121*4882a593Smuzhiyun .priv = (_e) \ 122*4882a593Smuzhiyun } 123*4882a593Smuzhiyun 124*4882a593Smuzhiyun enum counter_synapse_action { 125*4882a593Smuzhiyun COUNTER_SYNAPSE_ACTION_NONE = 0, 126*4882a593Smuzhiyun COUNTER_SYNAPSE_ACTION_RISING_EDGE, 127*4882a593Smuzhiyun COUNTER_SYNAPSE_ACTION_FALLING_EDGE, 128*4882a593Smuzhiyun COUNTER_SYNAPSE_ACTION_BOTH_EDGES 129*4882a593Smuzhiyun }; 130*4882a593Smuzhiyun 131*4882a593Smuzhiyun /** 132*4882a593Smuzhiyun * struct counter_synapse - Counter Synapse node 133*4882a593Smuzhiyun * @action: index of current action mode 134*4882a593Smuzhiyun * @actions_list: array of available action modes 135*4882a593Smuzhiyun * @num_actions: number of action modes specified in @actions_list 136*4882a593Smuzhiyun * @signal: pointer to associated signal 137*4882a593Smuzhiyun */ 138*4882a593Smuzhiyun struct counter_synapse { 139*4882a593Smuzhiyun size_t action; 140*4882a593Smuzhiyun const enum counter_synapse_action *actions_list; 141*4882a593Smuzhiyun size_t num_actions; 142*4882a593Smuzhiyun 143*4882a593Smuzhiyun struct counter_signal *signal; 144*4882a593Smuzhiyun }; 145*4882a593Smuzhiyun 146*4882a593Smuzhiyun struct counter_count; 147*4882a593Smuzhiyun 148*4882a593Smuzhiyun /** 149*4882a593Smuzhiyun * struct counter_count_ext - Counter Count extension 150*4882a593Smuzhiyun * @name: attribute name 151*4882a593Smuzhiyun * @read: read callback for this attribute; may be NULL 152*4882a593Smuzhiyun * @write: write callback for this attribute; may be NULL 153*4882a593Smuzhiyun * @priv: data private to the driver 154*4882a593Smuzhiyun */ 155*4882a593Smuzhiyun struct counter_count_ext { 156*4882a593Smuzhiyun const char *name; 157*4882a593Smuzhiyun ssize_t (*read)(struct counter_device *counter, 158*4882a593Smuzhiyun struct counter_count *count, void *priv, char *buf); 159*4882a593Smuzhiyun ssize_t (*write)(struct counter_device *counter, 160*4882a593Smuzhiyun struct counter_count *count, void *priv, 161*4882a593Smuzhiyun const char *buf, size_t len); 162*4882a593Smuzhiyun void *priv; 163*4882a593Smuzhiyun }; 164*4882a593Smuzhiyun 165*4882a593Smuzhiyun enum counter_count_function { 166*4882a593Smuzhiyun COUNTER_COUNT_FUNCTION_INCREASE = 0, 167*4882a593Smuzhiyun COUNTER_COUNT_FUNCTION_DECREASE, 168*4882a593Smuzhiyun COUNTER_COUNT_FUNCTION_PULSE_DIRECTION, 169*4882a593Smuzhiyun COUNTER_COUNT_FUNCTION_QUADRATURE_X1_A, 170*4882a593Smuzhiyun COUNTER_COUNT_FUNCTION_QUADRATURE_X1_B, 171*4882a593Smuzhiyun COUNTER_COUNT_FUNCTION_QUADRATURE_X2_A, 172*4882a593Smuzhiyun COUNTER_COUNT_FUNCTION_QUADRATURE_X2_B, 173*4882a593Smuzhiyun COUNTER_COUNT_FUNCTION_QUADRATURE_X4 174*4882a593Smuzhiyun }; 175*4882a593Smuzhiyun 176*4882a593Smuzhiyun /** 177*4882a593Smuzhiyun * struct counter_count - Counter Count node 178*4882a593Smuzhiyun * @id: unique ID used to identify Count 179*4882a593Smuzhiyun * @name: device-specific Count name; ideally, this should match 180*4882a593Smuzhiyun * the name as it appears in the datasheet documentation 181*4882a593Smuzhiyun * @function: index of current function mode 182*4882a593Smuzhiyun * @functions_list: array available function modes 183*4882a593Smuzhiyun * @num_functions: number of function modes specified in @functions_list 184*4882a593Smuzhiyun * @synapses: array of synapses for initialization 185*4882a593Smuzhiyun * @num_synapses: number of synapses specified in @synapses 186*4882a593Smuzhiyun * @ext: optional array of Counter Count extensions 187*4882a593Smuzhiyun * @num_ext: number of Counter Count extensions specified in @ext 188*4882a593Smuzhiyun * @priv: optional private data supplied by driver 189*4882a593Smuzhiyun */ 190*4882a593Smuzhiyun struct counter_count { 191*4882a593Smuzhiyun int id; 192*4882a593Smuzhiyun const char *name; 193*4882a593Smuzhiyun 194*4882a593Smuzhiyun size_t function; 195*4882a593Smuzhiyun const enum counter_count_function *functions_list; 196*4882a593Smuzhiyun size_t num_functions; 197*4882a593Smuzhiyun 198*4882a593Smuzhiyun struct counter_synapse *synapses; 199*4882a593Smuzhiyun size_t num_synapses; 200*4882a593Smuzhiyun 201*4882a593Smuzhiyun const struct counter_count_ext *ext; 202*4882a593Smuzhiyun size_t num_ext; 203*4882a593Smuzhiyun 204*4882a593Smuzhiyun void *priv; 205*4882a593Smuzhiyun }; 206*4882a593Smuzhiyun 207*4882a593Smuzhiyun /** 208*4882a593Smuzhiyun * struct counter_count_enum_ext - Count enum extension attribute 209*4882a593Smuzhiyun * @items: Array of strings 210*4882a593Smuzhiyun * @num_items: Number of items specified in @items 211*4882a593Smuzhiyun * @set: Set callback function; may be NULL 212*4882a593Smuzhiyun * @get: Get callback function; may be NULL 213*4882a593Smuzhiyun * 214*4882a593Smuzhiyun * The counter_count_enum_ext structure can be used to implement enum style 215*4882a593Smuzhiyun * Count extension attributes. Enum style attributes are those which have a set 216*4882a593Smuzhiyun * of strings that map to unsigned integer values. The Generic Counter Count 217*4882a593Smuzhiyun * enum extension helper code takes care of mapping between value and string, as 218*4882a593Smuzhiyun * well as generating a "_available" file which contains a list of all available 219*4882a593Smuzhiyun * items. The get callback is used to query the currently active item; the index 220*4882a593Smuzhiyun * of the item within the respective items array is returned via the 'item' 221*4882a593Smuzhiyun * parameter. The set callback is called when the attribute is updated; the 222*4882a593Smuzhiyun * 'item' parameter contains the index of the newly activated item within the 223*4882a593Smuzhiyun * respective items array. 224*4882a593Smuzhiyun */ 225*4882a593Smuzhiyun struct counter_count_enum_ext { 226*4882a593Smuzhiyun const char * const *items; 227*4882a593Smuzhiyun size_t num_items; 228*4882a593Smuzhiyun int (*get)(struct counter_device *counter, struct counter_count *count, 229*4882a593Smuzhiyun size_t *item); 230*4882a593Smuzhiyun int (*set)(struct counter_device *counter, struct counter_count *count, 231*4882a593Smuzhiyun size_t item); 232*4882a593Smuzhiyun }; 233*4882a593Smuzhiyun 234*4882a593Smuzhiyun /** 235*4882a593Smuzhiyun * COUNTER_COUNT_ENUM() - Initialize Count enum extension 236*4882a593Smuzhiyun * @_name: Attribute name 237*4882a593Smuzhiyun * @_e: Pointer to a counter_count_enum_ext structure 238*4882a593Smuzhiyun * 239*4882a593Smuzhiyun * This should usually be used together with COUNTER_COUNT_ENUM_AVAILABLE() 240*4882a593Smuzhiyun */ 241*4882a593Smuzhiyun #define COUNTER_COUNT_ENUM(_name, _e) \ 242*4882a593Smuzhiyun { \ 243*4882a593Smuzhiyun .name = (_name), \ 244*4882a593Smuzhiyun .read = counter_count_enum_read, \ 245*4882a593Smuzhiyun .write = counter_count_enum_write, \ 246*4882a593Smuzhiyun .priv = (_e) \ 247*4882a593Smuzhiyun } 248*4882a593Smuzhiyun 249*4882a593Smuzhiyun /** 250*4882a593Smuzhiyun * COUNTER_COUNT_ENUM_AVAILABLE() - Initialize Count enum available extension 251*4882a593Smuzhiyun * @_name: Attribute name ("_available" will be appended to the name) 252*4882a593Smuzhiyun * @_e: Pointer to a counter_count_enum_ext structure 253*4882a593Smuzhiyun * 254*4882a593Smuzhiyun * Creates a read only attribute that lists all the available enum items in a 255*4882a593Smuzhiyun * newline separated list. This should usually be used together with 256*4882a593Smuzhiyun * COUNTER_COUNT_ENUM() 257*4882a593Smuzhiyun */ 258*4882a593Smuzhiyun #define COUNTER_COUNT_ENUM_AVAILABLE(_name, _e) \ 259*4882a593Smuzhiyun { \ 260*4882a593Smuzhiyun .name = (_name "_available"), \ 261*4882a593Smuzhiyun .read = counter_count_enum_available_read, \ 262*4882a593Smuzhiyun .priv = (_e) \ 263*4882a593Smuzhiyun } 264*4882a593Smuzhiyun 265*4882a593Smuzhiyun /** 266*4882a593Smuzhiyun * struct counter_device_attr_group - internal container for attribute group 267*4882a593Smuzhiyun * @attr_group: Counter sysfs attributes group 268*4882a593Smuzhiyun * @attr_list: list to keep track of created Counter sysfs attributes 269*4882a593Smuzhiyun * @num_attr: number of Counter sysfs attributes 270*4882a593Smuzhiyun */ 271*4882a593Smuzhiyun struct counter_device_attr_group { 272*4882a593Smuzhiyun struct attribute_group attr_group; 273*4882a593Smuzhiyun struct list_head attr_list; 274*4882a593Smuzhiyun size_t num_attr; 275*4882a593Smuzhiyun }; 276*4882a593Smuzhiyun 277*4882a593Smuzhiyun /** 278*4882a593Smuzhiyun * struct counter_device_state - internal state container for a Counter device 279*4882a593Smuzhiyun * @id: unique ID used to identify the Counter 280*4882a593Smuzhiyun * @dev: internal device structure 281*4882a593Smuzhiyun * @groups_list: attribute groups list (for Signals, Counts, and ext) 282*4882a593Smuzhiyun * @num_groups: number of attribute groups containers 283*4882a593Smuzhiyun * @groups: Counter sysfs attribute groups (to populate @dev.groups) 284*4882a593Smuzhiyun */ 285*4882a593Smuzhiyun struct counter_device_state { 286*4882a593Smuzhiyun int id; 287*4882a593Smuzhiyun struct device dev; 288*4882a593Smuzhiyun struct counter_device_attr_group *groups_list; 289*4882a593Smuzhiyun size_t num_groups; 290*4882a593Smuzhiyun const struct attribute_group **groups; 291*4882a593Smuzhiyun }; 292*4882a593Smuzhiyun 293*4882a593Smuzhiyun enum counter_signal_value { 294*4882a593Smuzhiyun COUNTER_SIGNAL_LOW = 0, 295*4882a593Smuzhiyun COUNTER_SIGNAL_HIGH 296*4882a593Smuzhiyun }; 297*4882a593Smuzhiyun 298*4882a593Smuzhiyun /** 299*4882a593Smuzhiyun * struct counter_ops - Callbacks from driver 300*4882a593Smuzhiyun * @signal_read: optional read callback for Signal attribute. The read 301*4882a593Smuzhiyun * value of the respective Signal should be passed back via 302*4882a593Smuzhiyun * the val parameter. 303*4882a593Smuzhiyun * @count_read: optional read callback for Count attribute. The read 304*4882a593Smuzhiyun * value of the respective Count should be passed back via 305*4882a593Smuzhiyun * the val parameter. 306*4882a593Smuzhiyun * @count_write: optional write callback for Count attribute. The write 307*4882a593Smuzhiyun * value for the respective Count is passed in via the val 308*4882a593Smuzhiyun * parameter. 309*4882a593Smuzhiyun * @function_get: function to get the current count function mode. Returns 310*4882a593Smuzhiyun * 0 on success and negative error code on error. The index 311*4882a593Smuzhiyun * of the respective Count's returned function mode should 312*4882a593Smuzhiyun * be passed back via the function parameter. 313*4882a593Smuzhiyun * @function_set: function to set the count function mode. function is the 314*4882a593Smuzhiyun * index of the requested function mode from the respective 315*4882a593Smuzhiyun * Count's functions_list array. 316*4882a593Smuzhiyun * @action_get: function to get the current action mode. Returns 0 on 317*4882a593Smuzhiyun * success and negative error code on error. The index of 318*4882a593Smuzhiyun * the respective Synapse's returned action mode should be 319*4882a593Smuzhiyun * passed back via the action parameter. 320*4882a593Smuzhiyun * @action_set: function to set the action mode. action is the index of 321*4882a593Smuzhiyun * the requested action mode from the respective Synapse's 322*4882a593Smuzhiyun * actions_list array. 323*4882a593Smuzhiyun */ 324*4882a593Smuzhiyun struct counter_ops { 325*4882a593Smuzhiyun int (*signal_read)(struct counter_device *counter, 326*4882a593Smuzhiyun struct counter_signal *signal, 327*4882a593Smuzhiyun enum counter_signal_value *val); 328*4882a593Smuzhiyun int (*count_read)(struct counter_device *counter, 329*4882a593Smuzhiyun struct counter_count *count, unsigned long *val); 330*4882a593Smuzhiyun int (*count_write)(struct counter_device *counter, 331*4882a593Smuzhiyun struct counter_count *count, unsigned long val); 332*4882a593Smuzhiyun int (*function_get)(struct counter_device *counter, 333*4882a593Smuzhiyun struct counter_count *count, size_t *function); 334*4882a593Smuzhiyun int (*function_set)(struct counter_device *counter, 335*4882a593Smuzhiyun struct counter_count *count, size_t function); 336*4882a593Smuzhiyun int (*action_get)(struct counter_device *counter, 337*4882a593Smuzhiyun struct counter_count *count, 338*4882a593Smuzhiyun struct counter_synapse *synapse, size_t *action); 339*4882a593Smuzhiyun int (*action_set)(struct counter_device *counter, 340*4882a593Smuzhiyun struct counter_count *count, 341*4882a593Smuzhiyun struct counter_synapse *synapse, size_t action); 342*4882a593Smuzhiyun }; 343*4882a593Smuzhiyun 344*4882a593Smuzhiyun /** 345*4882a593Smuzhiyun * struct counter_device_ext - Counter device extension 346*4882a593Smuzhiyun * @name: attribute name 347*4882a593Smuzhiyun * @read: read callback for this attribute; may be NULL 348*4882a593Smuzhiyun * @write: write callback for this attribute; may be NULL 349*4882a593Smuzhiyun * @priv: data private to the driver 350*4882a593Smuzhiyun */ 351*4882a593Smuzhiyun struct counter_device_ext { 352*4882a593Smuzhiyun const char *name; 353*4882a593Smuzhiyun ssize_t (*read)(struct counter_device *counter, void *priv, char *buf); 354*4882a593Smuzhiyun ssize_t (*write)(struct counter_device *counter, void *priv, 355*4882a593Smuzhiyun const char *buf, size_t len); 356*4882a593Smuzhiyun void *priv; 357*4882a593Smuzhiyun }; 358*4882a593Smuzhiyun 359*4882a593Smuzhiyun /** 360*4882a593Smuzhiyun * struct counter_device_enum_ext - Counter enum extension attribute 361*4882a593Smuzhiyun * @items: Array of strings 362*4882a593Smuzhiyun * @num_items: Number of items specified in @items 363*4882a593Smuzhiyun * @set: Set callback function; may be NULL 364*4882a593Smuzhiyun * @get: Get callback function; may be NULL 365*4882a593Smuzhiyun * 366*4882a593Smuzhiyun * The counter_device_enum_ext structure can be used to implement enum style 367*4882a593Smuzhiyun * Counter extension attributes. Enum style attributes are those which have a 368*4882a593Smuzhiyun * set of strings that map to unsigned integer values. The Generic Counter enum 369*4882a593Smuzhiyun * extension helper code takes care of mapping between value and string, as well 370*4882a593Smuzhiyun * as generating a "_available" file which contains a list of all available 371*4882a593Smuzhiyun * items. The get callback is used to query the currently active item; the index 372*4882a593Smuzhiyun * of the item within the respective items array is returned via the 'item' 373*4882a593Smuzhiyun * parameter. The set callback is called when the attribute is updated; the 374*4882a593Smuzhiyun * 'item' parameter contains the index of the newly activated item within the 375*4882a593Smuzhiyun * respective items array. 376*4882a593Smuzhiyun */ 377*4882a593Smuzhiyun struct counter_device_enum_ext { 378*4882a593Smuzhiyun const char * const *items; 379*4882a593Smuzhiyun size_t num_items; 380*4882a593Smuzhiyun int (*get)(struct counter_device *counter, size_t *item); 381*4882a593Smuzhiyun int (*set)(struct counter_device *counter, size_t item); 382*4882a593Smuzhiyun }; 383*4882a593Smuzhiyun 384*4882a593Smuzhiyun /** 385*4882a593Smuzhiyun * COUNTER_DEVICE_ENUM() - Initialize Counter enum extension 386*4882a593Smuzhiyun * @_name: Attribute name 387*4882a593Smuzhiyun * @_e: Pointer to a counter_device_enum_ext structure 388*4882a593Smuzhiyun * 389*4882a593Smuzhiyun * This should usually be used together with COUNTER_DEVICE_ENUM_AVAILABLE() 390*4882a593Smuzhiyun */ 391*4882a593Smuzhiyun #define COUNTER_DEVICE_ENUM(_name, _e) \ 392*4882a593Smuzhiyun { \ 393*4882a593Smuzhiyun .name = (_name), \ 394*4882a593Smuzhiyun .read = counter_device_enum_read, \ 395*4882a593Smuzhiyun .write = counter_device_enum_write, \ 396*4882a593Smuzhiyun .priv = (_e) \ 397*4882a593Smuzhiyun } 398*4882a593Smuzhiyun 399*4882a593Smuzhiyun /** 400*4882a593Smuzhiyun * COUNTER_DEVICE_ENUM_AVAILABLE() - Initialize Counter enum available extension 401*4882a593Smuzhiyun * @_name: Attribute name ("_available" will be appended to the name) 402*4882a593Smuzhiyun * @_e: Pointer to a counter_device_enum_ext structure 403*4882a593Smuzhiyun * 404*4882a593Smuzhiyun * Creates a read only attribute that lists all the available enum items in a 405*4882a593Smuzhiyun * newline separated list. This should usually be used together with 406*4882a593Smuzhiyun * COUNTER_DEVICE_ENUM() 407*4882a593Smuzhiyun */ 408*4882a593Smuzhiyun #define COUNTER_DEVICE_ENUM_AVAILABLE(_name, _e) \ 409*4882a593Smuzhiyun { \ 410*4882a593Smuzhiyun .name = (_name "_available"), \ 411*4882a593Smuzhiyun .read = counter_device_enum_available_read, \ 412*4882a593Smuzhiyun .priv = (_e) \ 413*4882a593Smuzhiyun } 414*4882a593Smuzhiyun 415*4882a593Smuzhiyun /** 416*4882a593Smuzhiyun * struct counter_device - Counter data structure 417*4882a593Smuzhiyun * @name: name of the device as it appears in the datasheet 418*4882a593Smuzhiyun * @parent: optional parent device providing the counters 419*4882a593Smuzhiyun * @device_state: internal device state container 420*4882a593Smuzhiyun * @ops: callbacks from driver 421*4882a593Smuzhiyun * @signals: array of Signals 422*4882a593Smuzhiyun * @num_signals: number of Signals specified in @signals 423*4882a593Smuzhiyun * @counts: array of Counts 424*4882a593Smuzhiyun * @num_counts: number of Counts specified in @counts 425*4882a593Smuzhiyun * @ext: optional array of Counter device extensions 426*4882a593Smuzhiyun * @num_ext: number of Counter device extensions specified in @ext 427*4882a593Smuzhiyun * @priv: optional private data supplied by driver 428*4882a593Smuzhiyun */ 429*4882a593Smuzhiyun struct counter_device { 430*4882a593Smuzhiyun const char *name; 431*4882a593Smuzhiyun struct device *parent; 432*4882a593Smuzhiyun struct counter_device_state *device_state; 433*4882a593Smuzhiyun 434*4882a593Smuzhiyun const struct counter_ops *ops; 435*4882a593Smuzhiyun 436*4882a593Smuzhiyun struct counter_signal *signals; 437*4882a593Smuzhiyun size_t num_signals; 438*4882a593Smuzhiyun struct counter_count *counts; 439*4882a593Smuzhiyun size_t num_counts; 440*4882a593Smuzhiyun 441*4882a593Smuzhiyun const struct counter_device_ext *ext; 442*4882a593Smuzhiyun size_t num_ext; 443*4882a593Smuzhiyun 444*4882a593Smuzhiyun void *priv; 445*4882a593Smuzhiyun }; 446*4882a593Smuzhiyun 447*4882a593Smuzhiyun int counter_register(struct counter_device *const counter); 448*4882a593Smuzhiyun void counter_unregister(struct counter_device *const counter); 449*4882a593Smuzhiyun int devm_counter_register(struct device *dev, 450*4882a593Smuzhiyun struct counter_device *const counter); 451*4882a593Smuzhiyun void devm_counter_unregister(struct device *dev, 452*4882a593Smuzhiyun struct counter_device *const counter); 453*4882a593Smuzhiyun 454*4882a593Smuzhiyun #endif /* _COUNTER_H_ */ 455