blob: 184d46f7202257a0a23b39de51cfdfe1ed6b583d [file] [log] [blame]
David Collinsed930492013-01-23 13:57:09 -08001/* Copyright (c) 2013, The Linux Foundation. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 */
12
13#ifndef _LINUX_BIF_DRIVER_H_
14#define _LINUX_BIF_DRIVER_H_
15
16#include <linux/device.h>
17#include <linux/err.h>
18#include <linux/types.h>
19#include <linux/bif/consumer.h>
20
21/**
22 * struct bif_ctrl_dev - opaque handle used to identify a given BIF controller
23 * device
24 */
25struct bif_ctrl_dev;
26
27/**
28 * struct bif_ctrl_ops - BIF operations which may be implemented by BIF
29 * controller drivers
30 * @bus_transaction: Perform the specified BIF transaction which does
31 * not result in any slave response.
32 * @bus_transaction_query: Perform the specified BIF transaction which
33 * expects a BQ response in the case of slave
34 * positive acknowledgement.
35 * @bus_transaction_read: Perform the specified BIF transaction which
36 * expects an RD or TACK response from the selected
37 * slave.
38 * @read_slave_registers: Perform all BIF transactions necessary to read
39 * the specified set of contiguous registers from
40 * the previously selected slave. This operation
41 * is used to optimize the common case of slave
42 * register reads since the a BIF controller driver
43 * can take advantage of BIF burst reads while the
44 * BIF core driver cannot due to the inherient
45 * tight timing requirements.
46 * @write_slave_registers: Perform all BIF transactions necessary to write
47 * the specified set of contiguous registers to
48 * the previously selected slave. This operation
49 * is used to optimize the common case of slave
50 * register writes since the a BIF controller
51 * driver can remove redundant steps when
52 * performing several WD commands in a row.
53 * @get_bus_period: Return the tau_bif BIF bus clock period in
54 * nanoseconds.
55 * @set_bus_period: Set the tau_bif BIF bus clock period in
56 * nanoseconds. If the exact period is not
57 * supported by the BIF controller hardware, then
58 * the next larger supported period should be used.
59 * @get_battery_presence: Return the current state of the battery pack.
60 * If a battery pack is present, then return >= 1.
61 * If a battery pack is not present, then return 0.
62 * If an error occurs during presence detection,
63 * then return errno.
64 * @get_battery_rid: Return the measured value of the Rid battery
65 * pack pull-down resistor in ohms.
66 * @get_bus_state: Return the current bus state as defined by one
67 * of the enum bif_bus_state values.
68 * @set_bus_state: Set the BIF bus state to the specified enum
69 * bif_bus_state value.
70 *
71 * The following operations must be defined by every BIF controller driver in
72 * order to ensure baseline functionality:
73 * bus_transaction, bus_transaction_query, get_bus_state, and set_bus_state.
74 *
75 * The BIF core driver is unaware of BIF transaction timing constraints. A
76 * given BIF controller driver must ensure that all timing constraints in the
77 * MIPI-BIF specification are met as transactions are carried out.
78 *
79 * Conversion between 11-bit and 17-bit BIF words (i.e. the insertion of BCF_n,
80 * parity bits, and the inversion bit) must be handled inside of the BIF
81 * controller driver (either in software or hardware). This guarantees maximum
82 * performance if hardware support is available.
83 *
84 * The bus_transaction_read operation must return -ETIMEDOUT in the case of no
85 * RD or TACK word received. This allows the transaction query, TQ, command
86 * to be used for slave selection verification.
87 *
88 * It is acceptable for the BIF bus state to be changed autonomously by a BIF
89 * controller driver in response to low level bus actions without a call to
90 * set_bus_state. One example is the case of receiving a slave interrupt
91 * while in interrupt state as this intrinsically causes the bus to enter the
92 * active communication state.
93 */
94struct bif_ctrl_ops {
95 int (*bus_transaction) (struct bif_ctrl_dev *bdev, int transaction,
96 u8 data);
97 int (*bus_transaction_query) (struct bif_ctrl_dev *bdev,
98 int transaction, u8 data,
99 bool *query_response);
100 int (*bus_transaction_read) (struct bif_ctrl_dev *bdev,
101 int transaction, u8 data,
102 int *response);
103 int (*read_slave_registers) (struct bif_ctrl_dev *bdev, u16 addr,
104 u8 *data, int len);
105 int (*write_slave_registers) (struct bif_ctrl_dev *bdev, u16 addr,
106 const u8 *data, int len);
107 int (*get_bus_period) (struct bif_ctrl_dev *bdev);
108 int (*set_bus_period) (struct bif_ctrl_dev *bdev, int period_ns);
109 int (*get_battery_presence) (struct bif_ctrl_dev *bdev);
110 int (*get_battery_rid) (struct bif_ctrl_dev *bdev);
111 int (*get_bus_state) (struct bif_ctrl_dev *bdev);
112 int (*set_bus_state) (struct bif_ctrl_dev *bdev, int state);
113};
114
115/**
116 * struct bif_ctrl_desc - BIF bus controller descriptor
117 * @name: Name used to identify the BIF controller
118 * @ops: BIF operations supported by the BIF controller
119 * @bus_clock_min_ns: Minimum tau_bif BIF bus clock period supported by the
120 * BIF controller
121 * @bus_clock_max_ns: Maximum tau_bif BIF bus clock period supported by the
122 * BIF controller
123 *
124 * Each BIF controller registered with the BIF core is described with a
125 * structure of this type.
126 */
127struct bif_ctrl_desc {
128 const char *name;
129 struct bif_ctrl_ops *ops;
130 int bus_clock_min_ns;
131 int bus_clock_max_ns;
132};
133
134#ifdef CONFIG_BIF
135
136struct bif_ctrl_dev *bif_ctrl_register(struct bif_ctrl_desc *bif_desc,
137 struct device *dev, void *driver_data, struct device_node *of_node);
138
139void bif_ctrl_unregister(struct bif_ctrl_dev *bdev);
140
141void *bdev_get_drvdata(struct bif_ctrl_dev *bdev);
142
143int bif_ctrl_notify_battery_changed(struct bif_ctrl_dev *bdev);
144int bif_ctrl_notify_slave_irq(struct bif_ctrl_dev *bdev);
145
146#else
147
148static inline struct bif_ctrl_dev *bif_ctrl_register(
149 struct bif_ctrl_desc *bif_desc, struct device *dev, void *driver_data,
150 struct device_node *of_node)
151{ return ERR_PTR(-EINVAL); }
152
153static inline void bif_ctrl_unregister(struct bif_ctrl_dev *bdev) { }
154
155static inline void *bdev_get_drvdata(struct bif_ctrl_dev *bdev) { return NULL; }
156
157int bif_ctrl_notify_slave_irq(struct bif_ctrl_dev *bdev) { return -EINVAL; }
158
159#endif
160
161#endif