1 /* SPDX-License-Identifier: GPL-2.0 */ 1 2 /* 3 * mux/driver.h - definitions for the multiple 4 * 5 * Copyright (C) 2017 Axentia Technologies AB 6 * 7 * Author: Peter Rosin <peda@axentia.se> 8 */ 9 10 #ifndef _LINUX_MUX_DRIVER_H 11 #define _LINUX_MUX_DRIVER_H 12 13 #include <dt-bindings/mux/mux.h> 14 #include <linux/device.h> 15 #include <linux/ktime.h> 16 #include <linux/semaphore.h> 17 18 struct mux_chip; 19 struct mux_control; 20 21 /** 22 * struct mux_control_ops - Mux controller 23 * @set: Set the state 24 */ 25 struct mux_control_ops { 26 int (*set)(struct mux_control *mux, in 27 }; 28 29 /** 30 * struct mux_control - Represents a mux contr 31 * @lock: Protects the mux contr 32 * @chip: The mux chip that is h 33 * @cached_state: The current mux contro 34 * @states: The number of mux cont 35 * @idle_state: The mux controller sta 36 * of MUX_IDLE_AS_IS and 37 * @last_change: Timestamp of last chan 38 * 39 * Mux drivers may only change @states and @id 40 * between allocation and registration of the 41 * @cached_state is internal to the mux core a 42 * mux drivers. 43 */ 44 struct mux_control { 45 struct semaphore lock; /* protects the 46 47 struct mux_chip *chip; 48 int cached_state; 49 50 unsigned int states; 51 int idle_state; 52 53 ktime_t last_change; 54 }; 55 56 /** 57 * struct mux_chip - Represents a chip hold 58 * @controllers: Number of mux controll 59 * @mux: Array of mux controlle 60 * @dev: Device structure. 61 * @id: Used to identify the d 62 * @ops: Mux controller operati 63 */ 64 struct mux_chip { 65 unsigned int controllers; 66 struct mux_control *mux; 67 struct device dev; 68 int id; 69 70 const struct mux_control_ops *ops; 71 }; 72 73 #define to_mux_chip(x) container_of((x), struc 74 75 /** 76 * mux_chip_priv() - Get the extra memory rese 77 * @mux_chip: The mux-chip to get the private 78 * 79 * Return: Pointer to the private memory reser 80 */ 81 static inline void *mux_chip_priv(struct mux_c 82 { 83 return &mux_chip->mux[mux_chip->contro 84 } 85 86 struct mux_chip *mux_chip_alloc(struct device 87 unsigned int c 88 int mux_chip_register(struct mux_chip *mux_chi 89 void mux_chip_unregister(struct mux_chip *mux_ 90 void mux_chip_free(struct mux_chip *mux_chip); 91 92 struct mux_chip *devm_mux_chip_alloc(struct de 93 unsigned 94 size_t si 95 int devm_mux_chip_register(struct device *dev, 96 97 /** 98 * mux_control_get_index() - Get the index of 99 * @mux: The mux-control to get the index for. 100 * 101 * Return: The index of the mux controller wit 102 * controller is a part of. 103 */ 104 static inline unsigned int mux_control_get_ind 105 { 106 return mux - mux->chip->mux; 107 } 108 109 #endif /* _LINUX_MUX_DRIVER_H */ 110
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.