Use BIT macro

Mostly done with the cocci script. macro.h was then added manually.
This commit is contained in:
Tim Crawford
2021-02-24 07:52:42 -07:00
committed by Jeremy Soller
parent 9a3ecba010
commit 720af4b2b0
36 changed files with 188 additions and 154 deletions

View File

@@ -43,7 +43,7 @@ struct I2C __code I2C_4 = {
void i2c_reset(struct I2C * i2c, bool kill) {
if (*(i2c->hosta) & HOSTA_BUSY) {
// Set kill bit
if (kill) *(i2c->hoctl) |= (1 << 1);
if (kill) *(i2c->hoctl) |= BIT(1);
// Wait for host to finish
while (*(i2c->hosta) & HOSTA_BUSY) {}
}
@@ -63,7 +63,7 @@ int i2c_start(struct I2C * i2c, uint8_t addr, bool read) __reentrant {
// If we are switching to read mode
if (read) {
// Enable direction switch
*(i2c->hoctl2) |= (1 << 3) | (1 << 2);
*(i2c->hoctl2) |= BIT(3) | BIT(2);
} else {
// Unsupported!
i2c_reset(i2c, true);
@@ -74,7 +74,7 @@ int i2c_start(struct I2C * i2c, uint8_t addr, bool read) __reentrant {
i2c_reset(i2c, true);
// Enable host controller with i2c compatibility
*(i2c->hoctl2) = (1 << 1) | 1;
*(i2c->hoctl2) = BIT(1) | BIT(0);
// Set address
*(i2c->trasla) = (addr << 1) | read;
@@ -85,7 +85,7 @@ int i2c_start(struct I2C * i2c, uint8_t addr, bool read) __reentrant {
void i2c_stop(struct I2C * i2c) {
// Disable i2c compatibility
*(i2c->hoctl2) &= ~(1 << 1);
*(i2c->hoctl2) &= ~BIT(1);
// Clear status
*(i2c->hosta) = *(i2c->hosta);
@@ -99,7 +99,7 @@ static int i2c_transaction(struct I2C * i2c, uint8_t * data, int length, bool re
// If last byte
if ((i + 1) == length) {
// Set last byte bit
*(i2c->hoctl) |= (1 << 5);
*(i2c->hoctl) |= BIT(5);
}
} else {
// Write byte
@@ -112,13 +112,13 @@ static int i2c_transaction(struct I2C * i2c, uint8_t * data, int length, bool re
*(i2c->hosta) = *(i2c->hosta);
} else {
// Start new transaction
*(i2c->hoctl) = (1 << 6) | (0b111 << 2);
*(i2c->hoctl) = BIT(6) | (0b111 << 2);
}
// If we are waiting on direction switch
if (*(i2c->hoctl2) & (1 << 2)) {
if (*(i2c->hoctl2) & BIT(2)) {
// Complete direction switch
*(i2c->hoctl2) &= ~(1 << 2);
*(i2c->hoctl2) &= ~BIT(2);
}
// Wait for byte done, timeout, or error

View File

@@ -3,6 +3,8 @@
#ifndef _EC_GPIO_H
#define _EC_GPIO_H
#include <common/macro.h>
#include <stdbool.h>
#include <stdint.h>
@@ -17,7 +19,7 @@ struct Gpio {
.data = &GPDR ## BLOCK, \
.mirror = &GPDMR ## BLOCK, \
.control = &GPCR ## BLOCK ## NUMBER, \
.value = (1 << NUMBER), \
.value = BIT(NUMBER), \
}
bool gpio_get(struct Gpio * gpio);

View File

@@ -3,6 +3,8 @@
#ifndef _EC_KBC_H
#define _EC_KBC_H
#include <common/macro.h>
#include <stdbool.h>
#include <stdint.h>
@@ -25,9 +27,9 @@ struct Kbc {
extern struct Kbc __code KBC;
#define KBC_STS_OBF (1 << 0)
#define KBC_STS_IBF (1 << 1)
#define KBC_STS_CMD (1 << 3)
#define KBC_STS_OBF BIT(0)
#define KBC_STS_IBF BIT(1)
#define KBC_STS_CMD BIT(3)
uint8_t kbc_status(struct Kbc * kbc);
uint8_t kbc_read(struct Kbc * kbc);

View File

@@ -3,6 +3,8 @@
#ifndef _EC_PMC_H
#define _EC_PMC_H
#include <common/macro.h>
#include <stdbool.h>
#include <stdint.h>
@@ -23,9 +25,9 @@ extern struct Pmc __code PMC_3;
extern struct Pmc __code PMC_4;
extern struct Pmc __code PMC_5;
#define PMC_STS_OBF (1 << 0)
#define PMC_STS_IBF (1 << 1)
#define PMC_STS_CMD (1 << 3)
#define PMC_STS_OBF BIT(0)
#define PMC_STS_IBF BIT(1)
#define PMC_STS_CMD BIT(3)
uint8_t pmc_status(struct Pmc * pmc);
void pmc_set_status(struct Pmc * pmc, uint8_t status);

View File

@@ -3,16 +3,18 @@
#ifndef _EC_SMBUS_H
#define _EC_SMBUS_H
#include <common/macro.h>
#include <stdint.h>
#define HOSTA_BYTE_DONE (1 << 7)
#define HOSTA_TIMEOUT (1 << 6)
#define HOSTA_NACK (1 << 5)
#define HOSTA_FAIL (1 << 4)
#define HOSTA_BUS_ERR (1 << 3)
#define HOSTA_DEV_ERR (1 << 2)
#define HOSTA_FINISH (1 << 1)
#define HOSTA_BUSY (1 << 0)
#define HOSTA_BYTE_DONE BIT(7)
#define HOSTA_TIMEOUT BIT(6)
#define HOSTA_NACK BIT(5)
#define HOSTA_FAIL BIT(4)
#define HOSTA_BUS_ERR BIT(3)
#define HOSTA_DEV_ERR BIT(2)
#define HOSTA_FINISH BIT(1)
#define HOSTA_BUSY BIT(0)
#define HOSTA_ERR (HOSTA_TIMEOUT | HOSTA_NACK | HOSTA_FAIL | HOSTA_BUS_ERR | HOSTA_DEV_ERR)
// Host status for channel A

View File

@@ -2,6 +2,7 @@
#include <stdbool.h>
#include <common/macro.h>
#include <ec/ps2.h>
#define PS2(NUM) { \
@@ -13,11 +14,11 @@
#define PS2_TIMEOUT 10000
#define PSSTS_TIMEOUT_ERR (1 << 6)
#define PSSTS_FRAME_ERR (1 << 5)
#define PSSTS_PARITY_ERR (1 << 4)
#define PSSTS_TIMEOUT_ERR BIT(6)
#define PSSTS_FRAME_ERR BIT(5)
#define PSSTS_PARITY_ERR BIT(4)
#define PSSTS_ALL_ERR (PSSTS_TIMEOUT_ERR | PSSTS_FRAME_ERR | PSSTS_PARITY_ERR)
#define PSSTS_DONE (1 << 3)
#define PSSTS_DONE BIT(3)
struct Ps2 __code PS2_1 = PS2(1);
struct Ps2 __code PS2_2 = PS2(2);

View File

@@ -35,7 +35,7 @@ struct I2C __code I2C_1 = {
void i2c_reset(struct I2C * i2c, bool kill) {
if (*(i2c->hosta) & HOSTA_BUSY) {
// Set kill bit
if (kill) *(i2c->hoctl) |= (1 << 1);
if (kill) *(i2c->hoctl) |= BIT(1);
// Wait for host to finish
while (*(i2c->hosta) & HOSTA_BUSY) {}
}
@@ -55,7 +55,7 @@ int i2c_start(struct I2C * i2c, uint8_t addr, bool read) __reentrant {
// If we are switching to read mode
if (read) {
// Enable direction switch
*(i2c->hoctl2) |= (1 << 3) | (1 << 2);
*(i2c->hoctl2) |= BIT(3) | BIT(2);
} else {
// Unsupported!
i2c_reset(i2c, true);
@@ -66,7 +66,7 @@ int i2c_start(struct I2C * i2c, uint8_t addr, bool read) __reentrant {
i2c_reset(i2c, true);
// Enable host controller with i2c compatibility
*(i2c->hoctl2) = (1 << 1) | 1;
*(i2c->hoctl2) = BIT(1) | BIT(0);
// Set address
*(i2c->trasla) = (addr << 1) | read;
@@ -77,7 +77,7 @@ int i2c_start(struct I2C * i2c, uint8_t addr, bool read) __reentrant {
void i2c_stop(struct I2C * i2c) {
// Disable i2c compatibility
*(i2c->hoctl2) &= ~(1 << 1);
*(i2c->hoctl2) &= ~BIT(1);
// Clear status
*(i2c->hosta) = *(i2c->hosta);
@@ -91,7 +91,7 @@ static int i2c_transaction(struct I2C * i2c, uint8_t * data, int length, bool re
// If last byte
if ((i + 1) == length) {
// Set last byte bit
*(i2c->hoctl) |= (1 << 5);
*(i2c->hoctl) |= BIT(5);
}
} else {
// Write byte
@@ -104,13 +104,13 @@ static int i2c_transaction(struct I2C * i2c, uint8_t * data, int length, bool re
*(i2c->hosta) = *(i2c->hosta);
} else {
// Start new transaction
*(i2c->hoctl) = (1 << 6) | (0b111 << 2);
*(i2c->hoctl) = BIT(6) | (0b111 << 2);
}
// If we are waiting on direction switch
if (*(i2c->hoctl2) & (1 << 2)) {
if (*(i2c->hoctl2) & BIT(2)) {
// Complete direction switch
*(i2c->hoctl2) &= ~(1 << 2);
*(i2c->hoctl2) &= ~BIT(2);
}
// Wait for byte done, timeout, or error

View File

@@ -3,6 +3,8 @@
#ifndef _EC_GPIO_H
#define _EC_GPIO_H
#include <common/macro.h>
#include <stdbool.h>
#include <stdint.h>
@@ -17,7 +19,7 @@ struct Gpio {
.data = &GPDR ## BLOCK, \
.mirror = &GPDMR ## BLOCK, \
.control = &GPCR ## BLOCK ## NUMBER, \
.value = (1 << NUMBER), \
.value = BIT(NUMBER), \
}
bool gpio_get(struct Gpio * gpio);

View File

@@ -3,6 +3,8 @@
#ifndef _EC_KBC_H
#define _EC_KBC_H
#include <common/macro.h>
#include <stdbool.h>
#include <stdint.h>
@@ -25,9 +27,9 @@ struct Kbc {
extern struct Kbc __code KBC;
#define KBC_STS_OBF (1 << 0)
#define KBC_STS_IBF (1 << 1)
#define KBC_STS_CMD (1 << 3)
#define KBC_STS_OBF BIT(0)
#define KBC_STS_IBF BIT(1)
#define KBC_STS_CMD BIT(3)
uint8_t kbc_status(struct Kbc * kbc);
uint8_t kbc_read(struct Kbc * kbc);

View File

@@ -3,6 +3,8 @@
#ifndef _EC_PMC_H
#define _EC_PMC_H
#include <common/macro.h>
#include <stdbool.h>
#include <stdint.h>
@@ -23,9 +25,9 @@ extern struct Pmc __code PMC_3;
extern struct Pmc __code PMC_4;
extern struct Pmc __code PMC_5;
#define PMC_STS_OBF (1 << 0)
#define PMC_STS_IBF (1 << 1)
#define PMC_STS_CMD (1 << 3)
#define PMC_STS_OBF BIT(0)
#define PMC_STS_IBF BIT(1)
#define PMC_STS_CMD BIT(3)
uint8_t pmc_status(struct Pmc * pmc);
void pmc_set_status(struct Pmc * pmc, uint8_t status);

View File

@@ -3,16 +3,18 @@
#ifndef _EC_SMBUS_H
#define _EC_SMBUS_H
#include <common/macro.h>
#include <stdint.h>
#define HOSTA_BYTE_DONE (1 << 7)
#define HOSTA_TIMEOUT (1 << 6)
#define HOSTA_NACK (1 << 5)
#define HOSTA_FAIL (1 << 4)
#define HOSTA_BUS_ERR (1 << 3)
#define HOSTA_DEV_ERR (1 << 2)
#define HOSTA_FINISH (1 << 1)
#define HOSTA_BUSY (1 << 0)
#define HOSTA_BYTE_DONE BIT(7)
#define HOSTA_TIMEOUT BIT(6)
#define HOSTA_NACK BIT(5)
#define HOSTA_FAIL BIT(4)
#define HOSTA_BUS_ERR BIT(3)
#define HOSTA_DEV_ERR BIT(2)
#define HOSTA_FINISH BIT(1)
#define HOSTA_BUSY BIT(0)
#define HOSTA_ERR (HOSTA_TIMEOUT | HOSTA_NACK | HOSTA_FAIL | HOSTA_BUS_ERR | HOSTA_DEV_ERR)
// Host status for channel A

View File

@@ -2,6 +2,7 @@
#include <stdbool.h>
#include <common/macro.h>
#include <ec/ps2.h>
#define PS2(NUM) { \
@@ -13,11 +14,11 @@
#define PS2_TIMEOUT 10000
#define PSSTS_TIMEOUT_ERR (1 << 6)
#define PSSTS_FRAME_ERR (1 << 5)
#define PSSTS_PARITY_ERR (1 << 4)
#define PSSTS_TIMEOUT_ERR BIT(6)
#define PSSTS_FRAME_ERR BIT(5)
#define PSSTS_PARITY_ERR BIT(4)
#define PSSTS_ALL_ERR (PSSTS_TIMEOUT_ERR | PSSTS_FRAME_ERR | PSSTS_PARITY_ERR)
#define PSSTS_DONE (1 << 3)
#define PSSTS_DONE BIT(3)
struct Ps2 __code PS2_1 = PS2(1);
struct Ps2 __code PS2_2 = PS2(2);